CyTube/www/js/vjs/videojs-dash.js
Xaekai f6ba5b71e8 Update vjs components
Upgrade Video.js core to v7.18.0 from v5.10.7
Upgrade Dash.js to v4.2.8 from v2.6.3
Upgrade videojs-contrib-dash to v5.1.1 from v2.9.1
Modify videojs-resolution-switcher
2022-09-18 19:10:36 -07:00

69963 lines
2.6 MiB
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*! @name videojs-contrib-dash @version 5.1.1 @license Apache-2.0 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('video.js'), require('global/window'), require('global/document')) :
typeof define === 'function' && define.amd ? define(['video.js', 'global/window', 'global/document'], factory) :
(global.videojsDash = factory(global.videojs,global.window,global.document));
}(this, (function (videojs,window$1,document$1) { 'use strict';
videojs = videojs && videojs.hasOwnProperty('default') ? videojs['default'] : videojs;
window$1 = window$1 && window$1.hasOwnProperty('default') ? window$1['default'] : window$1;
document$1 = document$1 && document$1.hasOwnProperty('default') ? document$1['default'] : document$1;
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var dash_all_debug = createCommonjsModule(function (module, exports) {
(function webpackUniversalModuleDefinition(root, factory) {
module.exports = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./externals/base64.js":
/*!*****************************!*\
!*** ./externals/base64.js ***!
\*****************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* $Date: 2007-06-12 18:02:31 $ */
// from: http://bannister.us/weblog/2007/06/09/simple-base64-encodedecode-javascript/
// Handles encode/decode of ASCII and Unicode strings.
var UTF8 = {};
UTF8.encode = function (s) {
var u = [];
for (var i = 0; i < s.length; ++i) {
var c = s.charCodeAt(i);
if (c < 0x80) {
u.push(c);
} else if (c < 0x800) {
u.push(0xC0 | c >> 6);
u.push(0x80 | 63 & c);
} else if (c < 0x10000) {
u.push(0xE0 | c >> 12);
u.push(0x80 | 63 & c >> 6);
u.push(0x80 | 63 & c);
} else {
u.push(0xF0 | c >> 18);
u.push(0x80 | 63 & c >> 12);
u.push(0x80 | 63 & c >> 6);
u.push(0x80 | 63 & c);
}
}
return u;
};
UTF8.decode = function (u) {
var a = [];
var i = 0;
while (i < u.length) {
var v = u[i++];
if (v < 0x80) ; else if (v < 0xE0) {
v = (31 & v) << 6;
v |= 63 & u[i++];
} else if (v < 0xF0) {
v = (15 & v) << 12;
v |= (63 & u[i++]) << 6;
v |= 63 & u[i++];
} else {
v = (7 & v) << 18;
v |= (63 & u[i++]) << 12;
v |= (63 & u[i++]) << 6;
v |= 63 & u[i++];
}
a.push(String.fromCharCode(v));
}
return a.join('');
};
var BASE64 = {};
(function (T) {
var encodeArray = function encodeArray(u) {
var i = 0;
var a = [];
var n = 0 | u.length / 3;
while (0 < n--) {
var v = (u[i] << 16) + (u[i + 1] << 8) + u[i + 2];
i += 3;
a.push(T.charAt(63 & v >> 18));
a.push(T.charAt(63 & v >> 12));
a.push(T.charAt(63 & v >> 6));
a.push(T.charAt(63 & v));
}
if (2 == u.length - i) {
var v = (u[i] << 16) + (u[i + 1] << 8);
a.push(T.charAt(63 & v >> 18));
a.push(T.charAt(63 & v >> 12));
a.push(T.charAt(63 & v >> 6));
a.push('=');
} else if (1 == u.length - i) {
var v = u[i] << 16;
a.push(T.charAt(63 & v >> 18));
a.push(T.charAt(63 & v >> 12));
a.push('==');
}
return a.join('');
};
var R = function () {
var a = [];
for (var i = 0; i < T.length; ++i) {
a[T.charCodeAt(i)] = i;
}
a['='.charCodeAt(0)] = 0;
return a;
}();
var decodeArray = function decodeArray(s) {
var i = 0;
var u = [];
var n = 0 | s.length / 4;
while (0 < n--) {
var v = (R[s.charCodeAt(i)] << 18) + (R[s.charCodeAt(i + 1)] << 12) + (R[s.charCodeAt(i + 2)] << 6) + R[s.charCodeAt(i + 3)];
u.push(255 & v >> 16);
u.push(255 & v >> 8);
u.push(255 & v);
i += 4;
}
if (u) {
if ('=' == s.charAt(i - 2)) {
u.pop();
u.pop();
} else if ('=' == s.charAt(i - 1)) {
u.pop();
}
}
return u;
};
var ASCII = {};
ASCII.encode = function (s) {
var u = [];
for (var i = 0; i < s.length; ++i) {
u.push(s.charCodeAt(i));
}
return u;
};
ASCII.decode = function (u) {
for (var i = 0; i < s.length; ++i) {
a[i] = String.fromCharCode(a[i]);
}
return a.join('');
};
BASE64.decodeArray = function (s) {
var u = decodeArray(s);
return new Uint8Array(u);
};
BASE64.encodeASCII = function (s) {
var u = ASCII.encode(s);
return encodeArray(u);
};
BASE64.decodeASCII = function (s) {
var a = decodeArray(s);
return ASCII.decode(a);
};
BASE64.encode = function (s) {
var u = UTF8.encode(s);
return encodeArray(u);
};
BASE64.decode = function (s) {
var u = decodeArray(s);
return UTF8.decode(u);
};
})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
/*The following polyfills are not used in dash.js but have caused multiplayer integration issues.
Therefore commenting them out.
if (undefined === btoa) {
var btoa = BASE64.encode;
}
if (undefined === atob) {
var atob = BASE64.decode;
}
*/
{
exports.decode = BASE64.decode;
exports.decodeArray = BASE64.decodeArray;
exports.encode = BASE64.encode;
exports.encodeASCII = BASE64.encodeASCII;
}
/***/ }),
/***/ "./externals/cea608-parser.js":
/*!************************************!*\
!*** ./externals/cea608-parser.js ***!
\************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2015-2016, DASH Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* 2. Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
(function (exports) {
/**
* Exceptions from regular ASCII. CodePoints are mapped to UTF-16 codes
*/
var specialCea608CharsCodes = {
0x2a: 0xe1,
// lowercase a, acute accent
0x5c: 0xe9,
// lowercase e, acute accent
0x5e: 0xed,
// lowercase i, acute accent
0x5f: 0xf3,
// lowercase o, acute accent
0x60: 0xfa,
// lowercase u, acute accent
0x7b: 0xe7,
// lowercase c with cedilla
0x7c: 0xf7,
// division symbol
0x7d: 0xd1,
// uppercase N tilde
0x7e: 0xf1,
// lowercase n tilde
0x7f: 0x2588,
// Full block
// THIS BLOCK INCLUDES THE 16 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x11 AND LOW BETWEEN 0x30 AND 0x3F
// THIS MEANS THAT \x50 MUST BE ADDED TO THE VALUES
0x80: 0xae,
// Registered symbol (R)
0x81: 0xb0,
// degree sign
0x82: 0xbd,
// 1/2 symbol
0x83: 0xbf,
// Inverted (open) question mark
0x84: 0x2122,
// Trademark symbol (TM)
0x85: 0xa2,
// Cents symbol
0x86: 0xa3,
// Pounds sterling
0x87: 0x266a,
// Music 8'th note
0x88: 0xe0,
// lowercase a, grave accent
0x89: 0x20,
// transparent space (regular)
0x8a: 0xe8,
// lowercase e, grave accent
0x8b: 0xe2,
// lowercase a, circumflex accent
0x8c: 0xea,
// lowercase e, circumflex accent
0x8d: 0xee,
// lowercase i, circumflex accent
0x8e: 0xf4,
// lowercase o, circumflex accent
0x8f: 0xfb,
// lowercase u, circumflex accent
// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x12 AND LOW BETWEEN 0x20 AND 0x3F
0x90: 0xc1,
// capital letter A with acute
0x91: 0xc9,
// capital letter E with acute
0x92: 0xd3,
// capital letter O with acute
0x93: 0xda,
// capital letter U with acute
0x94: 0xdc,
// capital letter U with diaresis
0x95: 0xfc,
// lowercase letter U with diaeresis
0x96: 0x2018,
// opening single quote
0x97: 0xa1,
// inverted exclamation mark
0x98: 0x2a,
// asterisk
0x99: 0x2019,
// closing single quote
0x9a: 0x2501,
// box drawings heavy horizontal
0x9b: 0xa9,
// copyright sign
0x9c: 0x2120,
// Service mark
0x9d: 0x2022,
// (round) bullet
0x9e: 0x201c,
// Left double quotation mark
0x9f: 0x201d,
// Right double quotation mark
0xa0: 0xc0,
// uppercase A, grave accent
0xa1: 0xc2,
// uppercase A, circumflex
0xa2: 0xc7,
// uppercase C with cedilla
0xa3: 0xc8,
// uppercase E, grave accent
0xa4: 0xca,
// uppercase E, circumflex
0xa5: 0xcb,
// capital letter E with diaresis
0xa6: 0xeb,
// lowercase letter e with diaresis
0xa7: 0xce,
// uppercase I, circumflex
0xa8: 0xcf,
// uppercase I, with diaresis
0xa9: 0xef,
// lowercase i, with diaresis
0xaa: 0xd4,
// uppercase O, circumflex
0xab: 0xd9,
// uppercase U, grave accent
0xac: 0xf9,
// lowercase u, grave accent
0xad: 0xdb,
// uppercase U, circumflex
0xae: 0xab,
// left-pointing double angle quotation mark
0xaf: 0xbb,
// right-pointing double angle quotation mark
// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x13 AND LOW BETWEEN 0x20 AND 0x3F
0xb0: 0xc3,
// Uppercase A, tilde
0xb1: 0xe3,
// Lowercase a, tilde
0xb2: 0xcd,
// Uppercase I, acute accent
0xb3: 0xcc,
// Uppercase I, grave accent
0xb4: 0xec,
// Lowercase i, grave accent
0xb5: 0xd2,
// Uppercase O, grave accent
0xb6: 0xf2,
// Lowercase o, grave accent
0xb7: 0xd5,
// Uppercase O, tilde
0xb8: 0xf5,
// Lowercase o, tilde
0xb9: 0x7b,
// Open curly brace
0xba: 0x7d,
// Closing curly brace
0xbb: 0x5c,
// Backslash
0xbc: 0x5e,
// Caret
0xbd: 0x5f,
// Underscore
0xbe: 0x7c,
// Pipe (vertical line)
0xbf: 0x223c,
// Tilde operator
0xc0: 0xc4,
// Uppercase A, umlaut
0xc1: 0xe4,
// Lowercase A, umlaut
0xc2: 0xd6,
// Uppercase O, umlaut
0xc3: 0xf6,
// Lowercase o, umlaut
0xc4: 0xdf,
// Esszett (sharp S)
0xc5: 0xa5,
// Yen symbol
0xc6: 0xa4,
// Generic currency sign
0xc7: 0x2503,
// Box drawings heavy vertical
0xc8: 0xc5,
// Uppercase A, ring
0xc9: 0xe5,
// Lowercase A, ring
0xca: 0xd8,
// Uppercase O, stroke
0xcb: 0xf8,
// Lowercase o, strok
0xcc: 0x250f,
// Box drawings heavy down and right
0xcd: 0x2513,
// Box drawings heavy down and left
0xce: 0x2517,
// Box drawings heavy up and right
0xcf: 0x251b // Box drawings heavy up and left
};
/**
* Get Unicode Character from CEA-608 byte code
*/
var getCharForByte = function getCharForByte(_byte) {
var charCode = _byte;
if (specialCea608CharsCodes.hasOwnProperty(_byte)) {
charCode = specialCea608CharsCodes[_byte];
}
return String.fromCharCode(charCode);
};
var NR_ROWS = 15,
NR_COLS = 32; // Tables to look up row from PAC data
var rowsLowCh1 = {
0x11: 1,
0x12: 3,
0x15: 5,
0x16: 7,
0x17: 9,
0x10: 11,
0x13: 12,
0x14: 14
};
var rowsHighCh1 = {
0x11: 2,
0x12: 4,
0x15: 6,
0x16: 8,
0x17: 10,
0x13: 13,
0x14: 15
};
var rowsLowCh2 = {
0x19: 1,
0x1A: 3,
0x1D: 5,
0x1E: 7,
0x1F: 9,
0x18: 11,
0x1B: 12,
0x1C: 14
};
var rowsHighCh2 = {
0x19: 2,
0x1A: 4,
0x1D: 6,
0x1E: 8,
0x1F: 10,
0x1B: 13,
0x1C: 15
};
var backgroundColors = ['white', 'green', 'blue', 'cyan', 'red', 'yellow', 'magenta', 'black', 'transparent'];
/**
* Simple logger class to be able to write with time-stamps and filter on level.
*/
var logger = {
verboseFilter: {
'DATA': 3,
'DEBUG': 3,
'INFO': 2,
'WARNING': 2,
'TEXT': 1,
'ERROR': 0
},
time: null,
verboseLevel: 0,
// Only write errors
setTime: function setTime(newTime) {
this.time = newTime;
},
log: function log(severity, msg) {
var minLevel = this.verboseFilter[severity];
if (this.verboseLevel >= minLevel) {
console.log(this.time + " [" + severity + "] " + msg);
}
}
};
var numArrayToHexArray = function numArrayToHexArray(numArray) {
var hexArray = [];
for (var j = 0; j < numArray.length; j++) {
hexArray.push(numArray[j].toString(16));
}
return hexArray;
};
/**
* State of CEA-608 pen or character
* @constructor
*/
var PenState = function PenState(foreground, underline, italics, background, flash) {
this.foreground = foreground || "white";
this.underline = underline || false;
this.italics = italics || false;
this.background = background || "black";
this.flash = flash || false;
};
PenState.prototype = {
reset: function reset() {
this.foreground = "white";
this.underline = false;
this.italics = false;
this.background = "black";
this.flash = false;
},
setStyles: function setStyles(styles) {
var attribs = ["foreground", "underline", "italics", "background", "flash"];
for (var i = 0; i < attribs.length; i++) {
var style = attribs[i];
if (styles.hasOwnProperty(style)) {
this[style] = styles[style];
}
}
},
isDefault: function isDefault() {
return this.foreground === "white" && !this.underline && !this.italics && this.background === "black" && !this.flash;
},
equals: function equals(other) {
return this.foreground === other.foreground && this.underline === other.underline && this.italics === other.italics && this.background === other.background && this.flash === other.flash;
},
copy: function copy(newPenState) {
this.foreground = newPenState.foreground;
this.underline = newPenState.underline;
this.italics = newPenState.italics;
this.background = newPenState.background;
this.flash = newPenState.flash;
},
toString: function toString() {
return "color=" + this.foreground + ", underline=" + this.underline + ", italics=" + this.italics + ", background=" + this.background + ", flash=" + this.flash;
}
};
/**
* Unicode character with styling and background.
* @constructor
*/
var StyledUnicodeChar = function StyledUnicodeChar(uchar, foreground, underline, italics, background, flash) {
this.uchar = uchar || ' '; // unicode character
this.penState = new PenState(foreground, underline, italics, background, flash);
};
StyledUnicodeChar.prototype = {
reset: function reset() {
this.uchar = ' ';
this.penState.reset();
},
setChar: function setChar(uchar, newPenState) {
this.uchar = uchar;
this.penState.copy(newPenState);
},
setPenState: function setPenState(newPenState) {
this.penState.copy(newPenState);
},
equals: function equals(other) {
return this.uchar === other.uchar && this.penState.equals(other.penState);
},
copy: function copy(newChar) {
this.uchar = newChar.uchar;
this.penState.copy(newChar.penState);
},
isEmpty: function isEmpty() {
return this.uchar === ' ' && this.penState.isDefault();
}
};
/**
* CEA-608 row consisting of NR_COLS instances of StyledUnicodeChar.
* @constructor
*/
var Row = function Row() {
this.chars = [];
for (var i = 0; i < NR_COLS; i++) {
this.chars.push(new StyledUnicodeChar());
}
this.pos = 0;
this.currPenState = new PenState();
};
Row.prototype = {
equals: function equals(other) {
var equal = true;
for (var i = 0; i < NR_COLS; i++) {
if (!this.chars[i].equals(other.chars[i])) {
equal = false;
break;
}
}
return equal;
},
copy: function copy(other) {
for (var i = 0; i < NR_COLS; i++) {
this.chars[i].copy(other.chars[i]);
}
},
isEmpty: function isEmpty() {
var empty = true;
for (var i = 0; i < NR_COLS; i++) {
if (!this.chars[i].isEmpty()) {
empty = false;
break;
}
}
return empty;
},
/**
* Set the cursor to a valid column.
*/
setCursor: function setCursor(absPos) {
if (this.pos !== absPos) {
this.pos = absPos;
}
if (this.pos < 0) {
logger.log("ERROR", "Negative cursor position " + this.pos);
this.pos = 0;
} else if (this.pos > NR_COLS) {
logger.log("ERROR", "Too large cursor position " + this.pos);
this.pos = NR_COLS;
}
},
/**
* Move the cursor relative to current position.
*/
moveCursor: function moveCursor(relPos) {
var newPos = this.pos + relPos;
if (relPos > 1) {
for (var i = this.pos + 1; i < newPos + 1; i++) {
this.chars[i].setPenState(this.currPenState);
}
}
this.setCursor(newPos);
},
/**
* Backspace, move one step back and clear character.
*/
backSpace: function backSpace() {
this.moveCursor(-1);
this.chars[this.pos].setChar(' ', this.currPenState);
},
insertChar: function insertChar(_byte2) {
if (_byte2 >= 0x90) {
//Extended char
this.backSpace();
}
var _char = getCharForByte(_byte2);
if (this.pos >= NR_COLS) {
logger.log("ERROR", "Cannot insert " + _byte2.toString(16) + " (" + _char + ") at position " + this.pos + ". Skipping it!");
return;
}
this.chars[this.pos].setChar(_char, this.currPenState);
this.moveCursor(1);
},
clearFromPos: function clearFromPos(startPos) {
var i;
for (i = startPos; i < NR_COLS; i++) {
this.chars[i].reset();
}
},
clear: function clear() {
this.clearFromPos(0);
this.pos = 0;
this.currPenState.reset();
},
clearToEndOfRow: function clearToEndOfRow() {
this.clearFromPos(this.pos);
},
getTextString: function getTextString() {
var chars = [];
var empty = true;
for (var i = 0; i < NR_COLS; i++) {
var _char2 = this.chars[i].uchar;
if (_char2 !== " ") {
empty = false;
}
chars.push(_char2);
}
if (empty) {
return "";
} else {
return chars.join("");
}
},
setPenStyles: function setPenStyles(styles) {
this.currPenState.setStyles(styles);
var currChar = this.chars[this.pos];
currChar.setPenState(this.currPenState);
}
};
/**
* Keep a CEA-608 screen of 32x15 styled characters
* @constructor
*/
var CaptionScreen = function CaptionScreen() {
this.rows = [];
for (var i = 0; i < NR_ROWS; i++) {
this.rows.push(new Row()); // Note that we use zero-based numbering (0-14)
}
this.currRow = NR_ROWS - 1;
this.nrRollUpRows = null;
this.reset();
};
CaptionScreen.prototype = {
reset: function reset() {
for (var i = 0; i < NR_ROWS; i++) {
this.rows[i].clear();
}
this.currRow = NR_ROWS - 1;
},
equals: function equals(other) {
var equal = true;
for (var i = 0; i < NR_ROWS; i++) {
if (!this.rows[i].equals(other.rows[i])) {
equal = false;
break;
}
}
return equal;
},
copy: function copy(other) {
for (var i = 0; i < NR_ROWS; i++) {
this.rows[i].copy(other.rows[i]);
}
},
isEmpty: function isEmpty() {
var empty = true;
for (var i = 0; i < NR_ROWS; i++) {
if (!this.rows[i].isEmpty()) {
empty = false;
break;
}
}
return empty;
},
backSpace: function backSpace() {
var row = this.rows[this.currRow];
row.backSpace();
},
clearToEndOfRow: function clearToEndOfRow() {
var row = this.rows[this.currRow];
row.clearToEndOfRow();
},
/**
* Insert a character (without styling) in the current row.
*/
insertChar: function insertChar(_char3) {
var row = this.rows[this.currRow];
row.insertChar(_char3);
},
setPen: function setPen(styles) {
var row = this.rows[this.currRow];
row.setPenStyles(styles);
},
moveCursor: function moveCursor(relPos) {
var row = this.rows[this.currRow];
row.moveCursor(relPos);
},
setCursor: function setCursor(absPos) {
logger.log("INFO", "setCursor: " + absPos);
var row = this.rows[this.currRow];
row.setCursor(absPos);
},
setPAC: function setPAC(pacData) {
logger.log("INFO", "pacData = " + JSON.stringify(pacData));
var newRow = pacData.row - 1;
if (this.nrRollUpRows && newRow < this.nrRollUpRows - 1) {
newRow = this.nrRollUpRows - 1;
}
this.currRow = newRow;
var row = this.rows[this.currRow];
if (pacData.indent !== null) {
var indent = pacData.indent;
var prevPos = Math.max(indent - 1, 0);
row.setCursor(pacData.indent);
pacData.color = row.chars[prevPos].penState.foreground;
}
var styles = {
foreground: pacData.color,
underline: pacData.underline,
italics: pacData.italics,
background: 'black',
flash: false
};
this.setPen(styles);
},
/**
* Set background/extra foreground, but first do back_space, and then insert space (backwards compatibility).
*/
setBkgData: function setBkgData(bkgData) {
logger.log("INFO", "bkgData = " + JSON.stringify(bkgData));
this.backSpace();
this.setPen(bkgData);
this.insertChar(0x20); //Space
},
setRollUpRows: function setRollUpRows(nrRows) {
this.nrRollUpRows = nrRows;
},
rollUp: function rollUp() {
if (this.nrRollUpRows === null) {
logger.log("DEBUG", "roll_up but nrRollUpRows not set yet");
return; //Not properly setup
}
logger.log("TEXT", this.getDisplayText());
var topRowIndex = this.currRow + 1 - this.nrRollUpRows;
var topRow = this.rows.splice(topRowIndex, 1)[0];
topRow.clear();
this.rows.splice(this.currRow, 0, topRow);
logger.log("INFO", "Rolling up"); //logger.log("TEXT", this.get_display_text())
},
/**
* Get all non-empty rows with as unicode text.
*/
getDisplayText: function getDisplayText(asOneRow) {
asOneRow = asOneRow || false;
var displayText = [];
var text = "";
var rowNr = -1;
for (var i = 0; i < NR_ROWS; i++) {
var rowText = this.rows[i].getTextString();
if (rowText) {
rowNr = i + 1;
if (asOneRow) {
displayText.push("Row " + rowNr + ': "' + rowText + '"');
} else {
displayText.push(rowText.trim());
}
}
}
if (displayText.length > 0) {
if (asOneRow) {
text = "[" + displayText.join(" | ") + "]";
} else {
text = displayText.join("\n");
}
}
return text;
},
getTextAndFormat: function getTextAndFormat() {
return this.rows;
}
};
/**
* Handle a CEA-608 channel and send decoded data to outputFilter
* @constructor
* @param {Number} channelNumber (1 or 2)
* @param {CueHandler} outputFilter Output from channel1 newCue(startTime, endTime, captionScreen)
*/
var Cea608Channel = function Cea608Channel(channelNumber, outputFilter) {
this.chNr = channelNumber;
this.outputFilter = outputFilter;
this.mode = null;
this.verbose = 0;
this.displayedMemory = new CaptionScreen();
this.nonDisplayedMemory = new CaptionScreen();
this.lastOutputScreen = new CaptionScreen();
this.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1];
this.writeScreen = this.displayedMemory;
this.mode = null;
this.cueStartTime = null; // Keeps track of where a cue started.
};
Cea608Channel.prototype = {
modes: ["MODE_ROLL-UP", "MODE_POP-ON", "MODE_PAINT-ON", "MODE_TEXT"],
reset: function reset() {
this.mode = null;
this.displayedMemory.reset();
this.nonDisplayedMemory.reset();
this.lastOutputScreen.reset();
this.currRollUpRow = this.displayedMemory.rows[NR_ROWS - 1];
this.writeScreen = this.displayedMemory;
this.mode = null;
this.cueStartTime = null;
this.lastCueEndTime = null;
},
getHandler: function getHandler() {
return this.outputFilter;
},
setHandler: function setHandler(newHandler) {
this.outputFilter = newHandler;
},
setPAC: function setPAC(pacData) {
this.writeScreen.setPAC(pacData);
},
setBkgData: function setBkgData(bkgData) {
this.writeScreen.setBkgData(bkgData);
},
setMode: function setMode(newMode) {
if (newMode === this.mode) {
return;
}
this.mode = newMode;
logger.log("INFO", "MODE=" + newMode);
if (this.mode == "MODE_POP-ON") {
this.writeScreen = this.nonDisplayedMemory;
} else {
this.writeScreen = this.displayedMemory;
this.writeScreen.reset();
}
if (this.mode !== "MODE_ROLL-UP") {
this.displayedMemory.nrRollUpRows = null;
this.nonDisplayedMemory.nrRollUpRows = null;
}
this.mode = newMode;
},
insertChars: function insertChars(chars) {
for (var i = 0; i < chars.length; i++) {
this.writeScreen.insertChar(chars[i]);
}
var screen = this.writeScreen === this.displayedMemory ? "DISP" : "NON_DISP";
logger.log("INFO", screen + ": " + this.writeScreen.getDisplayText(true));
if (this.mode === "MODE_PAINT-ON" || this.mode === "MODE_ROLL-UP") {
logger.log("TEXT", "DISPLAYED: " + this.displayedMemory.getDisplayText(true));
this.outputDataUpdate();
}
},
cc_RCL: function cc_RCL() {
// Resume Caption Loading (switch mode to Pop On)
logger.log("INFO", "RCL - Resume Caption Loading");
this.setMode("MODE_POP-ON");
},
cc_BS: function cc_BS() {
// BackSpace
logger.log("INFO", "BS - BackSpace");
if (this.mode === "MODE_TEXT") {
return;
}
this.writeScreen.backSpace();
if (this.writeScreen === this.displayedMemory) {
this.outputDataUpdate();
}
},
cc_AOF: function cc_AOF() {
// Reserved (formerly Alarm Off)
return;
},
cc_AON: function cc_AON() {
// Reserved (formerly Alarm On)
return;
},
cc_DER: function cc_DER() {
// Delete to End of Row
logger.log("INFO", "DER- Delete to End of Row");
this.writeScreen.clearToEndOfRow();
this.outputDataUpdate();
},
cc_RU: function cc_RU(nrRows) {
//Roll-Up Captions-2,3,or 4 Rows
logger.log("INFO", "RU(" + nrRows + ") - Roll Up");
this.writeScreen = this.displayedMemory;
this.setMode("MODE_ROLL-UP");
this.writeScreen.setRollUpRows(nrRows);
},
cc_FON: function cc_FON() {
//Flash On
logger.log("INFO", "FON - Flash On");
this.writeScreen.setPen({
flash: true
});
},
cc_RDC: function cc_RDC() {
// Resume Direct Captioning (switch mode to PaintOn)
logger.log("INFO", "RDC - Resume Direct Captioning");
this.setMode("MODE_PAINT-ON");
},
cc_TR: function cc_TR() {
// Text Restart in text mode (not supported, however)
logger.log("INFO", "TR");
this.setMode("MODE_TEXT");
},
cc_RTD: function cc_RTD() {
// Resume Text Display in Text mode (not supported, however)
logger.log("INFO", "RTD");
this.setMode("MODE_TEXT");
},
cc_EDM: function cc_EDM() {
// Erase Displayed Memory
logger.log("INFO", "EDM - Erase Displayed Memory");
this.displayedMemory.reset();
this.outputDataUpdate();
},
cc_CR: function cc_CR() {
// Carriage Return
logger.log("CR - Carriage Return");
this.writeScreen.rollUp();
this.outputDataUpdate();
},
cc_ENM: function cc_ENM() {
//Erase Non-Displayed Memory
logger.log("INFO", "ENM - Erase Non-displayed Memory");
this.nonDisplayedMemory.reset();
},
cc_EOC: function cc_EOC() {
//End of Caption (Flip Memories)
logger.log("INFO", "EOC - End Of Caption");
if (this.mode === "MODE_POP-ON") {
var tmp = this.displayedMemory;
this.displayedMemory = this.nonDisplayedMemory;
this.nonDisplayedMemory = tmp;
this.writeScreen = this.nonDisplayedMemory;
logger.log("TEXT", "DISP: " + this.displayedMemory.getDisplayText());
}
this.outputDataUpdate();
},
cc_TO: function cc_TO(nrCols) {
// Tab Offset 1,2, or 3 columns
logger.log("INFO", "TO(" + nrCols + ") - Tab Offset");
this.writeScreen.moveCursor(nrCols);
},
cc_MIDROW: function cc_MIDROW(secondByte) {
// Parse MIDROW command
var styles = {
flash: false
};
styles.underline = secondByte % 2 === 1;
styles.italics = secondByte >= 0x2e;
if (!styles.italics) {
var colorIndex = Math.floor(secondByte / 2) - 0x10;
var colors = ["white", "green", "blue", "cyan", "red", "yellow", "magenta"];
styles.foreground = colors[colorIndex];
} else {
styles.foreground = "white";
}
logger.log("INFO", "MIDROW: " + JSON.stringify(styles));
this.writeScreen.setPen(styles);
},
outputDataUpdate: function outputDataUpdate() {
var t = logger.time;
if (t === null) {
return;
}
if (this.outputFilter) {
if (this.outputFilter.updateData) {
this.outputFilter.updateData(t, this.displayedMemory);
}
if (this.cueStartTime === null && !this.displayedMemory.isEmpty()) {
// Start of a new cue
this.cueStartTime = t;
} else {
if (!this.displayedMemory.equals(this.lastOutputScreen)) {
if (this.outputFilter.newCue) {
this.outputFilter.newCue(this.cueStartTime, t, this.lastOutputScreen);
}
this.cueStartTime = this.displayedMemory.isEmpty() ? null : t;
}
}
this.lastOutputScreen.copy(this.displayedMemory);
}
},
cueSplitAtTime: function cueSplitAtTime(t) {
if (this.outputFilter) {
if (!this.displayedMemory.isEmpty()) {
if (this.outputFilter.newCue) {
this.outputFilter.newCue(this.cueStartTime, t, this.displayedMemory);
}
this.cueStartTime = t;
}
}
}
};
/**
* Parse CEA-608 data and send decoded data to out1 and out2.
* @constructor
* @param {Number} field CEA-608 field (1 or 2)
* @param {CueHandler} out1 Output from channel1 newCue(startTime, endTime, captionScreen)
* @param {CueHandler} out2 Output from channel2 newCue(startTime, endTime, captionScreen)
*/
var Cea608Parser = function Cea608Parser(field, out1, out2) {
this.field = field || 1;
this.outputs = [out1, out2];
this.channels = [new Cea608Channel(1, out1), new Cea608Channel(2, out2)];
this.currChNr = -1; // Will be 1 or 2
this.lastCmdA = null; // First byte of last command
this.lastCmdB = null; // Second byte of last command
this.bufferedData = [];
this.startTime = null;
this.lastTime = null;
this.dataCounters = {
'padding': 0,
'char': 0,
'cmd': 0,
'other': 0
};
};
Cea608Parser.prototype = {
getHandler: function getHandler(index) {
return this.channels[index].getHandler();
},
setHandler: function setHandler(index, newHandler) {
this.channels[index].setHandler(newHandler);
},
/**
* Add data for time t in forms of list of bytes (unsigned ints). The bytes are treated as pairs.
*/
addData: function addData(t, byteList) {
var cmdFound,
a,
b,
charsFound = false;
this.lastTime = t;
logger.setTime(t);
for (var i = 0; i < byteList.length; i += 2) {
a = byteList[i] & 0x7f;
b = byteList[i + 1] & 0x7f;
if (a >= 0x10 && a <= 0x1f && a === this.lastCmdA && b === this.lastCmdB) {
this.lastCmdA = null;
this.lastCmdB = null;
logger.log("DEBUG", "Repeated command (" + numArrayToHexArray([a, b]) + ") is dropped");
continue; // Repeated commands are dropped (once)
}
if (a === 0 && b === 0) {
this.dataCounters.padding += 2;
continue;
} else {
logger.log("DATA", "[" + numArrayToHexArray([byteList[i], byteList[i + 1]]) + "] -> (" + numArrayToHexArray([a, b]) + ")");
}
cmdFound = this.parseCmd(a, b);
if (!cmdFound) {
cmdFound = this.parseMidrow(a, b);
}
if (!cmdFound) {
cmdFound = this.parsePAC(a, b);
}
if (!cmdFound) {
cmdFound = this.parseBackgroundAttributes(a, b);
}
if (!cmdFound) {
charsFound = this.parseChars(a, b);
if (charsFound) {
if (this.currChNr && this.currChNr >= 0) {
var channel = this.channels[this.currChNr - 1];
channel.insertChars(charsFound);
} else {
logger.log("WARNING", "No channel found yet. TEXT-MODE?");
}
}
}
if (cmdFound) {
this.dataCounters.cmd += 2;
} else if (charsFound) {
this.dataCounters["char"] += 2;
} else {
this.dataCounters.other += 2;
logger.log("WARNING", "Couldn't parse cleaned data " + numArrayToHexArray([a, b]) + " orig: " + numArrayToHexArray([byteList[i], byteList[i + 1]]));
}
}
},
/**
* Parse Command.
* @returns {Boolean} Tells if a command was found
*/
parseCmd: function parseCmd(a, b) {
var chNr = null;
var cond1 = (a === 0x14 || a === 0x15 || a === 0x1C || a === 0x1D) && 0x20 <= b && b <= 0x2F;
var cond2 = (a === 0x17 || a === 0x1F) && 0x21 <= b && b <= 0x23;
if (!(cond1 || cond2)) {
return false;
}
if (a === 0x14 || a === 0x15 || a === 0x17) {
chNr = 1;
} else {
chNr = 2; // (a === 0x1C || a === 0x1D || a=== 0x1f)
}
var channel = this.channels[chNr - 1];
if (a === 0x14 || a === 0x15 || a === 0x1C || a === 0x1D) {
if (b === 0x20) {
channel.cc_RCL();
} else if (b === 0x21) {
channel.cc_BS();
} else if (b === 0x22) {
channel.cc_AOF();
} else if (b === 0x23) {
channel.cc_AON();
} else if (b === 0x24) {
channel.cc_DER();
} else if (b === 0x25) {
channel.cc_RU(2);
} else if (b === 0x26) {
channel.cc_RU(3);
} else if (b === 0x27) {
channel.cc_RU(4);
} else if (b === 0x28) {
channel.cc_FON();
} else if (b === 0x29) {
channel.cc_RDC();
} else if (b === 0x2A) {
channel.cc_TR();
} else if (b === 0x2B) {
channel.cc_RTD();
} else if (b === 0x2C) {
channel.cc_EDM();
} else if (b === 0x2D) {
channel.cc_CR();
} else if (b === 0x2E) {
channel.cc_ENM();
} else if (b === 0x2F) {
channel.cc_EOC();
}
} else {
//a == 0x17 || a == 0x1F
channel.cc_TO(b - 0x20);
}
this.lastCmdA = a;
this.lastCmdB = b;
this.currChNr = chNr;
return true;
},
/**
* Parse midrow styling command
* @returns {Boolean}
*/
parseMidrow: function parseMidrow(a, b) {
var chNr = null;
if ((a === 0x11 || a === 0x19) && 0x20 <= b && b <= 0x2f) {
if (a === 0x11) {
chNr = 1;
} else {
chNr = 2;
}
if (chNr !== this.currChNr) {
logger.log("ERROR", "Mismatch channel in midrow parsing");
return false;
}
var channel = this.channels[chNr - 1]; // cea608 spec says midrow codes should inject a space
channel.insertChars([0x20]);
channel.cc_MIDROW(b);
logger.log("DEBUG", "MIDROW (" + numArrayToHexArray([a, b]) + ")");
this.lastCmdA = a;
this.lastCmdB = b;
return true;
}
return false;
},
/**
* Parse Preable Access Codes (Table 53).
* @returns {Boolean} Tells if PAC found
*/
parsePAC: function parsePAC(a, b) {
var chNr = null;
var row = null;
var case1 = (0x11 <= a && a <= 0x17 || 0x19 <= a && a <= 0x1F) && 0x40 <= b && b <= 0x7F;
var case2 = (a === 0x10 || a === 0x18) && 0x40 <= b && b <= 0x5F;
if (!(case1 || case2)) {
return false;
}
chNr = a <= 0x17 ? 1 : 2;
if (0x40 <= b && b <= 0x5F) {
row = chNr === 1 ? rowsLowCh1[a] : rowsLowCh2[a];
} else {
// 0x60 <= b <= 0x7F
row = chNr === 1 ? rowsHighCh1[a] : rowsHighCh2[a];
}
var pacData = this.interpretPAC(row, b);
var channel = this.channels[chNr - 1];
channel.setPAC(pacData);
this.lastCmdA = a;
this.lastCmdB = b;
this.currChNr = chNr;
return true;
},
/**
* Interpret the second byte of the pac, and return the information.
* @returns {Object} pacData with style parameters.
*/
interpretPAC: function interpretPAC(row, _byte3) {
var pacIndex = _byte3;
var pacData = {
color: null,
italics: false,
indent: null,
underline: false,
row: row
};
if (_byte3 > 0x5F) {
pacIndex = _byte3 - 0x60;
} else {
pacIndex = _byte3 - 0x40;
}
pacData.underline = (pacIndex & 1) === 1;
if (pacIndex <= 0xd) {
pacData.color = ['white', 'green', 'blue', 'cyan', 'red', 'yellow', 'magenta', 'white'][Math.floor(pacIndex / 2)];
} else if (pacIndex <= 0xf) {
pacData.italics = true;
pacData.color = 'white';
} else {
pacData.indent = Math.floor((pacIndex - 0x10) / 2) * 4;
}
return pacData; // Note that row has zero offset. The spec uses 1.
},
/**
* Parse characters.
* @returns An array with 1 to 2 codes corresponding to chars, if found. null otherwise.
*/
parseChars: function parseChars(a, b) {
var channelNr = null,
charCodes = null,
charCode1 = null;
if (a >= 0x19) {
channelNr = 2;
charCode1 = a - 8;
} else {
channelNr = 1;
charCode1 = a;
}
if (0x11 <= charCode1 && charCode1 <= 0x13) {
// Special character
var oneCode = b;
if (charCode1 === 0x11) {
oneCode = b + 0x50;
} else if (charCode1 === 0x12) {
oneCode = b + 0x70;
} else {
oneCode = b + 0x90;
}
logger.log("INFO", "Special char '" + getCharForByte(oneCode) + "' in channel " + channelNr);
charCodes = [oneCode];
this.lastCmdA = a;
this.lastCmdB = b;
} else if (0x20 <= a && a <= 0x7f) {
charCodes = b === 0 ? [a] : [a, b];
this.lastCmdA = null;
this.lastCmdB = null;
}
if (charCodes) {
var hexCodes = numArrayToHexArray(charCodes);
logger.log("DEBUG", "Char codes = " + hexCodes.join(","));
}
return charCodes;
},
/**
* Parse extended background attributes as well as new foreground color black.
* @returns{Boolean} Tells if background attributes are found
*/
parseBackgroundAttributes: function parseBackgroundAttributes(a, b) {
var bkgData, index, chNr, channel;
var case1 = (a === 0x10 || a === 0x18) && 0x20 <= b && b <= 0x2f;
var case2 = (a === 0x17 || a === 0x1f) && 0x2d <= b && b <= 0x2f;
if (!(case1 || case2)) {
return false;
}
bkgData = {};
if (a === 0x10 || a === 0x18) {
index = Math.floor((b - 0x20) / 2);
bkgData.background = backgroundColors[index];
if (b % 2 === 1) {
bkgData.background = bkgData.background + "_semi";
}
} else if (b === 0x2d) {
bkgData.background = "transparent";
} else {
bkgData.foreground = "black";
if (b === 0x2f) {
bkgData.underline = true;
}
}
chNr = a < 0x18 ? 1 : 2;
channel = this.channels[chNr - 1];
channel.setBkgData(bkgData);
this.lastCmdA = a;
this.lastCmdB = b;
return true;
},
/**
* Reset state of parser and its channels.
*/
reset: function reset() {
for (var i = 0; i < this.channels.length; i++) {
if (this.channels[i]) {
this.channels[i].reset();
}
}
this.lastCmdA = null;
this.lastCmdB = null;
},
/**
* Trigger the generation of a cue, and the start of a new one if displayScreens are not empty.
*/
cueSplitAtTime: function cueSplitAtTime(t) {
for (var i = 0; i < this.channels.length; i++) {
if (this.channels[i]) {
this.channels[i].cueSplitAtTime(t);
}
}
}
};
/**
* Find ranges corresponding to SEA CEA-608 NALUS in sizeprepended NALU array.
* @param {raw} dataView of binary data
* @param {startPos} start position in raw
* @param {size} total size of data in raw to consider
* @returns
*/
var findCea608Nalus = function findCea608Nalus(raw, startPos, size) {
var nalSize = 0,
cursor = startPos,
nalType = 0,
cea608NaluRanges = [],
// Check SEI data according to ANSI-SCTE 128
isCEA608SEI = function isCEA608SEI(payloadType, payloadSize, raw, pos) {
if (payloadType !== 4 || payloadSize < 8) {
return null;
}
var countryCode = raw.getUint8(pos);
var providerCode = raw.getUint16(pos + 1);
var userIdentifier = raw.getUint32(pos + 3);
var userDataTypeCode = raw.getUint8(pos + 7);
return countryCode == 0xB5 && providerCode == 0x31 && userIdentifier == 0x47413934 && userDataTypeCode == 0x3;
};
while (cursor < startPos + size) {
nalSize = raw.getUint32(cursor);
nalType = raw.getUint8(cursor + 4) & 0x1F; //console.log(time + " NAL " + nalType);
if (nalType === 6) {
// SEI NAL Unit. The NAL header is the first byte
//console.log("SEI NALU of size " + nalSize + " at time " + time);
var pos = cursor + 5;
var payloadType = -1;
while (pos < cursor + 4 + nalSize - 1) {
// The last byte should be rbsp_trailing_bits
payloadType = 0;
var b = 0xFF;
while (b === 0xFF) {
b = raw.getUint8(pos);
payloadType += b;
pos++;
}
var payloadSize = 0;
b = 0xFF;
while (b === 0xFF) {
b = raw.getUint8(pos);
payloadSize += b;
pos++;
}
if (isCEA608SEI(payloadType, payloadSize, raw, pos)) {
//console.log("CEA608 SEI " + time + " " + payloadSize);
cea608NaluRanges.push([pos, payloadSize]);
}
pos += payloadSize;
}
}
cursor += nalSize + 4;
}
return cea608NaluRanges;
};
var extractCea608DataFromRange = function extractCea608DataFromRange(raw, cea608Range) {
var pos = cea608Range[0];
var fieldData = [[], []];
pos += 8; // Skip the identifier up to userDataTypeCode
var ccCount = raw.getUint8(pos) & 0x1f;
pos += 2; // Advance 1 and skip reserved byte
for (var i = 0; i < ccCount; i++) {
var _byte4 = raw.getUint8(pos);
var ccValid = _byte4 & 0x4;
var ccType = _byte4 & 0x3;
pos++;
var ccData1 = raw.getUint8(pos); // Keep parity bit
pos++;
var ccData2 = raw.getUint8(pos); // Keep parity bit
pos++;
if (ccValid && (ccData1 & 0x7f) + (ccData2 & 0x7f) !== 0) {
//Check validity and non-empty data
if (ccType === 0) {
fieldData[0].push(ccData1);
fieldData[0].push(ccData2);
} else if (ccType === 1) {
fieldData[1].push(ccData1);
fieldData[1].push(ccData2);
}
}
}
return fieldData;
};
exports.logger = logger;
exports.PenState = PenState;
exports.CaptionScreen = CaptionScreen;
exports.Cea608Parser = Cea608Parser;
exports.findCea608Nalus = findCea608Nalus;
exports.extractCea608DataFromRange = extractCea608DataFromRange;
})( exports);
/***/ }),
/***/ "./externals/xml2json.js":
/*!*******************************!*\
!*** ./externals/xml2json.js ***!
\*******************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/*
Copyright 2011-2013 Abdulla Abdurakhmanov
Original sources are available at https://code.google.com/p/x2js/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Further modified for dashjs to:
- keep track of children nodes in order in attribute __children.
- add type conversion matchers
- re-add ignoreRoot
- allow zero-length attributePrefix
- don't add white-space text nodes
- remove explicit RequireJS support
*/
function X2JS(config) {
var VERSION = "1.2.0";
config = config || {};
initConfigDefaults();
function initConfigDefaults() {
if (config.escapeMode === undefined) {
config.escapeMode = true;
}
if (config.attributePrefix === undefined) {
config.attributePrefix = "_";
}
config.arrayAccessForm = config.arrayAccessForm || "none";
config.emptyNodeForm = config.emptyNodeForm || "text";
if (config.enableToStringFunc === undefined) {
config.enableToStringFunc = true;
}
config.arrayAccessFormPaths = config.arrayAccessFormPaths || [];
if (config.skipEmptyTextNodesForObj === undefined) {
config.skipEmptyTextNodesForObj = true;
}
if (config.stripWhitespaces === undefined) {
config.stripWhitespaces = true;
}
config.datetimeAccessFormPaths = config.datetimeAccessFormPaths || [];
if (config.useDoubleQuotes === undefined) {
config.useDoubleQuotes = false;
}
config.xmlElementsFilter = config.xmlElementsFilter || [];
config.jsonPropertiesFilter = config.jsonPropertiesFilter || [];
if (config.keepCData === undefined) {
config.keepCData = false;
}
if (config.ignoreRoot === undefined) {
config.ignoreRoot = false;
}
}
var DOMNodeTypes = {
ELEMENT_NODE: 1,
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9
};
function getNodeLocalName(node) {
var nodeLocalName = node.localName;
if (nodeLocalName == null) // Yeah, this is IE!!
nodeLocalName = node.baseName;
if (nodeLocalName == null || nodeLocalName == "") // =="" is IE too
nodeLocalName = node.nodeName;
return nodeLocalName;
}
function getNodePrefix(node) {
return node.prefix;
}
function escapeXmlChars(str) {
if (typeof str == "string") return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');else return str;
}
function checkInStdFiltersArrayForm(stdFiltersArrayForm, obj, name, path) {
var idx = 0;
for (; idx < stdFiltersArrayForm.length; idx++) {
var filterPath = stdFiltersArrayForm[idx];
if (typeof filterPath === "string") {
if (filterPath == path) break;
} else if (filterPath instanceof RegExp) {
if (filterPath.test(path)) break;
} else if (typeof filterPath === "function") {
if (filterPath(obj, name, path)) break;
}
}
return idx != stdFiltersArrayForm.length;
}
function toArrayAccessForm(obj, childName, path) {
switch (config.arrayAccessForm) {
case "property":
if (!(obj[childName] instanceof Array)) obj[childName + "_asArray"] = [obj[childName]];else obj[childName + "_asArray"] = obj[childName];
break;
/*case "none":
break;*/
}
if (!(obj[childName] instanceof Array) && config.arrayAccessFormPaths.length > 0) {
if (checkInStdFiltersArrayForm(config.arrayAccessFormPaths, obj, childName, path)) {
obj[childName] = [obj[childName]];
}
}
}
function fromXmlDateTime(prop) {
// Implementation based up on http://stackoverflow.com/questions/8178598/xml-datetime-to-javascript-date-object
// Improved to support full spec and optional parts
var bits = prop.split(/[-T:+Z]/g);
var d = new Date(bits[0], bits[1] - 1, bits[2]);
var secondBits = bits[5].split("\.");
d.setHours(bits[3], bits[4], secondBits[0]);
if (secondBits.length > 1) d.setMilliseconds(secondBits[1]); // Get supplied time zone offset in minutes
if (bits[6] && bits[7]) {
var offsetMinutes = bits[6] * 60 + Number(bits[7]);
var sign = /\d\d-\d\d:\d\d$/.test(prop) ? '-' : '+'; // Apply the sign
offsetMinutes = 0 + (sign == '-' ? -1 * offsetMinutes : offsetMinutes); // Apply offset and local timezone
d.setMinutes(d.getMinutes() - offsetMinutes - d.getTimezoneOffset());
} else if (prop.indexOf("Z", prop.length - 1) !== -1) {
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()));
} // d is now a local time equivalent to the supplied time
return d;
}
function checkFromXmlDateTimePaths(value, childName, fullPath) {
if (config.datetimeAccessFormPaths.length > 0) {
var path = fullPath.split("\.#")[0];
if (checkInStdFiltersArrayForm(config.datetimeAccessFormPaths, value, childName, path)) {
return fromXmlDateTime(value);
} else return value;
} else return value;
}
function checkXmlElementsFilter(obj, childType, childName, childPath) {
if (childType == DOMNodeTypes.ELEMENT_NODE && config.xmlElementsFilter.length > 0) {
return checkInStdFiltersArrayForm(config.xmlElementsFilter, obj, childName, childPath);
} else return true;
}
function parseDOMChildren(node, path) {
if (node.nodeType == DOMNodeTypes.DOCUMENT_NODE) {
var result = new Object();
var nodeChildren = node.childNodes; // Alternative for firstElementChild which is not supported in some environments
for (var cidx = 0; cidx < nodeChildren.length; cidx++) {
var child = nodeChildren[cidx];
if (child.nodeType == DOMNodeTypes.ELEMENT_NODE) {
if (config.ignoreRoot) {
result = parseDOMChildren(child);
} else {
result = {};
var childName = getNodeLocalName(child);
result[childName] = parseDOMChildren(child);
}
}
}
return result;
} else if (node.nodeType == DOMNodeTypes.ELEMENT_NODE) {
var result = new Object();
result.__cnt = 0;
var children = [];
var nodeChildren = node.childNodes; // Children nodes
for (var cidx = 0; cidx < nodeChildren.length; cidx++) {
var child = nodeChildren[cidx];
var childName = getNodeLocalName(child);
if (child.nodeType != DOMNodeTypes.COMMENT_NODE) {
var childPath = path + "." + childName;
if (checkXmlElementsFilter(result, child.nodeType, childName, childPath)) {
result.__cnt++;
if (result[childName] == null) {
var c = parseDOMChildren(child, childPath);
if (childName != "#text" || /[^\s]/.test(c)) {
var o = {};
o[childName] = c;
children.push(o);
}
result[childName] = c;
toArrayAccessForm(result, childName, childPath);
} else {
if (result[childName] != null) {
if (!(result[childName] instanceof Array)) {
result[childName] = [result[childName]];
toArrayAccessForm(result, childName, childPath);
}
}
var c = parseDOMChildren(child, childPath);
if (childName != "#text" || /[^\s]/.test(c)) {
// Don't add white-space text nodes
var o = {};
o[childName] = c;
children.push(o);
}
result[childName][result[childName].length] = c;
}
}
}
}
result.__children = children; // Attributes
var nodeLocalName = getNodeLocalName(node);
for (var aidx = 0; aidx < node.attributes.length; aidx++) {
var attr = node.attributes[aidx];
result.__cnt++;
var value2 = attr.value;
for (var m = 0, ml = config.matchers.length; m < ml; m++) {
var matchobj = config.matchers[m];
if (matchobj.test(attr, nodeLocalName)) value2 = matchobj.converter(attr.value);
}
result[config.attributePrefix + attr.name] = value2;
} // Node namespace prefix
var nodePrefix = getNodePrefix(node);
if (nodePrefix != null && nodePrefix != "") {
result.__cnt++;
result.__prefix = nodePrefix;
}
if (result["#text"] != null) {
result.__text = result["#text"];
if (result.__text instanceof Array) {
result.__text = result.__text.join("\n");
} //if(config.escapeMode)
// result.__text = unescapeXmlChars(result.__text);
if (config.stripWhitespaces) result.__text = result.__text.trim();
delete result["#text"];
if (config.arrayAccessForm == "property") delete result["#text_asArray"];
result.__text = checkFromXmlDateTimePaths(result.__text, childName, path + "." + childName);
}
if (result["#cdata-section"] != null) {
result.__cdata = result["#cdata-section"];
delete result["#cdata-section"];
if (config.arrayAccessForm == "property") delete result["#cdata-section_asArray"];
}
if (result.__cnt == 0 && config.emptyNodeForm == "text") {
result = '';
} else if (result.__cnt == 1 && result.__text != null) {
result = result.__text;
} else if (result.__cnt == 1 && result.__cdata != null && !config.keepCData) {
result = result.__cdata;
} else if (result.__cnt > 1 && result.__text != null && config.skipEmptyTextNodesForObj) {
if (config.stripWhitespaces && result.__text == "" || result.__text.trim() == "") {
delete result.__text;
}
}
delete result.__cnt;
if (config.enableToStringFunc && (result.__text != null || result.__cdata != null)) {
result.toString = function () {
return (this.__text != null ? this.__text : '') + (this.__cdata != null ? this.__cdata : '');
};
}
return result;
} else if (node.nodeType == DOMNodeTypes.TEXT_NODE || node.nodeType == DOMNodeTypes.CDATA_SECTION_NODE) {
return node.nodeValue;
}
}
function startTag(jsonObj, element, attrList, closed) {
var resultStr = "<" + (jsonObj != null && jsonObj.__prefix != null ? jsonObj.__prefix + ":" : "") + element;
if (attrList != null) {
for (var aidx = 0; aidx < attrList.length; aidx++) {
var attrName = attrList[aidx];
var attrVal = jsonObj[attrName];
if (config.escapeMode) attrVal = escapeXmlChars(attrVal);
resultStr += " " + attrName.substr(config.attributePrefix.length) + "=";
if (config.useDoubleQuotes) resultStr += '"' + attrVal + '"';else resultStr += "'" + attrVal + "'";
}
}
if (!closed) resultStr += ">";else resultStr += "/>";
return resultStr;
}
function endTag(jsonObj, elementName) {
return "</" + (jsonObj.__prefix != null ? jsonObj.__prefix + ":" : "") + elementName + ">";
}
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function jsonXmlSpecialElem(jsonObj, jsonObjField) {
if (config.arrayAccessForm == "property" && endsWith(jsonObjField.toString(), "_asArray") || jsonObjField.toString().indexOf(config.attributePrefix) == 0 || jsonObjField.toString().indexOf("__") == 0 || jsonObj[jsonObjField] instanceof Function) return true;else return false;
}
function jsonXmlElemCount(jsonObj) {
var elementsCnt = 0;
if (jsonObj instanceof Object) {
for (var it in jsonObj) {
if (jsonXmlSpecialElem(jsonObj, it)) continue;
elementsCnt++;
}
}
return elementsCnt;
}
function checkJsonObjPropertiesFilter(jsonObj, propertyName, jsonObjPath) {
return config.jsonPropertiesFilter.length == 0 || jsonObjPath == "" || checkInStdFiltersArrayForm(config.jsonPropertiesFilter, jsonObj, propertyName, jsonObjPath);
}
function parseJSONAttributes(jsonObj) {
var attrList = [];
if (jsonObj instanceof Object) {
for (var ait in jsonObj) {
if (ait.toString().indexOf("__") == -1 && ait.toString().indexOf(config.attributePrefix) == 0) {
attrList.push(ait);
}
}
}
return attrList;
}
function parseJSONTextAttrs(jsonTxtObj) {
var result = "";
if (jsonTxtObj.__cdata != null) {
result += "<![CDATA[" + jsonTxtObj.__cdata + "]]>";
}
if (jsonTxtObj.__text != null) {
if (config.escapeMode) result += escapeXmlChars(jsonTxtObj.__text);else result += jsonTxtObj.__text;
}
return result;
}
function parseJSONTextObject(jsonTxtObj) {
var result = "";
if (jsonTxtObj instanceof Object) {
result += parseJSONTextAttrs(jsonTxtObj);
} else if (jsonTxtObj != null) {
if (config.escapeMode) result += escapeXmlChars(jsonTxtObj);else result += jsonTxtObj;
}
return result;
}
function getJsonPropertyPath(jsonObjPath, jsonPropName) {
if (jsonObjPath === "") {
return jsonPropName;
} else return jsonObjPath + "." + jsonPropName;
}
function parseJSONArray(jsonArrRoot, jsonArrObj, attrList, jsonObjPath) {
var result = "";
if (jsonArrRoot.length == 0) {
result += startTag(jsonArrRoot, jsonArrObj, attrList, true);
} else {
for (var arIdx = 0; arIdx < jsonArrRoot.length; arIdx++) {
result += startTag(jsonArrRoot[arIdx], jsonArrObj, parseJSONAttributes(jsonArrRoot[arIdx]), false);
result += parseJSONObject(jsonArrRoot[arIdx], getJsonPropertyPath(jsonObjPath, jsonArrObj));
result += endTag(jsonArrRoot[arIdx], jsonArrObj);
}
}
return result;
}
function parseJSONObject(jsonObj, jsonObjPath) {
var result = "";
var elementsCnt = jsonXmlElemCount(jsonObj);
if (elementsCnt > 0) {
for (var it in jsonObj) {
if (jsonXmlSpecialElem(jsonObj, it) || jsonObjPath != "" && !checkJsonObjPropertiesFilter(jsonObj, it, getJsonPropertyPath(jsonObjPath, it))) continue;
var subObj = jsonObj[it];
var attrList = parseJSONAttributes(subObj);
if (subObj == null || subObj == undefined) {
result += startTag(subObj, it, attrList, true);
} else if (subObj instanceof Object) {
if (subObj instanceof Array) {
result += parseJSONArray(subObj, it, attrList, jsonObjPath);
} else if (subObj instanceof Date) {
result += startTag(subObj, it, attrList, false);
result += subObj.toISOString();
result += endTag(subObj, it);
} else {
var subObjElementsCnt = jsonXmlElemCount(subObj);
if (subObjElementsCnt > 0 || subObj.__text != null || subObj.__cdata != null) {
result += startTag(subObj, it, attrList, false);
result += parseJSONObject(subObj, getJsonPropertyPath(jsonObjPath, it));
result += endTag(subObj, it);
} else {
result += startTag(subObj, it, attrList, true);
}
}
} else {
result += startTag(subObj, it, attrList, false);
result += parseJSONTextObject(subObj);
result += endTag(subObj, it);
}
}
}
result += parseJSONTextObject(jsonObj);
return result;
}
this.parseXmlString = function (xmlDocStr) {
var isIEParser = window.ActiveXObject || "ActiveXObject" in window;
if (xmlDocStr === undefined) {
return null;
}
var xmlDoc;
if (window.DOMParser) {
var parser = new window.DOMParser();
try {
xmlDoc = parser.parseFromString(xmlDocStr, "text/xml");
if (xmlDoc.getElementsByTagNameNS("*", "parsererror").length > 0) {
xmlDoc = null;
}
} catch (err) {
xmlDoc = null;
}
} else {
// IE :(
if (xmlDocStr.indexOf("<?") == 0) {
xmlDocStr = xmlDocStr.substr(xmlDocStr.indexOf("?>") + 2);
}
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(xmlDocStr);
}
return xmlDoc;
};
this.asArray = function (prop) {
if (prop === undefined || prop == null) return [];else if (prop instanceof Array) return prop;else return [prop];
};
this.toXmlDateTime = function (dt) {
if (dt instanceof Date) return dt.toISOString();else if (typeof dt === 'number') return new Date(dt).toISOString();else return null;
};
this.asDateTime = function (prop) {
if (typeof prop == "string") {
return fromXmlDateTime(prop);
} else return prop;
};
this.xml2json = function (xmlDoc) {
return parseDOMChildren(xmlDoc);
};
this.xml_str2json = function (xmlDocStr) {
var xmlDoc = this.parseXmlString(xmlDocStr);
if (xmlDoc != null) return this.xml2json(xmlDoc);else return null;
};
this.json2xml_str = function (jsonObj) {
return parseJSONObject(jsonObj, "");
};
this.json2xml = function (jsonObj) {
var xmlDocStr = this.json2xml_str(jsonObj);
return this.parseXmlString(xmlDocStr);
};
this.getVersion = function () {
return VERSION;
};
}
/* harmony default export */ __webpack_exports__["default"] = (X2JS);
/***/ }),
/***/ "./index.js":
/*!******************!*\
!*** ./index.js ***!
\******************/
/*! exports provided: default, MediaPlayer, Protection, MetricsReporting, MediaPlayerFactory, Debug, supportsMediaSource */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _index_mediaplayerOnly__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index_mediaplayerOnly */ "./index_mediaplayerOnly.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MediaPlayer", function() { return _index_mediaplayerOnly__WEBPACK_IMPORTED_MODULE_0__["MediaPlayer"]; });
/* harmony import */ var _src_streaming_utils_Capabilities__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./src/streaming/utils/Capabilities */ "./src/streaming/utils/Capabilities.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "supportsMediaSource", function() { return _src_streaming_utils_Capabilities__WEBPACK_IMPORTED_MODULE_1__["supportsMediaSource"]; });
/* harmony import */ var _src_streaming_metrics_MetricsReporting__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./src/streaming/metrics/MetricsReporting */ "./src/streaming/metrics/MetricsReporting.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MetricsReporting", function() { return _src_streaming_metrics_MetricsReporting__WEBPACK_IMPORTED_MODULE_2__["default"]; });
/* harmony import */ var _src_streaming_protection_Protection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./src/streaming/protection/Protection */ "./src/streaming/protection/Protection.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Protection", function() { return _src_streaming_protection_Protection__WEBPACK_IMPORTED_MODULE_3__["default"]; });
/* harmony import */ var _src_streaming_MediaPlayerFactory__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./src/streaming/MediaPlayerFactory */ "./src/streaming/MediaPlayerFactory.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MediaPlayerFactory", function() { return _src_streaming_MediaPlayerFactory__WEBPACK_IMPORTED_MODULE_4__["default"]; });
/* harmony import */ var _src_core_Debug__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./src/core/Debug */ "./src/core/Debug.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Debug", function() { return _src_core_Debug__WEBPACK_IMPORTED_MODULE_5__["default"]; });
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
dashjs.Protection = _src_streaming_protection_Protection__WEBPACK_IMPORTED_MODULE_3__["default"];
dashjs.MetricsReporting = _src_streaming_metrics_MetricsReporting__WEBPACK_IMPORTED_MODULE_2__["default"];
dashjs.MediaPlayerFactory = _src_streaming_MediaPlayerFactory__WEBPACK_IMPORTED_MODULE_4__["default"];
dashjs.Debug = _src_core_Debug__WEBPACK_IMPORTED_MODULE_5__["default"];
dashjs.supportsMediaSource = _src_streaming_utils_Capabilities__WEBPACK_IMPORTED_MODULE_1__["supportsMediaSource"];
/* harmony default export */ __webpack_exports__["default"] = (dashjs);
/***/ }),
/***/ "./index_mediaplayerOnly.js":
/*!**********************************!*\
!*** ./index_mediaplayerOnly.js ***!
\**********************************/
/*! exports provided: default, MediaPlayer, FactoryMaker, Debug */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _src_streaming_MediaPlayer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/streaming/MediaPlayer */ "./src/streaming/MediaPlayer.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MediaPlayer", function() { return _src_streaming_MediaPlayer__WEBPACK_IMPORTED_MODULE_0__["default"]; });
/* harmony import */ var _src_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./src/core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FactoryMaker", function() { return _src_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"]; });
/* harmony import */ var _src_core_Debug__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./src/core/Debug */ "./src/core/Debug.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Debug", function() { return _src_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"]; });
/* harmony import */ var _src_core_Version__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./src/core/Version */ "./src/core/Version.js");
/* harmony import */ var es6_promise_auto__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! es6-promise/auto */ "./node_modules/es6-promise/auto.js");
/* harmony import */ var es6_promise_auto__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(es6_promise_auto__WEBPACK_IMPORTED_MODULE_4__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// Shove both of these into the global scope
var context = typeof window !== 'undefined' && window || global;
var dashjs = context.dashjs;
if (!dashjs) {
dashjs = context.dashjs = {};
}
dashjs.MediaPlayer = _src_streaming_MediaPlayer__WEBPACK_IMPORTED_MODULE_0__["default"];
dashjs.FactoryMaker = _src_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"];
dashjs.Debug = _src_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"];
dashjs.Version = Object(_src_core_Version__WEBPACK_IMPORTED_MODULE_3__["getVersionString"])();
/* harmony default export */ __webpack_exports__["default"] = (dashjs);
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")));
/***/ }),
/***/ "./node_modules/base64-js/index.js":
/*!*****************************************!*\
!*** ./node_modules/base64-js/index.js ***!
\*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
exports.byteLength = byteLength;
exports.toByteArray = toByteArray;
exports.fromByteArray = fromByteArray;
var lookup = [];
var revLookup = [];
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i];
revLookup[code.charCodeAt(i)] = i;
}
// Support decoding URL-safe base64 strings, as Node.js does.
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
revLookup['-'.charCodeAt(0)] = 62;
revLookup['_'.charCodeAt(0)] = 63;
function getLens (b64) {
var len = b64.length;
if (len % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// Trim off extra bytes after placeholder bytes are found
// See: https://github.com/beatgammit/base64-js/issues/42
var validLen = b64.indexOf('=');
if (validLen === -1) validLen = len;
var placeHoldersLen = validLen === len
? 0
: 4 - (validLen % 4);
return [validLen, placeHoldersLen]
}
// base64 is 4/3 + up to two characters of the original data
function byteLength (b64) {
var lens = getLens(b64);
var validLen = lens[0];
var placeHoldersLen = lens[1];
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}
function _byteLength (b64, validLen, placeHoldersLen) {
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
}
function toByteArray (b64) {
var tmp;
var lens = getLens(b64);
var validLen = lens[0];
var placeHoldersLen = lens[1];
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
var curByte = 0;
// if there are placeholders, only get up to the last complete 4 chars
var len = placeHoldersLen > 0
? validLen - 4
: validLen;
for (var i = 0; i < len; i += 4) {
tmp =
(revLookup[b64.charCodeAt(i)] << 18) |
(revLookup[b64.charCodeAt(i + 1)] << 12) |
(revLookup[b64.charCodeAt(i + 2)] << 6) |
revLookup[b64.charCodeAt(i + 3)];
arr[curByte++] = (tmp >> 16) & 0xFF;
arr[curByte++] = (tmp >> 8) & 0xFF;
arr[curByte++] = tmp & 0xFF;
}
if (placeHoldersLen === 2) {
tmp =
(revLookup[b64.charCodeAt(i)] << 2) |
(revLookup[b64.charCodeAt(i + 1)] >> 4);
arr[curByte++] = tmp & 0xFF;
}
if (placeHoldersLen === 1) {
tmp =
(revLookup[b64.charCodeAt(i)] << 10) |
(revLookup[b64.charCodeAt(i + 1)] << 4) |
(revLookup[b64.charCodeAt(i + 2)] >> 2);
arr[curByte++] = (tmp >> 8) & 0xFF;
arr[curByte++] = tmp & 0xFF;
}
return arr
}
function tripletToBase64 (num) {
return lookup[num >> 18 & 0x3F] +
lookup[num >> 12 & 0x3F] +
lookup[num >> 6 & 0x3F] +
lookup[num & 0x3F]
}
function encodeChunk (uint8, start, end) {
var tmp;
var output = [];
for (var i = start; i < end; i += 3) {
tmp =
((uint8[i] << 16) & 0xFF0000) +
((uint8[i + 1] << 8) & 0xFF00) +
(uint8[i + 2] & 0xFF);
output.push(tripletToBase64(tmp));
}
return output.join('')
}
function fromByteArray (uint8) {
var tmp;
var len = uint8.length;
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
var parts = [];
var maxChunkLength = 16383; // must be multiple of 3
// go through the array every three bytes, we'll deal with trailing stuff later
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
parts.push(encodeChunk(
uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
));
}
// pad the end with zeros, but make sure to not forget the extra bytes
if (extraBytes === 1) {
tmp = uint8[len - 1];
parts.push(
lookup[tmp >> 2] +
lookup[(tmp << 4) & 0x3F] +
'=='
);
} else if (extraBytes === 2) {
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
parts.push(
lookup[tmp >> 10] +
lookup[(tmp >> 4) & 0x3F] +
lookup[(tmp << 2) & 0x3F] +
'='
);
}
return parts.join('')
}
/***/ }),
/***/ "./node_modules/codem-isoboxer/dist/iso_boxer.js":
/*!*******************************************************!*\
!*** ./node_modules/codem-isoboxer/dist/iso_boxer.js ***!
\*******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*! codem-isoboxer v0.3.6 https://github.com/madebyhiro/codem-isoboxer/blob/master/LICENSE.txt */
var ISOBoxer = {};
ISOBoxer.parseBuffer = function(arrayBuffer) {
return new ISOFile(arrayBuffer).parse();
};
ISOBoxer.addBoxProcessor = function(type, parser) {
if (typeof type !== 'string' || typeof parser !== 'function') {
return;
}
ISOBox.prototype._boxProcessors[type] = parser;
};
ISOBoxer.createFile = function() {
return new ISOFile();
};
// See ISOBoxer.append() for 'pos' parameter syntax
ISOBoxer.createBox = function(type, parent, pos) {
var newBox = ISOBox.create(type);
if (parent) {
parent.append(newBox, pos);
}
return newBox;
};
// See ISOBoxer.append() for 'pos' parameter syntax
ISOBoxer.createFullBox = function(type, parent, pos) {
var newBox = ISOBoxer.createBox(type, parent, pos);
newBox.version = 0;
newBox.flags = 0;
return newBox;
};
ISOBoxer.Utils = {};
ISOBoxer.Utils.dataViewToString = function(dataView, encoding) {
var impliedEncoding = encoding || 'utf-8';
if (typeof TextDecoder !== 'undefined') {
return new TextDecoder(impliedEncoding).decode(dataView);
}
var a = [];
var i = 0;
if (impliedEncoding === 'utf-8') {
/* The following algorithm is essentially a rewrite of the UTF8.decode at
http://bannister.us/weblog/2007/simple-base64-encodedecode-javascript/
*/
while (i < dataView.byteLength) {
var c = dataView.getUint8(i++);
if (c < 0x80) ; else if (c < 0xe0) {
// 2-byte character (11 bits)
c = (c & 0x1f) << 6;
c |= (dataView.getUint8(i++) & 0x3f);
} else if (c < 0xf0) {
// 3-byte character (16 bits)
c = (c & 0xf) << 12;
c |= (dataView.getUint8(i++) & 0x3f) << 6;
c |= (dataView.getUint8(i++) & 0x3f);
} else {
// 4-byte character (21 bits)
c = (c & 0x7) << 18;
c |= (dataView.getUint8(i++) & 0x3f) << 12;
c |= (dataView.getUint8(i++) & 0x3f) << 6;
c |= (dataView.getUint8(i++) & 0x3f);
}
a.push(String.fromCharCode(c));
}
} else { // Just map byte-by-byte (probably wrong)
while (i < dataView.byteLength) {
a.push(String.fromCharCode(dataView.getUint8(i++)));
}
}
return a.join('');
};
ISOBoxer.Utils.utf8ToByteArray = function(string) {
// Only UTF-8 encoding is supported by TextEncoder
var u, i;
if (typeof TextEncoder !== 'undefined') {
u = new TextEncoder().encode(string);
} else {
u = [];
for (i = 0; i < string.length; ++i) {
var c = string.charCodeAt(i);
if (c < 0x80) {
u.push(c);
} else if (c < 0x800) {
u.push(0xC0 | (c >> 6));
u.push(0x80 | (63 & c));
} else if (c < 0x10000) {
u.push(0xE0 | (c >> 12));
u.push(0x80 | (63 & (c >> 6)));
u.push(0x80 | (63 & c));
} else {
u.push(0xF0 | (c >> 18));
u.push(0x80 | (63 & (c >> 12)));
u.push(0x80 | (63 & (c >> 6)));
u.push(0x80 | (63 & c));
}
}
}
return u;
};
// Method to append a box in the list of child boxes
// The 'pos' parameter can be either:
// - (number) a position index at which to insert the new box
// - (string) the type of the box after which to insert the new box
// - (object) the box after which to insert the new box
ISOBoxer.Utils.appendBox = function(parent, box, pos) {
box._offset = parent._cursor.offset;
box._root = (parent._root ? parent._root : parent);
box._raw = parent._raw;
box._parent = parent;
if (pos === -1) {
// The new box is a sub-box of the parent but not added in boxes array,
// for example when the new box is set as an entry (see dref and stsd for example)
return;
}
if (pos === undefined || pos === null) {
parent.boxes.push(box);
return;
}
var index = -1,
type;
if (typeof pos === "number") {
index = pos;
} else {
if (typeof pos === "string") {
type = pos;
} else if (typeof pos === "object" && pos.type) {
type = pos.type;
} else {
parent.boxes.push(box);
return;
}
for (var i = 0; i < parent.boxes.length; i++) {
if (type === parent.boxes[i].type) {
index = i + 1;
break;
}
}
}
parent.boxes.splice(index, 0, box);
};
{
exports.parseBuffer = ISOBoxer.parseBuffer;
exports.addBoxProcessor = ISOBoxer.addBoxProcessor;
exports.createFile = ISOBoxer.createFile;
exports.createBox = ISOBoxer.createBox;
exports.createFullBox = ISOBoxer.createFullBox;
exports.Utils = ISOBoxer.Utils;
}
ISOBoxer.Cursor = function(initialOffset) {
this.offset = (typeof initialOffset == 'undefined' ? 0 : initialOffset);
};
var ISOFile = function(arrayBuffer) {
this._cursor = new ISOBoxer.Cursor();
this.boxes = [];
if (arrayBuffer) {
this._raw = new DataView(arrayBuffer);
}
};
ISOFile.prototype.fetch = function(type) {
var result = this.fetchAll(type, true);
return (result.length ? result[0] : null);
};
ISOFile.prototype.fetchAll = function(type, returnEarly) {
var result = [];
ISOFile._sweep.call(this, type, result, returnEarly);
return result;
};
ISOFile.prototype.parse = function() {
this._cursor.offset = 0;
this.boxes = [];
while (this._cursor.offset < this._raw.byteLength) {
var box = ISOBox.parse(this);
// Box could not be parsed
if (typeof box.type === 'undefined') break;
this.boxes.push(box);
}
return this;
};
ISOFile._sweep = function(type, result, returnEarly) {
if (this.type && this.type == type) result.push(this);
for (var box in this.boxes) {
if (result.length && returnEarly) return;
ISOFile._sweep.call(this.boxes[box], type, result, returnEarly);
}
};
ISOFile.prototype.write = function() {
var length = 0,
i;
for (i = 0; i < this.boxes.length; i++) {
length += this.boxes[i].getLength(false);
}
var bytes = new Uint8Array(length);
this._rawo = new DataView(bytes.buffer);
this.bytes = bytes;
this._cursor.offset = 0;
for (i = 0; i < this.boxes.length; i++) {
this.boxes[i].write();
}
return bytes.buffer;
};
ISOFile.prototype.append = function(box, pos) {
ISOBoxer.Utils.appendBox(this, box, pos);
};
var ISOBox = function() {
this._cursor = new ISOBoxer.Cursor();
};
ISOBox.parse = function(parent) {
var newBox = new ISOBox();
newBox._offset = parent._cursor.offset;
newBox._root = (parent._root ? parent._root : parent);
newBox._raw = parent._raw;
newBox._parent = parent;
newBox._parseBox();
parent._cursor.offset = newBox._raw.byteOffset + newBox._raw.byteLength;
return newBox;
};
ISOBox.create = function(type) {
var newBox = new ISOBox();
newBox.type = type;
newBox.boxes = [];
return newBox;
};
ISOBox.prototype._boxContainers = ['dinf', 'edts', 'mdia', 'meco', 'mfra', 'minf', 'moof', 'moov', 'mvex', 'stbl', 'strk', 'traf', 'trak', 'tref', 'udta', 'vttc', 'sinf', 'schi', 'encv', 'enca'];
ISOBox.prototype._boxProcessors = {};
///////////////////////////////////////////////////////////////////////////////////////////////////
// Generic read/write functions
ISOBox.prototype._procField = function (name, type, size) {
if (this._parsing) {
this[name] = this._readField(type, size);
}
else {
this._writeField(type, size, this[name]);
}
};
ISOBox.prototype._procFieldArray = function (name, length, type, size) {
var i;
if (this._parsing) {
this[name] = [];
for (i = 0; i < length; i++) {
this[name][i] = this._readField(type, size);
}
}
else {
for (i = 0; i < this[name].length; i++) {
this._writeField(type, size, this[name][i]);
}
}
};
ISOBox.prototype._procFullBox = function() {
this._procField('version', 'uint', 8);
this._procField('flags', 'uint', 24);
};
ISOBox.prototype._procEntries = function(name, length, fn) {
var i;
if (this._parsing) {
this[name] = [];
for (i = 0; i < length; i++) {
this[name].push({});
fn.call(this, this[name][i]);
}
}
else {
for (i = 0; i < length; i++) {
fn.call(this, this[name][i]);
}
}
};
ISOBox.prototype._procSubEntries = function(entry, name, length, fn) {
var i;
if (this._parsing) {
entry[name] = [];
for (i = 0; i < length; i++) {
entry[name].push({});
fn.call(this, entry[name][i]);
}
}
else {
for (i = 0; i < length; i++) {
fn.call(this, entry[name][i]);
}
}
};
ISOBox.prototype._procEntryField = function (entry, name, type, size) {
if (this._parsing) {
entry[name] = this._readField(type, size);
}
else {
this._writeField(type, size, entry[name]);
}
};
ISOBox.prototype._procSubBoxes = function(name, length) {
var i;
if (this._parsing) {
this[name] = [];
for (i = 0; i < length; i++) {
this[name].push(ISOBox.parse(this));
}
}
else {
for (i = 0; i < length; i++) {
if (this._rawo) {
this[name][i].write();
} else {
this.size += this[name][i].getLength();
}
}
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// Read/parse functions
ISOBox.prototype._readField = function(type, size) {
switch (type) {
case 'uint':
return this._readUint(size);
case 'int':
return this._readInt(size);
case 'template':
return this._readTemplate(size);
case 'string':
return (size === -1) ? this._readTerminatedString() : this._readString(size);
case 'data':
return this._readData(size);
case 'utf8':
return this._readUTF8String();
default:
return -1;
}
};
ISOBox.prototype._readInt = function(size) {
var result = null,
offset = this._cursor.offset - this._raw.byteOffset;
switch(size) {
case 8:
result = this._raw.getInt8(offset);
break;
case 16:
result = this._raw.getInt16(offset);
break;
case 32:
result = this._raw.getInt32(offset);
break;
case 64:
// Warning: JavaScript cannot handle 64-bit integers natively.
// This will give unexpected results for integers >= 2^53
var s1 = this._raw.getInt32(offset);
var s2 = this._raw.getInt32(offset + 4);
result = (s1 * Math.pow(2,32)) + s2;
break;
}
this._cursor.offset += (size >> 3);
return result;
};
ISOBox.prototype._readUint = function(size) {
var result = null,
offset = this._cursor.offset - this._raw.byteOffset,
s1, s2;
switch(size) {
case 8:
result = this._raw.getUint8(offset);
break;
case 16:
result = this._raw.getUint16(offset);
break;
case 24:
s1 = this._raw.getUint16(offset);
s2 = this._raw.getUint8(offset + 2);
result = (s1 << 8) + s2;
break;
case 32:
result = this._raw.getUint32(offset);
break;
case 64:
// Warning: JavaScript cannot handle 64-bit integers natively.
// This will give unexpected results for integers >= 2^53
s1 = this._raw.getUint32(offset);
s2 = this._raw.getUint32(offset + 4);
result = (s1 * Math.pow(2,32)) + s2;
break;
}
this._cursor.offset += (size >> 3);
return result;
};
ISOBox.prototype._readString = function(length) {
var str = '';
for (var c = 0; c < length; c++) {
var char = this._readUint(8);
str += String.fromCharCode(char);
}
return str;
};
ISOBox.prototype._readTemplate = function(size) {
var pre = this._readUint(size / 2);
var post = this._readUint(size / 2);
return pre + (post / Math.pow(2, size / 2));
};
ISOBox.prototype._readTerminatedString = function() {
var str = '';
while (this._cursor.offset - this._offset < this._raw.byteLength) {
var char = this._readUint(8);
if (char === 0) break;
str += String.fromCharCode(char);
}
return str;
};
ISOBox.prototype._readData = function(size) {
var length = (size > 0) ? size : (this._raw.byteLength - (this._cursor.offset - this._offset));
if (length > 0) {
var data = new Uint8Array(this._raw.buffer, this._cursor.offset, length);
this._cursor.offset += length;
return data;
}
else {
return null;
}
};
ISOBox.prototype._readUTF8String = function() {
var length = this._raw.byteLength - (this._cursor.offset - this._offset);
var data = null;
if (length > 0) {
data = new DataView(this._raw.buffer, this._cursor.offset, length);
this._cursor.offset += length;
}
return data ? ISOBoxer.Utils.dataViewToString(data) : data;
};
ISOBox.prototype._parseBox = function() {
this._parsing = true;
this._cursor.offset = this._offset;
// return immediately if there are not enough bytes to read the header
if (this._offset + 8 > this._raw.buffer.byteLength) {
this._root._incomplete = true;
return;
}
this._procField('size', 'uint', 32);
this._procField('type', 'string', 4);
if (this.size === 1) { this._procField('largesize', 'uint', 64); }
if (this.type === 'uuid') { this._procFieldArray('usertype', 16, 'uint', 8); }
switch(this.size) {
case 0:
this._raw = new DataView(this._raw.buffer, this._offset, (this._raw.byteLength - this._cursor.offset + 8));
break;
case 1:
if (this._offset + this.size > this._raw.buffer.byteLength) {
this._incomplete = true;
this._root._incomplete = true;
} else {
this._raw = new DataView(this._raw.buffer, this._offset, this.largesize);
}
break;
default:
if (this._offset + this.size > this._raw.buffer.byteLength) {
this._incomplete = true;
this._root._incomplete = true;
} else {
this._raw = new DataView(this._raw.buffer, this._offset, this.size);
}
}
// additional parsing
if (!this._incomplete) {
if (this._boxProcessors[this.type]) {
this._boxProcessors[this.type].call(this);
}
if (this._boxContainers.indexOf(this.type) !== -1) {
this._parseContainerBox();
} else{
// Unknown box => read and store box content
this._data = this._readData();
}
}
};
ISOBox.prototype._parseFullBox = function() {
this.version = this._readUint(8);
this.flags = this._readUint(24);
};
ISOBox.prototype._parseContainerBox = function() {
this.boxes = [];
while (this._cursor.offset - this._raw.byteOffset < this._raw.byteLength) {
this.boxes.push(ISOBox.parse(this));
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// Write functions
ISOBox.prototype.append = function(box, pos) {
ISOBoxer.Utils.appendBox(this, box, pos);
};
ISOBox.prototype.getLength = function() {
this._parsing = false;
this._rawo = null;
this.size = 0;
this._procField('size', 'uint', 32);
this._procField('type', 'string', 4);
if (this.size === 1) { this._procField('largesize', 'uint', 64); }
if (this.type === 'uuid') { this._procFieldArray('usertype', 16, 'uint', 8); }
if (this._boxProcessors[this.type]) {
this._boxProcessors[this.type].call(this);
}
if (this._boxContainers.indexOf(this.type) !== -1) {
for (var i = 0; i < this.boxes.length; i++) {
this.size += this.boxes[i].getLength();
}
}
if (this._data) {
this._writeData(this._data);
}
return this.size;
};
ISOBox.prototype.write = function() {
this._parsing = false;
this._cursor.offset = this._parent._cursor.offset;
switch(this.size) {
case 0:
this._rawo = new DataView(this._parent._rawo.buffer, this._cursor.offset, (this.parent._rawo.byteLength - this._cursor.offset));
break;
case 1:
this._rawo = new DataView(this._parent._rawo.buffer, this._cursor.offset, this.largesize);
break;
default:
this._rawo = new DataView(this._parent._rawo.buffer, this._cursor.offset, this.size);
}
this._procField('size', 'uint', 32);
this._procField('type', 'string', 4);
if (this.size === 1) { this._procField('largesize', 'uint', 64); }
if (this.type === 'uuid') { this._procFieldArray('usertype', 16, 'uint', 8); }
if (this._boxProcessors[this.type]) {
this._boxProcessors[this.type].call(this);
}
if (this._boxContainers.indexOf(this.type) !== -1) {
for (var i = 0; i < this.boxes.length; i++) {
this.boxes[i].write();
}
}
if (this._data) {
this._writeData(this._data);
}
this._parent._cursor.offset += this.size;
return this.size;
};
ISOBox.prototype._writeInt = function(size, value) {
if (this._rawo) {
var offset = this._cursor.offset - this._rawo.byteOffset;
switch(size) {
case 8:
this._rawo.setInt8(offset, value);
break;
case 16:
this._rawo.setInt16(offset, value);
break;
case 32:
this._rawo.setInt32(offset, value);
break;
case 64:
// Warning: JavaScript cannot handle 64-bit integers natively.
// This will give unexpected results for integers >= 2^53
var s1 = Math.floor(value / Math.pow(2,32));
var s2 = value - (s1 * Math.pow(2,32));
this._rawo.setUint32(offset, s1);
this._rawo.setUint32(offset + 4, s2);
break;
}
this._cursor.offset += (size >> 3);
} else {
this.size += (size >> 3);
}
};
ISOBox.prototype._writeUint = function(size, value) {
if (this._rawo) {
var offset = this._cursor.offset - this._rawo.byteOffset,
s1, s2;
switch(size) {
case 8:
this._rawo.setUint8(offset, value);
break;
case 16:
this._rawo.setUint16(offset, value);
break;
case 24:
s1 = (value & 0xFFFF00) >> 8;
s2 = (value & 0x0000FF);
this._rawo.setUint16(offset, s1);
this._rawo.setUint8(offset + 2, s2);
break;
case 32:
this._rawo.setUint32(offset, value);
break;
case 64:
// Warning: JavaScript cannot handle 64-bit integers natively.
// This will give unexpected results for integers >= 2^53
s1 = Math.floor(value / Math.pow(2,32));
s2 = value - (s1 * Math.pow(2,32));
this._rawo.setUint32(offset, s1);
this._rawo.setUint32(offset + 4, s2);
break;
}
this._cursor.offset += (size >> 3);
} else {
this.size += (size >> 3);
}
};
ISOBox.prototype._writeString = function(size, str) {
for (var c = 0; c < size; c++) {
this._writeUint(8, str.charCodeAt(c));
}
};
ISOBox.prototype._writeTerminatedString = function(str) {
if (str.length === 0) {
return;
}
for (var c = 0; c < str.length; c++) {
this._writeUint(8, str.charCodeAt(c));
}
this._writeUint(8, 0);
};
ISOBox.prototype._writeTemplate = function(size, value) {
var pre = Math.floor(value);
var post = (value - pre) * Math.pow(2, size / 2);
this._writeUint(size / 2, pre);
this._writeUint(size / 2, post);
};
ISOBox.prototype._writeData = function(data) {
var i;
//data to copy
if (data) {
if (this._rawo) {
//Array and Uint8Array has also to be managed
if (data instanceof Array) {
var offset = this._cursor.offset - this._rawo.byteOffset;
for (var i = 0; i < data.length; i++) {
this._rawo.setInt8(offset + i, data[i]);
}
this._cursor.offset += data.length;
}
if (data instanceof Uint8Array) {
this._root.bytes.set(data, this._cursor.offset);
this._cursor.offset += data.length;
}
} else {
//nothing to copy only size to compute
this.size += data.length;
}
}
};
ISOBox.prototype._writeUTF8String = function(string) {
var u = ISOBoxer.Utils.utf8ToByteArray(string);
if (this._rawo) {
var dataView = new DataView(this._rawo.buffer, this._cursor.offset, u.length);
for (var i = 0; i < u.length; i++) {
dataView.setUint8(i, u[i]);
}
} else {
this.size += u.length;
}
};
ISOBox.prototype._writeField = function(type, size, value) {
switch (type) {
case 'uint':
this._writeUint(size, value);
break;
case 'int':
this._writeInt(size, value);
break;
case 'template':
this._writeTemplate(size, value);
break;
case 'string':
if (size == -1) {
this._writeTerminatedString(value);
} else {
this._writeString(size, value);
}
break;
case 'data':
this._writeData(value);
break;
case 'utf8':
this._writeUTF8String(value);
break;
default:
break;
}
};
// ISO/IEC 14496-15:2014 - avc1 box
ISOBox.prototype._boxProcessors['avc1'] = ISOBox.prototype._boxProcessors['encv'] = function() {
// SampleEntry fields
this._procFieldArray('reserved1', 6, 'uint', 8);
this._procField('data_reference_index', 'uint', 16);
// VisualSampleEntry fields
this._procField('pre_defined1', 'uint', 16);
this._procField('reserved2', 'uint', 16);
this._procFieldArray('pre_defined2', 3, 'uint', 32);
this._procField('width', 'uint', 16);
this._procField('height', 'uint', 16);
this._procField('horizresolution', 'template', 32);
this._procField('vertresolution', 'template', 32);
this._procField('reserved3', 'uint', 32);
this._procField('frame_count', 'uint', 16);
this._procFieldArray('compressorname', 32,'uint', 8);
this._procField('depth', 'uint', 16);
this._procField('pre_defined3', 'int', 16);
// AVCSampleEntry fields
this._procField('config', 'data', -1);
};
// ISO/IEC 14496-12:2012 - 8.7.2 Data Reference Box
ISOBox.prototype._boxProcessors['dref'] = function() {
this._procFullBox();
this._procField('entry_count', 'uint', 32);
this._procSubBoxes('entries', this.entry_count);
};
// ISO/IEC 14496-12:2012 - 8.6.6 Edit List Box
ISOBox.prototype._boxProcessors['elst'] = function() {
this._procFullBox();
this._procField('entry_count', 'uint', 32);
this._procEntries('entries', this.entry_count, function(entry) {
this._procEntryField(entry, 'segment_duration', 'uint', (this.version === 1) ? 64 : 32);
this._procEntryField(entry, 'media_time', 'int', (this.version === 1) ? 64 : 32);
this._procEntryField(entry, 'media_rate_integer', 'int', 16);
this._procEntryField(entry, 'media_rate_fraction', 'int', 16);
});
};
// ISO/IEC 23009-1:2014 - 5.10.3.3 Event Message Box
ISOBox.prototype._boxProcessors['emsg'] = function() {
this._procFullBox();
if (this.version == 1) {
this._procField('timescale', 'uint', 32);
this._procField('presentation_time', 'uint', 64);
this._procField('event_duration', 'uint', 32);
this._procField('id', 'uint', 32);
this._procField('scheme_id_uri', 'string', -1);
this._procField('value', 'string', -1);
} else {
this._procField('scheme_id_uri', 'string', -1);
this._procField('value', 'string', -1);
this._procField('timescale', 'uint', 32);
this._procField('presentation_time_delta', 'uint', 32);
this._procField('event_duration', 'uint', 32);
this._procField('id', 'uint', 32);
}
this._procField('message_data', 'data', -1);
};
// ISO/IEC 14496-12:2012 - 8.1.2 Free Space Box
ISOBox.prototype._boxProcessors['free'] = ISOBox.prototype._boxProcessors['skip'] = function() {
this._procField('data', 'data', -1);
};
// ISO/IEC 14496-12:2012 - 8.12.2 Original Format Box
ISOBox.prototype._boxProcessors['frma'] = function() {
this._procField('data_format', 'uint', 32);
};
// ISO/IEC 14496-12:2012 - 4.3 File Type Box / 8.16.2 Segment Type Box
ISOBox.prototype._boxProcessors['ftyp'] =
ISOBox.prototype._boxProcessors['styp'] = function() {
this._procField('major_brand', 'string', 4);
this._procField('minor_version', 'uint', 32);
var nbCompatibleBrands = -1;
if (this._parsing) {
nbCompatibleBrands = (this._raw.byteLength - (this._cursor.offset - this._raw.byteOffset)) / 4;
}
this._procFieldArray('compatible_brands', nbCompatibleBrands, 'string', 4);
};
// ISO/IEC 14496-12:2012 - 8.4.3 Handler Reference Box
ISOBox.prototype._boxProcessors['hdlr'] = function() {
this._procFullBox();
this._procField('pre_defined', 'uint', 32);
this._procField('handler_type', 'string', 4);
this._procFieldArray('reserved', 3, 'uint', 32);
this._procField('name', 'string', -1);
};
// ISO/IEC 14496-12:2012 - 8.1.1 Media Data Box
ISOBox.prototype._boxProcessors['mdat'] = function() {
this._procField('data', 'data', -1);
};
// ISO/IEC 14496-12:2012 - 8.4.2 Media Header Box
ISOBox.prototype._boxProcessors['mdhd'] = function() {
this._procFullBox();
this._procField('creation_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('modification_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('timescale', 'uint', 32);
this._procField('duration', 'uint', (this.version == 1) ? 64 : 32);
if (!this._parsing && typeof this.language === 'string') {
// In case of writing and language has been set as a string, then convert it into char codes array
this.language = ((this.language.charCodeAt(0) - 0x60) << 10) |
((this.language.charCodeAt(1) - 0x60) << 5) |
((this.language.charCodeAt(2) - 0x60));
}
this._procField('language', 'uint', 16);
if (this._parsing) {
this.language = String.fromCharCode(((this.language >> 10) & 0x1F) + 0x60,
((this.language >> 5) & 0x1F) + 0x60,
(this.language & 0x1F) + 0x60);
}
this._procField('pre_defined', 'uint', 16);
};
// ISO/IEC 14496-12:2012 - 8.8.2 Movie Extends Header Box
ISOBox.prototype._boxProcessors['mehd'] = function() {
this._procFullBox();
this._procField('fragment_duration', 'uint', (this.version == 1) ? 64 : 32);
};
// ISO/IEC 14496-12:2012 - 8.8.5 Movie Fragment Header Box
ISOBox.prototype._boxProcessors['mfhd'] = function() {
this._procFullBox();
this._procField('sequence_number', 'uint', 32);
};
// ISO/IEC 14496-12:2012 - 8.8.11 Movie Fragment Random Access Box
ISOBox.prototype._boxProcessors['mfro'] = function() {
this._procFullBox();
this._procField('mfra_size', 'uint', 32); // Called mfra_size to distinguish from the normal "size" attribute of a box
};
// ISO/IEC 14496-12:2012 - 8.5.2.2 mp4a box (use AudioSampleEntry definition and naming)
ISOBox.prototype._boxProcessors['mp4a'] = ISOBox.prototype._boxProcessors['enca'] = function() {
// SampleEntry fields
this._procFieldArray('reserved1', 6, 'uint', 8);
this._procField('data_reference_index', 'uint', 16);
// AudioSampleEntry fields
this._procFieldArray('reserved2', 2, 'uint', 32);
this._procField('channelcount', 'uint', 16);
this._procField('samplesize', 'uint', 16);
this._procField('pre_defined', 'uint', 16);
this._procField('reserved3', 'uint', 16);
this._procField('samplerate', 'template', 32);
// ESDescriptor fields
this._procField('esds', 'data', -1);
};
// ISO/IEC 14496-12:2012 - 8.2.2 Movie Header Box
ISOBox.prototype._boxProcessors['mvhd'] = function() {
this._procFullBox();
this._procField('creation_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('modification_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('timescale', 'uint', 32);
this._procField('duration', 'uint', (this.version == 1) ? 64 : 32);
this._procField('rate', 'template', 32);
this._procField('volume', 'template', 16);
this._procField('reserved1', 'uint', 16);
this._procFieldArray('reserved2', 2, 'uint', 32);
this._procFieldArray('matrix', 9, 'template', 32);
this._procFieldArray('pre_defined', 6,'uint', 32);
this._procField('next_track_ID', 'uint', 32);
};
// ISO/IEC 14496-30:2014 - WebVTT Cue Payload Box.
ISOBox.prototype._boxProcessors['payl'] = function() {
this._procField('cue_text', 'utf8');
};
//ISO/IEC 23001-7:2011 - 8.1 Protection System Specific Header Box
ISOBox.prototype._boxProcessors['pssh'] = function() {
this._procFullBox();
this._procFieldArray('SystemID', 16, 'uint', 8);
this._procField('DataSize', 'uint', 32);
this._procFieldArray('Data', this.DataSize, 'uint', 8);
};
// ISO/IEC 14496-12:2012 - 8.12.5 Scheme Type Box
ISOBox.prototype._boxProcessors['schm'] = function() {
this._procFullBox();
this._procField('scheme_type', 'uint', 32);
this._procField('scheme_version', 'uint', 32);
if (this.flags & 0x000001) {
this._procField('scheme_uri', 'string', -1);
}
};
// ISO/IEC 14496-12:2012 - 8.6.4.1 sdtp box
ISOBox.prototype._boxProcessors['sdtp'] = function() {
this._procFullBox();
var sample_count = -1;
if (this._parsing) {
sample_count = (this._raw.byteLength - (this._cursor.offset - this._raw.byteOffset));
}
this._procFieldArray('sample_dependency_table', sample_count, 'uint', 8);
};
// ISO/IEC 14496-12:2012 - 8.16.3 Segment Index Box
ISOBox.prototype._boxProcessors['sidx'] = function() {
this._procFullBox();
this._procField('reference_ID', 'uint', 32);
this._procField('timescale', 'uint', 32);
this._procField('earliest_presentation_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('first_offset', 'uint', (this.version == 1) ? 64 : 32);
this._procField('reserved', 'uint', 16);
this._procField('reference_count', 'uint', 16);
this._procEntries('references', this.reference_count, function(entry) {
if (!this._parsing) {
entry.reference = (entry.reference_type & 0x00000001) << 31;
entry.reference |= (entry.referenced_size & 0x7FFFFFFF);
entry.sap = (entry.starts_with_SAP & 0x00000001) << 31;
entry.sap |= (entry.SAP_type & 0x00000003) << 28;
entry.sap |= (entry.SAP_delta_time & 0x0FFFFFFF);
}
this._procEntryField(entry, 'reference', 'uint', 32);
this._procEntryField(entry, 'subsegment_duration', 'uint', 32);
this._procEntryField(entry, 'sap', 'uint', 32);
if (this._parsing) {
entry.reference_type = (entry.reference >> 31) & 0x00000001;
entry.referenced_size = entry.reference & 0x7FFFFFFF;
entry.starts_with_SAP = (entry.sap >> 31) & 0x00000001;
entry.SAP_type = (entry.sap >> 28) & 0x00000007;
entry.SAP_delta_time = (entry.sap & 0x0FFFFFFF);
}
});
};
// ISO/IEC 14496-12:2012 - 8.4.5.3 Sound Media Header Box
ISOBox.prototype._boxProcessors['smhd'] = function() {
this._procFullBox();
this._procField('balance', 'uint', 16);
this._procField('reserved', 'uint', 16);
};
// ISO/IEC 14496-12:2012 - 8.16.4 Subsegment Index Box
ISOBox.prototype._boxProcessors['ssix'] = function() {
this._procFullBox();
this._procField('subsegment_count', 'uint', 32);
this._procEntries('subsegments', this.subsegment_count, function(subsegment) {
this._procEntryField(subsegment, 'ranges_count', 'uint', 32);
this._procSubEntries(subsegment, 'ranges', subsegment.ranges_count, function(range) {
this._procEntryField(range, 'level', 'uint', 8);
this._procEntryField(range, 'range_size', 'uint', 24);
});
});
};
// ISO/IEC 14496-12:2012 - 8.5.2 Sample Description Box
ISOBox.prototype._boxProcessors['stsd'] = function() {
this._procFullBox();
this._procField('entry_count', 'uint', 32);
this._procSubBoxes('entries', this.entry_count);
};
// ISO/IEC 14496-12:2015 - 8.7.7 Sub-Sample Information Box
ISOBox.prototype._boxProcessors['subs'] = function () {
this._procFullBox();
this._procField('entry_count', 'uint', 32);
this._procEntries('entries', this.entry_count, function(entry) {
this._procEntryField(entry, 'sample_delta', 'uint', 32);
this._procEntryField(entry, 'subsample_count', 'uint', 16);
this._procSubEntries(entry, 'subsamples', entry.subsample_count, function(subsample) {
this._procEntryField(subsample, 'subsample_size', 'uint', (this.version === 1) ? 32 : 16);
this._procEntryField(subsample, 'subsample_priority', 'uint', 8);
this._procEntryField(subsample, 'discardable', 'uint', 8);
this._procEntryField(subsample, 'codec_specific_parameters', 'uint', 32);
});
});
};
//ISO/IEC 23001-7:2011 - 8.2 Track Encryption Box
ISOBox.prototype._boxProcessors['tenc'] = function() {
this._procFullBox();
this._procField('default_IsEncrypted', 'uint', 24);
this._procField('default_IV_size', 'uint', 8);
this._procFieldArray('default_KID', 16, 'uint', 8);
};
// ISO/IEC 14496-12:2012 - 8.8.12 Track Fragmnent Decode Time
ISOBox.prototype._boxProcessors['tfdt'] = function() {
this._procFullBox();
this._procField('baseMediaDecodeTime', 'uint', (this.version == 1) ? 64 : 32);
};
// ISO/IEC 14496-12:2012 - 8.8.7 Track Fragment Header Box
ISOBox.prototype._boxProcessors['tfhd'] = function() {
this._procFullBox();
this._procField('track_ID', 'uint', 32);
if (this.flags & 0x01) this._procField('base_data_offset', 'uint', 64);
if (this.flags & 0x02) this._procField('sample_description_offset', 'uint', 32);
if (this.flags & 0x08) this._procField('default_sample_duration', 'uint', 32);
if (this.flags & 0x10) this._procField('default_sample_size', 'uint', 32);
if (this.flags & 0x20) this._procField('default_sample_flags', 'uint', 32);
};
// ISO/IEC 14496-12:2012 - 8.8.10 Track Fragment Random Access Box
ISOBox.prototype._boxProcessors['tfra'] = function() {
this._procFullBox();
this._procField('track_ID', 'uint', 32);
if (!this._parsing) {
this.reserved = 0;
this.reserved |= (this.length_size_of_traf_num & 0x00000030) << 4;
this.reserved |= (this.length_size_of_trun_num & 0x0000000C) << 2;
this.reserved |= (this.length_size_of_sample_num & 0x00000003);
}
this._procField('reserved', 'uint', 32);
if (this._parsing) {
this.length_size_of_traf_num = (this.reserved & 0x00000030) >> 4;
this.length_size_of_trun_num = (this.reserved & 0x0000000C) >> 2;
this.length_size_of_sample_num = (this.reserved & 0x00000003);
}
this._procField('number_of_entry', 'uint', 32);
this._procEntries('entries', this.number_of_entry, function(entry) {
this._procEntryField(entry, 'time', 'uint', (this.version === 1) ? 64 : 32);
this._procEntryField(entry, 'moof_offset', 'uint', (this.version === 1) ? 64 : 32);
this._procEntryField(entry, 'traf_number', 'uint', (this.length_size_of_traf_num + 1) * 8);
this._procEntryField(entry, 'trun_number', 'uint', (this.length_size_of_trun_num + 1) * 8);
this._procEntryField(entry, 'sample_number', 'uint', (this.length_size_of_sample_num + 1) * 8);
});
};
// ISO/IEC 14496-12:2012 - 8.3.2 Track Header Box
ISOBox.prototype._boxProcessors['tkhd'] = function() {
this._procFullBox();
this._procField('creation_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('modification_time', 'uint', (this.version == 1) ? 64 : 32);
this._procField('track_ID', 'uint', 32);
this._procField('reserved1', 'uint', 32);
this._procField('duration', 'uint', (this.version == 1) ? 64 : 32);
this._procFieldArray('reserved2', 2, 'uint', 32);
this._procField('layer', 'uint', 16);
this._procField('alternate_group', 'uint', 16);
this._procField('volume', 'template', 16);
this._procField('reserved3', 'uint', 16);
this._procFieldArray('matrix', 9, 'template', 32);
this._procField('width', 'template', 32);
this._procField('height', 'template', 32);
};
// ISO/IEC 14496-12:2012 - 8.8.3 Track Extends Box
ISOBox.prototype._boxProcessors['trex'] = function() {
this._procFullBox();
this._procField('track_ID', 'uint', 32);
this._procField('default_sample_description_index', 'uint', 32);
this._procField('default_sample_duration', 'uint', 32);
this._procField('default_sample_size', 'uint', 32);
this._procField('default_sample_flags', 'uint', 32);
};
// ISO/IEC 14496-12:2012 - 8.8.8 Track Run Box
// Note: the 'trun' box has a direct relation to the 'tfhd' box for defaults.
// These defaults are not set explicitly here, but are left to resolve for the user.
ISOBox.prototype._boxProcessors['trun'] = function() {
this._procFullBox();
this._procField('sample_count', 'uint', 32);
if (this.flags & 0x1) this._procField('data_offset', 'int', 32);
if (this.flags & 0x4) this._procField('first_sample_flags', 'uint', 32);
this._procEntries('samples', this.sample_count, function(sample) {
if (this.flags & 0x100) this._procEntryField(sample, 'sample_duration', 'uint', 32);
if (this.flags & 0x200) this._procEntryField(sample, 'sample_size', 'uint', 32);
if (this.flags & 0x400) this._procEntryField(sample, 'sample_flags', 'uint', 32);
if (this.flags & 0x800) this._procEntryField(sample, 'sample_composition_time_offset', (this.version === 1) ? 'int' : 'uint', 32);
});
};
// ISO/IEC 14496-12:2012 - 8.7.2 Data Reference Box
ISOBox.prototype._boxProcessors['url '] = ISOBox.prototype._boxProcessors['urn '] = function() {
this._procFullBox();
if (this.type === 'urn ') {
this._procField('name', 'string', -1);
}
this._procField('location', 'string', -1);
};
// ISO/IEC 14496-30:2014 - WebVTT Source Label Box
ISOBox.prototype._boxProcessors['vlab'] = function() {
this._procField('source_label', 'utf8');
};
// ISO/IEC 14496-12:2012 - 8.4.5.2 Video Media Header Box
ISOBox.prototype._boxProcessors['vmhd'] = function() {
this._procFullBox();
this._procField('graphicsmode', 'uint', 16);
this._procFieldArray('opcolor', 3, 'uint', 16);
};
// ISO/IEC 14496-30:2014 - WebVTT Configuration Box
ISOBox.prototype._boxProcessors['vttC'] = function() {
this._procField('config', 'utf8');
};
// ISO/IEC 14496-30:2014 - WebVTT Empty Sample Box
ISOBox.prototype._boxProcessors['vtte'] = function() {
// Nothing should happen here.
};
/***/ }),
/***/ "./node_modules/core-util-is/lib/util.js":
/*!***********************************************!*\
!*** ./node_modules/core-util-is/lib/util.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(Buffer) {// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(arg) {
if (Array.isArray) {
return Array.isArray(arg);
}
return objectToString(arg) === '[object Array]';
}
exports.isArray = isArray;
function isBoolean(arg) {
return typeof arg === 'boolean';
}
exports.isBoolean = isBoolean;
function isNull(arg) {
return arg === null;
}
exports.isNull = isNull;
function isNullOrUndefined(arg) {
return arg == null;
}
exports.isNullOrUndefined = isNullOrUndefined;
function isNumber(arg) {
return typeof arg === 'number';
}
exports.isNumber = isNumber;
function isString(arg) {
return typeof arg === 'string';
}
exports.isString = isString;
function isSymbol(arg) {
return typeof arg === 'symbol';
}
exports.isSymbol = isSymbol;
function isUndefined(arg) {
return arg === void 0;
}
exports.isUndefined = isUndefined;
function isRegExp(re) {
return objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
exports.isObject = isObject;
function isDate(d) {
return objectToString(d) === '[object Date]';
}
exports.isDate = isDate;
function isError(e) {
return (objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;
function isFunction(arg) {
return typeof arg === 'function';
}
exports.isFunction = isFunction;
function isPrimitive(arg) {
return arg === null ||
typeof arg === 'boolean' ||
typeof arg === 'number' ||
typeof arg === 'string' ||
typeof arg === 'symbol' || // ES6 symbol
typeof arg === 'undefined';
}
exports.isPrimitive = isPrimitive;
exports.isBuffer = Buffer.isBuffer;
function objectToString(o) {
return Object.prototype.toString.call(o);
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node-libs-browser/node_modules/buffer/index.js */ "./node_modules/node-libs-browser/node_modules/buffer/index.js").Buffer));
/***/ }),
/***/ "./node_modules/es6-promise/auto.js":
/*!******************************************!*\
!*** ./node_modules/es6-promise/auto.js ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// This file can be required in Browserify and Node.js for automatic polyfill
// To use it: require('es6-promise/auto');
module.exports = __webpack_require__(/*! ./ */ "./node_modules/es6-promise/dist/es6-promise.js").polyfill();
/***/ }),
/***/ "./node_modules/es6-promise/dist/es6-promise.js":
/*!******************************************************!*\
!*** ./node_modules/es6-promise/dist/es6-promise.js ***!
\******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process, global) {/*!
* @overview es6-promise - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
* @version v4.2.8+1e68dce6
*/
(function (global, factory) {
module.exports = factory();
}(this, (function () {
function objectOrFunction(x) {
var type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}
function isFunction(x) {
return typeof x === 'function';
}
var _isArray = void 0;
if (Array.isArray) {
_isArray = Array.isArray;
} else {
_isArray = function (x) {
return Object.prototype.toString.call(x) === '[object Array]';
};
}
var isArray = _isArray;
var len = 0;
var vertxNext = void 0;
var customSchedulerFn = void 0;
var asap = function asap(callback, arg) {
queue[len] = callback;
queue[len + 1] = arg;
len += 2;
if (len === 2) {
// If len is 2, that means that we need to schedule an async flush.
// If additional callbacks are queued before the queue is flushed, they
// will be processed by this flush that we are scheduling.
if (customSchedulerFn) {
customSchedulerFn(flush);
} else {
scheduleFlush();
}
}
};
function setScheduler(scheduleFn) {
customSchedulerFn = scheduleFn;
}
function setAsap(asapFn) {
asap = asapFn;
}
var browserWindow = typeof window !== 'undefined' ? window : undefined;
var browserGlobal = browserWindow || {};
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
// test for web worker but not in IE10
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
// node
function useNextTick() {
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
// see https://github.com/cujojs/when/issues/410 for details
return function () {
return process.nextTick(flush);
};
}
// vertx
function useVertxTimer() {
if (typeof vertxNext !== 'undefined') {
return function () {
vertxNext(flush);
};
}
return useSetTimeout();
}
function useMutationObserver() {
var iterations = 0;
var observer = new BrowserMutationObserver(flush);
var node = document.createTextNode('');
observer.observe(node, { characterData: true });
return function () {
node.data = iterations = ++iterations % 2;
};
}
// web worker
function useMessageChannel() {
var channel = new MessageChannel();
channel.port1.onmessage = flush;
return function () {
return channel.port2.postMessage(0);
};
}
function useSetTimeout() {
// Store setTimeout reference so es6-promise will be unaffected by
// other code modifying setTimeout (like sinon.useFakeTimers())
var globalSetTimeout = setTimeout;
return function () {
return globalSetTimeout(flush, 1);
};
}
var queue = new Array(1000);
function flush() {
for (var i = 0; i < len; i += 2) {
var callback = queue[i];
var arg = queue[i + 1];
callback(arg);
queue[i] = undefined;
queue[i + 1] = undefined;
}
len = 0;
}
function attemptVertx() {
try {
var vertx = Function('return this')().require('vertx');
vertxNext = vertx.runOnLoop || vertx.runOnContext;
return useVertxTimer();
} catch (e) {
return useSetTimeout();
}
}
var scheduleFlush = void 0;
// Decide what async method to use to triggering processing of queued callbacks:
if (isNode) {
scheduleFlush = useNextTick();
} else if (BrowserMutationObserver) {
scheduleFlush = useMutationObserver();
} else if (isWorker) {
scheduleFlush = useMessageChannel();
} else if (browserWindow === undefined && "function" === 'function') {
scheduleFlush = attemptVertx();
} else {
scheduleFlush = useSetTimeout();
}
function then(onFulfillment, onRejection) {
var parent = this;
var child = new this.constructor(noop);
if (child[PROMISE_ID] === undefined) {
makePromise(child);
}
var _state = parent._state;
if (_state) {
var callback = arguments[_state - 1];
asap(function () {
return invokeCallback(_state, child, callback, parent._result);
});
} else {
subscribe(parent, child, onFulfillment, onRejection);
}
return child;
}
/**
`Promise.resolve` returns a promise that will become resolved with the
passed `value`. It is shorthand for the following:
```javascript
let promise = new Promise(function(resolve, reject){
resolve(1);
});
promise.then(function(value){
// value === 1
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
let promise = Promise.resolve(1);
promise.then(function(value){
// value === 1
});
```
@method resolve
@static
@param {Any} value value that the returned promise will be resolved with
Useful for tooling.
@return {Promise} a promise that will become fulfilled with the given
`value`
*/
function resolve$1(object) {
/*jshint validthis:true */
var Constructor = this;
if (object && typeof object === 'object' && object.constructor === Constructor) {
return object;
}
var promise = new Constructor(noop);
resolve(promise, object);
return promise;
}
var PROMISE_ID = Math.random().toString(36).substring(2);
function noop() {}
var PENDING = void 0;
var FULFILLED = 1;
var REJECTED = 2;
function selfFulfillment() {
return new TypeError("You cannot resolve a promise with itself");
}
function cannotReturnOwn() {
return new TypeError('A promises callback cannot return that same promise.');
}
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
try {
then$$1.call(value, fulfillmentHandler, rejectionHandler);
} catch (e) {
return e;
}
}
function handleForeignThenable(promise, thenable, then$$1) {
asap(function (promise) {
var sealed = false;
var error = tryThen(then$$1, thenable, function (value) {
if (sealed) {
return;
}
sealed = true;
if (thenable !== value) {
resolve(promise, value);
} else {
fulfill(promise, value);
}
}, function (reason) {
if (sealed) {
return;
}
sealed = true;
reject(promise, reason);
}, 'Settle: ' + (promise._label || ' unknown promise'));
if (!sealed && error) {
sealed = true;
reject(promise, error);
}
}, promise);
}
function handleOwnThenable(promise, thenable) {
if (thenable._state === FULFILLED) {
fulfill(promise, thenable._result);
} else if (thenable._state === REJECTED) {
reject(promise, thenable._result);
} else {
subscribe(thenable, undefined, function (value) {
return resolve(promise, value);
}, function (reason) {
return reject(promise, reason);
});
}
}
function handleMaybeThenable(promise, maybeThenable, then$$1) {
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
handleOwnThenable(promise, maybeThenable);
} else {
if (then$$1 === undefined) {
fulfill(promise, maybeThenable);
} else if (isFunction(then$$1)) {
handleForeignThenable(promise, maybeThenable, then$$1);
} else {
fulfill(promise, maybeThenable);
}
}
}
function resolve(promise, value) {
if (promise === value) {
reject(promise, selfFulfillment());
} else if (objectOrFunction(value)) {
var then$$1 = void 0;
try {
then$$1 = value.then;
} catch (error) {
reject(promise, error);
return;
}
handleMaybeThenable(promise, value, then$$1);
} else {
fulfill(promise, value);
}
}
function publishRejection(promise) {
if (promise._onerror) {
promise._onerror(promise._result);
}
publish(promise);
}
function fulfill(promise, value) {
if (promise._state !== PENDING) {
return;
}
promise._result = value;
promise._state = FULFILLED;
if (promise._subscribers.length !== 0) {
asap(publish, promise);
}
}
function reject(promise, reason) {
if (promise._state !== PENDING) {
return;
}
promise._state = REJECTED;
promise._result = reason;
asap(publishRejection, promise);
}
function subscribe(parent, child, onFulfillment, onRejection) {
var _subscribers = parent._subscribers;
var length = _subscribers.length;
parent._onerror = null;
_subscribers[length] = child;
_subscribers[length + FULFILLED] = onFulfillment;
_subscribers[length + REJECTED] = onRejection;
if (length === 0 && parent._state) {
asap(publish, parent);
}
}
function publish(promise) {
var subscribers = promise._subscribers;
var settled = promise._state;
if (subscribers.length === 0) {
return;
}
var child = void 0,
callback = void 0,
detail = promise._result;
for (var i = 0; i < subscribers.length; i += 3) {
child = subscribers[i];
callback = subscribers[i + settled];
if (child) {
invokeCallback(settled, child, callback, detail);
} else {
callback(detail);
}
}
promise._subscribers.length = 0;
}
function invokeCallback(settled, promise, callback, detail) {
var hasCallback = isFunction(callback),
value = void 0,
error = void 0,
succeeded = true;
if (hasCallback) {
try {
value = callback(detail);
} catch (e) {
succeeded = false;
error = e;
}
if (promise === value) {
reject(promise, cannotReturnOwn());
return;
}
} else {
value = detail;
}
if (promise._state !== PENDING) ; else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (succeeded === false) {
reject(promise, error);
} else if (settled === FULFILLED) {
fulfill(promise, value);
} else if (settled === REJECTED) {
reject(promise, value);
}
}
function initializePromise(promise, resolver) {
try {
resolver(function resolvePromise(value) {
resolve(promise, value);
}, function rejectPromise(reason) {
reject(promise, reason);
});
} catch (e) {
reject(promise, e);
}
}
var id = 0;
function nextId() {
return id++;
}
function makePromise(promise) {
promise[PROMISE_ID] = id++;
promise._state = undefined;
promise._result = undefined;
promise._subscribers = [];
}
function validationError() {
return new Error('Array Methods must be provided an Array');
}
var Enumerator = function () {
function Enumerator(Constructor, input) {
this._instanceConstructor = Constructor;
this.promise = new Constructor(noop);
if (!this.promise[PROMISE_ID]) {
makePromise(this.promise);
}
if (isArray(input)) {
this.length = input.length;
this._remaining = input.length;
this._result = new Array(this.length);
if (this.length === 0) {
fulfill(this.promise, this._result);
} else {
this.length = this.length || 0;
this._enumerate(input);
if (this._remaining === 0) {
fulfill(this.promise, this._result);
}
}
} else {
reject(this.promise, validationError());
}
}
Enumerator.prototype._enumerate = function _enumerate(input) {
for (var i = 0; this._state === PENDING && i < input.length; i++) {
this._eachEntry(input[i], i);
}
};
Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
var c = this._instanceConstructor;
var resolve$$1 = c.resolve;
if (resolve$$1 === resolve$1) {
var _then = void 0;
var error = void 0;
var didError = false;
try {
_then = entry.then;
} catch (e) {
didError = true;
error = e;
}
if (_then === then && entry._state !== PENDING) {
this._settledAt(entry._state, i, entry._result);
} else if (typeof _then !== 'function') {
this._remaining--;
this._result[i] = entry;
} else if (c === Promise$1) {
var promise = new c(noop);
if (didError) {
reject(promise, error);
} else {
handleMaybeThenable(promise, entry, _then);
}
this._willSettleAt(promise, i);
} else {
this._willSettleAt(new c(function (resolve$$1) {
return resolve$$1(entry);
}), i);
}
} else {
this._willSettleAt(resolve$$1(entry), i);
}
};
Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
var promise = this.promise;
if (promise._state === PENDING) {
this._remaining--;
if (state === REJECTED) {
reject(promise, value);
} else {
this._result[i] = value;
}
}
if (this._remaining === 0) {
fulfill(promise, this._result);
}
};
Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
var enumerator = this;
subscribe(promise, undefined, function (value) {
return enumerator._settledAt(FULFILLED, i, value);
}, function (reason) {
return enumerator._settledAt(REJECTED, i, reason);
});
};
return Enumerator;
}();
/**
`Promise.all` accepts an array of promises, and returns a new promise which
is fulfilled with an array of fulfillment values for the passed promises, or
rejected with the reason of the first passed promise to be rejected. It casts all
elements of the passed iterable to promises as it runs this algorithm.
Example:
```javascript
let promise1 = resolve(1);
let promise2 = resolve(2);
let promise3 = resolve(3);
let promises = [ promise1, promise2, promise3 ];
Promise.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
let promise1 = resolve(1);
let promise2 = reject(new Error("2"));
let promise3 = reject(new Error("3"));
let promises = [ promise1, promise2, promise3 ];
Promise.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@static
@param {Array} entries array of promises
@param {String} label optional string for labeling the promise.
Useful for tooling.
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
@static
*/
function all(entries) {
return new Enumerator(this, entries).promise;
}
/**
`Promise.race` returns a new promise which is settled in the same way as the
first passed promise to settle.
Example:
```javascript
let promise1 = new Promise(function(resolve, reject){
setTimeout(function(){
resolve('promise 1');
}, 200);
});
let promise2 = new Promise(function(resolve, reject){
setTimeout(function(){
resolve('promise 2');
}, 100);
});
Promise.race([promise1, promise2]).then(function(result){
// result === 'promise 2' because it was resolved before promise1
// was resolved.
});
```
`Promise.race` is deterministic in that only the state of the first
settled promise matters. For example, even if other promises given to the
`promises` array argument are resolved, but the first settled promise has
become rejected before the other promises became fulfilled, the returned
promise will become rejected:
```javascript
let promise1 = new Promise(function(resolve, reject){
setTimeout(function(){
resolve('promise 1');
}, 200);
});
let promise2 = new Promise(function(resolve, reject){
setTimeout(function(){
reject(new Error('promise 2'));
}, 100);
});
Promise.race([promise1, promise2]).then(function(result){
// Code here never runs
}, function(reason){
// reason.message === 'promise 2' because promise 2 became rejected before
// promise 1 became fulfilled
});
```
An example real-world use case is implementing timeouts:
```javascript
Promise.race([ajax('foo.json'), timeout(5000)])
```
@method race
@static
@param {Array} promises array of promises to observe
Useful for tooling.
@return {Promise} a promise which settles in the same way as the first passed
promise to settle.
*/
function race(entries) {
/*jshint validthis:true */
var Constructor = this;
if (!isArray(entries)) {
return new Constructor(function (_, reject) {
return reject(new TypeError('You must pass an array to race.'));
});
} else {
return new Constructor(function (resolve, reject) {
var length = entries.length;
for (var i = 0; i < length; i++) {
Constructor.resolve(entries[i]).then(resolve, reject);
}
});
}
}
/**
`Promise.reject` returns a promise rejected with the passed `reason`.
It is shorthand for the following:
```javascript
let promise = new Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
let promise = Promise.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@static
@param {Any} reason value that the returned promise will be rejected with.
Useful for tooling.
@return {Promise} a promise rejected with the given `reason`.
*/
function reject$1(reason) {
/*jshint validthis:true */
var Constructor = this;
var promise = new Constructor(noop);
reject(promise, reason);
return promise;
}
function needsResolver() {
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
}
function needsNew() {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
}
/**
Promise objects represent the eventual result of an asynchronous operation. The
primary way of interacting with a promise is through its `then` method, which
registers callbacks to receive either a promise's eventual value or the reason
why the promise cannot be fulfilled.
Terminology
-----------
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
- `thenable` is an object or function that defines a `then` method.
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
- `exception` is a value that is thrown using the throw statement.
- `reason` is a value that indicates why a promise was rejected.
- `settled` the final resting state of a promise, fulfilled or rejected.
A promise can be in one of three states: pending, fulfilled, or rejected.
Promises that are fulfilled have a fulfillment value and are in the fulfilled
state. Promises that are rejected have a rejection reason and are in the
rejected state. A fulfillment value is never a thenable.
Promises can also be said to *resolve* a value. If this value is also a
promise, then the original promise's settled state will match the value's
settled state. So a promise that *resolves* a promise that rejects will
itself reject, and a promise that *resolves* a promise that fulfills will
itself fulfill.
Basic Usage:
------------
```js
let promise = new Promise(function(resolve, reject) {
// on success
resolve(value);
// on failure
reject(reason);
});
promise.then(function(value) {
// on fulfillment
}, function(reason) {
// on rejection
});
```
Advanced Usage:
---------------
Promises shine when abstracting away asynchronous interactions such as
`XMLHttpRequest`s.
```js
function getJSON(url) {
return new Promise(function(resolve, reject){
let xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = handler;
xhr.responseType = 'json';
xhr.setRequestHeader('Accept', 'application/json');
xhr.send();
function handler() {
if (this.readyState === this.DONE) {
if (this.status === 200) {
resolve(this.response);
} else {
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
}
}
};
});
}
getJSON('/posts.json').then(function(json) {
// on fulfillment
}, function(reason) {
// on rejection
});
```
Unlike callbacks, promises are great composable primitives.
```js
Promise.all([
getJSON('/posts'),
getJSON('/comments')
]).then(function(values){
values[0] // => postsJSON
values[1] // => commentsJSON
return values;
});
```
@class Promise
@param {Function} resolver
Useful for tooling.
@constructor
*/
var Promise$1 = function () {
function Promise(resolver) {
this[PROMISE_ID] = nextId();
this._result = this._state = undefined;
this._subscribers = [];
if (noop !== resolver) {
typeof resolver !== 'function' && needsResolver();
this instanceof Promise ? initializePromise(this, resolver) : needsNew();
}
}
/**
The primary way of interacting with a promise is through its `then` method,
which registers callbacks to receive either a promise's eventual value or the
reason why the promise cannot be fulfilled.
```js
findUser().then(function(user){
// user is available
}, function(reason){
// user is unavailable, and you are given the reason why
});
```
Chaining
--------
The return value of `then` is itself a promise. This second, 'downstream'
promise is resolved with the return value of the first promise's fulfillment
or rejection handler, or rejected if the handler throws an exception.
```js
findUser().then(function (user) {
return user.name;
}, function (reason) {
return 'default name';
}).then(function (userName) {
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
// will be `'default name'`
});
findUser().then(function (user) {
throw new Error('Found user, but still unhappy');
}, function (reason) {
throw new Error('`findUser` rejected and we're unhappy');
}).then(function (value) {
// never reached
}, function (reason) {
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
});
```
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
```js
findUser().then(function (user) {
throw new PedagogicalException('Upstream error');
}).then(function (value) {
// never reached
}).then(function (value) {
// never reached
}, function (reason) {
// The `PedgagocialException` is propagated all the way down to here
});
```
Assimilation
------------
Sometimes the value you want to propagate to a downstream promise can only be
retrieved asynchronously. This can be achieved by returning a promise in the
fulfillment or rejection handler. The downstream promise will then be pending
until the returned promise is settled. This is called *assimilation*.
```js
findUser().then(function (user) {
return findCommentsByAuthor(user);
}).then(function (comments) {
// The user's comments are now available
});
```
If the assimliated promise rejects, then the downstream promise will also reject.
```js
findUser().then(function (user) {
return findCommentsByAuthor(user);
}).then(function (comments) {
// If `findCommentsByAuthor` fulfills, we'll have the value here
}, function (reason) {
// If `findCommentsByAuthor` rejects, we'll have the reason here
});
```
Simple Example
--------------
Synchronous Example
```javascript
let result;
try {
result = findResult();
// success
} catch(reason) {
// failure
}
```
Errback Example
```js
findResult(function(result, err){
if (err) {
// failure
} else {
// success
}
});
```
Promise Example;
```javascript
findResult().then(function(result){
// success
}, function(reason){
// failure
});
```
Advanced Example
--------------
Synchronous Example
```javascript
let author, books;
try {
author = findAuthor();
books = findBooksByAuthor(author);
// success
} catch(reason) {
// failure
}
```
Errback Example
```js
function foundBooks(books) {
}
function failure(reason) {
}
findAuthor(function(author, err){
if (err) {
failure(err);
// failure
} else {
try {
findBoooksByAuthor(author, function(books, err) {
if (err) {
failure(err);
} else {
try {
foundBooks(books);
} catch(reason) {
failure(reason);
}
}
});
} catch(error) {
failure(err);
}
// success
}
});
```
Promise Example;
```javascript
findAuthor().
then(findBooksByAuthor).
then(function(books){
// found books
}).catch(function(reason){
// something went wrong
});
```
@method then
@param {Function} onFulfilled
@param {Function} onRejected
Useful for tooling.
@return {Promise}
*/
/**
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
as the catch block of a try/catch statement.
```js
function findAuthor(){
throw new Error('couldn't find that author');
}
// synchronous
try {
findAuthor();
} catch(reason) {
// something went wrong
}
// async with promises
findAuthor().catch(function(reason){
// something went wrong
});
```
@method catch
@param {Function} onRejection
Useful for tooling.
@return {Promise}
*/
Promise.prototype.catch = function _catch(onRejection) {
return this.then(null, onRejection);
};
/**
`finally` will be invoked regardless of the promise's fate just as native
try/catch/finally behaves
Synchronous example:
```js
findAuthor() {
if (Math.random() > 0.5) {
throw new Error();
}
return new Author();
}
try {
return findAuthor(); // succeed or fail
} catch(error) {
return findOtherAuther();
} finally {
// always runs
// doesn't affect the return value
}
```
Asynchronous example:
```js
findAuthor().catch(function(reason){
return findOtherAuther();
}).finally(function(){
// author was either found, or not
});
```
@method finally
@param {Function} callback
@return {Promise}
*/
Promise.prototype.finally = function _finally(callback) {
var promise = this;
var constructor = promise.constructor;
if (isFunction(callback)) {
return promise.then(function (value) {
return constructor.resolve(callback()).then(function () {
return value;
});
}, function (reason) {
return constructor.resolve(callback()).then(function () {
throw reason;
});
});
}
return promise.then(callback, callback);
};
return Promise;
}();
Promise$1.prototype.then = then;
Promise$1.all = all;
Promise$1.race = race;
Promise$1.resolve = resolve$1;
Promise$1.reject = reject$1;
Promise$1._setScheduler = setScheduler;
Promise$1._setAsap = setAsap;
Promise$1._asap = asap;
/*global self*/
function polyfill() {
var local = void 0;
if (typeof global !== 'undefined') {
local = global;
} else if (typeof self !== 'undefined') {
local = self;
} else {
try {
local = Function('return this')();
} catch (e) {
throw new Error('polyfill failed because global object is unavailable in this environment');
}
}
var P = local.Promise;
if (P) {
var promiseToString = null;
try {
promiseToString = Object.prototype.toString.call(P.resolve());
} catch (e) {
// silently ignored
}
if (promiseToString === '[object Promise]' && !P.cast) {
return;
}
}
local.Promise = Promise$1;
}
// Strange compat..
Promise$1.polyfill = polyfill;
Promise$1.Promise = Promise$1;
return Promise$1;
})));
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js"), __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")));
/***/ }),
/***/ "./node_modules/fast-deep-equal/index.js":
/*!***********************************************!*\
!*** ./node_modules/fast-deep-equal/index.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var isArray = Array.isArray;
var keyList = Object.keys;
var hasProp = Object.prototype.hasOwnProperty;
module.exports = function equal(a, b) {
if (a === b) return true;
if (a && b && typeof a == 'object' && typeof b == 'object') {
var arrA = isArray(a)
, arrB = isArray(b)
, i
, length
, key;
if (arrA && arrB) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;)
if (!equal(a[i], b[i])) return false;
return true;
}
if (arrA != arrB) return false;
var dateA = a instanceof Date
, dateB = b instanceof Date;
if (dateA != dateB) return false;
if (dateA && dateB) return a.getTime() == b.getTime();
var regexpA = a instanceof RegExp
, regexpB = b instanceof RegExp;
if (regexpA != regexpB) return false;
if (regexpA && regexpB) return a.toString() == b.toString();
var keys = keyList(a);
length = keys.length;
if (length !== keyList(b).length)
return false;
for (i = length; i-- !== 0;)
if (!hasProp.call(b, keys[i])) return false;
for (i = length; i-- !== 0;) {
key = keys[i];
if (!equal(a[key], b[key])) return false;
}
return true;
}
return a!==a && b!==b;
};
/***/ }),
/***/ "./node_modules/ieee754/index.js":
/*!***************************************!*\
!*** ./node_modules/ieee754/index.js ***!
\***************************************/
/*! no static exports found */
/***/ (function(module, exports) {
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m;
var eLen = (nBytes * 8) - mLen - 1;
var eMax = (1 << eLen) - 1;
var eBias = eMax >> 1;
var nBits = -7;
var i = isLE ? (nBytes - 1) : 0;
var d = isLE ? -1 : 1;
var s = buffer[offset + i];
i += d;
e = s & ((1 << (-nBits)) - 1);
s >>= (-nBits);
nBits += eLen;
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
m = e & ((1 << (-nBits)) - 1);
e >>= (-nBits);
nBits += mLen;
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
if (e === 0) {
e = 1 - eBias;
} else if (e === eMax) {
return m ? NaN : ((s ? -1 : 1) * Infinity)
} else {
m = m + Math.pow(2, mLen);
e = e - eBias;
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
};
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c;
var eLen = (nBytes * 8) - mLen - 1;
var eMax = (1 << eLen) - 1;
var eBias = eMax >> 1;
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
var i = isLE ? 0 : (nBytes - 1);
var d = isLE ? 1 : -1;
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
value = Math.abs(value);
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0;
e = eMax;
} else {
e = Math.floor(Math.log(value) / Math.LN2);
if (value * (c = Math.pow(2, -e)) < 1) {
e--;
c *= 2;
}
if (e + eBias >= 1) {
value += rt / c;
} else {
value += rt * Math.pow(2, 1 - eBias);
}
if (value * c >= 2) {
e++;
c /= 2;
}
if (e + eBias >= eMax) {
m = 0;
e = eMax;
} else if (e + eBias >= 1) {
m = ((value * c) - 1) * Math.pow(2, mLen);
e = e + eBias;
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
e = 0;
}
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
e = (e << mLen) | m;
eLen += mLen;
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
buffer[offset + i - d] |= s * 128;
};
/***/ }),
/***/ "./node_modules/imsc/src/main/js/doc.js":
/*!**********************************************!*\
!*** ./node_modules/imsc/src/main/js/doc.js ***!
\**********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
(function (imscDoc, sax, imscNames, imscStyles, imscUtils) {
/**
* Allows a client to provide callbacks to handle children of the <metadata> element
* @typedef {Object} MetadataHandler
* @property {?OpenTagCallBack} onOpenTag
* @property {?CloseTagCallBack} onCloseTag
* @property {?TextCallBack} onText
*/
/**
* Called when the opening tag of an element node is encountered.
* @callback OpenTagCallBack
* @param {string} ns Namespace URI of the element
* @param {string} name Local name of the element
* @param {Object[]} attributes List of attributes, each consisting of a
* `uri`, `name` and `value`
*/
/**
* Called when the closing tag of an element node is encountered.
* @callback CloseTagCallBack
*/
/**
* Called when a text node is encountered.
* @callback TextCallBack
* @param {string} contents Contents of the text node
*/
/**
* Parses an IMSC1 document into an opaque in-memory representation that exposes
* a single method <pre>getMediaTimeEvents()</pre> that returns a list of time
* offsets (in seconds) of the ISD, i.e. the points in time where the visual
* representation of the document change. `metadataHandler` allows the caller to
* be called back when nodes are present in <metadata> elements.
*
* @param {string} xmlstring XML document
* @param {?module:imscUtils.ErrorHandler} errorHandler Error callback
* @param {?MetadataHandler} metadataHandler Callback for <Metadata> elements
* @returns {Object} Opaque in-memory representation of an IMSC1 document
*/
imscDoc.fromXML = function (xmlstring, errorHandler, metadataHandler) {
var p = sax.parser(true, {xmlns: true});
var estack = [];
var xmllangstack = [];
var xmlspacestack = [];
var metadata_depth = 0;
var doc = null;
p.onclosetag = function (node) {
if (estack[0] instanceof Styling) {
/* flatten chained referential styling */
for (var sid in estack[0].styles) {
mergeChainedStyles(estack[0], estack[0].styles[sid], errorHandler);
}
} else if (estack[0] instanceof P || estack[0] instanceof Span) {
/* merge anonymous spans */
if (estack[0].contents.length > 1) {
var cs = [estack[0].contents[0]];
var c;
for (c = 1; c < estack[0].contents.length; c++) {
if (estack[0].contents[c] instanceof AnonymousSpan &&
cs[cs.length - 1] instanceof AnonymousSpan) {
cs[cs.length - 1].text += estack[0].contents[c].text;
} else {
cs.push(estack[0].contents[c]);
}
}
estack[0].contents = cs;
}
// remove redundant nested anonymous spans (9.3.3(1)(c))
if (estack[0] instanceof Span &&
estack[0].contents.length === 1 &&
estack[0].contents[0] instanceof AnonymousSpan) {
estack[0].text = estack[0].contents[0].text;
delete estack[0].contents;
}
} else if (estack[0] instanceof ForeignElement) {
if (estack[0].node.uri === imscNames.ns_tt &&
estack[0].node.local === 'metadata') {
/* leave the metadata element */
metadata_depth--;
} else if (metadata_depth > 0 &&
metadataHandler &&
'onCloseTag' in metadataHandler) {
/* end of child of metadata element */
metadataHandler.onCloseTag();
}
}
// TODO: delete stylerefs?
// maintain the xml:space stack
xmlspacestack.shift();
// maintain the xml:lang stack
xmllangstack.shift();
// prepare for the next element
estack.shift();
};
p.ontext = function (str) {
if (estack[0] === undefined) ; else if (estack[0] instanceof Span || estack[0] instanceof P) {
/* create an anonymous span */
var s = new AnonymousSpan();
s.initFromText(doc, estack[0], str, xmlspacestack[0], errorHandler);
estack[0].contents.push(s);
} else if (estack[0] instanceof ForeignElement &&
metadata_depth > 0 &&
metadataHandler &&
'onText' in metadataHandler) {
/* text node within a child of metadata element */
metadataHandler.onText(str);
}
};
p.onopentag = function (node) {
// maintain the xml:space stack
var xmlspace = node.attributes["xml:space"];
if (xmlspace) {
xmlspacestack.unshift(xmlspace.value);
} else {
if (xmlspacestack.length === 0) {
xmlspacestack.unshift("default");
} else {
xmlspacestack.unshift(xmlspacestack[0]);
}
}
/* maintain the xml:lang stack */
var xmllang = node.attributes["xml:lang"];
if (xmllang) {
xmllangstack.unshift(xmllang.value);
} else {
if (xmllangstack.length === 0) {
xmllangstack.unshift("");
} else {
xmllangstack.unshift(xmllangstack[0]);
}
}
/* process the element */
if (node.uri === imscNames.ns_tt) {
if (node.local === 'tt') {
if (doc !== null) {
reportFatal(errorHandler, "Two <tt> elements at (" + this.line + "," + this.column + ")");
}
doc = new TT();
doc.initFromNode(node, errorHandler);
estack.unshift(doc);
} else if (node.local === 'head') {
if (!(estack[0] instanceof TT)) {
reportFatal(errorHandler, "Parent of <head> element is not <tt> at (" + this.line + "," + this.column + ")");
}
if (doc.head !== null) {
reportFatal("Second <head> element at (" + this.line + "," + this.column + ")");
}
doc.head = new Head();
estack.unshift(doc.head);
} else if (node.local === 'styling') {
if (!(estack[0] instanceof Head)) {
reportFatal(errorHandler, "Parent of <styling> element is not <head> at (" + this.line + "," + this.column + ")");
}
if (doc.head.styling !== null) {
reportFatal("Second <styling> element at (" + this.line + "," + this.column + ")");
}
doc.head.styling = new Styling();
estack.unshift(doc.head.styling);
} else if (node.local === 'style') {
var s;
if (estack[0] instanceof Styling) {
s = new Style();
s.initFromNode(node, errorHandler);
/* ignore <style> element missing @id */
if (!s.id) {
reportError(errorHandler, "<style> element missing @id attribute");
} else {
doc.head.styling.styles[s.id] = s;
}
estack.unshift(s);
} else if (estack[0] instanceof Region) {
/* nested styles can be merged with specified styles
* immediately, with lower priority
* (see 8.4.4.2(3) at TTML1 )
*/
s = new Style();
s.initFromNode(node, errorHandler);
mergeStylesIfNotPresent(s.styleAttrs, estack[0].styleAttrs);
estack.unshift(s);
} else {
reportFatal(errorHandler, "Parent of <style> element is not <styling> or <region> at (" + this.line + "," + this.column + ")");
}
} else if (node.local === 'layout') {
if (!(estack[0] instanceof Head)) {
reportFatal(errorHandler, "Parent of <layout> element is not <head> at " + this.line + "," + this.column + ")");
}
if (doc.head.layout !== null) {
reportFatal(errorHandler, "Second <layout> element at " + this.line + "," + this.column + ")");
}
doc.head.layout = new Layout();
estack.unshift(doc.head.layout);
} else if (node.local === 'region') {
if (!(estack[0] instanceof Layout)) {
reportFatal(errorHandler, "Parent of <region> element is not <layout> at " + this.line + "," + this.column + ")");
}
var r = new Region();
r.initFromNode(doc, node, errorHandler);
if (!r.id || r.id in doc.head.layout.regions) {
reportError(errorHandler, "Ignoring <region> with duplicate or missing @id at " + this.line + "," + this.column + ")");
} else {
doc.head.layout.regions[r.id] = r;
}
estack.unshift(r);
} else if (node.local === 'body') {
if (!(estack[0] instanceof TT)) {
reportFatal(errorHandler, "Parent of <body> element is not <tt> at " + this.line + "," + this.column + ")");
}
if (doc.body !== null) {
reportFatal(errorHandler, "Second <body> element at " + this.line + "," + this.column + ")");
}
var b = new Body();
b.initFromNode(doc, node, errorHandler);
doc.body = b;
estack.unshift(b);
} else if (node.local === 'div') {
if (!(estack[0] instanceof Div || estack[0] instanceof Body)) {
reportFatal(errorHandler, "Parent of <div> element is not <body> or <div> at " + this.line + "," + this.column + ")");
}
var d = new Div();
d.initFromNode(doc, estack[0], node, errorHandler);
estack[0].contents.push(d);
estack.unshift(d);
} else if (node.local === 'p') {
if (!(estack[0] instanceof Div)) {
reportFatal(errorHandler, "Parent of <p> element is not <div> at " + this.line + "," + this.column + ")");
}
var p = new P();
p.initFromNode(doc, estack[0], node, errorHandler);
estack[0].contents.push(p);
estack.unshift(p);
} else if (node.local === 'span') {
if (!(estack[0] instanceof Span || estack[0] instanceof P)) {
reportFatal(errorHandler, "Parent of <span> element is not <span> or <p> at " + this.line + "," + this.column + ")");
}
var ns = new Span();
ns.initFromNode(doc, estack[0], node, xmlspacestack[0], errorHandler);
estack[0].contents.push(ns);
estack.unshift(ns);
} else if (node.local === 'br') {
if (!(estack[0] instanceof Span || estack[0] instanceof P)) {
reportFatal(errorHandler, "Parent of <br> element is not <span> or <p> at " + this.line + "," + this.column + ")");
}
var nb = new Br();
nb.initFromNode(doc, estack[0], node, errorHandler);
estack[0].contents.push(nb);
estack.unshift(nb);
} else if (node.local === 'set') {
if (!(estack[0] instanceof Span ||
estack[0] instanceof P ||
estack[0] instanceof Div ||
estack[0] instanceof Body ||
estack[0] instanceof Region ||
estack[0] instanceof Br)) {
reportFatal(errorHandler, "Parent of <set> element is not a content element or a region at " + this.line + "," + this.column + ")");
}
var st = new Set();
st.initFromNode(doc, estack[0], node, errorHandler);
estack[0].sets.push(st);
estack.unshift(st);
} else {
/* element in the TT namespace, but not a content element */
estack.unshift(new ForeignElement(node));
}
} else {
/* ignore elements not in the TTML namespace unless in metadata element */
estack.unshift(new ForeignElement(node));
}
/* handle metadata callbacks */
if (estack[0] instanceof ForeignElement) {
if (node.uri === imscNames.ns_tt &&
node.local === 'metadata') {
/* enter the metadata element */
metadata_depth++;
} else if (
metadata_depth > 0 &&
metadataHandler &&
'onOpenTag' in metadataHandler
) {
/* start of child of metadata element */
var attrs = [];
for (var a in node.attributes) {
attrs[node.attributes[a].uri + " " + node.attributes[a].local] =
{
uri: node.attributes[a].uri,
local: node.attributes[a].local,
value: node.attributes[a].value
};
}
metadataHandler.onOpenTag(node.uri, node.local, attrs);
}
}
};
// parse the document
p.write(xmlstring).close();
// all referential styling has been flatten, so delete the styling elements if there is a head
// otherwise create an empty head
if (doc.head !== null) {
delete doc.head.styling;
} else {
doc.head = new Head();
}
// create default region if no regions specified
if (doc.head.layout === null) {
doc.head.layout = new Layout();
}
var hasRegions = false;
/* AFAIK the only way to determine whether an object has members */
for (var i in doc.head.layout.regions) {
hasRegions = true;
break;
}
if (!hasRegions) {
/* create default region */
var dr = Region.prototype.createDefaultRegion();
doc.head.layout.regions[dr.id] = dr;
}
/* resolve desired timing for regions */
for (var region_i in doc.head.layout.regions) {
resolveTiming(doc, doc.head.layout.regions[region_i], null, null);
}
/* resolve desired timing for content elements */
if (doc.body) {
resolveTiming(doc, doc.body, null, null);
}
return doc;
};
function resolveTiming(doc, element, prev_sibling, parent) {
/* are we in a seq container? */
var isinseq = parent && parent.timeContainer === "seq";
/* determine implicit begin */
var implicit_begin = 0; /* default */
if (parent) {
if (isinseq && prev_sibling) {
/*
* if seq time container, offset from the previous sibling end
*/
implicit_begin = prev_sibling.end;
} else {
implicit_begin = parent.begin;
}
}
/* compute desired begin */
element.begin = element.explicit_begin ? element.explicit_begin + implicit_begin : implicit_begin;
/* determine implicit end */
var implicit_end = element.begin;
var s = null;
for (var set_i in element.sets) {
resolveTiming(doc, element.sets[set_i], s, element);
if (element.timeContainer === "seq") {
implicit_end = element.sets[set_i].end;
} else {
implicit_end = Math.max(implicit_end, element.sets[set_i].end);
}
s = element.sets[set_i];
}
if (!('contents' in element)) {
/* anonymous spans and regions and <set> and <br>s and spans with only children text nodes */
if (isinseq) {
/* in seq container, implicit duration is zero */
implicit_end = element.begin;
} else {
/* in par container, implicit duration is indefinite */
implicit_end = Number.POSITIVE_INFINITY;
}
} else {
for (var content_i in element.contents) {
resolveTiming(doc, element.contents[content_i], s, element);
if (element.timeContainer === "seq") {
implicit_end = element.contents[content_i].end;
} else {
implicit_end = Math.max(implicit_end, element.contents[content_i].end);
}
s = element.contents[content_i];
}
}
/* determine desired end */
/* it is never made really clear in SMIL that the explicit end is offset by the implicit begin */
if (element.explicit_end !== null && element.explicit_dur !== null) {
element.end = Math.min(element.begin + element.explicit_dur, implicit_begin + element.explicit_end);
} else if (element.explicit_end === null && element.explicit_dur !== null) {
element.end = element.begin + element.explicit_dur;
} else if (element.explicit_end !== null && element.explicit_dur === null) {
element.end = implicit_begin + element.explicit_end;
} else {
element.end = implicit_end;
}
delete element.explicit_begin;
delete element.explicit_dur;
delete element.explicit_end;
doc._registerEvent(element);
}
function ForeignElement(node) {
this.node = node;
}
function TT() {
this.events = [];
this.head = null;
this.body = null;
}
TT.prototype.initFromNode = function (node, errorHandler) {
/* compute cell resolution */
this.cellResolution = extractCellResolution(node, errorHandler);
/* extract frame rate and tick rate */
var frtr = extractFrameAndTickRate(node, errorHandler);
this.effectiveFrameRate = frtr.effectiveFrameRate;
this.tickRate = frtr.tickRate;
/* extract aspect ratio */
this.aspectRatio = extractAspectRatio(node, errorHandler);
/* check timebase */
var attr = findAttribute(node, imscNames.ns_ttp, "timeBase");
if (attr !== null && attr !== "media") {
reportFatal(errorHandler, "Unsupported time base");
}
/* retrieve extent */
var e = extractExtent(node, errorHandler);
if (e === null) {
/* TODO: remove once unit tests are ready */
this.pxDimensions = {'h': 480, 'w': 640};
} else {
if (e.h.unit !== "px" || e.w.unit !== "px") {
reportFatal(errorHandler, "Extent on TT must be in px or absent");
}
this.pxDimensions = {'h': e.h.value, 'w': e.w.value};
}
};
/* register a temporal events */
TT.prototype._registerEvent = function (elem) {
/* skip if begin is not < then end */
if (elem.end <= elem.begin)
return;
/* index the begin time of the event */
var b_i = indexOf(this.events, elem.begin);
if (!b_i.found) {
this.events.splice(b_i.index, 0, elem.begin);
}
/* index the end time of the event */
if (elem.end !== Number.POSITIVE_INFINITY) {
var e_i = indexOf(this.events, elem.end);
if (!e_i.found) {
this.events.splice(e_i.index, 0, elem.end);
}
}
};
/*
* Retrieves the range of ISD times covered by the document
*
* @returns {Array} Array of two elements: min_begin_time and max_begin_time
*
*/
TT.prototype.getMediaTimeRange = function () {
return [this.events[0], this.events[this.events.length - 1]];
};
/*
* Returns list of ISD begin times
*
* @returns {Array}
*/
TT.prototype.getMediaTimeEvents = function () {
return this.events;
};
/*
* Represents a TTML Head element
*/
function Head() {
this.styling = null;
this.layout = null;
}
/*
* Represents a TTML Styling element
*/
function Styling() {
this.styles = {};
}
/*
* Represents a TTML Style element
*/
function Style() {
this.id = null;
this.styleAttrs = null;
this.styleRefs = null;
}
Style.prototype.initFromNode = function (node, errorHandler) {
this.id = elementGetXMLID(node);
this.styleAttrs = elementGetStyles(node, errorHandler);
this.styleRefs = elementGetStyleRefs(node);
};
/*
* Represents a TTML Layout element
*
*/
function Layout() {
this.regions = {};
}
/*
* TTML element utility functions
*
*/
function ContentElement(kind) {
this.kind = kind;
}
function IdentifiedElement(id) {
this.id = id;
}
IdentifiedElement.prototype.initFromNode = function (doc, parent, node, errorHandler) {
this.id = elementGetXMLID(node);
};
function LayoutElement(id) {
this.regionID = id;
}
LayoutElement.prototype.initFromNode = function (doc, parent, node, errorHandler) {
this.regionID = elementGetRegionID(node);
};
function StyledElement(styleAttrs) {
this.styleAttrs = styleAttrs;
}
StyledElement.prototype.initFromNode = function (doc, parent, node, errorHandler) {
this.styleAttrs = elementGetStyles(node, errorHandler);
if (doc.head !== null && doc.head.styling !== null) {
mergeReferencedStyles(doc.head.styling, elementGetStyleRefs(node), this.styleAttrs, errorHandler);
}
};
function AnimatedElement(sets) {
this.sets = sets;
}
AnimatedElement.prototype.initFromNode = function (doc, parent, node, errorHandler) {
this.sets = [];
};
function ContainerElement(contents) {
this.contents = contents;
}
ContainerElement.prototype.initFromNode = function (doc, parent, node, errorHandler) {
this.contents = [];
};
function TimedElement(explicit_begin, explicit_end, explicit_dur) {
this.explicit_begin = explicit_begin;
this.explicit_end = explicit_end;
this.explicit_dur = explicit_dur;
}
TimedElement.prototype.initFromNode = function (doc, parent, node, errorHandler) {
var t = processTiming(doc, parent, node, errorHandler);
this.explicit_begin = t.explicit_begin;
this.explicit_end = t.explicit_end;
this.explicit_dur = t.explicit_dur;
this.timeContainer = elementGetTimeContainer(node, errorHandler);
};
/*
* Represents a TTML body element
*/
function Body() {
ContentElement.call(this, 'body');
}
Body.prototype.initFromNode = function (doc, node, errorHandler) {
StyledElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
TimedElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
AnimatedElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
LayoutElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
ContainerElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
};
/*
* Represents a TTML div element
*/
function Div() {
ContentElement.call(this, 'div');
}
Div.prototype.initFromNode = function (doc, parent, node, errorHandler) {
StyledElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
AnimatedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
LayoutElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
ContainerElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
};
/*
* Represents a TTML p element
*/
function P() {
ContentElement.call(this, 'p');
}
P.prototype.initFromNode = function (doc, parent, node, errorHandler) {
StyledElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
AnimatedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
LayoutElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
ContainerElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
};
/*
* Represents a TTML span element
*/
function Span() {
ContentElement.call(this, 'span');
}
Span.prototype.initFromNode = function (doc, parent, node, xmlspace, errorHandler) {
StyledElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
AnimatedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
LayoutElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
ContainerElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
this.space = xmlspace;
};
/*
* Represents a TTML anonymous span element
*/
function AnonymousSpan() {
ContentElement.call(this, 'span');
}
AnonymousSpan.prototype.initFromText = function (doc, parent, text, xmlspace, errorHandler) {
TimedElement.prototype.initFromNode.call(this, doc, parent, null, errorHandler);
this.text = text;
this.space = xmlspace;
};
/*
* Represents a TTML br element
*/
function Br() {
ContentElement.call(this, 'br');
}
Br.prototype.initFromNode = function (doc, parent, node, errorHandler) {
LayoutElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
};
/*
* Represents a TTML Region element
*
*/
function Region() {
}
Region.prototype.createDefaultRegion = function () {
var r = new Region();
IdentifiedElement.call(r, '');
StyledElement.call(r, {});
AnimatedElement.call(r, []);
TimedElement.call(r, 0, Number.POSITIVE_INFINITY, null);
return r;
};
Region.prototype.initFromNode = function (doc, node, errorHandler) {
IdentifiedElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
StyledElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
TimedElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
AnimatedElement.prototype.initFromNode.call(this, doc, null, node, errorHandler);
/* immediately merge referenced styles */
if (doc.head !== null && doc.head.styling !== null) {
mergeReferencedStyles(doc.head.styling, elementGetStyleRefs(node), this.styleAttrs, errorHandler);
}
};
/*
* Represents a TTML Set element
*
*/
function Set() {
}
Set.prototype.initFromNode = function (doc, parent, node, errorHandler) {
TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
var styles = elementGetStyles(node, errorHandler);
this.qname = null;
this.value = null;
for (var qname in styles) {
if (this.qname) {
reportError(errorHandler, "More than one style specified on set");
break;
}
this.qname = qname;
this.value = styles[qname];
}
};
/*
* Utility functions
*
*/
function elementGetXMLID(node) {
return node && 'xml:id' in node.attributes ? node.attributes['xml:id'].value || null : null;
}
function elementGetRegionID(node) {
return node && 'region' in node.attributes ? node.attributes.region.value : '';
}
function elementGetTimeContainer(node, errorHandler) {
var tc = node && 'timeContainer' in node.attributes ? node.attributes.timeContainer.value : null;
if ((!tc) || tc === "par") {
return "par";
} else if (tc === "seq") {
return "seq";
} else {
reportError(errorHandler, "Illegal value of timeContainer (assuming 'par')");
return "par";
}
}
function elementGetStyleRefs(node) {
return node && 'style' in node.attributes ? node.attributes.style.value.split(" ") : [];
}
function elementGetStyles(node, errorHandler) {
var s = {};
if (node !== null) {
for (var i in node.attributes) {
var qname = node.attributes[i].uri + " " + node.attributes[i].local;
var sa = imscStyles.byQName[qname];
if (sa !== undefined) {
var val = sa.parse(node.attributes[i].value);
if (val !== null) {
s[qname] = val;
/* TODO: consider refactoring errorHandler into parse and compute routines */
if (sa === imscStyles.byName.zIndex) {
reportWarning(errorHandler, "zIndex attribute present but not used by IMSC1 since regions do not overlap");
}
} else {
reportError(errorHandler, "Cannot parse styling attribute " + qname + " --> " + node.attributes[i].value);
}
}
}
}
return s;
}
function findAttribute(node, ns, name) {
for (var i in node.attributes) {
if (node.attributes[i].uri === ns &&
node.attributes[i].local === name) {
return node.attributes[i].value;
}
}
return null;
}
function extractAspectRatio(node, errorHandler) {
var ar = findAttribute(node, imscNames.ns_ittp, "aspectRatio");
var rslt = null;
if (ar !== null) {
var ASPECT_RATIO_RE = /(\d+) (\d+)/;
var m = ASPECT_RATIO_RE.exec(ar);
if (m !== null) {
var w = parseInt(m[1]);
var h = parseInt(m[2]);
if (w !== 0 && h !== 0) {
rslt = w / h;
} else {
reportError(errorHandler, "Illegal aspectRatio values (ignoring)");
}
} else {
reportError(errorHandler, "Malformed aspectRatio attribute (ignoring)");
}
}
return rslt;
}
/*
* Returns the cellResolution attribute from a node
*
*/
function extractCellResolution(node, errorHandler) {
var cr = findAttribute(node, imscNames.ns_ttp, "cellResolution");
// initial value
var h = 15;
var w = 32;
if (cr !== null) {
var CELL_RESOLUTION_RE = /(\d+) (\d+)/;
var m = CELL_RESOLUTION_RE.exec(cr);
if (m !== null) {
w = parseInt(m[1]);
h = parseInt(m[2]);
} else {
reportWarning(errorHandler, "Malformed cellResolution value (using initial value instead)");
}
}
return {'w': w, 'h': h};
}
function extractFrameAndTickRate(node, errorHandler) {
// subFrameRate is ignored per IMSC1 specification
// extract frame rate
var fps_attr = findAttribute(node, imscNames.ns_ttp, "frameRate");
// initial value
var fps = 30;
// match variable
var m;
if (fps_attr !== null) {
var FRAME_RATE_RE = /(\d+)/;
m = FRAME_RATE_RE.exec(fps_attr);
if (m !== null) {
fps = parseInt(m[1]);
} else {
reportWarning(errorHandler, "Malformed frame rate attribute (using initial value instead)");
}
}
// extract frame rate multiplier
var frm_attr = findAttribute(node, imscNames.ns_ttp, "frameRateMultiplier");
// initial value
var frm = 1;
if (frm_attr !== null) {
var FRAME_RATE_MULT_RE = /(\d+) (\d+)/;
m = FRAME_RATE_MULT_RE.exec(frm_attr);
if (m !== null) {
frm = parseInt(m[1]) / parseInt(m[2]);
} else {
reportWarning(errorHandler, "Malformed frame rate multiplier attribute (using initial value instead)");
}
}
var efps = frm * fps;
// extract tick rate
var tr = 1;
var trattr = findAttribute(node, imscNames.ns_ttp, "tickRate");
if (trattr === null) {
if (fps_attr !== null)
tr = efps;
} else {
var TICK_RATE_RE = /(\d+)/;
m = TICK_RATE_RE.exec(trattr);
if (m !== null) {
tr = parseInt(m[1]);
} else {
reportWarning(errorHandler, "Malformed tick rate attribute (using initial value instead)");
}
}
return {effectiveFrameRate: efps, tickRate: tr};
}
function extractExtent(node, errorHandler) {
var attr = findAttribute(node, imscNames.ns_tts, "extent");
if (attr === null)
return null;
var s = attr.split(" ");
if (s.length !== 2) {
reportWarning(errorHandler, "Malformed extent (ignoring)");
return null;
}
var w = imscUtils.parseLength(s[0]);
var h = imscUtils.parseLength(s[1]);
if (!h || !w) {
reportWarning(errorHandler, "Malformed extent values (ignoring)");
return null;
}
return {'h': h, 'w': w};
}
function parseTimeExpression(tickRate, effectiveFrameRate, str) {
var CLOCK_TIME_FRACTION_RE = /^(\d{2,}):(\d\d):(\d\d(?:\.\d+)?)$/;
var CLOCK_TIME_FRAMES_RE = /^(\d{2,}):(\d\d):(\d\d)\:(\d{2,})$/;
var OFFSET_FRAME_RE = /^(\d+(?:\.\d+)?)f$/;
var OFFSET_TICK_RE = /^(\d+(?:\.\d+)?)t$/;
var OFFSET_MS_RE = /^(\d+(?:\.\d+)?)ms$/;
var OFFSET_S_RE = /^(\d+(?:\.\d+)?)s$/;
var OFFSET_H_RE = /^(\d+(?:\.\d+)?)h$/;
var OFFSET_M_RE = /^(\d+(?:\.\d+)?)m$/;
var m;
var r = null;
if ((m = OFFSET_FRAME_RE.exec(str)) !== null) {
if (effectiveFrameRate !== null) {
r = parseFloat(m[1]) / effectiveFrameRate;
}
} else if ((m = OFFSET_TICK_RE.exec(str)) !== null) {
if (tickRate !== null) {
r = parseFloat(m[1]) / tickRate;
}
} else if ((m = OFFSET_MS_RE.exec(str)) !== null) {
r = parseFloat(m[1]) / 1000.0;
} else if ((m = OFFSET_S_RE.exec(str)) !== null) {
r = parseFloat(m[1]);
} else if ((m = OFFSET_H_RE.exec(str)) !== null) {
r = parseFloat(m[1]) * 3600.0;
} else if ((m = OFFSET_M_RE.exec(str)) !== null) {
r = parseFloat(m[1]) * 60.0;
} else if ((m = CLOCK_TIME_FRACTION_RE.exec(str)) !== null) {
r = parseInt(m[1]) * 3600 +
parseInt(m[2]) * 60 +
parseFloat(m[3]);
} else if ((m = CLOCK_TIME_FRAMES_RE.exec(str)) !== null) {
/* this assumes that HH:MM:SS is a clock-time-with-fraction */
if (effectiveFrameRate !== null) {
r = parseInt(m[1]) * 3600 +
parseInt(m[2]) * 60 +
parseInt(m[3]) +
(m[4] === null ? 0 : parseInt(m[4]) / effectiveFrameRate);
}
}
return r;
}
function processTiming(doc, parent, node, errorHandler) {
/* determine explicit begin */
var explicit_begin = null;
if (node && 'begin' in node.attributes) {
explicit_begin = parseTimeExpression(doc.tickRate, doc.effectiveFrameRate, node.attributes.begin.value);
if (explicit_begin === null) {
reportWarning(errorHandler, "Malformed begin value " + node.attributes.begin.value + " (using 0)");
}
}
/* determine explicit duration */
var explicit_dur = null;
if (node && 'dur' in node.attributes) {
explicit_dur = parseTimeExpression(doc.tickRate, doc.effectiveFrameRate, node.attributes.dur.value);
if (explicit_dur === null) {
reportWarning(errorHandler, "Malformed dur value " + node.attributes.dur.value + " (ignoring)");
}
}
/* determine explicit end */
var explicit_end = null;
if (node && 'end' in node.attributes) {
explicit_end = parseTimeExpression(doc.tickRate, doc.effectiveFrameRate, node.attributes.end.value);
if (explicit_end === null) {
reportWarning(errorHandler, "Malformed end value (ignoring)");
}
}
return {explicit_begin: explicit_begin,
explicit_end: explicit_end,
explicit_dur: explicit_dur};
}
function mergeChainedStyles(styling, style, errorHandler) {
while (style.styleRefs.length > 0) {
var sref = style.styleRefs.pop();
if (!(sref in styling.styles)) {
reportError(errorHandler, "Non-existant style id referenced");
continue;
}
mergeChainedStyles(styling, styling.styles[sref], errorHandler);
mergeStylesIfNotPresent(styling.styles[sref].styleAttrs, style.styleAttrs);
}
}
function mergeReferencedStyles(styling, stylerefs, styleattrs, errorHandler) {
for (var i = stylerefs.length - 1; i >= 0; i--) {
var sref = stylerefs[i];
if (!(sref in styling.styles)) {
reportError(errorHandler, "Non-existant style id referenced");
continue;
}
mergeStylesIfNotPresent(styling.styles[sref].styleAttrs, styleattrs);
}
}
function mergeStylesIfNotPresent(from_styles, into_styles) {
for (var sname in from_styles) {
if (sname in into_styles)
continue;
into_styles[sname] = from_styles[sname];
}
}
function reportWarning(errorHandler, msg) {
if (errorHandler && errorHandler.warn && errorHandler.warn(msg))
throw msg;
}
function reportError(errorHandler, msg) {
if (errorHandler && errorHandler.error && errorHandler.error(msg))
throw msg;
}
function reportFatal(errorHandler, msg) {
if (errorHandler && errorHandler.fatal)
errorHandler.fatal(msg);
throw msg;
}
/*
* Binary search utility function
*
* @typedef {Object} BinarySearchResult
* @property {boolean} found Was an exact match found?
* @property {number} index Position of the exact match or insert position
*
* @returns {BinarySearchResult}
*/
function indexOf(arr, searchval) {
var min = 0;
var max = arr.length - 1;
var cur;
while (min <= max) {
cur = Math.floor((min + max) / 2);
var curval = arr[cur];
if (curval < searchval) {
min = cur + 1;
} else if (curval > searchval) {
max = cur - 1;
} else {
return {found: true, index: cur};
}
}
return {found: false, index: min};
}
})( exports,
typeof sax === 'undefined' ? __webpack_require__(/*! sax */ "./node_modules/sax/lib/sax.js") : sax,
typeof imscNames === 'undefined' ? __webpack_require__(/*! ./names */ "./node_modules/imsc/src/main/js/names.js") : imscNames,
typeof imscStyles === 'undefined' ? __webpack_require__(/*! ./styles */ "./node_modules/imsc/src/main/js/styles.js") : imscStyles,
typeof imscUtils === 'undefined' ? __webpack_require__(/*! ./utils */ "./node_modules/imsc/src/main/js/utils.js") : imscUtils);
/***/ }),
/***/ "./node_modules/imsc/src/main/js/html.js":
/*!***********************************************!*\
!*** ./node_modules/imsc/src/main/js/html.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
(function (imscHTML, imscNames, imscStyles) {
/**
* Function that maps <pre>smpte:background</pre> URIs to URLs resolving to image resource
* @callback IMGResolver
* @param {string} <pre>smpte:background</pre> URI
* @return {string} PNG resource URL
*/
/**
* Renders an ISD object (returned by <pre>generateISD()</pre>) into a
* parent element, that must be attached to the DOM. The ISD will be rendered
* into a child <pre>div</pre>
* with heigh and width equal to the clientHeight and clientWidth of the element,
* unless explicitly specified otherwise by the caller. Images URIs specified
* by <pre>smpte:background</pre> attributes are mapped to image resource URLs
* by an <pre>imgResolver</pre> function. The latter takes the value of <code>smpte:background</code>
* attribute and an <code>img</code> DOM element as input, and is expected to
* set the <code>src</code> attribute of the <code>img</code> to the absolute URI of the image.
* <pre>displayForcedOnlyMode</pre> sets the (boolean)
* value of the IMSC1 displayForcedOnlyMode parameter. The function returns
* an opaque object that should passed in <code>previousISDState</code> when this function
* is called for the next ISD, otherwise <code>previousISDState</code> should be set to
* <code>null</code>.
*
* @param {Object} isd ISD to be rendered
* @param {Object} element Element into which the ISD is rendered
* @param {?IMGResolver} imgResolver Resolve <pre>smpte:background</pre> URIs into URLs.
* @param {?number} eheight Height (in pixel) of the child <div>div</div> or null
* to use clientHeight of the parent element
* @param {?number} ewidth Width (in pixel) of the child <div>div</div> or null
* to use clientWidth of the parent element
* @param {?boolean} displayForcedOnlyMode Value of the IMSC1 displayForcedOnlyMode parameter,
* or false if null
* @param {?module:imscUtils.ErrorHandler} errorHandler Error callback
* @param {Object} previousISDState State saved during processing of the previous ISD, or null if initial call
* @param {?boolean} enableRollUp Enables roll-up animations (see CEA 708)
* @return {Object} ISD state to be provided when this funtion is called for the next ISD
*/
imscHTML.render = function (isd,
element,
imgResolver,
eheight,
ewidth,
displayForcedOnlyMode,
errorHandler,
previousISDState,
enableRollUp
) {
/* maintain aspect ratio if specified */
var height = eheight || element.clientHeight;
var width = ewidth || element.clientWidth;
if (isd.aspectRatio !== null) {
var twidth = height * isd.aspectRatio;
if (twidth > width) {
height = Math.round(width / isd.aspectRatio);
} else {
width = twidth;
}
}
var rootcontainer = document.createElement("div");
rootcontainer.style.position = "relative";
rootcontainer.style.width = width + "px";
rootcontainer.style.height = height + "px";
rootcontainer.style.margin = "auto";
rootcontainer.style.top = 0;
rootcontainer.style.bottom = 0;
rootcontainer.style.left = 0;
rootcontainer.style.right = 0;
rootcontainer.style.zIndex = 0;
var context = {
h: height,
w: width,
regionH: null,
regionW: null,
imgResolver: imgResolver,
displayForcedOnlyMode: displayForcedOnlyMode || false,
isd: isd,
errorHandler: errorHandler,
previousISDState: previousISDState,
enableRollUp: enableRollUp || false,
currentISDState: {},
flg: null, /* current fillLineGap value if active, null otherwise */
lp: null, /* current linePadding value if active, null otherwise */
mra: null, /* current multiRowAlign value if active, null otherwise */
ipd: null, /* inline progression direction (lr, rl, tb) */
bpd: null /* block progression direction (lr, rl, tb) */
};
element.appendChild(rootcontainer);
for (var i in isd.contents) {
processElement(context, rootcontainer, isd.contents[i]);
}
return context.currentISDState;
};
function processElement(context, dom_parent, isd_element) {
var e;
if (isd_element.kind === 'region') {
e = document.createElement("div");
e.style.position = "absolute";
} else if (isd_element.kind === 'body') {
e = document.createElement("div");
} else if (isd_element.kind === 'div') {
e = document.createElement("div");
} else if (isd_element.kind === 'p') {
e = document.createElement("p");
} else if (isd_element.kind === 'span') {
e = document.createElement("span");
//e.textContent = isd_element.text;
} else if (isd_element.kind === 'br') {
e = document.createElement("br");
}
if (!e) {
reportError(context.errorHandler, "Error processing ISD element kind: " + isd_element.kind);
return;
}
/* override UA default margin */
/* TODO: should apply to <p> only */
e.style.margin = "0";
/* tranform TTML styles to CSS styles */
for (var i in STYLING_MAP_DEFS) {
var sm = STYLING_MAP_DEFS[i];
var attr = isd_element.styleAttrs[sm.qname];
if (attr !== undefined && sm.map !== null) {
sm.map(context, e, isd_element, attr);
}
}
var proc_e = e;
/* remember writing direction */
if (isd_element.kind === "region") {
var wdir = isd_element.styleAttrs[imscStyles.byName.writingMode.qname];
if (wdir === "lrtb" || wdir === "lr") {
context.ipd = "lr";
context.bpd = "tb";
} else if (wdir === "rltb" || wdir === "rl") {
context.ipd = "rl";
context.bpd = "tb";
} else if (wdir === "tblr") {
context.ipd = "tb";
context.bpd = "lr";
} else if (wdir === "tbrl" || wdir === "tb") {
context.ipd = "tb";
context.bpd = "rl";
}
}
/* do we have linePadding ? */
var lp = isd_element.styleAttrs[imscStyles.byName.linePadding.qname];
if (lp && lp > 0) {
/* apply padding to the <p> so that line padding does not cause line wraps */
var padmeasure = Math.ceil(lp * context.h) + "px";
if (context.bpd === "tb") {
proc_e.style.paddingLeft = padmeasure;
proc_e.style.paddingRight = padmeasure;
} else {
proc_e.style.paddingTop = padmeasure;
proc_e.style.paddingBottom = padmeasure;
}
context.lp = lp;
}
// do we have multiRowAlign?
var mra = isd_element.styleAttrs[imscStyles.byName.multiRowAlign.qname];
if (mra && mra !== "auto") {
/* create inline block to handle multirowAlign */
var s = document.createElement("span");
s.style.display = "inline-block";
s.style.textAlign = mra;
e.appendChild(s);
proc_e = s;
context.mra = mra;
}
/* remember we are filling line gaps */
if (isd_element.styleAttrs[imscStyles.byName.fillLineGap.qname]) {
context.flg = true;
}
if (isd_element.kind === "span" && isd_element.text) {
if (context.lp || context.mra || context.flg) {
// wrap characters in spans to find the line wrap locations
var cbuf = '';
for (var j = 0; j < isd_element.text.length; j++) {
cbuf += isd_element.text.charAt(j);
var cc = isd_element.text.charCodeAt(j);
if (cc < 0xD800 || cc > 0xDBFF || j === isd_element.text.length) {
/* wrap the character(s) in a span unless it is a high surrogate */
var span = document.createElement("span");
span.textContent = cbuf;
e.appendChild(span);
cbuf = '';
}
}
} else {
e.textContent = isd_element.text;
}
}
dom_parent.appendChild(e);
/* process the children of the ISD element */
for (var k in isd_element.contents) {
processElement(context, proc_e, isd_element.contents[k]);
}
/* list of lines */
var linelist = [];
/* paragraph processing */
/* TODO: linePadding only supported for horizontal scripts */
if ((context.lp || context.mra || context.flg) && isd_element.kind === "p") {
constructLineList(context, proc_e, linelist, null);
/* insert line breaks for multirowalign */
if (context.mra) {
applyMultiRowAlign(linelist);
context.mra = null;
}
/* add linepadding */
if (context.lp) {
applyLinePadding(linelist, context.lp * context.h, context);
context.lp = null;
}
/* fill line gaps linepadding */
if (context.flg) {
var par_edges = rect2edges(proc_e.getBoundingClientRect(), context);
applyFillLineGap(linelist, par_edges.before, par_edges.after, context);
context.flg = null;
}
}
/* region processing */
if (isd_element.kind === "region") {
/* build line list */
constructLineList(context, proc_e, linelist);
/* perform roll up if needed */
if ((context.bpd === "tb") &&
context.enableRollUp &&
isd_element.contents.length > 0 &&
isd_element.styleAttrs[imscStyles.byName.displayAlign.qname] === 'after') {
/* horrible hack, perhaps default region id should be underscore everywhere? */
var rid = isd_element.id === '' ? '_' : isd_element.id;
var rb = new RegionPBuffer(rid, linelist);
context.currentISDState[rb.id] = rb;
if (context.previousISDState &&
rb.id in context.previousISDState &&
context.previousISDState[rb.id].plist.length > 0 &&
rb.plist.length > 1 &&
rb.plist[rb.plist.length - 2].text ===
context.previousISDState[rb.id].plist[context.previousISDState[rb.id].plist.length - 1].text) {
var body_elem = e.firstElementChild;
var h = rb.plist[rb.plist.length - 1].after - rb.plist[rb.plist.length - 1].before;
body_elem.style.bottom = "-" + h + "px";
body_elem.style.transition = "transform 0.4s";
body_elem.style.position = "relative";
body_elem.style.transform = "translateY(-" + h + "px)";
}
}
/* TODO: clean-up the spans ? */
}
}
function applyLinePadding(lineList, lp, context) {
for (var i in lineList) {
var l = lineList[i].elements.length;
var se = lineList[i].elements[lineList[i].start_elem];
var ee = lineList[i].elements[lineList[i].end_elem];
var pospadpxlen = Math.ceil(lp) + "px";
var negpadpxlen = "-" + Math.ceil(lp) + "px";
if (l !== 0) {
if (context.ipd === "lr") {
se.node.style.borderLeftColor = se.bgcolor || "#00000000";
se.node.style.borderLeftStyle = "solid";
se.node.style.borderLeftWidth = pospadpxlen;
se.node.style.marginLeft = negpadpxlen;
} else if (context.ipd === "rl") {
se.node.style.borderRightColor = se.bgcolor || "#00000000";
se.node.style.borderRightStyle = "solid";
se.node.style.borderRightWidth = pospadpxlen;
se.node.style.marginRight = negpadpxlen;
} else if (context.ipd === "tb") {
se.node.style.borderTopColor = se.bgcolor || "#00000000";
se.node.style.borderTopStyle = "solid";
se.node.style.borderTopWidth = pospadpxlen;
se.node.style.marginTop = negpadpxlen;
}
if (context.ipd === "lr") {
ee.node.style.borderRightColor = ee.bgcolor || "#00000000";
ee.node.style.borderRightStyle = "solid";
ee.node.style.borderRightWidth = pospadpxlen;
ee.node.style.marginRight = negpadpxlen;
} else if (context.ipd === "rl") {
ee.node.style.borderLeftColor = ee.bgcolor || "#00000000";
ee.node.style.borderLeftStyle = "solid";
ee.node.style.borderLeftWidth = pospadpxlen;
ee.node.style.marginLeft = negpadpxlen;
} else if (context.ipd === "tb") {
ee.node.style.borderBottomColor = ee.bgcolor || "#00000000";
ee.node.style.borderBottomStyle = "solid";
ee.node.style.borderBottomWidth = pospadpxlen;
ee.node.style.marginBottom = negpadpxlen;
}
}
}
}
function applyMultiRowAlign(lineList) {
/* apply an explicit br to all but the last line */
for (var i = 0; i < lineList.length - 1; i++) {
var l = lineList[i].elements.length;
if (l !== 0 && lineList[i].br === false) {
var br = document.createElement("br");
var lastnode = lineList[i].elements[l - 1].node;
lastnode.parentElement.insertBefore(br, lastnode.nextSibling);
}
}
}
function applyFillLineGap(lineList, par_before, par_after, context) {
/* positive for BPD = lr and tb, negative for BPD = rl */
var s = Math.sign(par_after - par_before);
for (var i = 0; i <= lineList.length; i++) {
/* compute frontier between lines */
var frontier;
if (i === 0) {
frontier = par_before;
} else if (i === lineList.length) {
frontier = par_after;
} else {
frontier = (lineList[i].before + lineList[i - 1].after) / 2;
}
/* padding amount */
var pad;
/* current element */
var e;
/* before line */
if (i > 0) {
for (var j = 0; j < lineList[i - 1].elements.length; j++) {
if (lineList[i - 1].elements[j].bgcolor === null) continue;
e = lineList[i - 1].elements[j];
if (s * (e.after - frontier) < 0) {
pad = Math.ceil(Math.abs(frontier - e.after)) + "px";
e.node.style.backgroundColor = e.bgcolor;
if (context.bpd === "lr") {
e.node.style.paddingRight = pad;
} else if (context.bpd === "rl") {
e.node.style.paddingLeft = pad;
} else if (context.bpd === "tb") {
e.node.style.paddingBottom = pad;
}
}
}
}
/* after line */
if (i < lineList.length) {
for (var k = 0; k < lineList[i].elements.length; k++) {
e = lineList[i].elements[k];
if (e.bgcolor === null) continue;
if (s * (e.before - frontier) > 0) {
pad = Math.ceil(Math.abs(e.before - frontier)) + "px";
e.node.style.backgroundColor = e.bgcolor;
if (context.bpd === "lr") {
e.node.style.paddingLeft = pad;
} else if (context.bpd === "rl") {
e.node.style.paddingRight = pad;
} else if (context.bpd === "tb") {
e.node.style.paddingTop = pad;
}
}
}
}
}
}
function RegionPBuffer(id, lineList) {
this.id = id;
this.plist = lineList;
}
function rect2edges(rect, context) {
var edges = {before: null, after: null, start: null, end: null};
if (context.bpd === "tb") {
edges.before = rect.top;
edges.after = rect.bottom;
if (context.ipd === "lr") {
edges.start = rect.left;
edges.end = rect.right;
} else {
edges.start = rect.right;
edges.end = rect.left;
}
} else if (context.bpd === "lr") {
edges.before = rect.left;
edges.after = rect.right;
edges.start = rect.top;
edges.end = rect.bottom;
} else if (context.bpd === "rl") {
edges.before = rect.right;
edges.after = rect.left;
edges.start = rect.top;
edges.end = rect.bottom;
}
return edges;
}
function constructLineList(context, element, llist, bgcolor) {
var curbgcolor = element.style.backgroundColor || bgcolor;
if (element.childElementCount === 0) {
if (element.localName === 'span') {
var r = element.getBoundingClientRect();
/* skip if span is not displayed */
if (r.height === 0 || r.width === 0) return;
var edges = rect2edges(r, context);
if (llist.length === 0 ||
(!isSameLine(edges.before, edges.after, llist[llist.length - 1].before, llist[llist.length - 1].after))
) {
llist.push({
before: edges.before,
after: edges.after,
start: edges.start,
end: edges.end,
start_elem: 0,
end_elem: 0,
elements: [],
text: "",
br: false
});
} else {
/* positive for BPD = lr and tb, negative for BPD = rl */
var bpd_dir = Math.sign(edges.after - edges.before);
/* positive for IPD = lr and tb, negative for IPD = rl */
var ipd_dir = Math.sign(edges.end - edges.start);
/* check if the line height has increased */
if (bpd_dir * (edges.before - llist[llist.length - 1].before) < 0) {
llist[llist.length - 1].before = edges.before;
}
if (bpd_dir * (edges.after - llist[llist.length - 1].after) > 0) {
llist[llist.length - 1].after = edges.after;
}
if (ipd_dir * (edges.start - llist[llist.length - 1].start) < 0) {
llist[llist.length - 1].start = edges.start;
llist[llist.length - 1].start_elem = llist[llist.length - 1].elements.length;
}
if (ipd_dir * (edges.end - llist[llist.length - 1].end) > 0) {
llist[llist.length - 1].end = edges.end;
llist[llist.length - 1].end_elem = llist[llist.length - 1].elements.length;
}
}
llist[llist.length - 1].text += element.textContent;
llist[llist.length - 1].elements.push(
{
node: element,
bgcolor: curbgcolor,
before: edges.before,
after: edges.after
}
);
} else if (element.localName === 'br' && llist.length !== 0) {
llist[llist.length - 1].br = true;
}
} else {
var child = element.firstChild;
while (child) {
if (child.nodeType === Node.ELEMENT_NODE) {
constructLineList(context, child, llist, curbgcolor);
}
child = child.nextSibling;
}
}
}
function isSameLine(before1, after1, before2, after2) {
return ((after1 < after2) && (before1 > before2)) || ((after2 <= after1) && (before2 >= before1));
}
function HTMLStylingMapDefintion(qName, mapFunc) {
this.qname = qName;
this.map = mapFunc;
}
var STYLING_MAP_DEFS = [
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling backgroundColor",
function (context, dom_element, isd_element, attr) {
/* skip if transparent */
if (attr[3] === 0) return;
dom_element.style.backgroundColor = "rgba(" +
attr[0].toString() + "," +
attr[1].toString() + "," +
attr[2].toString() + "," +
(attr[3] / 255).toString() +
")";
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling color",
function (context, dom_element, isd_element, attr) {
dom_element.style.color = "rgba(" +
attr[0].toString() + "," +
attr[1].toString() + "," +
attr[2].toString() + "," +
(attr[3] / 255).toString() +
")";
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling direction",
function (context, dom_element, isd_element, attr) {
dom_element.style.direction = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling display",
function (context, dom_element, isd_element, attr) {}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling displayAlign",
function (context, dom_element, isd_element, attr) {
/* see https://css-tricks.com/snippets/css/a-guide-to-flexbox/ */
/* TODO: is this affected by writing direction? */
dom_element.style.display = "flex";
dom_element.style.flexDirection = "column";
if (attr === "before") {
dom_element.style.justifyContent = "flex-start";
} else if (attr === "center") {
dom_element.style.justifyContent = "center";
} else if (attr === "after") {
dom_element.style.justifyContent = "flex-end";
}
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling extent",
function (context, dom_element, isd_element, attr) {
/* TODO: this is super ugly */
context.regionH = (attr.h * context.h);
context.regionW = (attr.w * context.w);
/*
* CSS height/width are measured against the content rectangle,
* whereas TTML height/width include padding
*/
var hdelta = 0;
var wdelta = 0;
var p = isd_element.styleAttrs["http://www.w3.org/ns/ttml#styling padding"];
if (!p) ; else {
hdelta = (p[0] + p[2]) * context.h;
wdelta = (p[1] + p[3]) * context.w;
}
dom_element.style.height = (context.regionH - hdelta) + "px";
dom_element.style.width = (context.regionW - wdelta) + "px";
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling fontFamily",
function (context, dom_element, isd_element, attr) {
var rslt = [];
/* per IMSC1 */
for (var i in attr) {
if (attr[i] === "monospaceSerif") {
rslt.push("Courier New");
rslt.push('"Liberation Mono"');
rslt.push("Courier");
rslt.push("monospace");
} else if (attr[i] === "proportionalSansSerif") {
rslt.push("Arial");
rslt.push("Helvetica");
rslt.push('"Liberation Sans"');
rslt.push("sans-serif");
} else if (attr[i] === "monospace") {
rslt.push("monospace");
} else if (attr[i] === "sansSerif") {
rslt.push("sans-serif");
} else if (attr[i] === "serif") {
rslt.push("serif");
} else if (attr[i] === "monospaceSansSerif") {
rslt.push("Consolas");
rslt.push("monospace");
} else if (attr[i] === "proportionalSerif") {
rslt.push("serif");
} else {
rslt.push(attr[i]);
}
}
dom_element.style.fontFamily = rslt.join(",");
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling fontSize",
function (context, dom_element, isd_element, attr) {
dom_element.style.fontSize = (attr * context.h) + "px";
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling fontStyle",
function (context, dom_element, isd_element, attr) {
dom_element.style.fontStyle = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling fontWeight",
function (context, dom_element, isd_element, attr) {
dom_element.style.fontWeight = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling lineHeight",
function (context, dom_element, isd_element, attr) {
if (attr === "normal") {
dom_element.style.lineHeight = "normal";
} else {
dom_element.style.lineHeight = (attr * context.h) + "px";
}
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling opacity",
function (context, dom_element, isd_element, attr) {
dom_element.style.opacity = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling origin",
function (context, dom_element, isd_element, attr) {
dom_element.style.top = (attr.h * context.h) + "px";
dom_element.style.left = (attr.w * context.w) + "px";
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling overflow",
function (context, dom_element, isd_element, attr) {
dom_element.style.overflow = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling padding",
function (context, dom_element, isd_element, attr) {
/* attr: top,left,bottom,right*/
/* style: top right bottom left*/
var rslt = [];
rslt[0] = (attr[0] * context.h) + "px";
rslt[1] = (attr[3] * context.w) + "px";
rslt[2] = (attr[2] * context.h) + "px";
rslt[3] = (attr[1] * context.w) + "px";
dom_element.style.padding = rslt.join(" ");
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling showBackground",
null
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling textAlign",
function (context, dom_element, isd_element, attr) {
var ta;
var dir = isd_element.styleAttrs[imscStyles.byName.direction.qname];
/* handle UAs that do not understand start or end */
if (attr === "start") {
ta = (dir === "rtl") ? "right" : "left";
} else if (attr === "end") {
ta = (dir === "rtl") ? "left" : "right";
} else {
ta = attr;
}
dom_element.style.textAlign = ta;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling textDecoration",
function (context, dom_element, isd_element, attr) {
dom_element.style.textDecoration = attr.join(" ").replace("lineThrough", "line-through");
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling textOutline",
function (context, dom_element, isd_element, attr) {
if (attr === "none") {
dom_element.style.textShadow = "";
} else {
dom_element.style.textShadow = "rgba(" +
attr.color[0].toString() + "," +
attr.color[1].toString() + "," +
attr.color[2].toString() + "," +
(attr.color[3] / 255).toString() +
")" + " 0px 0px " +
(attr.thickness * context.h) + "px";
}
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling unicodeBidi",
function (context, dom_element, isd_element, attr) {
var ub;
if (attr === 'bidiOverride') {
ub = "bidi-override";
} else {
ub = attr;
}
dom_element.style.unicodeBidi = ub;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling visibility",
function (context, dom_element, isd_element, attr) {
dom_element.style.visibility = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling wrapOption",
function (context, dom_element, isd_element, attr) {
if (attr === "wrap") {
if (isd_element.space === "preserve") {
dom_element.style.whiteSpace = "pre-wrap";
} else {
dom_element.style.whiteSpace = "normal";
}
} else {
if (isd_element.space === "preserve") {
dom_element.style.whiteSpace = "pre";
} else {
dom_element.style.whiteSpace = "noWrap";
}
}
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling writingMode",
function (context, dom_element, isd_element, attr) {
if (attr === "lrtb" || attr === "lr") {
dom_element.style.writingMode = "horizontal-tb";
} else if (attr === "rltb" || attr === "rl") {
dom_element.style.writingMode = "horizontal-tb";
} else if (attr === "tblr") {
dom_element.style.writingMode = "vertical-lr";
} else if (attr === "tbrl" || attr === "tb") {
dom_element.style.writingMode = "vertical-rl";
}
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml#styling zIndex",
function (context, dom_element, isd_element, attr) {
dom_element.style.zIndex = attr;
}
),
new HTMLStylingMapDefintion(
"http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt backgroundImage",
function (context, dom_element, isd_element, attr) {
if (context.imgResolver !== null && attr !== null) {
var img = document.createElement("img");
var uri = context.imgResolver(attr, img);
if (uri)
img.src = uri;
img.height = context.regionH;
img.width = context.regionW;
dom_element.appendChild(img);
}
}
),
new HTMLStylingMapDefintion(
"http://www.w3.org/ns/ttml/profile/imsc1#styling forcedDisplay",
function (context, dom_element, isd_element, attr) {
if (context.displayForcedOnlyMode && attr === false) {
dom_element.style.visibility = "hidden";
}
}
)
];
var STYLMAP_BY_QNAME = {};
for (var i in STYLING_MAP_DEFS) {
STYLMAP_BY_QNAME[STYLING_MAP_DEFS[i].qname] = STYLING_MAP_DEFS[i];
}
function reportError(errorHandler, msg) {
if (errorHandler && errorHandler.error && errorHandler.error(msg))
throw msg;
}
})( exports,
typeof imscNames === 'undefined' ? __webpack_require__(/*! ./names */ "./node_modules/imsc/src/main/js/names.js") : imscNames,
typeof imscStyles === 'undefined' ? __webpack_require__(/*! ./styles */ "./node_modules/imsc/src/main/js/styles.js") : imscStyles);
/***/ }),
/***/ "./node_modules/imsc/src/main/js/isd.js":
/*!**********************************************!*\
!*** ./node_modules/imsc/src/main/js/isd.js ***!
\**********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
(function (imscISD, imscNames, imscStyles) { // wrapper for non-node envs
/**
* Creates a canonical representation of an IMSC1 document returned by <pre>imscDoc.fromXML()</pre>
* at a given absolute offset in seconds. This offset does not have to be one of the values returned
* by <pre>getMediaTimeEvents()</pre>.
*
* @param {Object} tt IMSC1 document
* @param {number} offset Absolute offset (in seconds)
* @param {?module:imscUtils.ErrorHandler} errorHandler Error callback
* @returns {Object} Opaque in-memory representation of an ISD
*/
imscISD.generateISD = function (tt, offset, errorHandler) {
/* TODO check for tt and offset validity */
/* create the ISD object from the IMSC1 doc */
var isd = new ISD(tt);
/* context */
var context = {
/* empty for now */
};
/* process regions */
for (var r in tt.head.layout.regions) {
/* post-order traversal of the body tree per [construct intermediate document] */
var c = isdProcessContentElement(tt, offset, tt.head.layout.regions[r], tt.body, null, '', tt.head.layout.regions[r], errorHandler, context);
if (c !== null) {
/* add the region to the ISD */
isd.contents.push(c.element);
}
}
return isd;
};
function isdProcessContentElement(doc, offset, region, body, parent, inherited_region_id, elem, errorHandler, context) {
/* prune if temporally inactive */
if (offset < elem.begin || offset >= elem.end) {
return null;
}
/*
* set the associated region as specified by the regionID attribute, or the
* inherited associated region otherwise
*/
var associated_region_id = 'regionID' in elem && elem.regionID !== '' ? elem.regionID : inherited_region_id;
/* prune the element if either:
* - the element is not terminal and the associated region is neither the default
* region nor the parent region (this allows children to be associated with a
* region later on)
* - the element is terminal and the associated region is not the parent region
*/
/* TODO: improve detection of terminal elements since <region> has no contents */
if (parent !== null /* are we in the region element */ &&
associated_region_id !== region.id &&
(
(! ('contents' in elem)) ||
('contents' in elem && elem.contents.length === 0) ||
associated_region_id !== ''
)
)
return null;
/* create an ISD element, including applying specified styles */
var isd_element = new ISDContentElement(elem);
/* apply set (animation) styling */
for (var i in elem.sets) {
if (offset < elem.sets[i].begin || offset >= elem.sets[i].end)
continue;
isd_element.styleAttrs[elem.sets[i].qname] = elem.sets[i].value;
}
/*
* keep track of specified styling attributes so that we
* can compute them later
*/
var spec_attr = {};
for (var qname in isd_element.styleAttrs) {
spec_attr[qname] = true;
/* special rule for tts:writingMode (section 7.29.1 of XSL)
* direction is set consistently with writingMode only
* if writingMode sets inline-direction to LTR or RTL
*/
if (qname === imscStyles.byName.writingMode.qname &&
!(imscStyles.byName.direction.qname in isd_element.styleAttrs)) {
var wm = isd_element.styleAttrs[qname];
if (wm === "lrtb" || wm === "lr") {
isd_element.styleAttrs[imscStyles.byName.direction.qname] = "ltr";
} else if (wm === "rltb" || wm === "rl") {
isd_element.styleAttrs[imscStyles.byName.direction.qname] = "rtl";
}
}
}
/* inherited styling */
if (parent !== null) {
for (var j in imscStyles.all) {
var sa = imscStyles.all[j];
/* textDecoration has special inheritance rules */
if (sa.qname === imscStyles.byName.textDecoration.qname) {
/* handle both textDecoration inheritance and specification */
var ps = parent.styleAttrs[sa.qname];
var es = isd_element.styleAttrs[sa.qname];
var outs = [];
if (es === undefined) {
outs = ps;
} else if (es.indexOf("none") === -1) {
if ((es.indexOf("noUnderline") === -1 &&
ps.indexOf("underline") !== -1) ||
es.indexOf("underline") !== -1) {
outs.push("underline");
}
if ((es.indexOf("noLineThrough") === -1 &&
ps.indexOf("lineThrough") !== -1) ||
es.indexOf("lineThrough") !== -1) {
outs.push("lineThrough");
}
if ((es.indexOf("noOverline") === -1 &&
ps.indexOf("overline") !== -1) ||
es.indexOf("overline") !== -1) {
outs.push("overline");
}
} else {
outs.push("none");
}
isd_element.styleAttrs[sa.qname] = outs;
} else if (sa.inherit &&
(sa.qname in parent.styleAttrs) &&
!(sa.qname in isd_element.styleAttrs)) {
isd_element.styleAttrs[sa.qname] = parent.styleAttrs[sa.qname];
}
}
}
/* initial value styling */
for (var k in imscStyles.all) {
var ivs = imscStyles.all[k];
/* skip if value is already specified */
if (ivs.qname in isd_element.styleAttrs) continue;
/* apply initial value to elements other than region only if non-inherited */
if (isd_element.kind === 'region' || (ivs.inherit === false && ivs.initial !== null)) {
isd_element.styleAttrs[ivs.qname] = ivs.parse(ivs.initial);
/* keep track of the style as specified */
spec_attr[ivs.qname] = true;
}
}
/* compute styles (only for non-inherited styles) */
/* TODO: get rid of spec_attr */
for (var z in imscStyles.all) {
var cs = imscStyles.all[z];
if (!(cs.qname in spec_attr)) continue;
if (cs.compute !== null) {
var cstyle = cs.compute(
/*doc, parent, element, attr, context*/
doc,
parent,
isd_element,
isd_element.styleAttrs[cs.qname],
context
);
if (cstyle !== null) {
isd_element.styleAttrs[cs.qname] = cstyle;
} else {
reportError(errorHandler, "Style '" + cs.qname + "' on element '" + isd_element.kind + "' cannot be computed");
}
}
}
/* prune if tts:display is none */
if (isd_element.styleAttrs[imscStyles.byName.display.qname] === "none")
return null;
/* process contents of the element */
var contents;
if (parent === null) {
/* we are processing the region */
if (body === null) {
/* if there is no body, still process the region but with empty content */
contents = [];
} else {
/*use the body element as contents */
contents = [body];
}
} else if ('contents' in elem) {
contents = elem.contents;
}
for (var x in contents) {
var c = isdProcessContentElement(doc, offset, region, body, isd_element, associated_region_id, contents[x], errorHandler, context);
/*
* keep child element only if they are non-null and their region match
* the region of this element
*/
if (c !== null) {
isd_element.contents.push(c.element);
}
}
/* compute used value of lineHeight="normal" */
/* if (isd_element.styleAttrs[imscStyles.byName.lineHeight.qname] === "normal" ) {
isd_element.styleAttrs[imscStyles.byName.lineHeight.qname] =
isd_element.styleAttrs[imscStyles.byName.fontSize.qname] * 1.2;
}
*/
/* remove styles that are not applicable */
for (var qnameb in isd_element.styleAttrs) {
var da = imscStyles.byQName[qnameb];
if (da.applies.indexOf(isd_element.kind) === -1) {
delete isd_element.styleAttrs[qnameb];
}
}
/* collapse white space if space is "default" */
if (isd_element.kind === 'span' && isd_element.text && isd_element.space === "default") {
var trimmedspan = isd_element.text.replace(/\s+/g, ' ');
isd_element.text = trimmedspan;
}
/* trim whitespace around explicit line breaks */
if (isd_element.kind === 'p') {
var elist = [];
constructSpanList(isd_element, elist);
var l = 0;
var state = "after_br";
var br_pos = 0;
while (true) {
if (state === "after_br") {
if (l >= elist.length || elist[l].kind === "br") {
state = "before_br";
br_pos = l;
l--;
} else {
if (elist[l].space !== "preserve") {
elist[l].text = elist[l].text.replace(/^\s+/g, '');
}
if (elist[l].text.length > 0) {
state = "looking_br";
l++;
} else {
elist.splice(l, 1);
}
}
} else if (state === "before_br") {
if (l < 0 || elist[l].kind === "br") {
state = "after_br";
l = br_pos + 1;
if (l >= elist.length) break;
} else {
if (elist[l].space !== "preserve") {
elist[l].text = elist[l].text.replace(/\s+$/g, '');
}
if (elist[l].text.length > 0) {
state = "after_br";
l = br_pos + 1;
if (l >= elist.length) break;
} else {
elist.splice(l, 1);
l--;
}
}
} else {
if (l >= elist.length || elist[l].kind === "br") {
state = "before_br";
br_pos = l;
l--;
} else {
l++;
}
}
}
pruneEmptySpans(isd_element);
}
/* keep element if:
* * contains a background image
* * <br/>
* * if there are children
* * if <span> and has text
* * if region and showBackground = always
*/
if ((isd_element.kind === 'div' && imscStyles.byName.backgroundImage.qname in isd_element.styleAttrs) ||
isd_element.kind === 'br' ||
('contents' in isd_element && isd_element.contents.length > 0) ||
(isd_element.kind === 'span' && isd_element.text !== null) ||
(isd_element.kind === 'region' &&
isd_element.styleAttrs[imscStyles.byName.showBackground.qname] === 'always')) {
return {
region_id: associated_region_id,
element: isd_element
};
}
return null;
}
function constructSpanList(element, elist) {
if ('contents' in element) {
for (var i in element.contents) {
constructSpanList(element.contents[i], elist);
}
} else {
elist.push(element);
}
}
function pruneEmptySpans(element) {
if (element.kind === 'br') {
return false;
} else if ('text' in element) {
return element.text.length === 0;
} else if ('contents' in element) {
var i = element.contents.length;
while (i--) {
if (pruneEmptySpans(element.contents[i])) {
element.contents.splice(i, 1);
}
}
return element.contents.length === 0;
}
}
function ISD(tt) {
this.contents = [];
this.aspectRatio = tt.aspectRatio;
}
function ISDContentElement(ttelem) {
/* assume the element is a region if it does not have a kind */
this.kind = ttelem.kind || 'region';
/* copy id */
if (ttelem.id) {
this.id = ttelem.id;
}
/* deep copy of style attributes */
this.styleAttrs = {};
for (var sname in ttelem.styleAttrs) {
this.styleAttrs[sname] =
ttelem.styleAttrs[sname];
}
/* TODO: clean this! */
if ('text' in ttelem) {
this.text = ttelem.text;
} else if (ttelem.kind !== 'br') {
this.contents = [];
}
if ('space' in ttelem) {
this.space = ttelem.space;
}
}
function reportError(errorHandler, msg) {
if (errorHandler && errorHandler.error && errorHandler.error(msg))
throw msg;
}
})( exports,
typeof imscNames === 'undefined' ? __webpack_require__(/*! ./names */ "./node_modules/imsc/src/main/js/names.js") : imscNames,
typeof imscStyles === 'undefined' ? __webpack_require__(/*! ./styles */ "./node_modules/imsc/src/main/js/styles.js") : imscStyles
);
/***/ }),
/***/ "./node_modules/imsc/src/main/js/main.js":
/*!***********************************************!*\
!*** ./node_modules/imsc/src/main/js/main.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*
* Copyright (c) 2016, Pierre-Anthony Lemieux <pal@sandflow.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
exports.generateISD = __webpack_require__(/*! ./isd */ "./node_modules/imsc/src/main/js/isd.js").generateISD;
exports.fromXML = __webpack_require__(/*! ./doc */ "./node_modules/imsc/src/main/js/doc.js").fromXML;
exports.renderHTML = __webpack_require__(/*! ./html */ "./node_modules/imsc/src/main/js/html.js").render;
/***/ }),
/***/ "./node_modules/imsc/src/main/js/names.js":
/*!************************************************!*\
!*** ./node_modules/imsc/src/main/js/names.js ***!
\************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
(function (imscNames) { // wrapper for non-node envs
imscNames.ns_tt = "http://www.w3.org/ns/ttml";
imscNames.ns_tts = "http://www.w3.org/ns/ttml#styling";
imscNames.ns_ttp = "http://www.w3.org/ns/ttml#parameter";
imscNames.ns_xml = "http://www.w3.org/XML/1998/namespace";
imscNames.ns_itts = "http://www.w3.org/ns/ttml/profile/imsc1#styling";
imscNames.ns_ittp = "http://www.w3.org/ns/ttml/profile/imsc1#parameter";
imscNames.ns_smpte = "http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt";
imscNames.ns_ebutts = "urn:ebu:tt:style";
})( exports);
/***/ }),
/***/ "./node_modules/imsc/src/main/js/styles.js":
/*!*************************************************!*\
!*** ./node_modules/imsc/src/main/js/styles.js ***!
\*************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
(function (imscStyles, imscNames, imscUtils) { // wrapper for non-node envs
function StylingAttributeDefinition(ns, name, initialValue, appliesTo, isInherit, isAnimatable, parseFunc, computeFunc) {
this.name = name;
this.ns = ns;
this.qname = ns + " " + name;
this.inherit = isInherit;
this.animatable = isAnimatable;
this.initial = initialValue;
this.applies = appliesTo;
this.parse = parseFunc;
this.compute = computeFunc;
}
imscStyles.all = [
new StylingAttributeDefinition(
imscNames.ns_tts,
"backgroundColor",
"transparent",
['body', 'div', 'p', 'region', 'span'],
false,
true,
imscUtils.parseColor,
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"color",
"white",
['span'],
true,
true,
imscUtils.parseColor,
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"direction",
"ltr",
['p', 'span'],
true,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"display",
"auto",
['body', 'div', 'p', 'region', 'span'],
false,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"displayAlign",
"before",
['region'],
false,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"extent",
"auto",
['tt', 'region'],
false,
true,
function (str) {
if (str === "auto") {
return str;
} else {
var s = str.split(" ");
if (s.length !== 2) return null;
var w = imscUtils.parseLength(s[0]);
var h = imscUtils.parseLength(s[1]);
if (!h || !w) return null;
return {'h': h, 'w': w};
}
},
function (doc, parent, element, attr, context) {
var h;
var w;
if (attr === "auto") {
h = 1;
} else if (attr.h.unit === "%") {
h = attr.h.value / 100;
} else if (attr.h.unit === "px") {
h = attr.h.value / doc.pxDimensions.h;
} else {
return null;
}
if (attr === "auto") {
w = 1;
} else if (attr.w.unit === "%") {
w = attr.w.value / 100;
} else if (attr.w.unit === "px") {
w = attr.w.value / doc.pxDimensions.w;
} else {
return null;
}
return {'h': h, 'w': w};
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"fontFamily",
"default",
['span'],
true,
true,
function (str) {
var ffs = str.split(",");
var rslt = [];
for (var i in ffs) {
if (ffs[i].charAt(0) !== "'" && ffs[i].charAt(0) !== '"') {
if (ffs[i] === "default") {
/* per IMSC1 */
rslt.push("monospaceSerif");
} else {
rslt.push(ffs[i]);
}
} else {
rslt.push(ffs[i]);
}
}
return rslt;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"fontSize",
"1c",
['span'],
true,
true,
imscUtils.parseLength,
function (doc, parent, element, attr, context) {
var fs;
if (attr.unit === "%") {
if (parent !== null) {
fs = parent.styleAttrs[imscStyles.byName.fontSize.qname] * attr.value / 100;
} else {
/* region, so percent of 1c */
fs = attr.value / 100 / doc.cellResolution.h;
}
} else if (attr.unit === "em") {
if (parent !== null) {
fs = parent.styleAttrs[imscStyles.byName.fontSize.qname] * attr.value;
} else {
/* region, so percent of 1c */
fs = attr.value / doc.cellResolution.h;
}
} else if (attr.unit === "c") {
fs = attr.value / doc.cellResolution.h;
} else if (attr.unit === "px") {
fs = attr.value / doc.pxDimensions.h;
} else {
return null;
}
return fs;
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"fontStyle",
"normal",
['span'],
true,
true,
function (str) {
/* TODO: handle font style */
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"fontWeight",
"normal",
['span'],
true,
true,
function (str) {
/* TODO: handle font weight */
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"lineHeight",
"normal",
['p'],
true,
true,
function (str) {
if (str === "normal") {
return str;
} else {
return imscUtils.parseLength(str);
}
},
function (doc, parent, element, attr, context) {
var lh;
if (attr === "normal") {
/* inherit normal per https://github.com/w3c/ttml1/issues/220 */
lh = attr;
} else if (attr.unit === "%") {
lh = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.value / 100;
} else if (attr.unit === "em") {
lh = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.value;
} else if (attr.unit === "c") {
lh = attr.value / doc.cellResolution.h;
} else if (attr.unit === "px") {
/* TODO: handle error if no px dimensions are provided */
lh = attr.value / doc.pxDimensions.h;
} else {
return null;
}
/* TODO: create a Length constructor */
return lh;
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"opacity",
1.0,
['region'],
false,
true,
parseFloat,
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"origin",
"auto",
['region'],
false,
true,
function (str) {
if (str === "auto") {
return str;
} else {
var s = str.split(" ");
if (s.length !== 2) return null;
var w = imscUtils.parseLength(s[0]);
var h = imscUtils.parseLength(s[1]);
if (!h || !w) return null;
return {'h': h, 'w': w};
}
},
function (doc, parent, element, attr, context) {
var h;
var w;
if (attr === "auto") {
h = 0;
} else if (attr.h.unit === "%") {
h = attr.h.value / 100;
} else if (attr.h.unit === "px") {
h = attr.h.value / doc.pxDimensions.h;
} else {
return null;
}
if (attr === "auto") {
w = 0;
} else if (attr.w.unit === "%") {
w = attr.w.value / 100;
} else if (attr.w.unit === "px") {
w = attr.w.value / doc.pxDimensions.w;
} else {
return null;
}
return {'h': h, 'w': w};
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"overflow",
"hidden",
['region'],
false,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"padding",
"0px",
['region'],
false,
true,
function (str) {
var s = str.split(" ");
if (s.length > 4) return null;
var r = [];
for (var i in s) {
var l = imscUtils.parseLength(s[i]);
if (!l) return null;
r.push(l);
}
return r;
},
function (doc, parent, element, attr, context) {
var padding;
/* TODO: make sure we are in region */
/*
* expand padding shortcuts to
* [before, end, after, start]
*
*/
if (attr.length === 1) {
padding = [attr[0], attr[0], attr[0], attr[0]];
} else if (attr.length === 2) {
padding = [attr[0], attr[1], attr[0], attr[1]];
} else if (attr.length === 3) {
padding = [attr[0], attr[1], attr[2], attr[1]];
} else if (attr.length === 4) {
padding = [attr[0], attr[1], attr[2], attr[3]];
} else {
return null;
}
/* TODO: take into account tts:direction */
/*
* transform [before, end, after, start] according to writingMode to
* [top,left,bottom,right]
*
*/
var dir = element.styleAttrs[imscStyles.byName.writingMode.qname];
if (dir === "lrtb" || dir === "lr") {
padding = [padding[0], padding[3], padding[2], padding[1]];
} else if (dir === "rltb" || dir === "rl") {
padding = [padding[0], padding[1], padding[2], padding[3]];
} else if (dir === "tblr") {
padding = [padding[3], padding[0], padding[1], padding[2]];
} else if (dir === "tbrl" || dir === "tb") {
padding = [padding[3], padding[2], padding[1], padding[0]];
} else {
return null;
}
var out = [];
for (var i in padding) {
if (padding[i].value === 0) {
out[i] = 0;
} else if (padding[i].unit === "%") {
if (i === "0" || i === "2") {
out[i] = element.styleAttrs[imscStyles.byName.extent.qname].h * padding[i].value / 100;
} else {
out[i] = element.styleAttrs[imscStyles.byName.extent.qname].w * padding[i].value / 100;
}
} else if (padding[i].unit === "em") {
out[i] = element.styleAttrs[imscStyles.byName.fontSize.qname] * padding[i].value;
} else if (padding[i].unit === "c") {
out[i] = padding[i].value / doc.cellResolution.h;
} else if (padding[i].unit === "px") {
if (i === "0" || i === "2") {
out[i] = padding[i].value / doc.pxDimensions.h;
} else {
out[i] = padding[i].value / doc.pxDimensions.w;
}
} else {
return null;
}
}
return out;
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"showBackground",
"always",
['region'],
false,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"textAlign",
"start",
['p'],
true,
true,
function (str) {
return str;
},
function (doc, parent, element, attr, context) {
/* Section 7.16.9 of XSL */
if (attr === "left") {
return "start";
} else if (attr === "right") {
return "end";
} else {
return attr;
}
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"textDecoration",
"none",
['span'],
true,
true,
function (str) {
return str.split(" ");
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"textOutline",
"none",
['span'],
true,
true,
function (str) {
/*
* returns {c: <color>?, thichness: <length>} | "none"
*
*/
if (str === "none") {
return str;
} else {
var r = {};
var s = str.split(" ");
if (s.length === 0 || s.length > 2) return null;
var c = imscUtils.parseColor(s[0]);
r.color = c;
if (c !== null) s.shift();
if (s.length !== 1) return null;
var l = imscUtils.parseLength(s[0]);
if (!l) return null;
r.thickness = l;
return r;
}
},
function (doc, parent, element, attr, context) {
/*
* returns {color: <color>, thickness: <norm length>}
*
*/
if (attr === "none") return attr;
var rslt = {};
if (attr.color === null) {
rslt.color = element.styleAttrs[imscStyles.byName.color.qname];
} else {
rslt.color = attr.color;
}
if (attr.thickness.unit === "%") {
rslt.thickness = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.thickness.value / 100;
} else if (attr.thickness.unit === "em") {
rslt.thickness = element.styleAttrs[imscStyles.byName.fontSize.qname] * attr.thickness.value;
} else if (attr.thickness.unit === "c") {
rslt.thickness = attr.thickness.value / doc.cellResolution.h;
} else if (attr.thickness.unit === "px") {
rslt.thickness = attr.thickness.value / doc.pxDimensions.h;
} else {
return null;
}
return rslt;
}
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"unicodeBidi",
"normal",
['span', 'p'],
false,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"visibility",
"visible",
['body', 'div', 'p', 'region', 'span'],
true,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"wrapOption",
"wrap",
['span'],
true,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"writingMode",
"lrtb",
['region'],
false,
true,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_tts,
"zIndex",
"auto",
['region'],
false,
true,
function (str) {
var rslt;
if (str === 'auto') {
rslt = str;
} else {
rslt = parseInt(str);
if (isNaN(rslt)) {
rslt = null;
}
}
return rslt;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_ebutts,
"linePadding",
"0c",
['p'],
true,
false,
imscUtils.parseLength,
function (doc, parent, element, attr, context) {
if (attr.unit === "c") {
return attr.value / doc.cellResolution.h;
} else {
return null;
}
}
),
new StylingAttributeDefinition(
imscNames.ns_ebutts,
"multiRowAlign",
"auto",
['p'],
true,
false,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_smpte,
"backgroundImage",
null,
['div'],
false,
false,
function (str) {
return str;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_itts,
"forcedDisplay",
"false",
['body', 'div', 'p', 'region', 'span'],
true,
true,
function (str) {
return str === 'true' ? true : false;
},
null
),
new StylingAttributeDefinition(
imscNames.ns_itts,
"fillLineGap",
"false",
['p'],
true,
true,
function (str) {
return str === 'true' ? true : false;
},
null
)
];
/* TODO: allow null parse function */
imscStyles.byQName = {};
for (var i in imscStyles.all) {
imscStyles.byQName[imscStyles.all[i].qname] = imscStyles.all[i];
}
imscStyles.byName = {};
for (var j in imscStyles.all) {
imscStyles.byName[imscStyles.all[j].name] = imscStyles.all[j];
}
})( exports,
typeof imscNames === 'undefined' ? __webpack_require__(/*! ./names */ "./node_modules/imsc/src/main/js/names.js") : imscNames,
typeof imscUtils === 'undefined' ? __webpack_require__(/*! ./utils */ "./node_modules/imsc/src/main/js/utils.js") : imscUtils);
/***/ }),
/***/ "./node_modules/imsc/src/main/js/utils.js":
/*!************************************************!*\
!*** ./node_modules/imsc/src/main/js/utils.js ***!
\************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
(function (imscUtils) { // wrapper for non-node envs
/* Documents the error handler interface */
/**
* @classdesc Generic interface for handling events. The interface exposes four
* methods:
* * <pre>info</pre>: unusual event that does not result in an inconsistent state
* * <pre>warn</pre>: unexpected event that should not result in an inconsistent state
* * <pre>error</pre>: unexpected event that may result in an inconsistent state
* * <pre>fatal</pre>: unexpected event that results in an inconsistent state
* and termination of processing
* Each method takes a single <pre>string</pre> describing the event as argument,
* and returns a single <pre>boolean</pre>, which terminates processing if <pre>true</pre>.
*
* @name ErrorHandler
* @class
*/
/*
* Parses a TTML color expression
*
*/
var HEX_COLOR_RE = /#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?/;
var DEC_COLOR_RE = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
var DEC_COLORA_RE = /rgba\(\s*(\d+),\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
var NAMED_COLOR = {
transparent: [0, 0, 0, 0],
black: [0, 0, 0, 255],
silver: [192, 192, 192, 255],
gray: [128, 128, 128, 255],
white: [255, 255, 255, 255],
maroon: [128, 0, 0, 255],
red: [255, 0, 0, 255],
purple: [128, 0, 128, 255],
fuchsia: [255, 0, 255, 255],
magenta: [255, 0, 255, 255],
green: [0, 128, 0, 255],
lime: [0, 255, 0, 255],
olive: [128, 128, 0, 255],
yellow: [255, 255, 0, 255],
navy: [0, 0, 128, 255],
blue: [0, 0, 255, 255],
teal: [0, 128, 128, 255],
aqua: [0, 255, 255, 255],
cyan: [0, 255, 255, 255]
};
imscUtils.parseColor = function (str) {
var m;
var r = null;
var nc = NAMED_COLOR[str.toLowerCase()];
if (nc !== undefined) {
r = nc;
} else if ((m = HEX_COLOR_RE.exec(str)) !== null) {
r = [parseInt(m[1], 16),
parseInt(m[2], 16),
parseInt(m[3], 16),
(m[4] !== undefined ? parseInt(m[4], 16) : 255)];
} else if ((m = DEC_COLOR_RE.exec(str)) !== null) {
r = [parseInt(m[1]),
parseInt(m[2]),
parseInt(m[3]),
255];
} else if ((m = DEC_COLORA_RE.exec(str)) !== null) {
r = [parseInt(m[1]),
parseInt(m[2]),
parseInt(m[3]),
parseInt(m[4])];
}
return r;
};
var LENGTH_RE = /^((?:\+|\-)?\d*(?:\.\d+)?)(px|em|c|%)$/;
imscUtils.parseLength = function (str) {
var m;
var r = null;
if ((m = LENGTH_RE.exec(str)) !== null) {
r = {value: parseFloat(m[1]), unit: m[2]};
}
return r;
};
})( exports);
/***/ }),
/***/ "./node_modules/inherits/inherits_browser.js":
/*!***************************************************!*\
!*** ./node_modules/inherits/inherits_browser.js ***!
\***************************************************/
/*! no static exports found */
/***/ (function(module, exports) {
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function () {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
};
}
/***/ }),
/***/ "./node_modules/isarray/index.js":
/*!***************************************!*\
!*** ./node_modules/isarray/index.js ***!
\***************************************/
/*! no static exports found */
/***/ (function(module, exports) {
var toString = {}.toString;
module.exports = Array.isArray || function (arr) {
return toString.call(arr) == '[object Array]';
};
/***/ }),
/***/ "./node_modules/node-libs-browser/node_modules/buffer/index.js":
/*!*********************************************************************!*\
!*** ./node_modules/node-libs-browser/node_modules/buffer/index.js ***!
\*********************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/
/* eslint-disable no-proto */
var base64 = __webpack_require__(/*! base64-js */ "./node_modules/base64-js/index.js");
var ieee754 = __webpack_require__(/*! ieee754 */ "./node_modules/ieee754/index.js");
var isArray = __webpack_require__(/*! isarray */ "./node_modules/isarray/index.js");
exports.Buffer = Buffer;
exports.SlowBuffer = SlowBuffer;
exports.INSPECT_MAX_BYTES = 50;
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Due to various browser bugs, sometimes the Object implementation will be used even
* when the browser supports typed arrays.
*
* Note:
*
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport();
/*
* Export kMaxLength after typed array support is determined.
*/
exports.kMaxLength = kMaxLength();
function typedArraySupport () {
try {
var arr = new Uint8Array(1);
arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }};
return arr.foo() === 42 && // typed array instances can be augmented
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
} catch (e) {
return false
}
}
function kMaxLength () {
return Buffer.TYPED_ARRAY_SUPPORT
? 0x7fffffff
: 0x3fffffff
}
function createBuffer (that, length) {
if (kMaxLength() < length) {
throw new RangeError('Invalid typed array length')
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
that = new Uint8Array(length);
that.__proto__ = Buffer.prototype;
} else {
// Fallback: Return an object instance of the Buffer class
if (that === null) {
that = new Buffer(length);
}
that.length = length;
}
return that
}
/**
* The Buffer constructor returns instances of `Uint8Array` that have their
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
* returns a single octet.
*
* The `Uint8Array` prototype remains unmodified.
*/
function Buffer (arg, encodingOrOffset, length) {
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
return new Buffer(arg, encodingOrOffset, length)
}
// Common case.
if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') {
throw new Error(
'If encoding is specified then the first argument must be a string'
)
}
return allocUnsafe(this, arg)
}
return from(this, arg, encodingOrOffset, length)
}
Buffer.poolSize = 8192; // not used by this implementation
// TODO: Legacy, not needed anymore. Remove in next major version.
Buffer._augment = function (arr) {
arr.__proto__ = Buffer.prototype;
return arr
};
function from (that, value, encodingOrOffset, length) {
if (typeof value === 'number') {
throw new TypeError('"value" argument must not be a number')
}
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
return fromArrayBuffer(that, value, encodingOrOffset, length)
}
if (typeof value === 'string') {
return fromString(that, value, encodingOrOffset)
}
return fromObject(that, value)
}
/**
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
* if value is a number.
* Buffer.from(str[, encoding])
* Buffer.from(array)
* Buffer.from(buffer)
* Buffer.from(arrayBuffer[, byteOffset[, length]])
**/
Buffer.from = function (value, encodingOrOffset, length) {
return from(null, value, encodingOrOffset, length)
};
if (Buffer.TYPED_ARRAY_SUPPORT) {
Buffer.prototype.__proto__ = Uint8Array.prototype;
Buffer.__proto__ = Uint8Array;
if (typeof Symbol !== 'undefined' && Symbol.species &&
Buffer[Symbol.species] === Buffer) {
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
Object.defineProperty(Buffer, Symbol.species, {
value: null,
configurable: true
});
}
}
function assertSize (size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be a number')
} else if (size < 0) {
throw new RangeError('"size" argument must not be negative')
}
}
function alloc (that, size, fill, encoding) {
assertSize(size);
if (size <= 0) {
return createBuffer(that, size)
}
if (fill !== undefined) {
// Only pay attention to encoding if it's a string. This
// prevents accidentally sending in a number that would
// be interpretted as a start offset.
return typeof encoding === 'string'
? createBuffer(that, size).fill(fill, encoding)
: createBuffer(that, size).fill(fill)
}
return createBuffer(that, size)
}
/**
* Creates a new filled Buffer instance.
* alloc(size[, fill[, encoding]])
**/
Buffer.alloc = function (size, fill, encoding) {
return alloc(null, size, fill, encoding)
};
function allocUnsafe (that, size) {
assertSize(size);
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
if (!Buffer.TYPED_ARRAY_SUPPORT) {
for (var i = 0; i < size; ++i) {
that[i] = 0;
}
}
return that
}
/**
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
* */
Buffer.allocUnsafe = function (size) {
return allocUnsafe(null, size)
};
/**
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
*/
Buffer.allocUnsafeSlow = function (size) {
return allocUnsafe(null, size)
};
function fromString (that, string, encoding) {
if (typeof encoding !== 'string' || encoding === '') {
encoding = 'utf8';
}
if (!Buffer.isEncoding(encoding)) {
throw new TypeError('"encoding" must be a valid string encoding')
}
var length = byteLength(string, encoding) | 0;
that = createBuffer(that, length);
var actual = that.write(string, encoding);
if (actual !== length) {
// Writing a hex string, for example, that contains invalid characters will
// cause everything after the first invalid character to be ignored. (e.g.
// 'abxxcd' will be treated as 'ab')
that = that.slice(0, actual);
}
return that
}
function fromArrayLike (that, array) {
var length = array.length < 0 ? 0 : checked(array.length) | 0;
that = createBuffer(that, length);
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255;
}
return that
}
function fromArrayBuffer (that, array, byteOffset, length) {
array.byteLength; // this throws if `array` is not a valid ArrayBuffer
if (byteOffset < 0 || array.byteLength < byteOffset) {
throw new RangeError('\'offset\' is out of bounds')
}
if (array.byteLength < byteOffset + (length || 0)) {
throw new RangeError('\'length\' is out of bounds')
}
if (byteOffset === undefined && length === undefined) {
array = new Uint8Array(array);
} else if (length === undefined) {
array = new Uint8Array(array, byteOffset);
} else {
array = new Uint8Array(array, byteOffset, length);
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
that = array;
that.__proto__ = Buffer.prototype;
} else {
// Fallback: Return an object instance of the Buffer class
that = fromArrayLike(that, array);
}
return that
}
function fromObject (that, obj) {
if (Buffer.isBuffer(obj)) {
var len = checked(obj.length) | 0;
that = createBuffer(that, len);
if (that.length === 0) {
return that
}
obj.copy(that, 0, 0, len);
return that
}
if (obj) {
if ((typeof ArrayBuffer !== 'undefined' &&
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
if (typeof obj.length !== 'number' || isnan(obj.length)) {
return createBuffer(that, 0)
}
return fromArrayLike(that, obj)
}
if (obj.type === 'Buffer' && isArray(obj.data)) {
return fromArrayLike(that, obj.data)
}
}
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
}
function checked (length) {
// Note: cannot use `length < kMaxLength()` here because that fails when
// length is NaN (which is otherwise coerced to zero.)
if (length >= kMaxLength()) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + kMaxLength().toString(16) + ' bytes')
}
return length | 0
}
function SlowBuffer (length) {
if (+length != length) { // eslint-disable-line eqeqeq
length = 0;
}
return Buffer.alloc(+length)
}
Buffer.isBuffer = function isBuffer (b) {
return !!(b != null && b._isBuffer)
};
Buffer.compare = function compare (a, b) {
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
throw new TypeError('Arguments must be Buffers')
}
if (a === b) return 0
var x = a.length;
var y = b.length;
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
if (a[i] !== b[i]) {
x = a[i];
y = b[i];
break
}
}
if (x < y) return -1
if (y < x) return 1
return 0
};
Buffer.isEncoding = function isEncoding (encoding) {
switch (String(encoding).toLowerCase()) {
case 'hex':
case 'utf8':
case 'utf-8':
case 'ascii':
case 'latin1':
case 'binary':
case 'base64':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return true
default:
return false
}
};
Buffer.concat = function concat (list, length) {
if (!isArray(list)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
if (list.length === 0) {
return Buffer.alloc(0)
}
var i;
if (length === undefined) {
length = 0;
for (i = 0; i < list.length; ++i) {
length += list[i].length;
}
}
var buffer = Buffer.allocUnsafe(length);
var pos = 0;
for (i = 0; i < list.length; ++i) {
var buf = list[i];
if (!Buffer.isBuffer(buf)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
buf.copy(buffer, pos);
pos += buf.length;
}
return buffer
};
function byteLength (string, encoding) {
if (Buffer.isBuffer(string)) {
return string.length
}
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
return string.byteLength
}
if (typeof string !== 'string') {
string = '' + string;
}
var len = string.length;
if (len === 0) return 0
// Use a for loop to avoid recursion
var loweredCase = false;
for (;;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
return len
case 'utf8':
case 'utf-8':
case undefined:
return utf8ToBytes(string).length
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return len * 2
case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) return utf8ToBytes(string).length // assume utf8
encoding = ('' + encoding).toLowerCase();
loweredCase = true;
}
}
}
Buffer.byteLength = byteLength;
function slowToString (encoding, start, end) {
var loweredCase = false;
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
// property of a typed array.
// This behaves neither like String nor Uint8Array in that we set start/end
// to their upper/lower bounds if the value passed is out of range.
// undefined is handled specially as per ECMA-262 6th Edition,
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
if (start === undefined || start < 0) {
start = 0;
}
// Return early if start > this.length. Done here to prevent potential uint32
// coercion fail below.
if (start > this.length) {
return ''
}
if (end === undefined || end > this.length) {
end = this.length;
}
if (end <= 0) {
return ''
}
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
end >>>= 0;
start >>>= 0;
if (end <= start) {
return ''
}
if (!encoding) encoding = 'utf8';
while (true) {
switch (encoding) {
case 'hex':
return hexSlice(this, start, end)
case 'utf8':
case 'utf-8':
return utf8Slice(this, start, end)
case 'ascii':
return asciiSlice(this, start, end)
case 'latin1':
case 'binary':
return latin1Slice(this, start, end)
case 'base64':
return base64Slice(this, start, end)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16leSlice(this, start, end)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase();
loweredCase = true;
}
}
}
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
// Buffer instances.
Buffer.prototype._isBuffer = true;
function swap (b, n, m) {
var i = b[n];
b[n] = b[m];
b[m] = i;
}
Buffer.prototype.swap16 = function swap16 () {
var len = this.length;
if (len % 2 !== 0) {
throw new RangeError('Buffer size must be a multiple of 16-bits')
}
for (var i = 0; i < len; i += 2) {
swap(this, i, i + 1);
}
return this
};
Buffer.prototype.swap32 = function swap32 () {
var len = this.length;
if (len % 4 !== 0) {
throw new RangeError('Buffer size must be a multiple of 32-bits')
}
for (var i = 0; i < len; i += 4) {
swap(this, i, i + 3);
swap(this, i + 1, i + 2);
}
return this
};
Buffer.prototype.swap64 = function swap64 () {
var len = this.length;
if (len % 8 !== 0) {
throw new RangeError('Buffer size must be a multiple of 64-bits')
}
for (var i = 0; i < len; i += 8) {
swap(this, i, i + 7);
swap(this, i + 1, i + 6);
swap(this, i + 2, i + 5);
swap(this, i + 3, i + 4);
}
return this
};
Buffer.prototype.toString = function toString () {
var length = this.length | 0;
if (length === 0) return ''
if (arguments.length === 0) return utf8Slice(this, 0, length)
return slowToString.apply(this, arguments)
};
Buffer.prototype.equals = function equals (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true
return Buffer.compare(this, b) === 0
};
Buffer.prototype.inspect = function inspect () {
var str = '';
var max = exports.INSPECT_MAX_BYTES;
if (this.length > 0) {
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
if (this.length > max) str += ' ... ';
}
return '<Buffer ' + str + '>'
};
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
if (!Buffer.isBuffer(target)) {
throw new TypeError('Argument must be a Buffer')
}
if (start === undefined) {
start = 0;
}
if (end === undefined) {
end = target ? target.length : 0;
}
if (thisStart === undefined) {
thisStart = 0;
}
if (thisEnd === undefined) {
thisEnd = this.length;
}
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
throw new RangeError('out of range index')
}
if (thisStart >= thisEnd && start >= end) {
return 0
}
if (thisStart >= thisEnd) {
return -1
}
if (start >= end) {
return 1
}
start >>>= 0;
end >>>= 0;
thisStart >>>= 0;
thisEnd >>>= 0;
if (this === target) return 0
var x = thisEnd - thisStart;
var y = end - start;
var len = Math.min(x, y);
var thisCopy = this.slice(thisStart, thisEnd);
var targetCopy = target.slice(start, end);
for (var i = 0; i < len; ++i) {
if (thisCopy[i] !== targetCopy[i]) {
x = thisCopy[i];
y = targetCopy[i];
break
}
}
if (x < y) return -1
if (y < x) return 1
return 0
};
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
//
// Arguments:
// - buffer - a Buffer to search
// - val - a string, Buffer, or number
// - byteOffset - an index into `buffer`; will be clamped to an int32
// - encoding - an optional encoding, relevant is val is a string
// - dir - true for indexOf, false for lastIndexOf
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
// Empty buffer means no match
if (buffer.length === 0) return -1
// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset;
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
byteOffset = dir ? 0 : (buffer.length - 1);
}
// Normalize byteOffset: negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
if (byteOffset >= buffer.length) {
if (dir) return -1
else byteOffset = buffer.length - 1;
} else if (byteOffset < 0) {
if (dir) byteOffset = 0;
else return -1
}
// Normalize val
if (typeof val === 'string') {
val = Buffer.from(val, encoding);
}
// Finally, search either indexOf (if dir is true) or lastIndexOf
if (Buffer.isBuffer(val)) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
} else if (typeof val === 'number') {
val = val & 0xFF; // Search for a byte value [0-255]
if (Buffer.TYPED_ARRAY_SUPPORT &&
typeof Uint8Array.prototype.indexOf === 'function') {
if (dir) {
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
} else {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
}
throw new TypeError('val must be string, number or Buffer')
}
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
var indexSize = 1;
var arrLength = arr.length;
var valLength = val.length;
if (encoding !== undefined) {
encoding = String(encoding).toLowerCase();
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
encoding === 'utf16le' || encoding === 'utf-16le') {
if (arr.length < 2 || val.length < 2) {
return -1
}
indexSize = 2;
arrLength /= 2;
valLength /= 2;
byteOffset /= 2;
}
}
function read (buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
}
var i;
if (dir) {
var foundIndex = -1;
for (i = byteOffset; i < arrLength; i++) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i;
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex;
foundIndex = -1;
}
}
} else {
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
for (i = byteOffset; i >= 0; i--) {
var found = true;
for (var j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {
found = false;
break
}
}
if (found) return i
}
}
return -1
}
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
return this.indexOf(val, byteOffset, encoding) !== -1
};
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
};
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
};
function hexWrite (buf, string, offset, length) {
offset = Number(offset) || 0;
var remaining = buf.length - offset;
if (!length) {
length = remaining;
} else {
length = Number(length);
if (length > remaining) {
length = remaining;
}
}
// must be an even number of digits
var strLen = string.length;
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
if (length > strLen / 2) {
length = strLen / 2;
}
for (var i = 0; i < length; ++i) {
var parsed = parseInt(string.substr(i * 2, 2), 16);
if (isNaN(parsed)) return i
buf[offset + i] = parsed;
}
return i
}
function utf8Write (buf, string, offset, length) {
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
}
function asciiWrite (buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
}
function latin1Write (buf, string, offset, length) {
return asciiWrite(buf, string, offset, length)
}
function base64Write (buf, string, offset, length) {
return blitBuffer(base64ToBytes(string), buf, offset, length)
}
function ucs2Write (buf, string, offset, length) {
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
}
Buffer.prototype.write = function write (string, offset, length, encoding) {
// Buffer#write(string)
if (offset === undefined) {
encoding = 'utf8';
length = this.length;
offset = 0;
// Buffer#write(string, encoding)
} else if (length === undefined && typeof offset === 'string') {
encoding = offset;
length = this.length;
offset = 0;
// Buffer#write(string, offset[, length][, encoding])
} else if (isFinite(offset)) {
offset = offset | 0;
if (isFinite(length)) {
length = length | 0;
if (encoding === undefined) encoding = 'utf8';
} else {
encoding = length;
length = undefined;
}
// legacy write(string, encoding, offset, length) - remove in v0.13
} else {
throw new Error(
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
)
}
var remaining = this.length - offset;
if (length === undefined || length > remaining) length = remaining;
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
throw new RangeError('Attempt to write outside buffer bounds')
}
if (!encoding) encoding = 'utf8';
var loweredCase = false;
for (;;) {
switch (encoding) {
case 'hex':
return hexWrite(this, string, offset, length)
case 'utf8':
case 'utf-8':
return utf8Write(this, string, offset, length)
case 'ascii':
return asciiWrite(this, string, offset, length)
case 'latin1':
case 'binary':
return latin1Write(this, string, offset, length)
case 'base64':
// Warning: maxLength not taken into account in base64Write
return base64Write(this, string, offset, length)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return ucs2Write(this, string, offset, length)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = ('' + encoding).toLowerCase();
loweredCase = true;
}
}
};
Buffer.prototype.toJSON = function toJSON () {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this._arr || this, 0)
}
};
function base64Slice (buf, start, end) {
if (start === 0 && end === buf.length) {
return base64.fromByteArray(buf)
} else {
return base64.fromByteArray(buf.slice(start, end))
}
}
function utf8Slice (buf, start, end) {
end = Math.min(buf.length, end);
var res = [];
var i = start;
while (i < end) {
var firstByte = buf[i];
var codePoint = null;
var bytesPerSequence = (firstByte > 0xEF) ? 4
: (firstByte > 0xDF) ? 3
: (firstByte > 0xBF) ? 2
: 1;
if (i + bytesPerSequence <= end) {
var secondByte, thirdByte, fourthByte, tempCodePoint;
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
codePoint = firstByte;
}
break
case 2:
secondByte = buf[i + 1];
if ((secondByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
if (tempCodePoint > 0x7F) {
codePoint = tempCodePoint;
}
}
break
case 3:
secondByte = buf[i + 1];
thirdByte = buf[i + 2];
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
codePoint = tempCodePoint;
}
}
break
case 4:
secondByte = buf[i + 1];
thirdByte = buf[i + 2];
fourthByte = buf[i + 3];
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
codePoint = tempCodePoint;
}
}
}
}
if (codePoint === null) {
// we did not generate a valid codePoint so insert a
// replacement char (U+FFFD) and advance only 1 byte
codePoint = 0xFFFD;
bytesPerSequence = 1;
} else if (codePoint > 0xFFFF) {
// encode to utf16 (surrogate pair dance)
codePoint -= 0x10000;
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
codePoint = 0xDC00 | codePoint & 0x3FF;
}
res.push(codePoint);
i += bytesPerSequence;
}
return decodeCodePointsArray(res)
}
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
// the lowest limit is Chrome, with 0x10000 args.
// We go 1 magnitude less, for safety
var MAX_ARGUMENTS_LENGTH = 0x1000;
function decodeCodePointsArray (codePoints) {
var len = codePoints.length;
if (len <= MAX_ARGUMENTS_LENGTH) {
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
}
// Decode in chunks to avoid "call stack size exceeded".
var res = '';
var i = 0;
while (i < len) {
res += String.fromCharCode.apply(
String,
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
);
}
return res
}
function asciiSlice (buf, start, end) {
var ret = '';
end = Math.min(buf.length, end);
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i] & 0x7F);
}
return ret
}
function latin1Slice (buf, start, end) {
var ret = '';
end = Math.min(buf.length, end);
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i]);
}
return ret
}
function hexSlice (buf, start, end) {
var len = buf.length;
if (!start || start < 0) start = 0;
if (!end || end < 0 || end > len) end = len;
var out = '';
for (var i = start; i < end; ++i) {
out += toHex(buf[i]);
}
return out
}
function utf16leSlice (buf, start, end) {
var bytes = buf.slice(start, end);
var res = '';
for (var i = 0; i < bytes.length; i += 2) {
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
}
return res
}
Buffer.prototype.slice = function slice (start, end) {
var len = this.length;
start = ~~start;
end = end === undefined ? len : ~~end;
if (start < 0) {
start += len;
if (start < 0) start = 0;
} else if (start > len) {
start = len;
}
if (end < 0) {
end += len;
if (end < 0) end = 0;
} else if (end > len) {
end = len;
}
if (end < start) end = start;
var newBuf;
if (Buffer.TYPED_ARRAY_SUPPORT) {
newBuf = this.subarray(start, end);
newBuf.__proto__ = Buffer.prototype;
} else {
var sliceLen = end - start;
newBuf = new Buffer(sliceLen, undefined);
for (var i = 0; i < sliceLen; ++i) {
newBuf[i] = this[i + start];
}
}
return newBuf
};
/*
* Need to make sure that buffer isn't trying to write out of bounds.
*/
function checkOffset (offset, ext, length) {
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
}
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) checkOffset(offset, byteLength, this.length);
var val = this[offset];
var mul = 1;
var i = 0;
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul;
}
return val
};
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) {
checkOffset(offset, byteLength, this.length);
}
var val = this[offset + --byteLength];
var mul = 1;
while (byteLength > 0 && (mul *= 0x100)) {
val += this[offset + --byteLength] * mul;
}
return val
};
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
if (!noAssert) checkOffset(offset, 1, this.length);
return this[offset]
};
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
return this[offset] | (this[offset + 1] << 8)
};
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
return (this[offset] << 8) | this[offset + 1]
};
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return ((this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16)) +
(this[offset + 3] * 0x1000000)
};
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return (this[offset] * 0x1000000) +
((this[offset + 1] << 16) |
(this[offset + 2] << 8) |
this[offset + 3])
};
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) checkOffset(offset, byteLength, this.length);
var val = this[offset];
var mul = 1;
var i = 0;
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul;
}
mul *= 0x80;
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
return val
};
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) checkOffset(offset, byteLength, this.length);
var i = byteLength;
var mul = 1;
var val = this[offset + --i];
while (i > 0 && (mul *= 0x100)) {
val += this[offset + --i] * mul;
}
mul *= 0x80;
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
return val
};
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
if (!noAssert) checkOffset(offset, 1, this.length);
if (!(this[offset] & 0x80)) return (this[offset])
return ((0xff - this[offset] + 1) * -1)
};
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
var val = this[offset] | (this[offset + 1] << 8);
return (val & 0x8000) ? val | 0xFFFF0000 : val
};
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
var val = this[offset + 1] | (this[offset] << 8);
return (val & 0x8000) ? val | 0xFFFF0000 : val
};
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return (this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16) |
(this[offset + 3] << 24)
};
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return (this[offset] << 24) |
(this[offset + 1] << 16) |
(this[offset + 2] << 8) |
(this[offset + 3])
};
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return ieee754.read(this, offset, true, 23, 4)
};
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return ieee754.read(this, offset, false, 23, 4)
};
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 8, this.length);
return ieee754.read(this, offset, true, 52, 8)
};
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 8, this.length);
return ieee754.read(this, offset, false, 52, 8)
};
function checkInt (buf, value, offset, ext, max, min) {
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
if (offset + ext > buf.length) throw new RangeError('Index out of range')
}
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
checkInt(this, value, offset, byteLength, maxBytes, 0);
}
var mul = 1;
var i = 0;
this[offset] = value & 0xFF;
while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
checkInt(this, value, offset, byteLength, maxBytes, 0);
}
var i = byteLength - 1;
var mul = 1;
this[offset + i] = value & 0xFF;
while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
this[offset] = (value & 0xff);
return offset + 1
};
function objectWriteUInt16 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffff + value + 1;
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
(littleEndian ? i : 1 - i) * 8;
}
}
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
} else {
objectWriteUInt16(this, value, offset, true);
}
return offset + 2
};
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
} else {
objectWriteUInt16(this, value, offset, false);
}
return offset + 2
};
function objectWriteUInt32 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffffffff + value + 1;
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
}
}
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset + 3] = (value >>> 24);
this[offset + 2] = (value >>> 16);
this[offset + 1] = (value >>> 8);
this[offset] = (value & 0xff);
} else {
objectWriteUInt32(this, value, offset, true);
}
return offset + 4
};
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
this[offset + 1] = (value >>> 16);
this[offset + 2] = (value >>> 8);
this[offset + 3] = (value & 0xff);
} else {
objectWriteUInt32(this, value, offset, false);
}
return offset + 4
};
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) {
var limit = Math.pow(2, 8 * byteLength - 1);
checkInt(this, value, offset, byteLength, limit - 1, -limit);
}
var i = 0;
var mul = 1;
var sub = 0;
this[offset] = value & 0xFF;
while (++i < byteLength && (mul *= 0x100)) {
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
sub = 1;
}
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) {
var limit = Math.pow(2, 8 * byteLength - 1);
checkInt(this, value, offset, byteLength, limit - 1, -limit);
}
var i = byteLength - 1;
var mul = 1;
var sub = 0;
this[offset + i] = value & 0xFF;
while (--i >= 0 && (mul *= 0x100)) {
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
sub = 1;
}
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
return offset + 1
};
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
} else {
objectWriteUInt16(this, value, offset, true);
}
return offset + 2
};
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
} else {
objectWriteUInt16(this, value, offset, false);
}
return offset + 2
};
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
this[offset + 2] = (value >>> 16);
this[offset + 3] = (value >>> 24);
} else {
objectWriteUInt32(this, value, offset, true);
}
return offset + 4
};
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
this[offset + 1] = (value >>> 16);
this[offset + 2] = (value >>> 8);
this[offset + 3] = (value & 0xff);
} else {
objectWriteUInt32(this, value, offset, false);
}
return offset + 4
};
function checkIEEE754 (buf, value, offset, ext, max, min) {
if (offset + ext > buf.length) throw new RangeError('Index out of range')
if (offset < 0) throw new RangeError('Index out of range')
}
function writeFloat (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
}
ieee754.write(buf, value, offset, littleEndian, 23, 4);
return offset + 4
}
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
return writeFloat(this, value, offset, true, noAssert)
};
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
return writeFloat(this, value, offset, false, noAssert)
};
function writeDouble (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
}
ieee754.write(buf, value, offset, littleEndian, 52, 8);
return offset + 8
}
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
return writeDouble(this, value, offset, true, noAssert)
};
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
return writeDouble(this, value, offset, false, noAssert)
};
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
if (!start) start = 0;
if (!end && end !== 0) end = this.length;
if (targetStart >= target.length) targetStart = target.length;
if (!targetStart) targetStart = 0;
if (end > 0 && end < start) end = start;
// Copy 0 bytes; we're done
if (end === start) return 0
if (target.length === 0 || this.length === 0) return 0
// Fatal error conditions
if (targetStart < 0) {
throw new RangeError('targetStart out of bounds')
}
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
if (end < 0) throw new RangeError('sourceEnd out of bounds')
// Are we oob?
if (end > this.length) end = this.length;
if (target.length - targetStart < end - start) {
end = target.length - targetStart + start;
}
var len = end - start;
var i;
if (this === target && start < targetStart && targetStart < end) {
// descending copy from end
for (i = len - 1; i >= 0; --i) {
target[i + targetStart] = this[i + start];
}
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
// ascending copy from start
for (i = 0; i < len; ++i) {
target[i + targetStart] = this[i + start];
}
} else {
Uint8Array.prototype.set.call(
target,
this.subarray(start, start + len),
targetStart
);
}
return len
};
// Usage:
// buffer.fill(number[, offset[, end]])
// buffer.fill(buffer[, offset[, end]])
// buffer.fill(string[, offset[, end]][, encoding])
Buffer.prototype.fill = function fill (val, start, end, encoding) {
// Handle string cases:
if (typeof val === 'string') {
if (typeof start === 'string') {
encoding = start;
start = 0;
end = this.length;
} else if (typeof end === 'string') {
encoding = end;
end = this.length;
}
if (val.length === 1) {
var code = val.charCodeAt(0);
if (code < 256) {
val = code;
}
}
if (encoding !== undefined && typeof encoding !== 'string') {
throw new TypeError('encoding must be a string')
}
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
throw new TypeError('Unknown encoding: ' + encoding)
}
} else if (typeof val === 'number') {
val = val & 255;
}
// Invalid ranges are not set to a default, so can range check early.
if (start < 0 || this.length < start || this.length < end) {
throw new RangeError('Out of range index')
}
if (end <= start) {
return this
}
start = start >>> 0;
end = end === undefined ? this.length : end >>> 0;
if (!val) val = 0;
var i;
if (typeof val === 'number') {
for (i = start; i < end; ++i) {
this[i] = val;
}
} else {
var bytes = Buffer.isBuffer(val)
? val
: utf8ToBytes(new Buffer(val, encoding).toString());
var len = bytes.length;
for (i = 0; i < end - start; ++i) {
this[i + start] = bytes[i % len];
}
}
return this
};
// HELPER FUNCTIONS
// ================
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
function base64clean (str) {
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = stringtrim(str).replace(INVALID_BASE64_RE, '');
// Node converts strings with length < 2 to ''
if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '=';
}
return str
}
function stringtrim (str) {
if (str.trim) return str.trim()
return str.replace(/^\s+|\s+$/g, '')
}
function toHex (n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
}
function utf8ToBytes (string, units) {
units = units || Infinity;
var codePoint;
var length = string.length;
var leadSurrogate = null;
var bytes = [];
for (var i = 0; i < length; ++i) {
codePoint = string.charCodeAt(i);
// is surrogate component
if (codePoint > 0xD7FF && codePoint < 0xE000) {
// last char was a lead
if (!leadSurrogate) {
// no lead yet
if (codePoint > 0xDBFF) {
// unexpected trail
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
continue
} else if (i + 1 === length) {
// unpaired lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
continue
}
// valid lead
leadSurrogate = codePoint;
continue
}
// 2 leads in a row
if (codePoint < 0xDC00) {
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
leadSurrogate = codePoint;
continue
}
// valid surrogate pair
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
} else if (leadSurrogate) {
// valid bmp char, but last char was a lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
}
leadSurrogate = null;
// encode utf8
if (codePoint < 0x80) {
if ((units -= 1) < 0) break
bytes.push(codePoint);
} else if (codePoint < 0x800) {
if ((units -= 2) < 0) break
bytes.push(
codePoint >> 0x6 | 0xC0,
codePoint & 0x3F | 0x80
);
} else if (codePoint < 0x10000) {
if ((units -= 3) < 0) break
bytes.push(
codePoint >> 0xC | 0xE0,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
);
} else if (codePoint < 0x110000) {
if ((units -= 4) < 0) break
bytes.push(
codePoint >> 0x12 | 0xF0,
codePoint >> 0xC & 0x3F | 0x80,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
);
} else {
throw new Error('Invalid code point')
}
}
return bytes
}
function asciiToBytes (str) {
var byteArray = [];
for (var i = 0; i < str.length; ++i) {
// Node's code seems to be doing this and not & 0x7F..
byteArray.push(str.charCodeAt(i) & 0xFF);
}
return byteArray
}
function utf16leToBytes (str, units) {
var c, hi, lo;
var byteArray = [];
for (var i = 0; i < str.length; ++i) {
if ((units -= 2) < 0) break
c = str.charCodeAt(i);
hi = c >> 8;
lo = c % 256;
byteArray.push(lo);
byteArray.push(hi);
}
return byteArray
}
function base64ToBytes (str) {
return base64.toByteArray(base64clean(str))
}
function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; ++i) {
if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i];
}
return i
}
function isnan (val) {
return val !== val // eslint-disable-line no-self-compare
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")));
/***/ }),
/***/ "./node_modules/node-libs-browser/node_modules/events/events.js":
/*!**********************************************************************!*\
!*** ./node_modules/node-libs-browser/node_modules/events/events.js ***!
\**********************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var R = typeof Reflect === 'object' ? Reflect : null;
var ReflectApply = R && typeof R.apply === 'function'
? R.apply
: function ReflectApply(target, receiver, args) {
return Function.prototype.apply.call(target, receiver, args);
};
var ReflectOwnKeys;
if (R && typeof R.ownKeys === 'function') {
ReflectOwnKeys = R.ownKeys;
} else if (Object.getOwnPropertySymbols) {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target)
.concat(Object.getOwnPropertySymbols(target));
};
} else {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target);
};
}
function ProcessEmitWarning(warning) {
if (console && console.warn) console.warn(warning);
}
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
return value !== value;
};
function EventEmitter() {
EventEmitter.init.call(this);
}
module.exports = EventEmitter;
module.exports.once = once;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._eventsCount = 0;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
var defaultMaxListeners = 10;
function checkListener(listener) {
if (typeof listener !== 'function') {
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
}
}
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
enumerable: true,
get: function() {
return defaultMaxListeners;
},
set: function(arg) {
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
}
defaultMaxListeners = arg;
}
});
EventEmitter.init = function() {
if (this._events === undefined ||
this._events === Object.getPrototypeOf(this)._events) {
this._events = Object.create(null);
this._eventsCount = 0;
}
this._maxListeners = this._maxListeners || undefined;
};
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
}
this._maxListeners = n;
return this;
};
function _getMaxListeners(that) {
if (that._maxListeners === undefined)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return _getMaxListeners(this);
};
EventEmitter.prototype.emit = function emit(type) {
var args = [];
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
var doError = (type === 'error');
var events = this._events;
if (events !== undefined)
doError = (doError && events.error === undefined);
else if (!doError)
return false;
// If there is no 'error' event listener then throw.
if (doError) {
var er;
if (args.length > 0)
er = args[0];
if (er instanceof Error) {
// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
throw er; // Unhandled 'error' event
}
// At least give some kind of context to the user
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
err.context = er;
throw err; // Unhandled 'error' event
}
var handler = events[type];
if (handler === undefined)
return false;
if (typeof handler === 'function') {
ReflectApply(handler, this, args);
} else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
ReflectApply(listeners[i], this, args);
}
return true;
};
function _addListener(target, type, listener, prepend) {
var m;
var events;
var existing;
checkListener(listener);
events = target._events;
if (events === undefined) {
events = target._events = Object.create(null);
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener !== undefined) {
target.emit('newListener', type,
listener.listener ? listener.listener : listener);
// Re-assign `events` because a newListener handler could have caused the
// this._events to be assigned to a new object
events = target._events;
}
existing = events[type];
}
if (existing === undefined) {
// Optimize the case of one listener. Don't need the extra array object.
existing = events[type] = listener;
++target._eventsCount;
} else {
if (typeof existing === 'function') {
// Adding the second element, need to change to array.
existing = events[type] =
prepend ? [listener, existing] : [existing, listener];
// If we've already got an array, just append.
} else if (prepend) {
existing.unshift(listener);
} else {
existing.push(listener);
}
// Check for listener leak
m = _getMaxListeners(target);
if (m > 0 && existing.length > m && !existing.warned) {
existing.warned = true;
// No error code for this since it is a Warning
// eslint-disable-next-line no-restricted-syntax
var w = new Error('Possible EventEmitter memory leak detected. ' +
existing.length + ' ' + String(type) + ' listeners ' +
'added. Use emitter.setMaxListeners() to ' +
'increase limit');
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;
ProcessEmitWarning(w);
}
}
return target;
}
EventEmitter.prototype.addListener = function addListener(type, listener) {
return _addListener(this, type, listener, false);
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.prependListener =
function prependListener(type, listener) {
return _addListener(this, type, listener, true);
};
function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
if (arguments.length === 0)
return this.listener.call(this.target);
return this.listener.apply(this.target, arguments);
}
}
function _onceWrap(target, type, listener) {
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
var wrapped = onceWrapper.bind(state);
wrapped.listener = listener;
state.wrapFn = wrapped;
return wrapped;
}
EventEmitter.prototype.once = function once(type, listener) {
checkListener(listener);
this.on(type, _onceWrap(this, type, listener));
return this;
};
EventEmitter.prototype.prependOnceListener =
function prependOnceListener(type, listener) {
checkListener(listener);
this.prependListener(type, _onceWrap(this, type, listener));
return this;
};
// Emits a 'removeListener' event if and only if the listener was removed.
EventEmitter.prototype.removeListener =
function removeListener(type, listener) {
var list, events, position, i, originalListener;
checkListener(listener);
events = this._events;
if (events === undefined)
return this;
list = events[type];
if (list === undefined)
return this;
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else {
delete events[type];
if (events.removeListener)
this.emit('removeListener', type, list.listener || listener);
}
} else if (typeof list !== 'function') {
position = -1;
for (i = list.length - 1; i >= 0; i--) {
if (list[i] === listener || list[i].listener === listener) {
originalListener = list[i].listener;
position = i;
break;
}
}
if (position < 0)
return this;
if (position === 0)
list.shift();
else {
spliceOne(list, position);
}
if (list.length === 1)
events[type] = list[0];
if (events.removeListener !== undefined)
this.emit('removeListener', type, originalListener || listener);
}
return this;
};
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var listeners, events, i;
events = this._events;
if (events === undefined)
return this;
// not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = Object.create(null);
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else
delete events[type];
}
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
var keys = Object.keys(events);
var key;
for (i = 0; i < keys.length; ++i) {
key = keys[i];
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = Object.create(null);
this._eventsCount = 0;
return this;
}
listeners = events[type];
if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners !== undefined) {
// LIFO order
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
}
}
return this;
};
function _listeners(target, type, unwrap) {
var events = target._events;
if (events === undefined)
return [];
var evlistener = events[type];
if (evlistener === undefined)
return [];
if (typeof evlistener === 'function')
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
return unwrap ?
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type) {
return _listeners(this, type, true);
};
EventEmitter.prototype.rawListeners = function rawListeners(type) {
return _listeners(this, type, false);
};
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
};
EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type) {
var events = this._events;
if (events !== undefined) {
var evlistener = events[type];
if (typeof evlistener === 'function') {
return 1;
} else if (evlistener !== undefined) {
return evlistener.length;
}
}
return 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
};
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
function spliceOne(list, index) {
for (; index + 1 < list.length; index++)
list[index] = list[index + 1];
list.pop();
}
function unwrapListeners(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
}
return ret;
}
function once(emitter, name) {
return new Promise(function (resolve, reject) {
function errorListener(err) {
emitter.removeListener(name, resolver);
reject(err);
}
function resolver() {
if (typeof emitter.removeListener === 'function') {
emitter.removeListener('error', errorListener);
}
resolve([].slice.call(arguments));
}
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
if (name !== 'error') {
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
}
});
}
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
if (typeof emitter.on === 'function') {
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
}
}
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
if (typeof emitter.on === 'function') {
if (flags.once) {
emitter.once(name, listener);
} else {
emitter.on(name, listener);
}
} else if (typeof emitter.addEventListener === 'function') {
// EventTarget does not have `error` event semantics like Node
// EventEmitters, we do not listen for `error` events here.
emitter.addEventListener(name, function wrapListener(arg) {
// IE does not have builtin `{ once: true }` support so we
// have to do it manually.
if (flags.once) {
emitter.removeEventListener(name, wrapListener);
}
listener(arg);
});
} else {
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
}
}
/***/ }),
/***/ "./node_modules/node-libs-browser/node_modules/timers-browserify/main.js":
/*!*******************************************************************************!*\
!*** ./node_modules/node-libs-browser/node_modules/timers-browserify/main.js ***!
\*******************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {var scope = (typeof global !== "undefined" && global) ||
(typeof self !== "undefined" && self) ||
window;
var apply = Function.prototype.apply;
// DOM APIs, for completeness
exports.setTimeout = function() {
return new Timeout(apply.call(setTimeout, scope, arguments), clearTimeout);
};
exports.setInterval = function() {
return new Timeout(apply.call(setInterval, scope, arguments), clearInterval);
};
exports.clearTimeout =
exports.clearInterval = function(timeout) {
if (timeout) {
timeout.close();
}
};
function Timeout(id, clearFn) {
this._id = id;
this._clearFn = clearFn;
}
Timeout.prototype.unref = Timeout.prototype.ref = function() {};
Timeout.prototype.close = function() {
this._clearFn.call(scope, this._id);
};
// Does not start the time, just sets up the members needed.
exports.enroll = function(item, msecs) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = msecs;
};
exports.unenroll = function(item) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = -1;
};
exports._unrefActive = exports.active = function(item) {
clearTimeout(item._idleTimeoutId);
var msecs = item._idleTimeout;
if (msecs >= 0) {
item._idleTimeoutId = setTimeout(function onTimeout() {
if (item._onTimeout)
item._onTimeout();
}, msecs);
}
};
// setimmediate attaches itself to the global object
__webpack_require__(/*! setimmediate */ "./node_modules/setimmediate/setImmediate.js");
// On some exotic environments, it's not clear which object `setimmediate` was
// able to install onto. Search each possibility in the same order as the
// `setimmediate` library.
exports.setImmediate = (typeof self !== "undefined" && self.setImmediate) ||
(typeof global !== "undefined" && global.setImmediate) ||
(this && this.setImmediate);
exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) ||
(typeof global !== "undefined" && global.clearImmediate) ||
(this && this.clearImmediate);
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")));
/***/ }),
/***/ "./node_modules/path-browserify/index.js":
/*!***********************************************!*\
!*** ./node_modules/path-browserify/index.js ***!
\***********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {// .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
// backported and transplited with Babel, with backwards-compat fixes
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = exports.isAbsolute(path),
trailingSlash = substr(path, -1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.isAbsolute = function(path) {
return path.charAt(0) === '/';
};
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}).join('/'));
};
// path.relative(from, to)
// posix version
exports.relative = function(from, to) {
from = exports.resolve(from).substr(1);
to = exports.resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
};
exports.sep = '/';
exports.delimiter = ':';
exports.dirname = function (path) {
if (typeof path !== 'string') path = path + '';
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47 /*/*/;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
if (!matchedSlash) {
end = i;
break;
}
} else {
// We saw the first non-path separator
matchedSlash = false;
}
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) {
// return '//';
// Backwards-compat fix:
return '/';
}
return path.slice(0, end);
};
function basename(path) {
if (typeof path !== 'string') path = path + '';
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// path component
matchedSlash = false;
end = i + 1;
}
}
if (end === -1) return '';
return path.slice(start, end);
}
// Uses a mixed approach for backwards-compatibility, as ext behavior changed
// in new Node.js versions, so only basename() above is backported here
exports.basename = function (path, ext) {
var f = basename(path);
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function (path) {
if (typeof path !== 'string') path = path + '';
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1)
startDot = i;
else if (preDotState !== 1)
preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
return '';
}
return path.slice(startDot, end);
};
function filter (xs, f) {
if (xs.filter) return xs.filter(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// String.prototype.substr - negative index don't work in IE8
var substr = 'ab'.substr(-1) === 'b'
? function (str, start, len) { return str.substr(start, len) }
: function (str, start, len) {
if (start < 0) start = str.length + start;
return str.substr(start, len);
}
;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../process/browser.js */ "./node_modules/process/browser.js")));
/***/ }),
/***/ "./node_modules/process-nextick-args/index.js":
/*!****************************************************!*\
!*** ./node_modules/process-nextick-args/index.js ***!
\****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {
if (!process.version ||
process.version.indexOf('v0.') === 0 ||
process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
module.exports = { nextTick: nextTick };
} else {
module.exports = process;
}
function nextTick(fn, arg1, arg2, arg3) {
if (typeof fn !== 'function') {
throw new TypeError('"callback" argument must be a function');
}
var len = arguments.length;
var args, i;
switch (len) {
case 0:
case 1:
return process.nextTick(fn);
case 2:
return process.nextTick(function afterTickOne() {
fn.call(null, arg1);
});
case 3:
return process.nextTick(function afterTickTwo() {
fn.call(null, arg1, arg2);
});
case 4:
return process.nextTick(function afterTickThree() {
fn.call(null, arg1, arg2, arg3);
});
default:
args = new Array(len - 1);
i = 0;
while (i < args.length) {
args[i++] = arguments[i];
}
return process.nextTick(function afterTick() {
fn.apply(null, args);
});
}
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../process/browser.js */ "./node_modules/process/browser.js")));
/***/ }),
/***/ "./node_modules/process/browser.js":
/*!*****************************************!*\
!*** ./node_modules/process/browser.js ***!
\*****************************************/
/*! no static exports found */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ());
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] };
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/***/ "./node_modules/readable-stream/duplex-browser.js":
/*!********************************************************!*\
!*** ./node_modules/readable-stream/duplex-browser.js ***!
\********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./lib/_stream_duplex.js */ "./node_modules/readable-stream/lib/_stream_duplex.js");
/***/ }),
/***/ "./node_modules/readable-stream/lib/_stream_duplex.js":
/*!************************************************************!*\
!*** ./node_modules/readable-stream/lib/_stream_duplex.js ***!
\************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// a duplex stream is just a stream that is both readable and writable.
// Since JS doesn't have multiple prototypal inheritance, this class
// prototypally inherits from Readable, and then parasitically from
// Writable.
/*<replacement>*/
var pna = __webpack_require__(/*! process-nextick-args */ "./node_modules/process-nextick-args/index.js");
/*</replacement>*/
/*<replacement>*/
var objectKeys = Object.keys || function (obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}return keys;
};
/*</replacement>*/
module.exports = Duplex;
/*<replacement>*/
var util = __webpack_require__(/*! core-util-is */ "./node_modules/core-util-is/lib/util.js");
util.inherits = __webpack_require__(/*! inherits */ "./node_modules/inherits/inherits_browser.js");
/*</replacement>*/
var Readable = __webpack_require__(/*! ./_stream_readable */ "./node_modules/readable-stream/lib/_stream_readable.js");
var Writable = __webpack_require__(/*! ./_stream_writable */ "./node_modules/readable-stream/lib/_stream_writable.js");
util.inherits(Duplex, Readable);
{
// avoid scope creep, the keys array can then be collected
var keys = objectKeys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
var method = keys[v];
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
}
}
function Duplex(options) {
if (!(this instanceof Duplex)) return new Duplex(options);
Readable.call(this, options);
Writable.call(this, options);
if (options && options.readable === false) this.readable = false;
if (options && options.writable === false) this.writable = false;
this.allowHalfOpen = true;
if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
this.once('end', onend);
}
Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
// making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function () {
return this._writableState.highWaterMark;
}
});
// the no-half-open enforcer
function onend() {
// if we allow half-open state, or if the writable side ended,
// then we're ok.
if (this.allowHalfOpen || this._writableState.ended) return;
// no more data can be written.
// But allow more writes to happen in this tick.
pna.nextTick(onEndNT, this);
}
function onEndNT(self) {
self.end();
}
Object.defineProperty(Duplex.prototype, 'destroyed', {
get: function () {
if (this._readableState === undefined || this._writableState === undefined) {
return false;
}
return this._readableState.destroyed && this._writableState.destroyed;
},
set: function (value) {
// we ignore the value if the stream
// has not been initialized yet
if (this._readableState === undefined || this._writableState === undefined) {
return;
}
// backward compatibility, the user is explicitly
// managing destroyed
this._readableState.destroyed = value;
this._writableState.destroyed = value;
}
});
Duplex.prototype._destroy = function (err, cb) {
this.push(null);
this.end();
pna.nextTick(cb, err);
};
/***/ }),
/***/ "./node_modules/readable-stream/lib/_stream_passthrough.js":
/*!*****************************************************************!*\
!*** ./node_modules/readable-stream/lib/_stream_passthrough.js ***!
\*****************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// a passthrough stream.
// basically just the most minimal sort of Transform stream.
// Every written chunk gets output as-is.
module.exports = PassThrough;
var Transform = __webpack_require__(/*! ./_stream_transform */ "./node_modules/readable-stream/lib/_stream_transform.js");
/*<replacement>*/
var util = __webpack_require__(/*! core-util-is */ "./node_modules/core-util-is/lib/util.js");
util.inherits = __webpack_require__(/*! inherits */ "./node_modules/inherits/inherits_browser.js");
/*</replacement>*/
util.inherits(PassThrough, Transform);
function PassThrough(options) {
if (!(this instanceof PassThrough)) return new PassThrough(options);
Transform.call(this, options);
}
PassThrough.prototype._transform = function (chunk, encoding, cb) {
cb(null, chunk);
};
/***/ }),
/***/ "./node_modules/readable-stream/lib/_stream_readable.js":
/*!**************************************************************!*\
!*** ./node_modules/readable-stream/lib/_stream_readable.js ***!
\**************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
/*<replacement>*/
var pna = __webpack_require__(/*! process-nextick-args */ "./node_modules/process-nextick-args/index.js");
/*</replacement>*/
module.exports = Readable;
/*<replacement>*/
var isArray = __webpack_require__(/*! isarray */ "./node_modules/isarray/index.js");
/*</replacement>*/
/*<replacement>*/
var Duplex;
/*</replacement>*/
Readable.ReadableState = ReadableState;
/*<replacement>*/
var EE = __webpack_require__(/*! events */ "./node_modules/node-libs-browser/node_modules/events/events.js").EventEmitter;
var EElistenerCount = function (emitter, type) {
return emitter.listeners(type).length;
};
/*</replacement>*/
/*<replacement>*/
var Stream = __webpack_require__(/*! ./internal/streams/stream */ "./node_modules/readable-stream/lib/internal/streams/stream-browser.js");
/*</replacement>*/
/*<replacement>*/
var Buffer = __webpack_require__(/*! safe-buffer */ "./node_modules/safe-buffer/index.js").Buffer;
var OurUint8Array = global.Uint8Array || function () {};
function _uint8ArrayToBuffer(chunk) {
return Buffer.from(chunk);
}
function _isUint8Array(obj) {
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
}
/*</replacement>*/
/*<replacement>*/
var util = __webpack_require__(/*! core-util-is */ "./node_modules/core-util-is/lib/util.js");
util.inherits = __webpack_require__(/*! inherits */ "./node_modules/inherits/inherits_browser.js");
/*</replacement>*/
/*<replacement>*/
var debugUtil = __webpack_require__(/*! util */ 0);
var debug = void 0;
if (debugUtil && debugUtil.debuglog) {
debug = debugUtil.debuglog('stream');
} else {
debug = function () {};
}
/*</replacement>*/
var BufferList = __webpack_require__(/*! ./internal/streams/BufferList */ "./node_modules/readable-stream/lib/internal/streams/BufferList.js");
var destroyImpl = __webpack_require__(/*! ./internal/streams/destroy */ "./node_modules/readable-stream/lib/internal/streams/destroy.js");
var StringDecoder;
util.inherits(Readable, Stream);
var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
function prependListener(emitter, event, fn) {
// Sadly this is not cacheable as some libraries bundle their own
// event emitter implementation with them.
if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
// This is a hack to make sure that our error handler is attached before any
// userland ones. NEVER DO THIS. This is here only because this code needs
// to continue to work with older versions of Node.js that do not include
// the prependListener() method. The goal is to eventually remove this hack.
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
}
function ReadableState(options, stream) {
Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/readable-stream/lib/_stream_duplex.js");
options = options || {};
// Duplex streams are both readable and writable, but share
// the same options object.
// However, some cases require setting options to different
// values for the readable and the writable sides of the duplex stream.
// These options can be provided separately as readableXXX and writableXXX.
var isDuplex = stream instanceof Duplex;
// object stream flag. Used to make read(n) ignore n and to
// make all the buffer merging and length checks go away
this.objectMode = !!options.objectMode;
if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
// the point at which it stops calling _read() to fill the buffer
// Note: 0 is a valid value, means "don't call _read preemptively ever"
var hwm = options.highWaterMark;
var readableHwm = options.readableHighWaterMark;
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
// cast to ints.
this.highWaterMark = Math.floor(this.highWaterMark);
// A linked list is used to store data chunks instead of an array because the
// linked list can remove elements from the beginning faster than
// array.shift()
this.buffer = new BufferList();
this.length = 0;
this.pipes = null;
this.pipesCount = 0;
this.flowing = null;
this.ended = false;
this.endEmitted = false;
this.reading = false;
// a flag to be able to tell if the event 'readable'/'data' is emitted
// immediately, or on a later tick. We set this to true at first, because
// any actions that shouldn't happen until "later" should generally also
// not happen before the first read call.
this.sync = true;
// whenever we return null, then we set a flag to say
// that we're awaiting a 'readable' event emission.
this.needReadable = false;
this.emittedReadable = false;
this.readableListening = false;
this.resumeScheduled = false;
// has it been destroyed
this.destroyed = false;
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
// the number of writers that are awaiting a drain event in .pipe()s
this.awaitDrain = 0;
// if true, a maybeReadMore has been scheduled
this.readingMore = false;
this.decoder = null;
this.encoding = null;
if (options.encoding) {
if (!StringDecoder) StringDecoder = __webpack_require__(/*! string_decoder/ */ "./node_modules/string_decoder/lib/string_decoder.js").StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
}
function Readable(options) {
Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/readable-stream/lib/_stream_duplex.js");
if (!(this instanceof Readable)) return new Readable(options);
this._readableState = new ReadableState(options, this);
// legacy
this.readable = true;
if (options) {
if (typeof options.read === 'function') this._read = options.read;
if (typeof options.destroy === 'function') this._destroy = options.destroy;
}
Stream.call(this);
}
Object.defineProperty(Readable.prototype, 'destroyed', {
get: function () {
if (this._readableState === undefined) {
return false;
}
return this._readableState.destroyed;
},
set: function (value) {
// we ignore the value if the stream
// has not been initialized yet
if (!this._readableState) {
return;
}
// backward compatibility, the user is explicitly
// managing destroyed
this._readableState.destroyed = value;
}
});
Readable.prototype.destroy = destroyImpl.destroy;
Readable.prototype._undestroy = destroyImpl.undestroy;
Readable.prototype._destroy = function (err, cb) {
this.push(null);
cb(err);
};
// Manually shove something into the read() buffer.
// This returns true if the highWaterMark has not been hit yet,
// similar to how Writable.write() returns true if you should
// write() some more.
Readable.prototype.push = function (chunk, encoding) {
var state = this._readableState;
var skipChunkCheck;
if (!state.objectMode) {
if (typeof chunk === 'string') {
encoding = encoding || state.defaultEncoding;
if (encoding !== state.encoding) {
chunk = Buffer.from(chunk, encoding);
encoding = '';
}
skipChunkCheck = true;
}
} else {
skipChunkCheck = true;
}
return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
};
// Unshift should *always* be something directly out of read()
Readable.prototype.unshift = function (chunk) {
return readableAddChunk(this, chunk, null, true, false);
};
function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
var state = stream._readableState;
if (chunk === null) {
state.reading = false;
onEofChunk(stream, state);
} else {
var er;
if (!skipChunkCheck) er = chunkInvalid(state, chunk);
if (er) {
stream.emit('error', er);
} else if (state.objectMode || chunk && chunk.length > 0) {
if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
chunk = _uint8ArrayToBuffer(chunk);
}
if (addToFront) {
if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
} else if (state.ended) {
stream.emit('error', new Error('stream.push() after EOF'));
} else {
state.reading = false;
if (state.decoder && !encoding) {
chunk = state.decoder.write(chunk);
if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
} else {
addChunk(stream, state, chunk, false);
}
}
} else if (!addToFront) {
state.reading = false;
}
}
return needMoreData(state);
}
function addChunk(stream, state, chunk, addToFront) {
if (state.flowing && state.length === 0 && !state.sync) {
stream.emit('data', chunk);
stream.read(0);
} else {
// update the buffer info.
state.length += state.objectMode ? 1 : chunk.length;
if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
if (state.needReadable) emitReadable(stream);
}
maybeReadMore(stream, state);
}
function chunkInvalid(state, chunk) {
var er;
if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
er = new TypeError('Invalid non-string/buffer chunk');
}
return er;
}
// if it's past the high water mark, we can push in some more.
// Also, if we have no data yet, we can stand some
// more bytes. This is to work around cases where hwm=0,
// such as the repl. Also, if the push() triggered a
// readable event, and the user called read(largeNumber) such that
// needReadable was set, then we ought to push more, so that another
// 'readable' event will be triggered.
function needMoreData(state) {
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
}
Readable.prototype.isPaused = function () {
return this._readableState.flowing === false;
};
// backwards compatibility.
Readable.prototype.setEncoding = function (enc) {
if (!StringDecoder) StringDecoder = __webpack_require__(/*! string_decoder/ */ "./node_modules/string_decoder/lib/string_decoder.js").StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
this._readableState.encoding = enc;
return this;
};
// Don't raise the hwm > 8MB
var MAX_HWM = 0x800000;
function computeNewHighWaterMark(n) {
if (n >= MAX_HWM) {
n = MAX_HWM;
} else {
// Get the next highest power of 2 to prevent increasing hwm excessively in
// tiny amounts
n--;
n |= n >>> 1;
n |= n >>> 2;
n |= n >>> 4;
n |= n >>> 8;
n |= n >>> 16;
n++;
}
return n;
}
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function howMuchToRead(n, state) {
if (n <= 0 || state.length === 0 && state.ended) return 0;
if (state.objectMode) return 1;
if (n !== n) {
// Only flow one buffer at a time
if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
}
// If we're asking for more than the current hwm, then raise the hwm.
if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
if (n <= state.length) return n;
// Don't have enough
if (!state.ended) {
state.needReadable = true;
return 0;
}
return state.length;
}
// you can override either this method, or the async _read(n) below.
Readable.prototype.read = function (n) {
debug('read', n);
n = parseInt(n, 10);
var state = this._readableState;
var nOrig = n;
if (n !== 0) state.emittedReadable = false;
// if we're doing read(0) to trigger a readable event, but we
// already have a bunch of data in the buffer, then just trigger
// the 'readable' event and move on.
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
debug('read: emitReadable', state.length, state.ended);
if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
return null;
}
n = howMuchToRead(n, state);
// if we've ended, and we're now clear, then finish it up.
if (n === 0 && state.ended) {
if (state.length === 0) endReadable(this);
return null;
}
// All the actual chunk generation logic needs to be
// *below* the call to _read. The reason is that in certain
// synthetic stream cases, such as passthrough streams, _read
// may be a completely synchronous operation which may change
// the state of the read buffer, providing enough data when
// before there was *not* enough.
//
// So, the steps are:
// 1. Figure out what the state of things will be after we do
// a read from the buffer.
//
// 2. If that resulting state will trigger a _read, then call _read.
// Note that this may be asynchronous, or synchronous. Yes, it is
// deeply ugly to write APIs this way, but that still doesn't mean
// that the Readable class should behave improperly, as streams are
// designed to be sync/async agnostic.
// Take note if the _read call is sync or async (ie, if the read call
// has returned yet), so that we know whether or not it's safe to emit
// 'readable' etc.
//
// 3. Actually pull the requested chunks out of the buffer and return.
// if we need a readable event, then we need to do some reading.
var doRead = state.needReadable;
debug('need readable', doRead);
// if we currently have less than the highWaterMark, then also read some
if (state.length === 0 || state.length - n < state.highWaterMark) {
doRead = true;
debug('length less than watermark', doRead);
}
// however, if we've ended, then there's no point, and if we're already
// reading, then it's unnecessary.
if (state.ended || state.reading) {
doRead = false;
debug('reading or ended', doRead);
} else if (doRead) {
debug('do read');
state.reading = true;
state.sync = true;
// if the length is currently zero, then we *need* a readable event.
if (state.length === 0) state.needReadable = true;
// call internal read method
this._read(state.highWaterMark);
state.sync = false;
// If _read pushed data synchronously, then `reading` will be false,
// and we need to re-evaluate how much data we can return to the user.
if (!state.reading) n = howMuchToRead(nOrig, state);
}
var ret;
if (n > 0) ret = fromList(n, state);else ret = null;
if (ret === null) {
state.needReadable = true;
n = 0;
} else {
state.length -= n;
}
if (state.length === 0) {
// If we have nothing in the buffer, then we want to know
// as soon as we *do* get something into the buffer.
if (!state.ended) state.needReadable = true;
// If we tried to read() past the EOF, then emit end on the next tick.
if (nOrig !== n && state.ended) endReadable(this);
}
if (ret !== null) this.emit('data', ret);
return ret;
};
function onEofChunk(stream, state) {
if (state.ended) return;
if (state.decoder) {
var chunk = state.decoder.end();
if (chunk && chunk.length) {
state.buffer.push(chunk);
state.length += state.objectMode ? 1 : chunk.length;
}
}
state.ended = true;
// emit 'readable' now to make sure it gets picked up.
emitReadable(stream);
}
// Don't emit readable right away in sync mode, because this can trigger
// another read() call => stack overflow. This way, it might trigger
// a nextTick recursion warning, but that's not so bad.
function emitReadable(stream) {
var state = stream._readableState;
state.needReadable = false;
if (!state.emittedReadable) {
debug('emitReadable', state.flowing);
state.emittedReadable = true;
if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
}
}
function emitReadable_(stream) {
debug('emit readable');
stream.emit('readable');
flow(stream);
}
// at this point, the user has presumably seen the 'readable' event,
// and called read() to consume some data. that may have triggered
// in turn another _read(n) call, in which case reading = true if
// it's in progress.
// However, if we're not ended, or reading, and the length < hwm,
// then go ahead and try to read some more preemptively.
function maybeReadMore(stream, state) {
if (!state.readingMore) {
state.readingMore = true;
pna.nextTick(maybeReadMore_, stream, state);
}
}
function maybeReadMore_(stream, state) {
var len = state.length;
while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
debug('maybeReadMore read 0');
stream.read(0);
if (len === state.length)
// didn't get any data, stop spinning.
break;else len = state.length;
}
state.readingMore = false;
}
// abstract method. to be overridden in specific implementation classes.
// call cb(er, data) where data is <= n in length.
// for virtual (non-string, non-buffer) streams, "length" is somewhat
// arbitrary, and perhaps not very meaningful.
Readable.prototype._read = function (n) {
this.emit('error', new Error('_read() is not implemented'));
};
Readable.prototype.pipe = function (dest, pipeOpts) {
var src = this;
var state = this._readableState;
switch (state.pipesCount) {
case 0:
state.pipes = dest;
break;
case 1:
state.pipes = [state.pipes, dest];
break;
default:
state.pipes.push(dest);
break;
}
state.pipesCount += 1;
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
var endFn = doEnd ? onend : unpipe;
if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
dest.on('unpipe', onunpipe);
function onunpipe(readable, unpipeInfo) {
debug('onunpipe');
if (readable === src) {
if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
unpipeInfo.hasUnpiped = true;
cleanup();
}
}
}
function onend() {
debug('onend');
dest.end();
}
// when the dest drains, it reduces the awaitDrain counter
// on the source. This would be more elegant with a .once()
// handler in flow(), but adding and removing repeatedly is
// too slow.
var ondrain = pipeOnDrain(src);
dest.on('drain', ondrain);
var cleanedUp = false;
function cleanup() {
debug('cleanup');
// cleanup event handlers once the pipe is broken
dest.removeListener('close', onclose);
dest.removeListener('finish', onfinish);
dest.removeListener('drain', ondrain);
dest.removeListener('error', onerror);
dest.removeListener('unpipe', onunpipe);
src.removeListener('end', onend);
src.removeListener('end', unpipe);
src.removeListener('data', ondata);
cleanedUp = true;
// if the reader is waiting for a drain event from this
// specific writer, then it would cause it to never start
// flowing again.
// So, if this is awaiting a drain, then we just call it now.
// If we don't know, then assume that we are waiting for one.
if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
}
// If the user pushes more data while we're writing to dest then we'll end up
// in ondata again. However, we only want to increase awaitDrain once because
// dest will only emit one 'drain' event for the multiple writes.
// => Introduce a guard on increasing awaitDrain.
var increasedAwaitDrain = false;
src.on('data', ondata);
function ondata(chunk) {
debug('ondata');
increasedAwaitDrain = false;
var ret = dest.write(chunk);
if (false === ret && !increasedAwaitDrain) {
// If the user unpiped during `dest.write()`, it is possible
// to get stuck in a permanently paused state if that write
// also returned false.
// => Check whether `dest` is still a piping destination.
if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
debug('false write response, pause', src._readableState.awaitDrain);
src._readableState.awaitDrain++;
increasedAwaitDrain = true;
}
src.pause();
}
}
// if the dest has an error, then stop piping into it.
// however, don't suppress the throwing behavior for this.
function onerror(er) {
debug('onerror', er);
unpipe();
dest.removeListener('error', onerror);
if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
}
// Make sure our error handler is attached before userland ones.
prependListener(dest, 'error', onerror);
// Both close and finish should trigger unpipe, but only once.
function onclose() {
dest.removeListener('finish', onfinish);
unpipe();
}
dest.once('close', onclose);
function onfinish() {
debug('onfinish');
dest.removeListener('close', onclose);
unpipe();
}
dest.once('finish', onfinish);
function unpipe() {
debug('unpipe');
src.unpipe(dest);
}
// tell the dest that it's being piped to
dest.emit('pipe', src);
// start the flow if it hasn't been started already.
if (!state.flowing) {
debug('pipe resume');
src.resume();
}
return dest;
};
function pipeOnDrain(src) {
return function () {
var state = src._readableState;
debug('pipeOnDrain', state.awaitDrain);
if (state.awaitDrain) state.awaitDrain--;
if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
state.flowing = true;
flow(src);
}
};
}
Readable.prototype.unpipe = function (dest) {
var state = this._readableState;
var unpipeInfo = { hasUnpiped: false };
// if we're not piping anywhere, then do nothing.
if (state.pipesCount === 0) return this;
// just one destination. most common case.
if (state.pipesCount === 1) {
// passed in one, but it's not the right one.
if (dest && dest !== state.pipes) return this;
if (!dest) dest = state.pipes;
// got a match.
state.pipes = null;
state.pipesCount = 0;
state.flowing = false;
if (dest) dest.emit('unpipe', this, unpipeInfo);
return this;
}
// slow case. multiple pipe destinations.
if (!dest) {
// remove all.
var dests = state.pipes;
var len = state.pipesCount;
state.pipes = null;
state.pipesCount = 0;
state.flowing = false;
for (var i = 0; i < len; i++) {
dests[i].emit('unpipe', this, unpipeInfo);
}return this;
}
// try to find the right one.
var index = indexOf(state.pipes, dest);
if (index === -1) return this;
state.pipes.splice(index, 1);
state.pipesCount -= 1;
if (state.pipesCount === 1) state.pipes = state.pipes[0];
dest.emit('unpipe', this, unpipeInfo);
return this;
};
// set up data events if they are asked for
// Ensure readable listeners eventually get something
Readable.prototype.on = function (ev, fn) {
var res = Stream.prototype.on.call(this, ev, fn);
if (ev === 'data') {
// Start flowing on next tick if stream isn't explicitly paused
if (this._readableState.flowing !== false) this.resume();
} else if (ev === 'readable') {
var state = this._readableState;
if (!state.endEmitted && !state.readableListening) {
state.readableListening = state.needReadable = true;
state.emittedReadable = false;
if (!state.reading) {
pna.nextTick(nReadingNextTick, this);
} else if (state.length) {
emitReadable(this);
}
}
}
return res;
};
Readable.prototype.addListener = Readable.prototype.on;
function nReadingNextTick(self) {
debug('readable nexttick read 0');
self.read(0);
}
// pause() and resume() are remnants of the legacy readable stream API
// If the user uses them, then switch into old mode.
Readable.prototype.resume = function () {
var state = this._readableState;
if (!state.flowing) {
debug('resume');
state.flowing = true;
resume(this, state);
}
return this;
};
function resume(stream, state) {
if (!state.resumeScheduled) {
state.resumeScheduled = true;
pna.nextTick(resume_, stream, state);
}
}
function resume_(stream, state) {
if (!state.reading) {
debug('resume read 0');
stream.read(0);
}
state.resumeScheduled = false;
state.awaitDrain = 0;
stream.emit('resume');
flow(stream);
if (state.flowing && !state.reading) stream.read(0);
}
Readable.prototype.pause = function () {
debug('call pause flowing=%j', this._readableState.flowing);
if (false !== this._readableState.flowing) {
debug('pause');
this._readableState.flowing = false;
this.emit('pause');
}
return this;
};
function flow(stream) {
var state = stream._readableState;
debug('flow', state.flowing);
while (state.flowing && stream.read() !== null) {}
}
// wrap an old-style stream as the async data source.
// This is *not* part of the readable stream interface.
// It is an ugly unfortunate mess of history.
Readable.prototype.wrap = function (stream) {
var _this = this;
var state = this._readableState;
var paused = false;
stream.on('end', function () {
debug('wrapped end');
if (state.decoder && !state.ended) {
var chunk = state.decoder.end();
if (chunk && chunk.length) _this.push(chunk);
}
_this.push(null);
});
stream.on('data', function (chunk) {
debug('wrapped data');
if (state.decoder) chunk = state.decoder.write(chunk);
// don't skip over falsy values in objectMode
if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
var ret = _this.push(chunk);
if (!ret) {
paused = true;
stream.pause();
}
});
// proxy all the other methods.
// important when wrapping filters and duplexes.
for (var i in stream) {
if (this[i] === undefined && typeof stream[i] === 'function') {
this[i] = function (method) {
return function () {
return stream[method].apply(stream, arguments);
};
}(i);
}
}
// proxy certain important events.
for (var n = 0; n < kProxyEvents.length; n++) {
stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
}
// when we try to consume some more bytes, simply unpause the
// underlying stream.
this._read = function (n) {
debug('wrapped _read', n);
if (paused) {
paused = false;
stream.resume();
}
};
return this;
};
Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
// making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function () {
return this._readableState.highWaterMark;
}
});
// exposed for testing purposes only.
Readable._fromList = fromList;
// Pluck off n bytes from an array of buffers.
// Length is the combined lengths of all the buffers in the list.
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function fromList(n, state) {
// nothing buffered
if (state.length === 0) return null;
var ret;
if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
// read it all, truncate the list
if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length);
state.buffer.clear();
} else {
// read part of list
ret = fromListPartial(n, state.buffer, state.decoder);
}
return ret;
}
// Extracts only enough buffered data to satisfy the amount requested.
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function fromListPartial(n, list, hasStrings) {
var ret;
if (n < list.head.data.length) {
// slice is the same for buffers and strings
ret = list.head.data.slice(0, n);
list.head.data = list.head.data.slice(n);
} else if (n === list.head.data.length) {
// first chunk is a perfect match
ret = list.shift();
} else {
// result spans more than one buffer
ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
}
return ret;
}
// Copies a specified amount of characters from the list of buffered data
// chunks.
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function copyFromBufferString(n, list) {
var p = list.head;
var c = 1;
var ret = p.data;
n -= ret.length;
while (p = p.next) {
var str = p.data;
var nb = n > str.length ? str.length : n;
if (nb === str.length) ret += str;else ret += str.slice(0, n);
n -= nb;
if (n === 0) {
if (nb === str.length) {
++c;
if (p.next) list.head = p.next;else list.head = list.tail = null;
} else {
list.head = p;
p.data = str.slice(nb);
}
break;
}
++c;
}
list.length -= c;
return ret;
}
// Copies a specified amount of bytes from the list of buffered data chunks.
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function copyFromBuffer(n, list) {
var ret = Buffer.allocUnsafe(n);
var p = list.head;
var c = 1;
p.data.copy(ret);
n -= p.data.length;
while (p = p.next) {
var buf = p.data;
var nb = n > buf.length ? buf.length : n;
buf.copy(ret, ret.length - n, 0, nb);
n -= nb;
if (n === 0) {
if (nb === buf.length) {
++c;
if (p.next) list.head = p.next;else list.head = list.tail = null;
} else {
list.head = p;
p.data = buf.slice(nb);
}
break;
}
++c;
}
list.length -= c;
return ret;
}
function endReadable(stream) {
var state = stream._readableState;
// If we get here before consuming all the bytes, then that is a
// bug in node. Should never happen.
if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
if (!state.endEmitted) {
state.ended = true;
pna.nextTick(endReadableNT, state, stream);
}
}
function endReadableNT(state, stream) {
// Check that we didn't get one last unshift.
if (!state.endEmitted && state.length === 0) {
state.endEmitted = true;
stream.readable = false;
stream.emit('end');
}
}
function indexOf(xs, x) {
for (var i = 0, l = xs.length; i < l; i++) {
if (xs[i] === x) return i;
}
return -1;
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js")));
/***/ }),
/***/ "./node_modules/readable-stream/lib/_stream_transform.js":
/*!***************************************************************!*\
!*** ./node_modules/readable-stream/lib/_stream_transform.js ***!
\***************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// a transform stream is a readable/writable stream where you do
// something with the data. Sometimes it's called a "filter",
// but that's not a great name for it, since that implies a thing where
// some bits pass through, and others are simply ignored. (That would
// be a valid example of a transform, of course.)
//
// While the output is causally related to the input, it's not a
// necessarily symmetric or synchronous transformation. For example,
// a zlib stream might take multiple plain-text writes(), and then
// emit a single compressed chunk some time in the future.
//
// Here's how this works:
//
// The Transform stream has all the aspects of the readable and writable
// stream classes. When you write(chunk), that calls _write(chunk,cb)
// internally, and returns false if there's a lot of pending writes
// buffered up. When you call read(), that calls _read(n) until
// there's enough pending readable data buffered up.
//
// In a transform stream, the written data is placed in a buffer. When
// _read(n) is called, it transforms the queued up data, calling the
// buffered _write cb's as it consumes chunks. If consuming a single
// written chunk would result in multiple output chunks, then the first
// outputted bit calls the readcb, and subsequent chunks just go into
// the read buffer, and will cause it to emit 'readable' if necessary.
//
// This way, back-pressure is actually determined by the reading side,
// since _read has to be called to start processing a new chunk. However,
// a pathological inflate type of transform can cause excessive buffering
// here. For example, imagine a stream where every byte of input is
// interpreted as an integer from 0-255, and then results in that many
// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
// 1kb of data being output. In this case, you could write a very small
// amount of input, and end up with a very large amount of output. In
// such a pathological inflating mechanism, there'd be no way to tell
// the system to stop doing the transform. A single 4MB write could
// cause the system to run out of memory.
//
// However, even in such a pathological case, only a single written chunk
// would be consumed, and then the rest would wait (un-transformed) until
// the results of the previous transformed chunk were consumed.
module.exports = Transform;
var Duplex = __webpack_require__(/*! ./_stream_duplex */ "./node_modules/readable-stream/lib/_stream_duplex.js");
/*<replacement>*/
var util = __webpack_require__(/*! core-util-is */ "./node_modules/core-util-is/lib/util.js");
util.inherits = __webpack_require__(/*! inherits */ "./node_modules/inherits/inherits_browser.js");
/*</replacement>*/
util.inherits(Transform, Duplex);
function afterTransform(er, data) {
var ts = this._transformState;
ts.transforming = false;
var cb = ts.writecb;
if (!cb) {
return this.emit('error', new Error('write callback called multiple times'));
}
ts.writechunk = null;
ts.writecb = null;
if (data != null) // single equals check for both `null` and `undefined`
this.push(data);
cb(er);
var rs = this._readableState;
rs.reading = false;
if (rs.needReadable || rs.length < rs.highWaterMark) {
this._read(rs.highWaterMark);
}
}
function Transform(options) {
if (!(this instanceof Transform)) return new Transform(options);
Duplex.call(this, options);
this._transformState = {
afterTransform: afterTransform.bind(this),
needTransform: false,
transforming: false,
writecb: null,
writechunk: null,
writeencoding: null
};
// start out asking for a readable event once data is transformed.
this._readableState.needReadable = true;
// we have implemented the _read method, and done the other things
// that Readable wants before the first _read call, so unset the
// sync guard flag.
this._readableState.sync = false;
if (options) {
if (typeof options.transform === 'function') this._transform = options.transform;
if (typeof options.flush === 'function') this._flush = options.flush;
}
// When the writable side finishes, then flush out anything remaining.
this.on('prefinish', prefinish);
}
function prefinish() {
var _this = this;
if (typeof this._flush === 'function') {
this._flush(function (er, data) {
done(_this, er, data);
});
} else {
done(this, null, null);
}
}
Transform.prototype.push = function (chunk, encoding) {
this._transformState.needTransform = false;
return Duplex.prototype.push.call(this, chunk, encoding);
};
// This is the part where you do stuff!
// override this function in implementation classes.
// 'chunk' is an input chunk.
//
// Call `push(newChunk)` to pass along transformed output
// to the readable side. You may call 'push' zero or more times.
//
// Call `cb(err)` when you are done with this chunk. If you pass
// an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk.
Transform.prototype._transform = function (chunk, encoding, cb) {
throw new Error('_transform() is not implemented');
};
Transform.prototype._write = function (chunk, encoding, cb) {
var ts = this._transformState;
ts.writecb = cb;
ts.writechunk = chunk;
ts.writeencoding = encoding;
if (!ts.transforming) {
var rs = this._readableState;
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
}
};
// Doesn't matter what the args are here.
// _transform does all the work.
// That we got here means that the readable side wants more data.
Transform.prototype._read = function (n) {
var ts = this._transformState;
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
ts.transforming = true;
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
} else {
// mark that we need a transform, so that any data that comes in
// will get processed, now that we've asked for it.
ts.needTransform = true;
}
};
Transform.prototype._destroy = function (err, cb) {
var _this2 = this;
Duplex.prototype._destroy.call(this, err, function (err2) {
cb(err2);
_this2.emit('close');
});
};
function done(stream, er, data) {
if (er) return stream.emit('error', er);
if (data != null) // single equals check for both `null` and `undefined`
stream.push(data);
// if there's nothing in the write buffer, then that means
// that nothing more will ever be provided
if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
return stream.push(null);
}
/***/ }),
/***/ "./node_modules/readable-stream/lib/_stream_writable.js":
/*!**************************************************************!*\
!*** ./node_modules/readable-stream/lib/_stream_writable.js ***!
\**************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process, setImmediate, global) {// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// A bit simpler than readable streams.
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
// the drain event emission and buffering.
/*<replacement>*/
var pna = __webpack_require__(/*! process-nextick-args */ "./node_modules/process-nextick-args/index.js");
/*</replacement>*/
module.exports = Writable;
// It seems a linked list but it is not
// there will be only 2 of these for each stream
function CorkedRequest(state) {
var _this = this;
this.next = null;
this.entry = null;
this.finish = function () {
onCorkedFinish(_this, state);
};
}
/* </replacement> */
/*<replacement>*/
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
/*</replacement>*/
/*<replacement>*/
var Duplex;
/*</replacement>*/
Writable.WritableState = WritableState;
/*<replacement>*/
var util = __webpack_require__(/*! core-util-is */ "./node_modules/core-util-is/lib/util.js");
util.inherits = __webpack_require__(/*! inherits */ "./node_modules/inherits/inherits_browser.js");
/*</replacement>*/
/*<replacement>*/
var internalUtil = {
deprecate: __webpack_require__(/*! util-deprecate */ "./node_modules/util-deprecate/browser.js")
};
/*</replacement>*/
/*<replacement>*/
var Stream = __webpack_require__(/*! ./internal/streams/stream */ "./node_modules/readable-stream/lib/internal/streams/stream-browser.js");
/*</replacement>*/
/*<replacement>*/
var Buffer = __webpack_require__(/*! safe-buffer */ "./node_modules/safe-buffer/index.js").Buffer;
var OurUint8Array = global.Uint8Array || function () {};
function _uint8ArrayToBuffer(chunk) {
return Buffer.from(chunk);
}
function _isUint8Array(obj) {
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
}
/*</replacement>*/
var destroyImpl = __webpack_require__(/*! ./internal/streams/destroy */ "./node_modules/readable-stream/lib/internal/streams/destroy.js");
util.inherits(Writable, Stream);
function nop() {}
function WritableState(options, stream) {
Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/readable-stream/lib/_stream_duplex.js");
options = options || {};
// Duplex streams are both readable and writable, but share
// the same options object.
// However, some cases require setting options to different
// values for the readable and the writable sides of the duplex stream.
// These options can be provided separately as readableXXX and writableXXX.
var isDuplex = stream instanceof Duplex;
// object stream flag to indicate whether or not this stream
// contains buffers or objects.
this.objectMode = !!options.objectMode;
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
// the point at which write() starts returning false
// Note: 0 is a valid value, means that we always return false if
// the entire buffer is not flushed immediately on write()
var hwm = options.highWaterMark;
var writableHwm = options.writableHighWaterMark;
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
// cast to ints.
this.highWaterMark = Math.floor(this.highWaterMark);
// if _final has been called
this.finalCalled = false;
// drain event flag.
this.needDrain = false;
// at the start of calling end()
this.ending = false;
// when end() has been called, and returned
this.ended = false;
// when 'finish' is emitted
this.finished = false;
// has it been destroyed
this.destroyed = false;
// should we decode strings into buffers before passing to _write?
// this is here so that some node-core streams can optimize string
// handling at a lower level.
var noDecode = options.decodeStrings === false;
this.decodeStrings = !noDecode;
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
// not an actual buffer we keep track of, but a measurement
// of how much we're waiting to get pushed to some underlying
// socket or file.
this.length = 0;
// a flag to see when we're in the middle of a write.
this.writing = false;
// when true all writes will be buffered until .uncork() call
this.corked = 0;
// a flag to be able to tell if the onwrite cb is called immediately,
// or on a later tick. We set this to true at first, because any
// actions that shouldn't happen until "later" should generally also
// not happen before the first write call.
this.sync = true;
// a flag to know if we're processing previously buffered items, which
// may call the _write() callback in the same tick, so that we don't
// end up in an overlapped onwrite situation.
this.bufferProcessing = false;
// the callback that's passed to _write(chunk,cb)
this.onwrite = function (er) {
onwrite(stream, er);
};
// the callback that the user supplies to write(chunk,encoding,cb)
this.writecb = null;
// the amount that is being written when _write is called.
this.writelen = 0;
this.bufferedRequest = null;
this.lastBufferedRequest = null;
// number of pending user-supplied write callbacks
// this must be 0 before 'finish' can be emitted
this.pendingcb = 0;
// emit prefinish if the only thing we're waiting for is _write cbs
// This is relevant for synchronous Transform streams
this.prefinished = false;
// True if the error was already emitted and should not be thrown again
this.errorEmitted = false;
// count buffered requests
this.bufferedRequestCount = 0;
// allocate the first CorkedRequest, there is always
// one allocated and free to use, and we maintain at most two
this.corkedRequestsFree = new CorkedRequest(this);
}
WritableState.prototype.getBuffer = function getBuffer() {
var current = this.bufferedRequest;
var out = [];
while (current) {
out.push(current);
current = current.next;
}
return out;
};
(function () {
try {
Object.defineProperty(WritableState.prototype, 'buffer', {
get: internalUtil.deprecate(function () {
return this.getBuffer();
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
});
} catch (_) {}
})();
// Test _writableState for inheritance to account for Duplex streams,
// whose prototype chain only points to Readable.
var realHasInstance;
if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
realHasInstance = Function.prototype[Symbol.hasInstance];
Object.defineProperty(Writable, Symbol.hasInstance, {
value: function (object) {
if (realHasInstance.call(this, object)) return true;
if (this !== Writable) return false;
return object && object._writableState instanceof WritableState;
}
});
} else {
realHasInstance = function (object) {
return object instanceof this;
};
}
function Writable(options) {
Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/readable-stream/lib/_stream_duplex.js");
// Writable ctor is applied to Duplexes, too.
// `realHasInstance` is necessary because using plain `instanceof`
// would return false, as no `_writableState` property is attached.
// Trying to use the custom `instanceof` for Writable here will also break the
// Node.js LazyTransform implementation, which has a non-trivial getter for
// `_writableState` that would lead to infinite recursion.
if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
return new Writable(options);
}
this._writableState = new WritableState(options, this);
// legacy.
this.writable = true;
if (options) {
if (typeof options.write === 'function') this._write = options.write;
if (typeof options.writev === 'function') this._writev = options.writev;
if (typeof options.destroy === 'function') this._destroy = options.destroy;
if (typeof options.final === 'function') this._final = options.final;
}
Stream.call(this);
}
// Otherwise people can pipe Writable streams, which is just wrong.
Writable.prototype.pipe = function () {
this.emit('error', new Error('Cannot pipe, not readable'));
};
function writeAfterEnd(stream, cb) {
var er = new Error('write after end');
// TODO: defer error events consistently everywhere, not just the cb
stream.emit('error', er);
pna.nextTick(cb, er);
}
// Checks that a user-supplied chunk is valid, especially for the particular
// mode the stream is in. Currently this means that `null` is never accepted
// and undefined/non-string values are only allowed in object mode.
function validChunk(stream, state, chunk, cb) {
var valid = true;
var er = false;
if (chunk === null) {
er = new TypeError('May not write null values to stream');
} else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
er = new TypeError('Invalid non-string/buffer chunk');
}
if (er) {
stream.emit('error', er);
pna.nextTick(cb, er);
valid = false;
}
return valid;
}
Writable.prototype.write = function (chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
var isBuf = !state.objectMode && _isUint8Array(chunk);
if (isBuf && !Buffer.isBuffer(chunk)) {
chunk = _uint8ArrayToBuffer(chunk);
}
if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
if (typeof cb !== 'function') cb = nop;
if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
state.pendingcb++;
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
}
return ret;
};
Writable.prototype.cork = function () {
var state = this._writableState;
state.corked++;
};
Writable.prototype.uncork = function () {
var state = this._writableState;
if (state.corked) {
state.corked--;
if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
}
};
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
// node::ParseEncoding() requires lower case.
if (typeof encoding === 'string') encoding = encoding.toLowerCase();
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
this._writableState.defaultEncoding = encoding;
return this;
};
function decodeChunk(state, chunk, encoding) {
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
chunk = Buffer.from(chunk, encoding);
}
return chunk;
}
Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
// making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function () {
return this._writableState.highWaterMark;
}
});
// if we're already writing something, then just put this
// in the queue, and wait our turn. Otherwise, call _write
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
if (!isBuf) {
var newChunk = decodeChunk(state, chunk, encoding);
if (chunk !== newChunk) {
isBuf = true;
encoding = 'buffer';
chunk = newChunk;
}
}
var len = state.objectMode ? 1 : chunk.length;
state.length += len;
var ret = state.length < state.highWaterMark;
// we must ensure that previous needDrain will not be reset to false.
if (!ret) state.needDrain = true;
if (state.writing || state.corked) {
var last = state.lastBufferedRequest;
state.lastBufferedRequest = {
chunk: chunk,
encoding: encoding,
isBuf: isBuf,
callback: cb,
next: null
};
if (last) {
last.next = state.lastBufferedRequest;
} else {
state.bufferedRequest = state.lastBufferedRequest;
}
state.bufferedRequestCount += 1;
} else {
doWrite(stream, state, false, len, chunk, encoding, cb);
}
return ret;
}
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
state.writelen = len;
state.writecb = cb;
state.writing = true;
state.sync = true;
if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
state.sync = false;
}
function onwriteError(stream, state, sync, er, cb) {
--state.pendingcb;
if (sync) {
// defer the callback if we are being called synchronously
// to avoid piling up things on the stack
pna.nextTick(cb, er);
// this can emit finish, and it will always happen
// after error
pna.nextTick(finishMaybe, stream, state);
stream._writableState.errorEmitted = true;
stream.emit('error', er);
} else {
// the caller expect this to happen before if
// it is async
cb(er);
stream._writableState.errorEmitted = true;
stream.emit('error', er);
// this can emit finish, but finish must
// always follow error
finishMaybe(stream, state);
}
}
function onwriteStateUpdate(state) {
state.writing = false;
state.writecb = null;
state.length -= state.writelen;
state.writelen = 0;
}
function onwrite(stream, er) {
var state = stream._writableState;
var sync = state.sync;
var cb = state.writecb;
onwriteStateUpdate(state);
if (er) onwriteError(stream, state, sync, er, cb);else {
// Check if we're actually ready to finish, but don't emit yet
var finished = needFinish(state);
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
clearBuffer(stream, state);
}
if (sync) {
/*<replacement>*/
asyncWrite(afterWrite, stream, state, finished, cb);
/*</replacement>*/
} else {
afterWrite(stream, state, finished, cb);
}
}
}
function afterWrite(stream, state, finished, cb) {
if (!finished) onwriteDrain(stream, state);
state.pendingcb--;
cb();
finishMaybe(stream, state);
}
// Must force callback to be called on nextTick, so that we don't
// emit 'drain' before the write() consumer gets the 'false' return
// value, and has a chance to attach a 'drain' listener.
function onwriteDrain(stream, state) {
if (state.length === 0 && state.needDrain) {
state.needDrain = false;
stream.emit('drain');
}
}
// if there's something in the buffer waiting, then process it
function clearBuffer(stream, state) {
state.bufferProcessing = true;
var entry = state.bufferedRequest;
if (stream._writev && entry && entry.next) {
// Fast case, write everything using _writev()
var l = state.bufferedRequestCount;
var buffer = new Array(l);
var holder = state.corkedRequestsFree;
holder.entry = entry;
var count = 0;
var allBuffers = true;
while (entry) {
buffer[count] = entry;
if (!entry.isBuf) allBuffers = false;
entry = entry.next;
count += 1;
}
buffer.allBuffers = allBuffers;
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
// doWrite is almost always async, defer these to save a bit of time
// as the hot path ends with doWrite
state.pendingcb++;
state.lastBufferedRequest = null;
if (holder.next) {
state.corkedRequestsFree = holder.next;
holder.next = null;
} else {
state.corkedRequestsFree = new CorkedRequest(state);
}
state.bufferedRequestCount = 0;
} else {
// Slow case, write chunks one-by-one
while (entry) {
var chunk = entry.chunk;
var encoding = entry.encoding;
var cb = entry.callback;
var len = state.objectMode ? 1 : chunk.length;
doWrite(stream, state, false, len, chunk, encoding, cb);
entry = entry.next;
state.bufferedRequestCount--;
// if we didn't call the onwrite immediately, then
// it means that we need to wait until it does.
// also, that means that the chunk and cb are currently
// being processed, so move the buffer counter past them.
if (state.writing) {
break;
}
}
if (entry === null) state.lastBufferedRequest = null;
}
state.bufferedRequest = entry;
state.bufferProcessing = false;
}
Writable.prototype._write = function (chunk, encoding, cb) {
cb(new Error('_write() is not implemented'));
};
Writable.prototype._writev = null;
Writable.prototype.end = function (chunk, encoding, cb) {
var state = this._writableState;
if (typeof chunk === 'function') {
cb = chunk;
chunk = null;
encoding = null;
} else if (typeof encoding === 'function') {
cb = encoding;
encoding = null;
}
if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
// .end() fully uncorks
if (state.corked) {
state.corked = 1;
this.uncork();
}
// ignore unnecessary end() calls.
if (!state.ending && !state.finished) endWritable(this, state, cb);
};
function needFinish(state) {
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
}
function callFinal(stream, state) {
stream._final(function (err) {
state.pendingcb--;
if (err) {
stream.emit('error', err);
}
state.prefinished = true;
stream.emit('prefinish');
finishMaybe(stream, state);
});
}
function prefinish(stream, state) {
if (!state.prefinished && !state.finalCalled) {
if (typeof stream._final === 'function') {
state.pendingcb++;
state.finalCalled = true;
pna.nextTick(callFinal, stream, state);
} else {
state.prefinished = true;
stream.emit('prefinish');
}
}
}
function finishMaybe(stream, state) {
var need = needFinish(state);
if (need) {
prefinish(stream, state);
if (state.pendingcb === 0) {
state.finished = true;
stream.emit('finish');
}
}
return need;
}
function endWritable(stream, state, cb) {
state.ending = true;
finishMaybe(stream, state);
if (cb) {
if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
}
state.ended = true;
stream.writable = false;
}
function onCorkedFinish(corkReq, state, err) {
var entry = corkReq.entry;
corkReq.entry = null;
while (entry) {
var cb = entry.callback;
state.pendingcb--;
cb(err);
entry = entry.next;
}
if (state.corkedRequestsFree) {
state.corkedRequestsFree.next = corkReq;
} else {
state.corkedRequestsFree = corkReq;
}
}
Object.defineProperty(Writable.prototype, 'destroyed', {
get: function () {
if (this._writableState === undefined) {
return false;
}
return this._writableState.destroyed;
},
set: function (value) {
// we ignore the value if the stream
// has not been initialized yet
if (!this._writableState) {
return;
}
// backward compatibility, the user is explicitly
// managing destroyed
this._writableState.destroyed = value;
}
});
Writable.prototype.destroy = destroyImpl.destroy;
Writable.prototype._undestroy = destroyImpl.undestroy;
Writable.prototype._destroy = function (err, cb) {
this.end();
cb(err);
};
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js"), __webpack_require__(/*! ./../../node-libs-browser/node_modules/timers-browserify/main.js */ "./node_modules/node-libs-browser/node_modules/timers-browserify/main.js").setImmediate, __webpack_require__(/*! ./../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")));
/***/ }),
/***/ "./node_modules/readable-stream/lib/internal/streams/BufferList.js":
/*!*************************************************************************!*\
!*** ./node_modules/readable-stream/lib/internal/streams/BufferList.js ***!
\*************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Buffer = __webpack_require__(/*! safe-buffer */ "./node_modules/safe-buffer/index.js").Buffer;
var util = __webpack_require__(/*! util */ 1);
function copyBuffer(src, target, offset) {
src.copy(target, offset);
}
module.exports = function () {
function BufferList() {
_classCallCheck(this, BufferList);
this.head = null;
this.tail = null;
this.length = 0;
}
BufferList.prototype.push = function push(v) {
var entry = { data: v, next: null };
if (this.length > 0) this.tail.next = entry;else this.head = entry;
this.tail = entry;
++this.length;
};
BufferList.prototype.unshift = function unshift(v) {
var entry = { data: v, next: this.head };
if (this.length === 0) this.tail = entry;
this.head = entry;
++this.length;
};
BufferList.prototype.shift = function shift() {
if (this.length === 0) return;
var ret = this.head.data;
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
--this.length;
return ret;
};
BufferList.prototype.clear = function clear() {
this.head = this.tail = null;
this.length = 0;
};
BufferList.prototype.join = function join(s) {
if (this.length === 0) return '';
var p = this.head;
var ret = '' + p.data;
while (p = p.next) {
ret += s + p.data;
}return ret;
};
BufferList.prototype.concat = function concat(n) {
if (this.length === 0) return Buffer.alloc(0);
if (this.length === 1) return this.head.data;
var ret = Buffer.allocUnsafe(n >>> 0);
var p = this.head;
var i = 0;
while (p) {
copyBuffer(p.data, ret, i);
i += p.data.length;
p = p.next;
}
return ret;
};
return BufferList;
}();
if (util && util.inspect && util.inspect.custom) {
module.exports.prototype[util.inspect.custom] = function () {
var obj = util.inspect({ length: this.length });
return this.constructor.name + ' ' + obj;
};
}
/***/ }),
/***/ "./node_modules/readable-stream/lib/internal/streams/destroy.js":
/*!**********************************************************************!*\
!*** ./node_modules/readable-stream/lib/internal/streams/destroy.js ***!
\**********************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/*<replacement>*/
var pna = __webpack_require__(/*! process-nextick-args */ "./node_modules/process-nextick-args/index.js");
/*</replacement>*/
// undocumented cb() API, needed for core, not for public API
function destroy(err, cb) {
var _this = this;
var readableDestroyed = this._readableState && this._readableState.destroyed;
var writableDestroyed = this._writableState && this._writableState.destroyed;
if (readableDestroyed || writableDestroyed) {
if (cb) {
cb(err);
} else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
pna.nextTick(emitErrorNT, this, err);
}
return this;
}
// we set destroyed to true before firing error callbacks in order
// to make it re-entrance safe in case destroy() is called within callbacks
if (this._readableState) {
this._readableState.destroyed = true;
}
// if this is a duplex stream mark the writable part as destroyed as well
if (this._writableState) {
this._writableState.destroyed = true;
}
this._destroy(err || null, function (err) {
if (!cb && err) {
pna.nextTick(emitErrorNT, _this, err);
if (_this._writableState) {
_this._writableState.errorEmitted = true;
}
} else if (cb) {
cb(err);
}
});
return this;
}
function undestroy() {
if (this._readableState) {
this._readableState.destroyed = false;
this._readableState.reading = false;
this._readableState.ended = false;
this._readableState.endEmitted = false;
}
if (this._writableState) {
this._writableState.destroyed = false;
this._writableState.ended = false;
this._writableState.ending = false;
this._writableState.finished = false;
this._writableState.errorEmitted = false;
}
}
function emitErrorNT(self, err) {
self.emit('error', err);
}
module.exports = {
destroy: destroy,
undestroy: undestroy
};
/***/ }),
/***/ "./node_modules/readable-stream/lib/internal/streams/stream-browser.js":
/*!*****************************************************************************!*\
!*** ./node_modules/readable-stream/lib/internal/streams/stream-browser.js ***!
\*****************************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! events */ "./node_modules/node-libs-browser/node_modules/events/events.js").EventEmitter;
/***/ }),
/***/ "./node_modules/readable-stream/passthrough.js":
/*!*****************************************************!*\
!*** ./node_modules/readable-stream/passthrough.js ***!
\*****************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./readable */ "./node_modules/readable-stream/readable-browser.js").PassThrough;
/***/ }),
/***/ "./node_modules/readable-stream/readable-browser.js":
/*!**********************************************************!*\
!*** ./node_modules/readable-stream/readable-browser.js ***!
\**********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(/*! ./lib/_stream_readable.js */ "./node_modules/readable-stream/lib/_stream_readable.js");
exports.Stream = exports;
exports.Readable = exports;
exports.Writable = __webpack_require__(/*! ./lib/_stream_writable.js */ "./node_modules/readable-stream/lib/_stream_writable.js");
exports.Duplex = __webpack_require__(/*! ./lib/_stream_duplex.js */ "./node_modules/readable-stream/lib/_stream_duplex.js");
exports.Transform = __webpack_require__(/*! ./lib/_stream_transform.js */ "./node_modules/readable-stream/lib/_stream_transform.js");
exports.PassThrough = __webpack_require__(/*! ./lib/_stream_passthrough.js */ "./node_modules/readable-stream/lib/_stream_passthrough.js");
/***/ }),
/***/ "./node_modules/readable-stream/transform.js":
/*!***************************************************!*\
!*** ./node_modules/readable-stream/transform.js ***!
\***************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./readable */ "./node_modules/readable-stream/readable-browser.js").Transform;
/***/ }),
/***/ "./node_modules/readable-stream/writable-browser.js":
/*!**********************************************************!*\
!*** ./node_modules/readable-stream/writable-browser.js ***!
\**********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./lib/_stream_writable.js */ "./node_modules/readable-stream/lib/_stream_writable.js");
/***/ }),
/***/ "./node_modules/safe-buffer/index.js":
/*!*******************************************!*\
!*** ./node_modules/safe-buffer/index.js ***!
\*******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* eslint-disable node/no-deprecated-api */
var buffer = __webpack_require__(/*! buffer */ "./node_modules/node-libs-browser/node_modules/buffer/index.js");
var Buffer = buffer.Buffer;
// alternative to using Object.keys for old browsers
function copyProps (src, dst) {
for (var key in src) {
dst[key] = src[key];
}
}
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer;
} else {
// Copy properties from require('buffer')
copyProps(buffer, exports);
exports.Buffer = SafeBuffer;
}
function SafeBuffer (arg, encodingOrOffset, length) {
return Buffer(arg, encodingOrOffset, length)
}
// Copy static methods from Buffer
copyProps(Buffer, SafeBuffer);
SafeBuffer.from = function (arg, encodingOrOffset, length) {
if (typeof arg === 'number') {
throw new TypeError('Argument must not be a number')
}
return Buffer(arg, encodingOrOffset, length)
};
SafeBuffer.alloc = function (size, fill, encoding) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
var buf = Buffer(size);
if (fill !== undefined) {
if (typeof encoding === 'string') {
buf.fill(fill, encoding);
} else {
buf.fill(fill);
}
} else {
buf.fill(0);
}
return buf
};
SafeBuffer.allocUnsafe = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return Buffer(size)
};
SafeBuffer.allocUnsafeSlow = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return buffer.SlowBuffer(size)
};
/***/ }),
/***/ "./node_modules/sax/lib/sax.js":
/*!*************************************!*\
!*** ./node_modules/sax/lib/sax.js ***!
\*************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(Buffer) {(function (sax) { // wrapper for non-node envs
sax.parser = function (strict, opt) { return new SAXParser(strict, opt) };
sax.SAXParser = SAXParser;
sax.SAXStream = SAXStream;
sax.createStream = createStream;
// When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns.
// When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)),
// since that's the earliest that a buffer overrun could occur. This way, checks are
// as rare as required, but as often as necessary to ensure never crossing this bound.
// Furthermore, buffers are only tested at most once per write(), so passing a very
// large string into write() might have undesirable effects, but this is manageable by
// the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme
// edge case, result in creating at most one complete copy of the string passed in.
// Set to Infinity to have unlimited buffers.
sax.MAX_BUFFER_LENGTH = 64 * 1024;
var buffers = [
'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype',
'procInstName', 'procInstBody', 'entity', 'attribName',
'attribValue', 'cdata', 'script'
];
sax.EVENTS = [
'text',
'processinginstruction',
'sgmldeclaration',
'doctype',
'comment',
'opentagstart',
'attribute',
'opentag',
'closetag',
'opencdata',
'cdata',
'closecdata',
'error',
'end',
'ready',
'script',
'opennamespace',
'closenamespace'
];
function SAXParser (strict, opt) {
if (!(this instanceof SAXParser)) {
return new SAXParser(strict, opt)
}
var parser = this;
clearBuffers(parser);
parser.q = parser.c = '';
parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH;
parser.opt = opt || {};
parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags;
parser.looseCase = parser.opt.lowercase ? 'toLowerCase' : 'toUpperCase';
parser.tags = [];
parser.closed = parser.closedRoot = parser.sawRoot = false;
parser.tag = parser.error = null;
parser.strict = !!strict;
parser.noscript = !!(strict || parser.opt.noscript);
parser.state = S.BEGIN;
parser.strictEntities = parser.opt.strictEntities;
parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES);
parser.attribList = [];
// namespaces form a prototype chain.
// it always points at the current tag,
// which protos to its parent tag.
if (parser.opt.xmlns) {
parser.ns = Object.create(rootNS);
}
// mostly just for error reporting
parser.trackPosition = parser.opt.position !== false;
if (parser.trackPosition) {
parser.position = parser.line = parser.column = 0;
}
emit(parser, 'onready');
}
if (!Object.create) {
Object.create = function (o) {
function F () {}
F.prototype = o;
var newf = new F();
return newf
};
}
if (!Object.keys) {
Object.keys = function (o) {
var a = [];
for (var i in o) if (o.hasOwnProperty(i)) a.push(i);
return a
};
}
function checkBufferLength (parser) {
var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10);
var maxActual = 0;
for (var i = 0, l = buffers.length; i < l; i++) {
var len = parser[buffers[i]].length;
if (len > maxAllowed) {
// Text/cdata nodes can get big, and since they're buffered,
// we can get here under normal conditions.
// Avoid issues by emitting the text node now,
// so at least it won't get any bigger.
switch (buffers[i]) {
case 'textNode':
closeText(parser);
break
case 'cdata':
emitNode(parser, 'oncdata', parser.cdata);
parser.cdata = '';
break
case 'script':
emitNode(parser, 'onscript', parser.script);
parser.script = '';
break
default:
error(parser, 'Max buffer length exceeded: ' + buffers[i]);
}
}
maxActual = Math.max(maxActual, len);
}
// schedule the next check for the earliest possible buffer overrun.
var m = sax.MAX_BUFFER_LENGTH - maxActual;
parser.bufferCheckPosition = m + parser.position;
}
function clearBuffers (parser) {
for (var i = 0, l = buffers.length; i < l; i++) {
parser[buffers[i]] = '';
}
}
function flushBuffers (parser) {
closeText(parser);
if (parser.cdata !== '') {
emitNode(parser, 'oncdata', parser.cdata);
parser.cdata = '';
}
if (parser.script !== '') {
emitNode(parser, 'onscript', parser.script);
parser.script = '';
}
}
SAXParser.prototype = {
end: function () { end(this); },
write: write,
resume: function () { this.error = null; return this },
close: function () { return this.write(null) },
flush: function () { flushBuffers(this); }
};
var Stream;
try {
Stream = __webpack_require__(/*! stream */ "./node_modules/stream-browserify/index.js").Stream;
} catch (ex) {
Stream = function () {};
}
var streamWraps = sax.EVENTS.filter(function (ev) {
return ev !== 'error' && ev !== 'end'
});
function createStream (strict, opt) {
return new SAXStream(strict, opt)
}
function SAXStream (strict, opt) {
if (!(this instanceof SAXStream)) {
return new SAXStream(strict, opt)
}
Stream.apply(this);
this._parser = new SAXParser(strict, opt);
this.writable = true;
this.readable = true;
var me = this;
this._parser.onend = function () {
me.emit('end');
};
this._parser.onerror = function (er) {
me.emit('error', er);
// if didn't throw, then means error was handled.
// go ahead and clear error, so we can write again.
me._parser.error = null;
};
this._decoder = null;
streamWraps.forEach(function (ev) {
Object.defineProperty(me, 'on' + ev, {
get: function () {
return me._parser['on' + ev]
},
set: function (h) {
if (!h) {
me.removeAllListeners(ev);
me._parser['on' + ev] = h;
return h
}
me.on(ev, h);
},
enumerable: true,
configurable: false
});
});
}
SAXStream.prototype = Object.create(Stream.prototype, {
constructor: {
value: SAXStream
}
});
SAXStream.prototype.write = function (data) {
if (typeof Buffer === 'function' &&
typeof Buffer.isBuffer === 'function' &&
Buffer.isBuffer(data)) {
if (!this._decoder) {
var SD = __webpack_require__(/*! string_decoder */ "./node_modules/string_decoder/lib/string_decoder.js").StringDecoder;
this._decoder = new SD('utf8');
}
data = this._decoder.write(data);
}
this._parser.write(data.toString());
this.emit('data', data);
return true
};
SAXStream.prototype.end = function (chunk) {
if (chunk && chunk.length) {
this.write(chunk);
}
this._parser.end();
return true
};
SAXStream.prototype.on = function (ev, handler) {
var me = this;
if (!me._parser['on' + ev] && streamWraps.indexOf(ev) !== -1) {
me._parser['on' + ev] = function () {
var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments);
args.splice(0, 0, ev);
me.emit.apply(me, args);
};
}
return Stream.prototype.on.call(me, ev, handler)
};
// character classes and tokens
var whitespace = '\r\n\t ';
// this really needs to be replaced with character classes.
// XML allows all manner of ridiculous numbers and digits.
var number = '0124356789';
var letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// (Letter | "_" | ":")
var quote = '\'"';
var attribEnd = whitespace + '>';
var CDATA = '[CDATA[';
var DOCTYPE = 'DOCTYPE';
var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
var XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/';
var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE };
// turn all the string character sets into character class objects.
whitespace = charClass(whitespace);
number = charClass(number);
letter = charClass(letter);
// http://www.w3.org/TR/REC-xml/#NT-NameStartChar
// This implementation works on strings, a single character at a time
// as such, it cannot ever support astral-plane characters (10000-EFFFF)
// without a significant breaking change to either this parser, or the
// JavaScript language. Implementation of an emoji-capable xml parser
// is left as an exercise for the reader.
var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040\.\d-]/;
var entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/;
var entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040\.\d-]/;
quote = charClass(quote);
attribEnd = charClass(attribEnd);
function charClass (str) {
return str.split('').reduce(function (s, c) {
s[c] = true;
return s
}, {})
}
function isRegExp (c) {
return Object.prototype.toString.call(c) === '[object RegExp]'
}
function is (charclass, c) {
return isRegExp(charclass) ? !!c.match(charclass) : charclass[c]
}
function not (charclass, c) {
return !is(charclass, c)
}
var S = 0;
sax.STATE = {
BEGIN: S++, // leading byte order mark or whitespace
BEGIN_WHITESPACE: S++, // leading whitespace
TEXT: S++, // general stuff
TEXT_ENTITY: S++, // &amp and such.
OPEN_WAKA: S++, // <
SGML_DECL: S++, // <!BLARG
SGML_DECL_QUOTED: S++, // <!BLARG foo "bar
DOCTYPE: S++, // <!DOCTYPE
DOCTYPE_QUOTED: S++, // <!DOCTYPE "//blah
DOCTYPE_DTD: S++, // <!DOCTYPE "//blah" [ ...
DOCTYPE_DTD_QUOTED: S++, // <!DOCTYPE "//blah" [ "foo
COMMENT_STARTING: S++, // <!-
COMMENT: S++, // <!--
COMMENT_ENDING: S++, // <!-- blah -
COMMENT_ENDED: S++, // <!-- blah --
CDATA: S++, // <![CDATA[ something
CDATA_ENDING: S++, // ]
CDATA_ENDING_2: S++, // ]]
PROC_INST: S++, // <?hi
PROC_INST_BODY: S++, // <?hi there
PROC_INST_ENDING: S++, // <?hi "there" ?
OPEN_TAG: S++, // <strong
OPEN_TAG_SLASH: S++, // <strong /
ATTRIB: S++, // <a
ATTRIB_NAME: S++, // <a foo
ATTRIB_NAME_SAW_WHITE: S++, // <a foo _
ATTRIB_VALUE: S++, // <a foo=
ATTRIB_VALUE_QUOTED: S++, // <a foo="bar
ATTRIB_VALUE_CLOSED: S++, // <a foo="bar"
ATTRIB_VALUE_UNQUOTED: S++, // <a foo=bar
ATTRIB_VALUE_ENTITY_Q: S++, // <foo bar="&quot;"
ATTRIB_VALUE_ENTITY_U: S++, // <foo bar=&quot
CLOSE_TAG: S++, // </a
CLOSE_TAG_SAW_WHITE: S++, // </a >
SCRIPT: S++, // <script> ...
SCRIPT_ENDING: S++ // <script> ... <
};
sax.XML_ENTITIES = {
'amp': '&',
'gt': '>',
'lt': '<',
'quot': '"',
'apos': "'"
};
sax.ENTITIES = {
'amp': '&',
'gt': '>',
'lt': '<',
'quot': '"',
'apos': "'",
'AElig': 198,
'Aacute': 193,
'Acirc': 194,
'Agrave': 192,
'Aring': 197,
'Atilde': 195,
'Auml': 196,
'Ccedil': 199,
'ETH': 208,
'Eacute': 201,
'Ecirc': 202,
'Egrave': 200,
'Euml': 203,
'Iacute': 205,
'Icirc': 206,
'Igrave': 204,
'Iuml': 207,
'Ntilde': 209,
'Oacute': 211,
'Ocirc': 212,
'Ograve': 210,
'Oslash': 216,
'Otilde': 213,
'Ouml': 214,
'THORN': 222,
'Uacute': 218,
'Ucirc': 219,
'Ugrave': 217,
'Uuml': 220,
'Yacute': 221,
'aacute': 225,
'acirc': 226,
'aelig': 230,
'agrave': 224,
'aring': 229,
'atilde': 227,
'auml': 228,
'ccedil': 231,
'eacute': 233,
'ecirc': 234,
'egrave': 232,
'eth': 240,
'euml': 235,
'iacute': 237,
'icirc': 238,
'igrave': 236,
'iuml': 239,
'ntilde': 241,
'oacute': 243,
'ocirc': 244,
'ograve': 242,
'oslash': 248,
'otilde': 245,
'ouml': 246,
'szlig': 223,
'thorn': 254,
'uacute': 250,
'ucirc': 251,
'ugrave': 249,
'uuml': 252,
'yacute': 253,
'yuml': 255,
'copy': 169,
'reg': 174,
'nbsp': 160,
'iexcl': 161,
'cent': 162,
'pound': 163,
'curren': 164,
'yen': 165,
'brvbar': 166,
'sect': 167,
'uml': 168,
'ordf': 170,
'laquo': 171,
'not': 172,
'shy': 173,
'macr': 175,
'deg': 176,
'plusmn': 177,
'sup1': 185,
'sup2': 178,
'sup3': 179,
'acute': 180,
'micro': 181,
'para': 182,
'middot': 183,
'cedil': 184,
'ordm': 186,
'raquo': 187,
'frac14': 188,
'frac12': 189,
'frac34': 190,
'iquest': 191,
'times': 215,
'divide': 247,
'OElig': 338,
'oelig': 339,
'Scaron': 352,
'scaron': 353,
'Yuml': 376,
'fnof': 402,
'circ': 710,
'tilde': 732,
'Alpha': 913,
'Beta': 914,
'Gamma': 915,
'Delta': 916,
'Epsilon': 917,
'Zeta': 918,
'Eta': 919,
'Theta': 920,
'Iota': 921,
'Kappa': 922,
'Lambda': 923,
'Mu': 924,
'Nu': 925,
'Xi': 926,
'Omicron': 927,
'Pi': 928,
'Rho': 929,
'Sigma': 931,
'Tau': 932,
'Upsilon': 933,
'Phi': 934,
'Chi': 935,
'Psi': 936,
'Omega': 937,
'alpha': 945,
'beta': 946,
'gamma': 947,
'delta': 948,
'epsilon': 949,
'zeta': 950,
'eta': 951,
'theta': 952,
'iota': 953,
'kappa': 954,
'lambda': 955,
'mu': 956,
'nu': 957,
'xi': 958,
'omicron': 959,
'pi': 960,
'rho': 961,
'sigmaf': 962,
'sigma': 963,
'tau': 964,
'upsilon': 965,
'phi': 966,
'chi': 967,
'psi': 968,
'omega': 969,
'thetasym': 977,
'upsih': 978,
'piv': 982,
'ensp': 8194,
'emsp': 8195,
'thinsp': 8201,
'zwnj': 8204,
'zwj': 8205,
'lrm': 8206,
'rlm': 8207,
'ndash': 8211,
'mdash': 8212,
'lsquo': 8216,
'rsquo': 8217,
'sbquo': 8218,
'ldquo': 8220,
'rdquo': 8221,
'bdquo': 8222,
'dagger': 8224,
'Dagger': 8225,
'bull': 8226,
'hellip': 8230,
'permil': 8240,
'prime': 8242,
'Prime': 8243,
'lsaquo': 8249,
'rsaquo': 8250,
'oline': 8254,
'frasl': 8260,
'euro': 8364,
'image': 8465,
'weierp': 8472,
'real': 8476,
'trade': 8482,
'alefsym': 8501,
'larr': 8592,
'uarr': 8593,
'rarr': 8594,
'darr': 8595,
'harr': 8596,
'crarr': 8629,
'lArr': 8656,
'uArr': 8657,
'rArr': 8658,
'dArr': 8659,
'hArr': 8660,
'forall': 8704,
'part': 8706,
'exist': 8707,
'empty': 8709,
'nabla': 8711,
'isin': 8712,
'notin': 8713,
'ni': 8715,
'prod': 8719,
'sum': 8721,
'minus': 8722,
'lowast': 8727,
'radic': 8730,
'prop': 8733,
'infin': 8734,
'ang': 8736,
'and': 8743,
'or': 8744,
'cap': 8745,
'cup': 8746,
'int': 8747,
'there4': 8756,
'sim': 8764,
'cong': 8773,
'asymp': 8776,
'ne': 8800,
'equiv': 8801,
'le': 8804,
'ge': 8805,
'sub': 8834,
'sup': 8835,
'nsub': 8836,
'sube': 8838,
'supe': 8839,
'oplus': 8853,
'otimes': 8855,
'perp': 8869,
'sdot': 8901,
'lceil': 8968,
'rceil': 8969,
'lfloor': 8970,
'rfloor': 8971,
'lang': 9001,
'rang': 9002,
'loz': 9674,
'spades': 9824,
'clubs': 9827,
'hearts': 9829,
'diams': 9830
};
Object.keys(sax.ENTITIES).forEach(function (key) {
var e = sax.ENTITIES[key];
var s = typeof e === 'number' ? String.fromCharCode(e) : e;
sax.ENTITIES[key] = s;
});
for (var s in sax.STATE) {
sax.STATE[sax.STATE[s]] = s;
}
// shorthand
S = sax.STATE;
function emit (parser, event, data) {
parser[event] && parser[event](data);
}
function emitNode (parser, nodeType, data) {
if (parser.textNode) closeText(parser);
emit(parser, nodeType, data);
}
function closeText (parser) {
parser.textNode = textopts(parser.opt, parser.textNode);
if (parser.textNode) emit(parser, 'ontext', parser.textNode);
parser.textNode = '';
}
function textopts (opt, text) {
if (opt.trim) text = text.trim();
if (opt.normalize) text = text.replace(/\s+/g, ' ');
return text
}
function error (parser, er) {
closeText(parser);
if (parser.trackPosition) {
er += '\nLine: ' + parser.line +
'\nColumn: ' + parser.column +
'\nChar: ' + parser.c;
}
er = new Error(er);
parser.error = er;
emit(parser, 'onerror', er);
return parser
}
function end (parser) {
if (parser.sawRoot && !parser.closedRoot) strictFail(parser, 'Unclosed root tag');
if ((parser.state !== S.BEGIN) &&
(parser.state !== S.BEGIN_WHITESPACE) &&
(parser.state !== S.TEXT)) {
error(parser, 'Unexpected end');
}
closeText(parser);
parser.c = '';
parser.closed = true;
emit(parser, 'onend');
SAXParser.call(parser, parser.strict, parser.opt);
return parser
}
function strictFail (parser, message) {
if (typeof parser !== 'object' || !(parser instanceof SAXParser)) {
throw new Error('bad call to strictFail')
}
if (parser.strict) {
error(parser, message);
}
}
function newTag (parser) {
if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]();
var parent = parser.tags[parser.tags.length - 1] || parser;
var tag = parser.tag = { name: parser.tagName, attributes: {} };
// will be overridden if tag contails an xmlns="foo" or xmlns:foo="bar"
if (parser.opt.xmlns) {
tag.ns = parent.ns;
}
parser.attribList.length = 0;
emitNode(parser, 'onopentagstart', tag);
}
function qname (name, attribute) {
var i = name.indexOf(':');
var qualName = i < 0 ? [ '', name ] : name.split(':');
var prefix = qualName[0];
var local = qualName[1];
// <x "xmlns"="http://foo">
if (attribute && name === 'xmlns') {
prefix = 'xmlns';
local = '';
}
return { prefix: prefix, local: local }
}
function attrib (parser) {
if (!parser.strict) {
parser.attribName = parser.attribName[parser.looseCase]();
}
if (parser.attribList.indexOf(parser.attribName) !== -1 ||
parser.tag.attributes.hasOwnProperty(parser.attribName)) {
parser.attribName = parser.attribValue = '';
return
}
if (parser.opt.xmlns) {
var qn = qname(parser.attribName, true);
var prefix = qn.prefix;
var local = qn.local;
if (prefix === 'xmlns') {
// namespace binding attribute. push the binding into scope
if (local === 'xml' && parser.attribValue !== XML_NAMESPACE) {
strictFail(parser,
'xml: prefix must be bound to ' + XML_NAMESPACE + '\n' +
'Actual: ' + parser.attribValue);
} else if (local === 'xmlns' && parser.attribValue !== XMLNS_NAMESPACE) {
strictFail(parser,
'xmlns: prefix must be bound to ' + XMLNS_NAMESPACE + '\n' +
'Actual: ' + parser.attribValue);
} else {
var tag = parser.tag;
var parent = parser.tags[parser.tags.length - 1] || parser;
if (tag.ns === parent.ns) {
tag.ns = Object.create(parent.ns);
}
tag.ns[local] = parser.attribValue;
}
}
// defer onattribute events until all attributes have been seen
// so any new bindings can take effect. preserve attribute order
// so deferred events can be emitted in document order
parser.attribList.push([parser.attribName, parser.attribValue]);
} else {
// in non-xmlns mode, we can emit the event right away
parser.tag.attributes[parser.attribName] = parser.attribValue;
emitNode(parser, 'onattribute', {
name: parser.attribName,
value: parser.attribValue
});
}
parser.attribName = parser.attribValue = '';
}
function openTag (parser, selfClosing) {
if (parser.opt.xmlns) {
// emit namespace binding events
var tag = parser.tag;
// add namespace info to tag
var qn = qname(parser.tagName);
tag.prefix = qn.prefix;
tag.local = qn.local;
tag.uri = tag.ns[qn.prefix] || '';
if (tag.prefix && !tag.uri) {
strictFail(parser, 'Unbound namespace prefix: ' +
JSON.stringify(parser.tagName));
tag.uri = qn.prefix;
}
var parent = parser.tags[parser.tags.length - 1] || parser;
if (tag.ns && parent.ns !== tag.ns) {
Object.keys(tag.ns).forEach(function (p) {
emitNode(parser, 'onopennamespace', {
prefix: p,
uri: tag.ns[p]
});
});
}
// handle deferred onattribute events
// Note: do not apply default ns to attributes:
// http://www.w3.org/TR/REC-xml-names/#defaulting
for (var i = 0, l = parser.attribList.length; i < l; i++) {
var nv = parser.attribList[i];
var name = nv[0];
var value = nv[1];
var qualName = qname(name, true);
var prefix = qualName.prefix;
var local = qualName.local;
var uri = prefix === '' ? '' : (tag.ns[prefix] || '');
var a = {
name: name,
value: value,
prefix: prefix,
local: local,
uri: uri
};
// if there's any attributes with an undefined namespace,
// then fail on them now.
if (prefix && prefix !== 'xmlns' && !uri) {
strictFail(parser, 'Unbound namespace prefix: ' +
JSON.stringify(prefix));
a.uri = prefix;
}
parser.tag.attributes[name] = a;
emitNode(parser, 'onattribute', a);
}
parser.attribList.length = 0;
}
parser.tag.isSelfClosing = !!selfClosing;
// process the tag
parser.sawRoot = true;
parser.tags.push(parser.tag);
emitNode(parser, 'onopentag', parser.tag);
if (!selfClosing) {
// special case for <script> in non-strict mode.
if (!parser.noscript && parser.tagName.toLowerCase() === 'script') {
parser.state = S.SCRIPT;
} else {
parser.state = S.TEXT;
}
parser.tag = null;
parser.tagName = '';
}
parser.attribName = parser.attribValue = '';
parser.attribList.length = 0;
}
function closeTag (parser) {
if (!parser.tagName) {
strictFail(parser, 'Weird empty close tag.');
parser.textNode += '</>';
parser.state = S.TEXT;
return
}
if (parser.script) {
if (parser.tagName !== 'script') {
parser.script += '</' + parser.tagName + '>';
parser.tagName = '';
parser.state = S.SCRIPT;
return
}
emitNode(parser, 'onscript', parser.script);
parser.script = '';
}
// first make sure that the closing tag actually exists.
// <a><b></c></b></a> will close everything, otherwise.
var t = parser.tags.length;
var tagName = parser.tagName;
if (!parser.strict) {
tagName = tagName[parser.looseCase]();
}
var closeTo = tagName;
while (t--) {
var close = parser.tags[t];
if (close.name !== closeTo) {
// fail the first time in strict mode
strictFail(parser, 'Unexpected close tag');
} else {
break
}
}
// didn't find it. we already failed for strict, so just abort.
if (t < 0) {
strictFail(parser, 'Unmatched closing tag: ' + parser.tagName);
parser.textNode += '</' + parser.tagName + '>';
parser.state = S.TEXT;
return
}
parser.tagName = tagName;
var s = parser.tags.length;
while (s-- > t) {
var tag = parser.tag = parser.tags.pop();
parser.tagName = parser.tag.name;
emitNode(parser, 'onclosetag', parser.tagName);
var x = {};
for (var i in tag.ns) {
x[i] = tag.ns[i];
}
var parent = parser.tags[parser.tags.length - 1] || parser;
if (parser.opt.xmlns && tag.ns !== parent.ns) {
// remove namespace bindings introduced by tag
Object.keys(tag.ns).forEach(function (p) {
var n = tag.ns[p];
emitNode(parser, 'onclosenamespace', { prefix: p, uri: n });
});
}
}
if (t === 0) parser.closedRoot = true;
parser.tagName = parser.attribValue = parser.attribName = '';
parser.attribList.length = 0;
parser.state = S.TEXT;
}
function parseEntity (parser) {
var entity = parser.entity;
var entityLC = entity.toLowerCase();
var num;
var numStr = '';
if (parser.ENTITIES[entity]) {
return parser.ENTITIES[entity]
}
if (parser.ENTITIES[entityLC]) {
return parser.ENTITIES[entityLC]
}
entity = entityLC;
if (entity.charAt(0) === '#') {
if (entity.charAt(1) === 'x') {
entity = entity.slice(2);
num = parseInt(entity, 16);
numStr = num.toString(16);
} else {
entity = entity.slice(1);
num = parseInt(entity, 10);
numStr = num.toString(10);
}
}
entity = entity.replace(/^0+/, '');
if (numStr.toLowerCase() !== entity) {
strictFail(parser, 'Invalid character entity');
return '&' + parser.entity + ';'
}
return String.fromCodePoint(num)
}
function beginWhiteSpace (parser, c) {
if (c === '<') {
parser.state = S.OPEN_WAKA;
parser.startTagPosition = parser.position;
} else if (not(whitespace, c)) {
// have to process this as a text node.
// weird, but happens.
strictFail(parser, 'Non-whitespace before first tag.');
parser.textNode = c;
parser.state = S.TEXT;
}
}
function charAt (chunk, i) {
var result = '';
if (i < chunk.length) {
result = chunk.charAt(i);
}
return result
}
function write (chunk) {
var parser = this;
if (this.error) {
throw this.error
}
if (parser.closed) {
return error(parser,
'Cannot write after close. Assign an onready handler.')
}
if (chunk === null) {
return end(parser)
}
if (typeof chunk === 'object') {
chunk = chunk.toString();
}
var i = 0;
var c = '';
while (true) {
c = charAt(chunk, i++);
parser.c = c;
if (!c) {
break
}
if (parser.trackPosition) {
parser.position++;
if (c === '\n') {
parser.line++;
parser.column = 0;
} else {
parser.column++;
}
}
switch (parser.state) {
case S.BEGIN:
parser.state = S.BEGIN_WHITESPACE;
if (c === '\uFEFF') {
continue
}
beginWhiteSpace(parser, c);
continue
case S.BEGIN_WHITESPACE:
beginWhiteSpace(parser, c);
continue
case S.TEXT:
if (parser.sawRoot && !parser.closedRoot) {
var starti = i - 1;
while (c && c !== '<' && c !== '&') {
c = charAt(chunk, i++);
if (c && parser.trackPosition) {
parser.position++;
if (c === '\n') {
parser.line++;
parser.column = 0;
} else {
parser.column++;
}
}
}
parser.textNode += chunk.substring(starti, i - 1);
}
if (c === '<' && !(parser.sawRoot && parser.closedRoot && !parser.strict)) {
parser.state = S.OPEN_WAKA;
parser.startTagPosition = parser.position;
} else {
if (not(whitespace, c) && (!parser.sawRoot || parser.closedRoot)) {
strictFail(parser, 'Text data outside of root node.');
}
if (c === '&') {
parser.state = S.TEXT_ENTITY;
} else {
parser.textNode += c;
}
}
continue
case S.SCRIPT:
// only non-strict
if (c === '<') {
parser.state = S.SCRIPT_ENDING;
} else {
parser.script += c;
}
continue
case S.SCRIPT_ENDING:
if (c === '/') {
parser.state = S.CLOSE_TAG;
} else {
parser.script += '<' + c;
parser.state = S.SCRIPT;
}
continue
case S.OPEN_WAKA:
// either a /, ?, !, or text is coming next.
if (c === '!') {
parser.state = S.SGML_DECL;
parser.sgmlDecl = '';
} else if (is(whitespace, c)) ; else if (is(nameStart, c)) {
parser.state = S.OPEN_TAG;
parser.tagName = c;
} else if (c === '/') {
parser.state = S.CLOSE_TAG;
parser.tagName = '';
} else if (c === '?') {
parser.state = S.PROC_INST;
parser.procInstName = parser.procInstBody = '';
} else {
strictFail(parser, 'Unencoded <');
// if there was some whitespace, then add that in.
if (parser.startTagPosition + 1 < parser.position) {
var pad = parser.position - parser.startTagPosition;
c = new Array(pad).join(' ') + c;
}
parser.textNode += '<' + c;
parser.state = S.TEXT;
}
continue
case S.SGML_DECL:
if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
emitNode(parser, 'onopencdata');
parser.state = S.CDATA;
parser.sgmlDecl = '';
parser.cdata = '';
} else if (parser.sgmlDecl + c === '--') {
parser.state = S.COMMENT;
parser.comment = '';
parser.sgmlDecl = '';
} else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
parser.state = S.DOCTYPE;
if (parser.doctype || parser.sawRoot) {
strictFail(parser,
'Inappropriately located doctype declaration');
}
parser.doctype = '';
parser.sgmlDecl = '';
} else if (c === '>') {
emitNode(parser, 'onsgmldeclaration', parser.sgmlDecl);
parser.sgmlDecl = '';
parser.state = S.TEXT;
} else if (is(quote, c)) {
parser.state = S.SGML_DECL_QUOTED;
parser.sgmlDecl += c;
} else {
parser.sgmlDecl += c;
}
continue
case S.SGML_DECL_QUOTED:
if (c === parser.q) {
parser.state = S.SGML_DECL;
parser.q = '';
}
parser.sgmlDecl += c;
continue
case S.DOCTYPE:
if (c === '>') {
parser.state = S.TEXT;
emitNode(parser, 'ondoctype', parser.doctype);
parser.doctype = true; // just remember that we saw it.
} else {
parser.doctype += c;
if (c === '[') {
parser.state = S.DOCTYPE_DTD;
} else if (is(quote, c)) {
parser.state = S.DOCTYPE_QUOTED;
parser.q = c;
}
}
continue
case S.DOCTYPE_QUOTED:
parser.doctype += c;
if (c === parser.q) {
parser.q = '';
parser.state = S.DOCTYPE;
}
continue
case S.DOCTYPE_DTD:
parser.doctype += c;
if (c === ']') {
parser.state = S.DOCTYPE;
} else if (is(quote, c)) {
parser.state = S.DOCTYPE_DTD_QUOTED;
parser.q = c;
}
continue
case S.DOCTYPE_DTD_QUOTED:
parser.doctype += c;
if (c === parser.q) {
parser.state = S.DOCTYPE_DTD;
parser.q = '';
}
continue
case S.COMMENT:
if (c === '-') {
parser.state = S.COMMENT_ENDING;
} else {
parser.comment += c;
}
continue
case S.COMMENT_ENDING:
if (c === '-') {
parser.state = S.COMMENT_ENDED;
parser.comment = textopts(parser.opt, parser.comment);
if (parser.comment) {
emitNode(parser, 'oncomment', parser.comment);
}
parser.comment = '';
} else {
parser.comment += '-' + c;
parser.state = S.COMMENT;
}
continue
case S.COMMENT_ENDED:
if (c !== '>') {
strictFail(parser, 'Malformed comment');
// allow <!-- blah -- bloo --> in non-strict mode,
// which is a comment of " blah -- bloo "
parser.comment += '--' + c;
parser.state = S.COMMENT;
} else {
parser.state = S.TEXT;
}
continue
case S.CDATA:
if (c === ']') {
parser.state = S.CDATA_ENDING;
} else {
parser.cdata += c;
}
continue
case S.CDATA_ENDING:
if (c === ']') {
parser.state = S.CDATA_ENDING_2;
} else {
parser.cdata += ']' + c;
parser.state = S.CDATA;
}
continue
case S.CDATA_ENDING_2:
if (c === '>') {
if (parser.cdata) {
emitNode(parser, 'oncdata', parser.cdata);
}
emitNode(parser, 'onclosecdata');
parser.cdata = '';
parser.state = S.TEXT;
} else if (c === ']') {
parser.cdata += ']';
} else {
parser.cdata += ']]' + c;
parser.state = S.CDATA;
}
continue
case S.PROC_INST:
if (c === '?') {
parser.state = S.PROC_INST_ENDING;
} else if (is(whitespace, c)) {
parser.state = S.PROC_INST_BODY;
} else {
parser.procInstName += c;
}
continue
case S.PROC_INST_BODY:
if (!parser.procInstBody && is(whitespace, c)) {
continue
} else if (c === '?') {
parser.state = S.PROC_INST_ENDING;
} else {
parser.procInstBody += c;
}
continue
case S.PROC_INST_ENDING:
if (c === '>') {
emitNode(parser, 'onprocessinginstruction', {
name: parser.procInstName,
body: parser.procInstBody
});
parser.procInstName = parser.procInstBody = '';
parser.state = S.TEXT;
} else {
parser.procInstBody += '?' + c;
parser.state = S.PROC_INST_BODY;
}
continue
case S.OPEN_TAG:
if (is(nameBody, c)) {
parser.tagName += c;
} else {
newTag(parser);
if (c === '>') {
openTag(parser);
} else if (c === '/') {
parser.state = S.OPEN_TAG_SLASH;
} else {
if (not(whitespace, c)) {
strictFail(parser, 'Invalid character in tag name');
}
parser.state = S.ATTRIB;
}
}
continue
case S.OPEN_TAG_SLASH:
if (c === '>') {
openTag(parser, true);
closeTag(parser);
} else {
strictFail(parser, 'Forward-slash in opening tag not followed by >');
parser.state = S.ATTRIB;
}
continue
case S.ATTRIB:
// haven't read the attribute name yet.
if (is(whitespace, c)) {
continue
} else if (c === '>') {
openTag(parser);
} else if (c === '/') {
parser.state = S.OPEN_TAG_SLASH;
} else if (is(nameStart, c)) {
parser.attribName = c;
parser.attribValue = '';
parser.state = S.ATTRIB_NAME;
} else {
strictFail(parser, 'Invalid attribute name');
}
continue
case S.ATTRIB_NAME:
if (c === '=') {
parser.state = S.ATTRIB_VALUE;
} else if (c === '>') {
strictFail(parser, 'Attribute without value');
parser.attribValue = parser.attribName;
attrib(parser);
openTag(parser);
} else if (is(whitespace, c)) {
parser.state = S.ATTRIB_NAME_SAW_WHITE;
} else if (is(nameBody, c)) {
parser.attribName += c;
} else {
strictFail(parser, 'Invalid attribute name');
}
continue
case S.ATTRIB_NAME_SAW_WHITE:
if (c === '=') {
parser.state = S.ATTRIB_VALUE;
} else if (is(whitespace, c)) {
continue
} else {
strictFail(parser, 'Attribute without value');
parser.tag.attributes[parser.attribName] = '';
parser.attribValue = '';
emitNode(parser, 'onattribute', {
name: parser.attribName,
value: ''
});
parser.attribName = '';
if (c === '>') {
openTag(parser);
} else if (is(nameStart, c)) {
parser.attribName = c;
parser.state = S.ATTRIB_NAME;
} else {
strictFail(parser, 'Invalid attribute name');
parser.state = S.ATTRIB;
}
}
continue
case S.ATTRIB_VALUE:
if (is(whitespace, c)) {
continue
} else if (is(quote, c)) {
parser.q = c;
parser.state = S.ATTRIB_VALUE_QUOTED;
} else {
strictFail(parser, 'Unquoted attribute value');
parser.state = S.ATTRIB_VALUE_UNQUOTED;
parser.attribValue = c;
}
continue
case S.ATTRIB_VALUE_QUOTED:
if (c !== parser.q) {
if (c === '&') {
parser.state = S.ATTRIB_VALUE_ENTITY_Q;
} else {
parser.attribValue += c;
}
continue
}
attrib(parser);
parser.q = '';
parser.state = S.ATTRIB_VALUE_CLOSED;
continue
case S.ATTRIB_VALUE_CLOSED:
if (is(whitespace, c)) {
parser.state = S.ATTRIB;
} else if (c === '>') {
openTag(parser);
} else if (c === '/') {
parser.state = S.OPEN_TAG_SLASH;
} else if (is(nameStart, c)) {
strictFail(parser, 'No whitespace between attributes');
parser.attribName = c;
parser.attribValue = '';
parser.state = S.ATTRIB_NAME;
} else {
strictFail(parser, 'Invalid attribute name');
}
continue
case S.ATTRIB_VALUE_UNQUOTED:
if (not(attribEnd, c)) {
if (c === '&') {
parser.state = S.ATTRIB_VALUE_ENTITY_U;
} else {
parser.attribValue += c;
}
continue
}
attrib(parser);
if (c === '>') {
openTag(parser);
} else {
parser.state = S.ATTRIB;
}
continue
case S.CLOSE_TAG:
if (!parser.tagName) {
if (is(whitespace, c)) {
continue
} else if (not(nameStart, c)) {
if (parser.script) {
parser.script += '</' + c;
parser.state = S.SCRIPT;
} else {
strictFail(parser, 'Invalid tagname in closing tag.');
}
} else {
parser.tagName = c;
}
} else if (c === '>') {
closeTag(parser);
} else if (is(nameBody, c)) {
parser.tagName += c;
} else if (parser.script) {
parser.script += '</' + parser.tagName;
parser.tagName = '';
parser.state = S.SCRIPT;
} else {
if (not(whitespace, c)) {
strictFail(parser, 'Invalid tagname in closing tag');
}
parser.state = S.CLOSE_TAG_SAW_WHITE;
}
continue
case S.CLOSE_TAG_SAW_WHITE:
if (is(whitespace, c)) {
continue
}
if (c === '>') {
closeTag(parser);
} else {
strictFail(parser, 'Invalid characters in closing tag');
}
continue
case S.TEXT_ENTITY:
case S.ATTRIB_VALUE_ENTITY_Q:
case S.ATTRIB_VALUE_ENTITY_U:
var returnState;
var buffer;
switch (parser.state) {
case S.TEXT_ENTITY:
returnState = S.TEXT;
buffer = 'textNode';
break
case S.ATTRIB_VALUE_ENTITY_Q:
returnState = S.ATTRIB_VALUE_QUOTED;
buffer = 'attribValue';
break
case S.ATTRIB_VALUE_ENTITY_U:
returnState = S.ATTRIB_VALUE_UNQUOTED;
buffer = 'attribValue';
break
}
if (c === ';') {
parser[buffer] += parseEntity(parser);
parser.entity = '';
parser.state = returnState;
} else if (is(parser.entity.length ? entityBody : entityStart, c)) {
parser.entity += c;
} else {
strictFail(parser, 'Invalid character in entity name');
parser[buffer] += '&' + parser.entity + c;
parser.entity = '';
parser.state = returnState;
}
continue
default:
throw new Error(parser, 'Unknown state: ' + parser.state)
}
} // while
if (parser.position >= parser.bufferCheckPosition) {
checkBufferLength(parser);
}
return parser
}
/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */
if (!String.fromCodePoint) {
(function () {
var stringFromCharCode = String.fromCharCode;
var floor = Math.floor;
var fromCodePoint = function () {
var MAX_SIZE = 0x4000;
var codeUnits = [];
var highSurrogate;
var lowSurrogate;
var index = -1;
var length = arguments.length;
if (!length) {
return ''
}
var result = '';
while (++index < length) {
var codePoint = Number(arguments[index]);
if (
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10FFFF || // not a valid Unicode code point
floor(codePoint) !== codePoint // not an integer
) {
throw RangeError('Invalid code point: ' + codePoint)
}
if (codePoint <= 0xFFFF) { // BMP code point
codeUnits.push(codePoint);
} else { // Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xD800;
lowSurrogate = (codePoint % 0x400) + 0xDC00;
codeUnits.push(highSurrogate, lowSurrogate);
}
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += stringFromCharCode.apply(null, codeUnits);
codeUnits.length = 0;
}
}
return result
};
if (Object.defineProperty) {
Object.defineProperty(String, 'fromCodePoint', {
value: fromCodePoint,
configurable: true,
writable: true
});
} else {
String.fromCodePoint = fromCodePoint;
}
}());
}
})( exports);
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node-libs-browser/node_modules/buffer/index.js */ "./node_modules/node-libs-browser/node_modules/buffer/index.js").Buffer));
/***/ }),
/***/ "./node_modules/setimmediate/setImmediate.js":
/*!***************************************************!*\
!*** ./node_modules/setimmediate/setImmediate.js ***!
\***************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
if (global.setImmediate) {
return;
}
var nextHandle = 1; // Spec says greater than zero
var tasksByHandle = {};
var currentlyRunningATask = false;
var doc = global.document;
var registerImmediate;
function setImmediate(callback) {
// Callback can either be a function or a string
if (typeof callback !== "function") {
callback = new Function("" + callback);
}
// Copy function arguments
var args = new Array(arguments.length - 1);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i + 1];
}
// Store and register the task
var task = { callback: callback, args: args };
tasksByHandle[nextHandle] = task;
registerImmediate(nextHandle);
return nextHandle++;
}
function clearImmediate(handle) {
delete tasksByHandle[handle];
}
function run(task) {
var callback = task.callback;
var args = task.args;
switch (args.length) {
case 0:
callback();
break;
case 1:
callback(args[0]);
break;
case 2:
callback(args[0], args[1]);
break;
case 3:
callback(args[0], args[1], args[2]);
break;
default:
callback.apply(undefined, args);
break;
}
}
function runIfPresent(handle) {
// From the spec: "Wait until any invocations of this algorithm started before this one have completed."
// So if we're currently running a task, we'll need to delay this invocation.
if (currentlyRunningATask) {
// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
// "too much recursion" error.
setTimeout(runIfPresent, 0, handle);
} else {
var task = tasksByHandle[handle];
if (task) {
currentlyRunningATask = true;
try {
run(task);
} finally {
clearImmediate(handle);
currentlyRunningATask = false;
}
}
}
}
function installNextTickImplementation() {
registerImmediate = function(handle) {
process.nextTick(function () { runIfPresent(handle); });
};
}
function canUsePostMessage() {
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
// where `global.postMessage` means something completely different and can't be used for this purpose.
if (global.postMessage && !global.importScripts) {
var postMessageIsAsynchronous = true;
var oldOnMessage = global.onmessage;
global.onmessage = function() {
postMessageIsAsynchronous = false;
};
global.postMessage("", "*");
global.onmessage = oldOnMessage;
return postMessageIsAsynchronous;
}
}
function installPostMessageImplementation() {
// Installs an event handler on `global` for the `message` event: see
// * https://developer.mozilla.org/en/DOM/window.postMessage
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
var messagePrefix = "setImmediate$" + Math.random() + "$";
var onGlobalMessage = function(event) {
if (event.source === global &&
typeof event.data === "string" &&
event.data.indexOf(messagePrefix) === 0) {
runIfPresent(+event.data.slice(messagePrefix.length));
}
};
if (global.addEventListener) {
global.addEventListener("message", onGlobalMessage, false);
} else {
global.attachEvent("onmessage", onGlobalMessage);
}
registerImmediate = function(handle) {
global.postMessage(messagePrefix + handle, "*");
};
}
function installMessageChannelImplementation() {
var channel = new MessageChannel();
channel.port1.onmessage = function(event) {
var handle = event.data;
runIfPresent(handle);
};
registerImmediate = function(handle) {
channel.port2.postMessage(handle);
};
}
function installReadyStateChangeImplementation() {
var html = doc.documentElement;
registerImmediate = function(handle) {
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var script = doc.createElement("script");
script.onreadystatechange = function () {
runIfPresent(handle);
script.onreadystatechange = null;
html.removeChild(script);
script = null;
};
html.appendChild(script);
};
}
function installSetTimeoutImplementation() {
registerImmediate = function(handle) {
setTimeout(runIfPresent, 0, handle);
};
}
// If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
// Don't get fooled by e.g. browserify environments.
if ({}.toString.call(global.process) === "[object process]") {
// For Node.js before 0.9
installNextTickImplementation();
} else if (canUsePostMessage()) {
// For non-IE10 modern browsers
installPostMessageImplementation();
} else if (global.MessageChannel) {
// For web workers, where supported
installMessageChannelImplementation();
} else if (doc && "onreadystatechange" in doc.createElement("script")) {
// For IE 68
installReadyStateChangeImplementation();
} else {
// For older browsers
installSetTimeoutImplementation();
}
attachTo.setImmediate = setImmediate;
attachTo.clearImmediate = clearImmediate;
}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../process/browser.js */ "./node_modules/process/browser.js")));
/***/ }),
/***/ "./node_modules/stream-browserify/index.js":
/*!*************************************************!*\
!*** ./node_modules/stream-browserify/index.js ***!
\*************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
module.exports = Stream;
var EE = __webpack_require__(/*! events */ "./node_modules/node-libs-browser/node_modules/events/events.js").EventEmitter;
var inherits = __webpack_require__(/*! inherits */ "./node_modules/inherits/inherits_browser.js");
inherits(Stream, EE);
Stream.Readable = __webpack_require__(/*! readable-stream/readable.js */ "./node_modules/readable-stream/readable-browser.js");
Stream.Writable = __webpack_require__(/*! readable-stream/writable.js */ "./node_modules/readable-stream/writable-browser.js");
Stream.Duplex = __webpack_require__(/*! readable-stream/duplex.js */ "./node_modules/readable-stream/duplex-browser.js");
Stream.Transform = __webpack_require__(/*! readable-stream/transform.js */ "./node_modules/readable-stream/transform.js");
Stream.PassThrough = __webpack_require__(/*! readable-stream/passthrough.js */ "./node_modules/readable-stream/passthrough.js");
// Backwards-compat with node 0.4.x
Stream.Stream = Stream;
// old-style streams. Note that the pipe method (the only relevant
// part of this class) is overridden in the Readable class.
function Stream() {
EE.call(this);
}
Stream.prototype.pipe = function(dest, options) {
var source = this;
function ondata(chunk) {
if (dest.writable) {
if (false === dest.write(chunk) && source.pause) {
source.pause();
}
}
}
source.on('data', ondata);
function ondrain() {
if (source.readable && source.resume) {
source.resume();
}
}
dest.on('drain', ondrain);
// If the 'end' option is not supplied, dest.end() will be called when
// source gets the 'end' or 'close' events. Only dest.end() once.
if (!dest._isStdio && (!options || options.end !== false)) {
source.on('end', onend);
source.on('close', onclose);
}
var didOnEnd = false;
function onend() {
if (didOnEnd) return;
didOnEnd = true;
dest.end();
}
function onclose() {
if (didOnEnd) return;
didOnEnd = true;
if (typeof dest.destroy === 'function') dest.destroy();
}
// don't leave dangling pipes when there are errors.
function onerror(er) {
cleanup();
if (EE.listenerCount(this, 'error') === 0) {
throw er; // Unhandled stream error in pipe.
}
}
source.on('error', onerror);
dest.on('error', onerror);
// remove all the event listeners that were added.
function cleanup() {
source.removeListener('data', ondata);
dest.removeListener('drain', ondrain);
source.removeListener('end', onend);
source.removeListener('close', onclose);
source.removeListener('error', onerror);
dest.removeListener('error', onerror);
source.removeListener('end', cleanup);
source.removeListener('close', cleanup);
dest.removeListener('close', cleanup);
}
source.on('end', cleanup);
source.on('close', cleanup);
dest.on('close', cleanup);
dest.emit('pipe', source);
// Allow for unix-like usage: A.pipe(B).pipe(C)
return dest;
};
/***/ }),
/***/ "./node_modules/string_decoder/lib/string_decoder.js":
/*!***********************************************************!*\
!*** ./node_modules/string_decoder/lib/string_decoder.js ***!
\***********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
/*<replacement>*/
var Buffer = __webpack_require__(/*! safe-buffer */ "./node_modules/safe-buffer/index.js").Buffer;
/*</replacement>*/
var isEncoding = Buffer.isEncoding || function (encoding) {
encoding = '' + encoding;
switch (encoding && encoding.toLowerCase()) {
case 'hex':case 'utf8':case 'utf-8':case 'ascii':case 'binary':case 'base64':case 'ucs2':case 'ucs-2':case 'utf16le':case 'utf-16le':case 'raw':
return true;
default:
return false;
}
};
function _normalizeEncoding(enc) {
if (!enc) return 'utf8';
var retried;
while (true) {
switch (enc) {
case 'utf8':
case 'utf-8':
return 'utf8';
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return 'utf16le';
case 'latin1':
case 'binary':
return 'latin1';
case 'base64':
case 'ascii':
case 'hex':
return enc;
default:
if (retried) return; // undefined
enc = ('' + enc).toLowerCase();
retried = true;
}
}
}
// Do not cache `Buffer.isEncoding` when checking encoding names as some
// modules monkey-patch it to support additional encodings
function normalizeEncoding(enc) {
var nenc = _normalizeEncoding(enc);
if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
return nenc || enc;
}
// StringDecoder provides an interface for efficiently splitting a series of
// buffers into a series of JS strings without breaking apart multi-byte
// characters.
exports.StringDecoder = StringDecoder;
function StringDecoder(encoding) {
this.encoding = normalizeEncoding(encoding);
var nb;
switch (this.encoding) {
case 'utf16le':
this.text = utf16Text;
this.end = utf16End;
nb = 4;
break;
case 'utf8':
this.fillLast = utf8FillLast;
nb = 4;
break;
case 'base64':
this.text = base64Text;
this.end = base64End;
nb = 3;
break;
default:
this.write = simpleWrite;
this.end = simpleEnd;
return;
}
this.lastNeed = 0;
this.lastTotal = 0;
this.lastChar = Buffer.allocUnsafe(nb);
}
StringDecoder.prototype.write = function (buf) {
if (buf.length === 0) return '';
var r;
var i;
if (this.lastNeed) {
r = this.fillLast(buf);
if (r === undefined) return '';
i = this.lastNeed;
this.lastNeed = 0;
} else {
i = 0;
}
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
return r || '';
};
StringDecoder.prototype.end = utf8End;
// Returns only complete characters in a Buffer
StringDecoder.prototype.text = utf8Text;
// Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
StringDecoder.prototype.fillLast = function (buf) {
if (this.lastNeed <= buf.length) {
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
}
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
this.lastNeed -= buf.length;
};
// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
// continuation byte. If an invalid byte is detected, -2 is returned.
function utf8CheckByte(byte) {
if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
return byte >> 6 === 0x02 ? -1 : -2;
}
// Checks at most 3 bytes at the end of a Buffer in order to detect an
// incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
// needed to complete the UTF-8 character (if applicable) are returned.
function utf8CheckIncomplete(self, buf, i) {
var j = buf.length - 1;
if (j < i) return 0;
var nb = utf8CheckByte(buf[j]);
if (nb >= 0) {
if (nb > 0) self.lastNeed = nb - 1;
return nb;
}
if (--j < i || nb === -2) return 0;
nb = utf8CheckByte(buf[j]);
if (nb >= 0) {
if (nb > 0) self.lastNeed = nb - 2;
return nb;
}
if (--j < i || nb === -2) return 0;
nb = utf8CheckByte(buf[j]);
if (nb >= 0) {
if (nb > 0) {
if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
}
return nb;
}
return 0;
}
// Validates as many continuation bytes for a multi-byte UTF-8 character as
// needed or are available. If we see a non-continuation byte where we expect
// one, we "replace" the validated continuation bytes we've seen so far with
// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
// behavior. The continuation byte check is included three times in the case
// where all of the continuation bytes for a character exist in the same buffer.
// It is also done this way as a slight performance increase instead of using a
// loop.
function utf8CheckExtraBytes(self, buf, p) {
if ((buf[0] & 0xC0) !== 0x80) {
self.lastNeed = 0;
return '\ufffd';
}
if (self.lastNeed > 1 && buf.length > 1) {
if ((buf[1] & 0xC0) !== 0x80) {
self.lastNeed = 1;
return '\ufffd';
}
if (self.lastNeed > 2 && buf.length > 2) {
if ((buf[2] & 0xC0) !== 0x80) {
self.lastNeed = 2;
return '\ufffd';
}
}
}
}
// Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
function utf8FillLast(buf) {
var p = this.lastTotal - this.lastNeed;
var r = utf8CheckExtraBytes(this, buf, p);
if (r !== undefined) return r;
if (this.lastNeed <= buf.length) {
buf.copy(this.lastChar, p, 0, this.lastNeed);
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
}
buf.copy(this.lastChar, p, 0, buf.length);
this.lastNeed -= buf.length;
}
// Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
// partial character, the character's bytes are buffered until the required
// number of bytes are available.
function utf8Text(buf, i) {
var total = utf8CheckIncomplete(this, buf, i);
if (!this.lastNeed) return buf.toString('utf8', i);
this.lastTotal = total;
var end = buf.length - (total - this.lastNeed);
buf.copy(this.lastChar, 0, end);
return buf.toString('utf8', i, end);
}
// For UTF-8, a replacement character is added when ending on a partial
// character.
function utf8End(buf) {
var r = buf && buf.length ? this.write(buf) : '';
if (this.lastNeed) return r + '\ufffd';
return r;
}
// UTF-16LE typically needs two bytes per character, but even if we have an even
// number of bytes available, we need to check if we end on a leading/high
// surrogate. In that case, we need to wait for the next two bytes in order to
// decode the last character properly.
function utf16Text(buf, i) {
if ((buf.length - i) % 2 === 0) {
var r = buf.toString('utf16le', i);
if (r) {
var c = r.charCodeAt(r.length - 1);
if (c >= 0xD800 && c <= 0xDBFF) {
this.lastNeed = 2;
this.lastTotal = 4;
this.lastChar[0] = buf[buf.length - 2];
this.lastChar[1] = buf[buf.length - 1];
return r.slice(0, -1);
}
}
return r;
}
this.lastNeed = 1;
this.lastTotal = 2;
this.lastChar[0] = buf[buf.length - 1];
return buf.toString('utf16le', i, buf.length - 1);
}
// For UTF-16LE we do not explicitly append special replacement characters if we
// end on a partial character, we simply let v8 handle that.
function utf16End(buf) {
var r = buf && buf.length ? this.write(buf) : '';
if (this.lastNeed) {
var end = this.lastTotal - this.lastNeed;
return r + this.lastChar.toString('utf16le', 0, end);
}
return r;
}
function base64Text(buf, i) {
var n = (buf.length - i) % 3;
if (n === 0) return buf.toString('base64', i);
this.lastNeed = 3 - n;
this.lastTotal = 3;
if (n === 1) {
this.lastChar[0] = buf[buf.length - 1];
} else {
this.lastChar[0] = buf[buf.length - 2];
this.lastChar[1] = buf[buf.length - 1];
}
return buf.toString('base64', i, buf.length - n);
}
function base64End(buf) {
var r = buf && buf.length ? this.write(buf) : '';
if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
return r;
}
// Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
function simpleWrite(buf) {
return buf.toString(this.encoding);
}
function simpleEnd(buf) {
return buf && buf.length ? this.write(buf) : '';
}
/***/ }),
/***/ "./node_modules/util-deprecate/browser.js":
/*!************************************************!*\
!*** ./node_modules/util-deprecate/browser.js ***!
\************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {
/**
* Module exports.
*/
module.exports = deprecate;
/**
* Mark that a method should not be used.
* Returns a modified function which warns once by default.
*
* If `localStorage.noDeprecation = true` is set, then it is a no-op.
*
* If `localStorage.throwDeprecation = true` is set, then deprecated functions
* will throw an Error when invoked.
*
* If `localStorage.traceDeprecation = true` is set, then deprecated functions
* will invoke `console.trace()` instead of `console.error()`.
*
* @param {Function} fn - the function to deprecate
* @param {String} msg - the string to print to the console when `fn` is invoked
* @returns {Function} a new "deprecated" version of `fn`
* @api public
*/
function deprecate (fn, msg) {
if (config('noDeprecation')) {
return fn;
}
var warned = false;
function deprecated() {
if (!warned) {
if (config('throwDeprecation')) {
throw new Error(msg);
} else if (config('traceDeprecation')) {
console.trace(msg);
} else {
console.warn(msg);
}
warned = true;
}
return fn.apply(this, arguments);
}
return deprecated;
}
/**
* Checks `localStorage` for boolean values for the given `name`.
*
* @param {String} name
* @returns {Boolean}
* @api private
*/
function config (name) {
// accessing global.localStorage can trigger a DOMException in sandboxed iframes
try {
if (!global.localStorage) return false;
} catch (_) {
return false;
}
var val = global.localStorage[name];
if (null == val) return false;
return String(val).toLowerCase() === 'true';
}
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")));
/***/ }),
/***/ "./node_modules/webpack/buildin/global.js":
/*!***********************************!*\
!*** (webpack)/buildin/global.js ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports) {
var g;
// This works in non-strict mode
g = (function() {
return this;
})();
try {
// This works if eval is allowed (see CSP)
g = g || new Function("return this")();
} catch (e) {
// This works if the window reference is available
if (typeof window === "object") g = window;
}
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
/***/ }),
/***/ "./src/core/Debug.js":
/*!***************************!*\
!*** ./src/core/Debug.js ***!
\***************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var LOG_LEVEL_NONE = 0;
var LOG_LEVEL_FATAL = 1;
var LOG_LEVEL_ERROR = 2;
var LOG_LEVEL_WARNING = 3;
var LOG_LEVEL_INFO = 4;
var LOG_LEVEL_DEBUG = 5;
/**
* @module Debug
* @param {object} config
* @ignore
*/
function Debug(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var settings = config.settings;
var logFn = [];
var instance, showLogTimestamp, showCalleeName, startTime;
function setup() {
showLogTimestamp = true;
showCalleeName = true;
startTime = new Date().getTime();
if (typeof window !== 'undefined' && window.console) {
logFn[LOG_LEVEL_FATAL] = getLogFn(window.console.error);
logFn[LOG_LEVEL_ERROR] = getLogFn(window.console.error);
logFn[LOG_LEVEL_WARNING] = getLogFn(window.console.warn);
logFn[LOG_LEVEL_INFO] = getLogFn(window.console.info);
logFn[LOG_LEVEL_DEBUG] = getLogFn(window.console.debug);
}
}
function getLogFn(fn) {
if (fn && fn.bind) {
return fn.bind(window.console);
} // if not define, return the default function for reporting logs
return window.console.log.bind(window.console);
}
/**
* Retrieves a logger which can be used to write logging information in browser console.
* @param {object} instance Object for which the logger is created. It is used
* to include calle object information in log messages.
* @memberof module:Debug
* @returns {Logger}
* @instance
*/
function getLogger(instance) {
return {
fatal: fatal.bind(instance),
error: error.bind(instance),
warn: warn.bind(instance),
info: info.bind(instance),
debug: debug.bind(instance)
};
}
/**
* Prepends a timestamp in milliseconds to each log message.
* @param {boolean} value Set to true if you want to see a timestamp in each log message.
* @default LOG_LEVEL_WARNING
* @memberof module:Debug
* @instance
*/
function setLogTimestampVisible(value) {
showLogTimestamp = value;
}
/**
* Prepends the callee object name, and media type if available, to each log message.
* @param {boolean} value Set to true if you want to see the callee object name and media type in each log message.
* @default true
* @memberof module:Debug
* @instance
*/
function setCalleeNameVisible(value) {
showCalleeName = value;
}
function fatal() {
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
params[_key] = arguments[_key];
}
doLog.apply(void 0, [LOG_LEVEL_FATAL, this].concat(params));
}
function error() {
for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
params[_key2] = arguments[_key2];
}
doLog.apply(void 0, [LOG_LEVEL_ERROR, this].concat(params));
}
function warn() {
for (var _len3 = arguments.length, params = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
params[_key3] = arguments[_key3];
}
doLog.apply(void 0, [LOG_LEVEL_WARNING, this].concat(params));
}
function info() {
for (var _len4 = arguments.length, params = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
params[_key4] = arguments[_key4];
}
doLog.apply(void 0, [LOG_LEVEL_INFO, this].concat(params));
}
function debug() {
for (var _len5 = arguments.length, params = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
params[_key5] = arguments[_key5];
}
doLog.apply(void 0, [LOG_LEVEL_DEBUG, this].concat(params));
}
function doLog(level, _this) {
var message = '';
var logTime = null;
if (showLogTimestamp) {
logTime = new Date().getTime();
message += '[' + (logTime - startTime) + ']';
}
if (showCalleeName && _this && _this.getClassName) {
message += '[' + _this.getClassName() + ']';
if (_this.getType) {
message += '[' + _this.getType() + ']';
}
}
if (message.length > 0) {
message += ' ';
}
for (var _len6 = arguments.length, params = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
params[_key6 - 2] = arguments[_key6];
}
Array.apply(null, params).forEach(function (item) {
message += item + ' ';
}); // log to console if the log level is high enough
if (logFn[level] && settings.get().debug.logLevel >= level) {
logFn[level](message);
} // send log event regardless of log level
if (settings && settings.get().debug.dispatchEvent) {
eventBus.trigger(_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].LOG, {
message: message,
level: level
});
}
}
instance = {
getLogger: getLogger,
setLogTimestampVisible: setLogTimestampVisible,
setCalleeNameVisible: setCalleeNameVisible
};
setup();
return instance;
}
Debug.__dashjs_factory_name = 'Debug';
var factory = _FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(Debug);
factory.LOG_LEVEL_NONE = LOG_LEVEL_NONE;
factory.LOG_LEVEL_FATAL = LOG_LEVEL_FATAL;
factory.LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;
factory.LOG_LEVEL_WARNING = LOG_LEVEL_WARNING;
factory.LOG_LEVEL_INFO = LOG_LEVEL_INFO;
factory.LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;
_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].updateSingletonFactory(Debug.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/core/EventBus.js":
/*!******************************!*\
!*** ./src/core/EventBus.js ***!
\******************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var EVENT_PRIORITY_LOW = 0;
var EVENT_PRIORITY_HIGH = 5000;
function EventBus() {
var handlers = {};
function on(type, listener, scope) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (!type) {
throw new Error('event type cannot be null or undefined');
}
if (!listener || typeof listener !== 'function') {
throw new Error('listener must be a function: ' + listener);
}
var priority = options.priority || EVENT_PRIORITY_LOW;
if (getHandlerIdx(type, listener, scope) >= 0) return;
handlers[type] = handlers[type] || [];
var handler = {
callback: listener,
scope: scope,
priority: priority
};
if (scope && scope.getStreamId) {
handler.streamId = scope.getStreamId();
}
if (scope && scope.getType) {
handler.mediaType = scope.getType();
}
if (options && options.mode) {
handler.mode = options.mode;
}
var inserted = handlers[type].some(function (item, idx) {
if (item && priority > item.priority) {
handlers[type].splice(idx, 0, handler);
return true;
}
});
if (!inserted) {
handlers[type].push(handler);
}
}
function off(type, listener, scope) {
if (!type || !listener || !handlers[type]) return;
var idx = getHandlerIdx(type, listener, scope);
if (idx < 0) return;
handlers[type][idx] = null;
}
function trigger(type) {
var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var filters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (!type || !handlers[type]) return;
payload = payload || {};
if (payload.hasOwnProperty('type')) throw new Error('\'type\' is a reserved word for event dispatching');
payload.type = type;
if (filters.streamId) {
payload.streamId = filters.streamId;
}
if (filters.mediaType) {
payload.mediaType = filters.mediaType;
}
handlers[type].filter(function (handler) {
if (!handler) {
return false;
}
if (filters.streamId && handler.streamId && handler.streamId !== filters.streamId) {
return false;
}
if (filters.mediaType && handler.mediaType && handler.mediaType !== filters.mediaType) {
return false;
} // This is used for dispatching DASH events. By default we use the onStart mode. Consequently we filter everything that has a non matching mode and the onReceive events for handlers that did not specify a mode.
if (filters.mode && handler.mode && handler.mode !== filters.mode || !handler.mode && filters.mode && filters.mode === _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].EVENT_MODE_ON_RECEIVE) {
return false;
}
return true;
}).forEach(function (handler) {
return handler && handler.callback.call(handler.scope, payload);
});
}
function getHandlerIdx(type, listener, scope) {
var idx = -1;
if (!handlers[type]) return idx;
handlers[type].some(function (item, index) {
if (item && item.callback === listener && (!scope || scope === item.scope)) {
idx = index;
return true;
}
});
return idx;
}
function reset() {
handlers = {};
}
var instance = {
on: on,
off: off,
trigger: trigger,
reset: reset
};
return instance;
}
EventBus.__dashjs_factory_name = 'EventBus';
var factory = _FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(EventBus);
factory.EVENT_PRIORITY_LOW = EVENT_PRIORITY_LOW;
factory.EVENT_PRIORITY_HIGH = EVENT_PRIORITY_HIGH;
_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].updateSingletonFactory(EventBus.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/core/FactoryMaker.js":
/*!**********************************!*\
!*** ./src/core/FactoryMaker.js ***!
\**********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module FactoryMaker
* @ignore
*/
var FactoryMaker = function () {
var instance;
var singletonContexts = [];
var singletonFactories = {};
var classFactories = {};
function extend(name, childInstance, override, context) {
if (!context[name] && childInstance) {
context[name] = {
instance: childInstance,
override: override
};
}
}
/**
* Use this method from your extended object. this.factory is injected into your object.
* this.factory.getSingletonInstance(this.context, 'VideoModel')
* will return the video model for use in the extended object.
*
* @param {Object} context - injected into extended object as this.context
* @param {string} className - string name found in all dash.js objects
* with name __dashjs_factory_name Will be at the bottom. Will be the same as the object's name.
* @returns {*} Context aware instance of specified singleton name.
* @memberof module:FactoryMaker
* @instance
*/
function getSingletonInstance(context, className) {
for (var i in singletonContexts) {
var obj = singletonContexts[i];
if (obj.context === context && obj.name === className) {
return obj.instance;
}
}
return null;
}
/**
* Use this method to add an singleton instance to the system. Useful for unit testing to mock objects etc.
*
* @param {Object} context
* @param {string} className
* @param {Object} instance
* @memberof module:FactoryMaker
* @instance
*/
function setSingletonInstance(context, className, instance) {
for (var i in singletonContexts) {
var obj = singletonContexts[i];
if (obj.context === context && obj.name === className) {
singletonContexts[i].instance = instance;
return;
}
}
singletonContexts.push({
name: className,
context: context,
instance: instance
});
}
/**
* Use this method to remove all singleton instances associated with a particular context.
*
* @param {Object} context
* @memberof module:FactoryMaker
* @instance
*/
function deleteSingletonInstances(context) {
singletonContexts = singletonContexts.filter(function (x) {
return x.context !== context;
});
}
/*------------------------------------------------------------------------------------------*/
// Factories storage Management
/*------------------------------------------------------------------------------------------*/
function getFactoryByName(name, factoriesArray) {
return factoriesArray[name];
}
function updateFactory(name, factory, factoriesArray) {
if (name in factoriesArray) {
factoriesArray[name] = factory;
}
}
/*------------------------------------------------------------------------------------------*/
// Class Factories Management
/*------------------------------------------------------------------------------------------*/
function updateClassFactory(name, factory) {
updateFactory(name, factory, classFactories);
}
function getClassFactoryByName(name) {
return getFactoryByName(name, classFactories);
}
function getClassFactory(classConstructor) {
var factory = getFactoryByName(classConstructor.__dashjs_factory_name, classFactories);
if (!factory) {
factory = function factory(context) {
if (context === undefined) {
context = {};
}
return {
create: function create() {
return merge(classConstructor, context, arguments);
}
};
};
classFactories[classConstructor.__dashjs_factory_name] = factory; // store factory
}
return factory;
}
/*------------------------------------------------------------------------------------------*/
// Singleton Factory MAangement
/*------------------------------------------------------------------------------------------*/
function updateSingletonFactory(name, factory) {
updateFactory(name, factory, singletonFactories);
}
function getSingletonFactoryByName(name) {
return getFactoryByName(name, singletonFactories);
}
function getSingletonFactory(classConstructor) {
var factory = getFactoryByName(classConstructor.__dashjs_factory_name, singletonFactories);
if (!factory) {
factory = function factory(context) {
var instance;
if (context === undefined) {
context = {};
}
return {
getInstance: function getInstance() {
// If we don't have an instance yet check for one on the context
if (!instance) {
instance = getSingletonInstance(context, classConstructor.__dashjs_factory_name);
} // If there's no instance on the context then create one
if (!instance) {
instance = merge(classConstructor, context, arguments);
singletonContexts.push({
name: classConstructor.__dashjs_factory_name,
context: context,
instance: instance
});
}
return instance;
}
};
};
singletonFactories[classConstructor.__dashjs_factory_name] = factory; // store factory
}
return factory;
}
function merge(classConstructor, context, args) {
var classInstance;
var className = classConstructor.__dashjs_factory_name;
var extensionObject = context[className];
if (extensionObject) {
var extension = extensionObject.instance;
if (extensionObject.override) {
//Override public methods in parent but keep parent.
classInstance = classConstructor.apply({
context: context
}, args);
extension = extension.apply({
context: context,
factory: instance,
parent: classInstance
}, args);
for (var prop in extension) {
if (classInstance.hasOwnProperty(prop)) {
classInstance[prop] = extension[prop];
}
}
} else {
//replace parent object completely with new object. Same as dijon.
return extension.apply({
context: context,
factory: instance
}, args);
}
} else {
// Create new instance of the class
classInstance = classConstructor.apply({
context: context
}, args);
} // Add getClassName function to class instance prototype (used by Debug)
classInstance.getClassName = function () {
return className;
};
return classInstance;
}
instance = {
extend: extend,
getSingletonInstance: getSingletonInstance,
setSingletonInstance: setSingletonInstance,
deleteSingletonInstances: deleteSingletonInstances,
getSingletonFactory: getSingletonFactory,
getSingletonFactoryByName: getSingletonFactoryByName,
updateSingletonFactory: updateSingletonFactory,
getClassFactory: getClassFactory,
getClassFactoryByName: getClassFactoryByName,
updateClassFactory: updateClassFactory
};
return instance;
}();
/* harmony default export */ __webpack_exports__["default"] = (FactoryMaker);
/***/ }),
/***/ "./src/core/Settings.js":
/*!******************************!*\
!*** ./src/core/Settings.js ***!
\******************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ "./src/core/Utils.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../streaming/vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** @module Settings
* @description Define the configuration parameters of Dash.js MediaPlayer.
* @see {@link module:Settings~PlayerSettings PlayerSettings} for further information about the supported configuration properties.
*/
/**
* @typedef {Object} PlayerSettings
* @property {module:Settings~DebugSettings} [debug]
* Debug related settings.
* @property {module:Settings~ErrorSettings} [errors]
* Error related settings
* @property {module:Settings~StreamingSettings} [streaming]
* Streaming related settings.
* @example
*
* // Full settings object
* settings = {
* debug: {
* logLevel: Debug.LOG_LEVEL_WARNING,
* dispatchEvent: false
* },
* streaming: {
* abandonLoadTimeout: 10000,
* wallclockTimeUpdateInterval: 100,
* lowLatencyEnabled: false,
* lowLatencyEnabledByManifest: true,
* manifestUpdateRetryInterval: 100,
* cacheInitSegments: true,
* eventControllerRefreshDelay: 100,
* capabilities: {
* filterUnsupportedEssentialProperties: true,
* useMediaCapabilitiesApi: false
* },
* timeShiftBuffer: {
* calcFromSegmentTimeline: false,
* fallbackToSegmentTimeline: true
* },
* metrics: {
* maxListDepth: 100
* },
* delay: {
* liveDelayFragmentCount: NaN,
* liveDelay: NaN,
* useSuggestedPresentationDelay: true,
* applyServiceDescription: true
* },
* protection: {
* keepProtectionMediaKeys: false
* },
* buffer: {
* enableSeekDecorrelationFix: true,
* fastSwitchEnabled: true,
* flushBufferAtTrackSwitch: false,
* reuseExistingSourceBuffers: true,
* bufferPruningInterval: 10,
* bufferToKeep: 20,
* bufferTimeAtTopQuality: 30,
* bufferTimeAtTopQualityLongForm: 60,
* initialBufferLevel: NaN,
* stableBufferTime: 12,
* longFormContentDurationThreshold: 600,
* stallThreshold: 0.5,
* useAppendWindow: true,
* setStallState: false
* },
* gaps: {
* jumpGaps: true,
* jumpLargeGaps: true,
* smallGapLimit: 1.5,
* threshold: 0.3,
* enableSeekFix: false
* },
* utcSynchronization: {
* enabled: true,
* useManifestDateHeaderTimeSource: true,
* backgroundAttempts: 2,
* timeBetweenSyncAttempts: 30,
* maximumTimeBetweenSyncAttempts: 600,
* minimumTimeBetweenSyncAttempts: 2,
* timeBetweenSyncAttemptsAdjustmentFactor: 2,
* maximumAllowedDrift: 100,
* enableBackgroundSyncAfterSegmentDownloadError: true,
* defaultTimingSource: {
* scheme: 'urn:mpeg:dash:utc:http-xsdate:2014',
* value: 'http://time.akamai.com/?iso&ms'
* }
* },
* scheduling: {
* defaultTimeout: 300,
* lowLatencyTimeout: 100,
* scheduleWhilePaused: true
* },
* text: {
* defaultEnabled: true
* },
* liveCatchup: {
* minDrift: 0.02,
* maxDrift: 12,
* playbackRate: 0.5,
* latencyThreshold: 60,
* playbackBufferMin: 0.5,
* enabled: false,
* mode: Constants.LIVE_CATCHUP_MODE_DEFAULT
* },
* lastBitrateCachingInfo: { enabled: true, ttl: 360000 },
* lastMediaSettingsCachingInfo: { enabled: true, ttl: 360000 },
* cacheLoadThresholds: { video: 50, audio: 5 },
* trackSwitchMode: {
* audio: Constants.TRACK_SWITCH_MODE_ALWAYS_REPLACE,
* video: Constants.TRACK_SWITCH_MODE_NEVER_REPLACE
* },
* selectionModeForInitialTrack: Constants.TRACK_SELECTION_MODE_HIGHEST_SELECTION_PRIORITY,
* fragmentRequestTimeout: 0,
* retryIntervals: {
* [HTTPRequest.MPD_TYPE]: 500,
* [HTTPRequest.XLINK_EXPANSION_TYPE]: 500,
* [HTTPRequest.MEDIA_SEGMENT_TYPE]: 1000,
* [HTTPRequest.INIT_SEGMENT_TYPE]: 1000,
* [HTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE]: 1000,
* [HTTPRequest.INDEX_SEGMENT_TYPE]: 1000,
* [HTTPRequest.MSS_FRAGMENT_INFO_SEGMENT_TYPE]: 1000,
* [HTTPRequest.LICENSE]: 1000,
* [HTTPRequest.OTHER_TYPE]: 1000,
* lowLatencyReductionFactor: 10
* },
* retryAttempts: {
* [HTTPRequest.MPD_TYPE]: 3,
* [HTTPRequest.XLINK_EXPANSION_TYPE]: 1,
* [HTTPRequest.MEDIA_SEGMENT_TYPE]: 3,
* [HTTPRequest.INIT_SEGMENT_TYPE]: 3,
* [HTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE]: 3,
* [HTTPRequest.INDEX_SEGMENT_TYPE]: 3,
* [HTTPRequest.MSS_FRAGMENT_INFO_SEGMENT_TYPE]: 3,
* [HTTPRequest.LICENSE]: 3,
* [HTTPRequest.OTHER_TYPE]: 3,
* lowLatencyMultiplyFactor: 5
* },
* abr: {
* movingAverageMethod: Constants.MOVING_AVERAGE_SLIDING_WINDOW,
* ABRStrategy: Constants.ABR_STRATEGY_DYNAMIC,
* additionalAbrRules: {
* insufficientBufferRule: false,
* switchHistoryRule: true,
* droppedFramesRule: true,
* abandonRequestsRule: false
* },
* bandwidthSafetyFactor: 0.9,
* useDefaultABRRules: true,
* useDeadTimeLatency: true,
* limitBitrateByPortal: false,
* usePixelRatioInLimitBitrateByPortal: false,
* maxBitrate: { audio: -1, video: -1 },
* minBitrate: { audio: -1, video: -1 },
* maxRepresentationRatio: { audio: 1, video: 1 },
* initialBitrate: { audio: -1, video: -1 },
* initialRepresentationRatio: { audio: -1, video: -1 },
* autoSwitchBitrate: { audio: true, video: true },
* fetchThroughputCalculationMode: Constants.ABR_FETCH_THROUGHPUT_CALCULATION_DOWNLOADED_DATA
* },
* cmcd: {
* enabled: false,
* sid: null,
* cid: null,
* rtp: null,
* rtpSafetyFactor: 5,
* mode: Constants.CMCD_MODE_QUERY
* }
* },
* errors: {
* recoverAttempts: {
* mediaErrorDecode: 5
* }
* }
* }
*/
/**
* @typedef {Object} TimeShiftBuffer
* @property {boolean} [calcFromSegmentTimeline=false]
* Enable calculation of the DVR window for SegmentTimeline manifests based on the entries in \<SegmentTimeline\>.
* * @property {boolean} [fallbackToSegmentTimeline=true]
* In case the MPD uses \<SegmentTimeline\ and no segment is found within the DVR window the DVR window is calculated based on the entries in \<SegmentTimeline\>.
*/
/**
* @typedef {Object} LiveDelay
* @property {number} [liveDelayFragmentCount=NaN]
* Changing this value will lower or increase live stream latency.
*
* The detected segment duration will be multiplied by this value to define a time in seconds to delay a live stream from the live edge.
*
* Lowering this value will lower latency but may decrease the player's ability to build a stable buffer.
* @property {number} [liveDelay]
* Equivalent in seconds of setLiveDelayFragmentCount.
*
* Lowering this value will lower latency but may decrease the player's ability to build a stable buffer.
*
* This value should be less than the manifest duration by a couple of segment durations to avoid playback issues.
*
* If set, this parameter will take precedence over setLiveDelayFragmentCount and manifest info.
* @property {boolean} [useSuggestedPresentationDelay=true]
* Set to true if you would like to overwrite the default live delay and honor the SuggestedPresentationDelay attribute in by the manifest.
* @property {boolean} [applyServiceDescription=true]
* Set to true if dash.js should use latency targets defined in ServiceDescription elements
*/
/**
* @typedef {Object} Buffer
* @property {boolean} [enableSeekDecorrelationFix=false]
* Enables a workaround for playback start on some devices, e.g. WebOS 4.9.
* It is necessary because some browsers do not support setting currentTime on video element to a value that is outside of current buffer.
*
* If you experience unexpected seeking triggered by BufferController, you can try setting this value to false.
* @property {boolean} [fastSwitchEnabled=true]
* When enabled, after an ABR up-switch in quality, instead of requesting and appending the next fragment at the end of the current buffer range it is requested and appended closer to the current time.
*
* When enabled, The maximum time to render a higher quality is current time + (1.5 * fragment duration).
*
* Note, When ABR down-switch is detected, we appended the lower quality at the end of the buffer range to preserve the
* higher quality media for as long as possible.
*
* If enabled, it should be noted there are a few cases when the client will not replace inside buffer range but rather just append at the end.
* 1. When the buffer level is less than one fragment duration.
* 2. The client is in an Abandonment State due to recent fragment abandonment event.
*
* Known issues:
* 1. In IE11 with auto switching off, if a user switches to a quality they can not download in time the fragment may be appended in the same range as the playhead or even in the past, in IE11 it may cause a stutter or stall in playback.
* @property {boolean} [flushBufferAtTrackSwitch=false]
* When enabled, after a track switch and in case buffer is being replaced, the video element is flushed (seek at current playback time) once a segment of the new track is appended in buffer in order to force video decoder to play new track.
*
* This can be required on some devices like GoogleCast devices to make track switching functional.
*
* Otherwise track switching will be effective only once after previous buffered track is fully consumed.
* @property {boolean} [reuseExistingSourceBuffers=true]
* Enable reuse of existing MediaSource Sourcebuffers during period transition.
* @property {number} [bufferPruningInterval=10]
* The interval of pruning buffer in seconds.
* @property {number} [bufferToKeep=20]
* This value influences the buffer pruning logic.
*
* Allows you to modify the buffer that is kept in source buffer in seconds.
* 0|-----------bufferToPrune-----------|-----bufferToKeep-----|currentTime|
* @property {number} [bufferTimeAtTopQuality=30]
* The time that the internal buffer target will be set to once playing the top quality.
*
* If there are multiple bitrates in your adaptation, and the media is playing at the highest bitrate, then we try to build a larger buffer at the top quality to increase stability and to maintain media quality.
* @property {number} [bufferTimeAtTopQualityLongForm=60]
* The time that the internal buffer target will be set to once playing the top quality for long form content.
* @property {number} [longFormContentDurationThreshold=600]
* The threshold which defines if the media is considered long form content.
*
* This will directly affect the buffer targets when playing back at the top quality.
* @property {number} [initialBufferLevel=NaN]
* Initial buffer level before playback starts
* @property {number} [stableBufferTime=12]
* The time that the internal buffer target will be set to post startup/seeks (NOT top quality).
*
* When the time is set higher than the default you will have to wait longer to see automatic bitrate switches but will have a larger buffer which will increase stability.
* @property {number} [stallThreshold=0.3]
* Stall threshold used in BufferController.js to determine whether a track should still be changed and which buffer range to prune.
* @property {boolean} [useAppendWindow=true]
* Specifies if the appendWindow attributes of the MSE SourceBuffers should be set according to content duration from manifest.
* @property {boolean} [setStallState=false]
* Specifies if we fire manual waiting events once the stall threshold is reached
*/
/**
* @typedef {Object} module:Settings~AudioVideoSettings
* @property {number|boolean|string} [audio]
* Configuration for audio media type of tracks.
* @property {number|boolean|string} [video]
* Configuration for video media type of tracks.
*/
/**
* @typedef {Object} DebugSettings
* @property {number} [logLevel=dashjs.Debug.LOG_LEVEL_WARNING]
* Sets up the log level. The levels are cumulative.
*
* For example, if you set the log level to dashjs.Debug.LOG_LEVEL_WARNING all warnings, errors and fatals will be logged.
*
* Possible values.
*
* - dashjs.Debug.LOG_LEVEL_NONE
* No message is written in the browser console.
*
* - dashjs.Debug.LOG_LEVEL_FATAL
* Log fatal errors.
* An error is considered fatal when it causes playback to fail completely.
*
* - dashjs.Debug.LOG_LEVEL_ERROR
* Log error messages.
*
* - dashjs.Debug.LOG_LEVEL_WARNING
* Log warning messages.
*
* - dashjs.Debug.LOG_LEVEL_INFO
* Log info messages.
*
* - dashjs.Debug.LOG_LEVEL_DEBUG
* Log debug messages.
* @property {boolean} [dispatchEvent=false]
* Enable to trigger a Events.LOG event whenever log output is generated.
*
* Note this will be dispatched regardless of log level.
*/
/**
* @typedef {Object} module:Settings~ErrorSettings
* @property {object} [recoverAttempts={mediaErrorDecode: 5}]
* Defines the maximum number of recover attempts for specific media errors.
*
* For mediaErrorDecode the player will reset the MSE and skip the blacklisted segment that caused the decode error. The resulting gap will be handled by the GapController.
*/
/**
* @typedef {Object} CachingInfoSettings
* @property {boolean} [enable]
* Enable or disable the caching feature.
* @property {number} [ttl]
* Time to live.
*
* A value defined in milliseconds representing how log to cache the settings for.
*/
/**
* @typedef {Object} Gaps
* @property {boolean} [jumpGaps=true]
* Sets whether player should jump small gaps (discontinuities) in the buffer.
* @property {boolean} [jumpLargeGaps=true]
* Sets whether player should jump large gaps (discontinuities) in the buffer.
* @property {number} [smallGapLimit=1.5]
* Time in seconds for a gap to be considered small.
* @property {number} [threshold=0.3]
* Threshold at which the gap handling is executed. If currentRangeEnd - currentTime < threshold the gap jump will be triggered.
* For live stream the jump might be delayed to keep a consistent live edge.
* Note that the amount of buffer at which platforms automatically stall might differ.
* @property {boolean} [enableSeekFix=false]
* Enables the adjustment of the seek target once no valid segment request could be generated for a specific seek time. This can happen if the user seeks to a position for which there is a gap in the timeline.
*/
/**
* @typedef {Object} UtcSynchronizationSettings
* @property {boolean} [enabled=true]
* Enables or disables the UTC clock synchronization
* @property {boolean} [useManifestDateHeaderTimeSource=true]
* Allows you to enable the use of the Date Header, if exposed with CORS, as a timing source for live edge detection.
*
* The use of the date header will happen only after the other timing source that take precedence fail or are omitted as described.
* @property {number} [backgroundAttempts=2]
* Number of synchronization attempts to perform in the background after an initial synchronization request has been done. This is used to verify that the derived client-server offset is correct.
*
* The background requests are async and done in parallel to the start of the playback.
*
* This value is also used to perform a resync after 404 errors on segments.
* @property {number} [timeBetweenSyncAttempts=30]
* The time in seconds between two consecutive sync attempts.
*
* Note: This value is used as an initial starting value. The internal value of the TimeSyncController is adjusted during playback based on the drift between two consecutive synchronization attempts.
*
* Note: A sync is only performed after an MPD update. In case the @minimumUpdatePeriod is larger than this value the sync will be delayed until the next MPD update.
* @property {number} [maximumTimeBetweenSyncAttempts=600]
* The maximum time in seconds between two consecutive sync attempts.
*
* @property {number} [minimumTimeBetweenSyncAttempts=2]
* The minimum time in seconds between two consecutive sync attempts.
*
* @property {number} [timeBetweenSyncAttemptsAdjustmentFactor=2]
* The factor used to multiply or divide the timeBetweenSyncAttempts parameter after a sync. The maximumAllowedDrift defines whether this value is used as a factor or a dividend.
*
* @property {number} [maximumAllowedDrift=100]
* The maximum allowed drift specified in milliseconds between two consecutive synchronization attempts.
*
* @property {boolean} [enableBackgroundSyncAfterSegmentDownloadError=true]
* Enables or disables the background sync after the player ran into a segment download error.
*
* @property {object} [defaultTimingSource={scheme:'urn:mpeg:dash:utc:http-xsdate:2014',value: 'http://time.akamai.com/?iso&ms'}]
* The default timing source to be used. The timing sources in the MPD take precedence over this one.
*/
/**
* @typedef {Object} Scheduling
* @property {number} [defaultTimeout=300]
* Default timeout between two consecutive segment scheduling attempts
* @property {number} [lowLatencyTimeout]
* Default timeout between two consecutive low-latency segment scheduling attempts
* @property {boolean} [scheduleWhilePaused=true]
* Set to true if you would like dash.js to keep downloading fragments in the background when the video element is paused.
*/
/**
* @typedef {Object} Text
* @property {number} [defaultEnabled=true]
* Enable/disable subtitle rendering by default.
*/
/**
* @typedef {Object} LiveCatchupSettings
* @property {number} [minDrift=0.02]
* Use this method to set the minimum latency deviation allowed before activating catch-up mechanism.
*
* In low latency mode, when the difference between the measured latency and the target one, as an absolute number, is higher than the one sets with this method, then dash.js increases/decreases playback rate until target latency is reached.
*
* LowLatencyMinDrift should be provided in seconds, and it uses values between 0.0 and 0.5.
*
* Note: Catch-up mechanism is only applied when playing low latency live streams.
* @property {number} [maxDrift=12]
* Use this method to set the maximum latency deviation allowed before dash.js to do a seeking to live position.
*
* In low latency mode, when the difference between the measured latency and the target one, as an absolute number, is higher than the one sets with this method, then dash.js does a seek to live edge position minus the target live delay.
*
* LowLatencyMaxDriftBeforeSeeking should be provided in seconds.
*
* If 0, then seeking operations won't be used for fixing latency deviations.
*
* Note: Catch-up mechanism is only applied when playing low latency live streams.
* @property {number} [playbackRate=0.5]
* Use this parameter to set the maximum catch up rate, as a percentage, for low latency live streams.
*
* In low latency mode, when measured latency is higher/lower than the target one, dash.js increases/decreases playback rate respectively up to (+/-) the percentage defined with this method until target is reached.
*
* Valid values for catch up rate are in range 0-0.5 (0-50%).
*
* Set it to 0 to turn off live catch up feature.
*
* Note: Catch-up mechanism is only applied when playing low latency live streams.
* @property {number} [latencyThreshold=NaN]
* Use this parameter to set the maximum threshold for which live catch up is applied.
*
* For instance, if this value is set to 8 seconds, then live catchup is only applied if the current live latency is equal or below 8 seconds.
*
* The reason behind this parameter is to avoid an increase of the playback rate if the user seeks within the DVR window.
*
* If no value is specified this will be twice the maximum live delay.
*
* The maximum live delay is either specified in the manifest as part of a ServiceDescriptor or calculated the following:
* maximumLiveDelay = targetDelay + liveCatchupMinDrift.
*
* @property {number} [playbackBufferMin=NaN]
* Use this parameter to specify the minimum buffer which is used for LoL+ based playback rate reduction.
*
*
* @property {boolean} [enabled=false]
* Use this parameter to enable the catchup mode for non low-latency streams.
*
* @property {string} [mode="liveCatchupModeDefault"]
* Use this parameter to switch between different catchup modes.
*
* Options: "liveCatchupModeDefault" or "liveCatchupModeLOLP".
*
* Note: Catch-up mechanism is automatically applied when playing low latency live streams.
*/
/**
* @typedef {Object} RequestTypeSettings
* @property {number} [MPD]
* Manifest type of requests.
* @property {number} [XLinkExpansion]
* XLink expansion type of requests.
* @property {number} [InitializationSegment]
* Request to retrieve an initialization segment.
* @property {number} [IndexSegment]
* Request to retrieve an index segment (SegmentBase).
* @property {number} [MediaSegment]
* Request to retrieve a media segment (video/audio/image/text chunk).
* @property {number} [BitstreamSwitchingSegment]
* Bitrate stream switching type of request.
* @property {number} [FragmentInfoSegment]
* Request to retrieve a FragmentInfo segment (specific to Smooth Streaming live streams).
* @property {number} [other]
* Other type of request.
* @property {number} [lowLatencyReductionFactor]
* For low latency mode, values of type of request are divided by lowLatencyReductionFactor.
*
* Note: It's not type of request.
* @property {number} [lowLatencyMultiplyFactor]
* For low latency mode, values of type of request are multiplied by lowLatencyMultiplyFactor.
*
* Note: It's not type of request.
*/
/**
* @typedef {Object} Protection
* @property {boolean} [keepProtectionMediaKeys=false]
* Set the value for the ProtectionController and MediaKeys life cycle.
*
* If true, the ProtectionController and then created MediaKeys and MediaKeySessions will be preserved during the MediaPlayer lifetime.
* @property {boolean} ignoreEmeEncryptedEvent
* If set to true the player will ignore "encrypted" and "needkey" events thrown by the EME.
*/
/**
* @typedef {Object} Capabilities
* @property {boolean} [filterUnsupportedEssentialProperties=true]
* Enable to filter all the AdaptationSets and Representations which contain an unsupported \<EssentialProperty\> element.
* @property {boolean} [useMediaCapabilitiesApi=false]
* Enable to use the MediaCapabilities API to check whether codecs are supported. If disabled MSE.isTypeSupported will be used instead.
*/
/**
* @typedef {Object} AbrSettings
* @property {string} [movingAverageMethod="slidingWindow"]
* Sets the moving average method used for smoothing throughput estimates.
*
* Valid methods are "slidingWindow" and "ewma".
*
* The call has no effect if an invalid method is passed.
*
* The sliding window moving average method computes the average throughput using the last four segments downloaded.
*
* If the stream is live (as opposed to VOD), then only the last three segments are used.
*
* If wide variations in throughput are detected, the number of segments can be dynamically increased to avoid oscillations.
*
* The exponentially weighted moving average (EWMA) method computes the average using exponential smoothing.
*
* Two separate estimates are maintained, a fast one with a three-second half life and a slow one with an eight-second half life.
*
* The throughput estimate at any time is the minimum of the fast and slow estimates.
*
* This allows a fast reaction to a bandwidth drop and prevents oscillations on bandwidth spikes.
* @property {string} [ABRStrategy="abrDynamic"]
* Returns the current ABR strategy being used: "abrDynamic", "abrBola" or "abrThroughput".
* @property {object} [trackSwitchMode={video: "neverReplace", audio: "alwaysReplace"}]
* @property {object} [additionalAbrRules={insufficientBufferRule: false,switchHistoryRule: true,droppedFramesRule: true,abandonRequestsRule: false}]
* Enable/Disable additional ABR rules in case ABRStrategy is set to "abrDynamic", "abrBola" or "abrThroughput".
* @property {number} [bandwidthSafetyFactor=0.9]
* Standard ABR throughput rules multiply the throughput by this value.
*
* It should be between 0 and 1, with lower values giving less rebuffering (but also lower quality).
* @property {boolean} [useDefaultABRRules=true]
* Should the default ABR rules be used, or the custom ones added.
* @property {boolean} [useDeadTimeLatency=true]
* If true, only the download portion will be considered part of the download bitrate and latency will be regarded as static.
*
* If false, the reciprocal of the whole transfer time will be used.
* @property {boolean} [limitBitrateByPortal=false]
* If true, the size of the video portal will limit the max chosen video resolution.
* @property {boolean} [usePixelRatioInLimitBitrateByPortal=false]
* Sets whether to take into account the device's pixel ratio when defining the portal dimensions.
*
* Useful on, for example, retina displays.
* @property {module:Settings~AudioVideoSettings} [maxBitrate={audio: -1, video: -1}]
* The maximum bitrate that the ABR algorithms will choose.
*
* Use NaN for no limit.
* @property {module:Settings~AudioVideoSettings} [minBitrate={audio: -1, video: -1}]
* The minimum bitrate that the ABR algorithms will choose.
*
* Use NaN for no limit.
* @property {module:Settings~AudioVideoSettings} [maxRepresentationRatio={audio: 1, video: 1}]
* When switching multi-bitrate content (auto or manual mode) this property specifies the maximum representation allowed, as a proportion of the size of the representation set.
*
* You can set or remove this cap at anytime before or during playback.
*
* To clear this setting you set the value to 1.
*
* If both this and maxAllowedBitrate are defined, maxAllowedBitrate is evaluated first, then maxAllowedRepresentation, i.e. the lowest value from executing these rules is used.
*
* This feature is typically used to reserve higher representations for playback only when connected over a fast connection.
* @property {module:Settings~AudioVideoSettings} [initialBitrate={audio: -1, video: -1}]
* Explicitly set the starting bitrate for audio or video.
* @property {module:Settings~AudioVideoSettings} [initialRepresentationRatio={audio: -1, video: -1}]
* Explicitly set the initial representation ratio.
*
* If initalBitrate is specified, this is ignored.
* @property {module:Settings~AudioVideoSettings} [autoSwitchBitrate={audio: true, video: true}]
* Indicates whether the player should enable ABR algorithms to switch the bitrate.
*
* @property {string} [fetchThroughputCalculationMode="abrFetchThroughputCalculationDownloadedData"]
* Algorithm to determine the throughput in case the Fetch API is used for low latency streaming.
*
* For details please check the samples section and FetchLoader.js.
*/
/**
* @typedef {Object} module:Settings~CmcdSettings
* @property {boolean} [enable=false]
* Enable or disable the CMCD reporting.
* @property {string} [sid]
* GUID identifying the current playback session.
*
* Should be in UUID format.
*
* If not specified a UUID will be automatically generated.
* @property {string} [cid]
* A unique string to identify the current content.
*
* If not specified it will be a hash of the MPD url.
* @property {number} [rtp]
* The requested maximum throughput that the client considers sufficient for delivery of the asset.
*
* If not specified this value will be dynamically calculated in the CMCDModel based on the current buffer level.
* @property {number} [rtpSafetyFactor]
* This value is used as a factor for the rtp value calculation: rtp = minBandwidth * rtpSafetyFactor
*
* If not specified this value defaults to 5. Note that this value is only used when no static rtp value is defined.
* @property {number} [mode]
* The method to use to attach cmcd metrics to the requests. 'query' to use query parameters, 'header' to use http headers.
*
* If not specified this value defaults to 'query'.
*/
/**
* @typedef {Object} Metrics
* @property {number} [metricsMaxListDepth=100]
* Maximum number of metrics that are persisted per type.
*/
/**
* @typedef {Object} StreamingSettings
* @property {number} [abandonLoadTimeout=10000]
* A timeout value in seconds, which during the ABRController will block switch-up events.
*
* This will only take effect after an abandoned fragment event occurs.
* @property {number} [wallclockTimeUpdateInterval=50]
* How frequently the wallclockTimeUpdated internal event is triggered (in milliseconds).
* @property {boolean} [lowLatencyEnabled=false]
* Manually enable or disable low latency mode.
*
* @property {boolean} [lowLatencyEnabledByManifest=true]
* If this value is set to true we enable the low latency mode based on MPD attributes: Specifically in case "availabilityTimeComplete" of the current representation is set to false.
*
* @property {number} [manifestUpdateRetryInterval=100]
* For live streams, set the interval-frequency in milliseconds at which dash.js will check if the current manifest is still processed before downloading the next manifest once the minimumUpdatePeriod time has.
* @property {boolean} [cacheInitSegments=true]
* Enables the caching of init segments to avoid requesting the init segments before each representation switch.
* @property {number} [eventControllerRefreshDelay=100]
* Defines the delay in milliseconds between two consecutive checks for events to be fired.
* @property {module:Settings~Metrics} metrics Metric settings
* @property {module:Settings~LiveDelay} delay Live Delay settings
* @property {module:Settings~TimeShiftBuffer} timeShiftBuffer TimeShiftBuffer settings
* @property {module:Settings~Protection} protection DRM related settings
* @property {module:Settings~Capabilities} capabilities Capability related settings
* @property {module:Settings~Buffer} buffer Buffer related settings
* @property {module:Settings~Gaps} gaps Gap related settings
* @property {module:Settings~UtcSynchronizationSettings} utcSynchronization Settings related to UTC clock synchronization
* @property {module:Settings~Scheduling} scheduling Settings related to segment scheduling
* @property {module:Settings~Text} text Settings related to Subtitles and captions
* @property {module:Settings~LiveCatchupSettings} liveCatchup Settings related to live catchup.
* @property {module:Settings~CachingInfoSettings} [lastBitrateCachingInfo={enabled: true, ttl: 360000}]
* Set to false if you would like to disable the last known bit rate from being stored during playback and used to set the initial bit rate for subsequent playback within the expiration window.
*
* The default expiration is one hour, defined in milliseconds.
*
* If expired, the default initial bit rate (closest to 1000 kbps) will be used for that session and a new bit rate will be stored during that session.
* @property {module:Settings~AudioVideoSettings} [cacheLoadThresholds={video: 50, audio: 5}]
* For a given media type, the threshold which defines if the response to a fragment request is coming from browser cache or not.
* @property {module:Settings~AudioVideoSettings} [trackSwitchMode={video: "neverReplace", audio: "alwaysReplace"}]
* For a given media type defines if existing segments in the buffer should be overwritten once the track is switched. For instance if the user switches the audio language the existing segments in the audio buffer will be replaced when setting this value to "alwaysReplace".
*
* Possible values
*
* - Constants.TRACK_SWITCH_MODE_ALWAYS_REPLACE
* Replace existing segments in the buffer
*
* - Constants.TRACK_SWITCH_MODE_NEVER_REPLACE
* Do not replace existing segments in the buffer
*
* @property {string} [selectionModeForInitialTrack="highestBitrate"]
* Sets the selection mode for the initial track. This mode defines how the initial track will be selected if no initial media settings are set. If initial media settings are set this parameter will be ignored. Available options are:
*
* Possible values
*
* - Constants.TRACK_SELECTION_MODE_HIGHEST_SELECTION_PRIORITY
* This mode makes the player select the track with the highest selectionPriority as defined in the manifest. If not selectionPriority is given we fallback to TRACK_SELECTION_MODE_HIGHEST_BITRATE. This mode is a default mode.
*
* - Constants.TRACK_SELECTION_MODE_HIGHEST_BITRATE
* This mode makes the player select the track with a highest bitrate.
*
* - Constants.TRACK_SELECTION_MODE_FIRST_TRACK
* This mode makes the player select the first track found in the manifest.
*
* - Constants.TRACK_SELECTION_MODE_HIGHEST_EFFICIENCY
* This mode makes the player select the track with the lowest bitrate per pixel average.
*
* - Constants.TRACK_SELECTION_MODE_WIDEST_RANGE
* This mode makes the player select the track with a widest range of bitrates.
*
*
* @property {number} [fragmentRequestTimeout=0]
* Time in milliseconds before timing out on loading a media fragment.
*
* Fragments that timeout are retried as if they failed.
* @property {module:Settings~RequestTypeSettings} [retryIntervals]
* Time in milliseconds of which to reload a failed file load attempt.
*
* For low latency mode these values are divided by lowLatencyReductionFactor.
* @property {module:Settings~RequestTypeSettings} [retryAttempts]
* Total number of retry attempts that will occur on a file load before it fails.
*
* For low latency mode these values are multiplied by lowLatencyMultiplyFactor.
* @property {module:Settings~AbrSettings} abr
* Adaptive Bitrate algorithm related settings.
* @property {module:Settings~CmcdSettings} cmcd
* Settings related to Common Media Client Data reporting.
*/
/**
* @class
* @ignore
*/
function Settings() {
var _retryIntervals, _retryAttempts;
var instance;
/**
* @const {PlayerSettings} defaultSettings
* @ignore
*/
var defaultSettings = {
debug: {
logLevel: _core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"].LOG_LEVEL_WARNING,
dispatchEvent: false
},
streaming: {
abandonLoadTimeout: 10000,
wallclockTimeUpdateInterval: 100,
lowLatencyEnabled: false,
lowLatencyEnabledByManifest: true,
manifestUpdateRetryInterval: 100,
cacheInitSegments: false,
eventControllerRefreshDelay: 150,
capabilities: {
filterUnsupportedEssentialProperties: true,
useMediaCapabilitiesApi: false
},
timeShiftBuffer: {
calcFromSegmentTimeline: false,
fallbackToSegmentTimeline: true
},
metrics: {
maxListDepth: 100
},
delay: {
liveDelayFragmentCount: NaN,
liveDelay: NaN,
useSuggestedPresentationDelay: true,
applyServiceDescription: true
},
protection: {
keepProtectionMediaKeys: false,
ignoreEmeEncryptedEvent: false
},
buffer: {
enableSeekDecorrelationFix: false,
fastSwitchEnabled: true,
flushBufferAtTrackSwitch: false,
reuseExistingSourceBuffers: true,
bufferPruningInterval: 10,
bufferToKeep: 20,
bufferTimeAtTopQuality: 30,
bufferTimeAtTopQualityLongForm: 60,
initialBufferLevel: NaN,
stableBufferTime: 12,
longFormContentDurationThreshold: 600,
stallThreshold: 0.3,
useAppendWindow: true,
setStallState: true
},
gaps: {
jumpGaps: true,
jumpLargeGaps: true,
smallGapLimit: 1.5,
threshold: 0.3,
enableSeekFix: false
},
utcSynchronization: {
enabled: true,
useManifestDateHeaderTimeSource: true,
backgroundAttempts: 2,
timeBetweenSyncAttempts: 30,
maximumTimeBetweenSyncAttempts: 600,
minimumTimeBetweenSyncAttempts: 2,
timeBetweenSyncAttemptsAdjustmentFactor: 2,
maximumAllowedDrift: 100,
enableBackgroundSyncAfterSegmentDownloadError: true,
defaultTimingSource: {
scheme: 'urn:mpeg:dash:utc:http-xsdate:2014',
value: 'https://time.akamai.com/?iso&ms'
}
},
scheduling: {
defaultTimeout: 500,
lowLatencyTimeout: 0,
scheduleWhilePaused: true
},
text: {
defaultEnabled: true
},
liveCatchup: {
minDrift: 0.02,
maxDrift: 12,
playbackRate: 0.5,
latencyThreshold: 60,
playbackBufferMin: 0.5,
enabled: false,
mode: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].LIVE_CATCHUP_MODE_DEFAULT
},
lastBitrateCachingInfo: {
enabled: true,
ttl: 360000
},
lastMediaSettingsCachingInfo: {
enabled: true,
ttl: 360000
},
cacheLoadThresholds: {
video: 50,
audio: 5
},
trackSwitchMode: {
audio: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].TRACK_SWITCH_MODE_ALWAYS_REPLACE,
video: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].TRACK_SWITCH_MODE_NEVER_REPLACE
},
selectionModeForInitialTrack: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].TRACK_SELECTION_MODE_HIGHEST_SELECTION_PRIORITY,
fragmentRequestTimeout: 0,
retryIntervals: (_retryIntervals = {}, _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].MPD_TYPE, 500), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].XLINK_EXPANSION_TYPE, 500), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].MEDIA_SEGMENT_TYPE, 1000), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].INIT_SEGMENT_TYPE, 1000), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].BITSTREAM_SWITCHING_SEGMENT_TYPE, 1000), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].INDEX_SEGMENT_TYPE, 1000), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].MSS_FRAGMENT_INFO_SEGMENT_TYPE, 1000), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].LICENSE, 1000), _defineProperty(_retryIntervals, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].OTHER_TYPE, 1000), _defineProperty(_retryIntervals, "lowLatencyReductionFactor", 10), _retryIntervals),
retryAttempts: (_retryAttempts = {}, _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].MPD_TYPE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].XLINK_EXPANSION_TYPE, 1), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].MEDIA_SEGMENT_TYPE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].INIT_SEGMENT_TYPE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].BITSTREAM_SWITCHING_SEGMENT_TYPE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].INDEX_SEGMENT_TYPE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].MSS_FRAGMENT_INFO_SEGMENT_TYPE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].LICENSE, 3), _defineProperty(_retryAttempts, _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_4__["HTTPRequest"].OTHER_TYPE, 3), _defineProperty(_retryAttempts, "lowLatencyMultiplyFactor", 5), _retryAttempts),
abr: {
movingAverageMethod: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].MOVING_AVERAGE_SLIDING_WINDOW,
ABRStrategy: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].ABR_STRATEGY_DYNAMIC,
additionalAbrRules: {
insufficientBufferRule: true,
switchHistoryRule: true,
droppedFramesRule: true,
abandonRequestsRule: false
},
bandwidthSafetyFactor: 0.9,
useDefaultABRRules: true,
useDeadTimeLatency: true,
limitBitrateByPortal: false,
usePixelRatioInLimitBitrateByPortal: false,
maxBitrate: {
audio: -1,
video: -1
},
minBitrate: {
audio: -1,
video: -1
},
maxRepresentationRatio: {
audio: 1,
video: 1
},
initialBitrate: {
audio: -1,
video: -1
},
initialRepresentationRatio: {
audio: -1,
video: -1
},
autoSwitchBitrate: {
audio: true,
video: true
},
fetchThroughputCalculationMode: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING
},
cmcd: {
enabled: false,
sid: null,
cid: null,
rtp: null,
rtpSafetyFactor: 5,
mode: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].CMCD_MODE_QUERY
}
},
errors: {
recoverAttempts: {
mediaErrorDecode: 5
}
}
};
var settings = _Utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].clone(defaultSettings); //Merge in the settings. If something exists in the new config that doesn't match the schema of the default config,
//regard it as an error and log it.
function mixinSettings(source, dest, path) {
for (var n in source) {
if (source.hasOwnProperty(n)) {
if (dest.hasOwnProperty(n)) {
if (_typeof(source[n]) === 'object' && source[n] !== null) {
mixinSettings(source[n], dest[n], path.slice() + n + '.');
} else {
dest[n] = _Utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].clone(source[n]);
}
}
}
}
}
/**
* Return the settings object. Don't copy/store this object, you won't get updates.
* @func
* @instance
*/
function get() {
return settings;
}
/**
* @func
* @instance
* @param {object} settingsObj - This should be a partial object of the Settings.Schema type. That is, fields defined should match the path (e.g.
* settingsObj.streaming.abr.autoSwitchBitrate.audio -> defaultSettings.streaming.abr.autoSwitchBitrate.audio). Where an element's path does
* not match it is ignored, and a warning is logged.
*
* Use to change the settings object. Any new values defined will overwrite the settings and anything undefined will not change.
* Implementers of new settings should add it in an approriate namespace to the defaultSettings object and give it a default value (that is not undefined).
*
*/
function update(settingsObj) {
if (_typeof(settingsObj) === 'object') {
mixinSettings(settingsObj, settings, '');
}
}
/**
* Resets the settings object. Everything is set to its default value.
* @func
* @instance
*
*/
function reset() {
settings = _Utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].clone(defaultSettings);
}
instance = {
get: get,
update: update,
reset: reset
};
return instance;
}
Settings.__dashjs_factory_name = 'Settings';
var factory = _FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(Settings);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/core/Utils.js":
/*!***************************!*\
!*** ./src/core/Utils.js ***!
\***************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var path_browserify__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! path-browserify */ "./node_modules/path-browserify/index.js");
/* harmony import */ var path_browserify__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path_browserify__WEBPACK_IMPORTED_MODULE_0__);
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Utils = /*#__PURE__*/function () {
function Utils() {
_classCallCheck(this, Utils);
}
_createClass(Utils, null, [{
key: "mixin",
value: function mixin(dest, source, copy) {
var s;
var empty = {};
if (dest) {
for (var name in source) {
if (source.hasOwnProperty(name)) {
s = source[name];
if (!(name in dest) || dest[name] !== s && (!(name in empty) || empty[name] !== s)) {
if (_typeof(dest[name]) === 'object' && dest[name] !== null) {
dest[name] = Utils.mixin(dest[name], s, copy);
} else {
dest[name] = copy(s);
}
}
}
}
}
return dest;
}
}, {
key: "clone",
value: function clone(src) {
if (!src || _typeof(src) !== 'object') {
return src; // anything
}
var r;
if (src instanceof Array) {
// array
r = [];
for (var i = 0, l = src.length; i < l; ++i) {
if (i in src) {
r.push(Utils.clone(src[i]));
}
}
} else {
r = {};
}
return Utils.mixin(r, src, Utils.clone);
}
}, {
key: "addAditionalQueryParameterToUrl",
value: function addAditionalQueryParameterToUrl(url, params) {
try {
if (!params || params.length === 0) {
return url;
}
var modifiedUrl = new URL(url);
params.forEach(function (param) {
if (param.key && param.value) {
modifiedUrl.searchParams.set(param.key, param.value);
}
});
return modifiedUrl.href;
} catch (e) {
return url;
}
}
}, {
key: "parseHttpHeaders",
value: function parseHttpHeaders(headerStr) {
var headers = {};
if (!headerStr) {
return headers;
} // Trim headerStr to fix a MS Edge bug with xhr.getAllResponseHeaders method
// which send a string starting with a "\n" character
var headerPairs = headerStr.trim().split("\r\n");
for (var i = 0, ilen = headerPairs.length; i < ilen; i++) {
var headerPair = headerPairs[i];
var index = headerPair.indexOf(": ");
if (index > 0) {
headers[headerPair.substring(0, index)] = headerPair.substring(index + 2);
}
}
return headers;
}
}, {
key: "generateUuid",
value: function generateUuid() {
var dt = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);
});
return uuid;
}
}, {
key: "generateHashCode",
value: function generateHashCode(string) {
var hash = 0;
if (string.length === 0) {
return hash;
}
for (var i = 0; i < string.length; i++) {
var chr = string.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0;
}
return hash;
}
/**
* Compares both urls and returns a relative url (target relative to original)
* @param {string} original
* @param {string} target
* @return {string|*}
*/
}, {
key: "getRelativeUrl",
value: function getRelativeUrl(originalUrl, targetUrl) {
try {
var original = new URL(originalUrl);
var target = new URL(targetUrl); // Unify the protocol to compare the origins
original.protocol = target.protocol;
if (original.origin !== target.origin) {
return targetUrl;
} // Use the relative path implementation of the path library. We need to cut off the actual filename in the end to get the relative path
var relativePath = path_browserify__WEBPACK_IMPORTED_MODULE_0___default.a.relative(original.pathname.substr(0, original.pathname.lastIndexOf('/')), target.pathname.substr(0, target.pathname.lastIndexOf('/'))); // In case the relative path is empty (both path are equal) return the filename only. Otherwise add a slash in front of the filename
var startIndexOffset = relativePath.length === 0 ? 1 : 0;
relativePath += target.pathname.substr(target.pathname.lastIndexOf('/') + startIndexOffset, target.pathname.length - 1); // Build the other candidate, e.g. the 'host relative' path that starts with "/", and return the shortest of the two candidates.
if (target.pathname.length < relativePath.length) {
return target.pathname;
}
return relativePath;
} catch (e) {
return targetUrl;
}
}
}]);
return Utils;
}();
/* harmony default export */ __webpack_exports__["default"] = (Utils);
/***/ }),
/***/ "./src/core/Version.js":
/*!*****************************!*\
!*** ./src/core/Version.js ***!
\*****************************/
/*! exports provided: getVersionString */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVersionString", function() { return getVersionString; });
var VERSION = '4.2.0';
function getVersionString() {
return VERSION;
}
/***/ }),
/***/ "./src/core/errors/Errors.js":
/*!***********************************!*\
!*** ./src/core/errors/Errors.js ***!
\***********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _ErrorsBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ErrorsBase */ "./src/core/errors/ErrorsBase.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Errors declaration
* @class
*/
var Errors = /*#__PURE__*/function (_ErrorsBase) {
_inherits(Errors, _ErrorsBase);
var _super = _createSuper(Errors);
function Errors() {
var _this;
_classCallCheck(this, Errors);
_this = _super.call(this);
/**
* Error code returned when a manifest parsing error occurs
*/
_this.MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE = 10;
/**
* Error code returned when a manifest loading error occurs
*/
_this.MANIFEST_LOADER_LOADING_FAILURE_ERROR_CODE = 11;
/**
* Error code returned when a xlink loading error occurs
*/
_this.XLINK_LOADER_LOADING_FAILURE_ERROR_CODE = 12;
/**
* Error code returned when no segment ranges could be determined from the sidx box
*/
_this.SEGMENT_BASE_LOADER_ERROR_CODE = 15;
/**
* Error code returned when the time synchronization failed
*/
_this.TIME_SYNC_FAILED_ERROR_CODE = 16;
/**
* Error code returned when loading a fragment failed
*/
_this.FRAGMENT_LOADER_LOADING_FAILURE_ERROR_CODE = 17;
/**
* Error code returned when the FragmentLoader did not receive a request object
*/
_this.FRAGMENT_LOADER_NULL_REQUEST_ERROR_CODE = 18;
/**
* Error code returned when the BaseUrl resolution failed
*/
_this.URL_RESOLUTION_FAILED_GENERIC_ERROR_CODE = 19;
/**
* Error code returned when the append operation in the SourceBuffer failed
*/
_this.APPEND_ERROR_CODE = 20;
/**
* Error code returned when the remove operation in the SourceBuffer failed
*/
_this.REMOVE_ERROR_CODE = 21;
/**
* Error code returned when updating the internal objects after loading an MPD failed
*/
_this.DATA_UPDATE_FAILED_ERROR_CODE = 22;
/**
* Error code returned when MediaSource is not supported by the browser
*/
_this.CAPABILITY_MEDIASOURCE_ERROR_CODE = 23;
/**
* Error code returned when Protected contents are not supported
*/
_this.CAPABILITY_MEDIAKEYS_ERROR_CODE = 24;
/**
* Error code returned when loading the manifest failed
*/
_this.DOWNLOAD_ERROR_ID_MANIFEST_CODE = 25;
/**
* Error code returned when loading the sidx failed
*/
_this.DOWNLOAD_ERROR_ID_SIDX_CODE = 26;
/**
* Error code returned when loading the media content failed
*/
_this.DOWNLOAD_ERROR_ID_CONTENT_CODE = 27;
/**
* Error code returned when loading the init segment failed
*/
_this.DOWNLOAD_ERROR_ID_INITIALIZATION_CODE = 28;
/**
* Error code returned when loading the XLink content failed
*/
_this.DOWNLOAD_ERROR_ID_XLINK_CODE = 29;
/**
* Error code returned when parsing the MPD resulted in a logical error
*/
_this.MANIFEST_ERROR_ID_PARSE_CODE = 31;
/**
* Error code returned when no stream (period) has been detected in the manifest
*/
_this.MANIFEST_ERROR_ID_NOSTREAMS_CODE = 32;
/**
* Error code returned when something wrong has happened during parsing and appending subtitles (TTML or VTT)
*/
_this.TIMED_TEXT_ERROR_ID_PARSE_CODE = 33;
/**
* Error code returned when a 'muxed' media type has been detected in the manifest. This type is not supported
*/
_this.MANIFEST_ERROR_ID_MULTIPLEXED_CODE = 34;
/**
* Error code returned when a media source type is not supported
*/
_this.MEDIASOURCE_TYPE_UNSUPPORTED_CODE = 35;
_this.MANIFEST_LOADER_PARSING_FAILURE_ERROR_MESSAGE = 'parsing failed for ';
_this.MANIFEST_LOADER_LOADING_FAILURE_ERROR_MESSAGE = 'Failed loading manifest: ';
_this.XLINK_LOADER_LOADING_FAILURE_ERROR_MESSAGE = 'Failed loading Xlink element: ';
_this.SEGMENTS_UPDATE_FAILED_ERROR_MESSAGE = 'Segments update failed';
_this.SEGMENTS_UNAVAILABLE_ERROR_MESSAGE = 'no segments are available yet';
_this.SEGMENT_BASE_LOADER_ERROR_MESSAGE = 'error loading segment ranges from sidx';
_this.TIME_SYNC_FAILED_ERROR_MESSAGE = 'Failed to synchronize client and server time';
_this.FRAGMENT_LOADER_NULL_REQUEST_ERROR_MESSAGE = 'request is null';
_this.URL_RESOLUTION_FAILED_GENERIC_ERROR_MESSAGE = 'Failed to resolve a valid URL';
_this.APPEND_ERROR_MESSAGE = 'chunk is not defined';
_this.REMOVE_ERROR_MESSAGE = 'Removing data from the SourceBuffer';
_this.DATA_UPDATE_FAILED_ERROR_MESSAGE = 'Data update failed';
_this.CAPABILITY_MEDIASOURCE_ERROR_MESSAGE = 'mediasource is not supported';
_this.CAPABILITY_MEDIAKEYS_ERROR_MESSAGE = 'mediakeys is not supported';
_this.TIMED_TEXT_ERROR_MESSAGE_PARSE = 'parsing error :';
_this.MEDIASOURCE_TYPE_UNSUPPORTED_MESSAGE = 'Error creating source buffer of type : ';
return _this;
}
return Errors;
}(_ErrorsBase__WEBPACK_IMPORTED_MODULE_0__["default"]);
var errors = new Errors();
/* harmony default export */ __webpack_exports__["default"] = (errors);
/***/ }),
/***/ "./src/core/errors/ErrorsBase.js":
/*!***************************************!*\
!*** ./src/core/errors/ErrorsBase.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var ErrorsBase = /*#__PURE__*/function () {
function ErrorsBase() {
_classCallCheck(this, ErrorsBase);
}
_createClass(ErrorsBase, [{
key: "extend",
value: function extend(errors, config) {
if (!errors) return;
var override = config ? config.override : false;
var publicOnly = config ? config.publicOnly : false;
for (var err in errors) {
if (!errors.hasOwnProperty(err) || this[err] && !override) continue;
if (publicOnly && errors[err].indexOf('public_') === -1) continue;
this[err] = errors[err];
}
}
}]);
return ErrorsBase;
}();
/* harmony default export */ __webpack_exports__["default"] = (ErrorsBase);
/***/ }),
/***/ "./src/core/events/CoreEvents.js":
/*!***************************************!*\
!*** ./src/core/events/CoreEvents.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _EventsBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EventsBase */ "./src/core/events/EventsBase.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* These are internal events that should not be needed at the player level.
* If you find and event in here that you would like access to from MediaPlayer level
* please add an issue at https://github.com/Dash-Industry-Forum/dash.js/issues/new
* @class
* @ignore
*/
var CoreEvents = /*#__PURE__*/function (_EventsBase) {
_inherits(CoreEvents, _EventsBase);
var _super = _createSuper(CoreEvents);
function CoreEvents() {
var _this;
_classCallCheck(this, CoreEvents);
_this = _super.call(this);
_this.ATTEMPT_BACKGROUND_SYNC = 'attemptBackgroundSync';
_this.BUFFERING_COMPLETED = 'bufferingCompleted';
_this.BUFFER_CLEARED = 'bufferCleared';
_this.BYTES_APPENDED_END_FRAGMENT = 'bytesAppendedEndFragment';
_this.BUFFER_REPLACEMENT_STARTED = 'bufferReplacementStarted';
_this.CHECK_FOR_EXISTENCE_COMPLETED = 'checkForExistenceCompleted';
_this.CURRENT_TRACK_CHANGED = 'currentTrackChanged';
_this.DATA_UPDATE_COMPLETED = 'dataUpdateCompleted';
_this.INBAND_EVENTS = 'inbandEvents';
_this.INITIAL_STREAM_SWITCH = 'initialStreamSwitch';
_this.INIT_FRAGMENT_LOADED = 'initFragmentLoaded';
_this.INIT_FRAGMENT_NEEDED = 'initFragmentNeeded';
_this.INTERNAL_MANIFEST_LOADED = 'internalManifestLoaded';
_this.ORIGINAL_MANIFEST_LOADED = 'originalManifestLoaded';
_this.LOADING_COMPLETED = 'loadingCompleted';
_this.LOADING_PROGRESS = 'loadingProgress';
_this.LOADING_DATA_PROGRESS = 'loadingDataProgress';
_this.LOADING_ABANDONED = 'loadingAborted';
_this.MANIFEST_UPDATED = 'manifestUpdated';
_this.MEDIA_FRAGMENT_LOADED = 'mediaFragmentLoaded';
_this.MEDIA_FRAGMENT_NEEDED = 'mediaFragmentNeeded';
_this.QUOTA_EXCEEDED = 'quotaExceeded';
_this.SEGMENT_LOCATION_BLACKLIST_ADD = 'segmentLocationBlacklistAdd';
_this.SEGMENT_LOCATION_BLACKLIST_CHANGED = 'segmentLocationBlacklistChanged';
_this.SERVICE_LOCATION_BLACKLIST_ADD = 'serviceLocationBlacklistAdd';
_this.SERVICE_LOCATION_BLACKLIST_CHANGED = 'serviceLocationBlacklistChanged';
_this.SET_FRAGMENTED_TEXT_AFTER_DISABLED = 'setFragmentedTextAfterDisabled';
_this.SET_NON_FRAGMENTED_TEXT = 'setNonFragmentedText';
_this.SOURCE_BUFFER_ERROR = 'sourceBufferError';
_this.STREAMS_COMPOSED = 'streamsComposed';
_this.STREAM_BUFFERING_COMPLETED = 'streamBufferingCompleted';
_this.STREAM_REQUESTING_COMPLETED = 'streamRequestingCompleted';
_this.TEXT_TRACKS_QUEUE_INITIALIZED = 'textTracksQueueInitialized';
_this.TIME_SYNCHRONIZATION_COMPLETED = 'timeSynchronizationComplete';
_this.UPDATE_TIME_SYNC_OFFSET = 'updateTimeSyncOffset';
_this.URL_RESOLUTION_FAILED = 'urlResolutionFailed';
_this.VIDEO_CHUNK_RECEIVED = 'videoChunkReceived';
_this.WALLCLOCK_TIME_UPDATED = 'wallclockTimeUpdated';
_this.XLINK_ELEMENT_LOADED = 'xlinkElementLoaded';
_this.XLINK_READY = 'xlinkReady';
_this.SEEK_TARGET = 'seekTarget';
return _this;
}
return CoreEvents;
}(_EventsBase__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (CoreEvents);
/***/ }),
/***/ "./src/core/events/Events.js":
/*!***********************************!*\
!*** ./src/core/events/Events.js ***!
\***********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _CoreEvents__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./CoreEvents */ "./src/core/events/CoreEvents.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Events = /*#__PURE__*/function (_CoreEvents) {
_inherits(Events, _CoreEvents);
var _super = _createSuper(Events);
function Events() {
_classCallCheck(this, Events);
return _super.apply(this, arguments);
}
return Events;
}(_CoreEvents__WEBPACK_IMPORTED_MODULE_0__["default"]);
var events = new Events();
/* harmony default export */ __webpack_exports__["default"] = (events);
/***/ }),
/***/ "./src/core/events/EventsBase.js":
/*!***************************************!*\
!*** ./src/core/events/EventsBase.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var EventsBase = /*#__PURE__*/function () {
function EventsBase() {
_classCallCheck(this, EventsBase);
}
_createClass(EventsBase, [{
key: "extend",
value: function extend(events, config) {
if (!events) return;
var override = config ? config.override : false;
var publicOnly = config ? config.publicOnly : false;
for (var evt in events) {
if (!events.hasOwnProperty(evt) || this[evt] && !override) continue;
if (publicOnly && events[evt].indexOf('public_') === -1) continue;
this[evt] = events[evt];
}
}
}]);
return EventsBase;
}();
/* harmony default export */ __webpack_exports__["default"] = (EventsBase);
/***/ }),
/***/ "./src/dash/DashAdapter.js":
/*!*********************************!*\
!*** ./src/dash/DashAdapter.js ***!
\*********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _vo_RepresentationInfo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./vo/RepresentationInfo */ "./src/dash/vo/RepresentationInfo.js");
/* harmony import */ var _vo_MediaInfo__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./vo/MediaInfo */ "./src/dash/vo/MediaInfo.js");
/* harmony import */ var _vo_StreamInfo__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./vo/StreamInfo */ "./src/dash/vo/StreamInfo.js");
/* harmony import */ var _vo_ManifestInfo__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./vo/ManifestInfo */ "./src/dash/vo/ManifestInfo.js");
/* harmony import */ var _vo_Event__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./vo/Event */ "./src/dash/vo/Event.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _models_DashManifestModel__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./models/DashManifestModel */ "./src/dash/models/DashManifestModel.js");
/* harmony import */ var _models_PatchManifestModel__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./models/PatchManifestModel */ "./src/dash/models/PatchManifestModel.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module DashAdapter
* @description The DashAdapter module can be accessed using the MediaPlayer API getDashAdapter()
*/
function DashAdapter() {
var instance, dashManifestModel, patchManifestModel, voPeriods, currentMediaInfo, constants, cea608parser;
var context = this.context;
var PROFILE_DVB = 'urn:dvb:dash:profile:dvb-dash:2014';
function setup() {
dashManifestModel = Object(_models_DashManifestModel__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
patchManifestModel = Object(_models_PatchManifestModel__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
reset();
} // #region PUBLIC FUNCTIONS
// --------------------------------------------------
function setConfig(config) {
if (!config) return;
if (config.constants) {
constants = config.constants;
}
if (config.cea608parser) {
cea608parser = config.cea608parser;
}
if (config.errHandler) {
dashManifestModel.setConfig({
errHandler: config.errHandler
});
}
if (config.BASE64) {
dashManifestModel.setConfig({
BASE64: config.BASE64
});
}
}
/**
* Creates an instance of RepresentationInfo based on a representation value object
* @param {object} voRepresentation
* @returns {RepresentationInfo|null} representationInfo
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function convertRepresentationToRepresentationInfo(voRepresentation) {
if (voRepresentation) {
var representationInfo = new _vo_RepresentationInfo__WEBPACK_IMPORTED_MODULE_1__["default"]();
var realAdaptation = voRepresentation.adaptation.period.mpd.manifest.Period_asArray[voRepresentation.adaptation.period.index].AdaptationSet_asArray[voRepresentation.adaptation.index];
var realRepresentation = dashManifestModel.getRepresentationFor(voRepresentation.index, realAdaptation);
representationInfo.id = voRepresentation.id;
representationInfo.quality = voRepresentation.index;
representationInfo.bandwidth = dashManifestModel.getBandwidth(realRepresentation);
representationInfo.fragmentDuration = voRepresentation.segmentDuration || (voRepresentation.segments && voRepresentation.segments.length > 0 ? voRepresentation.segments[0].duration : NaN);
representationInfo.MSETimeOffset = voRepresentation.MSETimeOffset;
representationInfo.mediaInfo = convertAdaptationToMediaInfo(voRepresentation.adaptation);
return representationInfo;
} else {
return null;
}
}
/**
* Returns a MediaInfo object for a given media type and the corresponding streamInfo.
* @param {object} streamInfo
* @param {MediaType }type
* @returns {null|MediaInfo} mediaInfo
* @memberOf module:DashAdapter
* @instance
*/
function getMediaInfoForType(streamInfo, type) {
if (voPeriods.length === 0 || !streamInfo) {
return null;
}
var selectedVoPeriod = getPeriodForStreamInfo(streamInfo, voPeriods);
if (!selectedVoPeriod) return null;
var voAdaptations = dashManifestModel.getAdaptationsForPeriod(selectedVoPeriod);
var realAdaptation = getAdaptationForType(streamInfo.index, type, streamInfo);
if (!realAdaptation) return null;
var idx = dashManifestModel.getIndexForAdaptation(realAdaptation, voPeriods[0].mpd.manifest, streamInfo.index);
return convertAdaptationToMediaInfo(voAdaptations[idx]);
}
/**
* Checks if the role of the specified AdaptationSet is set to main
* @param {object} adaptation
* @returns {boolean}
* @memberOf module:DashAdapter
* @instance
*/
function getIsMain(adaptation) {
return dashManifestModel.getRolesForAdaptation(adaptation).filter(function (role) {
return role.value === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].MAIN;
})[0];
}
/**
* Returns the AdaptationSet for a given period index and a given mediaType.
* @param {number} periodIndex
* @param {MediaType} type
* @param {object} streamInfo
* @returns {null|object} adaptation
* @memberOf module:DashAdapter
* @instance
*/
function getAdaptationForType(periodIndex, type, streamInfo) {
var adaptations = dashManifestModel.getAdaptationsForType(voPeriods[0].mpd.manifest, periodIndex, type);
if (!adaptations || adaptations.length === 0) return null;
if (adaptations.length > 1 && streamInfo) {
var allMediaInfoForType = getAllMediaInfoForType(streamInfo, type);
if (currentMediaInfo[streamInfo.id] && currentMediaInfo[streamInfo.id][type]) {
for (var i = 0, ln = adaptations.length; i < ln; i++) {
if (areMediaInfosEqual(currentMediaInfo[streamInfo.id][type], allMediaInfoForType[i])) {
return adaptations[i];
}
}
}
for (var _i = 0, _ln = adaptations.length; _i < _ln; _i++) {
if (getIsMain(adaptations[_i])) {
return adaptations[_i];
}
}
}
return adaptations[0];
}
/**
* Compares two mediaInfo objects
* @param {MediaInfo} mInfoOne
* @param {MediaInfo} mInfoTwo
* @returns {boolean}
*/
function areMediaInfosEqual(mInfoOne, mInfoTwo) {
if (!mInfoOne || !mInfoTwo) {
return false;
}
var sameId = mInfoOne.id === mInfoTwo.id;
var sameCodec = mInfoOne.codec === mInfoTwo.codec;
var sameViewpoint = mInfoOne.viewpoint === mInfoTwo.viewpoint;
var sameLang = mInfoOne.lang === mInfoTwo.lang;
var sameRoles = mInfoOne.roles.toString() === mInfoTwo.roles.toString();
var sameAccessibility = mInfoOne.accessibility.toString() === mInfoTwo.accessibility.toString();
var sameAudioChannelConfiguration = mInfoOne.audioChannelConfiguration.toString() === mInfoTwo.audioChannelConfiguration.toString();
return sameId && sameCodec && sameViewpoint && sameLang && sameRoles && sameAccessibility && sameAudioChannelConfiguration;
}
function _getAllMediaInfo(manifest, period, streamInfo, adaptations, type, embeddedText) {
var mediaArr = [];
var data, media, idx, i, j, ln;
if (!adaptations || adaptations.length === 0) {
return [];
}
var voAdaptations = dashManifestModel.getAdaptationsForPeriod(period);
for (i = 0, ln = adaptations.length; i < ln; i++) {
data = adaptations[i];
idx = dashManifestModel.getIndexForAdaptation(data, manifest, streamInfo.index);
media = convertAdaptationToMediaInfo(voAdaptations[idx]);
if (embeddedText) {
var accessibilityLength = media.accessibility.length;
for (j = 0; j < accessibilityLength; j++) {
if (!media) {
continue;
}
var accessibility = media.accessibility[j];
if (accessibility.indexOf('cea-608:') === 0) {
var value = accessibility.substring(8);
var parts = value.split(';');
if (parts[0].substring(0, 2) === 'CC') {
for (j = 0; j < parts.length; j++) {
if (!media) {
media = convertAdaptationToMediaInfo.call(this, voAdaptations[idx]);
}
convertVideoInfoToEmbeddedTextInfo(media, parts[j].substring(0, 3), parts[j].substring(4));
mediaArr.push(media);
media = null;
}
} else {
for (j = 0; j < parts.length; j++) {
// Only languages for CC1, CC2, ...
if (!media) {
media = convertAdaptationToMediaInfo.call(this, voAdaptations[idx]);
}
convertVideoInfoToEmbeddedTextInfo(media, 'CC' + (j + 1), parts[j]);
mediaArr.push(media);
media = null;
}
}
} else if (accessibility.indexOf('cea-608') === 0) {
// Nothing known. We interpret it as CC1=eng
convertVideoInfoToEmbeddedTextInfo(media, constants.CC1, 'eng');
mediaArr.push(media);
media = null;
}
}
} else if (type === constants.IMAGE) {
convertVideoInfoToThumbnailInfo(media);
mediaArr.push(media);
media = null;
} else if (media) {
mediaArr.push(media);
}
}
return mediaArr;
}
/**
* Returns all the mediaInfos for a given mediaType and the corresponding streamInfo.
* @param {object} streamInfo
* @param {MediaType} type
* @param {object} externalManifest Set to null or undefined if no external manifest is to be used
* @returns {Array} mediaArr
* @memberOf module:DashAdapter
* @instance
*/
function getAllMediaInfoForType(streamInfo, type, externalManifest) {
var voLocalPeriods = voPeriods;
var manifest = externalManifest;
var mediaArr = [];
if (manifest) {
checkConfig();
voLocalPeriods = getRegularPeriods(manifest);
} else {
if (voPeriods.length > 0) {
manifest = voPeriods[0].mpd.manifest;
} else {
return mediaArr;
}
}
var selectedVoPeriod = getPeriodForStreamInfo(streamInfo, voLocalPeriods);
var adaptationsForType = dashManifestModel.getAdaptationsForType(manifest, streamInfo ? streamInfo.index : null, type);
mediaArr = _getAllMediaInfo(manifest, selectedVoPeriod, streamInfo, adaptationsForType, type); // Search for embedded text in video track
if (type === constants.TEXT) {
adaptationsForType = dashManifestModel.getAdaptationsForType(manifest, streamInfo ? streamInfo.index : null, constants.VIDEO);
mediaArr = mediaArr.concat(_getAllMediaInfo(manifest, selectedVoPeriod, streamInfo, adaptationsForType, type, true));
}
return mediaArr;
}
/**
* Update the internal voPeriods array with the information from the new manifest
* @param {object} newManifest
* @returns {*}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function updatePeriods(newManifest) {
if (!newManifest) return null;
checkConfig();
voPeriods = getRegularPeriods(newManifest);
}
/**
* Returns an array of streamInfo objects
* @param {object} externalManifest
* @param {number} maxStreamsInfo
* @returns {Array} streams
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getStreamsInfo(externalManifest, maxStreamsInfo) {
var streams = [];
var voLocalPeriods = voPeriods; //if manifest is defined, getStreamsInfo is for an outside manifest, not the current one
if (externalManifest) {
checkConfig();
voLocalPeriods = getRegularPeriods(externalManifest);
}
if (voLocalPeriods.length > 0) {
if (!maxStreamsInfo || maxStreamsInfo > voLocalPeriods.length) {
maxStreamsInfo = voLocalPeriods.length;
}
for (var i = 0; i < maxStreamsInfo; i++) {
streams.push(convertPeriodToStreamInfo(voLocalPeriods[i]));
}
}
return streams;
}
/**
* Returns the AdaptationSet as saved in the DashManifestModel
* @param {object} streamInfo
* @param {object} mediaInfo
* @returns {object} realAdaptation
* @memberOf module:DashAdapter
* @instance
*/
function getRealAdaptation(streamInfo, mediaInfo) {
var id, realAdaptation;
var selectedVoPeriod = getPeriodForStreamInfo(streamInfo, voPeriods);
id = mediaInfo ? mediaInfo.id : null;
if (voPeriods.length > 0 && selectedVoPeriod) {
realAdaptation = id ? dashManifestModel.getAdaptationForId(id, voPeriods[0].mpd.manifest, selectedVoPeriod.index) : dashManifestModel.getAdaptationForIndex(mediaInfo ? mediaInfo.index : null, voPeriods[0].mpd.manifest, selectedVoPeriod.index);
}
return realAdaptation;
}
/**
* Return all EssentialProperties of a Representation
* @param {object} representation
* @return {array}
*/
function getEssentialPropertiesForRepresentation(representation) {
try {
return dashManifestModel.getEssentialPropertiesForRepresentation(representation);
} catch (e) {
return [];
}
}
/**
* Returns the period as defined in the DashManifestModel for a given index
* @param {number} index
* @return {object}
*/
function getRealPeriodByIndex(index) {
return dashManifestModel.getRealPeriodForIndex(index, voPeriods[0].mpd.manifest);
}
/**
* Returns all voRepresentations for a given mediaInfo
* @param {object} mediaInfo
* @returns {Array} voReps
* @memberOf module:DashAdapter
* @instance
*/
function getVoRepresentations(mediaInfo) {
var voReps;
var voAdaptation = getAdaptationForMediaInfo(mediaInfo);
voReps = dashManifestModel.getRepresentationsForAdaptation(voAdaptation);
return voReps;
}
/**
* Returns the event for the given parameters.
* @param {object} eventBox
* @param {object} eventStreams
* @param {number} mediaStartTime
* @param {object} voRepresentation
* @returns {null|Event}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getEvent(eventBox, eventStreams, mediaStartTime, voRepresentation) {
try {
if (!eventBox || !eventStreams || isNaN(mediaStartTime) || !voRepresentation) {
return null;
}
var schemeIdUri = eventBox.scheme_id_uri;
var value = eventBox.value;
if (!eventStreams[schemeIdUri + '/' + value]) {
return null;
}
var event = new _vo_Event__WEBPACK_IMPORTED_MODULE_5__["default"]();
var timescale = eventBox.timescale || 1;
var periodStart = voRepresentation.adaptation.period.start;
var eventStream = eventStreams[schemeIdUri + '/' + value];
var presentationTimeOffset = !isNaN(voRepresentation.presentationTimeOffset) ? voRepresentation.presentationTimeOffset : !isNaN(eventStream.presentationTimeOffset) ? eventStream.presentationTimeOffset : 0;
var presentationTimeDelta = eventBox.presentation_time_delta / timescale; // In case of version 1 events the presentation_time is parsed as presentation_time_delta
var calculatedPresentationTime;
if (eventBox.version === 0) {
calculatedPresentationTime = periodStart + mediaStartTime - presentationTimeOffset + presentationTimeDelta;
} else {
calculatedPresentationTime = periodStart - presentationTimeOffset + presentationTimeDelta;
}
var duration = eventBox.event_duration;
var id = eventBox.id;
var messageData = eventBox.message_data;
event.eventStream = eventStream;
event.eventStream.value = value;
event.eventStream.timescale = timescale;
event.duration = duration;
event.id = id;
event.calculatedPresentationTime = calculatedPresentationTime;
event.messageData = messageData;
event.presentationTimeDelta = presentationTimeDelta;
return event;
} catch (e) {
return null;
}
}
/**
* Returns the events for the given info object. info can either be an instance of StreamInfo, MediaInfo or RepresentationInfo
* @param {object} info
* @param {object} voRepresentation
* @returns {Array}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getEventsFor(info, voRepresentation) {
var events = [];
if (voPeriods.length > 0) {
var manifest = voPeriods[0].mpd.manifest;
if (info instanceof _vo_StreamInfo__WEBPACK_IMPORTED_MODULE_3__["default"]) {
events = dashManifestModel.getEventsForPeriod(getPeriodForStreamInfo(info, voPeriods));
} else if (info instanceof _vo_MediaInfo__WEBPACK_IMPORTED_MODULE_2__["default"]) {
events = dashManifestModel.getEventStreamForAdaptationSet(manifest, getAdaptationForMediaInfo(info));
} else if (info instanceof _vo_RepresentationInfo__WEBPACK_IMPORTED_MODULE_1__["default"]) {
events = dashManifestModel.getEventStreamForRepresentation(manifest, voRepresentation);
}
}
return events;
}
/**
* Sets the current active mediaInfo for a given streamId and a given mediaType
* @param {number} streamId
* @param {MediaType} type
* @param {object} mediaInfo
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function setCurrentMediaInfo(streamId, type, mediaInfo) {
currentMediaInfo[streamId] = currentMediaInfo[streamId] || {};
currentMediaInfo[streamId][type] = currentMediaInfo[streamId][type] || {};
currentMediaInfo[streamId][type] = mediaInfo;
}
/**
* Check if the given type is a text track
* @param {object} adaptation
* @returns {boolean}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getIsTextTrack(adaptation) {
return dashManifestModel.getIsText(adaptation);
}
/**
* Returns the UTC Timing Sources specified in the manifest
* @returns {Array} utcTimingSources
* @memberOf module:DashAdapter
* @instance
*/
function getUTCTimingSources() {
var manifest = getManifest();
return dashManifestModel.getUTCTimingSources(manifest);
}
/**
* Returns the suggestedPresentationDelay as specified in the manifest
* @returns {String} suggestedPresentationDelay
* @memberOf module:DashAdapter
* @instance
*/
function getSuggestedPresentationDelay() {
var mpd = voPeriods.length > 0 ? voPeriods[0].mpd : null;
return dashManifestModel.getSuggestedPresentationDelay(mpd);
}
/**
* Returns the availabilityStartTime as specified in the manifest
* @param {object} externalManifest Omit this value if no external manifest should be used
* @returns {string} availabilityStartTime
* @memberOf module:DashAdapter
* @instance
*/
function getAvailabilityStartTime(externalManifest) {
var mpd = getMpd(externalManifest);
return dashManifestModel.getAvailabilityStartTime(mpd);
}
/**
* Returns a boolean indicating if the manifest is dynamic or not
* @param {object} externalManifest Omit this value if no external manifest should be used
* @returns {boolean}
* @memberOf module:DashAdapter
* @instance
*/
function getIsDynamic(externalManifest) {
var manifest = getManifest(externalManifest);
return dashManifestModel.getIsDynamic(manifest);
}
/**
* Returns the duration of the MPD
* @param {object} externalManifest Omit this value if no external manifest should be used
* @returns {number} duration
* @memberOf module:DashAdapter
* @instance
*/
function getDuration(externalManifest) {
var manifest = getManifest(externalManifest);
return dashManifestModel.getDuration(manifest);
}
/**
* Returns all periods of the MPD
* @param {object} externalManifest Omit this value if no external manifest should be used
* @returns {Array} periods
* @memberOf module:DashAdapter
* @instance
*/
function getRegularPeriods(externalManifest) {
var mpd = getMpd(externalManifest);
return dashManifestModel.getRegularPeriods(mpd);
}
/**
* Returns an MPD object
* @param {object} externalManifest Omit this value if no external manifest should be used
* @returns {object} MPD
* @memberOf module:DashAdapter
* @instance
*/
function getMpd(externalManifest) {
var manifest = getManifest(externalManifest);
return dashManifestModel.getMpd(manifest);
}
/**
* Returns the location element of the MPD
* @param {object} manifest
* @returns {String} location
* @memberOf module:DashAdapter
* @instance
*/
function getLocation(manifest) {
return dashManifestModel.getLocation(manifest);
}
/**
* Returns the manifest update period used for dynamic manifests
* @param {object} manifest
* @param {number} latencyOfLastUpdate
* @returns {NaN|number} manifestUpdatePeriod
* @memberOf module:DashAdapter
* @instance
*/
function getManifestUpdatePeriod(manifest) {
var latencyOfLastUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
return dashManifestModel.getManifestUpdatePeriod(manifest, latencyOfLastUpdate);
}
/**
* Returns the publish time from the manifest
* @param {object} manifest
* @returns {Date|null} publishTime
* @memberOf module:DashAdapter
* @instance
*/
function getPublishTime(manifest) {
return dashManifestModel.getPublishTime(manifest);
}
/**
* Returns the patch location of the MPD if one exists and it is still valid
* @param {object} manifest
* @returns {(String|null)} patch location
* @memberOf module:DashAdapter
* @instance
*/
function getPatchLocation(manifest) {
var patchLocation = dashManifestModel.getPatchLocation(manifest);
var publishTime = dashManifestModel.getPublishTime(manifest); // short-circuit when no patch location or publish time exists
if (!patchLocation || !publishTime) {
return null;
} // if a ttl is provided, ensure patch location has not expired
if (patchLocation.hasOwnProperty('ttl') && publishTime) {
// attribute describes number of seconds as a double
var ttl = parseFloat(patchLocation.ttl) * 1000; // check if the patch location has expired, if so do not consider it
if (publishTime.getTime() + ttl <= new Date().getTime()) {
return null;
}
} // the patch location exists and, if a ttl applies, has not expired
return patchLocation.__text;
}
/**
* Checks if the manifest has a DVB profile
* @param {object} manifest
* @returns {boolean}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getIsDVB(manifest) {
return dashManifestModel.hasProfile(manifest, PROFILE_DVB);
}
/**
* Checks if the manifest is actually just a patch manifest
* @param {object} manifest
* @return {boolean}
*/
function getIsPatch(manifest) {
return patchManifestModel.getIsPatch(manifest);
}
/**
* Returns the base urls for a given element
* @param {object} node
* @returns {Array}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getBaseURLsFromElement(node) {
return dashManifestModel.getBaseURLsFromElement(node);
}
/**
* Returns the function to sort the Representations
* @returns {*}
* @memberOf module:DashAdapter
* @instance
* @ignore
*/
function getRepresentationSortFunction() {
return dashManifestModel.getRepresentationSortFunction();
}
/**
* Returns the codec for a given adaptation set and a given representation id.
* @param {object} adaptation
* @param {number} representationId
* @param {boolean} addResolutionInfo Defines whether to include resolution information in the output
* @returns {String} codec
* @memberOf module:DashAdapter
* @instance
*/
function getCodec(adaptation, representationId, addResolutionInfo) {
return dashManifestModel.getCodec(adaptation, representationId, addResolutionInfo);
}
/**
* Returns the bandwidth for a given representation id and the corresponding period index
* @param {number} representationId
* @param {number} periodIdx
* @returns {number} bandwidth
* @memberOf module:DashAdapter
* @instance
*/
function getBandwidthForRepresentation(representationId, periodIdx) {
var representation;
var period = getPeriod(periodIdx);
representation = findRepresentation(period, representationId);
return representation ? representation.bandwidth : null;
}
/**
* Returns the index for a given representation id
* @param {string} representationId
* @param {number} periodIdx
* @returns {number} index
* @memberOf module:DashAdapter
* @instance
*/
function getIndexForRepresentation(representationId, periodIdx) {
var period = getPeriod(periodIdx);
return findRepresentationIndex(period, representationId);
}
/**
* This method returns the current max index based on what is defined in the MPD.
* @param {string} bufferType - String 'audio' or 'video',
* @param {number} periodIdx - Make sure this is the period index not id
* @return {number}
* @memberof module:DashAdapter
* @instance
*/
function getMaxIndexForBufferType(bufferType, periodIdx) {
var period = getPeriod(periodIdx);
return findMaxBufferIndex(period, bufferType);
}
/**
* Returns the voPeriod object for a given id
* @param {String} id
* @returns {object|null}
*/
function getPeriodById(id) {
if (!id || voPeriods.length === 0) {
return null;
}
var periods = voPeriods.filter(function (p) {
return p.id === id;
});
if (periods && periods.length > 0) {
return periods[0];
}
return null;
}
/**
* Checks if the given AdaptationSet is from the given media type
* @param {object} adaptation
* @param {string} type
* @return {boolean}
*/
function getIsTypeOf(adaptation, type) {
return dashManifestModel.getIsTypeOf(adaptation, type);
}
function reset() {
voPeriods = [];
currentMediaInfo = {};
}
/**
* Checks if the supplied manifest is compatible for application of the supplied patch
* @param {object} manifest
* @param {object} patch
* @return {boolean}
*/
function isPatchValid(manifest, patch) {
var manifestId = dashManifestModel.getId(manifest);
var patchManifestId = patchManifestModel.getMpdId(patch);
var manifestPublishTime = dashManifestModel.getPublishTime(manifest);
var patchPublishTime = patchManifestModel.getPublishTime(patch);
var originalManifestPublishTime = patchManifestModel.getOriginalPublishTime(patch); // Patches are considered compatible if the following are true
// - MPD@id == Patch@mpdId
// - MPD@publishTime == Patch@originalPublishTime
// - MPD@publishTime < Patch@publishTime
// - All values in comparison exist
return !!(manifestId && patchManifestId && manifestId == patchManifestId && manifestPublishTime && originalManifestPublishTime && manifestPublishTime.getTime() == originalManifestPublishTime.getTime() && patchPublishTime && manifestPublishTime.getTime() < patchPublishTime.getTime());
}
/**
* Takes a given patch and applies it to the provided manifest, assumes patch is valid for manifest
* @param {object} manifest
* @param {object} patch
*/
function applyPatchToManifest(manifest, patch) {
// get all operations from the patch and apply them in document order
patchManifestModel.getPatchOperations(patch).forEach(function (operation) {
var result = operation.getMpdTarget(manifest); // operation supplies a path that doesn't match mpd, skip
if (result === null) {
return;
}
var name = result.name,
target = result.target,
leaf = result.leaf; // short circuit for attribute selectors
if (operation.xpath.findsAttribute()) {
switch (operation.action) {
case 'add':
case 'replace':
// add and replace are just setting the value
target[name] = operation.value;
break;
case 'remove':
// remove is deleting the value
delete target[name];
break;
}
return;
} // determine the relative insert position prior to possible removal
var relativePosition = (target[name + '_asArray'] || []).indexOf(leaf);
var insertBefore = operation.position === 'prepend' || operation.position === 'before'; // perform removal operation first, we have already capture the appropriate relative position
if (operation.action === 'remove' || operation.action === 'replace') {
// note that we ignore the 'ws' attribute of patch operations as it does not effect parsed mpd operations
// purge the directly named entity
delete target[name]; // if we did have a positional reference we need to purge from array set and restore X2JS proper semantics
if (relativePosition != -1) {
var targetArray = target[name + '_asArray'];
targetArray.splice(relativePosition, 1);
if (targetArray.length > 1) {
target[name] = targetArray;
} else if (targetArray.length == 1) {
// xml parsing semantics, singular asArray must be non-array in the unsuffixed key
target[name] = targetArray[0];
} else {
// all nodes of this type deleted, remove entry
delete target[name + '_asArray'];
}
}
} // Perform any add/replace operations now, technically RFC5261 only allows a single element to take the
// place of a replaced element while the add case allows an arbitrary number of children.
// Due to the both operations requiring the same insertion logic they have been combined here and we will
// not enforce single child operations for replace, assertions should be made at patch parse time if necessary
if (operation.action === 'add' || operation.action === 'replace') {
// value will be an object with element name keys pointing to arrays of objects
Object.keys(operation.value).forEach(function (insert) {
var insertNodes = operation.value[insert];
var updatedNodes = target[insert + '_asArray'] || [];
if (updatedNodes.length === 0 && target[insert]) {
updatedNodes.push(target[insert]);
}
if (updatedNodes.length === 0) {
// no original nodes for this element type
updatedNodes = insertNodes;
} else {
// compute the position we need to insert at, default to end of set
var position = updatedNodes.length;
if (insert == name && relativePosition != -1) {
// if the inserted element matches the operation target (not leaf) and there is a relative position we
// want the inserted position to be set such that our insertion is relative to original position
// since replace has modified the array length we reduce the insert point by 1
position = relativePosition + (insertBefore ? 0 : 1) + (operation.action == 'replace' ? -1 : 0);
} else {
// otherwise we are in an add append/prepend case or replace case that removed the target name completely
position = insertBefore ? 0 : updatedNodes.length;
} // we dont have to perform element removal for the replace case as that was done above
updatedNodes.splice.apply(updatedNodes, [position, 0].concat(insertNodes));
} // now we properly reset the element keys on the target to match parsing semantics
target[insert + '_asArray'] = updatedNodes;
target[insert] = updatedNodes.length == 1 ? updatedNodes[0] : updatedNodes;
});
}
});
} // #endregion PUBLIC FUNCTIONS
// #region PRIVATE FUNCTIONS
// --------------------------------------------------
function getManifest(externalManifest) {
return externalManifest ? externalManifest : voPeriods.length > 0 ? voPeriods[0].mpd.manifest : null;
}
function getAdaptationForMediaInfo(mediaInfo) {
try {
var selectedVoPeriod = getPeriodForStreamInfo(mediaInfo.streamInfo, voPeriods);
var voAdaptations = dashManifestModel.getAdaptationsForPeriod(selectedVoPeriod);
if (!mediaInfo || !mediaInfo.streamInfo || mediaInfo.streamInfo.id === undefined || !voAdaptations) return null;
return voAdaptations[mediaInfo.index];
} catch (e) {
return null;
}
}
function getPeriodForStreamInfo(streamInfo, voPeriodsArray) {
var ln = voPeriodsArray.length;
for (var i = 0; i < ln; i++) {
var voPeriod = voPeriodsArray[i];
if (streamInfo && streamInfo.id === voPeriod.id) return voPeriod;
}
return null;
}
function convertAdaptationToMediaInfo(adaptation) {
if (!adaptation) {
return null;
}
var mediaInfo = new _vo_MediaInfo__WEBPACK_IMPORTED_MODULE_2__["default"]();
var realAdaptation = adaptation.period.mpd.manifest.Period_asArray[adaptation.period.index].AdaptationSet_asArray[adaptation.index];
var viewpoint;
mediaInfo.id = adaptation.id;
mediaInfo.index = adaptation.index;
mediaInfo.type = adaptation.type;
mediaInfo.streamInfo = convertPeriodToStreamInfo(adaptation.period);
mediaInfo.representationCount = dashManifestModel.getRepresentationCount(realAdaptation);
mediaInfo.labels = dashManifestModel.getLabelsForAdaptation(realAdaptation);
mediaInfo.lang = dashManifestModel.getLanguageForAdaptation(realAdaptation);
viewpoint = dashManifestModel.getViewpointForAdaptation(realAdaptation);
mediaInfo.viewpoint = viewpoint ? viewpoint.value : undefined;
mediaInfo.accessibility = dashManifestModel.getAccessibilityForAdaptation(realAdaptation).map(function (accessibility) {
var accessibilityValue = accessibility.value;
var accessibilityData = accessibilityValue;
if (accessibility.schemeIdUri && accessibility.schemeIdUri.search('cea-608') >= 0 && typeof cea608parser !== 'undefined') {
if (accessibilityValue) {
accessibilityData = 'cea-608:' + accessibilityValue;
} else {
accessibilityData = 'cea-608';
}
mediaInfo.embeddedCaptions = true;
}
return accessibilityData;
});
mediaInfo.audioChannelConfiguration = dashManifestModel.getAudioChannelConfigurationForAdaptation(realAdaptation).map(function (audioChannelConfiguration) {
return audioChannelConfiguration.value;
});
if (mediaInfo.audioChannelConfiguration.length === 0 && Array.isArray(realAdaptation.Representation_asArray) && realAdaptation.Representation_asArray.length > 0) {
mediaInfo.audioChannelConfiguration = dashManifestModel.getAudioChannelConfigurationForRepresentation(realAdaptation.Representation_asArray[0]).map(function (audioChannelConfiguration) {
return audioChannelConfiguration.value;
});
}
mediaInfo.roles = dashManifestModel.getRolesForAdaptation(realAdaptation).map(function (role) {
return role.value;
});
mediaInfo.codec = dashManifestModel.getCodec(realAdaptation);
mediaInfo.mimeType = dashManifestModel.getMimeType(realAdaptation);
mediaInfo.contentProtection = dashManifestModel.getContentProtectionData(realAdaptation);
mediaInfo.bitrateList = dashManifestModel.getBitrateListForAdaptation(realAdaptation);
mediaInfo.selectionPriority = dashManifestModel.getSelectionPriority(realAdaptation);
if (mediaInfo.contentProtection) {
// Get the default key ID and apply it to all key systems
var keyIds = mediaInfo.contentProtection.map(function (cp) {
return dashManifestModel.getKID(cp);
}).filter(function (kid) {
return kid !== null;
});
if (keyIds.length) {
var keyId = keyIds[0];
mediaInfo.contentProtection.forEach(function (cp) {
cp.keyId = keyId;
});
}
}
mediaInfo.isText = dashManifestModel.getIsText(realAdaptation);
mediaInfo.supplementalProperties = dashManifestModel.getSupplementalProperties(realAdaptation);
mediaInfo.isFragmented = dashManifestModel.getIsFragmented(realAdaptation);
mediaInfo.isEmbedded = false;
return mediaInfo;
}
function convertVideoInfoToEmbeddedTextInfo(mediaInfo, channel, lang) {
mediaInfo.id = channel; // CC1, CC2, CC3, or CC4
mediaInfo.index = 100 + parseInt(channel.substring(2, 3));
mediaInfo.type = constants.TEXT;
mediaInfo.codec = 'cea-608-in-SEI';
mediaInfo.isEmbedded = true;
mediaInfo.isFragmented = false;
mediaInfo.lang = lang;
mediaInfo.roles = ['caption'];
}
function convertVideoInfoToThumbnailInfo(mediaInfo) {
mediaInfo.type = constants.IMAGE;
}
function convertPeriodToStreamInfo(period) {
var streamInfo = new _vo_StreamInfo__WEBPACK_IMPORTED_MODULE_3__["default"]();
var THRESHOLD = 1;
streamInfo.id = period.id;
streamInfo.index = period.index;
streamInfo.start = period.start;
streamInfo.duration = period.duration;
streamInfo.manifestInfo = convertMpdToManifestInfo(period.mpd);
streamInfo.isLast = period.mpd.manifest.Period_asArray.length === 1 || Math.abs(streamInfo.start + streamInfo.duration - streamInfo.manifestInfo.duration) < THRESHOLD;
return streamInfo;
}
function convertMpdToManifestInfo(mpd) {
var manifestInfo = new _vo_ManifestInfo__WEBPACK_IMPORTED_MODULE_4__["default"]();
manifestInfo.dvrWindowSize = mpd.timeShiftBufferDepth;
manifestInfo.loadedTime = mpd.manifest.loadedTime;
manifestInfo.availableFrom = mpd.availabilityStartTime;
manifestInfo.minBufferTime = mpd.manifest.minBufferTime;
manifestInfo.maxFragmentDuration = mpd.maxSegmentDuration;
manifestInfo.duration = dashManifestModel.getDuration(mpd.manifest);
manifestInfo.isDynamic = dashManifestModel.getIsDynamic(mpd.manifest);
manifestInfo.serviceDescriptions = dashManifestModel.getServiceDescriptions(mpd.manifest);
manifestInfo.protocol = mpd.manifest.protocol;
return manifestInfo;
}
function checkConfig() {
if (!constants) {
throw new Error('setConfig function has to be called previously');
}
}
function getPeriod(periodIdx) {
return voPeriods.length > 0 ? voPeriods[0].mpd.manifest.Period_asArray[periodIdx] : null;
}
function findRepresentationIndex(period, representationId) {
var index = findRepresentation(period, representationId, true);
return index !== null ? index : -1;
}
function findRepresentation(period, representationId, returnIndex) {
var adaptationSet, adaptationSetArray, representation, representationArray, adaptationSetArrayIndex, representationArrayIndex;
if (period) {
adaptationSetArray = period.AdaptationSet_asArray;
for (adaptationSetArrayIndex = 0; adaptationSetArrayIndex < adaptationSetArray.length; adaptationSetArrayIndex = adaptationSetArrayIndex + 1) {
adaptationSet = adaptationSetArray[adaptationSetArrayIndex];
representationArray = adaptationSet.Representation_asArray;
for (representationArrayIndex = 0; representationArrayIndex < representationArray.length; representationArrayIndex = representationArrayIndex + 1) {
representation = representationArray[representationArrayIndex];
if (representationId === representation.id) {
if (returnIndex) {
return representationArrayIndex;
} else {
return representation;
}
}
}
}
}
return null;
}
function findMaxBufferIndex(period, bufferType) {
var adaptationSet, adaptationSetArray, representationArray, adaptationSetArrayIndex;
if (!period || !bufferType) return -1;
adaptationSetArray = period.AdaptationSet_asArray;
for (adaptationSetArrayIndex = 0; adaptationSetArrayIndex < adaptationSetArray.length; adaptationSetArrayIndex = adaptationSetArrayIndex + 1) {
adaptationSet = adaptationSetArray[adaptationSetArrayIndex];
representationArray = adaptationSet.Representation_asArray;
if (dashManifestModel.getIsTypeOf(adaptationSet, bufferType)) {
return representationArray.length;
}
}
return -1;
} // #endregion PRIVATE FUNCTIONS
instance = {
getBandwidthForRepresentation: getBandwidthForRepresentation,
getIndexForRepresentation: getIndexForRepresentation,
getMaxIndexForBufferType: getMaxIndexForBufferType,
convertRepresentationToRepresentationInfo: convertRepresentationToRepresentationInfo,
getStreamsInfo: getStreamsInfo,
getMediaInfoForType: getMediaInfoForType,
getAllMediaInfoForType: getAllMediaInfoForType,
getAdaptationForType: getAdaptationForType,
getRealAdaptation: getRealAdaptation,
getRealPeriodByIndex: getRealPeriodByIndex,
getEssentialPropertiesForRepresentation: getEssentialPropertiesForRepresentation,
getVoRepresentations: getVoRepresentations,
getEventsFor: getEventsFor,
getEvent: getEvent,
getMpd: getMpd,
setConfig: setConfig,
updatePeriods: updatePeriods,
getIsTextTrack: getIsTextTrack,
getUTCTimingSources: getUTCTimingSources,
getSuggestedPresentationDelay: getSuggestedPresentationDelay,
getAvailabilityStartTime: getAvailabilityStartTime,
getIsTypeOf: getIsTypeOf,
getIsDynamic: getIsDynamic,
getDuration: getDuration,
getRegularPeriods: getRegularPeriods,
getLocation: getLocation,
getPatchLocation: getPatchLocation,
getManifestUpdatePeriod: getManifestUpdatePeriod,
getPublishTime: getPublishTime,
getIsDVB: getIsDVB,
getIsPatch: getIsPatch,
getBaseURLsFromElement: getBaseURLsFromElement,
getRepresentationSortFunction: getRepresentationSortFunction,
getCodec: getCodec,
getPeriodById: getPeriodById,
setCurrentMediaInfo: setCurrentMediaInfo,
isPatchValid: isPatchValid,
applyPatchToManifest: applyPatchToManifest,
areMediaInfosEqual: areMediaInfosEqual,
reset: reset
};
setup();
return instance;
}
DashAdapter.__dashjs_factory_name = 'DashAdapter';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__["default"].getSingletonFactory(DashAdapter));
/***/ }),
/***/ "./src/dash/DashHandler.js":
/*!*********************************!*\
!*** ./src/dash/DashHandler.js ***!
\*********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../streaming/vo/FragmentRequest */ "./src/streaming/vo/FragmentRequest.js");
/* harmony import */ var _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../streaming/vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var DEFAULT_ADJUST_SEEK_TIME_THRESHOLD = 0.5;
function DashHandler(config) {
config = config || {};
var eventBus = config.eventBus;
var debug = config.debug;
var urlUtils = config.urlUtils;
var type = config.type;
var streamInfo = config.streamInfo;
var segmentsController = config.segmentsController;
var timelineConverter = config.timelineConverter;
var baseURLController = config.baseURLController;
var instance, logger, lastSegment, isDynamicManifest, mediaHasFinished;
function setup() {
logger = debug.getLogger(instance);
resetInitialSettings();
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].DYNAMIC_TO_STATIC, _onDynamicToStatic, instance);
}
function initialize(isDynamic) {
isDynamicManifest = isDynamic;
mediaHasFinished = false;
segmentsController.initialize(isDynamic);
}
function getStreamId() {
return streamInfo.id;
}
function getType() {
return type;
}
function getStreamInfo() {
return streamInfo;
}
function resetInitialSettings() {
lastSegment = null;
}
function reset() {
resetInitialSettings();
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].DYNAMIC_TO_STATIC, _onDynamicToStatic, instance);
}
function _setRequestUrl(request, destination, representation) {
var baseURL = baseURLController.resolve(representation.path);
var url, serviceLocation;
if (!baseURL || destination === baseURL.url || !urlUtils.isRelative(destination)) {
url = destination;
} else {
url = baseURL.url;
serviceLocation = baseURL.serviceLocation;
if (destination) {
url = urlUtils.resolve(destination, url);
}
}
if (urlUtils.isRelative(url)) {
return false;
}
request.url = url;
request.serviceLocation = serviceLocation;
return true;
}
function getInitRequest(mediaInfo, representation) {
if (!representation) return null;
return _generateInitRequest(mediaInfo, representation, getType());
}
function _generateInitRequest(mediaInfo, representation, mediaType) {
var request = new _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_0__["default"]();
var period = representation.adaptation.period;
var presentationStartTime = period.start;
request.mediaType = mediaType;
request.type = _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].INIT_SEGMENT_TYPE;
request.range = representation.range;
request.availabilityStartTime = timelineConverter.calcAvailabilityStartTimeFromPresentationTime(presentationStartTime, representation, isDynamicManifest);
request.availabilityEndTime = timelineConverter.calcAvailabilityEndTimeFromPresentationTime(presentationStartTime + period.duration, representation, isDynamicManifest);
request.quality = representation.index;
request.mediaInfo = mediaInfo;
request.representationId = representation.id;
if (_setRequestUrl(request, representation.initialization, representation)) {
request.url = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__["replaceTokenForTemplate"])(request.url, 'Bandwidth', representation.bandwidth);
return request;
}
}
function _getRequestForSegment(mediaInfo, segment) {
if (segment === null || segment === undefined) {
return null;
}
var request = new _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_0__["default"]();
var representation = segment.representation;
var bandwidth = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].bandwidth;
var url = segment.media;
url = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__["replaceTokenForTemplate"])(url, 'Number', segment.replacementNumber);
url = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__["replaceTokenForTemplate"])(url, 'Time', segment.replacementTime);
url = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__["replaceTokenForTemplate"])(url, 'Bandwidth', bandwidth);
url = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__["replaceIDForTemplate"])(url, representation.id);
url = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__["unescapeDollarsInTemplate"])(url);
request.mediaType = getType();
request.type = _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].MEDIA_SEGMENT_TYPE;
request.range = segment.mediaRange;
request.startTime = segment.presentationStartTime;
request.mediaStartTime = segment.mediaStartTime;
request.duration = segment.duration;
request.timescale = representation.timescale;
request.availabilityStartTime = segment.availabilityStartTime;
request.availabilityEndTime = segment.availabilityEndTime;
request.wallStartTime = segment.wallStartTime;
request.quality = representation.index;
request.index = segment.index;
request.mediaInfo = mediaInfo;
request.adaptationIndex = representation.adaptation.index;
request.representationId = representation.id;
if (_setRequestUrl(request, url, representation)) {
return request;
}
}
function isLastSegmentRequested(representation, bufferingTime) {
if (!representation || !lastSegment) {
return false;
} // Either transition from dynamic to static was done or no next static segment found
if (mediaHasFinished) {
return true;
} // Period is endless
if (!isFinite(representation.adaptation.period.duration)) {
return false;
} // we are replacing existing stuff in the buffer for instance after a track switch
if (lastSegment.presentationStartTime + lastSegment.duration > bufferingTime) {
return false;
} // Additional segment references may be added to the last period.
// Additional periods may be added to the end of the MPD.
// Segment references SHALL NOT be added to any period other than the last period.
// An MPD update MAY combine adding segment references to the last period with adding of new periods. An MPD update that adds content MAY be combined with an MPD update that removes content.
// The index of the last requested segment is higher than the number of available segments.
// For SegmentTimeline and SegmentTemplate the index does not include the startNumber.
// For SegmentList the index includes the startnumber which is why the numberOfSegments includes this as well
if (representation.mediaFinishedInformation && !isNaN(representation.mediaFinishedInformation.numberOfSegments) && !isNaN(lastSegment.index) && lastSegment.index >= representation.mediaFinishedInformation.numberOfSegments - 1) {
// For static manifests and Template addressing we can compare the index against the number of available segments
if (!isDynamicManifest || representation.segmentInfoType === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_5__["default"].SEGMENT_TEMPLATE) {
return true;
} // For SegmentList we need to check if the next period is signaled
else if (isDynamicManifest && representation.segmentInfoType === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_5__["default"].SEGMENT_LIST && representation.adaptation.period.nextPeriodId) {
return true;
}
} // For dynamic SegmentTimeline manifests we need to check if the next period is already signaled and the segment we fetched before is the last one that is signaled.
// We can not simply use the index, as numberOfSegments might have decreased after an MPD update
return !!(isDynamicManifest && representation.adaptation.period.nextPeriodId && representation.segmentInfoType === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_5__["default"].SEGMENT_TIMELINE && representation.mediaFinishedInformation && !isNaN(representation.mediaFinishedInformation.mediaTimeOfLastSignaledSegment) && lastSegment && !isNaN(lastSegment.mediaStartTime) && !isNaN(lastSegment.duration) && lastSegment.mediaStartTime + lastSegment.duration >= representation.mediaFinishedInformation.mediaTimeOfLastSignaledSegment - 0.05);
}
function getSegmentRequestForTime(mediaInfo, representation, time) {
var request = null;
if (!representation || !representation.segmentInfoType) {
return request;
}
var segment = segmentsController.getSegmentByTime(representation, time);
if (segment) {
lastSegment = segment;
logger.debug('Index for time ' + time + ' is ' + segment.index);
request = _getRequestForSegment(mediaInfo, segment);
}
return request;
}
/**
* This function returns the next segment request without modifying any internal variables. Any class (e.g CMCD Model) that needs information about the upcoming request should use this method.
* @param {object} mediaInfo
* @param {object} representation
* @return {FragmentRequest|null}
*/
function getNextSegmentRequestIdempotent(mediaInfo, representation) {
var request = null;
var indexToRequest = lastSegment ? lastSegment.index + 1 : 0;
var segment = segmentsController.getSegmentByIndex(representation, indexToRequest, lastSegment ? lastSegment.mediaStartTime : -1);
if (!segment) return null;
request = _getRequestForSegment(mediaInfo, segment);
return request;
}
/**
* Main function to get the next segment request.
* @param {object} mediaInfo
* @param {object} representation
* @return {FragmentRequest|null}
*/
function getNextSegmentRequest(mediaInfo, representation) {
var request = null;
if (!representation || !representation.segmentInfoType) {
return null;
}
var indexToRequest = lastSegment ? lastSegment.index + 1 : 0;
var segment = segmentsController.getSegmentByIndex(representation, indexToRequest, lastSegment ? lastSegment.mediaStartTime : -1); // No segment found
if (!segment) {
// Dynamic manifest there might be something available in the next iteration
if (isDynamicManifest && !mediaHasFinished) {
logger.debug(getType() + ' No segment found at index: ' + indexToRequest + '. Wait for next loop');
return null;
} else {
mediaHasFinished = true;
}
} else {
request = _getRequestForSegment(mediaInfo, segment);
lastSegment = segment;
}
return request;
}
/**
* This function returns a time for which we can generate a request. It is supposed to be as close as possible to the target time.
* This is useful in scenarios in which the user seeks into a gap. We will not find a valid request then and need to adjust the seektime.
* @param {number} time
* @param {object} mediaInfo
* @param {object} representation
* @param {number} targetThreshold
*/
function getValidSeekTimeCloseToTargetTime(time, mediaInfo, representation, targetThreshold) {
try {
if (isNaN(time) || !mediaInfo || !representation) {
return NaN;
}
if (time < 0) {
time = 0;
}
if (isNaN(targetThreshold)) {
targetThreshold = DEFAULT_ADJUST_SEEK_TIME_THRESHOLD;
}
if (getSegmentRequestForTime(mediaInfo, representation, time)) {
return time;
}
var start = representation.adaptation.period.start;
var end = representation.adaptation.period.start + representation.adaptation.period.duration;
var currentUpperTime = Math.min(time + targetThreshold, end);
var currentLowerTime = Math.max(time - targetThreshold, start);
var adjustedTime = NaN;
var targetRequest = null;
while (currentUpperTime <= end || currentLowerTime >= start) {
var upperRequest = null;
var lowerRequest = null;
if (currentUpperTime <= end) {
upperRequest = getSegmentRequestForTime(mediaInfo, representation, currentUpperTime);
}
if (currentLowerTime >= start) {
lowerRequest = getSegmentRequestForTime(mediaInfo, representation, currentLowerTime);
}
if (lowerRequest) {
adjustedTime = currentLowerTime;
targetRequest = lowerRequest;
break;
} else if (upperRequest) {
adjustedTime = currentUpperTime;
targetRequest = upperRequest;
break;
}
currentUpperTime += targetThreshold;
currentLowerTime -= targetThreshold;
}
if (targetRequest) {
var requestEndTime = targetRequest.startTime + targetRequest.duration; // Keep the original start time in case it is covered by a segment
if (time >= targetRequest.startTime && requestEndTime - time > targetThreshold) {
return time;
} // If target time is before the start of the request use request starttime
if (time < targetRequest.startTime) {
return targetRequest.startTime;
}
return Math.min(requestEndTime - targetThreshold, adjustedTime);
}
return adjustedTime;
} catch (e) {
return NaN;
}
}
function getCurrentIndex() {
return lastSegment ? lastSegment.index : -1;
}
function _onDynamicToStatic() {
logger.debug('Dynamic stream complete');
mediaHasFinished = true;
}
instance = {
initialize: initialize,
getStreamId: getStreamId,
getType: getType,
getStreamInfo: getStreamInfo,
getInitRequest: getInitRequest,
getSegmentRequestForTime: getSegmentRequestForTime,
getCurrentIndex: getCurrentIndex,
getNextSegmentRequest: getNextSegmentRequest,
isLastSegmentRequested: isLastSegmentRequested,
reset: reset,
getNextSegmentRequestIdempotent: getNextSegmentRequestIdempotent,
getValidSeekTimeCloseToTargetTime: getValidSeekTimeCloseToTargetTime
};
setup();
return instance;
}
DashHandler.__dashjs_factory_name = 'DashHandler';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(DashHandler));
/***/ }),
/***/ "./src/dash/DashMetrics.js":
/*!*********************************!*\
!*** ./src/dash/DashMetrics.js ***!
\*********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../streaming/vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../streaming/constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _utils_Round10__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/Round10 */ "./src/dash/utils/Round10.js");
/* harmony import */ var _streaming_models_MetricsModel__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../streaming/models/MetricsModel */ "./src/streaming/models/MetricsModel.js");
/* harmony import */ var _core_Utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../core/Utils */ "./src/core/Utils.js");
/* harmony import */ var _streaming_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../streaming/vo/metrics/PlayList */ "./src/streaming/vo/metrics/PlayList.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module DashMetrics
* @description The DashMetrics module can be accessed using the MediaPlayer API getDashMetrics()
* @param {object} config
*/
function DashMetrics(config) {
config = config || {};
var context = this.context;
var instance, playListTraceMetricsClosed, playListTraceMetrics, playListMetrics;
var metricsModel = config.metricsModel;
function setup() {
metricsModel = metricsModel || Object(_streaming_models_MetricsModel__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance({
settings: config.settings
});
resetInitialSettings();
}
function resetInitialSettings() {
playListTraceMetricsClosed = true;
playListTraceMetrics = null;
playListMetrics = null;
}
/**
* Returns the latest Representation switch for a given media type
* @param {MediaType} mediaType
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentRepresentationSwitch(mediaType) {
var metrics = metricsModel.getMetricsFor(mediaType, true);
return getCurrent(metrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].TRACK_SWITCH);
}
/**
* @param {MediaType} mediaType
* @param {Date} t time of the switch event
* @param {Date} mt media presentation time
* @param {string} to id of representation
* @param {string} lto if present, subrepresentation reference
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addRepresentationSwitch(mediaType, t, mt, to, lto) {
metricsModel.addRepresentationSwitch(mediaType, t, mt, to, lto);
}
/**
* Returns the current buffer state for a given media type
* @param {MediaType} mediaType
* @returns {number}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentBufferState(mediaType) {
var metrics = metricsModel.getMetricsFor(mediaType, true);
return getCurrent(metrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].BUFFER_STATE);
}
/**
* Returns the current buffer level for a given media type
* @param {MediaType} mediaType
* @returns {number}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentBufferLevel(mediaType) {
var metrics = metricsModel.getMetricsFor(mediaType, true);
var metric = getCurrent(metrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].BUFFER_LEVEL);
if (metric) {
return _utils_Round10__WEBPACK_IMPORTED_MODULE_4__["default"].round10(metric.level / 1000, -3);
}
return 0;
}
/**
* @param {MediaType} mediaType
* @param {number} t
* @param {number} level
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addBufferLevel(mediaType, t, level) {
metricsModel.addBufferLevel(mediaType, t, level);
}
/**
* @param {MediaType} mediaType
* @param {string} state
* @param {number} target
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addBufferState(mediaType, state, target) {
metricsModel.addBufferState(mediaType, state, target);
}
/**
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function clearAllCurrentMetrics() {
metricsModel.clearAllCurrentMetrics();
}
/**
* Returns the latest HTTP request for a given media type
* @param {MediaType} mediaType
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentHttpRequest(mediaType) {
var metrics = metricsModel.getMetricsFor(mediaType, true);
if (!metrics) {
return null;
}
var httpList = metrics.HttpList;
var currentHttpList = null;
var httpListLastIndex;
if (!httpList || httpList.length <= 0) {
return null;
}
httpListLastIndex = httpList.length - 1;
while (httpListLastIndex >= 0) {
if (httpList[httpListLastIndex].responsecode) {
currentHttpList = httpList[httpListLastIndex];
break;
}
httpListLastIndex--;
}
return currentHttpList;
}
/**
* Returns all HTTP requests for a given media type
* @param {MediaType} mediaType
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getHttpRequests(mediaType) {
var metrics = metricsModel.getMetricsFor(mediaType, true);
if (!metrics) {
return [];
}
return !!metrics.HttpList ? metrics.HttpList : [];
}
/**
* @param {MediaType} mediaType
* @param {Array} loadingRequests
* @param {Array} executedRequests
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addRequestsQueue(mediaType, loadingRequests, executedRequests) {
metricsModel.addRequestsQueue(mediaType, loadingRequests, executedRequests);
}
/**
* Returns the latest metrics for a given metric list and specific metric name
* @param {MetricsList} metrics
* @param {string} metricName
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrent(metrics, metricName) {
if (!metrics) {
return null;
}
var list = metrics[metricName];
return !list || list.length === 0 ? null : list[list.length - 1];
}
/**
* Returns the number of dropped frames
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentDroppedFrames() {
var metrics = metricsModel.getMetricsFor(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, true);
return getCurrent(metrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].DROPPED_FRAMES);
}
/**
* @param {number} quality
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addDroppedFrames(quality) {
metricsModel.addDroppedFrames(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, quality);
}
/**
* Returns the current scheduling info for a given media type
* @param {MediaType} mediaType
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentSchedulingInfo(mediaType) {
var metrics = metricsModel.getMetricsFor(mediaType, true);
return getCurrent(metrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].SCHEDULING_INFO);
}
/**
* @param {object} request
* @param {string} state
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addSchedulingInfo(request, state) {
metricsModel.addSchedulingInfo(request.mediaType, new Date(), request.type, request.startTime, request.availabilityStartTime, request.duration, request.quality, request.range, state);
}
/**
* Returns the current manifest update information
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentManifestUpdate() {
var streamMetrics = metricsModel.getMetricsFor(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM);
return getCurrent(streamMetrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].MANIFEST_UPDATE);
}
/**
* @param {object} updatedFields fields to be updated
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function updateManifestUpdateInfo(updatedFields) {
var manifestUpdate = this.getCurrentManifestUpdate();
metricsModel.updateManifestUpdateInfo(manifestUpdate, updatedFields);
}
/**
* @param {object} streamInfo
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addManifestUpdateStreamInfo(streamInfo) {
if (streamInfo) {
var manifestUpdate = this.getCurrentManifestUpdate();
metricsModel.addManifestUpdateStreamInfo(manifestUpdate, streamInfo.id, streamInfo.index, streamInfo.start, streamInfo.duration);
}
}
/**
* @param {object} request
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addManifestUpdate(request) {
metricsModel.addManifestUpdate(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM, request.type, request.requestStartDate, request.requestEndDate);
}
/**
* @param {object} request
* @param {string} responseURL
* @param {number} responseStatus
* @param {object} responseHeaders
* @param {object} traces
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addHttpRequest(request, responseURL, responseStatus, responseHeaders, traces) {
metricsModel.addHttpRequest(request.mediaType, null, request.type, request.url, request.quality, responseURL, request.serviceLocation || null, request.range || null, request.requestStartDate, request.firstByteDate, request.requestEndDate, responseStatus, request.duration, responseHeaders, traces);
}
/**
* @param {object} representation
* @param {MediaType} mediaType
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addManifestUpdateRepresentationInfo(representation, mediaType) {
if (representation) {
var manifestUpdateInfo = this.getCurrentManifestUpdate();
metricsModel.addManifestUpdateRepresentationInfo(manifestUpdateInfo, representation.id, representation.index, representation.streamIndex, mediaType, representation.presentationTimeOffset, representation.startNumber, representation.fragmentInfoType);
}
}
/**
* Returns the current DVR window
* @param {MediaType} mediaType
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getCurrentDVRInfo(mediaType) {
var metrics = mediaType ? metricsModel.getMetricsFor(mediaType, true) : metricsModel.getMetricsFor(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, true) || metricsModel.getMetricsFor(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO, true);
return getCurrent(metrics, _streaming_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].DVR_INFO);
}
/**
* @param {MediaType} mediaType
* @param {Date} currentTime time of the switch event
* @param {object} mpd mpd reference
* @param {object} range range of the dvr info
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addDVRInfo(mediaType, currentTime, mpd, range) {
metricsModel.addDVRInfo(mediaType, currentTime, mpd, range);
}
/**
* Returns the value for a specific request headers used in the latest MPD request
* @param {string} id
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getLatestMPDRequestHeaderValueByID(id) {
if (!id) {
return null;
}
var headers = {};
var httpRequestList, httpRequest, i;
httpRequestList = getHttpRequests(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM);
for (i = httpRequestList.length - 1; i >= 0; i--) {
httpRequest = httpRequestList[i];
if (httpRequest.type === _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].MPD_TYPE) {
headers = _core_Utils__WEBPACK_IMPORTED_MODULE_6__["default"].parseHttpHeaders(httpRequest._responseHeaders);
break;
}
}
var value = headers[id.toLowerCase()];
return value === undefined ? null : value;
}
/**
* Returns the value for a specific request headers used in the latest fragment request
* @param {MediaType} mediaType
* @param {string} id
* @returns {*}
* @memberof module:DashMetrics
* @instance
*/
function getLatestFragmentRequestHeaderValueByID(mediaType, id) {
if (!id) {
return null;
}
var headers = {};
var httpRequest = getCurrentHttpRequest(mediaType);
if (httpRequest) {
headers = _core_Utils__WEBPACK_IMPORTED_MODULE_6__["default"].parseHttpHeaders(httpRequest._responseHeaders);
}
var value = headers[id.toLowerCase()];
return value === undefined ? null : value;
}
/**
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addPlayList() {
if (playListMetrics) {
metricsModel.addPlayList(playListMetrics);
playListMetrics = null;
}
}
/**
* Create a new playlist metric
* @param {number} mediaStartTime
* @param {string} startReason
* @ignore
*/
function createPlaylistMetrics(mediaStartTime, startReason) {
playListMetrics = new _streaming_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayList"]();
playListMetrics.start = new Date();
playListMetrics.mstart = mediaStartTime;
playListMetrics.starttype = startReason;
}
/**
* Create a playlist trace metric
* @param {number} representationId
* @param {number} mediaStartTime
* @param {number} speed
* @ignore
*/
function createPlaylistTraceMetrics(representationId, mediaStartTime, speed) {
if (playListTraceMetricsClosed === true) {
playListTraceMetricsClosed = false;
playListTraceMetrics = new _streaming_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"]();
playListTraceMetrics.representationid = representationId;
playListTraceMetrics.start = new Date();
playListTraceMetrics.mstart = mediaStartTime;
playListTraceMetrics.playbackspeed = speed !== null ? speed.toString() : null;
}
}
/**
* Update existing playlist trace metric
* @param {object} traceToUpdate
* @ignore
*/
function updatePlayListTraceMetrics(traceToUpdate) {
if (playListTraceMetrics) {
for (var field in playListTraceMetrics) {
playListTraceMetrics[field] = traceToUpdate[field];
}
}
}
/**
* Push a new playlist trace metric
* @param endTime
* @param reason
* @ignore
*/
function pushPlayListTraceMetrics(endTime, reason) {
if (playListTraceMetricsClosed === false && playListMetrics && playListTraceMetrics && playListTraceMetrics.start) {
var startTime = playListTraceMetrics.start;
var duration = endTime.getTime() - startTime.getTime();
playListTraceMetrics.duration = duration;
playListTraceMetrics.stopreason = reason;
playListMetrics.trace.push(playListTraceMetrics);
playListTraceMetricsClosed = true;
}
}
/**
* @param {object} errors
* @memberof module:DashMetrics
* @instance
* @ignore
*/
function addDVBErrors(errors) {
metricsModel.addDVBErrors(errors);
}
instance = {
getCurrentRepresentationSwitch: getCurrentRepresentationSwitch,
getCurrentBufferState: getCurrentBufferState,
getCurrentBufferLevel: getCurrentBufferLevel,
getCurrentHttpRequest: getCurrentHttpRequest,
getHttpRequests: getHttpRequests,
getCurrentDroppedFrames: getCurrentDroppedFrames,
getCurrentSchedulingInfo: getCurrentSchedulingInfo,
getCurrentDVRInfo: getCurrentDVRInfo,
getCurrentManifestUpdate: getCurrentManifestUpdate,
getLatestFragmentRequestHeaderValueByID: getLatestFragmentRequestHeaderValueByID,
getLatestMPDRequestHeaderValueByID: getLatestMPDRequestHeaderValueByID,
addRepresentationSwitch: addRepresentationSwitch,
addDVRInfo: addDVRInfo,
updateManifestUpdateInfo: updateManifestUpdateInfo,
addManifestUpdateStreamInfo: addManifestUpdateStreamInfo,
addManifestUpdateRepresentationInfo: addManifestUpdateRepresentationInfo,
addManifestUpdate: addManifestUpdate,
addHttpRequest: addHttpRequest,
addSchedulingInfo: addSchedulingInfo,
addRequestsQueue: addRequestsQueue,
addBufferLevel: addBufferLevel,
addBufferState: addBufferState,
addDroppedFrames: addDroppedFrames,
addPlayList: addPlayList,
addDVBErrors: addDVBErrors,
createPlaylistMetrics: createPlaylistMetrics,
createPlaylistTraceMetrics: createPlaylistTraceMetrics,
updatePlayListTraceMetrics: updatePlayListTraceMetrics,
pushPlayListTraceMetrics: pushPlayListTraceMetrics,
clearAllCurrentMetrics: clearAllCurrentMetrics
};
setup();
return instance;
}
DashMetrics.__dashjs_factory_name = 'DashMetrics';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(DashMetrics));
/***/ }),
/***/ "./src/dash/SegmentBaseLoader.js":
/*!***************************************!*\
!*** ./src/dash/SegmentBaseLoader.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_Segment__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./vo/Segment */ "./src/dash/vo/Segment.js");
/* harmony import */ var _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../streaming/vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../streaming/vo/FragmentRequest */ "./src/streaming/vo/FragmentRequest.js");
/* harmony import */ var _streaming_net_URLLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../streaming/net/URLLoader */ "./src/streaming/net/URLLoader.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function SegmentBaseLoader() {
var context = this.context;
var instance, logger, errHandler, boxParser, requestModifier, dashMetrics, mediaPlayerModel, urlLoader, errors, constants, dashConstants, urlUtils, baseURLController;
function initialize() {
urlLoader = Object(_streaming_net_URLLoader__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
errHandler: errHandler,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
requestModifier: requestModifier,
boxParser: boxParser,
errors: errors,
urlUtils: urlUtils,
constants: constants,
dashConstants: dashConstants
});
}
function setConfig(config) {
if (config.baseURLController) {
baseURLController = config.baseURLController;
}
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
if (config.mediaPlayerModel) {
mediaPlayerModel = config.mediaPlayerModel;
}
if (config.errHandler) {
errHandler = config.errHandler;
}
if (config.boxParser) {
boxParser = config.boxParser;
}
if (config.debug) {
logger = config.debug.getLogger(instance);
}
if (config.requestModifier) {
requestModifier = config.requestModifier;
}
if (config.errors) {
errors = config.errors;
}
if (config.urlUtils) {
urlUtils = config.urlUtils;
}
if (config.constants) {
constants = config.constants;
}
if (config.dashConstants) {
dashConstants = config.dashConstants;
}
}
function loadInitialization(representation, mediaType) {
return new Promise(function (resolve) {
_loadInitializationRecursively(representation, mediaType, resolve);
});
}
function _loadInitializationRecursively(representation, mediaType, resolve, loadingInfo) {
var initRange = null;
var baseUrl = representation ? baseURLController.resolve(representation.path) : null;
var info = loadingInfo || {
init: true,
url: baseUrl ? baseUrl.url : undefined,
range: {
start: 0,
end: 1500
},
searching: false,
bytesLoaded: 0,
bytesToLoad: 1500,
mediaType: mediaType
};
logger.debug('Start searching for initialization.');
var request = getFragmentRequest(info);
var onload = function onload(response) {
info.bytesLoaded = info.range.end;
initRange = boxParser.findInitRange(response);
if (initRange) {
representation.range = initRange; // note that we don't explicitly set rep.initialization as this
// will be computed when all BaseURLs are resolved later
resolve(representation);
} else {
info.range.end = info.bytesLoaded + info.bytesToLoad;
return _loadInitializationRecursively(representation, mediaType, resolve, info);
}
};
var onerror = function onerror() {
resolve(representation);
};
urlLoader.load({
request: request,
success: onload,
error: onerror
});
logger.debug('Perform init search: ' + info.url);
}
function loadSegments(representation, mediaType, range) {
return new Promise(function (resolve) {
_loadSegmentsRecursively(representation, mediaType, range, resolve);
});
}
function _loadSegmentsRecursively(representation, mediaType, range, resolve, callback, loadingInfo) {
if (range && (range.start === undefined || range.end === undefined)) {
var parts = range ? range.toString().split('-') : null;
range = parts ? {
start: parseFloat(parts[0]),
end: parseFloat(parts[1])
} : null;
}
callback = !callback ? onLoaded : callback;
var isoFile = null;
var sidx = null;
var hasRange = !!range;
var baseUrl = representation ? baseURLController.resolve(representation.path) : null;
var info = {
init: false,
url: baseUrl ? baseUrl.url : undefined,
range: hasRange ? range : {
start: 0,
end: 1500
},
searching: !hasRange,
bytesLoaded: loadingInfo ? loadingInfo.bytesLoaded : 0,
bytesToLoad: 1500,
mediaType: mediaType
};
var request = getFragmentRequest(info);
var onload = function onload(response) {
var extraBytes = info.bytesToLoad;
var loadedLength = response.byteLength;
info.bytesLoaded = info.range.end - info.range.start;
isoFile = boxParser.parse(response);
sidx = isoFile.getBox('sidx');
if (!sidx || !sidx.isComplete) {
if (sidx) {
info.range.start = sidx.offset || info.range.start;
info.range.end = info.range.start + (sidx.size || extraBytes);
} else if (loadedLength < info.bytesLoaded) {
// if we have reached a search limit or if we have reached the end of the file we have to stop trying to find sidx
callback(null, representation, resolve);
return;
} else {
var lastBox = isoFile.getLastBox();
if (lastBox && lastBox.size) {
info.range.start = lastBox.offset + lastBox.size;
info.range.end = info.range.start + extraBytes;
} else {
info.range.end += extraBytes;
}
}
_loadSegmentsRecursively(representation, mediaType, info.range, resolve, null, info);
} else {
var ref = sidx.references;
var loadMultiSidx, segments;
if (ref !== null && ref !== undefined && ref.length > 0) {
loadMultiSidx = ref[0].reference_type === 1;
}
if (loadMultiSidx) {
logger.debug('Initiate multiple SIDX load.');
info.range.end = info.range.start + sidx.size;
var j, len, ss, se, r;
var segs = [];
var count = 0;
var offset = (sidx.offset || info.range.start) + sidx.size;
var tmpCallback = function tmpCallback(result) {
if (result) {
segs = segs.concat(result);
count++;
if (count >= len) {
// http requests can be processed in a wrong order, so, we have to reorder segments with an ascending start Time order
segs.sort(function (a, b) {
return a.startTime - b.startTime < 0 ? -1 : 0;
});
callback(segs, representation, resolve);
}
} else {
callback(null, representation, resolve);
}
};
for (j = 0, len = ref.length; j < len; j++) {
ss = offset;
se = offset + ref[j].referenced_size - 1;
offset = offset + ref[j].referenced_size;
r = {
start: ss,
end: se
};
_loadSegmentsRecursively(representation, mediaType, r, resolve, tmpCallback, info);
}
} else {
logger.debug('Parsing segments from SIDX. representation ' + mediaType + ' - id: ' + representation.id + ' for range : ' + info.range.start + ' - ' + info.range.end);
segments = getSegmentsForSidx(sidx, info);
callback(segments, representation, resolve);
}
}
};
var onerror = function onerror() {
callback(null, representation, resolve);
};
urlLoader.load({
request: request,
success: onload,
error: onerror
});
logger.debug("Perform SIDX load for type ".concat(mediaType, " : ").concat(info.url, " with range ").concat(info.range.start, " - ").concat(info.range.end));
}
function onLoaded(segments, representation, resolve) {
resolve({
segments: segments,
representation: representation,
error: segments ? undefined : new _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_1__["default"](errors.SEGMENT_BASE_LOADER_ERROR_CODE, errors.SEGMENT_BASE_LOADER_ERROR_MESSAGE)
});
}
function reset() {
if (urlLoader) {
urlLoader.abort();
urlLoader = null;
}
}
function getSegmentsForSidx(sidx, info) {
var refs = sidx.references;
var len = refs.length;
var timescale = sidx.timescale;
var time = sidx.earliest_presentation_time;
var start = info.range.start + sidx.offset + sidx.first_offset + sidx.size;
var segments = [];
var segment, end, duration, size;
for (var i = 0; i < len; i++) {
duration = refs[i].subsegment_duration;
size = refs[i].referenced_size;
segment = new _vo_Segment__WEBPACK_IMPORTED_MODULE_0__["default"](); // note that we don't explicitly set segment.media as this will be
// computed when all BaseURLs are resolved later
segment.duration = duration;
segment.startTime = time;
segment.timescale = timescale;
end = start + size - 1;
segment.mediaRange = start + '-' + end;
segments.push(segment);
time += duration;
start += size;
}
return segments;
}
function getFragmentRequest(info) {
if (!info.url) {
return;
}
var request = new _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_3__["default"]();
request.setInfo(info);
return request;
}
instance = {
setConfig: setConfig,
initialize: initialize,
loadInitialization: loadInitialization,
loadSegments: loadSegments,
reset: reset
};
return instance;
}
SegmentBaseLoader.__dashjs_factory_name = 'SegmentBaseLoader';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(SegmentBaseLoader));
/***/ }),
/***/ "./src/dash/WebmSegmentBaseLoader.js":
/*!*******************************************!*\
!*** ./src/dash/WebmSegmentBaseLoader.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _streaming_utils_EBMLParser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../streaming/utils/EBMLParser */ "./src/streaming/utils/EBMLParser.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_Segment__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./vo/Segment */ "./src/dash/vo/Segment.js");
/* harmony import */ var _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../streaming/vo/FragmentRequest */ "./src/streaming/vo/FragmentRequest.js");
/* harmony import */ var _streaming_net_URLLoader__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../streaming/net/URLLoader */ "./src/streaming/net/URLLoader.js");
/* harmony import */ var _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../streaming/vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
function WebmSegmentBaseLoader() {
var context = this.context;
var instance, logger, WebM, errHandler, requestModifier, dashMetrics, mediaPlayerModel, urlLoader, errors, baseURLController;
function setup() {
WebM = {
EBML: {
tag: 0x1A45DFA3,
required: true
},
Segment: {
tag: 0x18538067,
required: true,
SeekHead: {
tag: 0x114D9B74,
required: true
},
Info: {
tag: 0x1549A966,
required: true,
TimecodeScale: {
tag: 0x2AD7B1,
required: true,
parse: 'getMatroskaUint'
},
Duration: {
tag: 0x4489,
required: true,
parse: 'getMatroskaFloat'
}
},
Tracks: {
tag: 0x1654AE6B,
required: true
},
Cues: {
tag: 0x1C53BB6B,
required: true,
CuePoint: {
tag: 0xBB,
required: true,
CueTime: {
tag: 0xB3,
required: true,
parse: 'getMatroskaUint'
},
CueTrackPositions: {
tag: 0xB7,
required: true,
CueTrack: {
tag: 0xF7,
required: true,
parse: 'getMatroskaUint'
},
CueClusterPosition: {
tag: 0xF1,
required: true,
parse: 'getMatroskaUint'
}
}
}
}
},
Void: {
tag: 0xEC,
required: true
}
};
}
function initialize() {
urlLoader = Object(_streaming_net_URLLoader__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
errHandler: errHandler,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
requestModifier: requestModifier,
errors: errors
});
}
function setConfig(config) {
if (!config.baseURLController || !config.dashMetrics || !config.mediaPlayerModel || !config.errHandler) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].MISSING_CONFIG_ERROR);
}
baseURLController = config.baseURLController;
dashMetrics = config.dashMetrics;
mediaPlayerModel = config.mediaPlayerModel;
errHandler = config.errHandler;
errors = config.errors;
logger = config.debug.getLogger(instance);
requestModifier = config.requestModifier;
}
function parseCues(ab) {
var cues = [];
var ebmlParser = Object(_streaming_utils_EBMLParser__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
data: ab
});
var cue, cueTrack;
ebmlParser.consumeTagAndSize(WebM.Segment.Cues);
while (ebmlParser.moreData() && ebmlParser.consumeTagAndSize(WebM.Segment.Cues.CuePoint, true)) {
cue = {};
cue.CueTime = ebmlParser.parseTag(WebM.Segment.Cues.CuePoint.CueTime);
cue.CueTracks = [];
while (ebmlParser.moreData() && ebmlParser.consumeTag(WebM.Segment.Cues.CuePoint.CueTrackPositions, true)) {
var cueTrackPositionSize = ebmlParser.getMatroskaCodedNum();
var startPos = ebmlParser.getPos();
cueTrack = {};
cueTrack.Track = ebmlParser.parseTag(WebM.Segment.Cues.CuePoint.CueTrackPositions.CueTrack);
if (cueTrack.Track === 0) {
throw new Error('Cue track cannot be 0');
}
cueTrack.ClusterPosition = ebmlParser.parseTag(WebM.Segment.Cues.CuePoint.CueTrackPositions.CueClusterPosition);
cue.CueTracks.push(cueTrack); // we're not interested any other elements - skip remaining bytes
ebmlParser.setPos(startPos + cueTrackPositionSize);
}
if (cue.CueTracks.length === 0) {
throw new Error('Mandatory cuetrack not found');
}
cues.push(cue);
}
if (cues.length === 0) {
throw new Error('mandatory cuepoint not found');
}
return cues;
}
function parseSegments(data, segmentStart, segmentEnd, segmentDuration) {
var duration, parsed, segments, segment, i, len, start, end;
parsed = parseCues(data);
segments = []; // we are assuming one cue track per cue point
// both duration and media range require the i + 1 segment
// the final segment has to use global segment parameters
for (i = 0, len = parsed.length; i < len; i += 1) {
segment = new _vo_Segment__WEBPACK_IMPORTED_MODULE_3__["default"]();
duration = 0;
if (i < parsed.length - 1) {
duration = parsed[i + 1].CueTime - parsed[i].CueTime;
} else {
duration = segmentDuration - parsed[i].CueTime;
} // note that we don't explicitly set segment.media as this will be
// computed when all BaseURLs are resolved later
segment.duration = duration;
segment.startTime = parsed[i].CueTime;
segment.timescale = 1000; // hardcoded for ms
start = parsed[i].CueTracks[0].ClusterPosition + segmentStart;
if (i < parsed.length - 1) {
end = parsed[i + 1].CueTracks[0].ClusterPosition + segmentStart - 1;
} else {
end = segmentEnd - 1;
}
segment.mediaRange = start + '-' + end;
segments.push(segment);
}
logger.debug('Parsed cues: ' + segments.length + ' cues.');
return segments;
}
function parseEbmlHeader(data, media, theRange, callback) {
if (!data || data.byteLength === 0) {
callback(null);
return;
}
var ebmlParser = Object(_streaming_utils_EBMLParser__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
data: data
});
var duration, segments, segmentEnd, segmentStart;
var parts = theRange ? theRange.split('-') : null;
var request = null;
var info = {
url: media,
range: {
start: parts ? parseFloat(parts[0]) : null,
end: parts ? parseFloat(parts[1]) : null
},
request: request
};
logger.debug('Parse EBML header: ' + info.url); // skip over the header itself
ebmlParser.skipOverElement(WebM.EBML);
ebmlParser.consumeTag(WebM.Segment); // segments start here
segmentEnd = ebmlParser.getMatroskaCodedNum();
segmentEnd += ebmlParser.getPos();
segmentStart = ebmlParser.getPos(); // skip over any top level elements to get to the segment info
while (ebmlParser.moreData() && !ebmlParser.consumeTagAndSize(WebM.Segment.Info, true)) {
if (!(ebmlParser.skipOverElement(WebM.Segment.SeekHead, true) || ebmlParser.skipOverElement(WebM.Segment.Tracks, true) || ebmlParser.skipOverElement(WebM.Segment.Cues, true) || ebmlParser.skipOverElement(WebM.Void, true))) {
throw new Error('no valid top level element found');
}
} // we only need one thing in segment info, duration
while (duration === undefined) {
var infoTag = ebmlParser.getMatroskaCodedNum(true);
var infoElementSize = ebmlParser.getMatroskaCodedNum();
switch (infoTag) {
case WebM.Segment.Info.Duration.tag:
duration = ebmlParser[WebM.Segment.Info.Duration.parse](infoElementSize);
break;
default:
ebmlParser.setPos(ebmlParser.getPos() + infoElementSize);
break;
}
} // once we have what we need from segment info, we jump right to the
// cues
request = _getFragmentRequest(info);
var onload = function onload(response) {
segments = parseSegments(response, segmentStart, segmentEnd, duration);
callback(segments);
};
var onloadend = function onloadend() {
logger.error('Download Error: Cues ' + info.url);
callback(null);
};
urlLoader.load({
request: request,
success: onload,
error: onloadend
});
logger.debug('Perform cues load: ' + info.url + ' bytes=' + info.range.start + '-' + info.range.end);
}
function loadInitialization(representation, mediaType) {
return new Promise(function (resolve) {
var request = null;
var baseUrl = representation ? baseURLController.resolve(representation.path) : null;
var initRange = representation ? representation.range.split('-') : null;
var info = {
range: {
start: initRange ? parseFloat(initRange[0]) : null,
end: initRange ? parseFloat(initRange[1]) : null
},
request: request,
url: baseUrl ? baseUrl.url : undefined,
init: true,
mediaType: mediaType
};
logger.info('Start loading initialization.');
request = _getFragmentRequest(info);
var onload = function onload() {
// note that we don't explicitly set rep.initialization as this
// will be computed when all BaseURLs are resolved later
resolve(representation);
};
var onloadend = function onloadend() {
resolve(representation);
};
urlLoader.load({
request: request,
success: onload,
error: onloadend
});
logger.debug('Perform init load: ' + info.url);
});
}
function loadSegments(representation, mediaType, theRange) {
return new Promise(function (resolve) {
var request = null;
var baseUrl = representation ? baseURLController.resolve(representation.path) : null;
var media = baseUrl ? baseUrl.url : undefined;
var bytesToLoad = 8192;
var info = {
bytesLoaded: 0,
bytesToLoad: bytesToLoad,
range: {
start: 0,
end: bytesToLoad
},
request: request,
url: media,
init: false,
mediaType: mediaType
};
request = _getFragmentRequest(info); // first load the header, but preserve the manifest range so we can
// load the cues after parsing the header
// NOTE: we expect segment info to appear in the first 8192 bytes
logger.debug('Parsing ebml header');
var onload = function onload(response) {
parseEbmlHeader(response, media, theRange, function (segments) {
resolve({
segments: segments,
representation: representation,
error: segments ? undefined : new _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__["default"](errors.SEGMENT_BASE_LOADER_ERROR_CODE, errors.SEGMENT_BASE_LOADER_ERROR_MESSAGE)
});
});
};
var onloadend = function onloadend() {
resolve({
representation: representation,
error: new _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__["default"](errors.SEGMENT_BASE_LOADER_ERROR_CODE, errors.SEGMENT_BASE_LOADER_ERROR_MESSAGE)
});
};
urlLoader.load({
request: request,
success: onload,
error: onloadend
});
});
}
function _getFragmentRequest(info) {
var request = new _streaming_vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_4__["default"]();
request.setInfo(info);
return request;
}
function reset() {
if (urlLoader) {
urlLoader.abort();
urlLoader = null;
}
}
instance = {
setConfig: setConfig,
initialize: initialize,
loadInitialization: loadInitialization,
loadSegments: loadSegments,
reset: reset
};
setup();
return instance;
}
WebmSegmentBaseLoader.__dashjs_factory_name = 'WebmSegmentBaseLoader';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(WebmSegmentBaseLoader));
/***/ }),
/***/ "./src/dash/constants/DashConstants.js":
/*!*********************************************!*\
!*** ./src/dash/constants/DashConstants.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Dash constants declaration
* @class
* @ignore
*/
var DashConstants = /*#__PURE__*/function () {
function DashConstants() {
_classCallCheck(this, DashConstants);
this.init();
}
_createClass(DashConstants, [{
key: "init",
value: function init() {
this.BASE_URL = 'BaseURL';
this.SEGMENT_BASE = 'SegmentBase';
this.SEGMENT_TEMPLATE = 'SegmentTemplate';
this.SEGMENT_LIST = 'SegmentList';
this.SEGMENT_URL = 'SegmentURL';
this.SEGMENT_TIMELINE = 'SegmentTimeline';
this.SEGMENT_PROFILES = 'segmentProfiles';
this.ADAPTATION_SET = 'AdaptationSet';
this.REPRESENTATION = 'Representation';
this.REPRESENTATION_INDEX = 'RepresentationIndex';
this.SUB_REPRESENTATION = 'SubRepresentation';
this.INITIALIZATION = 'Initialization';
this.INITIALIZATION_MINUS = 'initialization';
this.MPD = 'MPD';
this.PERIOD = 'Period';
this.ASSET_IDENTIFIER = 'AssetIdentifier';
this.EVENT_STREAM = 'EventStream';
this.ID = 'id';
this.PROFILES = 'profiles';
this.SERVICE_LOCATION = 'serviceLocation';
this.RANGE = 'range';
this.INDEX = 'index';
this.MEDIA = 'media';
this.BYTE_RANGE = 'byteRange';
this.INDEX_RANGE = 'indexRange';
this.MEDIA_RANGE = 'mediaRange';
this.VALUE = 'value';
this.CONTENT_TYPE = 'contentType';
this.MIME_TYPE = 'mimeType';
this.BITSTREAM_SWITCHING = 'BitstreamSwitching';
this.BITSTREAM_SWITCHING_MINUS = 'bitstreamSwitching';
this.CODECS = 'codecs';
this.DEPENDENCY_ID = 'dependencyId';
this.MEDIA_STREAM_STRUCTURE_ID = 'mediaStreamStructureId';
this.METRICS = 'Metrics';
this.METRICS_MINUS = 'metrics';
this.REPORTING = 'Reporting';
this.WIDTH = 'width';
this.HEIGHT = 'height';
this.SAR = 'sar';
this.FRAMERATE = 'frameRate';
this.AUDIO_SAMPLING_RATE = 'audioSamplingRate';
this.MAXIMUM_SAP_PERIOD = 'maximumSAPPeriod';
this.START_WITH_SAP = 'startWithSAP';
this.MAX_PLAYOUT_RATE = 'maxPlayoutRate';
this.CODING_DEPENDENCY = 'codingDependency';
this.SCAN_TYPE = 'scanType';
this.FRAME_PACKING = 'FramePacking';
this.AUDIO_CHANNEL_CONFIGURATION = 'AudioChannelConfiguration';
this.CONTENT_PROTECTION = 'ContentProtection';
this.ESSENTIAL_PROPERTY = 'EssentialProperty';
this.SUPPLEMENTAL_PROPERTY = 'SupplementalProperty';
this.INBAND_EVENT_STREAM = 'InbandEventStream';
this.ACCESSIBILITY = 'Accessibility';
this.ROLE = 'Role';
this.RATING = 'Rating';
this.CONTENT_COMPONENT = 'ContentComponent';
this.SUBSET = 'Subset';
this.LANG = 'lang';
this.VIEWPOINT = 'Viewpoint';
this.ROLE_ASARRAY = 'Role_asArray';
this.ACCESSIBILITY_ASARRAY = 'Accessibility_asArray';
this.AUDIOCHANNELCONFIGURATION_ASARRAY = 'AudioChannelConfiguration_asArray';
this.CONTENTPROTECTION_ASARRAY = 'ContentProtection_asArray';
this.MAIN = 'main';
this.DYNAMIC = 'dynamic';
this.STATIC = 'static';
this.MEDIA_PRESENTATION_DURATION = 'mediaPresentationDuration';
this.MINIMUM_UPDATE_PERIOD = 'minimumUpdatePeriod';
this.CODEC_PRIVATE_DATA = 'codecPrivateData';
this.BANDWITH = 'bandwidth';
this.SOURCE_URL = 'sourceURL';
this.TIMESCALE = 'timescale';
this.DURATION = 'duration';
this.START_NUMBER = 'startNumber';
this.PRESENTATION_TIME_OFFSET = 'presentationTimeOffset';
this.AVAILABILITY_START_TIME = 'availabilityStartTime';
this.AVAILABILITY_END_TIME = 'availabilityEndTime';
this.TIMESHIFT_BUFFER_DEPTH = 'timeShiftBufferDepth';
this.MAX_SEGMENT_DURATION = 'maxSegmentDuration';
this.PRESENTATION_TIME = 'presentationTime';
this.MIN_BUFFER_TIME = 'minBufferTime';
this.MAX_SUBSEGMENT_DURATION = 'maxSubsegmentDuration';
this.START = 'start';
this.AVAILABILITY_TIME_OFFSET = 'availabilityTimeOffset';
this.AVAILABILITY_TIME_COMPLETE = 'availabilityTimeComplete';
this.CENC_DEFAULT_KID = 'cenc:default_KID';
this.DVB_PRIORITY = 'dvb:priority';
this.DVB_WEIGHT = 'dvb:weight';
this.SUGGESTED_PRESENTATION_DELAY = 'suggestedPresentationDelay';
this.SERVICE_DESCRIPTION = 'ServiceDescription';
this.SERVICE_DESCRIPTION_SCOPE = 'Scope';
this.SERVICE_DESCRIPTION_LATENCY = 'Latency';
this.SERVICE_DESCRIPTION_PLAYBACK_RATE = 'PlaybackRate';
this.PATCH_LOCATION = 'PatchLocation';
this.PUBLISH_TIME = 'publishTime';
this.ORIGINAL_PUBLISH_TIME = 'originalPublishTime';
this.ORIGINAL_MPD_ID = 'mpdId';
}
}]);
return DashConstants;
}();
var constants = new DashConstants();
/* harmony default export */ __webpack_exports__["default"] = (constants);
/***/ }),
/***/ "./src/dash/controllers/RepresentationController.js":
/*!**********************************************************!*\
!*** ./src/dash/controllers/RepresentationController.js ***!
\**********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function RepresentationController(config) {
config = config || {};
var eventBus = config.eventBus;
var events = config.events;
var abrController = config.abrController;
var dashMetrics = config.dashMetrics;
var playbackController = config.playbackController;
var timelineConverter = config.timelineConverter;
var type = config.type;
var streamInfo = config.streamInfo;
var dashConstants = config.dashConstants;
var segmentsController = config.segmentsController;
var isDynamic = config.isDynamic;
var instance, realAdaptation, updating, voAvailableRepresentations, currentVoRepresentation;
function setup() {
resetInitialSettings();
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].MANIFEST_VALIDITY_CHANGED, onManifestValidityChanged, instance);
}
function getStreamId() {
return streamInfo.id;
}
function getType() {
return type;
}
function checkConfig() {
if (!abrController || !dashMetrics || !playbackController || !timelineConverter) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MISSING_CONFIG_ERROR);
}
}
function getData() {
return realAdaptation;
}
function isUpdating() {
return updating;
}
function getCurrentRepresentation() {
return currentVoRepresentation;
}
function resetInitialSettings() {
realAdaptation = null;
updating = true;
voAvailableRepresentations = [];
}
function reset() {
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].MANIFEST_VALIDITY_CHANGED, onManifestValidityChanged, instance);
resetInitialSettings();
}
function updateData(newRealAdaptation, availableRepresentations, type, isFragmented, quality) {
checkConfig();
updating = true;
voAvailableRepresentations = availableRepresentations;
var rep = getRepresentationForQuality(quality);
_setCurrentVoRepresentation(rep);
realAdaptation = newRealAdaptation;
if (type !== _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO && type !== _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && (type !== _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || !isFragmented)) {
endDataUpdate();
return Promise.resolve();
}
var promises = [];
for (var i = 0, ln = voAvailableRepresentations.length; i < ln; i++) {
var currentRep = voAvailableRepresentations[i];
promises.push(_updateRepresentation(currentRep));
}
return Promise.all(promises);
}
function _updateRepresentation(currentRep) {
return new Promise(function (resolve, reject) {
var hasInitialization = currentRep.hasInitialization();
var hasSegments = currentRep.hasSegments(); // If representation has initialization and segments information we are done
// otherwise, it means that a request has to be made to get initialization and/or segments information
var promises = [];
promises.push(segmentsController.updateInitData(currentRep, hasInitialization));
promises.push(segmentsController.updateSegmentData(currentRep, hasSegments));
Promise.all(promises).then(function (data) {
if (data[0] && !data[0].error) {
currentRep = _onInitLoaded(currentRep, data[0]);
}
if (data[1] && !data[1].error) {
currentRep = _onSegmentsLoaded(currentRep, data[1]);
}
_setMediaFinishedInformation(currentRep);
_onRepresentationUpdated(currentRep);
resolve();
})["catch"](function (e) {
reject(e);
});
});
}
function _setMediaFinishedInformation(representation) {
representation.mediaFinishedInformation = segmentsController.getMediaFinishedInformation(representation);
}
function _onInitLoaded(representation, e) {
if (!e || e.error || !e.representation) {
return representation;
}
return e.representation;
}
function _onSegmentsLoaded(representation, e) {
if (!e || e.error) return;
var fragments = e.segments;
var segments = [];
var count = 0;
var i, len, s, seg;
for (i = 0, len = fragments ? fragments.length : 0; i < len; i++) {
s = fragments[i];
seg = Object(_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_3__["getTimeBasedSegment"])(timelineConverter, isDynamic, representation, s.startTime, s.duration, s.timescale, s.media, s.mediaRange, count);
if (seg) {
segments.push(seg);
seg = null;
count++;
}
}
if (segments.length > 0) {
representation.segments = segments;
}
return representation;
}
function _addRepresentationSwitch() {
checkConfig();
var now = new Date();
var currentRepresentation = getCurrentRepresentation();
var currentVideoTimeMs = playbackController.getTime() * 1000;
if (currentRepresentation) {
dashMetrics.addRepresentationSwitch(currentRepresentation.adaptation.type, now, currentVideoTimeMs, currentRepresentation.id);
}
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].REPRESENTATION_SWITCH, {
mediaType: type,
streamId: streamInfo.id,
currentRepresentation: currentRepresentation,
numberOfRepresentations: voAvailableRepresentations.length
}, {
streamId: streamInfo.id,
mediaType: type
});
}
function getRepresentationForQuality(quality) {
return quality === null || quality === undefined || quality >= voAvailableRepresentations.length ? null : voAvailableRepresentations[quality];
}
function getQualityForRepresentation(voRepresentation) {
return voAvailableRepresentations.indexOf(voRepresentation);
}
function isAllRepresentationsUpdated() {
for (var i = 0, ln = voAvailableRepresentations.length; i < ln; i++) {
var segmentInfoType = voAvailableRepresentations[i].segmentInfoType;
if (!voAvailableRepresentations[i].hasInitialization() || (segmentInfoType === dashConstants.SEGMENT_BASE || segmentInfoType === dashConstants.BASE_URL) && !voAvailableRepresentations[i].segments) {
return false;
}
}
return true;
}
function endDataUpdate(error) {
updating = false;
eventBus.trigger(events.DATA_UPDATE_COMPLETED, {
data: realAdaptation,
currentRepresentation: currentVoRepresentation,
error: error
}, {
streamId: streamInfo.id,
mediaType: type
});
}
function _onRepresentationUpdated(r) {
if (!isUpdating()) return;
var manifestUpdateInfo = dashMetrics.getCurrentManifestUpdate();
var alreadyAdded = false;
var repInfo, repSwitch;
if (manifestUpdateInfo) {
for (var i = 0; i < manifestUpdateInfo.representationInfo.length; i++) {
repInfo = manifestUpdateInfo.representationInfo[i];
if (repInfo.index === r.index && repInfo.mediaType === getType()) {
alreadyAdded = true;
break;
}
}
if (!alreadyAdded) {
dashMetrics.addManifestUpdateRepresentationInfo(r, getType());
}
}
if (isAllRepresentationsUpdated()) {
abrController.setPlaybackQuality(type, streamInfo, getQualityForRepresentation(currentVoRepresentation));
var dvrInfo = dashMetrics.getCurrentDVRInfo(type);
if (dvrInfo) {
dashMetrics.updateManifestUpdateInfo({
latency: dvrInfo.range.end - playbackController.getTime()
});
}
repSwitch = dashMetrics.getCurrentRepresentationSwitch(getCurrentRepresentation().adaptation.type);
if (!repSwitch) {
_addRepresentationSwitch();
}
endDataUpdate();
}
}
function prepareQualityChange(newQuality) {
var newRep = getRepresentationForQuality(newQuality);
_setCurrentVoRepresentation(newRep);
_addRepresentationSwitch();
}
function _setCurrentVoRepresentation(value) {
currentVoRepresentation = value;
}
function onManifestValidityChanged(e) {
if (e.newDuration) {
var representation = getCurrentRepresentation();
if (representation && representation.adaptation.period) {
var period = representation.adaptation.period;
period.duration = e.newDuration;
}
}
}
instance = {
getStreamId: getStreamId,
getType: getType,
getData: getData,
isUpdating: isUpdating,
updateData: updateData,
getCurrentRepresentation: getCurrentRepresentation,
getRepresentationForQuality: getRepresentationForQuality,
prepareQualityChange: prepareQualityChange,
reset: reset
};
setup();
return instance;
}
RepresentationController.__dashjs_factory_name = 'RepresentationController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(RepresentationController));
/***/ }),
/***/ "./src/dash/controllers/SegmentBaseController.js":
/*!*******************************************************!*\
!*** ./src/dash/controllers/SegmentBaseController.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _SegmentBaseLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../SegmentBaseLoader */ "./src/dash/SegmentBaseLoader.js");
/* harmony import */ var _WebmSegmentBaseLoader__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../WebmSegmentBaseLoader */ "./src/dash/WebmSegmentBaseLoader.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function SegmentBaseController(config) {
config = config || {};
var context = this.context;
var eventBus = config.eventBus;
var events = config.events;
var dashMetrics = config.dashMetrics;
var mediaPlayerModel = config.mediaPlayerModel;
var errHandler = config.errHandler;
var baseURLController = config.baseURLController;
var debug = config.debug;
var boxParser = config.boxParser;
var requestModifier = config.requestModifier;
var errors = config.errors;
var instance, segmentBaseLoader, webmSegmentBaseLoader;
function setup() {
segmentBaseLoader = Object(_SegmentBaseLoader__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
webmSegmentBaseLoader = Object(_WebmSegmentBaseLoader__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
segmentBaseLoader.setConfig({
baseURLController: baseURLController,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
errHandler: errHandler,
eventBus: eventBus,
events: events,
errors: errors,
debug: debug,
boxParser: boxParser,
requestModifier: requestModifier
});
webmSegmentBaseLoader.setConfig({
baseURLController: baseURLController,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
errHandler: errHandler,
eventBus: eventBus,
events: events,
errors: errors,
debug: debug,
requestModifier: requestModifier
});
}
function isWebM(mimeType) {
var type = mimeType ? mimeType.split('/')[1] : '';
return 'webm' === type.toLowerCase();
}
function initialize() {
segmentBaseLoader.initialize();
webmSegmentBaseLoader.initialize();
}
function getSegmentBaseInitSegment(data) {
if (isWebM(data.representation.mimeType)) {
return webmSegmentBaseLoader.loadInitialization(data.representation, data.mediaType);
} else {
return segmentBaseLoader.loadInitialization(data.representation, data.mediaType);
}
}
function getSegmentList(e) {
if (isWebM(e.mimeType)) {
return webmSegmentBaseLoader.loadSegments(e.representation, e.mediaType, e.representation ? e.representation.indexRange : null);
} else {
return segmentBaseLoader.loadSegments(e.representation, e.mediaType, e.representation ? e.representation.indexRange : null);
}
}
function reset() {
segmentBaseLoader.reset();
webmSegmentBaseLoader.reset();
}
instance = {
initialize: initialize,
getSegmentBaseInitSegment: getSegmentBaseInitSegment,
getSegmentList: getSegmentList,
reset: reset
};
setup();
return instance;
}
SegmentBaseController.__dashjs_factory_name = 'SegmentBaseController';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(SegmentBaseController);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/controllers/SegmentsController.js":
/*!****************************************************!*\
!*** ./src/dash/controllers/SegmentsController.js ***!
\****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _utils_TimelineSegmentsGetter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/TimelineSegmentsGetter */ "./src/dash/utils/TimelineSegmentsGetter.js");
/* harmony import */ var _utils_TemplateSegmentsGetter__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/TemplateSegmentsGetter */ "./src/dash/utils/TemplateSegmentsGetter.js");
/* harmony import */ var _utils_ListSegmentsGetter__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/ListSegmentsGetter */ "./src/dash/utils/ListSegmentsGetter.js");
/* harmony import */ var _utils_SegmentBaseGetter__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/SegmentBaseGetter */ "./src/dash/utils/SegmentBaseGetter.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function SegmentsController(config) {
config = config || {};
var context = this.context;
var dashConstants = config.dashConstants;
var type = config.type;
var segmentBaseController = config.segmentBaseController;
var instance, getters;
function setup() {
getters = {};
}
function initialize(isDynamic) {
getters[dashConstants.SEGMENT_TIMELINE] = Object(_utils_TimelineSegmentsGetter__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create(config, isDynamic);
getters[dashConstants.SEGMENT_TEMPLATE] = Object(_utils_TemplateSegmentsGetter__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create(config, isDynamic);
getters[dashConstants.SEGMENT_LIST] = Object(_utils_ListSegmentsGetter__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create(config, isDynamic);
getters[dashConstants.SEGMENT_BASE] = Object(_utils_SegmentBaseGetter__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create(config, isDynamic);
}
function updateInitData(voRepresentation, hasInitialization) {
if (hasInitialization) {
return Promise.resolve();
}
return segmentBaseController.getSegmentBaseInitSegment({
representation: voRepresentation,
mediaType: type
});
}
function updateSegmentData(voRepresentation, hasSegments) {
if (hasSegments) {
return Promise.resolve();
}
return segmentBaseController.getSegmentList({
mimeType: voRepresentation.mimeType,
representation: voRepresentation,
mediaType: type
});
}
function getSegmentsGetter(representation) {
return representation ? representation.segments ? getters[dashConstants.SEGMENT_BASE] : getters[representation.segmentInfoType] : null;
}
function getSegmentByIndex(representation, index, lastSegmentTime) {
var getter = getSegmentsGetter(representation);
return getter ? getter.getSegmentByIndex(representation, index, lastSegmentTime) : null;
}
function getSegmentByTime(representation, time) {
var getter = getSegmentsGetter(representation);
return getter ? getter.getSegmentByTime(representation, time) : null;
}
function getMediaFinishedInformation(representation) {
var getter = getSegmentsGetter(representation);
return getter ? getter.getMediaFinishedInformation(representation) : {
numberOfSegments: 0,
mediaTimeOfLastSignaledSegment: NaN
};
}
instance = {
initialize: initialize,
updateInitData: updateInitData,
updateSegmentData: updateSegmentData,
getSegmentByIndex: getSegmentByIndex,
getSegmentByTime: getSegmentByTime,
getMediaFinishedInformation: getMediaFinishedInformation
};
setup();
return instance;
}
SegmentsController.__dashjs_factory_name = 'SegmentsController';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(SegmentsController);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/models/DashManifestModel.js":
/*!**********************************************!*\
!*** ./src/dash/models/DashManifestModel.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _vo_Representation__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/Representation */ "./src/dash/vo/Representation.js");
/* harmony import */ var _vo_AdaptationSet__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../vo/AdaptationSet */ "./src/dash/vo/AdaptationSet.js");
/* harmony import */ var _vo_Period__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/Period */ "./src/dash/vo/Period.js");
/* harmony import */ var _vo_Mpd__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/Mpd */ "./src/dash/vo/Mpd.js");
/* harmony import */ var _vo_UTCTiming__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../vo/UTCTiming */ "./src/dash/vo/UTCTiming.js");
/* harmony import */ var _vo_Event__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../vo/Event */ "./src/dash/vo/Event.js");
/* harmony import */ var _vo_BaseURL__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../vo/BaseURL */ "./src/dash/vo/BaseURL.js");
/* harmony import */ var _vo_EventStream__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../vo/EventStream */ "./src/dash/vo/EventStream.js");
/* harmony import */ var _streaming_utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../streaming/utils/ObjectUtils */ "./src/streaming/utils/ObjectUtils.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../streaming/vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _streaming_thumbnail_ThumbnailTracks__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../streaming/thumbnail/ThumbnailTracks */ "./src/streaming/thumbnail/ThumbnailTracks.js");
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function DashManifestModel() {
var instance, logger, errHandler, BASE64;
var context = this.context;
var urlUtils = Object(_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
var isInteger = Number.isInteger || function (value) {
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
};
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance().getLogger(instance);
}
function getIsTypeOf(adaptation, type) {
if (!adaptation) {
throw new Error('adaptation is not defined');
}
if (!type) {
throw new Error('type is not defined');
} // Check for thumbnail images
if (adaptation.Representation_asArray && adaptation.Representation_asArray.length) {
var essentialProperties = getEssentialPropertiesForRepresentation(adaptation.Representation_asArray[0]);
if (essentialProperties && essentialProperties.length > 0 && _streaming_thumbnail_ThumbnailTracks__WEBPACK_IMPORTED_MODULE_16__["THUMBNAILS_SCHEME_ID_URIS"].indexOf(essentialProperties[0].schemeIdUri) >= 0) {
return type === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE;
}
} // Check ContentComponent.contentType
if (adaptation.ContentComponent_asArray && adaptation.ContentComponent_asArray.length > 0) {
if (adaptation.ContentComponent_asArray.length > 1) {
return type === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MUXED;
} else if (adaptation.ContentComponent_asArray[0].contentType === type) {
return true;
}
}
var mimeTypeRegEx = type === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT ? new RegExp('(ttml|vtt|wvtt|stpp)') : new RegExp(type); // Check codecs
if (adaptation.Representation_asArray && adaptation.Representation_asArray.length) {
var codecs = adaptation.Representation_asArray[0].codecs;
if (mimeTypeRegEx.test(codecs)) {
return true;
}
} // Check Adaptation's mimeType
if (adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MIME_TYPE)) {
return mimeTypeRegEx.test(adaptation.mimeType);
} // Check Representation's mimeType
if (adaptation.Representation_asArray) {
var representation;
for (var i = 0; i < adaptation.Representation_asArray.length; i++) {
representation = adaptation.Representation_asArray[i];
if (representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MIME_TYPE)) {
return mimeTypeRegEx.test(representation.mimeType);
}
}
}
return false;
}
function getIsFragmented(adaptation) {
if (!adaptation) {
throw new Error('adaptation is not defined');
}
if (adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE) || adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE) || adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_LIST) || adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE)) {
return true;
}
if (adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0) {
var representation = adaptation.Representation_asArray[0];
if (representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE) || representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE) || representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_LIST) || representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE)) {
return true;
}
}
return false;
}
function getIsAudio(adaptation) {
return getIsTypeOf(adaptation, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO);
}
function getIsVideo(adaptation) {
return getIsTypeOf(adaptation, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO);
}
function getIsText(adaptation) {
return getIsTypeOf(adaptation, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT);
}
function getIsMuxed(adaptation) {
return getIsTypeOf(adaptation, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MUXED);
}
function getIsImage(adaptation) {
return getIsTypeOf(adaptation, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE);
}
function getLanguageForAdaptation(adaptation) {
var lang = '';
if (adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG)) {
//Filter out any other characters not allowed according to RFC5646
lang = adaptation.lang.replace(/[^A-Za-z0-9-]/g, '');
}
return lang;
}
function getViewpointForAdaptation(adaptation) {
return adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VIEWPOINT) ? adaptation.Viewpoint : null;
}
function getRolesForAdaptation(adaptation) {
return adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ROLE_ASARRAY) ? adaptation.Role_asArray : [];
}
function getAccessibilityForAdaptation(adaptation) {
return adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ACCESSIBILITY_ASARRAY) ? adaptation.Accessibility_asArray : [];
}
function getAudioChannelConfigurationForAdaptation(adaptation) {
return adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY) ? adaptation.AudioChannelConfiguration_asArray : [];
}
function getAudioChannelConfigurationForRepresentation(representation) {
return representation && representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY) ? representation.AudioChannelConfiguration_asArray : [];
}
function getRepresentationSortFunction() {
return function (a, b) {
return a.bandwidth - b.bandwidth;
};
}
function processAdaptation(realAdaptation) {
if (realAdaptation && Array.isArray(realAdaptation.Representation_asArray)) {
realAdaptation.Representation_asArray.sort(getRepresentationSortFunction());
}
return realAdaptation;
}
function getRealAdaptations(manifest, periodIndex) {
return manifest && manifest.Period_asArray && isInteger(periodIndex) ? manifest.Period_asArray[periodIndex] ? manifest.Period_asArray[periodIndex].AdaptationSet_asArray : [] : [];
}
function getRealPeriods(manifest) {
return manifest && manifest.Period_asArray ? manifest.Period_asArray : [];
}
function getRealPeriodForIndex(index, manifest) {
var realPeriods = getRealPeriods(manifest);
if (realPeriods.length > 0 && isInteger(index)) {
return realPeriods[index];
} else {
return null;
}
}
function getAdaptationForId(id, manifest, periodIndex) {
var realAdaptations = getRealAdaptations(manifest, periodIndex);
var i, len;
for (i = 0, len = realAdaptations.length; i < len; i++) {
if (realAdaptations[i].hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID) && realAdaptations[i].id === id) {
return realAdaptations[i];
}
}
return null;
}
function getAdaptationForIndex(index, manifest, periodIndex) {
var realAdaptations = getRealAdaptations(manifest, periodIndex);
if (realAdaptations.length > 0 && isInteger(index)) {
return realAdaptations[index];
} else {
return null;
}
}
function getIndexForAdaptation(realAdaptation, manifest, periodIndex) {
if (!realAdaptation) {
return -1;
}
var realAdaptations = getRealAdaptations(manifest, periodIndex);
for (var i = 0; i < realAdaptations.length; i++) {
var objectUtils = Object(_streaming_utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
if (objectUtils.areEqual(realAdaptations[i], realAdaptation)) {
return i;
}
}
return -1;
}
function getAdaptationsForType(manifest, periodIndex, type) {
var realAdaptations = getRealAdaptations(manifest, periodIndex);
var i, len;
var adaptations = [];
for (i = 0, len = realAdaptations.length; i < len; i++) {
if (getIsTypeOf(realAdaptations[i], type)) {
adaptations.push(processAdaptation(realAdaptations[i]));
}
}
return adaptations;
}
function getCodec(adaptation, representationId, addResolutionInfo) {
var codec = null;
if (adaptation && adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0) {
var representation = isInteger(representationId) && representationId >= 0 && representationId < adaptation.Representation_asArray.length ? adaptation.Representation_asArray[representationId] : adaptation.Representation_asArray[0];
if (representation) {
codec = representation.mimeType + ';codecs="' + representation.codecs + '"';
if (addResolutionInfo && representation.width !== undefined) {
codec += ';width="' + representation.width + '";height="' + representation.height + '"';
}
}
} // If the codec contains a profiles parameter we remove it. Otherwise it will cause problems when checking for codec capabilities of the platform
if (codec) {
codec = codec.replace(/\sprofiles=[^;]*/g, '');
}
return codec;
}
function getMimeType(adaptation) {
return adaptation && adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0 ? adaptation.Representation_asArray[0].mimeType : null;
}
function getKID(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CENC_DEFAULT_KID)) {
return null;
}
return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CENC_DEFAULT_KID];
}
function getLabelsForAdaptation(adaptation) {
if (!adaptation || !Array.isArray(adaptation.Label_asArray)) {
return [];
}
var labelArray = [];
for (var i = 0; i < adaptation.Label_asArray.length; i++) {
labelArray.push({
lang: adaptation.Label_asArray[i].lang,
text: adaptation.Label_asArray[i].__text || adaptation.Label_asArray[i]
});
}
return labelArray;
}
function getContentProtectionData(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENTPROTECTION_ASARRAY) || adaptation.ContentProtection_asArray.length === 0) {
return null;
}
return adaptation.ContentProtection_asArray;
}
function getIsDynamic(manifest) {
var isDynamic = false;
if (manifest && manifest.hasOwnProperty('type')) {
isDynamic = manifest.type === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DYNAMIC;
}
return isDynamic;
}
function getId(manifest) {
return manifest && manifest[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID] || null;
}
function hasProfile(manifest, profile) {
var has = false;
if (manifest && manifest.profiles && manifest.profiles.length > 0) {
has = manifest.profiles.indexOf(profile) !== -1;
}
return has;
}
function getDuration(manifest) {
var mpdDuration; //@mediaPresentationDuration specifies the duration of the entire Media Presentation.
//If the attribute is not present, the duration of the Media Presentation is unknown.
if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MEDIA_PRESENTATION_DURATION)) {
mpdDuration = manifest.mediaPresentationDuration;
} else if (manifest && manifest.type == 'dynamic') {
mpdDuration = Number.POSITIVE_INFINITY;
} else {
mpdDuration = Number.MAX_SAFE_INTEGER || Number.MAX_VALUE;
}
return mpdDuration;
}
function getBandwidth(representation) {
return representation && representation.bandwidth ? representation.bandwidth : NaN;
}
function getManifestUpdatePeriod(manifest) {
var latencyOfLastUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var delay = NaN;
if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MINIMUM_UPDATE_PERIOD)) {
delay = manifest.minimumUpdatePeriod;
}
return isNaN(delay) ? delay : Math.max(delay - latencyOfLastUpdate, 1);
}
function getPublishTime(manifest) {
return manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PUBLISH_TIME) ? new Date(manifest[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PUBLISH_TIME]) : null;
}
function getRepresentationCount(adaptation) {
return adaptation && Array.isArray(adaptation.Representation_asArray) ? adaptation.Representation_asArray.length : 0;
}
function getBitrateListForAdaptation(realAdaptation) {
var processedRealAdaptation = processAdaptation(realAdaptation);
var realRepresentations = processedRealAdaptation && Array.isArray(processedRealAdaptation.Representation_asArray) ? processedRealAdaptation.Representation_asArray : [];
return realRepresentations.map(function (realRepresentation) {
return {
bandwidth: realRepresentation.bandwidth,
width: realRepresentation.width || 0,
height: realRepresentation.height || 0,
scanType: realRepresentation.scanType || null,
id: realRepresentation.id || null
};
});
}
function getSelectionPriority(realAdaption) {
try {
var priority = realAdaption && typeof realAdaption.selectionPriority !== 'undefined' ? parseInt(realAdaption.selectionPriority) : 1;
return isNaN(priority) ? 1 : priority;
} catch (e) {
return 1;
}
}
function getEssentialPropertiesForRepresentation(realRepresentation) {
if (!realRepresentation || !realRepresentation.EssentialProperty_asArray || !realRepresentation.EssentialProperty_asArray.length) return null;
return realRepresentation.EssentialProperty_asArray.map(function (prop) {
return {
schemeIdUri: prop.schemeIdUri,
value: prop.value
};
});
}
function getRepresentationFor(index, adaptation) {
return adaptation && adaptation.Representation_asArray && adaptation.Representation_asArray.length > 0 && isInteger(index) ? adaptation.Representation_asArray[index] : null;
}
function getRealAdaptationFor(voAdaptation) {
if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {
var periodArray = voAdaptation.period.mpd.manifest.Period_asArray[voAdaptation.period.index];
if (periodArray && periodArray.AdaptationSet_asArray && isInteger(voAdaptation.index)) {
return processAdaptation(periodArray.AdaptationSet_asArray[voAdaptation.index]);
}
}
}
function getRepresentationsForAdaptation(voAdaptation) {
var voRepresentations = [];
var processedRealAdaptation = getRealAdaptationFor(voAdaptation);
var segmentInfo, baseUrl;
if (processedRealAdaptation && processedRealAdaptation.Representation_asArray) {
// TODO: TO BE REMOVED. We should get just the baseUrl elements that affects to the representations
// that we are processing. Making it works properly will require much further changes and given
// parsing base Urls parameters is needed for our ultra low latency examples, we will
// keep this "tricky" code until the real (and good) solution comes
if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {
var baseUrls = getBaseURLsFromElement(voAdaptation.period.mpd.manifest);
if (baseUrls) {
baseUrl = baseUrls[0];
}
}
for (var i = 0, len = processedRealAdaptation.Representation_asArray.length; i < len; ++i) {
var realRepresentation = processedRealAdaptation.Representation_asArray[i];
var voRepresentation = new _vo_Representation__WEBPACK_IMPORTED_MODULE_2__["default"]();
voRepresentation.index = i;
voRepresentation.adaptation = voAdaptation;
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID)) {
voRepresentation.id = realRepresentation.id;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CODECS)) {
voRepresentation.codecs = realRepresentation.codecs;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MIME_TYPE)) {
voRepresentation.mimeType = realRepresentation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MIME_TYPE];
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CODEC_PRIVATE_DATA)) {
voRepresentation.codecPrivateData = realRepresentation.codecPrivateData;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BANDWITH)) {
voRepresentation.bandwidth = realRepresentation.bandwidth;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].WIDTH)) {
voRepresentation.width = realRepresentation.width;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].HEIGHT)) {
voRepresentation.height = realRepresentation.height;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SCAN_TYPE)) {
voRepresentation.scanType = realRepresentation.scanType;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MAX_PLAYOUT_RATE)) {
voRepresentation.maxPlayoutRate = realRepresentation.maxPlayoutRate;
}
if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE)) {
segmentInfo = realRepresentation.SegmentBase;
voRepresentation.segmentInfoType = _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE;
} else if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_LIST)) {
segmentInfo = realRepresentation.SegmentList;
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE)) {
voRepresentation.segmentInfoType = _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE;
} else {
voRepresentation.segmentInfoType = _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_LIST;
}
} else if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE)) {
segmentInfo = realRepresentation.SegmentTemplate;
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE)) {
voRepresentation.segmentInfoType = _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE;
} else {
voRepresentation.segmentInfoType = _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INITIALIZATION_MINUS)) {
voRepresentation.initialization = segmentInfo.initialization.split('$Bandwidth$').join(realRepresentation.bandwidth).split('$RepresentationID$').join(realRepresentation.id);
}
} else {
voRepresentation.segmentInfoType = _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BASE_URL;
}
voRepresentation.essentialProperties = getEssentialPropertiesForRepresentation(realRepresentation);
if (segmentInfo) {
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INITIALIZATION)) {
var initialization = segmentInfo.Initialization;
if (initialization.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SOURCE_URL)) {
voRepresentation.initialization = initialization.sourceURL;
}
if (initialization.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].RANGE)) {
voRepresentation.range = initialization.range; // initialization source url will be determined from
// BaseURL when resolved at load time.
}
} else if (getIsText(processedRealAdaptation) && getIsFragmented(processedRealAdaptation) && processedRealAdaptation.mimeType && processedRealAdaptation.mimeType.indexOf('application/mp4') === -1) {
voRepresentation.range = 0;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TIMESCALE)) {
voRepresentation.timescale = segmentInfo.timescale;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DURATION)) {
// TODO according to the spec @maxSegmentDuration specifies the maximum duration of any Segment in any Representation in the Media Presentation
// It is also said that for a SegmentTimeline any @d value shall not exceed the value of MPD@maxSegmentDuration, but nothing is said about
// SegmentTemplate @duration attribute. We need to find out if @maxSegmentDuration should be used instead of calculated duration if the the duration
// exceeds @maxSegmentDuration
voRepresentation.segmentDuration = segmentInfo.duration / voRepresentation.timescale;
} else if (realRepresentation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE)) {
segmentInfo = realRepresentation.SegmentTemplate;
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE)) {
voRepresentation.segmentDuration = calcSegmentDuration(segmentInfo.SegmentTimeline) / voRepresentation.timescale;
}
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MEDIA)) {
voRepresentation.media = segmentInfo.media;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].START_NUMBER)) {
voRepresentation.startNumber = segmentInfo.startNumber;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INDEX_RANGE)) {
voRepresentation.indexRange = segmentInfo.indexRange;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME_OFFSET)) {
voRepresentation.presentationTimeOffset = segmentInfo.presentationTimeOffset / voRepresentation.timescale;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_TIME_OFFSET)) {
voRepresentation.availabilityTimeOffset = segmentInfo.availabilityTimeOffset;
} else if (baseUrl && baseUrl.availabilityTimeOffset !== undefined) {
voRepresentation.availabilityTimeOffset = baseUrl.availabilityTimeOffset;
}
if (segmentInfo.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_TIME_COMPLETE)) {
voRepresentation.availabilityTimeComplete = segmentInfo.availabilityTimeComplete !== 'false';
} else if (baseUrl && baseUrl.availabilityTimeComplete !== undefined) {
voRepresentation.availabilityTimeComplete = baseUrl.availabilityTimeComplete;
}
}
voRepresentation.MSETimeOffset = calcMSETimeOffset(voRepresentation);
voRepresentation.path = [voAdaptation.period.index, voAdaptation.index, i];
voRepresentations.push(voRepresentation);
}
}
return voRepresentations;
}
function calcSegmentDuration(segmentTimeline) {
if (!segmentTimeline || !segmentTimeline.S_asArray) {
return NaN;
}
var s0 = segmentTimeline.S_asArray[0];
var s1 = segmentTimeline.S_asArray[1];
return s0.hasOwnProperty('d') ? s0.d : s1.t - s0.t;
}
function calcMSETimeOffset(representation) {
// The MSEOffset is offset from AST for media. It is Period@start - presentationTimeOffset
var presentationOffset = representation.presentationTimeOffset;
var periodStart = representation.adaptation.period.start;
return periodStart - presentationOffset;
}
function getAdaptationsForPeriod(voPeriod) {
var realPeriod = voPeriod && isInteger(voPeriod.index) ? voPeriod.mpd.manifest.Period_asArray[voPeriod.index] : null;
var voAdaptations = [];
var voAdaptationSet, realAdaptationSet, i;
if (realPeriod && realPeriod.AdaptationSet_asArray) {
for (i = 0; i < realPeriod.AdaptationSet_asArray.length; i++) {
realAdaptationSet = realPeriod.AdaptationSet_asArray[i];
voAdaptationSet = new _vo_AdaptationSet__WEBPACK_IMPORTED_MODULE_3__["default"]();
if (realAdaptationSet.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID)) {
voAdaptationSet.id = realAdaptationSet.id;
}
voAdaptationSet.index = i;
voAdaptationSet.period = voPeriod;
if (getIsMuxed(realAdaptationSet)) {
voAdaptationSet.type = _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MUXED;
} else if (getIsAudio(realAdaptationSet)) {
voAdaptationSet.type = _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO;
} else if (getIsVideo(realAdaptationSet)) {
voAdaptationSet.type = _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO;
} else if (getIsText(realAdaptationSet)) {
voAdaptationSet.type = _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT;
} else if (getIsImage(realAdaptationSet)) {
voAdaptationSet.type = _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE;
} else {
logger.warn('Unknown Adaptation stream type');
}
voAdaptations.push(voAdaptationSet);
}
}
return voAdaptations;
}
function getRegularPeriods(mpd) {
var isDynamic = mpd ? getIsDynamic(mpd.manifest) : false;
var voPeriods = [];
var realPreviousPeriod = null;
var realPeriod = null;
var voPreviousPeriod = null;
var voPeriod = null;
var len, i;
for (i = 0, len = mpd && mpd.manifest && mpd.manifest.Period_asArray ? mpd.manifest.Period_asArray.length : 0; i < len; i++) {
realPeriod = mpd.manifest.Period_asArray[i]; // If the attribute @start is present in the Period, then the
// Period is a regular Period and the PeriodStart is equal
// to the value of this attribute.
if (realPeriod.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].START)) {
voPeriod = new _vo_Period__WEBPACK_IMPORTED_MODULE_4__["default"]();
voPeriod.start = realPeriod.start;
} // If the @start attribute is absent, but the previous Period
// element contains a @duration attribute then then this new
// Period is also a regular Period. The start time of the new
// Period PeriodStart is the sum of the start time of the previous
// Period PeriodStart and the value of the attribute @duration
// of the previous Period.
else if (realPreviousPeriod !== null && realPreviousPeriod.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DURATION) && voPreviousPeriod !== null) {
voPeriod = new _vo_Period__WEBPACK_IMPORTED_MODULE_4__["default"]();
voPeriod.start = parseFloat((voPreviousPeriod.start + voPreviousPeriod.duration).toFixed(5));
} // If (i) @start attribute is absent, and (ii) the Period element
// is the first in the MPD, and (iii) the MPD@type is 'static',
// then the PeriodStart time shall be set to zero.
else if (i === 0 && !isDynamic) {
voPeriod = new _vo_Period__WEBPACK_IMPORTED_MODULE_4__["default"]();
voPeriod.start = 0;
} // The Period extends until the PeriodStart of the next Period.
// The difference between the PeriodStart time of a Period and
// the PeriodStart time of the following Period.
if (voPreviousPeriod !== null && isNaN(voPreviousPeriod.duration)) {
if (voPeriod !== null) {
voPreviousPeriod.duration = parseFloat((voPeriod.start - voPreviousPeriod.start).toFixed(5));
} else {
logger.warn('First period duration could not be calculated because lack of start and duration period properties. This will cause timing issues during playback');
}
}
if (voPeriod !== null) {
voPeriod.id = getPeriodId(realPeriod, i);
voPeriod.index = i;
voPeriod.mpd = mpd;
if (realPeriod.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DURATION)) {
voPeriod.duration = realPeriod.duration;
}
if (voPreviousPeriod) {
voPreviousPeriod.nextPeriodId = voPeriod.id;
}
voPeriods.push(voPeriod);
realPreviousPeriod = realPeriod;
voPreviousPeriod = voPeriod;
}
realPeriod = null;
voPeriod = null;
}
if (voPeriods.length === 0) {
return voPeriods;
} // The last Period extends until the end of the Media Presentation.
// The difference between the PeriodStart time of the last Period
// and the mpd duration
if (voPreviousPeriod !== null && isNaN(voPreviousPeriod.duration)) {
voPreviousPeriod.duration = parseFloat((getEndTimeForLastPeriod(voPreviousPeriod) - voPreviousPeriod.start).toFixed(5));
}
return voPeriods;
}
function getPeriodId(realPeriod, i) {
if (!realPeriod) {
throw new Error('Period cannot be null or undefined');
}
var id = _vo_Period__WEBPACK_IMPORTED_MODULE_4__["default"].DEFAULT_ID + '_' + i;
if (realPeriod.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID) && realPeriod.id.length > 0 && realPeriod.id !== '__proto__') {
id = realPeriod.id;
}
return id;
}
function getMpd(manifest) {
var mpd = new _vo_Mpd__WEBPACK_IMPORTED_MODULE_5__["default"]();
if (manifest) {
mpd.manifest = manifest;
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_START_TIME)) {
mpd.availabilityStartTime = new Date(manifest.availabilityStartTime.getTime());
} else {
if (manifest.loadedTime) {
mpd.availabilityStartTime = new Date(manifest.loadedTime.getTime());
}
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_END_TIME)) {
mpd.availabilityEndTime = new Date(manifest.availabilityEndTime.getTime());
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MINIMUM_UPDATE_PERIOD)) {
mpd.minimumUpdatePeriod = manifest.minimumUpdatePeriod;
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MEDIA_PRESENTATION_DURATION)) {
mpd.mediaPresentationDuration = manifest.mediaPresentationDuration;
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUGGESTED_PRESENTATION_DELAY)) {
mpd.suggestedPresentationDelay = manifest.suggestedPresentationDelay;
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TIMESHIFT_BUFFER_DEPTH)) {
mpd.timeShiftBufferDepth = manifest.timeShiftBufferDepth;
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MAX_SEGMENT_DURATION)) {
mpd.maxSegmentDuration = manifest.maxSegmentDuration;
}
if (manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PUBLISH_TIME)) {
mpd.publishTime = new Date(manifest.publishTime);
}
}
return mpd;
}
function checkConfig() {
if (!errHandler || !errHandler.hasOwnProperty('error')) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MISSING_CONFIG_ERROR);
}
}
function getEndTimeForLastPeriod(voPeriod) {
checkConfig();
var isDynamic = getIsDynamic(voPeriod.mpd.manifest);
var periodEnd;
if (voPeriod.mpd.manifest.mediaPresentationDuration) {
periodEnd = voPeriod.mpd.manifest.mediaPresentationDuration;
} else if (voPeriod.duration) {
periodEnd = voPeriod.duration;
} else if (isDynamic) {
periodEnd = Number.POSITIVE_INFINITY;
} else {
errHandler.error(new _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_15__["default"].MANIFEST_ERROR_ID_PARSE_CODE, 'Must have @mediaPresentationDuration on MPD or an explicit @duration on the last period.', voPeriod));
}
return periodEnd;
}
function getEventsForPeriod(period) {
var manifest = period && period.mpd && period.mpd.manifest ? period.mpd.manifest : null;
var periodArray = manifest ? manifest.Period_asArray : null;
var eventStreams = periodArray && period && isInteger(period.index) ? periodArray[period.index].EventStream_asArray : null;
var events = [];
var i, j;
if (eventStreams) {
for (i = 0; i < eventStreams.length; i++) {
var eventStream = new _vo_EventStream__WEBPACK_IMPORTED_MODULE_9__["default"]();
eventStream.period = period;
eventStream.timescale = 1;
if (eventStreams[i].hasOwnProperty(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SCHEME_ID_URI)) {
eventStream.schemeIdUri = eventStreams[i][_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SCHEME_ID_URI];
} else {
throw new Error('Invalid EventStream. SchemeIdUri has to be set');
}
if (eventStreams[i].hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TIMESCALE)) {
eventStream.timescale = eventStreams[i][_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TIMESCALE];
}
if (eventStreams[i].hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE)) {
eventStream.value = eventStreams[i][_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE];
}
if (eventStreams[i].hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME_OFFSET)) {
eventStream.presentationTimeOffset = eventStreams[i][_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME_OFFSET];
}
for (j = 0; eventStreams[i].Event_asArray && j < eventStreams[i].Event_asArray.length; j++) {
var currentMpdEvent = eventStreams[i].Event_asArray[j];
var event = new _vo_Event__WEBPACK_IMPORTED_MODULE_7__["default"]();
event.presentationTime = 0;
event.eventStream = eventStream;
if (currentMpdEvent.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME)) {
event.presentationTime = currentMpdEvent.presentationTime;
var presentationTimeOffset = eventStream.presentationTimeOffset ? eventStream.presentationTimeOffset / eventStream.timescale : 0;
event.calculatedPresentationTime = event.presentationTime / eventStream.timescale + period.start - presentationTimeOffset;
}
if (currentMpdEvent.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DURATION)) {
event.duration = currentMpdEvent.duration / eventStream.timescale;
}
if (currentMpdEvent.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID)) {
event.id = currentMpdEvent.id;
}
if (currentMpdEvent.Signal && currentMpdEvent.Signal.Binary) {
// toString is used to manage both regular and namespaced tags
event.messageData = BASE64.decodeArray(currentMpdEvent.Signal.Binary.toString());
} else {
// From Cor.1: 'NOTE: this attribute is an alternative
// to specifying a complete XML element(s) in the Event.
// It is useful when an event leans itself to a compact
// string representation'.
event.messageData = currentMpdEvent.messageData || currentMpdEvent.__text;
}
events.push(event);
}
}
}
return events;
}
function getEventStreams(inbandStreams, representation) {
var eventStreams = [];
var i;
if (!inbandStreams) return eventStreams;
for (i = 0; i < inbandStreams.length; i++) {
var eventStream = new _vo_EventStream__WEBPACK_IMPORTED_MODULE_9__["default"]();
eventStream.timescale = 1;
eventStream.representation = representation;
if (inbandStreams[i].hasOwnProperty(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SCHEME_ID_URI)) {
eventStream.schemeIdUri = inbandStreams[i].schemeIdUri;
} else {
throw new Error('Invalid EventStream. SchemeIdUri has to be set');
}
if (inbandStreams[i].hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TIMESCALE)) {
eventStream.timescale = inbandStreams[i].timescale;
}
if (inbandStreams[i].hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE)) {
eventStream.value = inbandStreams[i].value;
}
eventStreams.push(eventStream);
}
return eventStreams;
}
function getEventStreamForAdaptationSet(manifest, adaptation) {
var inbandStreams, periodArray, adaptationArray;
if (manifest && manifest.Period_asArray && adaptation && adaptation.period && isInteger(adaptation.period.index)) {
periodArray = manifest.Period_asArray[adaptation.period.index];
if (periodArray && periodArray.AdaptationSet_asArray && isInteger(adaptation.index)) {
adaptationArray = periodArray.AdaptationSet_asArray[adaptation.index];
if (adaptationArray) {
inbandStreams = adaptationArray.InbandEventStream_asArray;
}
}
}
return getEventStreams(inbandStreams, null);
}
function getEventStreamForRepresentation(manifest, representation) {
var inbandStreams, periodArray, adaptationArray, representationArray;
if (manifest && manifest.Period_asArray && representation && representation.adaptation && representation.adaptation.period && isInteger(representation.adaptation.period.index)) {
periodArray = manifest.Period_asArray[representation.adaptation.period.index];
if (periodArray && periodArray.AdaptationSet_asArray && isInteger(representation.adaptation.index)) {
adaptationArray = periodArray.AdaptationSet_asArray[representation.adaptation.index];
if (adaptationArray && adaptationArray.Representation_asArray && isInteger(representation.index)) {
representationArray = adaptationArray.Representation_asArray[representation.index];
if (representationArray) {
inbandStreams = representationArray.InbandEventStream_asArray;
}
}
}
}
return getEventStreams(inbandStreams, representation);
}
function getUTCTimingSources(manifest) {
var isDynamic = getIsDynamic(manifest);
var hasAST = manifest ? manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_START_TIME) : false;
var utcTimingsArray = manifest ? manifest.UTCTiming_asArray : null;
var utcTimingEntries = []; // do not bother synchronizing the clock unless MPD is live,
// or it is static and has availabilityStartTime attribute
if (isDynamic || hasAST) {
if (utcTimingsArray) {
// the order is important here - 23009-1 states that the order
// in the manifest "indicates relative preference, first having
// the highest, and the last the lowest priority".
utcTimingsArray.forEach(function (utcTiming) {
var entry = new _vo_UTCTiming__WEBPACK_IMPORTED_MODULE_6__["default"]();
if (utcTiming.hasOwnProperty(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SCHEME_ID_URI)) {
entry.schemeIdUri = utcTiming.schemeIdUri;
} else {
// entries of type DescriptorType with no schemeIdUri
// are meaningless. let's just ignore this entry and
// move on.
return;
} // this is (incorrectly) interpreted as a number - schema
// defines it as a string
if (utcTiming.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE)) {
entry.value = utcTiming.value.toString();
} else {
// without a value, there's not a lot we can do with
// this entry. let's just ignore this one and move on
return;
} // we're not interested in the optional id or any other
// attributes which might be attached to the entry
utcTimingEntries.push(entry);
});
}
}
return utcTimingEntries;
}
function getBaseURLsFromElement(node) {
var baseUrls = []; // if node.BaseURL_asArray and node.baseUri are undefined entries
// will be [undefined] which entries.some will just skip
var entries = node.BaseURL_asArray || [node.baseUri];
var earlyReturn = false;
entries.some(function (entry) {
if (entry) {
var baseUrl = new _vo_BaseURL__WEBPACK_IMPORTED_MODULE_8__["default"]();
var text = entry.__text || entry;
if (urlUtils.isRelative(text)) {
// it doesn't really make sense to have relative and
// absolute URLs at the same level, or multiple
// relative URLs at the same level, so assume we are
// done from this level of the MPD
earlyReturn = true; // deal with the specific case where the MPD@BaseURL
// is specified and is relative. when no MPD@BaseURL
// entries exist, that case is handled by the
// [node.baseUri] in the entries definition.
if (node.baseUri) {
text = urlUtils.resolve(text, node.baseUri);
}
}
baseUrl.url = text; // serviceLocation is optional, but we need it in order
// to blacklist correctly. if it's not available, use
// anything unique since there's no relationship to any
// other BaseURL and, in theory, the url should be
// unique so use this instead.
if (entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_LOCATION) && entry.serviceLocation.length) {
baseUrl.serviceLocation = entry.serviceLocation;
} else {
baseUrl.serviceLocation = text;
}
if (entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVB_PRIORITY)) {
baseUrl.dvb_priority = entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVB_PRIORITY];
}
if (entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVB_WEIGHT)) {
baseUrl.dvb_weight = entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVB_WEIGHT];
}
if (entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_TIME_OFFSET)) {
baseUrl.availabilityTimeOffset = entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_TIME_OFFSET];
}
if (entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_TIME_COMPLETE)) {
baseUrl.availabilityTimeComplete = entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_TIME_COMPLETE] !== 'false';
}
/* NOTE: byteRange currently unused
*/
baseUrls.push(baseUrl);
return earlyReturn;
}
});
return baseUrls;
}
function getLocation(manifest) {
if (manifest && manifest.hasOwnProperty(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LOCATION)) {
// for now, do not support multiple Locations -
// just set Location to the first Location.
manifest.Location = manifest.Location_asArray[0];
return manifest.Location;
} // may well be undefined
return undefined;
}
function getPatchLocation(manifest) {
if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PATCH_LOCATION)) {
// only include support for single patch location currently
manifest.PatchLocation = manifest.PatchLocation_asArray[0];
return manifest.PatchLocation;
} // no patch location provided
return undefined;
}
function getSuggestedPresentationDelay(mpd) {
return mpd && mpd.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUGGESTED_PRESENTATION_DELAY) ? mpd.suggestedPresentationDelay : null;
}
function getAvailabilityStartTime(mpd) {
return mpd && mpd.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AVAILABILITY_START_TIME) && mpd.availabilityStartTime !== null ? mpd.availabilityStartTime.getTime() : null;
}
function getServiceDescriptions(manifest) {
var serviceDescriptions = [];
if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION)) {
var _iterator = _createForOfIteratorHelper(manifest.ServiceDescription_asArray),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var sd = _step.value;
// Convert each of the properties defined in
var id = void 0,
schemeIdUri = void 0,
latency = void 0,
playbackRate = void 0;
for (var prop in sd) {
if (sd.hasOwnProperty(prop)) {
if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID) {
id = sd[prop];
} else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION_SCOPE) {
schemeIdUri = sd[prop].schemeIdUri;
} else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION_LATENCY) {
latency = {
target: sd[prop].target,
max: sd[prop].max,
min: sd[prop].min
};
} else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION_PLAYBACK_RATE) {
playbackRate = {
max: sd[prop].max,
min: sd[prop].min
};
}
}
} // we have a ServiceDescription for low latency. Add it if it really has parameters defined
if (schemeIdUri === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SERVICE_DESCRIPTION_LL_SCHEME && (latency || playbackRate)) {
serviceDescriptions.push({
id: id,
schemeIdUri: schemeIdUri,
latency: latency,
playbackRate: playbackRate
});
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return serviceDescriptions;
}
function getSupplementalProperties(adaptation) {
var supplementalProperties = {};
if (adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY)) {
var _iterator2 = _createForOfIteratorHelper(adaptation.SupplementalProperty_asArray),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var sp = _step2.value;
if (sp.hasOwnProperty(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SCHEME_ID_URI) && sp.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE)) {
supplementalProperties[sp[_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SCHEME_ID_URI]] = sp[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE];
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
return supplementalProperties;
}
function setConfig(config) {
if (!config) return;
if (config.errHandler) {
errHandler = config.errHandler;
}
if (config.BASE64) {
BASE64 = config.BASE64;
}
}
instance = {
getIsTypeOf: getIsTypeOf,
getIsText: getIsText,
getIsFragmented: getIsFragmented,
getLanguageForAdaptation: getLanguageForAdaptation,
getViewpointForAdaptation: getViewpointForAdaptation,
getRolesForAdaptation: getRolesForAdaptation,
getAccessibilityForAdaptation: getAccessibilityForAdaptation,
getAudioChannelConfigurationForAdaptation: getAudioChannelConfigurationForAdaptation,
getAudioChannelConfigurationForRepresentation: getAudioChannelConfigurationForRepresentation,
getAdaptationForIndex: getAdaptationForIndex,
getIndexForAdaptation: getIndexForAdaptation,
getAdaptationForId: getAdaptationForId,
getAdaptationsForType: getAdaptationsForType,
getRealPeriods: getRealPeriods,
getRealPeriodForIndex: getRealPeriodForIndex,
getCodec: getCodec,
getSelectionPriority: getSelectionPriority,
getMimeType: getMimeType,
getKID: getKID,
getLabelsForAdaptation: getLabelsForAdaptation,
getContentProtectionData: getContentProtectionData,
getIsDynamic: getIsDynamic,
getId: getId,
hasProfile: hasProfile,
getDuration: getDuration,
getBandwidth: getBandwidth,
getManifestUpdatePeriod: getManifestUpdatePeriod,
getPublishTime: getPublishTime,
getRepresentationCount: getRepresentationCount,
getBitrateListForAdaptation: getBitrateListForAdaptation,
getRepresentationFor: getRepresentationFor,
getRepresentationsForAdaptation: getRepresentationsForAdaptation,
getAdaptationsForPeriod: getAdaptationsForPeriod,
getRegularPeriods: getRegularPeriods,
getMpd: getMpd,
getEventsForPeriod: getEventsForPeriod,
getEssentialPropertiesForRepresentation: getEssentialPropertiesForRepresentation,
getEventStreamForAdaptationSet: getEventStreamForAdaptationSet,
getEventStreamForRepresentation: getEventStreamForRepresentation,
getUTCTimingSources: getUTCTimingSources,
getBaseURLsFromElement: getBaseURLsFromElement,
getRepresentationSortFunction: getRepresentationSortFunction,
getLocation: getLocation,
getPatchLocation: getPatchLocation,
getSuggestedPresentationDelay: getSuggestedPresentationDelay,
getAvailabilityStartTime: getAvailabilityStartTime,
getServiceDescriptions: getServiceDescriptions,
getSupplementalProperties: getSupplementalProperties,
setConfig: setConfig
};
setup();
return instance;
}
DashManifestModel.__dashjs_factory_name = 'DashManifestModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_12__["default"].getSingletonFactory(DashManifestModel));
/***/ }),
/***/ "./src/dash/models/PatchManifestModel.js":
/*!***********************************************!*\
!*** ./src/dash/models/PatchManifestModel.js ***!
\***********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _vo_SimpleXPath__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../vo/SimpleXPath */ "./src/dash/vo/SimpleXPath.js");
/* harmony import */ var _vo_PatchOperation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/PatchOperation */ "./src/dash/vo/PatchOperation.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function PatchManifestModel() {
var instance, logger;
var context = this.context;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance().getLogger(instance);
}
function getIsPatch(patch) {
return patch && patch.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].ORIGINAL_MPD_ID) || false;
}
function getPublishTime(patch) {
return patch && patch.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].PUBLISH_TIME) ? new Date(patch[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].PUBLISH_TIME]) : null;
}
function getOriginalPublishTime(patch) {
return patch && patch.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].ORIGINAL_PUBLISH_TIME) ? new Date(patch[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].ORIGINAL_PUBLISH_TIME]) : null;
}
function getMpdId(patch) {
return patch && patch[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].ORIGINAL_MPD_ID] || null;
}
function getPatchOperations(patch) {
if (!patch) {
return [];
} // Go through the patch operations in order and parse their actions out for usage
return (patch.__children || []).map(function (nodeContainer) {
var action = Object.keys(nodeContainer)[0]; // we only look add add/remove/replace actions
if (action !== 'add' && action !== 'remove' && action !== 'replace') {
logger.warn("Ignoring node of invalid action: ".concat(action));
return null;
}
var node = nodeContainer[action];
var selector = node.sel; // add action can have special targeting via the 'type' attribute
if (action === 'add' && node.type) {
if (!node.type.startsWith('@')) {
logger.warn("Ignoring add action for prefixed namespace declaration: ".concat(node.type, "=").concat(node.__text));
return null;
} // for our purposes adding/replacing attribute are equivalent and we can normalize
// our processing logic by appending the attribute to the selector path
selector = "".concat(selector, "/").concat(node.type);
}
var xpath = new _vo_SimpleXPath__WEBPACK_IMPORTED_MODULE_3__["default"](selector);
if (!xpath.isValid()) {
logger.warn("Ignoring action with invalid selector: ".concat(action, " - ").concat(selector));
return null;
}
var value = null;
if (xpath.findsAttribute()) {
value = node.__text || '';
} else if (action !== 'remove') {
value = node.__children.reduce(function (groups, child) {
// note that this is informed by xml2js parse structure for the __children array
// which will be something like this for each child:
// {
// "<node-name>": { <xml2js-node-object> }
// }
var key = Object.keys(child)[0]; // we also ignore
if (key !== '#text') {
groups[key] = groups[key] || [];
groups[key].push(child[key]);
}
return groups;
}, {});
}
var operation = new _vo_PatchOperation__WEBPACK_IMPORTED_MODULE_4__["default"](action, xpath, value);
if (action === 'add') {
operation.position = node.pos;
}
return operation;
}).filter(function (operation) {
return !!operation;
});
}
instance = {
getIsPatch: getIsPatch,
getPublishTime: getPublishTime,
getOriginalPublishTime: getOriginalPublishTime,
getMpdId: getMpdId,
getPatchOperations: getPatchOperations
};
setup();
return instance;
}
PatchManifestModel.__dashjs_factory_name = 'PatchManifestModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getSingletonFactory(PatchManifestModel));
/***/ }),
/***/ "./src/dash/parser/DashParser.js":
/*!***************************************!*\
!*** ./src/dash/parser/DashParser.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _objectiron__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./objectiron */ "./src/dash/parser/objectiron.js");
/* harmony import */ var _externals_xml2json__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../externals/xml2json */ "./externals/xml2json.js");
/* harmony import */ var _matchers_StringMatcher__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./matchers/StringMatcher */ "./src/dash/parser/matchers/StringMatcher.js");
/* harmony import */ var _matchers_DurationMatcher__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./matchers/DurationMatcher */ "./src/dash/parser/matchers/DurationMatcher.js");
/* harmony import */ var _matchers_DateTimeMatcher__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./matchers/DateTimeMatcher */ "./src/dash/parser/matchers/DateTimeMatcher.js");
/* harmony import */ var _matchers_NumericMatcher__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./matchers/NumericMatcher */ "./src/dash/parser/matchers/NumericMatcher.js");
/* harmony import */ var _maps_RepresentationBaseValuesMap__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./maps/RepresentationBaseValuesMap */ "./src/dash/parser/maps/RepresentationBaseValuesMap.js");
/* harmony import */ var _maps_SegmentValuesMap__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./maps/SegmentValuesMap */ "./src/dash/parser/maps/SegmentValuesMap.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function DashParser(config) {
config = config || {};
var context = this.context;
var debug = config.debug;
var instance, logger, matchers, converter, objectIron;
function setup() {
logger = debug.getLogger(instance);
matchers = [new _matchers_DurationMatcher__WEBPACK_IMPORTED_MODULE_4__["default"](), new _matchers_DateTimeMatcher__WEBPACK_IMPORTED_MODULE_5__["default"](), new _matchers_NumericMatcher__WEBPACK_IMPORTED_MODULE_6__["default"](), new _matchers_StringMatcher__WEBPACK_IMPORTED_MODULE_3__["default"]() // last in list to take precedence over NumericMatcher
];
converter = new _externals_xml2json__WEBPACK_IMPORTED_MODULE_2__["default"]({
escapeMode: false,
attributePrefix: '',
arrayAccessForm: 'property',
emptyNodeForm: 'object',
stripWhitespaces: false,
enableToStringFunc: true,
ignoreRoot: false,
matchers: matchers
});
objectIron = Object(_objectiron__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
adaptationset: new _maps_RepresentationBaseValuesMap__WEBPACK_IMPORTED_MODULE_7__["default"](),
period: new _maps_SegmentValuesMap__WEBPACK_IMPORTED_MODULE_8__["default"]()
});
}
function getMatchers() {
return matchers;
}
function getIron() {
return objectIron;
}
function parse(data) {
var manifest;
var startTime = window.performance.now();
manifest = converter.xml_str2json(data);
if (!manifest) {
throw new Error('parsing the manifest failed');
}
var jsonTime = window.performance.now(); // handle full MPD and Patch ironing separately
if (manifest.Patch) {
manifest = manifest.Patch; // drop root reference
// apply iron to patch operations individually
if (manifest.add_asArray) {
manifest.add_asArray.forEach(function (operand) {
return objectIron.run(operand);
});
}
if (manifest.replace_asArray) {
manifest.replace_asArray.forEach(function (operand) {
return objectIron.run(operand);
});
} // note that we don't need to iron remove as they contain no children
} else {
manifest = manifest.MPD; // drop root reference
objectIron.run(manifest);
}
var ironedTime = window.performance.now();
logger.info('Parsing complete: ( xml2json: ' + (jsonTime - startTime).toPrecision(3) + 'ms, objectiron: ' + (ironedTime - jsonTime).toPrecision(3) + 'ms, total: ' + ((ironedTime - startTime) / 1000).toPrecision(3) + 's)');
manifest.protocol = 'DASH';
return manifest;
}
instance = {
parse: parse,
getMatchers: getMatchers,
getIron: getIron
};
setup();
return instance;
}
DashParser.__dashjs_factory_name = 'DashParser';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(DashParser));
/***/ }),
/***/ "./src/dash/parser/maps/CommonProperty.js":
/*!************************************************!*\
!*** ./src/dash/parser/maps/CommonProperty.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc a property belonging to a MapNode
* @ignore
*/
var CommonProperty = /*#__PURE__*/function () {
function CommonProperty(name) {
_classCallCheck(this, CommonProperty);
var getDefaultMergeForName = function getDefaultMergeForName(n) {
return n && n.length && n.charAt(0) === n.charAt(0).toUpperCase();
};
this._name = name;
this._merge = getDefaultMergeForName(name);
}
_createClass(CommonProperty, [{
key: "name",
get: function get() {
return this._name;
}
}, {
key: "merge",
get: function get() {
return this._merge;
}
}]);
return CommonProperty;
}();
/* harmony default export */ __webpack_exports__["default"] = (CommonProperty);
/***/ }),
/***/ "./src/dash/parser/maps/MapNode.js":
/*!*****************************************!*\
!*** ./src/dash/parser/maps/MapNode.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _CommonProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./CommonProperty */ "./src/dash/parser/maps/CommonProperty.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc a node at some level in a ValueMap
*/
var MapNode = /*#__PURE__*/function () {
function MapNode(name, properties, children) {
var _this = this;
_classCallCheck(this, MapNode);
this._name = name || '';
this._properties = [];
this._children = children || [];
if (Array.isArray(properties)) {
properties.forEach(function (p) {
_this._properties.push(new _CommonProperty__WEBPACK_IMPORTED_MODULE_0__["default"](p));
});
}
}
_createClass(MapNode, [{
key: "name",
get: function get() {
return this._name;
}
}, {
key: "children",
get: function get() {
return this._children;
}
}, {
key: "properties",
get: function get() {
return this._properties;
}
}]);
return MapNode;
}();
/* harmony default export */ __webpack_exports__["default"] = (MapNode);
/***/ }),
/***/ "./src/dash/parser/maps/RepresentationBaseValuesMap.js":
/*!*************************************************************!*\
!*** ./src/dash/parser/maps/RepresentationBaseValuesMap.js ***!
\*************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _MapNode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./MapNode */ "./src/dash/parser/maps/MapNode.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc a RepresentationBaseValuesMap type for input to objectiron
*/
var RepresentationBaseValuesMap = /*#__PURE__*/function (_MapNode) {
_inherits(RepresentationBaseValuesMap, _MapNode);
var _super = _createSuper(RepresentationBaseValuesMap);
function RepresentationBaseValuesMap() {
_classCallCheck(this, RepresentationBaseValuesMap);
var commonProperties = [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PROFILES, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].WIDTH, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].HEIGHT, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SAR, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].FRAMERATE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO_SAMPLING_RATE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MIME_TYPE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_PROFILES, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CODECS, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MAXIMUM_SAP_PERIOD, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].START_WITH_SAP, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MAX_PLAYOUT_RATE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CODING_DEPENDENCY, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SCAN_TYPE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].FRAME_PACKING, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO_CHANNEL_CONFIGURATION, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_PROTECTION, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ESSENTIAL_PROPERTY, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INBAND_EVENT_STREAM];
return _super.call(this, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ADAPTATION_SET, commonProperties, [new _MapNode__WEBPACK_IMPORTED_MODULE_0__["default"](_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION, commonProperties, [new _MapNode__WEBPACK_IMPORTED_MODULE_0__["default"](_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUB_REPRESENTATION, commonProperties)])]);
}
return RepresentationBaseValuesMap;
}(_MapNode__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (RepresentationBaseValuesMap);
/***/ }),
/***/ "./src/dash/parser/maps/SegmentValuesMap.js":
/*!**************************************************!*\
!*** ./src/dash/parser/maps/SegmentValuesMap.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _MapNode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./MapNode */ "./src/dash/parser/maps/MapNode.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc a SegmentValuesMap type for input to objectiron
*/
var SegmentValuesMap = /*#__PURE__*/function (_MapNode) {
_inherits(SegmentValuesMap, _MapNode);
var _super = _createSuper(SegmentValuesMap);
function SegmentValuesMap() {
_classCallCheck(this, SegmentValuesMap);
var commonProperties = [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_LIST];
return _super.call(this, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PERIOD, commonProperties, [new _MapNode__WEBPACK_IMPORTED_MODULE_0__["default"](_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ADAPTATION_SET, commonProperties, [new _MapNode__WEBPACK_IMPORTED_MODULE_0__["default"](_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION, commonProperties)])]);
}
return SegmentValuesMap;
}(_MapNode__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (SegmentValuesMap);
/***/ }),
/***/ "./src/dash/parser/matchers/BaseMatcher.js":
/*!*************************************************!*\
!*** ./src/dash/parser/matchers/BaseMatcher.js ***!
\*************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc a base type for matching and converting types in manifest to
* something more useful
* @ignore
*/
var BaseMatcher = /*#__PURE__*/function () {
function BaseMatcher(test, converter) {
_classCallCheck(this, BaseMatcher);
this._test = test;
this._converter = converter;
}
_createClass(BaseMatcher, [{
key: "test",
get: function get() {
return this._test;
}
}, {
key: "converter",
get: function get() {
return this._converter;
}
}]);
return BaseMatcher;
}();
/* harmony default export */ __webpack_exports__["default"] = (BaseMatcher);
/***/ }),
/***/ "./src/dash/parser/matchers/DateTimeMatcher.js":
/*!*****************************************************!*\
!*** ./src/dash/parser/matchers/DateTimeMatcher.js ***!
\*****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _BaseMatcher__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BaseMatcher */ "./src/dash/parser/matchers/BaseMatcher.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc matches and converts xs:datetime to Date
*/
var SECONDS_IN_MIN = 60;
var MINUTES_IN_HOUR = 60;
var MILLISECONDS_IN_SECONDS = 1000;
var datetimeRegex = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\.[0-9]*)?)?(?:([+-])([0-9]{2})(?::?)([0-9]{2}))?/;
var DateTimeMatcher = /*#__PURE__*/function (_BaseMatcher) {
_inherits(DateTimeMatcher, _BaseMatcher);
var _super = _createSuper(DateTimeMatcher);
function DateTimeMatcher() {
_classCallCheck(this, DateTimeMatcher);
return _super.call(this, function (attr) {
return datetimeRegex.test(attr.value);
}, function (str) {
var match = datetimeRegex.exec(str);
var utcDate; // If the string does not contain a timezone offset different browsers can interpret it either
// as UTC or as a local time so we have to parse the string manually to normalize the given date value for
// all browsers
utcDate = Date.UTC(parseInt(match[1], 10), parseInt(match[2], 10) - 1, // months start from zero
parseInt(match[3], 10), parseInt(match[4], 10), parseInt(match[5], 10), match[6] && parseInt(match[6], 10) || 0, match[7] && parseFloat(match[7]) * MILLISECONDS_IN_SECONDS || 0); // If the date has timezone offset take it into account as well
if (match[9] && match[10]) {
var timezoneOffset = parseInt(match[9], 10) * MINUTES_IN_HOUR + parseInt(match[10], 10);
utcDate += (match[8] === '+' ? -1 : +1) * timezoneOffset * SECONDS_IN_MIN * MILLISECONDS_IN_SECONDS;
}
return new Date(utcDate);
});
}
return DateTimeMatcher;
}(_BaseMatcher__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (DateTimeMatcher);
/***/ }),
/***/ "./src/dash/parser/matchers/DurationMatcher.js":
/*!*****************************************************!*\
!*** ./src/dash/parser/matchers/DurationMatcher.js ***!
\*****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _BaseMatcher__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BaseMatcher */ "./src/dash/parser/matchers/BaseMatcher.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc matches and converts xs:duration to seconds
*/
var durationRegex = /^([-])?P(([\d.]*)Y)?(([\d.]*)M)?(([\d.]*)D)?T?(([\d.]*)H)?(([\d.]*)M)?(([\d.]*)S)?/;
var SECONDS_IN_YEAR = 365 * 24 * 60 * 60;
var SECONDS_IN_MONTH = 30 * 24 * 60 * 60;
var SECONDS_IN_DAY = 24 * 60 * 60;
var SECONDS_IN_HOUR = 60 * 60;
var SECONDS_IN_MIN = 60;
var DurationMatcher = /*#__PURE__*/function (_BaseMatcher) {
_inherits(DurationMatcher, _BaseMatcher);
var _super = _createSuper(DurationMatcher);
function DurationMatcher() {
_classCallCheck(this, DurationMatcher);
return _super.call(this, function (attr) {
var attributeList = [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].MIN_BUFFER_TIME, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].MEDIA_PRESENTATION_DURATION, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].MINIMUM_UPDATE_PERIOD, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].TIMESHIFT_BUFFER_DEPTH, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].MAX_SEGMENT_DURATION, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].MAX_SUBSEGMENT_DURATION, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].SUGGESTED_PRESENTATION_DELAY, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].START, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].START_TIME, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"].DURATION];
var len = attributeList.length;
for (var i = 0; i < len; i++) {
if (attr.nodeName === attributeList[i]) {
return durationRegex.test(attr.value);
}
}
return false;
}, function (str) {
//str = "P10Y10M10DT10H10M10.1S";
var match = durationRegex.exec(str);
var result = parseFloat(match[3] || 0) * SECONDS_IN_YEAR + parseFloat(match[5] || 0) * SECONDS_IN_MONTH + parseFloat(match[7] || 0) * SECONDS_IN_DAY + parseFloat(match[9] || 0) * SECONDS_IN_HOUR + parseFloat(match[11] || 0) * SECONDS_IN_MIN + parseFloat(match[13] || 0);
if (match[1] !== undefined) {
result = -result;
}
return result;
});
}
return DurationMatcher;
}(_BaseMatcher__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (DurationMatcher);
/***/ }),
/***/ "./src/dash/parser/matchers/NumericMatcher.js":
/*!****************************************************!*\
!*** ./src/dash/parser/matchers/NumericMatcher.js ***!
\****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _BaseMatcher__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BaseMatcher */ "./src/dash/parser/matchers/BaseMatcher.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Matches and converts xs:numeric to float
*/
var numericRegex = /^[-+]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?$/;
var NumericMatcher = /*#__PURE__*/function (_BaseMatcher) {
_inherits(NumericMatcher, _BaseMatcher);
var _super = _createSuper(NumericMatcher);
function NumericMatcher() {
_classCallCheck(this, NumericMatcher);
return _super.call(this, function (attr) {
return numericRegex.test(attr.value);
}, function (str) {
return parseFloat(str);
});
}
return NumericMatcher;
}(_BaseMatcher__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (NumericMatcher);
/***/ }),
/***/ "./src/dash/parser/matchers/StringMatcher.js":
/*!***************************************************!*\
!*** ./src/dash/parser/matchers/StringMatcher.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _BaseMatcher__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BaseMatcher */ "./src/dash/parser/matchers/BaseMatcher.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Matches and converts xs:string to string, but only for specific attributes on specific nodes
*/
var StringMatcher = /*#__PURE__*/function (_BaseMatcher) {
_inherits(StringMatcher, _BaseMatcher);
var _super = _createSuper(StringMatcher);
function StringMatcher() {
_classCallCheck(this, StringMatcher);
return _super.call(this, function (attr, nodeName) {
var _stringAttrsInElement;
var stringAttrsInElements = (_stringAttrsInElement = {}, _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MPD, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PROFILES]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PERIOD, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BASE_URL, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_LOCATION, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BYTE_RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INDEX_RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INITIALIZATION, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION_INDEX, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_LIST, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INDEX_RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BITSTREAM_SWITCHING, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_URL, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MEDIA_RANGE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INDEX_RANGE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INDEX_RANGE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MEDIA, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INDEX, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INITIALIZATION_MINUS, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BITSTREAM_SWITCHING_MINUS]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ASSET_IDENTIFIER, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].EVENT_STREAM, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ADAPTATION_SET, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PROFILES, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MIME_TYPE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_PROFILES, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CODECS, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_TYPE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].FRAME_PACKING, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO_CHANNEL_CONFIGURATION, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_PROTECTION, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ESSENTIAL_PROPERTY, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INBAND_EVENT_STREAM, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ACCESSIBILITY, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ROLE, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].RATING, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VIEWPOINT, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_COMPONENT, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_TYPE]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DEPENDENCY_ID, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MEDIA_STREAM_STRUCTURE_ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUBSET, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].METRICS, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].METRICS_MINUS]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPORTING, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VALUE, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID]), _stringAttrsInElement);
if (stringAttrsInElements.hasOwnProperty(nodeName)) {
var attrNames = stringAttrsInElements[nodeName];
if (attrNames !== undefined) {
return attrNames.indexOf(attr.name) >= 0;
} else {
return false;
}
}
return false;
}, function (str) {
return String(str);
});
}
return StringMatcher;
}(_BaseMatcher__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (StringMatcher);
/***/ }),
/***/ "./src/dash/parser/objectiron.js":
/*!***************************************!*\
!*** ./src/dash/parser/objectiron.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ObjectIron(mappers) {
function mergeValues(parentItem, childItem) {
for (var name in parentItem) {
if (!childItem.hasOwnProperty(name)) {
childItem[name] = parentItem[name];
}
}
}
function mapProperties(properties, parent, child) {
for (var i = 0, len = properties.length; i < len; ++i) {
var property = properties[i];
if (parent[property.name]) {
if (child[property.name]) {
// check to see if we should merge
if (property.merge) {
var parentValue = parent[property.name];
var childValue = child[property.name]; // complex objects; merge properties
if (_typeof(parentValue) === 'object' && _typeof(childValue) === 'object') {
mergeValues(parentValue, childValue);
} // simple objects; merge them together
else {
child[property.name] = parentValue + childValue;
}
}
} else {
// just add the property
child[property.name] = parent[property.name];
}
}
}
}
function mapItem(item, node) {
for (var i = 0, len = item.children.length; i < len; ++i) {
var childItem = item.children[i];
var array = node[childItem.name + '_asArray'];
if (array) {
for (var v = 0, len2 = array.length; v < len2; ++v) {
var childNode = array[v];
mapProperties(item.properties, node, childNode);
mapItem(childItem, childNode);
}
}
}
}
function run(source) {
if (source === null || _typeof(source) !== 'object') {
return source;
}
if (source.Period_asArray && 'period' in mappers) {
var periodMapper = mappers.period;
var periods = source.Period_asArray;
for (var i = 0, len = periods.length; i < len; ++i) {
var period = periods[i];
mapItem(periodMapper, period);
if ('adaptationset' in mappers) {
var adaptationSets = period.AdaptationSet_asArray;
if (adaptationSets) {
var adaptationSetMapper = mappers.adaptationset;
for (var _i = 0, _len = adaptationSets.length; _i < _len; ++_i) {
mapItem(adaptationSetMapper, adaptationSets[_i]);
}
}
}
}
}
return source;
}
return {
run: run
};
}
ObjectIron.__dashjs_factory_name = 'ObjectIron';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(ObjectIron);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/utils/ListSegmentsGetter.js":
/*!**********************************************!*\
!*** ./src/dash/utils/ListSegmentsGetter.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ListSegmentsGetter(config, isDynamic) {
config = config || {};
var timelineConverter = config.timelineConverter;
var instance;
function checkConfig() {
if (!timelineConverter || !timelineConverter.hasOwnProperty('calcPeriodRelativeTimeFromMpdRelativeTime')) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].MISSING_CONFIG_ERROR);
}
}
function getMediaFinishedInformation(representation) {
var mediaFinishedInformation = {
numberOfSegments: 0,
mediaTimeOfLastSignaledSegment: NaN
};
if (!representation) {
return mediaFinishedInformation;
}
var list = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentList;
var startNumber = representation && !isNaN(representation.startNumber) ? representation.startNumber : 1;
var offset = Math.max(startNumber - 1, 0);
mediaFinishedInformation.numberOfSegments = offset + list.SegmentURL_asArray.length;
return mediaFinishedInformation;
}
function getSegmentByIndex(representation, index) {
checkConfig();
if (!representation) {
return null;
}
var list = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentList;
var len = list.SegmentURL_asArray.length;
var startNumber = representation && !isNaN(representation.startNumber) ? representation.startNumber : 1;
var offsetToSubtract = Math.max(startNumber - 1, 0);
var relativeIndex = Math.max(index - offsetToSubtract, 0);
var segment = null;
if (relativeIndex < len) {
var s = list.SegmentURL_asArray[relativeIndex];
segment = Object(_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__["getIndexBasedSegment"])(timelineConverter, isDynamic, representation, index);
if (segment) {
segment.replacementTime = (startNumber + index - 1) * representation.segmentDuration;
segment.media = s.media ? s.media : '';
segment.mediaRange = s.mediaRange;
segment.indexRange = s.indexRange;
}
}
return segment;
}
function getSegmentByTime(representation, requestedTime) {
checkConfig();
if (!representation) {
return null;
}
var duration = representation.segmentDuration;
if (isNaN(duration)) {
return null;
}
var periodTime = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, requestedTime);
var index = Math.floor(periodTime / duration);
return getSegmentByIndex(representation, index);
}
instance = {
getSegmentByIndex: getSegmentByIndex,
getSegmentByTime: getSegmentByTime,
getMediaFinishedInformation: getMediaFinishedInformation
};
return instance;
}
ListSegmentsGetter.__dashjs_factory_name = 'ListSegmentsGetter';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(ListSegmentsGetter);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/utils/Round10.js":
/*!***********************************!*\
!*** ./src/dash/utils/Round10.js ***!
\***********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Round10; });
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Static methods for rounding decimals
*
* Modified version of the CC0-licenced example at:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
*
* @export
* @class Round10
* @ignore
*/
var Round10 = /*#__PURE__*/function () {
function Round10() {
_classCallCheck(this, Round10);
}
_createClass(Round10, null, [{
key: "round10",
value:
/**
* Decimal round.
*
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
* @returns {Number} The adjusted value.
* @ignore
*/
function round10(value, exp) {
return _decimalAdjust('round', value, exp);
}
}]);
return Round10;
}();
/**
* Decimal adjustment of a number.
*
* @param {String} type The type of adjustment.
* @param {Number} value The number.
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
* @returns {Number} The adjusted value.
* @ignore
*/
function _decimalAdjust(type, value, exp) {
// If the exp is undefined or zero...
if (typeof exp === 'undefined' || +exp === 0) {
return Math[type](value);
}
value = +value;
exp = +exp; // If the value is not a number or the exp is not an integer...
if (value === null || isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
return NaN;
} // Shift
value = value.toString().split('e');
value = Math[type](+(value[0] + 'e' + (value[1] ? +value[1] - exp : -exp))); // Shift back
value = value.toString().split('e');
return +(value[0] + 'e' + (value[1] ? +value[1] + exp : exp));
}
/***/ }),
/***/ "./src/dash/utils/SegmentBaseGetter.js":
/*!*********************************************!*\
!*** ./src/dash/utils/SegmentBaseGetter.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function SegmentBaseGetter(config) {
config = config || {};
var timelineConverter = config.timelineConverter;
var instance;
function checkConfig() {
if (!timelineConverter || !timelineConverter.hasOwnProperty('calcPeriodRelativeTimeFromMpdRelativeTime')) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].MISSING_CONFIG_ERROR);
}
}
function getMediaFinishedInformation(representation) {
var mediaFinishedInformation = {
numberOfSegments: 0,
mediaTimeOfLastSignaledSegment: NaN
};
if (!representation || !representation.segments) {
return mediaFinishedInformation;
}
mediaFinishedInformation.numberOfSegments = representation.segments.length;
return mediaFinishedInformation;
}
function getSegmentByIndex(representation, index) {
checkConfig();
if (!representation) {
return null;
}
var len = representation.segments ? representation.segments.length : -1;
var seg;
if (index < len) {
seg = representation.segments[index];
if (seg && seg.index === index) {
return seg;
}
}
for (var i = 0; i < len; i++) {
seg = representation.segments[i];
if (seg && seg.index === index) {
return seg;
}
}
return null;
}
function getSegmentByTime(representation, requestedTime) {
checkConfig();
var index = getIndexByTime(representation, requestedTime);
return getSegmentByIndex(representation, index);
}
function getIndexByTime(representation, time) {
if (!representation) {
return -1;
}
var segments = representation.segments;
var ln = segments ? segments.length : null;
var idx = -1;
var epsilon, seg, ft, fd, i;
if (segments && ln > 0) {
for (i = 0; i < ln; i++) {
seg = segments[i];
ft = seg.presentationStartTime;
fd = seg.duration;
epsilon = fd / 2;
if (time + epsilon >= ft && time - epsilon < ft + fd) {
idx = seg.index;
break;
}
}
}
return idx;
}
instance = {
getSegmentByIndex: getSegmentByIndex,
getSegmentByTime: getSegmentByTime,
getMediaFinishedInformation: getMediaFinishedInformation
};
return instance;
}
SegmentBaseGetter.__dashjs_factory_name = 'SegmentBaseGetter';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(SegmentBaseGetter);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/utils/SegmentsUtils.js":
/*!*****************************************!*\
!*** ./src/dash/utils/SegmentsUtils.js ***!
\*****************************************/
/*! exports provided: unescapeDollarsInTemplate, replaceIDForTemplate, replaceTokenForTemplate, getIndexBasedSegment, getTimeBasedSegment */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "unescapeDollarsInTemplate", function() { return unescapeDollarsInTemplate; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replaceIDForTemplate", function() { return replaceIDForTemplate; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replaceTokenForTemplate", function() { return replaceTokenForTemplate; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getIndexBasedSegment", function() { return getIndexBasedSegment; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getTimeBasedSegment", function() { return getTimeBasedSegment; });
/* harmony import */ var _vo_Segment__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../vo/Segment */ "./src/dash/vo/Segment.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function zeroPadToLength(numStr, minStrLength) {
while (numStr.length < minStrLength) {
numStr = '0' + numStr;
}
return numStr;
}
function getNumberForSegment(segment, segmentIndex) {
return segment.representation.startNumber + segmentIndex;
}
function unescapeDollarsInTemplate(url) {
return url ? url.split('$$').join('$') : url;
}
function replaceIDForTemplate(url, value) {
if (!value || !url || url.indexOf('$RepresentationID$') === -1) {
return url;
}
var v = value.toString();
return url.split('$RepresentationID$').join(v);
}
function replaceTokenForTemplate(url, token, value) {
var formatTag = '%0';
var startPos, endPos, formatTagPos, specifier, width, paddedValue;
var tokenLen = token.length;
var formatTagLen = formatTag.length;
if (!url) {
return url;
} // keep looping round until all instances of <token> have been
// replaced. once that has happened, startPos below will be -1
// and the completed url will be returned.
while (true) {
// check if there is a valid $<token>...$ identifier
// if not, return the url as is.
startPos = url.indexOf('$' + token);
if (startPos < 0) {
return url;
} // the next '$' must be the end of the identifier
// if there isn't one, return the url as is.
endPos = url.indexOf('$', startPos + tokenLen);
if (endPos < 0) {
return url;
} // now see if there is an additional format tag suffixed to
// the identifier within the enclosing '$' characters
formatTagPos = url.indexOf(formatTag, startPos + tokenLen);
if (formatTagPos > startPos && formatTagPos < endPos) {
specifier = url.charAt(endPos - 1);
width = parseInt(url.substring(formatTagPos + formatTagLen, endPos - 1), 10); // support the minimum specifiers required by IEEE 1003.1
// (d, i , o, u, x, and X) for completeness
switch (specifier) {
// treat all int types as uint,
// hence deliberate fallthrough
case 'd':
case 'i':
case 'u':
paddedValue = zeroPadToLength(value.toString(), width);
break;
case 'x':
paddedValue = zeroPadToLength(value.toString(16), width);
break;
case 'X':
paddedValue = zeroPadToLength(value.toString(16), width).toUpperCase();
break;
case 'o':
paddedValue = zeroPadToLength(value.toString(8), width);
break;
default:
return url;
}
} else {
paddedValue = value;
}
url = url.substring(0, startPos) + paddedValue + url.substring(endPos + 1);
}
}
function getSegment(representation, duration, presentationStartTime, mediaStartTime, timelineConverter, presentationEndTime, isDynamic, index) {
var seg = new _vo_Segment__WEBPACK_IMPORTED_MODULE_0__["default"]();
seg.representation = representation;
seg.duration = duration;
seg.presentationStartTime = presentationStartTime;
seg.mediaStartTime = mediaStartTime;
seg.availabilityStartTime = timelineConverter.calcAvailabilityStartTimeFromPresentationTime(presentationEndTime, representation, isDynamic);
seg.availabilityEndTime = timelineConverter.calcAvailabilityEndTimeFromPresentationTime(presentationEndTime + duration, representation, isDynamic);
seg.wallStartTime = timelineConverter.calcWallTimeForSegment(seg, isDynamic);
seg.replacementNumber = getNumberForSegment(seg, index);
seg.index = index;
return seg;
}
function isSegmentAvailable(timelineConverter, representation, segment, isDynamic) {
var voPeriod = representation.adaptation.period; // Avoid requesting segments that overlap the period boundary
if (isFinite(voPeriod.duration) && voPeriod.start + voPeriod.duration <= segment.presentationStartTime) {
return false;
}
if (isDynamic) {
if (representation.availabilityTimeOffset === 'INF') {
return true;
} // For dynamic manifests we check if the presentation start time + duration is included in the availability window
// SAST = Period@start + seg@presentationStartTime + seg@duration
// ASAST = SAST - ATO
// SAET = SAST + TSBD + seg@duration
// refTime serves as an anchor time to compare the availability time of the segments against.
var refTime = timelineConverter.getClientReferenceTime();
return segment.availabilityStartTime.getTime() <= refTime && (!isFinite(segment.availabilityEndTime) || segment.availabilityEndTime.getTime() >= refTime);
}
return true;
}
function getIndexBasedSegment(timelineConverter, isDynamic, representation, index) {
var duration, presentationStartTime, presentationEndTime;
duration = representation.segmentDuration;
/*
* From spec - If neither @duration attribute nor SegmentTimeline element is present, then the Representation
* shall contain exactly one Media Segment. The MPD start time is 0 and the MPD duration is obtained
* in the same way as for the last Media Segment in the Representation.
*/
if (isNaN(duration)) {
duration = representation.adaptation.period.duration;
}
presentationStartTime = parseFloat((representation.adaptation.period.start + index * duration).toFixed(5));
presentationEndTime = parseFloat((presentationStartTime + duration).toFixed(5));
var mediaTime = timelineConverter.calcMediaTimeFromPresentationTime(presentationStartTime, representation);
var segment = getSegment(representation, duration, presentationStartTime, mediaTime, timelineConverter, presentationEndTime, isDynamic, index);
if (!isSegmentAvailable(timelineConverter, representation, segment, isDynamic)) {
return null;
}
return segment;
}
function getTimeBasedSegment(timelineConverter, isDynamic, representation, time, duration, fTimescale, url, range, index, tManifest) {
var scaledTime = time / fTimescale;
var scaledDuration = duration / fTimescale;
var presentationStartTime, presentationEndTime, seg;
presentationStartTime = timelineConverter.calcPresentationTimeFromMediaTime(scaledTime, representation);
presentationEndTime = presentationStartTime + scaledDuration;
seg = getSegment(representation, scaledDuration, presentationStartTime, scaledTime, timelineConverter, presentationEndTime, isDynamic, index);
if (!isSegmentAvailable(timelineConverter, representation, seg, isDynamic)) {
return null;
}
seg.replacementTime = tManifest ? tManifest : time;
url = replaceTokenForTemplate(url, 'Number', seg.replacementNumber);
url = replaceTokenForTemplate(url, 'Time', seg.replacementTime);
seg.media = url;
seg.mediaRange = range;
return seg;
}
/***/ }),
/***/ "./src/dash/utils/TemplateSegmentsGetter.js":
/*!**************************************************!*\
!*** ./src/dash/utils/TemplateSegmentsGetter.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TemplateSegmentsGetter(config, isDynamic) {
config = config || {};
var timelineConverter = config.timelineConverter;
var instance;
function checkConfig() {
if (!timelineConverter || !timelineConverter.hasOwnProperty('calcPeriodRelativeTimeFromMpdRelativeTime')) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].MISSING_CONFIG_ERROR);
}
}
function getMediaFinishedInformation(representation) {
var mediaFinishedInformation = {
numberOfSegments: 0,
mediaTimeOfLastSignaledSegment: NaN
};
if (!representation) {
return mediaFinishedInformation;
}
var duration = representation.segmentDuration;
if (isNaN(duration)) {
mediaFinishedInformation.numberOfSegments = 1;
} else {
mediaFinishedInformation.numberOfSegments = Math.ceil(representation.adaptation.period.duration / duration);
}
return mediaFinishedInformation;
}
function getSegmentByIndex(representation, index) {
checkConfig();
if (!representation) {
return null;
}
var template = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentTemplate; // This is the index without @startNumber
index = Math.max(index, 0);
var seg = Object(_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__["getIndexBasedSegment"])(timelineConverter, isDynamic, representation, index);
if (seg) {
seg.replacementTime = Math.round((index - 1) * representation.segmentDuration * representation.timescale, 10);
var url = template.media;
url = Object(_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__["replaceTokenForTemplate"])(url, 'Number', seg.replacementNumber);
url = Object(_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__["replaceTokenForTemplate"])(url, 'Time', seg.replacementTime);
seg.media = url;
}
return seg;
}
function getSegmentByTime(representation, requestedTime) {
checkConfig();
if (!representation) {
return null;
}
var duration = representation.segmentDuration;
if (isNaN(duration)) {
return null;
} // Calculate the relative time for the requested time in this period
var periodTime = timelineConverter.calcPeriodRelativeTimeFromMpdRelativeTime(representation, requestedTime);
var index = Math.floor(periodTime / duration);
return getSegmentByIndex(representation, index);
}
instance = {
getSegmentByIndex: getSegmentByIndex,
getSegmentByTime: getSegmentByTime,
getMediaFinishedInformation: getMediaFinishedInformation
};
return instance;
}
TemplateSegmentsGetter.__dashjs_factory_name = 'TemplateSegmentsGetter';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(TemplateSegmentsGetter);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/utils/TimelineConverter.js":
/*!*********************************************!*\
!*** ./src/dash/utils/TimelineConverter.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _models_DashManifestModel__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../models/DashManifestModel */ "./src/dash/models/DashManifestModel.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _streaming_constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../streaming/constants/ConformanceViolationConstants */ "./src/streaming/constants/ConformanceViolationConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TimelineConverter() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
var instance, dashManifestModel, timelineAnchorAvailabilityOffset, // In case we calculate the TSBD using _calcTimeShiftBufferWindowForDynamicTimelineManifest we use the segments as anchor times. We apply this offset when calculating if a segment is available or not.
clientServerTimeShift;
function setup() {
dashManifestModel = Object(_models_DashManifestModel__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
reset();
}
function initialize() {
resetInitialSettings();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].UPDATE_TIME_SYNC_OFFSET, _onUpdateTimeSyncOffset, this);
}
function getClientTimeOffset() {
return clientServerTimeShift;
}
function setClientTimeOffset(value) {
clientServerTimeShift = value;
}
/**
* Returns a "now" reference time for the client to compare the availability time of a segment against.
* Takes the client/server drift into account
*/
function getClientReferenceTime() {
return Date.now() - timelineAnchorAvailabilityOffset * 1000 + clientServerTimeShift * 1000;
}
function _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic, calculateAvailabilityEndTime) {
var availabilityTime;
var mpd = representation.adaptation.period.mpd;
var availabilityStartTime = mpd.availabilityStartTime;
if (calculateAvailabilityEndTime) {
//@timeShiftBufferDepth specifies the duration of the time shifting buffer that is guaranteed
// to be available for a Media Presentation with type 'dynamic'.
// When not present, the value is infinite.
if (isDynamic && mpd.timeShiftBufferDepth !== Number.POSITIVE_INFINITY) {
// SAET = SAST + TSBD + seg@duration
availabilityTime = new Date(availabilityStartTime.getTime() + (presentationEndTime + mpd.timeShiftBufferDepth) * 1000);
} else {
availabilityTime = mpd.availabilityEndTime;
}
} else {
if (isDynamic) {
// SAST = Period@start + seg@presentationStartTime + seg@duration
// ASAST = SAST - ATO
var availabilityTimeOffset = representation.availabilityTimeOffset; // presentationEndTime = Period@start + seg@presentationStartTime + Segment@duration
availabilityTime = new Date(availabilityStartTime.getTime() + (presentationEndTime - availabilityTimeOffset) * 1000);
} else {
// in static mpd, all segments are available at the same time
availabilityTime = availabilityStartTime;
}
}
return availabilityTime;
}
function calcAvailabilityStartTimeFromPresentationTime(presentationEndTime, representation, isDynamic) {
return _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic);
}
function calcAvailabilityEndTimeFromPresentationTime(presentationEndTime, representation, isDynamic) {
return _calcAvailabilityTimeFromPresentationTime(presentationEndTime, representation, isDynamic, true);
}
function calcPresentationTimeFromWallTime(wallTime, period) {
return (wallTime.getTime() - period.mpd.availabilityStartTime.getTime() + clientServerTimeShift * 1000) / 1000;
}
function calcPresentationTimeFromMediaTime(mediaTime, representation) {
var periodStart = representation.adaptation.period.start;
var presentationOffset = representation.presentationTimeOffset;
return mediaTime + (periodStart - presentationOffset);
}
function calcMediaTimeFromPresentationTime(presentationTime, representation) {
var periodStart = representation.adaptation.period.start;
var presentationOffset = representation.presentationTimeOffset;
return presentationTime - periodStart + presentationOffset;
}
function calcWallTimeForSegment(segment, isDynamic) {
var suggestedPresentationDelay, displayStartTime, wallTime;
if (isDynamic) {
suggestedPresentationDelay = segment.representation.adaptation.period.mpd.suggestedPresentationDelay;
displayStartTime = segment.presentationStartTime + suggestedPresentationDelay;
wallTime = new Date(segment.availabilityStartTime.getTime() + displayStartTime * 1000);
}
return wallTime;
}
/**
* Calculates the timeshiftbuffer range. This range might overlap multiple periods and is not limited to period boundaries. However, we make sure that the range is potentially covered by period.
* @param {Array} streams
* @param {boolean} isDynamic
* @return {}
*/
function calcTimeShiftBufferWindow(streams, isDynamic) {
// Static manifests. The availability window is equal to the DVR window
if (!isDynamic) {
return _calcTimeshiftBufferForStaticManifest(streams);
} // Specific use case of SegmentTimeline
if (settings.get().streaming.timeShiftBuffer.calcFromSegmentTimeline) {
var data = _calcTimeShiftBufferWindowForDynamicTimelineManifest(streams);
_adjustTimelineAnchorAvailabilityOffset(data.now, data.range);
return data.range;
}
return _calcTimeShiftBufferWindowForDynamicManifest(streams);
}
function _calcTimeshiftBufferForStaticManifest(streams) {
// Static Range Finder. We iterate over all periods and return the total duration
var range = {
start: NaN,
end: NaN
};
var duration = 0;
var start = NaN;
streams.forEach(function (stream) {
var streamInfo = stream.getStreamInfo();
duration += streamInfo.duration;
if (isNaN(start) || streamInfo.start < start) {
start = streamInfo.start;
}
});
range.start = start;
range.end = start + duration;
return range;
}
function _calcTimeShiftBufferWindowForDynamicManifest(streams) {
var range = {
start: NaN,
end: NaN
};
if (!streams || streams.length === 0) {
return range;
}
var voPeriod = streams[0].getAdapter().getRegularPeriods()[0];
var now = calcPresentationTimeFromWallTime(new Date(), voPeriod);
var timeShiftBufferDepth = voPeriod.mpd.timeShiftBufferDepth;
var start = !isNaN(timeShiftBufferDepth) ? now - timeShiftBufferDepth : 0; // check if we find a suitable period for that starttime. Otherwise we use the time closest to that
range.start = _adjustTimeBasedOnPeriodRanges(streams, start);
range.end = !isNaN(range.start) && now < range.start ? now : _adjustTimeBasedOnPeriodRanges(streams, now, true);
if (!isNaN(timeShiftBufferDepth) && range.end < now - timeShiftBufferDepth) {
range.end = NaN;
} // If we have SegmentTimeline as a reference we can verify that the calculated DVR window is at least partially included in the DVR window exposed by the timeline.
// If that is not the case we stick to the DVR window defined by SegmentTimeline
if (settings.get().streaming.timeShiftBuffer.fallbackToSegmentTimeline) {
var timelineRefData = _calcTimeShiftBufferWindowForDynamicTimelineManifest(streams);
if (timelineRefData.range.end < range.start) {
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].CONFORMANCE_VIOLATION, {
level: _streaming_constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_8__["default"].LEVELS.WARNING,
event: _streaming_constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_8__["default"].EVENTS.INVALID_DVR_WINDOW
});
_adjustTimelineAnchorAvailabilityOffset(timelineRefData.now, timelineRefData.range);
return timelineRefData.range;
}
}
return range;
}
function _calcTimeShiftBufferWindowForDynamicTimelineManifest(streams) {
var range = {
start: NaN,
end: NaN
};
var voPeriod = streams[0].getAdapter().getRegularPeriods()[0];
var now = calcPresentationTimeFromWallTime(new Date(), voPeriod);
if (!streams || streams.length === 0) {
return {
range: range,
now: now
};
}
streams.forEach(function (stream) {
var adapter = stream.getAdapter();
var mediaInfo = adapter.getMediaInfoForType(stream.getStreamInfo(), _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_6__["default"].VIDEO) || adapter.getMediaInfoForType(stream.getStreamInfo(), _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_6__["default"].AUDIO);
var voRepresentations = adapter.getVoRepresentations(mediaInfo);
var voRepresentation = voRepresentations[0];
var periodRange = {
start: NaN,
end: NaN
};
if (voRepresentation) {
if (voRepresentation.segmentInfoType === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].SEGMENT_TIMELINE) {
periodRange = _calcRangeForTimeline(voRepresentation);
} else {
var currentVoPeriod = voRepresentation.adaptation.period;
periodRange.start = currentVoPeriod.start;
periodRange.end = Math.max(now, currentVoPeriod.start + currentVoPeriod.duration);
}
}
if (!isNaN(periodRange.start) && (isNaN(range.start) || range.start > periodRange.start)) {
range.start = periodRange.start;
}
if (!isNaN(periodRange.end) && (isNaN(range.end) || range.end < periodRange.end)) {
range.end = periodRange.end;
}
});
range.end = Math.min(now, range.end);
var adjustedEndTime = _adjustTimeBasedOnPeriodRanges(streams, range.end, true); // if range is NaN all periods are in the future. we should return range.start > range.end in this case
range.end = isNaN(adjustedEndTime) ? range.end : adjustedEndTime;
range.start = voPeriod && voPeriod.mpd && voPeriod.mpd.timeShiftBufferDepth && !isNaN(voPeriod.mpd.timeShiftBufferDepth) && !isNaN(range.end) ? Math.max(range.end - voPeriod.mpd.timeShiftBufferDepth, range.start) : range.start;
range.start = _adjustTimeBasedOnPeriodRanges(streams, range.start);
return {
range: range,
now: now
};
}
function _adjustTimelineAnchorAvailabilityOffset(now, range) {
timelineAnchorAvailabilityOffset = now - range.end;
}
function _adjustTimeBasedOnPeriodRanges(streams, time) {
var isEndOfDvrWindow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
try {
var i = 0;
var found = false;
var adjustedTime = NaN;
while (!found && i < streams.length) {
var streamInfo = streams[i].getStreamInfo(); // We found a period which contains the target time.
if (streamInfo.start <= time && (!isFinite(streamInfo.duration) || streamInfo.start + streamInfo.duration >= time)) {
adjustedTime = time;
found = true;
} // Adjust the time for the start of the DVR window. The current period starts after the target time. We use the starttime of this period as adjusted time
else if (!isEndOfDvrWindow && streamInfo.start > time && (isNaN(adjustedTime) || streamInfo.start < adjustedTime)) {
adjustedTime = streamInfo.start;
} // Adjust the time for the end of the DVR window. The current period ends before the targettime. We use the end time of this period as the adjusted time
else if (isEndOfDvrWindow && streamInfo.start + streamInfo.duration < time && (isNaN(adjustedTime) || streamInfo.start + streamInfo.duration > adjustedTime)) {
adjustedTime = streamInfo.start + streamInfo.duration;
}
i += 1;
}
return adjustedTime;
} catch (e) {
return time;
}
}
function _calcRangeForTimeline(voRepresentation) {
var adaptation = voRepresentation.adaptation.period.mpd.manifest.Period_asArray[voRepresentation.adaptation.period.index].AdaptationSet_asArray[voRepresentation.adaptation.index];
var representation = dashManifestModel.getRepresentationFor(voRepresentation.index, adaptation);
var timeline = representation.SegmentTemplate.SegmentTimeline;
var timescale = representation.SegmentTemplate.timescale;
var segments = timeline.S_asArray;
var range = {
start: 0,
end: 0
};
var d = 0;
var segment, repeat, i, len;
range.start = calcPresentationTimeFromMediaTime(segments[0].t / timescale, voRepresentation);
for (i = 0, len = segments.length; i < len; i++) {
segment = segments[i];
repeat = 0;
if (segment.hasOwnProperty('r')) {
repeat = segment.r;
}
d += segment.d / timescale * (1 + repeat);
}
range.end = range.start + d;
return range;
}
function calcPeriodRelativeTimeFromMpdRelativeTime(representation, mpdRelativeTime) {
var periodStartTime = representation.adaptation.period.start;
return mpdRelativeTime - periodStartTime;
}
function _onUpdateTimeSyncOffset(e) {
if (e.offset !== undefined && !isNaN(e.offset)) {
setClientTimeOffset(e.offset / 1000);
}
}
function resetInitialSettings() {
clientServerTimeShift = 0;
timelineAnchorAvailabilityOffset = 0;
}
function reset() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].UPDATE_TIME_SYNC_OFFSET, _onUpdateTimeSyncOffset, this);
resetInitialSettings();
}
instance = {
initialize: initialize,
getClientTimeOffset: getClientTimeOffset,
setClientTimeOffset: setClientTimeOffset,
getClientReferenceTime: getClientReferenceTime,
calcAvailabilityStartTimeFromPresentationTime: calcAvailabilityStartTimeFromPresentationTime,
calcAvailabilityEndTimeFromPresentationTime: calcAvailabilityEndTimeFromPresentationTime,
calcPresentationTimeFromWallTime: calcPresentationTimeFromWallTime,
calcPresentationTimeFromMediaTime: calcPresentationTimeFromMediaTime,
calcPeriodRelativeTimeFromMpdRelativeTime: calcPeriodRelativeTimeFromMpdRelativeTime,
calcMediaTimeFromPresentationTime: calcMediaTimeFromPresentationTime,
calcWallTimeForSegment: calcWallTimeForSegment,
calcTimeShiftBufferWindow: calcTimeShiftBufferWindow,
reset: reset
};
setup();
return instance;
}
TimelineConverter.__dashjs_factory_name = 'TimelineConverter';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(TimelineConverter));
/***/ }),
/***/ "./src/dash/utils/TimelineSegmentsGetter.js":
/*!**************************************************!*\
!*** ./src/dash/utils/TimelineSegmentsGetter.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TimelineSegmentsGetter(config, isDynamic) {
config = config || {};
var timelineConverter = config.timelineConverter;
var dashMetrics = config.dashMetrics;
var instance;
function checkConfig() {
if (!timelineConverter) {
throw new Error(_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].MISSING_CONFIG_ERROR);
}
}
function getMediaFinishedInformation(representation) {
if (!representation) {
return 0;
}
var base = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentTemplate || representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentList;
var timeline = base.SegmentTimeline;
var time = 0;
var scaledTime = 0;
var availableSegments = 0;
var fragments, frag, i, len, j, repeat, fTimescale;
fTimescale = representation.timescale;
fragments = timeline.S_asArray;
len = fragments.length;
for (i = 0; i < len; i++) {
frag = fragments[i];
repeat = 0;
if (frag.hasOwnProperty('r')) {
repeat = frag.r;
} // For a repeated S element, t belongs only to the first segment
if (frag.hasOwnProperty('t')) {
time = frag.t;
scaledTime = time / fTimescale;
} // This is a special case: "A negative value of the @r attribute of the S element indicates that the duration indicated in @d attribute repeats until the start of the next S element, the end of the Period or until the
// next MPD update."
if (repeat < 0) {
var nextFrag = fragments[i + 1];
repeat = _calculateRepeatCountForNegativeR(representation, nextFrag, frag, fTimescale, scaledTime);
}
for (j = 0; j <= repeat; j++) {
availableSegments++;
time += frag.d;
scaledTime = time / fTimescale;
}
} // We need to account for the index of the segments starting at 0. We subtract 1
return {
numberOfSegments: availableSegments,
mediaTimeOfLastSignaledSegment: scaledTime
};
}
function iterateSegments(representation, iterFunc) {
var base = representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentTemplate || representation.adaptation.period.mpd.manifest.Period_asArray[representation.adaptation.period.index].AdaptationSet_asArray[representation.adaptation.index].Representation_asArray[representation.index].SegmentList;
var timeline = base.SegmentTimeline;
var list = base.SegmentURL_asArray;
var time = 0;
var scaledTime = 0;
var relativeIdx = -1;
var fragments, frag, i, len, j, repeat, fTimescale;
fTimescale = representation.timescale;
fragments = timeline.S_asArray;
var breakIterator = false;
for (i = 0, len = fragments.length; i < len && !breakIterator; i++) {
frag = fragments[i];
repeat = 0;
if (frag.hasOwnProperty('r')) {
repeat = frag.r;
} // For a repeated S element, t belongs only to the first segment
if (frag.hasOwnProperty('t')) {
time = frag.t;
scaledTime = time / fTimescale;
} // This is a special case: "A negative value of the @r attribute of the S element indicates that the duration indicated in @d attribute repeats until the start of the next S element, the end of the Period or until the
// next MPD update."
if (repeat < 0) {
var nextFrag = fragments[i + 1];
repeat = _calculateRepeatCountForNegativeR(representation, nextFrag, frag, fTimescale, scaledTime);
}
for (j = 0; j <= repeat && !breakIterator; j++) {
relativeIdx++;
breakIterator = iterFunc(time, scaledTime, base, list, frag, fTimescale, relativeIdx, i);
if (breakIterator) {
representation.segmentDuration = frag.d / fTimescale;
}
time += frag.d;
scaledTime = time / fTimescale;
}
}
}
function _calculateRepeatCountForNegativeR(representation, nextFrag, frag, fTimescale, scaledTime) {
var repeatEndTime;
if (nextFrag && nextFrag.hasOwnProperty('t')) {
repeatEndTime = nextFrag.t / fTimescale;
} else {
try {
var availabilityEnd = 0;
if (!isNaN(representation.adaptation.period.start) && !isNaN(representation.adaptation.period.duration) && isFinite(representation.adaptation.period.duration)) {
// use end of the Period
availabilityEnd = representation.adaptation.period.start + representation.adaptation.period.duration;
} else {
// use DVR window
var dvrWindow = dashMetrics.getCurrentDVRInfo();
availabilityEnd = !isNaN(dvrWindow.end) ? dvrWindow.end : 0;
}
repeatEndTime = timelineConverter.calcMediaTimeFromPresentationTime(availabilityEnd, representation);
representation.segmentDuration = frag.d / fTimescale;
} catch (e) {
repeatEndTime = 0;
}
}
return Math.max(Math.ceil((repeatEndTime - scaledTime) / (frag.d / fTimescale)) - 1, 0);
}
function getSegmentByIndex(representation, index, lastSegmentTime) {
checkConfig();
if (!representation) {
return null;
}
var segment = null;
var found = false;
iterateSegments(representation, function (time, scaledTime, base, list, frag, fTimescale, relativeIdx, i) {
if (found || lastSegmentTime < 0) {
var media = base.media;
var mediaRange = frag.mediaRange;
if (list) {
media = list[i].media || '';
mediaRange = list[i].mediaRange;
}
segment = Object(_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__["getTimeBasedSegment"])(timelineConverter, isDynamic, representation, time, frag.d, fTimescale, media, mediaRange, relativeIdx, frag.tManifest);
return true;
} else if (scaledTime >= lastSegmentTime - frag.d * 0.5 / fTimescale) {
// same logic, if deviation is
// 50% of segment duration, segment is found if scaledTime is greater than or equal to (startTime of previous segment - half of the previous segment duration)
found = true;
}
return false;
});
return segment;
}
function getSegmentByTime(representation, requestedTime) {
checkConfig();
if (!representation) {
return null;
}
if (requestedTime === undefined) {
requestedTime = null;
}
var segment = null;
var requiredMediaTime = timelineConverter.calcMediaTimeFromPresentationTime(requestedTime, representation);
iterateSegments(representation, function (time, scaledTime, base, list, frag, fTimescale, relativeIdx, i) {
// In some cases when requiredMediaTime = actual end time of the last segment
// it is possible that this time a bit exceeds the declared end time of the last segment.
// in this case we still need to include the last segment in the segment list.
if (requiredMediaTime < scaledTime + frag.d / fTimescale) {
var media = base.media;
var mediaRange = frag.mediaRange;
if (list) {
media = list[i].media || '';
mediaRange = list[i].mediaRange;
}
segment = Object(_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__["getTimeBasedSegment"])(timelineConverter, isDynamic, representation, time, frag.d, fTimescale, media, mediaRange, relativeIdx, frag.tManifest);
return true;
}
return false;
});
return segment;
}
instance = {
getSegmentByIndex: getSegmentByIndex,
getSegmentByTime: getSegmentByTime,
getMediaFinishedInformation: getMediaFinishedInformation
};
return instance;
}
TimelineSegmentsGetter.__dashjs_factory_name = 'TimelineSegmentsGetter';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(TimelineSegmentsGetter);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/dash/vo/AdaptationSet.js":
/*!**************************************!*\
!*** ./src/dash/vo/AdaptationSet.js ***!
\**************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var AdaptationSet = function AdaptationSet() {
_classCallCheck(this, AdaptationSet);
this.period = null;
this.index = -1;
this.type = null;
};
/* harmony default export */ __webpack_exports__["default"] = (AdaptationSet);
/***/ }),
/***/ "./src/dash/vo/BaseURL.js":
/*!********************************!*\
!*** ./src/dash/vo/BaseURL.js ***!
\********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var DEFAULT_DVB_PRIORITY = 1;
var DEFAULT_DVB_WEIGHT = 1;
var BaseURL = function BaseURL(url, serviceLocation, priority, weight) {
_classCallCheck(this, BaseURL);
this.url = url || '';
this.serviceLocation = serviceLocation || url || ''; // DVB extensions
this.dvb_priority = priority || DEFAULT_DVB_PRIORITY;
this.dvb_weight = weight || DEFAULT_DVB_WEIGHT;
this.availabilityTimeOffset = 0;
this.availabilityTimeComplete = true;
/* currently unused:
* byteRange,
*/
};
BaseURL.DEFAULT_DVB_PRIORITY = DEFAULT_DVB_PRIORITY;
BaseURL.DEFAULT_DVB_WEIGHT = DEFAULT_DVB_WEIGHT;
/* harmony default export */ __webpack_exports__["default"] = (BaseURL);
/***/ }),
/***/ "./src/dash/vo/Event.js":
/*!******************************!*\
!*** ./src/dash/vo/Event.js ***!
\******************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Event = function Event() {
_classCallCheck(this, Event);
this.duration = NaN;
this.presentationTime = NaN;
this.id = NaN;
this.messageData = '';
this.eventStream = null;
this.presentationTimeDelta = NaN; // Specific EMSG Box parameter
};
/* harmony default export */ __webpack_exports__["default"] = (Event);
/***/ }),
/***/ "./src/dash/vo/EventStream.js":
/*!************************************!*\
!*** ./src/dash/vo/EventStream.js ***!
\************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var EventStream = function EventStream() {
_classCallCheck(this, EventStream);
this.adaptionSet = null;
this.representation = null;
this.period = null;
this.timescale = 1;
this.value = '';
this.schemeIdUri = '';
this.presentationTimeOffset = 0;
};
/* harmony default export */ __webpack_exports__["default"] = (EventStream);
/***/ }),
/***/ "./src/dash/vo/ManifestInfo.js":
/*!*************************************!*\
!*** ./src/dash/vo/ManifestInfo.js ***!
\*************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var ManifestInfo = function ManifestInfo() {
_classCallCheck(this, ManifestInfo);
this.dvrWindowSize = NaN;
this.loadedTime = null;
this.availableFrom = null;
this.minBufferTime = NaN;
this.duration = NaN;
this.isDynamic = false;
this.maxFragmentDuration = null;
};
/* harmony default export */ __webpack_exports__["default"] = (ManifestInfo);
/***/ }),
/***/ "./src/dash/vo/MediaInfo.js":
/*!**********************************!*\
!*** ./src/dash/vo/MediaInfo.js ***!
\**********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var MediaInfo = function MediaInfo() {
_classCallCheck(this, MediaInfo);
this.id = null;
this.index = null;
this.type = null;
this.streamInfo = null;
this.representationCount = 0;
this.labels = null;
this.lang = null;
this.viewpoint = null;
this.accessibility = null;
this.audioChannelConfiguration = null;
this.roles = null;
this.codec = null;
this.mimeType = null;
this.contentProtection = null;
this.KID = null;
this.bitrateList = null;
this.isFragmented = null;
this.isEmbedded = null;
this.selectionPriority = 1;
};
/* harmony default export */ __webpack_exports__["default"] = (MediaInfo);
/***/ }),
/***/ "./src/dash/vo/Mpd.js":
/*!****************************!*\
!*** ./src/dash/vo/Mpd.js ***!
\****************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Mpd = function Mpd() {
_classCallCheck(this, Mpd);
this.manifest = null;
this.suggestedPresentationDelay = 0;
this.availabilityStartTime = null;
this.availabilityEndTime = Number.POSITIVE_INFINITY;
this.timeShiftBufferDepth = Number.POSITIVE_INFINITY;
this.maxSegmentDuration = Number.POSITIVE_INFINITY;
this.publishTime = null;
this.minimumUpdatePeriod = NaN;
this.mediaPresentationDuration = NaN;
};
/* harmony default export */ __webpack_exports__["default"] = (Mpd);
/***/ }),
/***/ "./src/dash/vo/PatchOperation.js":
/*!***************************************!*\
!*** ./src/dash/vo/PatchOperation.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var PatchOperation = /*#__PURE__*/function () {
function PatchOperation(action, xpath, value) {
_classCallCheck(this, PatchOperation);
this.action = action;
this.xpath = xpath;
this.value = value;
this.position = null;
}
_createClass(PatchOperation, [{
key: "getMpdTarget",
value: function getMpdTarget(root) {
var isSiblingOperation = this.action === 'remove' || this.action === 'replace' || this.position === 'before' || this.position === 'after';
return this.xpath.getMpdTarget(root, isSiblingOperation);
}
}]);
return PatchOperation;
}();
/* harmony default export */ __webpack_exports__["default"] = (PatchOperation);
/***/ }),
/***/ "./src/dash/vo/Period.js":
/*!*******************************!*\
!*** ./src/dash/vo/Period.js ***!
\*******************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Period = function Period() {
_classCallCheck(this, Period);
this.id = null;
this.index = -1;
this.duration = NaN;
this.start = NaN;
this.mpd = null;
this.nextPeriodId = null;
};
Period.DEFAULT_ID = 'defaultId';
/* harmony default export */ __webpack_exports__["default"] = (Period);
/***/ }),
/***/ "./src/dash/vo/Representation.js":
/*!***************************************!*\
!*** ./src/dash/vo/Representation.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Representation = /*#__PURE__*/function () {
function Representation() {
_classCallCheck(this, Representation);
this.id = null;
this.index = -1;
this.adaptation = null;
this.segmentInfoType = null;
this.initialization = null;
this.codecs = null;
this.mimeType = null;
this.codecPrivateData = null;
this.segmentDuration = NaN;
this.timescale = 1;
this.startNumber = 1;
this.indexRange = null;
this.range = null;
this.presentationTimeOffset = 0; // Set the source buffer timeOffset to this
this.MSETimeOffset = NaN; // The information we need in the DashHandler to determine whether the last segment has been loaded
this.mediaFinishedInformation = {
numberOfSegments: 0,
mediaTimeOfLastSignaledSegment: NaN
};
this.bandwidth = NaN;
this.width = NaN;
this.height = NaN;
this.scanType = null;
this.maxPlayoutRate = NaN;
this.availabilityTimeOffset = 0;
this.availabilityTimeComplete = true;
}
_createClass(Representation, [{
key: "hasInitialization",
value: function hasInitialization() {
return this.initialization !== null || this.range !== null;
}
}, {
key: "hasSegments",
value: function hasSegments() {
return this.segmentInfoType !== _constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].BASE_URL && this.segmentInfoType !== _constants_DashConstants__WEBPACK_IMPORTED_MODULE_0__["default"].SEGMENT_BASE && !this.indexRange;
}
}]);
return Representation;
}();
/* harmony default export */ __webpack_exports__["default"] = (Representation);
/***/ }),
/***/ "./src/dash/vo/RepresentationInfo.js":
/*!*******************************************!*\
!*** ./src/dash/vo/RepresentationInfo.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var RepresentationInfo = function RepresentationInfo() {
_classCallCheck(this, RepresentationInfo);
this.id = null;
this.quality = null;
this.fragmentDuration = null;
this.mediaInfo = null;
this.MSETimeOffset = null;
};
/* harmony default export */ __webpack_exports__["default"] = (RepresentationInfo);
/***/ }),
/***/ "./src/dash/vo/Segment.js":
/*!********************************!*\
!*** ./src/dash/vo/Segment.js ***!
\********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Segment = function Segment() {
_classCallCheck(this, Segment);
this.indexRange = null; // The index of the segment in the list of segments. We start at 0
this.index = null;
this.mediaRange = null;
this.media = null;
this.duration = NaN; // this is the time that should be inserted into the media url
this.replacementTime = null; // this is the number that should be inserted into the media url
this.replacementNumber = NaN; // This is supposed to match the time encoded in the media Segment
this.mediaStartTime = NaN; // When the source buffer timeOffset is set to MSETimeOffset this is the
// time that will match the seekTarget and video.currentTime
this.presentationStartTime = NaN; // Do not schedule this segment until
this.availabilityStartTime = NaN; // Ignore and discard this segment after
this.availabilityEndTime = NaN; // For dynamic mpd's, this is the wall clock time that the video
// element currentTime should be presentationStartTime
this.wallStartTime = NaN;
this.representation = null;
};
/* harmony default export */ __webpack_exports__["default"] = (Segment);
/***/ }),
/***/ "./src/dash/vo/SimpleXPath.js":
/*!************************************!*\
!*** ./src/dash/vo/SimpleXPath.js ***!
\************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var SimpleXPath = /*#__PURE__*/function () {
function SimpleXPath(selector) {
var _this = this;
_classCallCheck(this, SimpleXPath);
// establish validation of the path, to catch unsupported cases
this.valid = selector[0] == '/'; // first check, we only support absolute addressing
// establish parsed path, example:
// /MPD/Period[@id="foobar"]/AdaptationSet[@id="2"]/SegmentTemplate/SegmentTimeline
this.path = selector.split('/').filter(function (component) {
return component.length !== 0;
}) // remove excess empty components
.map(function (component) {
var parsed = {
name: component
};
var qualifierPoint = component.indexOf('[');
if (qualifierPoint != -1) {
parsed.name = component.substring(0, qualifierPoint);
var qualifier = component.substring(qualifierPoint + 1, component.length - 1); // quick sanity check are there additional qualifiers making this invalid
_this.valid = _this.valid && qualifier.indexOf('[') == -1;
var equalityPoint = qualifier.indexOf('=');
if (equalityPoint != -1) {
parsed.attribute = {
name: qualifier.substring(1, equalityPoint),
// skip the @
value: qualifier.substring(equalityPoint + 1)
}; // check for single and double quoted attribute values
if (['\'', '"'].indexOf(parsed.attribute.value[0]) != -1) {
parsed.attribute.value = parsed.attribute.value.substring(1, parsed.attribute.value.length - 1);
}
} else {
// positional access in xpath is 1-based index
// internal processes will assume 0-based so we normalize that here
parsed.position = parseInt(qualifier, 10) - 1;
}
}
return parsed;
});
}
_createClass(SimpleXPath, [{
key: "isValid",
value: function isValid() {
return this.valid;
}
}, {
key: "findsElement",
value: function findsElement() {
return !this.findsAttribute();
}
}, {
key: "findsAttribute",
value: function findsAttribute() {
return this.path[this.path.length - 1].name.startsWith('@');
}
}, {
key: "getMpdTarget",
value: function getMpdTarget(root, isSiblingOperation) {
var parent = null;
var leaf = root; // assume root is MPD and we start at next level match
var level = 1;
var name = 'MPD';
while (level < this.path.length && leaf !== null) {
// set parent to current
parent = leaf; // select next leaf based on component
var component = this.path[level];
name = component.name; // stop one early if this is the last element and an attribute
if (level !== this.path.length - 1 || !name.startsWith('@')) {
var children = parent[name + '_asArray'] || [];
if (children.length === 0 && parent[name]) {
children.push(parent[name]);
}
if (component.position) {
leaf = children[component.position] || null;
} else if (component.attribute) {
(function () {
var attr = component.attribute;
leaf = children.filter(function (elm) {
return elm[attr.name] == attr.value;
})[0] || null;
})();
} else {
// default case, select first
leaf = children[0] || null;
}
}
level++;
}
if (leaf === null) {
// given path not found in root
return null;
} // attributes the target is the leaf node, the name is the attribute
if (name.startsWith('@')) {
return {
name: name.substring(1),
leaf: leaf,
target: leaf
};
} // otherwise we target the parent for sibling operations and leaf for child operations
return {
name: name,
leaf: leaf,
target: isSiblingOperation ? parent : leaf
};
}
}]);
return SimpleXPath;
}();
/* harmony default export */ __webpack_exports__["default"] = (SimpleXPath);
/***/ }),
/***/ "./src/dash/vo/StreamInfo.js":
/*!***********************************!*\
!*** ./src/dash/vo/StreamInfo.js ***!
\***********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var StreamInfo = function StreamInfo() {
_classCallCheck(this, StreamInfo);
this.id = null;
this.index = null;
this.start = NaN;
this.duration = NaN;
this.manifestInfo = null;
this.isLast = true;
};
/* harmony default export */ __webpack_exports__["default"] = (StreamInfo);
/***/ }),
/***/ "./src/dash/vo/UTCTiming.js":
/*!**********************************!*\
!*** ./src/dash/vo/UTCTiming.js ***!
\**********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var UTCTiming = function UTCTiming() {
_classCallCheck(this, UTCTiming);
// UTCTiming is a DescriptorType and doesn't have any additional fields
this.schemeIdUri = '';
this.value = '';
};
/* harmony default export */ __webpack_exports__["default"] = (UTCTiming);
/***/ }),
/***/ "./src/streaming/FragmentLoader.js":
/*!*****************************************!*\
!*** ./src/streaming/FragmentLoader.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _net_URLLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./net/URLLoader */ "./src/streaming/net/URLLoader.js");
/* harmony import */ var _vo_HeadRequest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./vo/HeadRequest */ "./src/streaming/vo/HeadRequest.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function FragmentLoader(config) {
config = config || {};
var context = this.context;
var eventBus = config.eventBus;
var events = config.events;
var urlUtils = config.urlUtils;
var errors = config.errors;
var streamId = config.streamId;
var instance, urlLoader;
function setup() {
urlLoader = Object(_net_URLLoader__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
errHandler: config.errHandler,
errors: errors,
dashMetrics: config.dashMetrics,
mediaPlayerModel: config.mediaPlayerModel,
requestModifier: config.requestModifier,
urlUtils: urlUtils,
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"],
boxParser: config.boxParser,
dashConstants: config.dashConstants,
requestTimeout: config.settings.get().streaming.fragmentRequestTimeout
});
}
function checkForExistence(request) {
var report = function report(success) {
eventBus.trigger(events.CHECK_FOR_EXISTENCE_COMPLETED, {
request: request,
exists: success
});
};
if (request) {
var headRequest = new _vo_HeadRequest__WEBPACK_IMPORTED_MODULE_2__["default"](request.url);
urlLoader.load({
request: headRequest,
success: function success() {
report(true);
},
error: function error() {
report(false);
}
});
} else {
report(false);
}
}
function load(request) {
var report = function report(data, error) {
eventBus.trigger(events.LOADING_COMPLETED, {
request: request,
response: data || null,
error: error || null,
sender: instance
});
};
if (request) {
urlLoader.load({
request: request,
progress: function progress(event) {
eventBus.trigger(events.LOADING_PROGRESS, {
request: request,
stream: event.stream,
streamId: streamId
});
if (event.data) {
eventBus.trigger(events.LOADING_DATA_PROGRESS, {
request: request,
response: event.data || null,
error: null,
sender: instance
});
}
},
success: function success(data) {
report(data);
},
error: function error(request, statusText, errorText) {
report(undefined, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](errors.FRAGMENT_LOADER_LOADING_FAILURE_ERROR_CODE, errorText, statusText));
},
abort: function abort(request) {
if (request) {
eventBus.trigger(events.LOADING_ABANDONED, {
mediaType: request.mediaType,
request: request,
sender: instance
});
}
}
});
} else {
report(undefined, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](errors.FRAGMENT_LOADER_NULL_REQUEST_ERROR_CODE, errors.FRAGMENT_LOADER_NULL_REQUEST_ERROR_MESSAGE));
}
}
function abort() {
if (urlLoader) {
urlLoader.abort();
}
}
function reset() {
if (urlLoader) {
urlLoader.abort();
urlLoader = null;
}
}
instance = {
checkForExistence: checkForExistence,
load: load,
abort: abort,
reset: reset
};
setup();
return instance;
}
FragmentLoader.__dashjs_factory_name = 'FragmentLoader';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__["default"].getClassFactory(FragmentLoader));
/***/ }),
/***/ "./src/streaming/ManifestLoader.js":
/*!*****************************************!*\
!*** ./src/streaming/ManifestLoader.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _controllers_XlinkController__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./controllers/XlinkController */ "./src/streaming/controllers/XlinkController.js");
/* harmony import */ var _net_URLLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./net/URLLoader */ "./src/streaming/net/URLLoader.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _vo_TextRequest__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./vo/TextRequest */ "./src/streaming/vo/TextRequest.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _dash_parser_DashParser__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../dash/parser/DashParser */ "./src/dash/parser/DashParser.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ManifestLoader(config) {
config = config || {};
var context = this.context;
var debug = config.debug;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
var urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var instance, logger, urlLoader, xlinkController, parser;
var mssHandler = config.mssHandler;
var errHandler = config.errHandler;
function setup() {
logger = debug.getLogger(instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].XLINK_READY, onXlinkReady, instance);
urlLoader = Object(_net_URLLoader__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
errHandler: config.errHandler,
dashMetrics: config.dashMetrics,
mediaPlayerModel: config.mediaPlayerModel,
requestModifier: config.requestModifier,
urlUtils: urlUtils,
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"],
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"]
});
xlinkController = Object(_controllers_XlinkController__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
errHandler: errHandler,
dashMetrics: config.dashMetrics,
mediaPlayerModel: config.mediaPlayerModel,
requestModifier: config.requestModifier,
settings: config.settings
});
parser = null;
}
function onXlinkReady(event) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].INTERNAL_MANIFEST_LOADED, {
manifest: event.manifest
});
}
function createParser(data) {
var parser = null; // Analyze manifest content to detect protocol and select appropriate parser
if (data.indexOf('SmoothStreamingMedia') > -1) {
//do some business to transform it into a Dash Manifest
if (mssHandler) {
parser = mssHandler.createMssParser();
mssHandler.registerEvents();
}
return parser;
} else if (data.indexOf('MPD') > -1 || data.indexOf('Patch') > -1) {
return Object(_dash_parser_DashParser__WEBPACK_IMPORTED_MODULE_12__["default"])(context).create({
debug: debug
});
} else {
return parser;
}
}
function load(url) {
var request = new _vo_TextRequest__WEBPACK_IMPORTED_MODULE_5__["default"](url, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].MPD_TYPE);
urlLoader.load({
request: request,
success: function success(data, textStatus, responseURL) {
// Manage situations in which success is called after calling reset
if (!xlinkController) return;
var actualUrl, baseUri, manifest; // Handle redirects for the MPD - as per RFC3986 Section 5.1.3
// also handily resolves relative MPD URLs to absolute
if (responseURL && responseURL !== url) {
baseUri = urlUtils.parseBaseUrl(responseURL);
actualUrl = responseURL;
} else {
// usually this case will be caught and resolved by
// responseURL above but it is not available for IE11 and Edge/12 and Edge/13
// baseUri must be absolute for BaseURL resolution later
if (urlUtils.isRelative(url)) {
url = urlUtils.resolve(url, window.location.href);
}
baseUri = urlUtils.parseBaseUrl(url);
} // A response of no content implies in-memory is properly up to date
if (textStatus == 'No Content') {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].INTERNAL_MANIFEST_LOADED, {
manifest: null
});
return;
} // Create parser according to manifest type
if (parser === null) {
parser = createParser(data);
}
if (parser === null) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].INTERNAL_MANIFEST_LOADED, {
manifest: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_MESSAGE + "".concat(url))
});
return;
} // init xlinkcontroller with matchers and iron object from created parser
xlinkController.setMatchers(parser.getMatchers());
xlinkController.setIron(parser.getIron());
try {
manifest = parser.parse(data);
} catch (e) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].INTERNAL_MANIFEST_LOADED, {
manifest: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_MESSAGE + "".concat(url))
});
return;
}
if (manifest) {
manifest.url = actualUrl || url; // URL from which the MPD was originally retrieved (MPD updates will not change this value)
if (!manifest.originalUrl) {
manifest.originalUrl = manifest.url;
} // In the following, we only use the first Location entry even if many are available
// Compare with ManifestUpdater/DashManifestModel
if (manifest.hasOwnProperty(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LOCATION)) {
baseUri = urlUtils.parseBaseUrl(manifest.Location_asArray[0]);
logger.debug('BaseURI set by Location to: ' + baseUri);
}
manifest.baseUri = baseUri;
manifest.loadedTime = new Date();
xlinkController.resolveManifestOnLoad(manifest);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].ORIGINAL_MANIFEST_LOADED, {
originalManifest: data
});
} else {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].INTERNAL_MANIFEST_LOADED, {
manifest: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_MESSAGE + "".concat(url))
});
}
},
error: function error(request, statusText, errorText) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].INTERNAL_MANIFEST_LOADED, {
manifest: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_6__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_LOADING_FAILURE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADER_LOADING_FAILURE_ERROR_MESSAGE + "".concat(url, ", ").concat(errorText))
});
}
});
}
function reset() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].XLINK_READY, onXlinkReady, instance);
if (mssHandler) {
mssHandler.reset();
}
if (xlinkController) {
xlinkController.reset();
xlinkController = null;
}
if (urlLoader) {
urlLoader.abort();
urlLoader = null;
}
}
instance = {
load: load,
reset: reset
};
setup();
return instance;
}
ManifestLoader.__dashjs_factory_name = 'ManifestLoader';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_11__["default"].getClassFactory(ManifestLoader);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/ManifestUpdater.js":
/*!******************************************!*\
!*** ./src/streaming/ManifestUpdater.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ManifestUpdater() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
var instance, logger, refreshDelay, refreshTimer, isPaused, isStopped, isUpdating, manifestLoader, manifestModel, adapter, errHandler, settings;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance().getLogger(instance);
}
function setConfig(config) {
if (!config) return;
if (config.manifestModel) {
manifestModel = config.manifestModel;
}
if (config.adapter) {
adapter = config.adapter;
}
if (config.manifestLoader) {
manifestLoader = config.manifestLoader;
}
if (config.errHandler) {
errHandler = config.errHandler;
}
if (config.settings) {
settings = config.settings;
}
}
function initialize() {
resetInitialSettings();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].STREAMS_COMPOSED, onStreamsComposed, this);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_STARTED, onPlaybackStarted, this);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PAUSED, onPlaybackPaused, this);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].INTERNAL_MANIFEST_LOADED, onManifestLoaded, this);
}
function setManifest(manifest) {
update(manifest);
}
function resetInitialSettings() {
refreshDelay = NaN;
isUpdating = false;
isPaused = true;
isStopped = false;
stopManifestRefreshTimer();
}
function reset() {
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_STARTED, onPlaybackStarted, this);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PAUSED, onPlaybackPaused, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].STREAMS_COMPOSED, onStreamsComposed, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].INTERNAL_MANIFEST_LOADED, onManifestLoaded, this);
resetInitialSettings();
}
function stopManifestRefreshTimer() {
if (refreshTimer !== null) {
clearTimeout(refreshTimer);
refreshTimer = null;
}
}
function startManifestRefreshTimer(delay) {
stopManifestRefreshTimer();
if (isStopped) {
return;
}
if (isNaN(delay) && !isNaN(refreshDelay)) {
delay = refreshDelay * 1000;
}
if (!isNaN(delay)) {
logger.debug('Refresh manifest in ' + delay + ' milliseconds.');
refreshTimer = setTimeout(onRefreshTimer, delay);
}
}
function refreshManifest() {
var ignorePatch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
isUpdating = true;
var manifest = manifestModel.getValue(); // default to the original url in the manifest
var url = manifest.url; // Check for PatchLocation and Location alternatives
var patchLocation = adapter.getPatchLocation(manifest);
var location = adapter.getLocation(manifest);
if (patchLocation && !ignorePatch) {
url = patchLocation;
} else if (location) {
url = location;
} // if one of the alternatives was relative, convert to absolute
if (urlUtils.isRelative(url)) {
url = urlUtils.resolve(url, manifest.url);
}
manifestLoader.load(url);
}
function update(manifest) {
if (!manifest) {
// successful update with no content implies existing manifest remains valid
manifest = manifestModel.getValue(); // override load time to avoid invalid latency tracking and ensure update cadence
manifest.loadedTime = new Date();
} else if (adapter.getIsPatch(manifest)) {
// with patches the in-memory manifest is our base
var patch = manifest;
manifest = manifestModel.getValue(); // check for patch validity
var isPatchValid = adapter.isPatchValid(manifest, patch);
var patchSuccessful = isPatchValid;
if (isPatchValid) {
// grab publish time before update
var publishTime = adapter.getPublishTime(manifest); // apply validated patch to manifest
patchSuccessful = adapter.applyPatchToManifest(manifest, patch); // get the updated publish time
var updatedPublishTime = adapter.getPublishTime(manifest); // ensure the patch properly updated the in-memory publish time
patchSuccessful = publishTime.getTime() != updatedPublishTime.getTime();
} // if the patch failed to apply, force a full manifest refresh
if (!patchSuccessful) {
logger.debug('Patch provided is invalid, performing full manifest refresh');
refreshManifest(true);
return;
} // override load time to avoid invalid latency tracking and ensure update cadence
manifest.loadedTime = new Date();
} // See DASH-IF IOP v4.3 section 4.6.4 "Transition Phase between Live and On-Demand"
// Stop manifest update, ignore static manifest and signal end of dynamic stream to detect end of stream
if (manifestModel.getValue() && manifestModel.getValue().type === _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].DYNAMIC && manifest.type === _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].STATIC) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].DYNAMIC_TO_STATIC);
isUpdating = false;
isStopped = true;
return;
}
manifestModel.setValue(manifest);
var date = new Date();
var latencyOfLastUpdate = (date.getTime() - manifest.loadedTime.getTime()) / 1000;
refreshDelay = adapter.getManifestUpdatePeriod(manifest, latencyOfLastUpdate); // setTimeout uses a 32 bit number to store the delay. Any number greater than it
// will cause event associated with setTimeout to trigger immediately
if (refreshDelay * 1000 > 0x7FFFFFFF) {
refreshDelay = 0x7FFFFFFF / 1000;
}
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_UPDATED, {
manifest: manifest
});
logger.info('Manifest has been refreshed at ' + date + '[' + date.getTime() / 1000 + '] ');
if (!isPaused) {
startManifestRefreshTimer();
}
}
function onRefreshTimer() {
if (isPaused) {
return;
}
if (isUpdating) {
startManifestRefreshTimer(settings.get().streaming.manifestUpdateRetryInterval);
return;
}
refreshManifest();
}
function onManifestLoaded(e) {
if (!e.error) {
update(e.manifest);
} else if (e.error.code === _core_errors_Errors__WEBPACK_IMPORTED_MODULE_5__["default"].MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE) {
errHandler.error(e.error);
}
}
function onPlaybackStarted()
/*e*/
{
isPaused = false;
startManifestRefreshTimer();
}
function onPlaybackPaused()
/*e*/
{
isPaused = !settings.get().streaming.scheduling.scheduleWhilePaused;
if (isPaused) {
stopManifestRefreshTimer();
}
}
function onStreamsComposed()
/*e*/
{
// When streams are ready we can consider manifest update completed. Resolve the update promise.
isUpdating = false;
}
function getIsUpdating() {
return isUpdating;
}
instance = {
initialize: initialize,
setManifest: setManifest,
refreshManifest: refreshManifest,
getIsUpdating: getIsUpdating,
setConfig: setConfig,
reset: reset
};
setup();
return instance;
}
ManifestUpdater.__dashjs_factory_name = 'ManifestUpdater';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__["default"].getClassFactory(ManifestUpdater));
/***/ }),
/***/ "./src/streaming/MediaPlayer.js":
/*!**************************************!*\
!*** ./src/streaming/MediaPlayer.js ***!
\**************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../externals/cea608-parser */ "./externals/cea608-parser.js");
/* harmony import */ var _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_externals_cea608_parser__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _controllers_PlaybackController__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./controllers/PlaybackController */ "./src/streaming/controllers/PlaybackController.js");
/* harmony import */ var _controllers_StreamController__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./controllers/StreamController */ "./src/streaming/controllers/StreamController.js");
/* harmony import */ var _controllers_GapController__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./controllers/GapController */ "./src/streaming/controllers/GapController.js");
/* harmony import */ var _controllers_MediaController__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./controllers/MediaController */ "./src/streaming/controllers/MediaController.js");
/* harmony import */ var _controllers_BaseURLController__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./controllers/BaseURLController */ "./src/streaming/controllers/BaseURLController.js");
/* harmony import */ var _ManifestLoader__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./ManifestLoader */ "./src/streaming/ManifestLoader.js");
/* harmony import */ var _utils_ErrorHandler__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./utils/ErrorHandler */ "./src/streaming/utils/ErrorHandler.js");
/* harmony import */ var _utils_Capabilities__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./utils/Capabilities */ "./src/streaming/utils/Capabilities.js");
/* harmony import */ var _utils_CapabilitiesFilter__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./utils/CapabilitiesFilter */ "./src/streaming/utils/CapabilitiesFilter.js");
/* harmony import */ var _utils_RequestModifier__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./utils/RequestModifier */ "./src/streaming/utils/RequestModifier.js");
/* harmony import */ var _models_URIFragmentModel__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./models/URIFragmentModel */ "./src/streaming/models/URIFragmentModel.js");
/* harmony import */ var _models_ManifestModel__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./models/ManifestModel */ "./src/streaming/models/ManifestModel.js");
/* harmony import */ var _models_MediaPlayerModel__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./models/MediaPlayerModel */ "./src/streaming/models/MediaPlayerModel.js");
/* harmony import */ var _controllers_AbrController__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./controllers/AbrController */ "./src/streaming/controllers/AbrController.js");
/* harmony import */ var _net_SchemeLoaderFactory__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./net/SchemeLoaderFactory */ "./src/streaming/net/SchemeLoaderFactory.js");
/* harmony import */ var _models_VideoModel__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./models/VideoModel */ "./src/streaming/models/VideoModel.js");
/* harmony import */ var _models_CmcdModel__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./models/CmcdModel */ "./src/streaming/models/CmcdModel.js");
/* harmony import */ var _utils_DOMStorage__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./utils/DOMStorage */ "./src/streaming/utils/DOMStorage.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ./../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ./MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _core_Version__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ../core/Version */ "./src/core/Version.js");
/* harmony import */ var _dash_controllers_SegmentBaseController__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ../dash/controllers/SegmentBaseController */ "./src/dash/controllers/SegmentBaseController.js");
/* harmony import */ var _dash_DashAdapter__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ../dash/DashAdapter */ "./src/dash/DashAdapter.js");
/* harmony import */ var _dash_DashMetrics__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ../dash/DashMetrics */ "./src/dash/DashMetrics.js");
/* harmony import */ var _dash_utils_TimelineConverter__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ../dash/utils/TimelineConverter */ "./src/dash/utils/TimelineConverter.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ./vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _externals_base64__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ../../externals/base64 */ "./externals/base64.js");
/* harmony import */ var _externals_base64__WEBPACK_IMPORTED_MODULE_35___default = /*#__PURE__*/__webpack_require__.n(_externals_base64__WEBPACK_IMPORTED_MODULE_35__);
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! codem-isoboxer */ "./node_modules/codem-isoboxer/dist/iso_boxer.js");
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_36___default = /*#__PURE__*/__webpack_require__.n(codem_isoboxer__WEBPACK_IMPORTED_MODULE_36__);
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_37__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_38__ = __webpack_require__(/*! ./utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/* harmony import */ var _ManifestUpdater__WEBPACK_IMPORTED_MODULE_39__ = __webpack_require__(/*! ./ManifestUpdater */ "./src/streaming/ManifestUpdater.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_40__ = __webpack_require__(/*! ../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _utils_BoxParser__WEBPACK_IMPORTED_MODULE_41__ = __webpack_require__(/*! ./utils/BoxParser */ "./src/streaming/utils/BoxParser.js");
/* harmony import */ var _text_TextController__WEBPACK_IMPORTED_MODULE_42__ = __webpack_require__(/*! ./text/TextController */ "./src/streaming/text/TextController.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
//Dash
/**
* The media types
* @typedef {("video" | "audio" | "text" | "image")} MediaType
*/
/**
* @module MediaPlayer
* @description The MediaPlayer is the primary dash.js Module and a Facade to build your player around.
* It will allow you access to all the important dash.js properties/methods via the public API and all the
* events to build a robust DASH media player.
*/
function MediaPlayer() {
/**
* @constant {string} STREAMING_NOT_INITIALIZED_ERROR error string thrown when a function is called before the dash.js has been fully initialized
* @inner
*/
var STREAMING_NOT_INITIALIZED_ERROR = 'You must first call initialize() and set a source before calling this method';
/**
* @constant {string} PLAYBACK_NOT_INITIALIZED_ERROR error string thrown when a function is called before the dash.js has been fully initialized
* @inner
*/
var PLAYBACK_NOT_INITIALIZED_ERROR = 'You must first call initialize() and set a valid source and view before calling this method';
/**
* @constant {string} ELEMENT_NOT_ATTACHED_ERROR error string thrown when a function is called before the dash.js has received a reference of an HTML5 video element
* @inner
*/
var ELEMENT_NOT_ATTACHED_ERROR = 'You must first call attachView() to set the video element before calling this method';
/**
* @constant {string} SOURCE_NOT_ATTACHED_ERROR error string thrown when a function is called before the dash.js has received a valid source stream.
* @inner
*/
var SOURCE_NOT_ATTACHED_ERROR = 'You must first call attachSource() with a valid source before calling this method';
/**
* @constant {string} MEDIA_PLAYER_NOT_INITIALIZED_ERROR error string thrown when a function is called before the dash.js has been fully initialized.
* @inner
*/
var MEDIA_PLAYER_NOT_INITIALIZED_ERROR = 'MediaPlayer not initialized!';
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_24__["default"])(context).getInstance();
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_28__["default"])(context).getInstance();
var debug = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_22__["default"])(context).getInstance({
settings: settings
});
var instance, logger, source, protectionData, mediaPlayerInitialized, streamingInitialized, playbackInitialized, autoPlay, abrController, schemeLoaderFactory, timelineConverter, mediaController, protectionController, metricsReportingController, mssHandler, offlineController, adapter, mediaPlayerModel, errHandler, baseURLController, capabilities, capabilitiesFilter, streamController, textController, gapController, playbackController, dashMetrics, manifestModel, cmcdModel, videoModel, uriFragmentModel, domStorage, segmentBaseController, licenseRequestFilters, licenseResponseFilters, customCapabilitiesFilters;
/*
---------------------------------------------------------------------------
INIT FUNCTIONS
---------------------------------------------------------------------------
*/
function setup() {
logger = debug.getLogger(instance);
mediaPlayerInitialized = false;
playbackInitialized = false;
streamingInitialized = false;
autoPlay = true;
protectionController = null;
offlineController = null;
protectionData = null;
adapter = null;
segmentBaseController = null;
_core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"].extend(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_26__["default"]);
mediaPlayerModel = Object(_models_MediaPlayerModel__WEBPACK_IMPORTED_MODULE_16__["default"])(context).getInstance();
videoModel = Object(_models_VideoModel__WEBPACK_IMPORTED_MODULE_19__["default"])(context).getInstance();
uriFragmentModel = Object(_models_URIFragmentModel__WEBPACK_IMPORTED_MODULE_14__["default"])(context).getInstance();
licenseRequestFilters = [];
licenseResponseFilters = [];
customCapabilitiesFilters = [];
}
/**
* Configure media player with customs controllers. Helpful for tests
*
* @param {object=} config controllers configuration
* @memberof module:MediaPlayer
* @instance
*/
function setConfig(config) {
if (!config) {
return;
}
if (config.capabilities) {
capabilities = config.capabilities;
}
if (config.capabilitiesFilter) {
capabilitiesFilter = config.capabilitiesFilter;
}
if (config.streamController) {
streamController = config.streamController;
}
if (config.textController) {
textController = config.textController;
}
if (config.gapController) {
gapController = config.gapController;
}
if (config.playbackController) {
playbackController = config.playbackController;
}
if (config.mediaPlayerModel) {
mediaPlayerModel = config.mediaPlayerModel;
}
if (config.abrController) {
abrController = config.abrController;
}
if (config.schemeLoaderFactory) {
schemeLoaderFactory = config.schemeLoaderFactory;
}
if (config.mediaController) {
mediaController = config.mediaController;
}
if (config.settings) {
settings = config.settings;
}
}
/**
* Upon creating the MediaPlayer you must call initialize before you call anything else.
* There is one exception to this rule. It is crucial to call {@link module:MediaPlayer#extend extend()}
* with all your extensions prior to calling initialize.
*
* ALL arguments are optional and there are individual methods to set each argument later on.
* The args in this method are just for convenience and should only be used for a simple player setup.
*
* @param {HTML5MediaElement=} view - Optional arg to set the video element. {@link module:MediaPlayer#attachView attachView()}
* @param {string=} source - Optional arg to set the media source. {@link module:MediaPlayer#attachSource attachSource()}
* @param {boolean=} AutoPlay - Optional arg to set auto play. {@link module:MediaPlayer#setAutoPlay setAutoPlay()}
* @see {@link module:MediaPlayer#attachView attachView()}
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @see {@link module:MediaPlayer#setAutoPlay setAutoPlay()}
* @memberof module:MediaPlayer
* @instance
*/
function initialize(view, source, AutoPlay) {
if (!capabilities) {
capabilities = Object(_utils_Capabilities__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
capabilities.setConfig({
settings: settings
});
}
if (!errHandler) {
errHandler = Object(_utils_ErrorHandler__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
}
if (!capabilities.supportsMediaSource()) {
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_37__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"].CAPABILITY_MEDIASOURCE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"].CAPABILITY_MEDIASOURCE_ERROR_MESSAGE));
return;
}
if (!mediaPlayerInitialized) {
mediaPlayerInitialized = true; // init some controllers and models
timelineConverter = Object(_dash_utils_TimelineConverter__WEBPACK_IMPORTED_MODULE_33__["default"])(context).getInstance();
if (!abrController) {
abrController = Object(_controllers_AbrController__WEBPACK_IMPORTED_MODULE_17__["default"])(context).getInstance();
abrController.setConfig({
settings: settings
});
}
if (!schemeLoaderFactory) {
schemeLoaderFactory = Object(_net_SchemeLoaderFactory__WEBPACK_IMPORTED_MODULE_18__["default"])(context).getInstance();
}
if (!playbackController) {
playbackController = Object(_controllers_PlaybackController__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
}
if (!mediaController) {
mediaController = Object(_controllers_MediaController__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
}
if (!streamController) {
streamController = Object(_controllers_StreamController__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
}
if (!gapController) {
gapController = Object(_controllers_GapController__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
}
if (!capabilitiesFilter) {
capabilitiesFilter = Object(_utils_CapabilitiesFilter__WEBPACK_IMPORTED_MODULE_12__["default"])(context).getInstance();
}
adapter = Object(_dash_DashAdapter__WEBPACK_IMPORTED_MODULE_31__["default"])(context).getInstance();
manifestModel = Object(_models_ManifestModel__WEBPACK_IMPORTED_MODULE_15__["default"])(context).getInstance();
cmcdModel = Object(_models_CmcdModel__WEBPACK_IMPORTED_MODULE_20__["default"])(context).getInstance();
dashMetrics = Object(_dash_DashMetrics__WEBPACK_IMPORTED_MODULE_32__["default"])(context).getInstance({
settings: settings
});
domStorage = Object(_utils_DOMStorage__WEBPACK_IMPORTED_MODULE_21__["default"])(context).getInstance({
settings: settings
});
adapter.setConfig({
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
cea608parser: _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_0___default.a,
errHandler: errHandler,
BASE64: _externals_base64__WEBPACK_IMPORTED_MODULE_35___default.a
});
if (!baseURLController) {
baseURLController = Object(_controllers_BaseURLController__WEBPACK_IMPORTED_MODULE_8__["default"])(context).create();
}
baseURLController.setConfig({
adapter: adapter
});
if (!segmentBaseController) {
segmentBaseController = Object(_dash_controllers_SegmentBaseController__WEBPACK_IMPORTED_MODULE_30__["default"])(context).getInstance({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
errHandler: errHandler,
baseURLController: baseURLController,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"],
eventBus: eventBus,
debug: debug,
boxParser: Object(_utils_BoxParser__WEBPACK_IMPORTED_MODULE_41__["default"])(context).getInstance(),
requestModifier: Object(_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance(),
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"]
});
} // configure controllers
mediaController.setConfig({
domStorage: domStorage,
settings: settings
});
restoreDefaultUTCTimingSources();
setAutoPlay(AutoPlay !== undefined ? AutoPlay : true); // Detect and initialize offline module to support offline contents playback
_detectOffline();
}
if (view) {
attachView(view);
}
if (source) {
attachSource(source);
}
logger.info('[dash.js ' + getVersion() + '] ' + 'MediaPlayer has been initialized');
}
/**
* Sets the MPD source and the video element to null. You can also reset the MediaPlayer by
* calling attachSource with a new source file.
*
* This call does not destroy the MediaPlayer. To destroy the MediaPlayer and free all of its
* memory, call destroy().
*
* @memberof module:MediaPlayer
* @instance
*/
function reset() {
attachSource(null);
attachView(null);
protectionData = null;
if (protectionController) {
protectionController.reset();
protectionController = null;
}
if (metricsReportingController) {
metricsReportingController.reset();
metricsReportingController = null;
}
settings.reset();
if (offlineController) {
offlineController.reset();
offlineController = null;
}
}
/**
* Completely destroys the media player and frees all memory.
*
* @memberof module:MediaPlayer
* @instance
*/
function destroy() {
reset();
licenseRequestFilters = [];
licenseResponseFilters = [];
customCapabilitiesFilters = [];
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_27__["default"].deleteSingletonInstances(context);
}
/**
* The ready state of the MediaPlayer based on both the video element and MPD source being defined.
*
* @returns {boolean} The current ready state of the MediaPlayer
* @see {@link module:MediaPlayer#attachView attachView()}
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @memberof module:MediaPlayer
* @instance
*/
function isReady() {
return !!source && !!videoModel.getElement();
}
/**
* Use the on method to listen for public events found in MediaPlayer.events. {@link MediaPlayerEvents}
*
* @param {string} type - {@link MediaPlayerEvents}
* @param {Function} listener - callback method when the event fires.
* @param {Object} scope - context of the listener so it can be removed properly.
* @param {Object} options - object to define various options such as priority and mode
* @memberof module:MediaPlayer
* @instance
*/
function on(type, listener, scope, options) {
eventBus.on(type, listener, scope, options);
}
/**
* Use the off method to remove listeners for public events found in MediaPlayer.events. {@link MediaPlayerEvents}
*
* @param {string} type - {@link MediaPlayerEvents}
* @param {Function} listener - callback method when the event fires.
* @param {Object} scope - context of the listener so it can be removed properly.
* @memberof module:MediaPlayer
* @instance
*/
function off(type, listener, scope) {
eventBus.off(type, listener, scope);
}
/**
* Current version of Dash.js
* @returns {string} the current dash.js version string.
* @memberof module:MediaPlayer
* @instance
*/
function getVersion() {
return Object(_core_Version__WEBPACK_IMPORTED_MODULE_29__["getVersionString"])();
}
/**
* Use this method to access the dash.js logging class.
*
* @returns {Debug}
* @memberof module:MediaPlayer
* @instance
*/
function getDebug() {
return debug;
}
/*
---------------------------------------------------------------------------
PLAYBACK FUNCTIONS
---------------------------------------------------------------------------
*/
/**
* The play method initiates playback of the media defined by the {@link module:MediaPlayer#attachSource attachSource()} method.
* This method will call play on the native Video Element.
*
* @see {@link module:MediaPlayer#attachSource attachSource()}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function play() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
if (!autoPlay || isPaused() && playbackInitialized) {
playbackController.play();
}
}
/**
* This method will call pause on the native Video Element.
*
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function pause() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
playbackController.pause();
}
/**
* Returns a Boolean that indicates whether the Video Element is paused.
* @return {boolean}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function isPaused() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.isPaused();
}
/**
* Sets the currentTime property of the attached video element. If it is a live stream with a
* timeShiftBufferLength, then the DVR window offset will be automatically calculated.
*
* @param {number} value - A relative time, in seconds, based on the return value of the {@link module:MediaPlayer#duration duration()} method is expected
* @see {@link module:MediaPlayer#getDVRSeekOffset getDVRSeekOffset()}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not number type or is NaN.
* @memberof module:MediaPlayer
* @instance
*/
function seek(value) {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_38__["checkParameterType"])(value, 'number');
if (isNaN(value)) {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].BAD_ARGUMENT_ERROR;
}
var s = playbackController.getIsDynamic() ? getDVRSeekOffset(value) : value;
playbackController.seek(s);
}
/**
* Returns a Boolean that indicates whether the media is in the process of seeking to a new position.
* @return {boolean}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function isSeeking() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.isSeeking();
}
/**
* Returns a Boolean that indicates whether the media is in the process of dynamic.
* @return {boolean}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function isDynamic() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return playbackController.getIsDynamic();
}
/**
* Use this method to set the native Video Element's playback rate.
* @param {number} value
* @memberof module:MediaPlayer
* @instance
*/
function setPlaybackRate(value) {
getVideoElement().playbackRate = value;
}
/**
* Returns the current playback rate.
* @returns {number}
* @memberof module:MediaPlayer
* @instance
*/
function getPlaybackRate() {
return getVideoElement().playbackRate;
}
/**
* Use this method to set the native Video Element's muted state. Takes a Boolean that determines whether audio is muted. true if the audio is muted and false otherwise.
* @param {boolean} value
* @memberof module:MediaPlayer
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not boolean type.
* @instance
*/
function setMute(value) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_38__["checkParameterType"])(value, 'boolean');
getVideoElement().muted = value;
}
/**
* A Boolean that determines whether audio is muted.
* @returns {boolean}
* @memberof module:MediaPlayer
* @instance
*/
function isMuted() {
return getVideoElement().muted;
}
/**
* A double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest).
* @param {number} value
* @memberof module:MediaPlayer
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not number type, or is NaN or not between 0 and 1.
* @instance
*/
function setVolume(value) {
if (typeof value !== 'number' || isNaN(value) || value < 0.0 || value > 1.0) {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].BAD_ARGUMENT_ERROR;
}
getVideoElement().volume = value;
}
/**
* Returns the current audio volume, from 0.0 (silent) to 1.0 (loudest).
* @returns {number}
* @memberof module:MediaPlayer
* @instance
*/
function getVolume() {
return getVideoElement().volume;
}
/**
* The length of the buffer for a given media type, in seconds. Valid media
* types are "video", "audio" and "text". If no type is passed
* in, then the minimum of video, audio and text buffer length is
* returned. NaN is returned if an invalid type is requested, the
* presentation does not contain that type, or if no arguments are passed
* and the presentation does not include any adaption sets of valid media
* type.
*
* @param {MediaType} type - 'video', 'audio' or 'text'
* @returns {number} The length of the buffer for the given media type, in
* seconds, or NaN
* @memberof module:MediaPlayer
* @instance
*/
function getBufferLength(type) {
var types = [_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO, _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO, _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].TEXT];
if (!type) {
var buffer = types.map(function (t) {
return getTracksFor(t).length > 0 ? getDashMetrics().getCurrentBufferLevel(t) : Number.MAX_VALUE;
}).reduce(function (p, c) {
return Math.min(p, c);
});
return buffer === Number.MAX_VALUE ? NaN : buffer;
} else {
if (types.indexOf(type) !== -1) {
var _buffer = getDashMetrics().getCurrentBufferLevel(type);
return _buffer ? _buffer : NaN;
} else {
logger.warn('getBufferLength requested for invalid type');
return NaN;
}
}
}
/**
* The timeShiftBufferLength (DVR Window), in seconds.
*
* @returns {number} The window of allowable play time behind the live point of a live stream as defined in the manifest.
* @memberof module:MediaPlayer
* @instance
*/
function getDVRWindowSize() {
var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO;
var metric = dashMetrics.getCurrentDVRInfo(type);
if (!metric) {
return 0;
}
return metric.manifestInfo.dvrWindowSize;
}
/**
* This method should only be used with a live stream that has a valid timeShiftBufferLength (DVR Window).
* NOTE - If you do not need the raw offset value (i.e. media analytics, tracking, etc) consider using the {@link module:MediaPlayer#seek seek()} method
* which will calculate this value for you and set the video element's currentTime property all in one simple call.
*
* @param {number} value - A relative time, in seconds, based on the return value of the {@link module:MediaPlayer#duration duration()} method is expected.
* @returns {number} A value that is relative the available range within the timeShiftBufferLength (DVR Window).
* @see {@link module:MediaPlayer#seek seek()}
* @memberof module:MediaPlayer
* @instance
*/
function getDVRSeekOffset(value) {
var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO;
var metric = dashMetrics.getCurrentDVRInfo(type);
if (!metric) {
return 0;
}
var liveDelay = playbackController.getLiveDelay();
var val = metric.range.start + value;
if (val > metric.range.end - liveDelay) {
val = metric.range.end - liveDelay;
}
return val;
}
/**
* Current time of the playhead, in seconds.
*
* If called with no arguments then the returned time value is time elapsed since the start point of the first stream, or if it is a live stream, then the time will be based on the return value of the {@link module:MediaPlayer#duration duration()} method.
* However if a stream ID is supplied then time is relative to the start of that stream, or is null if there is no such stream id in the manifest.
*
* @param {string} streamId - The ID of a stream that the returned playhead time must be relative to the start of. If undefined, then playhead time is relative to the first stream.
* @returns {number} The current playhead time of the media, or null.
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function time(streamId) {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
var t = getVideoElement().currentTime;
if (streamId !== undefined) {
t = streamController.getTimeRelativeToStreamId(t, streamId);
} else if (playbackController.getIsDynamic()) {
var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO;
var metric = dashMetrics.getCurrentDVRInfo(type);
t = metric === null || t === 0 ? 0 : Math.max(0, t - metric.range.start);
}
return t;
}
/**
* Duration of the media's playback, in seconds.
*
* @returns {number} The current duration of the media. For a dynamic stream this will return DVRWindow.end - DVRWindow.start
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function duration() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
var d = getVideoElement().duration;
if (playbackController.getIsDynamic()) {
var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO;
var metric = dashMetrics.getCurrentDVRInfo(type);
d = metric ? metric.range.end - metric.range.start : 0;
}
return d;
}
/**
* Use this method to get the current playhead time as an absolute value, the time in seconds since midnight UTC, Jan 1 1970.
* Note - this property only has meaning for live streams. If called before play() has begun, it will return a value of NaN.
*
* @returns {number} The current playhead time as UTC timestamp.
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function timeAsUTC() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
if (time() < 0) {
return NaN;
}
return _getAsUTC(time());
}
/**
* Use this method to get the current duration as an absolute value, the time in seconds since midnight UTC, Jan 1 1970.
* Note - this property only has meaning for live streams.
*
* @returns {number} The current duration as UTC timestamp.
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function durationAsUTC() {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
return _getAsUTC(duration());
}
/*
---------------------------------------------------------------------------
AUTO BITRATE
---------------------------------------------------------------------------
*/
/**
* Gets the top quality BitrateInfo checking portal limit and max allowed.
* It calls getMaxAllowedIndexFor internally
*
* @param {MediaType} type - 'video' or 'audio'
* @memberof module:MediaPlayer
* @returns {BitrateInfo | null}
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getTopBitrateInfoFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
return abrController.getTopBitrateInfoFor(type);
}
/**
* Gets the current download quality for media type video, audio or images. For video and audio types the ABR
* rules update this value before every new download unless autoSwitchBitrate is set to false. For 'image'
* type, thumbnails, there is no ABR algorithm and quality is set manually.
*
* @param {MediaType} type - 'video', 'audio' or 'image' (thumbnails)
* @returns {number} the quality index, 0 corresponding to the lowest bitrate
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#setQualityFor setQualityFor()}
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getQualityFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].IMAGE) {
var activeStream = getActiveStream();
if (!activeStream) {
return -1;
}
var thumbnailController = activeStream.getThumbnailController();
return !thumbnailController ? -1 : thumbnailController.getCurrentTrackIndex();
}
return abrController.getQualityFor(type);
}
/**
* Sets the current quality for media type instead of letting the ABR Heuristics automatically selecting it.
* This value will be overwritten by the ABR rules unless autoSwitchBitrate is set to false.
*
* @param {MediaType} type - 'video', 'audio' or 'image'
* @param {number} value - the quality index, 0 corresponding to the lowest bitrate
* @param {boolean} forceReplace - true if segments have to be replaced by segments of the new quality
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#getQualityFor getQualityFor()}
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function setQualityFor(type, value) {
var forceReplace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].IMAGE) {
var activeStream = getActiveStream();
if (!activeStream) {
return;
}
var thumbnailController = activeStream.getThumbnailController();
if (thumbnailController) {
thumbnailController.setTrackByIndex(value);
}
}
abrController.setPlaybackQuality(type, streamController.getActiveStreamInfo(), value, {
forceReplace: forceReplace
});
}
/**
* Update the video element size variables
* Should be called on window resize (or any other time player is resized). Fullscreen does trigger a window resize event.
*
* Once windowResizeEventCalled = true, abrController.checkPortalSize() will use element size variables rather than querying clientWidth every time.
*
* @memberof module:MediaPlayer
* @instance
*/
function updatePortalSize() {
abrController.setElementSize();
abrController.setWindowResizeEventCalled(true);
}
/*
---------------------------------------------------------------------------
MEDIA PLAYER CONFIGURATION
---------------------------------------------------------------------------
*/
/**
* <p>Set to false to prevent stream from auto-playing when the view is attached.</p>
*
* @param {boolean} value
* @default true
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#attachView attachView()}
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with an invalid argument, not boolean type.
* @instance
*
*/
function setAutoPlay(value) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_38__["checkParameterType"])(value, 'boolean');
autoPlay = value;
}
/**
* @returns {boolean} The current autoPlay state.
* @memberof module:MediaPlayer
* @instance
*/
function getAutoPlay() {
return autoPlay;
}
/**
* @memberof module:MediaPlayer
* @instance
* @returns {number|NaN} Current live stream latency in seconds. It is the difference between now time and time position at the playback head.
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
*/
function getCurrentLiveLatency() {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
if (!playbackInitialized) {
return NaN;
}
return playbackController.getCurrentLiveLatency();
}
/**
* Add a custom ABR Rule
* Rule will be apply on next stream if a stream is being played
*
* @param {string} type - rule type (one of ['qualitySwitchRules','abandonFragmentRules'])
* @param {string} rulename - name of rule (used to identify custom rule). If one rule of same name has been added, then existing rule will be updated
* @param {object} rule - the rule object instance
* @memberof module:MediaPlayer
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with invalid arguments.
* @instance
*/
function addABRCustomRule(type, rulename, rule) {
mediaPlayerModel.addABRCustomRule(type, rulename, rule);
}
/**
* Remove a custom ABR Rule
*
* @param {string} rulename - name of the rule to be removed
* @memberof module:MediaPlayer
* @instance
*/
function removeABRCustomRule(rulename) {
mediaPlayerModel.removeABRCustomRule(rulename);
}
/**
* Remove all custom rules
* @memberof module:MediaPlayer
* @instance
*/
function removeAllABRCustomRule() {
mediaPlayerModel.removeABRCustomRule();
}
/**
* <p>Allows you to set a scheme and server source for UTC live edge detection for dynamic streams.
* If UTCTiming is defined in the manifest, it will take precedence over any time source manually added.</p>
* <p>If you have exposed the Date header, use the method {@link module:MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}.
* This will allow the date header on the manifest to be used instead of a time server</p>
* @param {string} schemeIdUri - <ul>
* <li>urn:mpeg:dash:utc:http-head:2014</li>
* <li>urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>urn:mpeg:dash:utc:http-iso:2014</li>
* <li>urn:mpeg:dash:utc:direct:2014</li>
* </ul>
* <p>Some specs referencing early ISO23009-1 drafts incorrectly use
* 2012 in the URI, rather than 2014. support these for now.</p>
* <ul>
* <li>urn:mpeg:dash:utc:http-head:2012</li>
* <li>urn:mpeg:dash:utc:http-xsdate:2012</li>
* <li>urn:mpeg:dash:utc:http-iso:2012</li>
* <li>urn:mpeg:dash:utc:direct:2012</li>
* </ul>
* @param {string} value - Path to a time source.
* @default
* <ul>
* <li>schemeIdUri:urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>value:http://time.akamai.com/?iso&ms/li>
* </ul>
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#removeUTCTimingSource removeUTCTimingSource()}
* @instance
*/
function addUTCTimingSource(schemeIdUri, value) {
mediaPlayerModel.addUTCTimingSource(schemeIdUri, value);
}
/**
* <p>Allows you to remove a UTC time source. Both schemeIdUri and value need to match the Dash.vo.UTCTiming properties in order for the
* entry to be removed from the array</p>
* @param {string} schemeIdUri - see {@link module:MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @param {string} value - see {@link module:MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}
* @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with invalid arguments, schemeIdUri and value are not string type.
* @instance
*/
function removeUTCTimingSource(schemeIdUri, value) {
mediaPlayerModel.removeUTCTimingSource(schemeIdUri, value);
}
/**
* <p>Allows you to clear the stored array of time sources.</p>
* <p>Example use: If you have exposed the Date header, calling this method
* will allow the date header on the manifest to be used instead of the time server.</p>
* <p>Example use: Calling this method, assuming there is not an exposed date header on the manifest, will default back
* to using a binary search to discover the live edge</p>
*
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#restoreDefaultUTCTimingSources restoreDefaultUTCTimingSources()}
* @instance
*/
function clearDefaultUTCTimingSources() {
mediaPlayerModel.clearDefaultUTCTimingSources();
}
/**
* <p>Allows you to restore the default time sources after calling {@link module:MediaPlayer#clearDefaultUTCTimingSources clearDefaultUTCTimingSources()}</p>
*
* @default
* <ul>
* <li>schemeIdUri:urn:mpeg:dash:utc:http-xsdate:2014</li>
* <li>value:http://time.akamai.com/?iso&ms</li>
* </ul>
*
* @memberof module:MediaPlayer
* @see {@link module:MediaPlayer#addUTCTimingSource addUTCTimingSource()}
* @instance
*/
function restoreDefaultUTCTimingSources() {
mediaPlayerModel.restoreDefaultUTCTimingSources();
}
/**
* Returns the average throughput computed in the ABR logic
*
* @param {MediaType} type
* @return {number} value
* @memberof module:MediaPlayer
* @instance
*/
function getAverageThroughput(type) {
var throughputHistory = abrController.getThroughputHistory();
var isDynamic = playbackController.getIsDynamic();
return throughputHistory ? throughputHistory.getAverageThroughput(type, isDynamic) : 0;
}
/**
* Sets whether withCredentials on XHR requests for a particular request
* type is true or false
*
* @default false
* @param {string} type - one of HTTPRequest.*_TYPE
* @param {boolean} value
* @memberof module:MediaPlayer
* @instance
*/
function setXHRWithCredentialsForType(type, value) {
mediaPlayerModel.setXHRWithCredentialsForType(type, value);
}
/**
* Gets whether withCredentials on XHR requests for a particular request
* type is true or false
*
* @param {string} type - one of HTTPRequest.*_TYPE
* @return {boolean}
* @memberof module:MediaPlayer
* @instance
*/
function getXHRWithCredentialsForType(type) {
return mediaPlayerModel.getXHRWithCredentialsForType(type);
}
/*
---------------------------------------------------------------------------
OFFLINE
---------------------------------------------------------------------------
*/
/**
* Detects if Offline is included and returns an instance of OfflineController.js
* @memberof module:MediaPlayer
* @instance
*/
function getOfflineController() {
return _detectOffline();
}
/*
---------------------------------------------------------------------------
METRICS
---------------------------------------------------------------------------
*/
/**
* Returns the DashMetrics.js Module. You use this Module to get access to all the public metrics
* stored in dash.js
*
* @see {@link module:DashMetrics}
* @returns {Object}
* @memberof module:MediaPlayer
* @instance
*/
function getDashMetrics() {
return dashMetrics;
}
/*
---------------------------------------------------------------------------
TEXT MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Enable/disable text
* When enabling text, dash will choose the previous selected text track
*
* @param {boolean} enable - true to enable text, false otherwise (same as setTextTrack(-1))
* @memberof module:MediaPlayer
* @instance
*/
function enableText(enable) {
var activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return false;
}
return textController.enableText(activeStreamInfo.id, enable);
}
/**
* Enable/disable text
* When enabling dash will keep downloading and process fragmented text tracks even if all tracks are in mode "hidden"
*
* @param {boolean} enable - true to enable text streaming even if all text tracks are hidden.
* @memberof module:MediaPlayer
* @instance
*/
function enableForcedTextStreaming(enable) {
var activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return false;
}
return textController.enableForcedTextStreaming(enable);
}
/**
* Return if text is enabled
*
* @return {boolean} return true if text is enabled, false otherwise
* @memberof module:MediaPlayer
* @instance
*/
function isTextEnabled() {
var activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return false;
}
return textController.isTextEnabled(activeStreamInfo);
}
/**
* Use this method to change the current text track for both external time text files and fragmented text tracks. There is no need to
* set the track mode on the video object to switch a track when using this method.
* @param {number} idx - Index of track based on the order of the order the tracks are added Use -1 to disable all tracks. (turn captions off). Use module:MediaPlayer#dashjs.MediaPlayer.events.TEXT_TRACK_ADDED.
* @see {@link MediaPlayerEvents#event:TEXT_TRACK_ADDED dashjs.MediaPlayer.events.TEXT_TRACK_ADDED}
* @throws {@link module:MediaPlayer~PLAYBACK_NOT_INITIALIZED_ERROR PLAYBACK_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function setTextTrack(idx) {
if (!playbackInitialized) {
throw PLAYBACK_NOT_INITIALIZED_ERROR;
}
var activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return;
}
textController.setTextTrack(activeStreamInfo.id, idx);
}
function getCurrentTextTrackIndex() {
var idx = NaN;
var activeStreamInfo = streamController.getActiveStreamInfo();
if (!activeStreamInfo || !textController) {
return;
}
idx = textController.getCurrentTrackIdx(activeStreamInfo.id);
return idx;
}
/*
---------------------------------------------------------------------------
VIDEO ELEMENT MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Returns instance of Video Element that was attached by calling attachView()
* @returns {Object}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~ELEMENT_NOT_ATTACHED_ERROR ELEMENT_NOT_ATTACHED_ERROR} if called before attachView function
* @instance
*/
function getVideoElement() {
if (!videoModel.getElement()) {
throw ELEMENT_NOT_ATTACHED_ERROR;
}
return videoModel.getElement();
}
/**
* Use this method to attach an HTML5 VideoElement for dash.js to operate upon.
*
* @param {Object} element - An HTMLMediaElement that has already been defined in the DOM (or equivalent stub).
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
* @instance
*/
function attachView(element) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
videoModel.setElement(element);
if (element) {
_detectProtection();
_detectMetricsReporting();
_detectMss();
if (streamController) {
streamController.switchToVideoElement();
}
}
if (playbackInitialized) {
//Reset if we have been playing before, so this is a new element.
_resetPlaybackControllers();
}
_initializePlayback();
}
/**
* Returns instance of Div that was attached by calling attachTTMLRenderingDiv()
* @returns {Object}
* @memberof module:MediaPlayer
* @instance
*/
function getTTMLRenderingDiv() {
return videoModel ? videoModel.getTTMLRenderingDiv() : null;
}
/**
* Use this method to attach an HTML5 div for dash.js to render rich TTML subtitles.
*
* @param {HTMLDivElement} div - An unstyled div placed after the video element. It will be styled to match the video size and overlay z-order.
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~ELEMENT_NOT_ATTACHED_ERROR ELEMENT_NOT_ATTACHED_ERROR} if called before attachView function
* @instance
*/
function attachTTMLRenderingDiv(div) {
if (!videoModel.getElement()) {
throw ELEMENT_NOT_ATTACHED_ERROR;
}
videoModel.setTTMLRenderingDiv(div);
}
/*
---------------------------------------------------------------------------
STREAM AND TRACK MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* @param {MediaType} type
* @returns {Array}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getBitrateInfoListFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
var stream = getActiveStream();
return stream ? stream.getBitrateListFor(type) : [];
}
/**
* This method returns the list of all available streams from a given manifest
* @param {Object} manifest
* @returns {Array} list of {@link StreamInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getStreamsFromManifest(manifest) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
return adapter.getStreamsInfo(manifest);
}
/**
* This method returns the list of all available tracks for a given media type
* @param {MediaType} type
* @returns {Array} list of {@link MediaInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getTracksFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
var streamInfo = streamController.getActiveStreamInfo();
if (!streamInfo) {
return [];
}
return mediaController.getTracksFor(type, streamInfo.id);
}
/**
* This method returns the list of all available tracks for a given media type and streamInfo from a given manifest
* @param {MediaType} type
* @param {Object} manifest
* @param {Object} streamInfo
* @returns {Array} list of {@link MediaInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getTracksForTypeFromManifest(type, manifest, streamInfo) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
streamInfo = streamInfo || adapter.getStreamsInfo(manifest, 1)[0];
return streamInfo ? adapter.getAllMediaInfoForType(streamInfo, type, manifest) : [];
}
/**
* @param {MediaType} type
* @returns {Object|null} {@link MediaInfo}
*
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function getCurrentTrackFor(type) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
var streamInfo = streamController.getActiveStreamInfo();
return mediaController.getCurrentTrackFor(type, streamInfo.id);
}
/**
* This method allows to set media settings that will be used to pick the initial track. Format of the settings
* is following: <br />
* {lang: langValue (can be either a string or a regex to match),
* index: indexValue,
* viewpoint: viewpointValue,
* audioChannelConfiguration: audioChannelConfigurationValue,
* accessibility: accessibilityValue,
* role: roleValue}
*
* @param {MediaType} type
* @param {Object} value
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
* @instance
*/
function setInitialMediaSettingsFor(type, value) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
mediaController.setInitialSettings(type, value);
}
/**
* This method returns media settings that is used to pick the initial track. Format of the settings
* is following:
* {lang: langValue,
* index: indexValue,
* viewpoint: viewpointValue,
* audioChannelConfiguration: audioChannelConfigurationValue,
* accessibility: accessibilityValue,
* role: roleValue}
* @param {MediaType} type
* @returns {Object}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
* @instance
*/
function getInitialMediaSettingsFor(type) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
return mediaController.getInitialSettings(type);
}
/**
* @param {MediaInfo} track - instance of {@link MediaInfo}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @instance
*/
function setCurrentTrack(track) {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
mediaController.setTrack(track);
}
/*
---------------------------------------------------------------------------
PROTECTION MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Detects if Protection is included and returns an instance of ProtectionController.js
* @memberof module:MediaPlayer
* @instance
*/
function getProtectionController() {
return _detectProtection();
}
/**
* Will override dash.js protection controller.
* @param {ProtectionController} value - valid protection controller instance.
* @memberof module:MediaPlayer
* @instance
*/
function attachProtectionController(value) {
protectionController = value;
}
/**
* Sets Protection Data required to setup the Protection Module (DRM). Protection Data must
* be set before initializing MediaPlayer or, once initialized, before PROTECTION_CREATED event is fired.
* @see {@link module:MediaPlayer#initialize initialize()}
* @see {@link ProtectionEvents#event:PROTECTION_CREATED dashjs.Protection.events.PROTECTION_CREATED}
* @param {ProtectionDataSet} value - object containing
* property names corresponding to key system name strings and associated
* values being instances of.
* @memberof module:MediaPlayer
* @instance
*/
function setProtectionData(value) {
protectionData = value; // Propagate changes in case StreamController is already created
if (streamController) {
streamController.setProtectionData(protectionData);
}
}
/**
* Registers a license request filter. This enables application to manipulate/overwrite any request parameter and/or request data.
* The provided callback function shall return a promise that shall be resolved once the filter process is completed.
* The filters are applied in the order they are registered.
* @param {function} filter - the license request filter callback
* @memberof module:MediaPlayer
* @instance
*/
function registerLicenseRequestFilter(filter) {
licenseRequestFilters.push(filter);
if (protectionController) {
protectionController.setLicenseRequestFilters(licenseRequestFilters);
}
}
/**
* Registers a license response filter. This enables application to manipulate/overwrite the response data
* The provided callback function shall return a promise that shall be resolved once the filter process is completed.
* The filters are applied in the order they are registered.
* @param {function} filter - the license response filter callback
* @memberof module:MediaPlayer
* @instance
*/
function registerLicenseResponseFilter(filter) {
licenseResponseFilters.push(filter);
if (protectionController) {
protectionController.setLicenseResponseFilters(licenseResponseFilters);
}
}
/**
* Unregisters a license request filter.
* @param {function} filter - the license request filter callback
* @memberof module:MediaPlayer
* @instance
*/
function unregisterLicenseRequestFilter(filter) {
unregisterFilter(licenseRequestFilters, filter);
if (protectionController) {
protectionController.setLicenseRequestFilters(licenseRequestFilters);
}
}
/**
* Unregisters a license response filter.
* @param {function} filter - the license response filter callback
* @memberof module:MediaPlayer
* @instance
*/
function unregisterLicenseResponseFilter(filter) {
unregisterFilter(licenseResponseFilters, filter);
if (protectionController) {
protectionController.setLicenseResponseFilters(licenseResponseFilters);
}
}
/**
* Registers a custom capabilities filter. This enables application to filter representations to use.
* The provided callback function shall return a boolean based on whether or not to use the representation.
* The filters are applied in the order they are registered.
* @param {function} filter - the custom capabilities filter callback
* @memberof module:MediaPlayer
* @instance
*/
function registerCustomCapabilitiesFilter(filter) {
customCapabilitiesFilters.push(filter);
if (capabilitiesFilter) {
capabilitiesFilter.setCustomCapabilitiesFilters(customCapabilitiesFilters);
}
}
/**
* Unregisters a custom capabilities filter.
* @param {function} filter - the custom capabilities filter callback
* @memberof module:MediaPlayer
* @instance
*/
function unregisterCustomCapabilitiesFilter(filter) {
unregisterFilter(customCapabilitiesFilters, filter);
if (capabilitiesFilter) {
capabilitiesFilter.setCustomCapabilitiesFilters(customCapabilitiesFilters);
}
}
function unregisterFilter(filters, filter) {
var index = -1;
filters.some(function (item, i) {
if (item === filter) {
index = i;
return true;
}
});
if (index < 0) return;
filters.splice(index, 1);
}
/**
* Registers a custom initial track selection function. Only one function is allowed. Calling this method will overwrite a potentially existing function.
* @param {function} customFunc - the custom function that returns the initial track
*/
function setCustomInitialTrackSelectionFunction(customFunc) {
if (mediaController) {
mediaController.setCustomInitialTrackSelectionFunction(customFunc);
}
}
/**
* Resets the custom initial track selection
*/
function resetCustomInitialTrackSelectionFunction() {
if (mediaController) {
mediaController.setCustomInitialTrackSelectionFunction(null);
}
}
/*
---------------------------------------------------------------------------
THUMBNAILS MANAGEMENT
---------------------------------------------------------------------------
*/
/**
* Provide the thumbnail at time position. This can be asynchronous, so you must provide a callback ro retrieve thumbnails informations
* @param {number} time - A relative time, in seconds, based on the return value of the {@link module:MediaPlayer#duration duration()} method is expected
* @param {function} callback - A Callback function provided when retrieving thumbnail the given time position. Thumbnail object is null in case there are is not a thumbnails representation or
* if it doesn't contain a thumbnail for the given time position.
* @memberof module:MediaPlayer
* @instance
*/
function provideThumbnail(time, callback) {
if (typeof callback !== 'function') {
return;
}
if (time < 0) {
callback(null);
return;
}
var s = playbackController.getIsDynamic() ? getDVRSeekOffset(time) : time;
var stream = streamController.getStreamForTime(s);
if (stream === null) {
callback(null);
return;
}
var thumbnailController = stream.getThumbnailController();
if (!thumbnailController) {
callback(null);
return;
}
var timeInPeriod = streamController.getTimeRelativeToStreamId(s, stream.getId());
return thumbnailController.provide(timeInPeriod, callback);
}
/*
---------------------------------------------------------------------------
TOOLS AND OTHERS FUNCTIONS
---------------------------------------------------------------------------
*/
/**
* Allows application to retrieve a manifest. Manifest loading is asynchro
* nous and
* requires the app-provided callback function
*
* @param {string} url - url the manifest url
* @param {function} callback - A Callback function provided when retrieving manifests
* @memberof module:MediaPlayer
* @instance
*/
function retrieveManifest(url, callback) {
var manifestLoader = _createManifestLoader();
var self = this;
var handler = function handler(e) {
if (!e.error) {
callback(e.manifest);
} else {
callback(null, e.error);
}
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"].INTERNAL_MANIFEST_LOADED, handler, self);
manifestLoader.reset();
};
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"].INTERNAL_MANIFEST_LOADED, handler, self);
uriFragmentModel.initialize(url);
manifestLoader.load(url);
}
/**
* Returns the source string or manifest that was attached by calling attachSource()
* @returns {string | manifest}
* @memberof module:MediaPlayer
* @throws {@link module:MediaPlayer~SOURCE_NOT_ATTACHED_ERROR SOURCE_NOT_ATTACHED_ERROR} if called before attachSource function
* @instance
*/
function getSource() {
if (!source) {
throw SOURCE_NOT_ATTACHED_ERROR;
}
return source;
}
/**
* Use this method to set a source URL to a valid MPD manifest file OR
* a previously downloaded and parsed manifest object. Optionally, can
* also provide protection information
*
* @param {string|Object} urlOrManifest - A URL to a valid MPD manifest file, or a
* parsed manifest object.
*
*
* @throws {@link module:MediaPlayer~MEDIA_PLAYER_NOT_INITIALIZED_ERROR MEDIA_PLAYER_NOT_INITIALIZED_ERROR} if called before initialize function
*
* @memberof module:MediaPlayer
* @instance
*/
function attachSource(urlOrManifest) {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
if (typeof urlOrManifest === 'string') {
uriFragmentModel.initialize(urlOrManifest);
}
source = urlOrManifest;
if (streamingInitialized || playbackInitialized) {
_resetPlaybackControllers();
}
if (isReady()) {
_initializePlayback();
}
}
/**
* Get the current settings object being used on the player.
* @returns {PlayerSettings} The settings object being used.
*
* @memberof module:MediaPlayer
* @instance
*/
function getSettings() {
return settings.get();
}
/**
* @summary Update the current settings object being used on the player. Anything left unspecified is not modified.
* @param {PlayerSettings} settingsObj - An object corresponding to the settings definition.
* @description This function does not update the entire object, only properties in the passed in object are updated.
*
* This means that updateSettings({a: x}) and updateSettings({b: y}) are functionally equivalent to
* updateSettings({a: x, b: y}). If the default values are required again, @see{@link resetSettings}.
* @example
* player.updateSettings({
* streaming: {
* lowLatencyEnabled: false,
* abr: {
* maxBitrate: { audio: 100, video: 1000 }
* }
* }
* });
* @memberof module:MediaPlayer
* @instance
*/
function updateSettings(settingsObj) {
settings.update(settingsObj);
}
/**
* Resets the settings object back to the default.
*
* @memberof module:MediaPlayer
* @instance
*/
function resetSettings() {
settings.reset();
}
/**
* A utility methods which converts UTC timestamp value into a valid time and date string.
*
* @param {number} time - UTC timestamp to be converted into date and time.
* @param {string} locales - a region identifier (i.e. en_US).
* @param {boolean} hour12 - 12 vs 24 hour. Set to true for 12 hour time formatting.
* @param {boolean} withDate - default is false. Set to true to append current date to UTC time format.
* @returns {string} A formatted time and date string.
* @memberof module:MediaPlayer
* @instance
*/
function formatUTC(time, locales, hour12) {
var withDate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var dt = new Date(time * 1000);
var d = dt.toLocaleDateString(locales);
var t = dt.toLocaleTimeString(locales, {
hour12: hour12
});
return withDate ? t + ' ' + d : t;
}
/**
* A utility method which converts seconds into TimeCode (i.e. 300 --> 05:00).
*
* @param {number} value - A number in seconds to be converted into a formatted time code.
* @returns {string} A formatted time code string.
* @memberof module:MediaPlayer
* @instance
*/
function convertToTimeCode(value) {
value = Math.max(value, 0);
var h = Math.floor(value / 3600);
var m = Math.floor(value % 3600 / 60);
var s = Math.floor(value % 3600 % 60);
return (h === 0 ? '' : h < 10 ? '0' + h.toString() + ':' : h.toString() + ':') + (m < 10 ? '0' + m.toString() : m.toString()) + ':' + (s < 10 ? '0' + s.toString() : s.toString());
}
/**
* This method should be used to extend or replace internal dash.js objects.
* There are two ways to extend dash.js (determined by the override argument):
* <ol>
* <li>If you set override to true any public method or property in your custom object will
* override the dash.js parent object's property(ies) and will be used instead but the
* dash.js parent module will still be created.</li>
*
* <li>If you set override to false your object will completely replace the dash.js object.
* (Note: This is how it was in 1.x of Dash.js with Dijon).</li>
* </ol>
* <b>When you extend you get access to this.context, this.factory and this.parent to operate with in your custom object.</b>
* <ul>
* <li><b>this.context</b> - can be used to pass context for singleton access.</li>
* <li><b>this.factory</b> - can be used to call factory.getSingletonInstance().</li>
* <li><b>this.parent</b> - is the reference of the parent object to call other public methods. (this.parent is excluded if you extend with override set to false or option 2)</li>
* </ul>
* <b>You must call extend before you call initialize</b>
* @see {@link module:MediaPlayer#initialize initialize()}
* @param {string} parentNameString - name of parent module
* @param {Object} childInstance - overriding object
* @param {boolean} override - replace only some methods (true) or the whole object (false)
* @memberof module:MediaPlayer
* @instance
*/
function extend(parentNameString, childInstance, override) {
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_27__["default"].extend(parentNameString, childInstance, override, context);
}
/**
* This method returns the active stream
*
* @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
* @memberof module:MediaPlayer
* @instance
*/
function getActiveStream() {
if (!streamingInitialized) {
throw STREAMING_NOT_INITIALIZED_ERROR;
}
var streamInfo = streamController.getActiveStreamInfo();
return streamInfo ? streamController.getStreamById(streamInfo.id) : null;
}
/**
* Returns the DashAdapter.js Module.
*
* @see {@link module:DashAdapter}
* @returns {Object}
* @memberof module:MediaPlayer
* @instance
*/
function getDashAdapter() {
return adapter;
} //***********************************
// PRIVATE METHODS
//***********************************
function _resetPlaybackControllers() {
playbackInitialized = false;
streamingInitialized = false;
adapter.reset();
streamController.reset();
gapController.reset();
playbackController.reset();
abrController.reset();
mediaController.reset();
segmentBaseController.reset();
if (protectionController) {
if (settings.get().streaming.protection.keepProtectionMediaKeys) {
protectionController.stop();
} else {
protectionController.reset();
protectionController = null;
_detectProtection();
}
}
textController.reset();
cmcdModel.reset();
}
function _createPlaybackControllers() {
// creates or get objects instances
var manifestLoader = _createManifestLoader();
if (!streamController) {
streamController = Object(_controllers_StreamController__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
}
if (!textController) {
textController = Object(_text_TextController__WEBPACK_IMPORTED_MODULE_42__["default"])(context).create({
errHandler: errHandler,
manifestModel: manifestModel,
adapter: adapter,
mediaController: mediaController,
videoModel: videoModel,
settings: settings
});
}
capabilitiesFilter.setConfig({
capabilities: capabilities,
adapter: adapter,
settings: settings,
manifestModel: manifestModel,
errHandler: errHandler
});
capabilitiesFilter.setCustomCapabilitiesFilters(customCapabilitiesFilters);
streamController.setConfig({
capabilities: capabilities,
capabilitiesFilter: capabilitiesFilter,
manifestLoader: manifestLoader,
manifestModel: manifestModel,
mediaPlayerModel: mediaPlayerModel,
protectionController: protectionController,
textController: textController,
adapter: adapter,
dashMetrics: dashMetrics,
errHandler: errHandler,
timelineConverter: timelineConverter,
videoModel: videoModel,
playbackController: playbackController,
abrController: abrController,
mediaController: mediaController,
settings: settings,
baseURLController: baseURLController,
uriFragmentModel: uriFragmentModel,
segmentBaseController: segmentBaseController
});
gapController.setConfig({
settings: settings,
playbackController: playbackController,
streamController: streamController,
videoModel: videoModel,
timelineConverter: timelineConverter,
adapter: adapter
});
playbackController.setConfig({
streamController: streamController,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
adapter: adapter,
videoModel: videoModel,
timelineConverter: timelineConverter,
settings: settings
});
abrController.setConfig({
streamController: streamController,
domStorage: domStorage,
mediaPlayerModel: mediaPlayerModel,
dashMetrics: dashMetrics,
adapter: adapter,
videoModel: videoModel,
settings: settings
});
cmcdModel.setConfig({
abrController: abrController,
dashMetrics: dashMetrics,
playbackController: playbackController
}); // initialises controller
abrController.initialize();
streamController.initialize(autoPlay, protectionData);
textController.initialize();
gapController.initialize();
cmcdModel.initialize();
segmentBaseController.initialize();
}
function _createManifestLoader() {
return Object(_ManifestLoader__WEBPACK_IMPORTED_MODULE_9__["default"])(context).create({
debug: debug,
errHandler: errHandler,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
requestModifier: Object(_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance(),
mssHandler: mssHandler,
settings: settings
});
}
function _detectProtection() {
if (protectionController) {
return protectionController;
} // do not require Protection as dependencies as this is optional and intended to be loaded separately
var Protection = dashjs.Protection;
/* jshint ignore:line */
if (typeof Protection === 'function') {
//TODO need a better way to register/detect plugin components
var protection = Protection(context).create();
_core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"].extend(Protection.events);
_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_26__["default"].extend(Protection.events, {
publicOnly: true
});
_core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"].extend(Protection.errors);
if (!capabilities) {
capabilities = Object(_utils_Capabilities__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
}
protectionController = protection.createProtectionSystem({
debug: debug,
errHandler: errHandler,
videoModel: videoModel,
capabilities: capabilities,
eventBus: eventBus,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"],
BASE64: _externals_base64__WEBPACK_IMPORTED_MODULE_35___default.a,
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
cmcdModel: cmcdModel,
settings: settings
});
if (protectionController) {
protectionController.setLicenseRequestFilters(licenseRequestFilters);
protectionController.setLicenseResponseFilters(licenseResponseFilters);
}
return protectionController;
}
return null;
}
function _detectMetricsReporting() {
if (metricsReportingController) {
return;
} // do not require MetricsReporting as dependencies as this is optional and intended to be loaded separately
var MetricsReporting = dashjs.MetricsReporting;
/* jshint ignore:line */
if (typeof MetricsReporting === 'function') {
//TODO need a better way to register/detect plugin components
var metricsReporting = MetricsReporting(context).create();
metricsReportingController = metricsReporting.createMetricsReporting({
debug: debug,
eventBus: eventBus,
mediaElement: getVideoElement(),
adapter: adapter,
dashMetrics: dashMetrics,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"],
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
metricsConstants: _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"]
});
}
}
function _detectMss() {
if (mssHandler) {
return;
} // do not require MssHandler as dependencies as this is optional and intended to be loaded separately
var MssHandler = dashjs.MssHandler;
/* jshint ignore:line */
if (typeof MssHandler === 'function') {
//TODO need a better way to register/detect plugin components
_core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"].extend(MssHandler.errors);
mssHandler = MssHandler(context).create({
eventBus: eventBus,
mediaPlayerModel: mediaPlayerModel,
dashMetrics: dashMetrics,
manifestModel: manifestModel,
playbackController: playbackController,
streamController: streamController,
protectionController: protectionController,
baseURLController: baseURLController,
errHandler: errHandler,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"],
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
debug: debug,
initSegmentType: _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_34__["HTTPRequest"].INIT_SEGMENT_TYPE,
BASE64: _externals_base64__WEBPACK_IMPORTED_MODULE_35___default.a,
ISOBoxer: codem_isoboxer__WEBPACK_IMPORTED_MODULE_36___default.a,
settings: settings
});
}
}
function _detectOffline() {
if (!mediaPlayerInitialized) {
throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
}
if (offlineController) {
return offlineController;
} // do not require Offline as dependencies as this is optional and intended to be loaded separately
var OfflineController = dashjs.OfflineController;
/* jshint ignore:line */
if (typeof OfflineController === 'function') {
//TODO need a better way to register/detect plugin components
_core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"].extend(OfflineController.events);
_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_26__["default"].extend(OfflineController.events, {
publicOnly: true
});
_core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"].extend(OfflineController.errors);
var manifestLoader = _createManifestLoader();
var manifestUpdater = Object(_ManifestUpdater__WEBPACK_IMPORTED_MODULE_39__["default"])(context).create();
manifestUpdater.setConfig({
manifestModel: manifestModel,
adapter: adapter,
manifestLoader: manifestLoader,
errHandler: errHandler
});
offlineController = OfflineController(context).create({
debug: debug,
manifestUpdater: manifestUpdater,
baseURLController: baseURLController,
manifestLoader: manifestLoader,
manifestModel: manifestModel,
mediaPlayerModel: mediaPlayerModel,
abrController: abrController,
playbackController: playbackController,
adapter: adapter,
errHandler: errHandler,
dashMetrics: dashMetrics,
timelineConverter: timelineConverter,
segmentBaseController: segmentBaseController,
schemeLoaderFactory: schemeLoaderFactory,
eventBus: eventBus,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_25__["default"],
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"],
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
settings: settings,
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"],
urlUtils: Object(_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_40__["default"])(context).getInstance()
});
return offlineController;
}
return null;
}
function _getAsUTC(valToConvert) {
var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO;
var metric = dashMetrics.getCurrentDVRInfo(type);
var availableFrom, utcValue;
if (!metric) {
return 0;
}
availableFrom = metric.manifestInfo.availableFrom.getTime() / 1000;
utcValue = valToConvert + (availableFrom + metric.range.start);
return utcValue;
}
function _initializePlayback() {
if (offlineController) {
offlineController.resetRecords();
}
if (!streamingInitialized && source) {
streamingInitialized = true;
logger.info('Streaming Initialized');
_createPlaybackControllers();
if (typeof source === 'string') {
streamController.load(source);
} else {
streamController.loadWithManifest(source);
}
}
if (!playbackInitialized && isReady()) {
playbackInitialized = true;
logger.info('Playback Initialized');
}
}
instance = {
initialize: initialize,
setConfig: setConfig,
on: on,
off: off,
extend: extend,
attachView: attachView,
attachSource: attachSource,
isReady: isReady,
play: play,
isPaused: isPaused,
pause: pause,
isSeeking: isSeeking,
isDynamic: isDynamic,
seek: seek,
setPlaybackRate: setPlaybackRate,
getPlaybackRate: getPlaybackRate,
setMute: setMute,
isMuted: isMuted,
setVolume: setVolume,
getVolume: getVolume,
time: time,
duration: duration,
timeAsUTC: timeAsUTC,
durationAsUTC: durationAsUTC,
getActiveStream: getActiveStream,
getDVRWindowSize: getDVRWindowSize,
getDVRSeekOffset: getDVRSeekOffset,
convertToTimeCode: convertToTimeCode,
formatUTC: formatUTC,
getVersion: getVersion,
getDebug: getDebug,
getBufferLength: getBufferLength,
getTTMLRenderingDiv: getTTMLRenderingDiv,
getVideoElement: getVideoElement,
getSource: getSource,
getCurrentLiveLatency: getCurrentLiveLatency,
getTopBitrateInfoFor: getTopBitrateInfoFor,
setAutoPlay: setAutoPlay,
getAutoPlay: getAutoPlay,
getDashMetrics: getDashMetrics,
getQualityFor: getQualityFor,
setQualityFor: setQualityFor,
updatePortalSize: updatePortalSize,
enableText: enableText,
enableForcedTextStreaming: enableForcedTextStreaming,
isTextEnabled: isTextEnabled,
setTextTrack: setTextTrack,
getBitrateInfoListFor: getBitrateInfoListFor,
getStreamsFromManifest: getStreamsFromManifest,
getTracksFor: getTracksFor,
getTracksForTypeFromManifest: getTracksForTypeFromManifest,
getCurrentTrackFor: getCurrentTrackFor,
setInitialMediaSettingsFor: setInitialMediaSettingsFor,
getInitialMediaSettingsFor: getInitialMediaSettingsFor,
setCurrentTrack: setCurrentTrack,
addABRCustomRule: addABRCustomRule,
removeABRCustomRule: removeABRCustomRule,
removeAllABRCustomRule: removeAllABRCustomRule,
getAverageThroughput: getAverageThroughput,
retrieveManifest: retrieveManifest,
addUTCTimingSource: addUTCTimingSource,
removeUTCTimingSource: removeUTCTimingSource,
clearDefaultUTCTimingSources: clearDefaultUTCTimingSources,
restoreDefaultUTCTimingSources: restoreDefaultUTCTimingSources,
setXHRWithCredentialsForType: setXHRWithCredentialsForType,
getXHRWithCredentialsForType: getXHRWithCredentialsForType,
getProtectionController: getProtectionController,
attachProtectionController: attachProtectionController,
setProtectionData: setProtectionData,
registerLicenseRequestFilter: registerLicenseRequestFilter,
registerLicenseResponseFilter: registerLicenseResponseFilter,
unregisterLicenseRequestFilter: unregisterLicenseRequestFilter,
unregisterLicenseResponseFilter: unregisterLicenseResponseFilter,
registerCustomCapabilitiesFilter: registerCustomCapabilitiesFilter,
unregisterCustomCapabilitiesFilter: unregisterCustomCapabilitiesFilter,
setCustomInitialTrackSelectionFunction: setCustomInitialTrackSelectionFunction,
resetCustomInitialTrackSelectionFunction: resetCustomInitialTrackSelectionFunction,
attachTTMLRenderingDiv: attachTTMLRenderingDiv,
getCurrentTextTrackIndex: getCurrentTextTrackIndex,
provideThumbnail: provideThumbnail,
getDashAdapter: getDashAdapter,
getOfflineController: getOfflineController,
getSettings: getSettings,
updateSettings: updateSettings,
resetSettings: resetSettings,
reset: reset,
destroy: destroy
};
setup();
return instance;
}
MediaPlayer.__dashjs_factory_name = 'MediaPlayer';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_27__["default"].getClassFactory(MediaPlayer);
factory.events = _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_26__["default"];
factory.errors = _core_errors_Errors__WEBPACK_IMPORTED_MODULE_23__["default"];
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_27__["default"].updateClassFactory(MediaPlayer.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/MediaPlayerEvents.js":
/*!********************************************!*\
!*** ./src/streaming/MediaPlayerEvents.js ***!
\********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_events_EventsBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/events/EventsBase */ "./src/core/events/EventsBase.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @implements EventsBase
*/
var MediaPlayerEvents = /*#__PURE__*/function (_EventsBase) {
_inherits(MediaPlayerEvents, _EventsBase);
var _super = _createSuper(MediaPlayerEvents);
/**
* @description Public facing external events to be used when developing a player that implements dash.js.
*/
function MediaPlayerEvents() {
var _this;
_classCallCheck(this, MediaPlayerEvents);
_this = _super.call(this);
/**
* Triggered when playback will not start yet
* as the MPD's availabilityStartTime is in the future.
* Check delay property in payload to determine time before playback will start.
* @event MediaPlayerEvents#AST_IN_FUTURE
*/
_this.AST_IN_FUTURE = 'astInFuture';
/**
* Triggered when the video element's buffer state changes to stalled.
* Check mediaType in payload to determine type (Video, Audio, FragmentedText).
* @event MediaPlayerEvents#BUFFER_EMPTY
*/
_this.BUFFER_EMPTY = 'bufferStalled';
/**
* Triggered when the video element's buffer state changes to loaded.
* Check mediaType in payload to determine type (Video, Audio, FragmentedText).
* @event MediaPlayerEvents#BUFFER_LOADED
*/
_this.BUFFER_LOADED = 'bufferLoaded';
/**
* Triggered when the video element's buffer state changes, either stalled or loaded. Check payload for state.
* @event MediaPlayerEvents#BUFFER_LEVEL_STATE_CHANGED
*/
_this.BUFFER_LEVEL_STATE_CHANGED = 'bufferStateChanged';
/**
* Triggered when the buffer level of a media type has been updated
* @event MediaPlayerEvents#BUFFER_LEVEL_UPDATED
*/
_this.BUFFER_LEVEL_UPDATED = 'bufferLevelUpdated';
/**
* Triggered when a dynamic stream changed to static (transition phase between Live and On-Demand).
* @event MediaPlayerEvents#DYNAMIC_TO_STATIC
*/
_this.DYNAMIC_TO_STATIC = 'dynamicToStatic';
/**
* Triggered when there is an error from the element or MSE source buffer.
* @event MediaPlayerEvents#ERROR
*/
_this.ERROR = 'error';
/**
* Triggered when a fragment download has completed.
* @event MediaPlayerEvents#FRAGMENT_LOADING_COMPLETED
*/
_this.FRAGMENT_LOADING_COMPLETED = 'fragmentLoadingCompleted';
/**
* Triggered when a partial fragment download has completed.
* @event MediaPlayerEvents#FRAGMENT_LOADING_PROGRESS
*/
_this.FRAGMENT_LOADING_PROGRESS = 'fragmentLoadingProgress';
/**
* Triggered when a fragment download has started.
* @event MediaPlayerEvents#FRAGMENT_LOADING_STARTED
*/
_this.FRAGMENT_LOADING_STARTED = 'fragmentLoadingStarted';
/**
* Triggered when a fragment download is abandoned due to detection of slow download base on the ABR abandon rule..
* @event MediaPlayerEvents#FRAGMENT_LOADING_ABANDONED
*/
_this.FRAGMENT_LOADING_ABANDONED = 'fragmentLoadingAbandoned';
/**
* Triggered when {@link module:Debug} logger methods are called.
* @event MediaPlayerEvents#LOG
*/
_this.LOG = 'log';
/**
* Triggered when the manifest load is complete
* @event MediaPlayerEvents#MANIFEST_LOADED
*/
_this.MANIFEST_LOADED = 'manifestLoaded';
/**
* Triggered anytime there is a change to the overall metrics.
* @event MediaPlayerEvents#METRICS_CHANGED
*/
_this.METRICS_CHANGED = 'metricsChanged';
/**
* Triggered when an individual metric is added, updated or cleared.
* @event MediaPlayerEvents#METRIC_CHANGED
*/
_this.METRIC_CHANGED = 'metricChanged';
/**
* Triggered every time a new metric is added.
* @event MediaPlayerEvents#METRIC_ADDED
*/
_this.METRIC_ADDED = 'metricAdded';
/**
* Triggered every time a metric is updated.
* @event MediaPlayerEvents#METRIC_UPDATED
*/
_this.METRIC_UPDATED = 'metricUpdated';
/**
* Triggered when a new stream (period) starts.
* @event MediaPlayerEvents#PERIOD_SWITCH_STARTED
*/
_this.PERIOD_SWITCH_STARTED = 'periodSwitchStarted';
/**
* Triggered at the stream end of a period.
* @event MediaPlayerEvents#PERIOD_SWITCH_COMPLETED
*/
_this.PERIOD_SWITCH_COMPLETED = 'periodSwitchCompleted';
/**
* Triggered when an ABR up /down switch is initiated; either by user in manual mode or auto mode via ABR rules.
* @event MediaPlayerEvents#QUALITY_CHANGE_REQUESTED
*/
_this.QUALITY_CHANGE_REQUESTED = 'qualityChangeRequested';
/**
* Triggered when the new ABR quality is being rendered on-screen.
* @event MediaPlayerEvents#QUALITY_CHANGE_RENDERED
*/
_this.QUALITY_CHANGE_RENDERED = 'qualityChangeRendered';
/**
* Triggered when the new track is being rendered.
* @event MediaPlayerEvents#TRACK_CHANGE_RENDERED
*/
_this.TRACK_CHANGE_RENDERED = 'trackChangeRendered';
/**
* Triggered when a stream (period) is being loaded
* @event MediaPlayerEvents#STREAM_INITIALIZING
*/
_this.STREAM_INITIALIZING = 'streamInitializing';
/**
* Triggered when a stream (period) is loaded
* @event MediaPlayerEvents#STREAM_UPDATED
*/
_this.STREAM_UPDATED = 'streamUpdated';
/**
* Triggered when a stream (period) is activated
* @event MediaPlayerEvents#STREAM_ACTIVATED
*/
_this.STREAM_ACTIVATED = 'streamActivated';
/**
* Triggered when a stream (period) is deactivated
* @event MediaPlayerEvents#STREAM_DEACTIVATED
*/
_this.STREAM_DEACTIVATED = 'streamDeactivated';
/**
* Triggered when a stream (period) is activated
* @event MediaPlayerEvents#STREAM_INITIALIZED
*/
_this.STREAM_INITIALIZED = 'streamInitialized';
/**
* Triggered when the player has been reset.
* @event MediaPlayerEvents#STREAM_TEARDOWN_COMPLETE
*/
_this.STREAM_TEARDOWN_COMPLETE = 'streamTeardownComplete';
/**
* Triggered once all text tracks detected in the MPD are added to the video element.
* @event MediaPlayerEvents#TEXT_TRACKS_ADDED
*/
_this.TEXT_TRACKS_ADDED = 'allTextTracksAdded';
/**
* Triggered when a text track is added to the video element's TextTrackList
* @event MediaPlayerEvents#TEXT_TRACK_ADDED
*/
_this.TEXT_TRACK_ADDED = 'textTrackAdded';
/**
* Triggered when a ttml chunk is parsed.
* @event MediaPlayerEvents#TTML_PARSED
*/
_this.TTML_PARSED = 'ttmlParsed';
/**
* Triggered when a ttml chunk has to be parsed.
* @event MediaPlayerEvents#TTML_TO_PARSE
*/
_this.TTML_TO_PARSE = 'ttmlToParse';
/**
* Triggered when a caption is rendered.
* @event MediaPlayerEvents#CAPTION_RENDERED
*/
_this.CAPTION_RENDERED = 'captionRendered';
/**
* Triggered when the caption container is resized.
* @event MediaPlayerEvents#CAPTION_CONTAINER_RESIZE
*/
_this.CAPTION_CONTAINER_RESIZE = 'captionContainerResize';
/**
* Sent when enough data is available that the media can be played,
* at least for a couple of frames. This corresponds to the
* HAVE_ENOUGH_DATA readyState.
* @event MediaPlayerEvents#CAN_PLAY
*/
_this.CAN_PLAY = 'canPlay';
/**
* This corresponds to the CAN_PLAY_THROUGH readyState.
* @event MediaPlayerEvents#CAN_PLAY_THROUGH
*/
_this.CAN_PLAY_THROUGH = 'canPlayThrough';
/**
* Sent when playback completes.
* @event MediaPlayerEvents#PLAYBACK_ENDED
*/
_this.PLAYBACK_ENDED = 'playbackEnded';
/**
* Sent when an error occurs. The element's error
* attribute contains more information.
* @event MediaPlayerEvents#PLAYBACK_ERROR
*/
_this.PLAYBACK_ERROR = 'playbackError';
/**
* Sent when playback is not allowed (for example if user gesture is needed).
* @event MediaPlayerEvents#PLAYBACK_NOT_ALLOWED
*/
_this.PLAYBACK_NOT_ALLOWED = 'playbackNotAllowed';
/**
* The media's metadata has finished loading; all attributes now
* contain as much useful information as they're going to.
* @event MediaPlayerEvents#PLAYBACK_METADATA_LOADED
*/
_this.PLAYBACK_METADATA_LOADED = 'playbackMetaDataLoaded';
/**
* The media's metadata has finished loading; all attributes now
* contain as much useful information as they're going to.
* @event MediaPlayerEvents#PLAYBACK_METADATA_LOADED
*/
_this.PLAYBACK_LOADED_DATA = 'playbackLoadedData';
/**
* Sent when playback is paused.
* @event MediaPlayerEvents#PLAYBACK_PAUSED
*/
_this.PLAYBACK_PAUSED = 'playbackPaused';
/**
* Sent when the media begins to play (either for the first time, after having been paused,
* or after ending and then restarting).
*
* @event MediaPlayerEvents#PLAYBACK_PLAYING
*/
_this.PLAYBACK_PLAYING = 'playbackPlaying';
/**
* Sent periodically to inform interested parties of progress downloading
* the media. Information about the current amount of the media that has
* been downloaded is available in the media element's buffered attribute.
* @event MediaPlayerEvents#PLAYBACK_PROGRESS
*/
_this.PLAYBACK_PROGRESS = 'playbackProgress';
/**
* Sent when the playback speed changes.
* @event MediaPlayerEvents#PLAYBACK_RATE_CHANGED
*/
_this.PLAYBACK_RATE_CHANGED = 'playbackRateChanged';
/**
* Sent when a seek operation completes.
* @event MediaPlayerEvents#PLAYBACK_SEEKED
*/
_this.PLAYBACK_SEEKED = 'playbackSeeked';
/**
* Sent when a seek operation begins.
* @event MediaPlayerEvents#PLAYBACK_SEEKING
*/
_this.PLAYBACK_SEEKING = 'playbackSeeking';
/**
* Sent when a seek operation has been asked.
* @event MediaPlayerEvents#PLAYBACK_SEEK_ASKED
*/
_this.PLAYBACK_SEEK_ASKED = 'playbackSeekAsked';
/**
* Sent when the video element reports stalled
* @event MediaPlayerEvents#PLAYBACK_STALLED
*/
_this.PLAYBACK_STALLED = 'playbackStalled';
/**
* Sent when playback of the media starts after having been paused;
* that is, when playback is resumed after a prior pause event.
*
* @event MediaPlayerEvents#PLAYBACK_STARTED
*/
_this.PLAYBACK_STARTED = 'playbackStarted';
/**
* The time indicated by the element's currentTime attribute has changed.
* @event MediaPlayerEvents#PLAYBACK_TIME_UPDATED
*/
_this.PLAYBACK_TIME_UPDATED = 'playbackTimeUpdated';
/**
* Sent when the media playback has stopped because of a temporary lack of data.
*
* @event MediaPlayerEvents#PLAYBACK_WAITING
*/
_this.PLAYBACK_WAITING = 'playbackWaiting';
/**
* Manifest validity changed - As a result of an MPD validity expiration event.
* @event MediaPlayerEvents#MANIFEST_VALIDITY_CHANGED
*/
_this.MANIFEST_VALIDITY_CHANGED = 'manifestValidityChanged';
/**
* Dash events are triggered at their respective start points on the timeline.
* @event MediaPlayerEvents#EVENT_MODE_ON_START
*/
_this.EVENT_MODE_ON_START = 'eventModeOnStart';
/**
* Dash events are triggered as soon as they were parsed.
* @event MediaPlayerEvents#EVENT_MODE_ON_RECEIVE
*/
_this.EVENT_MODE_ON_RECEIVE = 'eventModeOnReceive';
/**
* Event that is dispatched whenever the player encounters a potential conformance validation that might lead to unexpected/not optimal behavior
* @event MediaPlayerEvents#CONFORMANCE_VIOLATION
*/
_this.CONFORMANCE_VIOLATION = 'conformanceViolation';
/**
* Event that is dispatched whenever the player switches to a different representation
* @event MediaPlayerEvents#REPRESENTATION_SWITCH
*/
_this.REPRESENTATION_SWITCH = 'representationSwitch';
return _this;
}
return MediaPlayerEvents;
}(_core_events_EventsBase__WEBPACK_IMPORTED_MODULE_0__["default"]);
var mediaPlayerEvents = new MediaPlayerEvents();
/* harmony default export */ __webpack_exports__["default"] = (mediaPlayerEvents);
/***/ }),
/***/ "./src/streaming/MediaPlayerFactory.js":
/*!*********************************************!*\
!*** ./src/streaming/MediaPlayerFactory.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _MediaPlayer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./MediaPlayer */ "./src/streaming/MediaPlayer.js");
function MediaPlayerFactory() {
/**
* mime-type identifier for any source content to be accepted as a dash manifest by the create() method.
* @type {string}
*/
var SUPPORTED_MIME_TYPE = 'application/dash+xml';
var logger;
/**
* A new MediaPlayer is instantiated for the supplied videoElement and optional source and context. If no context is provided,
* a default DashContext is used. If no source is provided, the videoElement is interrogated to extract the first source whose
* type is application/dash+xml.
* The autoplay property of the videoElement is preserved. Any preload attribute is ignored. This method should be called after the page onLoad event is dispatched.
* @param {HTMLMediaElement} video
* @param {HTMLSourceElement} source
* @param {Object} context
* @returns {MediaPlayer|null}
*/
function create(video, source, context) {
if (!video || !/^VIDEO$/i.test(video.nodeName)) return null;
if (video._dashjs_player) return video._dashjs_player;
var player;
var videoID = video.id || video.name || 'video element';
source = source || [].slice.call(video.querySelectorAll('source')).filter(function (s) {
return s.type == SUPPORTED_MIME_TYPE;
})[0];
if (!source && video.src) {
source = document.createElement('source');
source.src = video.src;
} else if (!source && !video.src) {
return null;
}
context = context || {};
player = Object(_MediaPlayer__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create();
player.initialize(video, source.src, video.autoplay);
if (!logger) {
logger = player.getDebug().getLogger();
}
logger.debug('Converted ' + videoID + ' to dash.js player and added content: ' + source.src); // Store a reference to the player on the video element so it can be gotten at for debugging and so we know its
// already been setup.
video._dashjs_player = player;
return player;
}
/**
* Searches the provided scope for all instances of the indicated selector. If no scope is provided, document is used. If no selector is
* specified, [data-dashjs-player] is used. The declarative setup also looks for source elements with the type attribute set to 'application/dash+xml'.
* It then looks for those video elements which have a source element defined with a type matching 'application/dash+xml'.
* A new MediaPlayer is instantiated for each matching video element and the appropriate source is assigned.
* The autoplay property of the video element is preserved. Any preload attribute is ignored. This method should be called after the page onLoad event is dispatched.
* Returns an array holding all the MediaPlayer instances that were added by this method.
* @param {string} selector - CSS selector
* @param {Object} scope
* @returns {Array} an array of MediaPlayer objects
*/
function createAll(selector, scope) {
var aPlayers = [];
selector = selector || '[data-dashjs-player]';
scope = scope || document;
var videos = scope.querySelectorAll(selector);
for (var i = 0; i < videos.length; i++) {
var player = create(videos[i], null);
aPlayers.push(player);
}
var sources = scope.querySelectorAll('source[type="' + SUPPORTED_MIME_TYPE + '"]');
for (var _i = 0; _i < sources.length; _i++) {
var video = findVideo(sources[_i]);
var _player = create(video, null);
aPlayers.push(_player);
}
return aPlayers;
}
function findVideo(el) {
if (/^VIDEO$/i.test(el.nodeName)) {
return el;
} else {
return findVideo(el.parentNode);
}
}
return {
create: create,
createAll: createAll
};
}
var instance = MediaPlayerFactory();
var loadInterval;
function loadHandler() {
window.removeEventListener('load', loadHandler);
instance.createAll();
}
function loadIntervalHandler() {
if (window.dashjs) {
window.clearInterval(loadInterval);
instance.createAll();
}
}
var avoidAutoCreate = typeof window !== 'undefined' && window && window.dashjs && window.dashjs.skipAutoCreate;
if (!avoidAutoCreate && typeof window !== 'undefined' && window && window.addEventListener) {
if (window.document.readyState === 'complete') {
if (window.dashjs) {
instance.createAll();
} else {
// If loaded asynchronously, window.readyState may be 'complete' even if dashjs hasn't loaded yet
loadInterval = window.setInterval(loadIntervalHandler, 500);
}
} else {
window.addEventListener('load', loadHandler);
}
}
/* harmony default export */ __webpack_exports__["default"] = (instance);
/***/ }),
/***/ "./src/streaming/SourceBufferSink.js":
/*!*******************************************!*\
!*** ./src/streaming/SourceBufferSink.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../core/events/Events */ "./src/core/events/Events.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var APPEND_WINDOW_START_OFFSET = 0.1;
var APPEND_WINDOW_END_OFFSET = 0.01;
/**
* @class SourceBufferSink
* @ignore
* @implements FragmentSink
*/
var CHECK_INTERVAL = 50;
function SourceBufferSink(config) {
var context = this.context;
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var textController = config.textController;
var eventBus = config.eventBus;
var instance, type, logger, buffer, mediaInfo, intervalId;
var callbacks = [];
var appendQueue = [];
var isAppendingInProgress = false;
var mediaSource = config.mediaSource;
var lastRequestAppended = null;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
}
function initializeForStreamSwitch(mInfo, selectedRepresentation, oldSourceBufferSink) {
mediaInfo = mInfo;
type = mediaInfo.type;
var codec = mediaInfo.codec;
_copyPreviousSinkData(oldSourceBufferSink);
_addEventListeners();
var promises = [];
promises.push(_abortBeforeAppend);
promises.push(updateAppendWindow(mediaInfo.streamInfo));
promises.push(changeType(codec));
if (selectedRepresentation && selectedRepresentation.MSETimeOffset !== undefined) {
promises.push(updateTimestampOffset(selectedRepresentation.MSETimeOffset));
}
return Promise.all(promises);
}
function changeType(codec) {
return new Promise(function (resolve) {
_waitForUpdateEnd(function () {
if (buffer.changeType) {
buffer.changeType(codec);
}
resolve();
});
});
}
function _copyPreviousSinkData(oldSourceBufferSink) {
buffer = oldSourceBufferSink.getBuffer();
}
function initializeForFirstUse(streamInfo, mInfo, selectedRepresentation) {
mediaInfo = mInfo;
type = mediaInfo.type;
var codec = mediaInfo.codec;
try {
// Safari claims to support anything starting 'application/mp4'.
// it definitely doesn't understand 'application/mp4;codecs="stpp"'
// - currently no browser does, so check for it and use our own
// implementation. The same is true for codecs="wvtt".
if (codec.match(/application\/mp4;\s*codecs="(stpp|wvtt).*"/i)) {
return _initializeForText(streamInfo);
}
buffer = mediaSource.addSourceBuffer(codec);
_addEventListeners();
var promises = [];
promises.push(updateAppendWindow(mediaInfo.streamInfo));
if (selectedRepresentation && selectedRepresentation.MSETimeOffset !== undefined) {
promises.push(updateTimestampOffset(selectedRepresentation.MSETimeOffset));
}
return Promise.all(promises);
} catch (e) {
// Note that in the following, the quotes are open to allow for extra text after stpp and wvtt
if (mediaInfo.type == _constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].TEXT && !mediaInfo.isFragmented || codec.indexOf('codecs="stpp') !== -1 || codec.indexOf('codecs="vtt') !== -1) {
return _initializeForText(streamInfo);
}
return Promise.reject(e);
}
}
function _initializeForText(streamInfo) {
buffer = textController.getTextSourceBuffer(streamInfo);
return Promise.resolve();
}
function _addEventListeners() {
// use updateend event if possible
if (typeof buffer.addEventListener === 'function') {
try {
buffer.addEventListener('updateend', _updateEndHandler, false);
buffer.addEventListener('error', _errHandler, false);
buffer.addEventListener('abort', _errHandler, false);
} catch (err) {
// use setInterval to periodically check if updating has been completed
intervalId = setInterval(_updateEndHandler, CHECK_INTERVAL);
}
} else {
// use setInterval to periodically check if updating has been completed
intervalId = setInterval(_updateEndHandler, CHECK_INTERVAL);
}
}
function getType() {
return type;
}
function _removeEventListeners() {
try {
if (typeof buffer.removeEventListener === 'function') {
buffer.removeEventListener('updateend', _updateEndHandler, false);
buffer.removeEventListener('error', _errHandler, false);
buffer.removeEventListener('abort', _errHandler, false);
}
clearInterval(intervalId);
} catch (e) {
logger.error(e);
}
}
function updateAppendWindow(sInfo) {
return new Promise(function (resolve) {
if (!buffer || !settings.get().streaming.buffer.useAppendWindow) {
resolve();
return;
}
_waitForUpdateEnd(function () {
try {
if (!buffer) {
resolve();
return;
}
var appendWindowEnd = mediaSource.duration;
var appendWindowStart = 0;
if (sInfo && !isNaN(sInfo.start) && !isNaN(sInfo.duration) && isFinite(sInfo.duration)) {
appendWindowEnd = sInfo.start + sInfo.duration;
}
if (sInfo && !isNaN(sInfo.start)) {
appendWindowStart = sInfo.start;
}
if (buffer.appendWindowEnd !== appendWindowEnd || buffer.appendWindowStart !== appendWindowStart) {
buffer.appendWindowStart = 0;
buffer.appendWindowEnd = appendWindowEnd + APPEND_WINDOW_END_OFFSET;
buffer.appendWindowStart = Math.max(appendWindowStart - APPEND_WINDOW_START_OFFSET, 0);
logger.debug("Updated append window for ".concat(mediaInfo.type, ". Set start to ").concat(buffer.appendWindowStart, " and end to ").concat(buffer.appendWindowEnd));
}
resolve();
} catch (e) {
logger.warn("Failed to set append window");
resolve();
}
});
});
}
function updateTimestampOffset(MSETimeOffset) {
return new Promise(function (resolve) {
if (!buffer) {
resolve();
return;
}
_waitForUpdateEnd(function () {
try {
if (buffer.timestampOffset !== MSETimeOffset && !isNaN(MSETimeOffset)) {
buffer.timestampOffset = MSETimeOffset;
logger.debug("Set MSE timestamp offset to ".concat(MSETimeOffset));
}
resolve();
} catch (e) {
resolve();
}
});
});
}
function reset() {
if (buffer) {
try {
callbacks = [];
_removeEventListeners();
isAppendingInProgress = false;
appendQueue = [];
if (!buffer.getClassName || buffer.getClassName() !== 'TextSourceBuffer') {
logger.debug("Removing sourcebuffer from media source");
mediaSource.removeSourceBuffer(buffer);
}
} catch (e) {}
buffer = null;
}
lastRequestAppended = null;
}
function getBuffer() {
return buffer;
}
function getAllBufferRanges() {
try {
return buffer.buffered;
} catch (e) {
logger.error('getAllBufferRanges exception: ' + e.message);
return null;
}
}
function append(chunk) {
var _this = this;
var request = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
return new Promise(function (resolve, reject) {
if (!chunk) {
reject({
chunk: chunk,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_1__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__["default"].APPEND_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__["default"].APPEND_ERROR_MESSAGE)
});
return;
}
appendQueue.push({
data: chunk,
promise: {
resolve: resolve,
reject: reject
},
request: request
});
_waitForUpdateEnd(_appendNextInQueue.bind(_this));
});
}
function _abortBeforeAppend() {
return new Promise(function (resolve) {
_waitForUpdateEnd(function () {
// Save the append window, which is reset on abort().
var appendWindowStart = buffer.appendWindowStart;
var appendWindowEnd = buffer.appendWindowEnd;
if (buffer) {
buffer.abort();
buffer.appendWindowStart = appendWindowStart;
buffer.appendWindowEnd = appendWindowEnd;
}
resolve();
});
});
}
function remove(range) {
return new Promise(function (resolve, reject) {
var start = range.start;
var end = range.end; // make sure that the given time range is correct. Otherwise we will get InvalidAccessError
if (!(start >= 0 && end > start)) {
resolve();
return;
}
_waitForUpdateEnd(function () {
try {
buffer.remove(start, end); // updating is in progress, we should wait for it to complete before signaling that this operation is done
_waitForUpdateEnd(function () {
resolve({
from: start,
to: end,
unintended: false
});
if (range.resolve) {
range.resolve();
}
});
} catch (err) {
reject({
from: start,
to: end,
unintended: false,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_1__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__["default"].REMOVE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__["default"].REMOVE_ERROR_MESSAGE)
});
if (range.reject) {
range.reject(err);
}
}
});
});
}
function _appendNextInQueue() {
if (isAppendingInProgress) {
return;
}
if (appendQueue.length > 0) {
isAppendingInProgress = true;
var nextChunk = appendQueue[0];
appendQueue.splice(0, 1);
var afterSuccess = function afterSuccess() {
isAppendingInProgress = false;
if (appendQueue.length > 0) {
_appendNextInQueue.call(this);
} // Init segments are cached. In any other case we dont need the chunk bytes anymore and can free the memory
if (nextChunk && nextChunk.data && nextChunk.data.segmentType && nextChunk.data.segmentType !== _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].INIT_SEGMENT_TYPE) {
delete nextChunk.data.bytes;
}
nextChunk.promise.resolve({
chunk: nextChunk.data
});
};
try {
lastRequestAppended = nextChunk.request;
if (nextChunk.data.bytes.byteLength === 0) {
afterSuccess.call(this);
} else {
if (buffer.appendBuffer) {
buffer.appendBuffer(nextChunk.data.bytes);
} else {
buffer.append(nextChunk.data.bytes, nextChunk.data);
} // updating is in progress, we should wait for it to complete before signaling that this operation is done
_waitForUpdateEnd(afterSuccess.bind(this));
}
} catch (err) {
logger.fatal('SourceBuffer append failed "' + err + '"');
if (appendQueue.length > 0) {
_appendNextInQueue();
} else {
isAppendingInProgress = false;
}
delete nextChunk.data.bytes;
nextChunk.promise.reject({
chunk: nextChunk.data,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_1__["default"](err.code, err.message)
});
}
}
}
function abort() {
return new Promise(function (resolve) {
try {
appendQueue = [];
if (mediaSource.readyState === 'open') {
_waitForUpdateEnd(function () {
try {
if (buffer) {
buffer.abort();
}
resolve();
} catch (e) {
resolve();
}
});
} else if (buffer && buffer.setTextTrack && mediaSource.readyState === 'ended') {
buffer.abort(); //The cues need to be removed from the TextSourceBuffer via a call to abort()
resolve();
} else {
resolve();
}
} catch (e) {
resolve();
}
});
}
function _executeCallback() {
if (callbacks.length > 0) {
if (!buffer.updating) {
var cb = callbacks.shift();
cb(); // Try to execute next callback if still not updating
_executeCallback();
}
}
}
function _updateEndHandler() {
// if updating is still in progress do nothing and wait for the next check again.
if (buffer.updating) {
return;
} // updating is completed, now we can stop checking and resolve the promise
_executeCallback();
}
function _errHandler(e) {
var error = e.target || {};
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].SOURCE_BUFFER_ERROR, {
error: error,
lastRequestAppended: lastRequestAppended
});
}
function _triggerEvent(eventType, data) {
var payload = data || {};
eventBus.trigger(eventType, payload, {
streamId: mediaInfo.streamInfo.id,
mediaType: type
});
}
function _waitForUpdateEnd(callback) {
callbacks.push(callback);
if (!buffer.updating) {
_executeCallback();
}
}
instance = {
getType: getType,
getAllBufferRanges: getAllBufferRanges,
getBuffer: getBuffer,
append: append,
remove: remove,
abort: abort,
reset: reset,
updateTimestampOffset: updateTimestampOffset,
initializeForStreamSwitch: initializeForStreamSwitch,
initializeForFirstUse: initializeForFirstUse,
updateAppendWindow: updateAppendWindow,
changeType: changeType
};
setup();
return instance;
}
SourceBufferSink.__dashjs_factory_name = 'SourceBufferSink';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(SourceBufferSink);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/Stream.js":
/*!*********************************!*\
!*** ./src/streaming/Stream.js ***!
\*********************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _StreamProcessor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./StreamProcessor */ "./src/streaming/StreamProcessor.js");
/* harmony import */ var _controllers_FragmentController__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./controllers/FragmentController */ "./src/streaming/controllers/FragmentController.js");
/* harmony import */ var _thumbnail_ThumbnailController__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./thumbnail/ThumbnailController */ "./src/streaming/thumbnail/ThumbnailController.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _utils_BoxParser__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./utils/BoxParser */ "./src/streaming/utils/BoxParser.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./controllers/BlacklistController */ "./src/streaming/controllers/BlacklistController.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var MEDIA_TYPES = [_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MUXED, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE];
function Stream(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
var urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_12__["default"])(context).getInstance();
var manifestModel = config.manifestModel;
var mediaPlayerModel = config.mediaPlayerModel;
var dashMetrics = config.dashMetrics;
var manifestUpdater = config.manifestUpdater;
var adapter = config.adapter;
var timelineConverter = config.timelineConverter;
var capabilities = config.capabilities;
var errHandler = config.errHandler;
var abrController = config.abrController;
var playbackController = config.playbackController;
var eventController = config.eventController;
var mediaController = config.mediaController;
var protectionController = config.protectionController;
var textController = config.textController;
var videoModel = config.videoModel;
var streamInfo = config.streamInfo;
var settings = config.settings;
var instance, logger, streamProcessors, isInitialized, isActive, hasFinishedBuffering, hasVideoTrack, hasAudioTrack, updateError, isUpdating, fragmentController, thumbnailController, segmentBlacklistController, preloaded, boxParser, debug, isEndedEventSignaled, trackChangedEvents;
/**
* Setup the stream
*/
function setup() {
try {
debug = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
logger = debug.getLogger(instance);
resetInitialSettings();
boxParser = Object(_utils_BoxParser__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
segmentBlacklistController = Object(_controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_13__["default"])(context).create({
updateEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SEGMENT_LOCATION_BLACKLIST_CHANGED,
addBlacklistEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SEGMENT_LOCATION_BLACKLIST_ADD
});
fragmentController = Object(_controllers_FragmentController__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
streamInfo: streamInfo,
mediaPlayerModel: mediaPlayerModel,
dashMetrics: dashMetrics,
errHandler: errHandler,
settings: settings,
boxParser: boxParser,
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
urlUtils: urlUtils
});
} catch (e) {
throw e;
}
}
/**
* Initialize the events
*/
function initialize() {
registerEvents();
registerProtectionEvents();
textController.initializeForStream(streamInfo);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_UPDATED, {
streamInfo: streamInfo
});
}
/**
* Register the streaming events
*/
function registerEvents() {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFERING_COMPLETED, onBufferingCompleted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].DATA_UPDATE_COMPLETED, onDataUpdateCompleted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].INBAND_EVENTS, onInbandEvents, instance);
}
/**
* Unregister the streaming events
*/
function unRegisterEvents() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].DATA_UPDATE_COMPLETED, onDataUpdateCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFERING_COMPLETED, onBufferingCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].INBAND_EVENTS, onInbandEvents, instance);
}
/**
* Register the protection events
*/
function registerProtectionEvents() {
if (protectionController) {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_ERROR, onProtectionError, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SERVER_CERTIFICATE_UPDATED, onProtectionError, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].LICENSE_REQUEST_COMPLETE, onProtectionError, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_SYSTEM_SELECTED, onProtectionError, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_SESSION_CREATED, onProtectionError, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_STATUSES_CHANGED, onProtectionError, instance);
}
}
/**
* Unregister the protection events
*/
function unRegisterProtectionEvents() {
if (protectionController) {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_ERROR, onProtectionError, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SERVER_CERTIFICATE_UPDATED, onProtectionError, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].LICENSE_REQUEST_COMPLETE, onProtectionError, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_SYSTEM_SELECTED, onProtectionError, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_SESSION_CREATED, onProtectionError, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].KEY_STATUSES_CHANGED, onProtectionError, instance);
}
}
/**
* Returns the stream id
* @return {*|null}
*/
function getStreamId() {
return streamInfo ? streamInfo.id : null;
}
/**
* Activates Stream by re-initializing some of its components
* @param {MediaSource} mediaSource
* @param {array} previousBufferSinks
* @memberof Stream#
*/
function activate(mediaSource, previousBufferSinks) {
return new Promise(function (resolve, reject) {
if (isActive) {
resolve(previousBufferSinks);
return;
}
if (getPreloaded()) {
isActive = true;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_ACTIVATED, {
streamInfo: streamInfo
});
resolve(previousBufferSinks);
return;
}
_initializeMedia(mediaSource, previousBufferSinks).then(function (bufferSinks) {
isActive = true;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_ACTIVATED, {
streamInfo: streamInfo
});
resolve(bufferSinks);
})["catch"](function (e) {
reject(e);
});
});
}
/**
*
* @param {object} mediaSource
* @param {array} previousBufferSinks
* @return {Promise<Array>}
* @private
*/
function _initializeMedia(mediaSource, previousBufferSinks) {
return _commonMediaInitialization(mediaSource, previousBufferSinks);
}
function startPreloading(mediaSource, previousBuffers) {
return new Promise(function (resolve, reject) {
if (getPreloaded()) {
reject();
return;
}
logger.info("[startPreloading] Preloading next stream with id ".concat(getId()));
setPreloaded(true);
_commonMediaInitialization(mediaSource, previousBuffers).then(function () {
for (var i = 0; i < streamProcessors.length && streamProcessors[i]; i++) {
streamProcessors[i].setExplicitBufferingTime(getStartTime());
streamProcessors[i].getScheduleController().startScheduleTimer();
}
resolve();
})["catch"](function () {
setPreloaded(false);
reject();
});
});
}
/**
*
* @param {object} mediaSource
* @param {array} previousBufferSinks
* @return {Promise<array>}
* @private
*/
function _commonMediaInitialization(mediaSource, previousBufferSinks) {
return new Promise(function (resolve, reject) {
checkConfig();
isUpdating = true;
addInlineEvents();
var element = videoModel.getElement();
MEDIA_TYPES.forEach(function (mediaType) {
if (mediaType !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || !element || element && /^VIDEO$/i.test(element.nodeName)) {
_initializeMediaForType(mediaType, mediaSource);
}
});
_createBufferSinks(previousBufferSinks).then(function (bufferSinks) {
isUpdating = false;
if (streamProcessors.length === 0) {
var msg = 'No streams to play.';
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].MANIFEST_ERROR_ID_NOSTREAMS_CODE, msg, manifestModel.getValue()));
logger.fatal(msg);
} else {
_checkIfInitializationCompleted();
} // All mediaInfos for texttracks are added to the TextSourceBuffer by now. We can start creating the tracks
textController.createTracks(streamInfo);
resolve(bufferSinks);
})["catch"](function (e) {
reject(e);
});
});
}
/**
* Initialize for a given media type. Creates a corresponding StreamProcessor
* @param {string} type
* @param {object} mediaSource
* @private
*/
function _initializeMediaForType(type, mediaSource) {
var allMediaForType = adapter.getAllMediaInfoForType(streamInfo, type);
var embeddedMediaInfos = [];
var mediaInfo = null;
var initialMediaInfo;
if (!allMediaForType || allMediaForType.length === 0) {
logger.info('No ' + type + ' data.');
return;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) {
hasVideoTrack = true;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO) {
hasAudioTrack = true;
}
for (var i = 0, ln = allMediaForType.length; i < ln; i++) {
mediaInfo = allMediaForType[i];
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !!mediaInfo.isEmbedded) {
textController.addEmbeddedTrack(streamInfo, mediaInfo);
embeddedMediaInfos.push(mediaInfo);
}
if (_isMediaSupported(mediaInfo)) {
mediaController.addTrack(mediaInfo);
}
}
if (embeddedMediaInfos.length > 0) {
mediaController.setInitialMediaSettingsForType(type, streamInfo);
textController.setInitialSettings(mediaController.getInitialSettings(type));
textController.addMediaInfosToBuffer(streamInfo, type, embeddedMediaInfos);
} // Filter out embedded text track before creating StreamProcessor
allMediaForType = allMediaForType.filter(function (mediaInfo) {
return !mediaInfo.isEmbedded;
});
if (allMediaForType.length === 0) {
return;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE) {
thumbnailController = Object(_thumbnail_ThumbnailController__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
streamInfo: streamInfo,
adapter: adapter,
baseURLController: config.baseURLController,
timelineConverter: config.timelineConverter,
debug: debug,
eventBus: eventBus,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"],
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
dashMetrics: config.dashMetrics,
segmentBaseController: config.segmentBaseController
});
thumbnailController.initialize();
return;
}
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_INITIALIZING, {
streamInfo: streamInfo,
mediaInfo: mediaInfo
});
mediaController.setInitialMediaSettingsForType(type, streamInfo);
var streamProcessor = _createStreamProcessor(allMediaForType, mediaSource);
initialMediaInfo = mediaController.getCurrentTrackFor(type, streamInfo.id);
if (initialMediaInfo) {
abrController.updateTopQualityIndex(initialMediaInfo); // In case of mixed fragmented and embedded text tracks, check if initial selected text track is not an embedded track
streamProcessor.selectMediaInfo(type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || !initialMediaInfo.isEmbedded ? initialMediaInfo : allMediaForType[0]);
}
}
function _isMediaSupported(mediaInfo) {
var type = mediaInfo ? mediaInfo.type : null;
var msg;
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MUXED) {
msg = 'Multiplexed representations are intentionally not supported, as they are not compliant with the DASH-AVC/264 guidelines';
logger.fatal(msg);
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].MANIFEST_ERROR_ID_MULTIPLEXED_CODE, msg, manifestModel.getValue()));
return false;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE) {
return true;
}
if (!!mediaInfo.contentProtection && !capabilities.supportsEncryptedMedia()) {
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].CAPABILITY_MEDIAKEYS_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].CAPABILITY_MEDIAKEYS_ERROR_MESSAGE));
return false;
}
return true;
}
/**
* Creates the StreamProcessor for a given media type.
* @param {object} initialMediaInfo
* @param {array} allMediaForType
* @param {object} mediaSource
* @private
*/
function _createStreamProcessor(allMediaForType, mediaSource) {
var mediaInfo = allMediaForType && allMediaForType.length > 0 ? allMediaForType[0] : null;
var fragmentModel = fragmentController.getModel(mediaInfo ? mediaInfo.type : null);
var type = mediaInfo ? mediaInfo.type : null;
var mimeType = mediaInfo ? mediaInfo.mimeType : null;
var isFragmented = mediaInfo ? mediaInfo.isFragmented : null;
var streamProcessor = Object(_StreamProcessor__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
streamInfo: streamInfo,
type: type,
mimeType: mimeType,
timelineConverter: timelineConverter,
adapter: adapter,
manifestModel: manifestModel,
mediaPlayerModel: mediaPlayerModel,
fragmentModel: fragmentModel,
dashMetrics: config.dashMetrics,
baseURLController: config.baseURLController,
segmentBaseController: config.segmentBaseController,
abrController: abrController,
playbackController: playbackController,
mediaController: mediaController,
textController: textController,
errHandler: errHandler,
settings: settings,
boxParser: boxParser,
segmentBlacklistController: segmentBlacklistController
});
streamProcessor.initialize(mediaSource, hasVideoTrack, isFragmented);
streamProcessors.push(streamProcessor);
for (var i = 0; i < allMediaForType.length; i++) {
streamProcessor.addMediaInfo(allMediaForType[i]);
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) {
textController.addMediaInfosToBuffer(streamInfo, type, allMediaForType, fragmentModel);
}
return streamProcessor;
}
/**
* Creates the SourceBufferSink objects for all StreamProcessors
* @param {array} previousBuffersSinks
* @return {Promise<object>}
* @private
*/
function _createBufferSinks(previousBuffersSinks) {
return new Promise(function (resolve) {
var buffers = {};
var promises = streamProcessors.map(function (sp) {
return sp.createBufferSinks(previousBuffersSinks);
});
Promise.all(promises).then(function (bufferSinks) {
bufferSinks.forEach(function (sink) {
if (sink) {
buffers[sink.getType()] = sink;
}
});
resolve(buffers);
})["catch"](function () {
resolve(buffers);
});
});
}
/**
* Partially resets some of the Stream elements. This function is called when preloading of streams is canceled or a stream switch occurs.
* @memberof Stream#
* @param {boolean} keepBuffers
*/
function deactivate(keepBuffers) {
var ln = streamProcessors ? streamProcessors.length : 0;
var errored = false;
for (var i = 0; i < ln; i++) {
var fragmentModel = streamProcessors[i].getFragmentModel();
fragmentModel.abortRequests();
fragmentModel.resetInitialSettings();
streamProcessors[i].reset(errored, keepBuffers);
}
if (textController) {
textController.deactivateStream(streamInfo);
}
streamProcessors = [];
isActive = false;
hasFinishedBuffering = false;
setPreloaded(false);
setIsEndedEventSignaled(false);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_DEACTIVATED, {
streamInfo: streamInfo
});
}
function getIsActive() {
return isActive;
}
function setMediaSource(mediaSource) {
for (var i = 0; i < streamProcessors.length;) {
if (_isMediaSupported(streamProcessors[i].getMediaInfo())) {
streamProcessors[i].setMediaSource(mediaSource);
i++;
} else {
streamProcessors[i].reset();
streamProcessors.splice(i, 1);
}
}
if (streamProcessors.length === 0) {
var msg = 'No streams to play.';
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].MANIFEST_ERROR_ID_NOSTREAMS_CODE, msg + 'nostreams', manifestModel.getValue()));
logger.fatal(msg);
}
}
function resetInitialSettings(keepBuffers) {
deactivate(keepBuffers);
isInitialized = false;
hasVideoTrack = false;
hasAudioTrack = false;
updateError = {};
isUpdating = false;
isEndedEventSignaled = false;
trackChangedEvents = [];
}
function reset(keepBuffers) {
if (fragmentController) {
fragmentController.reset();
fragmentController = null;
}
if (abrController && streamInfo) {
abrController.clearDataForStream(streamInfo.id);
}
if (segmentBlacklistController) {
segmentBlacklistController.reset();
segmentBlacklistController = null;
}
resetInitialSettings(keepBuffers);
streamInfo = null;
unRegisterEvents();
unRegisterProtectionEvents();
}
function getDuration() {
return streamInfo ? streamInfo.duration : NaN;
}
function getIsEndedEventSignaled() {
return isEndedEventSignaled;
}
function setIsEndedEventSignaled(value) {
isEndedEventSignaled = value;
}
function getStartTime() {
return streamInfo ? streamInfo.start : NaN;
}
function getId() {
return streamInfo ? streamInfo.id : null;
}
function getStreamInfo() {
return streamInfo;
}
function getHasAudioTrack() {
return hasAudioTrack;
}
function getHasVideoTrack() {
return hasVideoTrack;
}
function getThumbnailController() {
return thumbnailController;
}
function checkConfig() {
if (!videoModel || !abrController) {
throw new Error(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MISSING_CONFIG_ERROR);
}
}
/**
* @param {string} type
* @returns {Array}
* @memberof Stream#
*/
function getBitrateListFor(type) {
checkConfig();
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE) {
if (!thumbnailController) {
return [];
}
return thumbnailController.getBitrateList();
}
var mediaInfo = getMediaInfo(type);
return abrController.getBitrateList(mediaInfo);
}
function onProtectionError(event) {
if (event.error) {
errHandler.error(event.error);
logger.fatal(event.error.message);
}
}
function prepareTrackChange(e) {
if (!isActive || !streamInfo) {
return;
}
hasFinishedBuffering = false;
var mediaInfo = e.newMediaInfo;
var manifest = manifestModel.getValue();
adapter.setCurrentMediaInfo(streamInfo.id, mediaInfo.type, mediaInfo);
var processor = getProcessorForMediaInfo(mediaInfo);
if (!processor) return;
var currentTime = playbackController.getTime();
logger.info('Stream - Process track changed at current time ' + currentTime); // Applies only for MSS streams
if (manifest.refreshManifestOnSwitchTrack) {
trackChangedEvents.push(e);
if (!manifestUpdater.getIsUpdating()) {
logger.debug('Stream - Refreshing manifest for switch track');
manifestUpdater.refreshManifest();
}
} else {
processor.selectMediaInfo(mediaInfo).then(function () {
if (mediaInfo.type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || mediaInfo.type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO) {
abrController.updateTopQualityIndex(mediaInfo);
}
processor.prepareTrackSwitch();
});
}
}
function prepareQualityChange(e) {
var processor = _getProcessorByType(e.mediaType);
if (processor) {
processor.prepareQualityChange(e);
}
}
function addInlineEvents() {
if (eventController) {
var events = adapter.getEventsFor(streamInfo);
eventController.addInlineEvents(events);
}
}
function _checkIfInitializationCompleted() {
var ln = streamProcessors.length;
var hasError = !!updateError.audio || !!updateError.video;
var error = hasError ? new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].DATA_UPDATE_FAILED_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"].DATA_UPDATE_FAILED_ERROR_MESSAGE) : null;
for (var i = 0; i < ln; i++) {
if (streamProcessors[i].isUpdating() || isUpdating) {
return;
}
}
if (protectionController) {
// Need to check if streamProcessors exists because streamProcessors
// could be cleared in case an error is detected while initializing DRM keysystem
protectionController.clearMediaInfoArray();
for (var _i = 0; _i < ln && streamProcessors[_i]; _i++) {
var type = streamProcessors[_i].getType();
var mediaInfo = streamProcessors[_i].getMediaInfo();
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && mediaInfo.isFragmented) {
var _mediaInfo = streamProcessors[_i].getMediaInfo();
if (_mediaInfo) {
protectionController.initializeForMedia(_mediaInfo);
}
}
}
}
if (error) {
errHandler.error(error);
} else if (!isInitialized) {
isInitialized = true;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_INITIALIZED, {
streamInfo: streamInfo
});
}
}
function getMediaInfo(type) {
var streamProcessor = null;
for (var i = 0; i < streamProcessors.length; i++) {
streamProcessor = streamProcessors[i];
if (streamProcessor.getType() === type) {
return streamProcessor.getMediaInfo();
}
}
return null;
}
function onBufferingCompleted() {
var processors = getProcessors();
var ln = processors.length;
if (ln === 0) {
logger.warn('onBufferingCompleted - can\'t trigger STREAM_BUFFERING_COMPLETED because no streamProcessor is defined');
return;
} // if there is at least one buffer controller that has not completed buffering yet do nothing
for (var i = 0; i < ln; i++) {
//if audio or video buffer is not buffering completed state, do not send STREAM_BUFFERING_COMPLETED
if (!processors[i].isBufferingCompleted() && (processors[i].getType() === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO || processors[i].getType() === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO)) {
logger.debug('onBufferingCompleted - One streamProcessor has finished but', processors[i].getType(), 'one is not buffering completed');
return;
}
}
logger.debug('onBufferingCompleted - trigger STREAM_BUFFERING_COMPLETED');
hasFinishedBuffering = true;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_BUFFERING_COMPLETED, {
streamInfo: streamInfo
}, {
streamInfo: streamInfo
});
}
function onDataUpdateCompleted(e) {
updateError[e.mediaType] = e.error;
_checkIfInitializationCompleted();
}
function onInbandEvents(e) {
if (eventController) {
eventController.addInbandEvents(e.events);
}
}
function getProcessorForMediaInfo(mediaInfo) {
if (!mediaInfo || !mediaInfo.type) {
return null;
}
return _getProcessorByType(mediaInfo.type);
}
function _getProcessorByType(type) {
if (!type) {
return null;
}
var processors = getProcessors();
return processors.filter(function (processor) {
return processor.getType() === type;
})[0];
}
function getProcessors() {
var arr = [];
var type, streamProcessor;
for (var i = 0; i < streamProcessors.length; i++) {
streamProcessor = streamProcessors[i];
type = streamProcessor.getType();
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) {
arr.push(streamProcessor);
}
}
return arr;
}
function startScheduleControllers() {
var ln = streamProcessors.length;
for (var i = 0; i < ln && streamProcessors[i]; i++) {
streamProcessors[i].getScheduleController().startScheduleTimer();
}
}
function updateData(updatedStreamInfo) {
return new Promise(function (resolve) {
isUpdating = true;
streamInfo = updatedStreamInfo;
if (eventController) {
addInlineEvents();
}
var promises = [];
for (var i = 0, ln = streamProcessors.length; i < ln; i++) {
var streamProcessor = streamProcessors[i];
var currentMediaInfo = streamProcessor.getMediaInfo();
promises.push(streamProcessor.updateStreamInfo(streamInfo));
var allMediaForType = adapter.getAllMediaInfoForType(streamInfo, streamProcessor.getType()); // Check if AdaptationSet has not been removed in MPD update
if (allMediaForType) {
// Remove the current mediaInfo objects before adding the updated ones
streamProcessor.clearMediaInfoArray();
for (var j = 0; j < allMediaForType.length; j++) {
var mInfo = allMediaForType[j];
streamProcessor.addMediaInfo(allMediaForType[j]);
if (adapter.areMediaInfosEqual(currentMediaInfo, mInfo)) {
abrController.updateTopQualityIndex(mInfo);
promises.push(streamProcessor.selectMediaInfo(mInfo));
}
}
}
}
Promise.all(promises).then(function () {
promises = [];
while (trackChangedEvents.length > 0) {
var trackChangedEvent = trackChangedEvents.pop();
var mediaInfo = trackChangedEvent.newMediaInfo;
var processor = getProcessorForMediaInfo(trackChangedEvent.oldMediaInfo);
if (!processor) return;
promises.push(processor.prepareTrackSwitch());
processor.selectMediaInfo(mediaInfo);
}
return Promise.all(promises);
}).then(function () {
isUpdating = false;
_checkIfInitializationCompleted();
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_UPDATED, {
streamInfo: streamInfo
});
resolve();
});
});
}
function isMediaCodecCompatible(newStream) {
var previousStream = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
return compareCodecs(newStream, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, previousStream) && compareCodecs(newStream, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO, previousStream);
}
function isProtectionCompatible(newStream) {
if (!newStream) {
return true;
}
return _compareProtectionConfig(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, newStream) && _compareProtectionConfig(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO, newStream);
}
function _compareProtectionConfig(type, newStream) {
var currentStreamInfo = getStreamInfo();
var newStreamInfo = newStream.getStreamInfo();
if (!newStreamInfo || !currentStreamInfo) {
return true;
}
var newAdaptation = adapter.getAdaptationForType(newStreamInfo.index, type, newStreamInfo);
var currentAdaptation = adapter.getAdaptationForType(currentStreamInfo.index, type, currentStreamInfo);
if (!newAdaptation || !currentAdaptation) {
// If there is no adaptation for neither the old or the new stream they're compatible
return !newAdaptation && !currentAdaptation;
} // If the current period is unencrypted and the upcoming one is encrypted we need to reset sourcebuffers.
return !(!_isAdaptationDrmProtected(currentAdaptation) && _isAdaptationDrmProtected(newAdaptation));
}
function _isAdaptationDrmProtected(adaptation) {
if (!adaptation) {
// If there is no adaptation for neither the old or the new stream they're compatible
return false;
} // If the current period is unencrypted and the upcoming one is encrypted we need to reset sourcebuffers.
return !!(adaptation.ContentProtection || adaptation.Representation && adaptation.Representation.length > 0 && adaptation.Representation[0].ContentProtection);
}
function compareCodecs(newStream, type) {
var previousStream = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
if (!newStream || !newStream.hasOwnProperty('getStreamInfo')) {
return false;
}
var newStreamInfo = newStream.getStreamInfo();
var currentStreamInfo = previousStream ? previousStream.getStreamInfo() : getStreamInfo();
if (!newStreamInfo || !currentStreamInfo) {
return false;
}
var newAdaptation = adapter.getAdaptationForType(newStreamInfo.index, type, newStreamInfo);
var currentAdaptation = adapter.getAdaptationForType(currentStreamInfo.index, type, currentStreamInfo);
if (!newAdaptation || !currentAdaptation) {
// If there is no adaptation for neither the old or the new stream they're compatible
return !newAdaptation && !currentAdaptation;
}
var sameMimeType = newAdaptation && currentAdaptation && newAdaptation.mimeType === currentAdaptation.mimeType;
var oldCodecs = currentAdaptation.Representation_asArray.map(function (representation) {
return representation.codecs;
});
var newCodecs = newAdaptation.Representation_asArray.map(function (representation) {
return representation.codecs;
});
var codecMatch = newCodecs.some(function (newCodec) {
return oldCodecs.indexOf(newCodec) > -1;
});
var partialCodecMatch = newCodecs.some(function (newCodec) {
return oldCodecs.some(function (oldCodec) {
return capabilities.codecRootCompatibleWithCodec(oldCodec, newCodec);
});
});
return codecMatch || partialCodecMatch && sameMimeType;
}
function setPreloaded(value) {
preloaded = value;
}
function getPreloaded() {
return preloaded;
}
function getHasFinishedBuffering() {
return hasFinishedBuffering;
}
function getAdapter() {
return adapter;
}
instance = {
initialize: initialize,
getStreamId: getStreamId,
activate: activate,
deactivate: deactivate,
getIsActive: getIsActive,
getDuration: getDuration,
getStartTime: getStartTime,
getId: getId,
getStreamInfo: getStreamInfo,
getHasAudioTrack: getHasAudioTrack,
getHasVideoTrack: getHasVideoTrack,
startPreloading: startPreloading,
getThumbnailController: getThumbnailController,
getBitrateListFor: getBitrateListFor,
updateData: updateData,
reset: reset,
getProcessors: getProcessors,
setMediaSource: setMediaSource,
isMediaCodecCompatible: isMediaCodecCompatible,
isProtectionCompatible: isProtectionCompatible,
getPreloaded: getPreloaded,
getIsEndedEventSignaled: getIsEndedEventSignaled,
setIsEndedEventSignaled: setIsEndedEventSignaled,
getAdapter: getAdapter,
getHasFinishedBuffering: getHasFinishedBuffering,
setPreloaded: setPreloaded,
startScheduleControllers: startScheduleControllers,
prepareTrackChange: prepareTrackChange,
prepareQualityChange: prepareQualityChange
};
setup();
return instance;
}
Stream.__dashjs_factory_name = 'Stream';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_9__["default"].getClassFactory(Stream));
/***/ }),
/***/ "./src/streaming/StreamProcessor.js":
/*!******************************************!*\
!*** ./src/streaming/StreamProcessor.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _models_FragmentModel__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./models/FragmentModel */ "./src/streaming/models/FragmentModel.js");
/* harmony import */ var _controllers_BufferController__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./controllers/BufferController */ "./src/streaming/controllers/BufferController.js");
/* harmony import */ var _text_NotFragmentedTextBufferController__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./text/NotFragmentedTextBufferController */ "./src/streaming/text/NotFragmentedTextBufferController.js");
/* harmony import */ var _controllers_ScheduleController__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./controllers/ScheduleController */ "./src/streaming/controllers/ScheduleController.js");
/* harmony import */ var _dash_controllers_RepresentationController__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../dash/controllers/RepresentationController */ "./src/dash/controllers/RepresentationController.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _dash_DashHandler__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../dash/DashHandler */ "./src/dash/DashHandler.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _utils_RequestModifier__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./utils/RequestModifier */ "./src/streaming/utils/RequestModifier.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _utils_BoxParser__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./utils/BoxParser */ "./src/streaming/utils/BoxParser.js");
/* harmony import */ var _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./vo/metrics/PlayList */ "./src/streaming/vo/metrics/PlayList.js");
/* harmony import */ var _dash_controllers_SegmentsController__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../dash/controllers/SegmentsController */ "./src/dash/controllers/SegmentsController.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function StreamProcessor(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
var streamInfo = config.streamInfo;
var type = config.type;
var errHandler = config.errHandler;
var mimeType = config.mimeType;
var timelineConverter = config.timelineConverter;
var adapter = config.adapter;
var manifestModel = config.manifestModel;
var mediaPlayerModel = config.mediaPlayerModel;
var fragmentModel = config.fragmentModel;
var abrController = config.abrController;
var playbackController = config.playbackController;
var mediaController = config.mediaController;
var textController = config.textController;
var dashMetrics = config.dashMetrics;
var settings = config.settings;
var boxParser = config.boxParser;
var segmentBlacklistController = config.segmentBlacklistController;
var instance, logger, isDynamic, mediaInfo, mediaInfoArr, bufferController, scheduleController, representationController, shouldUseExplicitTimeForRequest, qualityChangeInProgress, dashHandler, segmentsController, bufferingTime;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_15__["default"])(context).getInstance().getLogger(instance);
resetInitialSettings();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].DATA_UPDATE_COMPLETED, _onDataUpdateCompleted, instance, {
priority: _core_EventBus__WEBPACK_IMPORTED_MODULE_10__["default"].EVENT_PRIORITY_HIGH
}); // High priority to be notified before Stream
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].INIT_FRAGMENT_NEEDED, _onInitFragmentNeeded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].MEDIA_FRAGMENT_NEEDED, _onMediaFragmentNeeded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_CLEARED, _onBufferCleared, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SEEK_TARGET, _onSeekTarget, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].FRAGMENT_LOADING_ABANDONED, _onFragmentLoadingAbandoned, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].FRAGMENT_LOADING_COMPLETED, _onFragmentLoadingCompleted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].QUOTA_EXCEEDED, _onQuotaExceeded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SET_FRAGMENTED_TEXT_AFTER_DISABLED, _onSetFragmentedTextAfterDisabled, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SET_NON_FRAGMENTED_TEXT, _onSetNonFragmentedText, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SOURCE_BUFFER_ERROR, _onSourceBufferError, instance);
}
function initialize(mediaSource, hasVideoTrack, isFragmented) {
segmentsController = Object(_dash_controllers_SegmentsController__WEBPACK_IMPORTED_MODULE_20__["default"])(context).create({
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"],
eventBus: eventBus,
streamInfo: streamInfo,
timelineConverter: timelineConverter,
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
segmentBaseController: config.segmentBaseController,
type: type
});
dashHandler = Object(_dash_DashHandler__WEBPACK_IMPORTED_MODULE_12__["default"])(context).create({
streamInfo: streamInfo,
type: type,
timelineConverter: timelineConverter,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
baseURLController: config.baseURLController,
errHandler: errHandler,
segmentsController: segmentsController,
settings: settings,
boxParser: boxParser,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"],
eventBus: eventBus,
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__["default"],
debug: Object(_core_Debug__WEBPACK_IMPORTED_MODULE_15__["default"])(context).getInstance(),
requestModifier: Object(_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_16__["default"])(context).getInstance(),
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"],
urlUtils: Object(_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_17__["default"])(context).getInstance()
});
isDynamic = streamInfo.manifestInfo.isDynamic; // Create/initialize controllers
dashHandler.initialize(isDynamic);
abrController.registerStreamType(type, instance);
representationController = Object(_dash_controllers_RepresentationController__WEBPACK_IMPORTED_MODULE_7__["default"])(context).create({
streamInfo: streamInfo,
type: type,
abrController: abrController,
dashMetrics: dashMetrics,
playbackController: playbackController,
timelineConverter: timelineConverter,
dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"],
eventBus: eventBus,
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__["default"],
isDynamic: isDynamic,
segmentsController: segmentsController
});
bufferController = _createBufferControllerForType(type, isFragmented);
if (bufferController) {
bufferController.initialize(mediaSource);
}
scheduleController = Object(_controllers_ScheduleController__WEBPACK_IMPORTED_MODULE_6__["default"])(context).create({
streamInfo: streamInfo,
type: type,
mimeType: mimeType,
adapter: adapter,
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
fragmentModel: fragmentModel,
abrController: abrController,
playbackController: playbackController,
textController: textController,
mediaController: mediaController,
bufferController: bufferController,
settings: settings
});
scheduleController.initialize(hasVideoTrack);
bufferingTime = 0;
shouldUseExplicitTimeForRequest = false;
}
function getStreamId() {
return streamInfo.id;
}
function getType() {
return type;
}
function getIsTextTrack() {
return adapter.getIsTextTrack(representationController.getData());
}
function resetInitialSettings() {
mediaInfoArr = [];
mediaInfo = null;
bufferingTime = 0;
shouldUseExplicitTimeForRequest = false;
qualityChangeInProgress = false;
}
function reset(errored, keepBuffers) {
if (dashHandler) {
dashHandler.reset();
}
if (bufferController) {
bufferController.reset(errored, keepBuffers);
bufferController = null;
}
if (scheduleController) {
scheduleController.reset();
scheduleController = null;
}
if (representationController) {
representationController.reset();
representationController = null;
}
if (segmentsController) {
segmentsController = null;
}
if (abrController) {
abrController.unRegisterStreamType(getStreamId(), type);
}
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].DATA_UPDATE_COMPLETED, _onDataUpdateCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].INIT_FRAGMENT_NEEDED, _onInitFragmentNeeded, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].MEDIA_FRAGMENT_NEEDED, _onMediaFragmentNeeded, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_CLEARED, _onBufferCleared, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SEEK_TARGET, _onSeekTarget, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].FRAGMENT_LOADING_ABANDONED, _onFragmentLoadingAbandoned, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].FRAGMENT_LOADING_COMPLETED, _onFragmentLoadingCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SET_FRAGMENTED_TEXT_AFTER_DISABLED, _onSetFragmentedTextAfterDisabled, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SET_NON_FRAGMENTED_TEXT, _onSetNonFragmentedText, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].QUOTA_EXCEEDED, _onQuotaExceeded, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].SOURCE_BUFFER_ERROR, _onSourceBufferError, instance);
resetInitialSettings();
type = null;
streamInfo = null;
}
function isUpdating() {
return representationController ? representationController.isUpdating() : false;
}
/**
* When a seek within the corresponding period occurs this function initiates the clearing of the buffer and sets the correct buffering time.
* @param {object} e
* @private
*/
function prepareInnerPeriodPlaybackSeeking(e) {
return new Promise(function (resolve) {
// Stop segment requests until we have figured out for which time we need to request a segment. We don't want to replace existing segments.
scheduleController.clearScheduleTimer();
fragmentModel.abortRequests(); // Abort operations to the SourceBuffer Sink and reset the BufferControllers isBufferingCompleted state.
bufferController.prepareForPlaybackSeek().then(function () {
// Clear the buffer. We need to prune everything which is not in the target interval.
var clearRanges = bufferController.getAllRangesWithSafetyFactor(e.seekTime); // When everything has been pruned go on
return bufferController.clearBuffers(clearRanges);
}).then(function () {
// Figure out the correct segment request time.
var targetTime = bufferController.getContinuousBufferTimeForTargetTime(e.seekTime); // If the buffer is continuous and exceeds the duration of the period we are still done buffering. We need to trigger the buffering completed event in order to start prebuffering upcoming periods again
if (!isNaN(streamInfo.duration) && isFinite(streamInfo.duration) && targetTime >= streamInfo.start + streamInfo.duration) {
bufferController.setIsBufferingCompleted(true);
resolve();
} else {
setExplicitBufferingTime(targetTime);
bufferController.setSeekTarget(targetTime);
var promises = []; // append window has been reset by abort() operation. Set the correct values again
promises.push(bufferController.updateAppendWindow()); // Timestamp offset couldve been changed by preloading period
var representationInfo = getRepresentationInfo();
promises.push(bufferController.updateBufferTimestampOffset(representationInfo));
Promise.all(promises).then(function () {
// We might have aborted the append operation of an init segment. Append init segment again.
scheduleController.setInitSegmentRequired(true); // Right after a seek we should not immediately check the playback quality
scheduleController.setCheckPlaybackQuality(false);
scheduleController.startScheduleTimer();
resolve();
});
}
})["catch"](function (e) {
logger.error(e);
});
});
}
/**
* Seek outside of the current period.
* @return {Promise<unknown>}
*/
function prepareOuterPeriodPlaybackSeeking() {
return new Promise(function (resolve, reject) {
try {
// Stop scheduling
scheduleController.clearScheduleTimer(); // Abort all ongoing requests
fragmentModel.abortRequests(); // buffering not complete anymore and abort current append operation to SourceBuffer
bufferController.prepareForPlaybackSeek().then(function () {
// Clear the buffers completely.
return bufferController.pruneAllSafely();
}).then(function () {
resolve();
});
} catch (e) {
reject(e);
}
});
}
/**
* ScheduleController indicates that an init segment needs to be fetched.
* @param {object} e
* @param {boolean} rescheduleIfNoRequest - Defines whether we reschedule in case no valid request could be generated
* @private
*/
function _onInitFragmentNeeded(e) {
var rescheduleIfNoRequest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
// Event propagation may have been stopped (see MssHandler)
if (!e.sender) return;
if (playbackController.getIsManifestUpdateInProgress()) {
_noValidRequest();
return;
}
if (getIsTextTrack() && !textController.isTextEnabled()) return;
if (bufferController && e.representationId) {
if (!bufferController.appendInitSegmentFromCache(e.representationId)) {
var rep = representationController.getCurrentRepresentation(); // Dummy init segment (fragmented tracks without initialization segment)
if (rep.range === 0) {
_onMediaFragmentNeeded();
return;
} // Init segment not in cache, send new request
var request = dashHandler ? dashHandler.getInitRequest(mediaInfo, rep) : null;
if (request) {
fragmentModel.executeRequest(request);
} else if (rescheduleIfNoRequest) {
scheduleController.setInitSegmentRequired(true);
_noValidRequest();
}
}
}
}
/**
* ScheduleController indicates that a media segment is needed
* @param {boolean} rescheduleIfNoRequest - Defines whether we reschedule in case no valid request could be generated
* @private
*/
function _onMediaFragmentNeeded(e) {
var rescheduleIfNoRequest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
// Don't schedule next fragments while updating manifest or pruning to avoid buffer inconsistencies
if (playbackController.getIsManifestUpdateInProgress() || bufferController.getIsPruningInProgress()) {
_noValidRequest();
return;
}
var request = _getFragmentRequest();
if (request) {
shouldUseExplicitTimeForRequest = false;
_mediaRequestGenerated(request);
} else {
_noMediaRequestGenerated(rescheduleIfNoRequest);
}
}
/**
* If we generated a valid media request we can execute the request. In some cases the segment might be blacklisted.
* @param {object} request
* @private
*/
function _mediaRequestGenerated(request) {
if (!isNaN(request.startTime + request.duration)) {
bufferingTime = request.startTime + request.duration;
}
request.delayLoadingTime = new Date().getTime() + scheduleController.getTimeToLoadDelay();
scheduleController.setTimeToLoadDelay(0);
if (!_shouldIgnoreRequest(request)) {
logger.debug("Next fragment request url for stream id ".concat(streamInfo.id, " and media type ").concat(type, " is ").concat(request.url));
fragmentModel.executeRequest(request);
} else {
logger.warn("Fragment request url ".concat(request.url, " for stream id ").concat(streamInfo.id, " and media type ").concat(type, " is on the ignore list and will be skipped"));
_noValidRequest();
}
}
/**
* We could not generate a valid request. Check if the media is finished, we are stuck in a gap or simply need to wait for the next segment to be available.
* @param {boolean} rescheduleIfNoRequest
* @private
*/
function _noMediaRequestGenerated(rescheduleIfNoRequest) {
var representation = representationController.getCurrentRepresentation(); // If this statement is true we are stuck. A static manifest does not change and we did not find a valid request for the target time
// There is no point in trying again. We need to adjust the time in order to find a valid request. This can happen if the user/app seeked into a gap.
if (settings.get().streaming.gaps.enableSeekFix && !isDynamic && shouldUseExplicitTimeForRequest && playbackController.isSeeking()) {
var adjustedTime = dashHandler.getValidSeekTimeCloseToTargetTime(bufferingTime, mediaInfo, representation, settings.get().streaming.gaps.threshold);
if (!isNaN(adjustedTime)) {
playbackController.seek(adjustedTime, false, false);
return;
}
} // Check if the media is finished. If so, no need to schedule another request
var isLastSegmentRequested = dashHandler.isLastSegmentRequested(representation, bufferingTime);
if (isLastSegmentRequested) {
var segmentIndex = dashHandler.getCurrentIndex();
logger.debug("Segment requesting for stream ".concat(streamInfo.id, " has finished"));
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].STREAM_REQUESTING_COMPLETED, {
segmentIndex: segmentIndex
}, {
streamId: streamInfo.id,
mediaType: type
});
bufferController.segmentRequestingCompleted(segmentIndex);
scheduleController.clearScheduleTimer();
return;
}
if (rescheduleIfNoRequest) {
_noValidRequest();
}
}
/**
* In certain situations we need to ignore a request. For instance, if a segment is blacklisted because it caused an MSE error.
* @private
*/
function _shouldIgnoreRequest(request) {
var blacklistUrl = request.url;
if (request.range) {
blacklistUrl = blacklistUrl.concat('_', request.range);
}
return segmentBlacklistController.contains(blacklistUrl);
}
/**
* Get the init or media segment request using the DashHandler.
* @return {null|FragmentRequest|null}
* @private
*/
function _getFragmentRequest() {
var representationInfo = getRepresentationInfo();
var request;
if (isNaN(bufferingTime) || getType() === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !textController.isTextEnabled()) {
return null;
} // Use time just whenever is strictly needed
var useTime = shouldUseExplicitTimeForRequest;
if (dashHandler) {
var representation = representationController && representationInfo ? representationController.getRepresentationForQuality(representationInfo.quality) : null;
if (useTime) {
request = dashHandler.getSegmentRequestForTime(mediaInfo, representation, bufferingTime);
} else {
request = dashHandler.getNextSegmentRequest(mediaInfo, representation);
}
}
return request;
}
/**
* Whenever we can not generate a valid request we restart scheduling according to the timeouts defined in the settings.
* @private
*/
function _noValidRequest() {
scheduleController.startScheduleTimer(settings.get().streaming.lowLatencyEnabled ? settings.get().streaming.scheduling.lowLatencyTimeout : settings.get().streaming.scheduling.defaultTimeout);
}
function _onDataUpdateCompleted(e) {
if (!e.error) {
// Update representation if no error
scheduleController.setCurrentRepresentation(adapter.convertRepresentationToRepresentationInfo(e.currentRepresentation));
if (!bufferController.getIsBufferingCompleted()) {
bufferController.updateBufferTimestampOffset(e.currentRepresentation);
}
}
}
function _onBufferLevelStateChanged(e) {
dashMetrics.addBufferState(type, e.state, scheduleController.getBufferTarget());
if (e.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].BUFFER_EMPTY && !playbackController.isSeeking()) {
logger.info('Buffer is empty! Stalling!');
dashMetrics.pushPlayListTraceMetrics(new Date(), _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_19__["PlayListTrace"].REBUFFERING_REASON);
}
}
function _onBufferCleared(e) {
// Remove executed requests not buffered anymore
fragmentModel.syncExecutedRequestsWithBufferedRange(bufferController.getBuffer().getAllBufferRanges(), streamInfo.duration); // If buffer removed ahead current time (QuotaExceededError or automatic buffer pruning) then adjust current index handler time
if (e.quotaExceeded && e.from > playbackController.getTime()) {
setExplicitBufferingTime(e.from);
} // (Re)start schedule once buffer has been pruned after a QuotaExceededError
if (e.hasEnoughSpaceToAppend && e.quotaExceeded) {
scheduleController.startScheduleTimer();
}
}
/**
* This function is called when the corresponding SourceBuffer encountered an error.
* We blacklist the last segment assuming it caused the error
* @param {object} e
* @private
*/
function _onSourceBufferError(e) {
if (!e || !e.lastRequestAppended || !e.lastRequestAppended.url) {
return;
}
var blacklistUrl = e.lastRequestAppended.url;
if (e.lastRequestAppended.range) {
blacklistUrl = blacklistUrl.concat('_', e.lastRequestAppended.range);
}
logger.warn("Blacklisting segment with url ".concat(blacklistUrl));
segmentBlacklistController.add(blacklistUrl);
}
/**
* The quality has changed which means we have switched to a different representation.
* If we want to aggressively replace existing parts in the buffer we need to make sure that the new quality is higher than the already buffered one.
* @param {object} e
* @private
*/
function prepareQualityChange(e) {
logger.debug("Preparing quality switch for type ".concat(type));
var newQuality = e.newQuality;
qualityChangeInProgress = true; // Stop scheduling until we are done with preparing the quality switch
scheduleController.clearScheduleTimer();
var representationInfo = getRepresentationInfo(newQuality);
scheduleController.setCurrentRepresentation(representationInfo);
representationController.prepareQualityChange(newQuality); // Abort the current request to avoid inconsistencies. A quality switch can also be triggered manually by the application.
// If we update the buffer values now, or initialize a request to the new init segment, the currently downloading media segment might "work" with wrong values.
// Everything that is already in the buffer queue is ok and will be handled by the corresponding function below depending on the switch mode.
fragmentModel.abortRequests(); // In any case we need to update the MSE.timeOffset
bufferController.updateBufferTimestampOffset(representationInfo).then(function () {
// If the switch should occur immediately we need to replace existing stuff in the buffer
if (e.reason && e.reason.forceReplace) {
_prepareReplacementQualitySwitch();
} // If fast switch is enabled we check if we are supposed to replace existing stuff in the buffer
else if (settings.get().streaming.buffer.fastSwitchEnabled) {
_prepareForFastQualitySwitch(representationInfo);
} // Default quality switch. We append the new quality to the already buffered stuff
else {
_prepareForDefaultQualitySwitch();
}
dashMetrics.pushPlayListTraceMetrics(new Date(), _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_19__["PlayListTrace"].REPRESENTATION_SWITCH_STOP_REASON);
dashMetrics.createPlaylistTraceMetrics(representationInfo.id, playbackController.getTime() * 1000, playbackController.getPlaybackRate());
});
}
function _prepareReplacementQualitySwitch() {
// Inform other classes like the GapController that we are replacing existing stuff
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_REPLACEMENT_STARTED, {
mediaType: type,
streamId: streamInfo.id
}, {
mediaType: type,
streamId: streamInfo.id
}); // Abort appending segments to the buffer. Also adjust the appendWindow as we might have been in the progress of prebuffering stuff.
bufferController.prepareForReplacementQualitySwitch().then(function () {
_bufferClearedForReplacement();
qualityChangeInProgress = false;
})["catch"](function () {
_bufferClearedForReplacement();
qualityChangeInProgress = false;
});
}
function _prepareForFastQualitySwitch(representationInfo) {
// if we switch up in quality and need to replace existing parts in the buffer we need to adjust the buffer target
var time = playbackController.getTime();
var safeBufferLevel = 1.5;
var request = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_3__["default"].FRAGMENT_MODEL_EXECUTED,
time: time + safeBufferLevel,
threshold: 0
})[0];
if (request && !getIsTextTrack()) {
var bufferLevel = bufferController.getBufferLevel();
var abandonmentState = abrController.getAbandonmentStateFor(streamInfo.id, type);
if (request.quality < representationInfo.quality && bufferLevel >= safeBufferLevel && abandonmentState !== _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].ABANDON_LOAD) {
var targetTime = time + safeBufferLevel;
setExplicitBufferingTime(targetTime);
scheduleController.setCheckPlaybackQuality(false);
scheduleController.startScheduleTimer();
} else {
_prepareForDefaultQualitySwitch();
}
} else {
scheduleController.startScheduleTimer();
}
qualityChangeInProgress = false;
}
function _prepareForDefaultQualitySwitch() {
// We might have aborted the current request. We need to set an explicit buffer time based on what we already have in the buffer.
_bufferClearedForNonReplacement();
qualityChangeInProgress = false;
}
/**
* We have canceled the download of a fragment and need to adjust the buffer time or reload an init segment
* @param {object} e
*/
function _onFragmentLoadingAbandoned(e) {
logger.info('onFragmentLoadingAbandoned request: ' + e.request.url + ' has been aborted'); // we only need to handle this if we are not seeking, not switching the tracks and not switching the quality
if (!playbackController.isSeeking() && !scheduleController.getSwitchStrack() && !qualityChangeInProgress) {
logger.info('onFragmentLoadingAbandoned request: ' + e.request.url + ' has to be downloaded again, origin is not seeking process or switch track call'); // in case of an init segment we force the download of an init segment
if (e.request && e.request.isInitializationRequest()) {
scheduleController.setInitSegmentRequired(true);
} // in case of a media segment we reset the buffering time
else {
setExplicitBufferingTime(e.request.startTime + e.request.duration / 2);
} // In case of a seek the schedule controller was stopped and will be started once the buffer has been pruned.
scheduleController.startScheduleTimer(0);
}
}
/**
* When a fragment has been loaded we need to start the schedule timer again in case of an error.
* @param {object} e
*/
function _onFragmentLoadingCompleted(e) {
logger.info('OnFragmentLoadingCompleted for stream id ' + streamInfo.id + ' and media type ' + type + ' - Url:', e.request ? e.request.url : 'undefined', e.request.range ? ', Range:' + e.request.range : '');
if (getIsTextTrack()) {
scheduleController.startScheduleTimer(0);
}
if (e.error && e.request.serviceLocation) {
_handleFragmentLoadingError(e);
}
}
/**
* If we encountered an error when loading the fragment we need to handle it according to the segment type
* @private
*/
function _handleFragmentLoadingError(e) {
logger.info("Fragment loading completed with an error");
if (!e || !e.request || !e.request.type) {
return;
} // In case there are baseUrls that can still be tried a valid request can be generated. If no valid request can be generated we ran out of baseUrls.
// Consequently, we need to signal that we dont want to retry in case no valid request could be generated otherwise we keep trying with the same url infinitely.
// Init segment could not be loaded. If we have multiple baseUrls we still have a chance to get a valid segment.
if (e.request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_21__["HTTPRequest"].INIT_SEGMENT_TYPE) {
_onInitFragmentNeeded({
representationId: e.request.representationId,
sender: {}
}, false);
} // Media segment could not be loaded
else if (e.request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_21__["HTTPRequest"].MEDIA_SEGMENT_TYPE) {
setExplicitBufferingTime(e.request.startTime + e.request.duration / 2);
_onMediaFragmentNeeded({}, false);
}
}
/**
* Callback function triggered by the TextController whenever a track is changed for fragmented text. Will only be triggered if textracks have previously been disabled.
* @private
*/
function _onSetFragmentedTextAfterDisabled() {
setExplicitBufferingTime(playbackController.getTime());
getScheduleController().startScheduleTimer();
}
/**
* Callback function triggered by the TextController whenever a track is changed for non fragmented text
* @param {object} e
* @private
*/
function _onSetNonFragmentedText(e) {
var currentTrackInfo = e.currentTrackInfo;
if (!currentTrackInfo) {
return;
}
var mInfo = mediaInfoArr.find(function (info) {
return info.index === currentTrackInfo.index && info.lang === currentTrackInfo.lang;
});
if (mInfo) {
selectMediaInfo(mInfo).then(function () {
bufferController.setIsBufferingCompleted(false);
setExplicitBufferingTime(playbackController.getTime());
scheduleController.setInitSegmentRequired(true);
scheduleController.startScheduleTimer();
});
}
}
function _onQuotaExceeded(e) {
// Stop scheduler (will be restarted once buffer is pruned)
setExplicitBufferingTime(e.quotaExceededTime);
scheduleController.clearScheduleTimer();
}
function getRepresentationController() {
return representationController;
}
function getBuffer() {
return bufferController ? bufferController.getBuffer() : null;
}
function getBufferController() {
return bufferController;
}
function getFragmentModel() {
return fragmentModel;
}
function updateStreamInfo(newStreamInfo) {
streamInfo = newStreamInfo;
if (!isBufferingCompleted()) {
return bufferController.updateAppendWindow();
}
return Promise.resolve();
}
function getStreamInfo() {
return streamInfo;
}
/**
* Called once the StreamProcessor is initialized and when the track is switched. We only have one StreamProcessor per media type. So we need to adjust the mediaInfo once we switch/select a track.
* @param {object} newMediaInfo
*/
function selectMediaInfo(newMediaInfo) {
if (newMediaInfo !== mediaInfo && (!newMediaInfo || !mediaInfo || newMediaInfo.type === mediaInfo.type)) {
mediaInfo = newMediaInfo;
}
var newRealAdaptation = adapter.getRealAdaptation(streamInfo, mediaInfo);
var voRepresentations = adapter.getVoRepresentations(mediaInfo);
if (representationController) {
var realAdaptation = representationController.getData();
var maxQuality = abrController.getMaxAllowedIndexFor(type, streamInfo.id);
var minIdx = abrController.getMinAllowedIndexFor(type, streamInfo.id);
var quality, averageThroughput;
var bitrate = null;
if ((realAdaptation === null || realAdaptation.id !== newRealAdaptation.id) && type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) {
averageThroughput = abrController.getThroughputHistory().getAverageThroughput(type, isDynamic);
bitrate = averageThroughput || abrController.getInitialBitrateFor(type, streamInfo.id);
quality = abrController.getQualityForBitrate(mediaInfo, bitrate, streamInfo.id);
} else {
quality = abrController.getQualityFor(type, streamInfo.id);
}
if (minIdx !== undefined && quality < minIdx) {
quality = minIdx;
}
if (quality > maxQuality) {
quality = maxQuality;
}
return representationController.updateData(newRealAdaptation, voRepresentations, type, mediaInfo.isFragmented, quality);
} else {
return Promise.resolve();
}
}
function addMediaInfo(newMediaInfo) {
if (mediaInfoArr.indexOf(newMediaInfo) === -1) {
mediaInfoArr.push(newMediaInfo);
}
}
function clearMediaInfoArray() {
mediaInfoArr = [];
}
function getMediaInfo() {
return mediaInfo;
}
function getMediaSource() {
return bufferController.getMediaSource();
}
function setMediaSource(mediaSource) {
bufferController.setMediaSource(mediaSource);
}
function getScheduleController() {
return scheduleController;
}
/**
* Get a specific voRepresentation. If quality parameter is defined, this function will return the voRepresentation for this quality.
* Otherwise, this function will return the current voRepresentation used by the representationController.
* @param {number} quality - quality index of the voRepresentaion expected.
*/
function getRepresentationInfo(quality) {
var voRepresentation;
if (quality !== undefined) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_9__["checkInteger"])(quality);
voRepresentation = representationController ? representationController.getRepresentationForQuality(quality) : null;
} else {
voRepresentation = representationController ? representationController.getCurrentRepresentation() : null;
}
return adapter.convertRepresentationToRepresentationInfo(voRepresentation);
}
function isBufferingCompleted() {
return bufferController ? bufferController.getIsBufferingCompleted() : false;
}
function getBufferLevel() {
return bufferController ? bufferController.getBufferLevel() : 0;
}
/**
* Probe the next request. This is used in the CMCD model to get information about the upcoming request. Note: No actual request is performed here.
* @return {FragmentRequest|null}
*/
function probeNextRequest() {
var representationInfo = getRepresentationInfo();
var representation = representationController && representationInfo ? representationController.getRepresentationForQuality(representationInfo.quality) : null;
var request = dashHandler.getNextSegmentRequestIdempotent(mediaInfo, representation);
return request;
}
function _onMediaFragmentLoaded(e) {
var chunk = e.chunk;
var bytes = chunk.bytes;
var quality = chunk.quality;
var currentRepresentation = getRepresentationInfo(quality);
var voRepresentation = representationController && currentRepresentation ? representationController.getRepresentationForQuality(currentRepresentation.quality) : null; // If we switch tracks this event might be fired after the representations in the RepresentationController have been updated according to the new MediaInfo.
// In this case there will be no currentRepresentation and voRepresentation matching the "old" quality
if (currentRepresentation && voRepresentation) {
var eventStreamMedia = adapter.getEventsFor(currentRepresentation.mediaInfo);
var eventStreamTrack = adapter.getEventsFor(currentRepresentation, voRepresentation);
if (eventStreamMedia && eventStreamMedia.length > 0 || eventStreamTrack && eventStreamTrack.length > 0) {
var request = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_3__["default"].FRAGMENT_MODEL_EXECUTED,
quality: quality,
index: chunk.index
})[0];
var events = _handleInbandEvents(bytes, request, eventStreamMedia, eventStreamTrack);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].INBAND_EVENTS, {
events: events
}, {
streamId: streamInfo.id
});
}
}
}
function _handleInbandEvents(data, request, mediaInbandEvents, trackInbandEvents) {
try {
var eventStreams = {};
var events = [];
/* Extract the possible schemeIdUri : If a DASH client detects an event message box with a scheme that is not defined in MPD, the client is expected to ignore it */
var inbandEvents = mediaInbandEvents.concat(trackInbandEvents);
for (var i = 0, ln = inbandEvents.length; i < ln; i++) {
eventStreams[inbandEvents[i].schemeIdUri + '/' + inbandEvents[i].value] = inbandEvents[i];
}
var isoFile = Object(_utils_BoxParser__WEBPACK_IMPORTED_MODULE_18__["default"])(context).getInstance().parse(data);
var eventBoxes = isoFile.getBoxes('emsg');
if (!eventBoxes || eventBoxes.length === 0) {
return events;
}
var sidx = isoFile.getBox('sidx');
var mediaAnchorTime = sidx && !isNaN(sidx.earliest_presentation_time) && !isNaN(sidx.timescale) ? sidx.earliest_presentation_time / sidx.timescale : request && !isNaN(request.mediaStartTime) ? request.mediaStartTime : 0;
var fragmentMediaStartTime = Math.max(mediaAnchorTime, 0);
var voRepresentation = representationController.getCurrentRepresentation();
for (var _i = 0, _ln = eventBoxes.length; _i < _ln; _i++) {
var event = adapter.getEvent(eventBoxes[_i], eventStreams, fragmentMediaStartTime, voRepresentation);
if (event) {
events.push(event);
}
}
return events;
} catch (e) {
return [];
}
}
function createBufferSinks(previousBufferSinks) {
var buffer = getBuffer();
if (buffer) {
return Promise.resolve(buffer);
}
return bufferController ? bufferController.createBufferSink(mediaInfo, previousBufferSinks) : Promise.resolve(null);
}
function prepareTrackSwitch() {
return new Promise(function (resolve) {
logger.debug("Preparing track switch for type ".concat(type));
var shouldReplace = type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || settings.get().streaming.trackSwitchMode[type] === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TRACK_SWITCH_MODE_ALWAYS_REPLACE && playbackController.getTimeToStreamEnd(streamInfo) > settings.get().streaming.buffer.stallThreshold; // when buffering is completed and we are not supposed to replace anything do nothing.
// Still we need to trigger preloading again and call change type in case user seeks back before transitioning to next period
if (bufferController.getIsBufferingCompleted() && !shouldReplace) {
bufferController.prepareForNonReplacementTrackSwitch(mediaInfo.codec).then(function () {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFERING_COMPLETED, {}, {
streamId: streamInfo.id,
mediaType: type
});
})["catch"](function () {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFERING_COMPLETED, {}, {
streamId: streamInfo.id,
mediaType: type
});
});
resolve();
return;
} // We stop the schedule controller and signal a track switch. That way we request a new init segment next
scheduleController.clearScheduleTimer();
scheduleController.setSwitchTrack(true); // when we are supposed to replace it does not matter if buffering is already completed
if (shouldReplace) {
// Inform other classes like the GapController that we are replacing existing stuff
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_REPLACEMENT_STARTED, {
mediaType: type,
streamId: streamInfo.id
}, {
mediaType: type,
streamId: streamInfo.id
}); // Abort the current request it will be removed from the buffer anyways
fragmentModel.abortRequests(); // Abort appending segments to the buffer. Also adjust the appendWindow as we might have been in the progress of prebuffering stuff.
bufferController.prepareForReplacementTrackSwitch(mediaInfo.codec).then(function () {
// Timestamp offset couldve been changed by preloading period
var representationInfo = getRepresentationInfo();
return bufferController.updateBufferTimestampOffset(representationInfo);
}).then(function () {
_bufferClearedForReplacement();
resolve();
})["catch"](function () {
_bufferClearedForReplacement();
resolve();
});
} else {
// We do not replace anything that is already in the buffer. Still we need to prepare the buffer for the track switch
bufferController.prepareForNonReplacementTrackSwitch(mediaInfo.codec).then(function () {
_bufferClearedForNonReplacement();
resolve();
})["catch"](function () {
_bufferClearedForNonReplacement();
resolve();
});
}
});
}
/**
* For an instant track switch we need to adjust the buffering time after the buffer has been pruned.
* @private
*/
function _bufferClearedForReplacement() {
var targetTime = playbackController.getTime();
if (settings.get().streaming.buffer.flushBufferAtTrackSwitch) {
// For some devices (like chromecast) it is necessary to seek the video element to reset the internal decoding buffer,
// otherwise audio track switch will be effective only once after previous buffered track is consumed
playbackController.seek(targetTime + 0.001, false, true);
}
setExplicitBufferingTime(targetTime);
bufferController.setSeekTarget(targetTime);
scheduleController.startScheduleTimer();
}
function _bufferClearedForNonReplacement() {
var time = playbackController.getTime();
var targetTime = bufferController.getContinuousBufferTimeForTargetTime(time);
setExplicitBufferingTime(targetTime);
scheduleController.startScheduleTimer();
}
function _createBufferControllerForType(type, isFragmented) {
var controller = null;
if (!type) {
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_MESSAGE + 'not properly defined'));
return null;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !isFragmented) {
controller = Object(_text_NotFragmentedTextBufferController__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
streamInfo: streamInfo,
type: type,
mimeType: mimeType,
fragmentModel: fragmentModel,
textController: textController,
errHandler: errHandler,
settings: settings
});
} else {
controller = Object(_controllers_BufferController__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
streamInfo: streamInfo,
type: type,
mediaPlayerModel: mediaPlayerModel,
manifestModel: manifestModel,
fragmentModel: fragmentModel,
errHandler: errHandler,
mediaController: mediaController,
representationController: representationController,
adapter: adapter,
textController: textController,
abrController: abrController,
playbackController: playbackController,
settings: settings
});
}
return controller;
}
function _onSeekTarget(e) {
if (e && !isNaN(e.time)) {
setExplicitBufferingTime(e.time);
bufferController.setSeekTarget(e.time);
}
}
function setExplicitBufferingTime(value) {
bufferingTime = value;
shouldUseExplicitTimeForRequest = true;
}
function finalisePlayList(time, reason) {
dashMetrics.pushPlayListTraceMetrics(time, reason);
}
instance = {
initialize: initialize,
getStreamId: getStreamId,
getType: getType,
isUpdating: isUpdating,
getBufferController: getBufferController,
getFragmentModel: getFragmentModel,
getScheduleController: getScheduleController,
getRepresentationController: getRepresentationController,
getRepresentationInfo: getRepresentationInfo,
getBufferLevel: getBufferLevel,
isBufferingCompleted: isBufferingCompleted,
createBufferSinks: createBufferSinks,
updateStreamInfo: updateStreamInfo,
getStreamInfo: getStreamInfo,
selectMediaInfo: selectMediaInfo,
clearMediaInfoArray: clearMediaInfoArray,
addMediaInfo: addMediaInfo,
prepareTrackSwitch: prepareTrackSwitch,
prepareQualityChange: prepareQualityChange,
getMediaInfo: getMediaInfo,
getMediaSource: getMediaSource,
setMediaSource: setMediaSource,
getBuffer: getBuffer,
setExplicitBufferingTime: setExplicitBufferingTime,
finalisePlayList: finalisePlayList,
probeNextRequest: probeNextRequest,
prepareInnerPeriodPlaybackSeeking: prepareInnerPeriodPlaybackSeeking,
prepareOuterPeriodPlaybackSeeking: prepareOuterPeriodPlaybackSeeking,
reset: reset
};
setup();
return instance;
}
StreamProcessor.__dashjs_factory_name = 'StreamProcessor';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_8__["default"].getClassFactory(StreamProcessor));
/***/ }),
/***/ "./src/streaming/XlinkLoader.js":
/*!**************************************!*\
!*** ./src/streaming/XlinkLoader.js ***!
\**************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _net_URLLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./net/URLLoader */ "./src/streaming/net/URLLoader.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _vo_TextRequest__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./vo/TextRequest */ "./src/streaming/vo/TextRequest.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function XlinkLoader(config) {
config = config || {};
var RESOLVE_TO_ZERO = 'urn:mpeg:dash:resolve-to-zero:2013';
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var urlLoader = Object(_net_URLLoader__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
errHandler: config.errHandler,
dashMetrics: config.dashMetrics,
mediaPlayerModel: config.mediaPlayerModel,
requestModifier: config.requestModifier,
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_7__["default"]
});
var instance;
function load(url, element, resolveObject) {
var report = function report(content, resolveToZero) {
element.resolved = true;
element.resolvedContent = content ? content : null;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].XLINK_ELEMENT_LOADED, {
element: element,
resolveObject: resolveObject,
error: content || resolveToZero ? null : new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_0__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_7__["default"].XLINK_LOADER_LOADING_FAILURE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_7__["default"].XLINK_LOADER_LOADING_FAILURE_ERROR_MESSAGE + url)
});
};
if (url === RESOLVE_TO_ZERO) {
report(null, true);
} else {
var request = new _vo_TextRequest__WEBPACK_IMPORTED_MODULE_3__["default"](url, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].XLINK_EXPANSION_TYPE);
urlLoader.load({
request: request,
success: function success(data) {
report(data);
},
error: function error() {
report(null);
}
});
}
}
function reset() {
if (urlLoader) {
urlLoader.abort();
urlLoader = null;
}
}
instance = {
load: load,
reset: reset
};
return instance;
}
XlinkLoader.__dashjs_factory_name = 'XlinkLoader';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__["default"].getClassFactory(XlinkLoader));
/***/ }),
/***/ "./src/streaming/constants/ConformanceViolationConstants.js":
/*!******************************************************************!*\
!*** ./src/streaming/constants/ConformanceViolationConstants.js ***!
\******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* harmony default export */ __webpack_exports__["default"] = ({
LEVELS: {
SUGGESTION: 'Suggestion',
WARNING: 'Warning',
ERROR: 'Error'
},
EVENTS: {
NO_UTC_TIMING_ELEMENT: {
key: 'NO_UTC_TIMING_ELEMENT',
message: 'No UTCTiming element is present in the manifest. You may experience playback failures. For a detailed validation use https://conformance.dashif.org/'
},
NON_COMPLIANT_SMPTE_IMAGE_ATTRIBUTE: {
key: 'NON_COMPLIANT_SMPTE_IMAGE_ATTRIBUTE',
message: 'SMPTE 2052-1:2013 defines the attribute name as "imageType" and does not define "imagetype"'
},
INVALID_DVR_WINDOW: {
key: 'INVALID_DVR_WINDOW',
message: 'No valid segment found when applying a specification compliant DVR window calculation. Using SegmentTimeline entries as a fallback.'
}
}
});
/***/ }),
/***/ "./src/streaming/constants/Constants.js":
/*!**********************************************!*\
!*** ./src/streaming/constants/Constants.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Constants declaration
* @class
* @ignore
* @hideconstructor
*/
var Constants = /*#__PURE__*/function () {
function Constants() {
_classCallCheck(this, Constants);
this.init();
}
_createClass(Constants, [{
key: "init",
value: function init() {
/**
* @constant {string} STREAM Stream media type. Mainly used to report metrics relative to the full stream
* @memberof Constants#
* @static
*/
this.STREAM = 'stream';
/**
* @constant {string} VIDEO Video media type
* @memberof Constants#
* @static
*/
this.VIDEO = 'video';
/**
* @constant {string} AUDIO Audio media type
* @memberof Constants#
* @static
*/
this.AUDIO = 'audio';
/**
* @constant {string} TEXT Text media type
* @memberof Constants#
* @static
*/
this.TEXT = 'text';
/**
* @constant {string} MUXED Muxed (video/audio in the same chunk) media type
* @memberof Constants#
* @static
*/
this.MUXED = 'muxed';
/**
* @constant {string} IMAGE Image media type
* @memberof Constants#
* @static
*/
this.IMAGE = 'image';
/**
* @constant {string} STPP STTP Subtitles format
* @memberof Constants#
* @static
*/
this.STPP = 'stpp';
/**
* @constant {string} TTML STTP Subtitles format
* @memberof Constants#
* @static
*/
this.TTML = 'ttml';
/**
* @constant {string} VTT STTP Subtitles format
* @memberof Constants#
* @static
*/
this.VTT = 'vtt';
/**
* @constant {string} WVTT STTP Subtitles format
* @memberof Constants#
* @static
*/
this.WVTT = 'wvtt';
/**
* @constant {string} ABR_STRATEGY_DYNAMIC Dynamic Adaptive bitrate algorithm
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_DYNAMIC = 'abrDynamic';
/**
* @constant {string} ABR_STRATEGY_BOLA Adaptive bitrate algorithm based on Bola (buffer level)
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_BOLA = 'abrBola';
/**
* @constant {string} ABR_STRATEGY_L2A Adaptive bitrate algorithm based on L2A (online learning)
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_L2A = 'abrL2A';
/**
* @constant {string} ABR_STRATEGY_LoLP Adaptive bitrate algorithm based on LoL+
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_LoLP = 'abrLoLP';
/**
* @constant {string} ABR_STRATEGY_THROUGHPUT Adaptive bitrate algorithm based on throughput
* @memberof Constants#
* @static
*/
this.ABR_STRATEGY_THROUGHPUT = 'abrThroughput';
/**
* @constant {string} ABR_FETCH_THROUGHPUT_CALUCUALTION_DOWNLOADED_DATA Throughput calculation based on downloaded data array
* @memberof Constants#
* @static
*/
this.ABR_FETCH_THROUGHPUT_CALCULATION_DOWNLOADED_DATA = 'abrFetchThroughputCalculationDownloadedData';
/**
* @constant {string} ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING Throughput calculation based on moof parsing
* @memberof Constants#
* @static
*/
this.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING = 'abrFetchThroughputCalculationMoofParsing';
/**
* @constant {string} ABR_FETCH_THROUGHPUT_CALCULATION_AAST Throughput calculation based on adjusted availability start time in low latency mode
* @memberof Constants#
* @static
*/
this.ABR_FETCH_THROUGHPUT_CALCULATION_AAST = 'abrFetchThroughputCalculationAAST';
/**
* @constant {string} LIVE_CATCHUP_MODE_DEFAULT Throughput calculation based on moof parsing
* @memberof Constants#
* @static
*/
this.LIVE_CATCHUP_MODE_DEFAULT = 'liveCatchupModeDefault';
/**
* @constant {string} LIVE_CATCHUP_MODE_LOLP Throughput calculation based on moof parsing
* @memberof Constants#
* @static
*/
this.LIVE_CATCHUP_MODE_LOLP = 'liveCatchupModeLoLP';
/**
* @constant {string} MOVING_AVERAGE_SLIDING_WINDOW Moving average sliding window
* @memberof Constants#
* @static
*/
this.MOVING_AVERAGE_SLIDING_WINDOW = 'slidingWindow';
/**
* @constant {string} EWMA Exponential moving average
* @memberof Constants#
* @static
*/
this.MOVING_AVERAGE_EWMA = 'ewma';
/**
* @constant {string} BAD_ARGUMENT_ERROR Invalid Arguments type of error
* @memberof Constants#
* @static
*/
this.BAD_ARGUMENT_ERROR = 'Invalid Arguments';
/**
* @constant {string} MISSING_CONFIG_ERROR Missing configuration parameters type of error
* @memberof Constants#
* @static
*/
this.MISSING_CONFIG_ERROR = 'Missing config parameter(s)';
/**
* @constant {string} TRACK_SWITCH_MODE_ALWAYS_REPLACE used to clear the buffered data (prior to current playback position) after track switch. Default for audio
* @memberof Constants#
* @static
*/
this.TRACK_SWITCH_MODE_ALWAYS_REPLACE = 'alwaysReplace';
/**
* @constant {string} TRACK_SWITCH_MODE_NEVER_REPLACE used to forbid clearing the buffered data (prior to current playback position) after track switch. Defers to fastSwitchEnabled for placement of new data. Default for video
* @memberof Constants#
* @static
*/
this.TRACK_SWITCH_MODE_NEVER_REPLACE = 'neverReplace';
/**
* @constant {string} TRACK_SELECTION_MODE_FIRST_TRACK makes the player select the first track found in the manifest.
* @memberof Constants#
* @static
*/
this.TRACK_SELECTION_MODE_FIRST_TRACK = 'firstTrack';
/**
* @constant {string} TRACK_SELECTION_MODE_HIGHEST_BITRATE makes the player select the track with a highest bitrate. This mode is a default mode.
* @memberof Constants#
* @static
*/
this.TRACK_SELECTION_MODE_HIGHEST_BITRATE = 'highestBitrate';
/**
* @constant {string} TRACK_SELECTION_MODE_HIGHEST_EFFICIENCY makes the player select the track with the lowest bitrate per pixel average.
* @memberof Constants#
* @static
*/
this.TRACK_SELECTION_MODE_HIGHEST_EFFICIENCY = 'highestEfficiency';
/**
* @constant {string} TRACK_SELECTION_MODE_WIDEST_RANGE makes the player select the track with a widest range of bitrates.
* @memberof Constants#
* @static
*/
this.TRACK_SELECTION_MODE_WIDEST_RANGE = 'widestRange';
/**
* @constant {string} TRACK_SELECTION_MODE_WIDEST_RANGE makes the player select the track with the highest selectionPriority as defined in the manifest
* @memberof Constants#
* @static
*/
this.TRACK_SELECTION_MODE_HIGHEST_SELECTION_PRIORITY = 'highestSelectionPriority';
/**
* @constant {string} CMCD_MODE_QUERY specifies to attach CMCD metrics as query parameters.
* @memberof Constants#
* @static
*/
this.CMCD_MODE_QUERY = 'query';
/**
* @constant {string} CMCD_MODE_HEADER specifies to attach CMCD metrics as HTTP headers.
* @memberof Constants#
* @static
*/
this.CMCD_MODE_HEADER = 'header';
this.LOCATION = 'Location';
this.INITIALIZE = 'initialize';
this.TEXT_SHOWING = 'showing';
this.TEXT_HIDDEN = 'hidden';
this.CC1 = 'CC1';
this.CC3 = 'CC3';
this.UTF8 = 'utf-8';
this.SCHEME_ID_URI = 'schemeIdUri';
this.START_TIME = 'starttime';
this.SERVICE_DESCRIPTION_LL_SCHEME = 'urn:dvb:dash:lowlatency:scope:2019';
this.SUPPLEMENTAL_PROPERTY_LL_SCHEME = 'urn:dvb:dash:lowlatency:critical:2019';
this.XML = 'XML';
this.ARRAY_BUFFER = 'ArrayBuffer';
this.DVB_REPORTING_URL = 'dvb:reportingUrl';
this.DVB_PROBABILITY = 'dvb:probability';
this.VIDEO_ELEMENT_READY_STATES = {
HAVE_NOTHING: 0,
HAVE_METADATA: 1,
HAVE_CURRENT_DATA: 2,
HAVE_FUTURE_DATA: 3,
HAVE_ENOUGH_DATA: 4
};
}
}]);
return Constants;
}();
var constants = new Constants();
/* harmony default export */ __webpack_exports__["default"] = (constants);
/***/ }),
/***/ "./src/streaming/constants/MetricsConstants.js":
/*!*****************************************************!*\
!*** ./src/streaming/constants/MetricsConstants.js ***!
\*****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Metrics Constants declaration
* @class
* @ignore
*/
var MetricsConstants = /*#__PURE__*/function () {
function MetricsConstants() {
_classCallCheck(this, MetricsConstants);
this.init();
}
_createClass(MetricsConstants, [{
key: "init",
value: function init() {
this.TCP_CONNECTION = 'TcpList';
this.HTTP_REQUEST = 'HttpList';
this.TRACK_SWITCH = 'RepSwitchList';
this.BUFFER_LEVEL = 'BufferLevel';
this.BUFFER_LOADED = 'bufferLoaded';
this.ABANDON_LOAD = 'abandonload';
this.ALLOW_LOAD = 'allowload';
this.BUFFER_EMPTY = 'bufferStalled';
this.BUFFER_STATE = 'BufferState';
this.DVR_INFO = 'DVRInfo';
this.DROPPED_FRAMES = 'DroppedFrames';
this.SCHEDULING_INFO = 'SchedulingInfo';
this.REQUESTS_QUEUE = 'RequestsQueue';
this.MANIFEST_UPDATE = 'ManifestUpdate';
this.MANIFEST_UPDATE_STREAM_INFO = 'ManifestUpdatePeriodInfo';
this.MANIFEST_UPDATE_TRACK_INFO = 'ManifestUpdateRepresentationInfo';
this.PLAY_LIST = 'PlayList';
this.DVB_ERRORS = 'DVBErrors';
}
}]);
return MetricsConstants;
}();
var constants = new MetricsConstants();
/* harmony default export */ __webpack_exports__["default"] = (constants);
/***/ }),
/***/ "./src/streaming/constants/ProtectionConstants.js":
/*!********************************************************!*\
!*** ./src/streaming/constants/ProtectionConstants.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Protection Constants declaration
* @class
* @ignore
*/
var ProtectionConstants = /*#__PURE__*/function () {
function ProtectionConstants() {
_classCallCheck(this, ProtectionConstants);
this.init();
}
_createClass(ProtectionConstants, [{
key: "init",
value: function init() {
this.CLEARKEY_KEYSTEM_STRING = 'org.w3.clearkey';
this.WIDEVINE_KEYSTEM_STRING = 'com.widevine.alpha';
this.PLAYREADY_KEYSTEM_STRING = 'com.microsoft.playready';
this.INITIALIZATION_DATA_TYPE_CENC = 'cenc';
this.INITIALIZATION_DATA_TYPE_KEYIDS = 'keyids';
this.INITIALIZATION_DATA_TYPE_WEBM = 'webm';
}
}]);
return ProtectionConstants;
}();
var constants = new ProtectionConstants();
/* harmony default export */ __webpack_exports__["default"] = (constants);
/***/ }),
/***/ "./src/streaming/controllers/AbrController.js":
/*!****************************************************!*\
!*** ./src/streaming/controllers/AbrController.js ***!
\****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../rules/abr/ABRRulesCollection */ "./src/streaming/rules/abr/ABRRulesCollection.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _vo_BitrateInfo__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../vo/BitrateInfo */ "./src/streaming/vo/BitrateInfo.js");
/* harmony import */ var _models_FragmentModel__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../models/FragmentModel */ "./src/streaming/models/FragmentModel.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _rules_RulesContext__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../rules/RulesContext */ "./src/streaming/rules/RulesContext.js");
/* harmony import */ var _rules_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../rules/SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _rules_SwitchRequestHistory__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../rules/SwitchRequestHistory */ "./src/streaming/rules/SwitchRequestHistory.js");
/* harmony import */ var _rules_DroppedFramesHistory__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../rules/DroppedFramesHistory */ "./src/streaming/rules/DroppedFramesHistory.js");
/* harmony import */ var _rules_ThroughputHistory__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../rules/ThroughputHistory */ "./src/streaming/rules/ThroughputHistory.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var DEFAULT_VIDEO_BITRATE = 1000;
var DEFAULT_AUDIO_BITRATE = 100;
var QUALITY_DEFAULT = 0;
function AbrController() {
var context = this.context;
var debug = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance();
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
var instance, logger, abrRulesCollection, streamController, topQualities, qualityDict, streamProcessorDict, abandonmentStateDict, abandonmentTimeout, windowResizeEventCalled, elementWidth, elementHeight, adapter, videoModel, mediaPlayerModel, domStorage, playbackIndex, switchHistoryDict, droppedFramesHistory, throughputHistory, isUsingBufferOccupancyAbrDict, isUsingL2AAbrDict, isUsingLoLPAbrDict, dashMetrics, settings;
function setup() {
logger = debug.getLogger(instance);
resetInitialSettings();
}
/**
* Initialize everything that is not Stream specific. We only have one instance of the ABR Controller for all periods.
*/
function initialize() {
droppedFramesHistory = Object(_rules_DroppedFramesHistory__WEBPACK_IMPORTED_MODULE_11__["default"])(context).create();
throughputHistory = Object(_rules_ThroughputHistory__WEBPACK_IMPORTED_MODULE_12__["default"])(context).create({
settings: settings
});
abrRulesCollection = Object(_rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
settings: settings
});
abrRulesCollection.initialize();
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_16__["default"].QUALITY_CHANGE_RENDERED, _onQualityChangeRendered, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_16__["default"].METRIC_ADDED, _onMetricAdded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].LOADING_PROGRESS, _onFragmentLoadProgress, instance);
}
/**
* Whenever a StreamProcessor is created it is added to the list of streamProcessorDict
* In addition, the corresponding objects for this object and its stream id are created
* @param {object} type
* @param {object} streamProcessor
*/
function registerStreamType(type, streamProcessor) {
var streamId = streamProcessor.getStreamInfo().id;
if (!streamProcessorDict[streamId]) {
streamProcessorDict[streamId] = {};
}
if (!switchHistoryDict[streamId]) {
switchHistoryDict[streamId] = {};
}
if (!abandonmentStateDict[streamId]) {
abandonmentStateDict[streamId] = {};
}
switchHistoryDict[streamId][type] = Object(_rules_SwitchRequestHistory__WEBPACK_IMPORTED_MODULE_10__["default"])(context).create();
streamProcessorDict[streamId][type] = streamProcessor;
abandonmentStateDict[streamId][type] = {};
abandonmentStateDict[streamId][type].state = _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].ALLOW_LOAD;
_initializeAbrStrategy(type);
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO) {
setElementSize();
}
}
function _initializeAbrStrategy(type) {
var strategy = settings.get().streaming.abr.ABRStrategy;
if (strategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].ABR_STRATEGY_L2A) {
isUsingBufferOccupancyAbrDict[type] = false;
isUsingLoLPAbrDict[type] = false;
isUsingL2AAbrDict[type] = true;
} else if (strategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].ABR_STRATEGY_LoLP) {
isUsingBufferOccupancyAbrDict[type] = false;
isUsingLoLPAbrDict[type] = true;
isUsingL2AAbrDict[type] = false;
} else if (strategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].ABR_STRATEGY_BOLA) {
isUsingBufferOccupancyAbrDict[type] = true;
isUsingLoLPAbrDict[type] = false;
isUsingL2AAbrDict[type] = false;
} else if (strategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].ABR_STRATEGY_THROUGHPUT) {
isUsingBufferOccupancyAbrDict[type] = false;
isUsingLoLPAbrDict[type] = false;
isUsingL2AAbrDict[type] = false;
} else if (strategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].ABR_STRATEGY_DYNAMIC) {
isUsingBufferOccupancyAbrDict[type] = isUsingBufferOccupancyAbrDict && isUsingBufferOccupancyAbrDict[type] ? isUsingBufferOccupancyAbrDict[type] : false;
isUsingLoLPAbrDict[type] = false;
isUsingL2AAbrDict[type] = false;
}
}
function unRegisterStreamType(streamId, type) {
try {
if (streamProcessorDict[streamId] && streamProcessorDict[streamId][type]) {
delete streamProcessorDict[streamId][type];
}
if (switchHistoryDict[streamId] && switchHistoryDict[streamId][type]) {
delete switchHistoryDict[streamId][type];
}
if (abandonmentStateDict[streamId] && abandonmentStateDict[streamId][type]) {
delete abandonmentStateDict[streamId][type];
}
} catch (e) {}
}
function resetInitialSettings() {
topQualities = {};
qualityDict = {};
abandonmentStateDict = {};
streamProcessorDict = {};
switchHistoryDict = {};
isUsingBufferOccupancyAbrDict = {};
isUsingL2AAbrDict = {};
isUsingLoLPAbrDict = {};
if (windowResizeEventCalled === undefined) {
windowResizeEventCalled = false;
}
if (droppedFramesHistory) {
droppedFramesHistory.reset();
}
playbackIndex = undefined;
droppedFramesHistory = undefined;
throughputHistory = undefined;
clearTimeout(abandonmentTimeout);
abandonmentTimeout = null;
}
function reset() {
resetInitialSettings();
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].LOADING_PROGRESS, _onFragmentLoadProgress, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_16__["default"].QUALITY_CHANGE_RENDERED, _onQualityChangeRendered, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_16__["default"].METRIC_ADDED, _onMetricAdded, instance);
if (abrRulesCollection) {
abrRulesCollection.reset();
}
}
function setConfig(config) {
if (!config) return;
if (config.streamController) {
streamController = config.streamController;
}
if (config.domStorage) {
domStorage = config.domStorage;
}
if (config.mediaPlayerModel) {
mediaPlayerModel = config.mediaPlayerModel;
}
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
if (config.adapter) {
adapter = config.adapter;
}
if (config.videoModel) {
videoModel = config.videoModel;
}
if (config.settings) {
settings = config.settings;
}
}
function checkConfig() {
if (!domStorage || !domStorage.hasOwnProperty('getSavedBitrateSettings')) {
throw new Error(_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].MISSING_CONFIG_ERROR);
}
}
/**
* While fragment loading is in progress we check if we might need to abort the request
* @param {object} e
* @private
*/
function _onFragmentLoadProgress(e) {
var type = e.request.mediaType;
var streamId = e.streamId;
if (!type || !streamId || !streamProcessorDict[streamId] || !settings.get().streaming.abr.autoSwitchBitrate[type]) {
return;
}
var streamProcessor = streamProcessorDict[streamId][type];
if (!streamProcessor) {
return;
}
var rulesContext = Object(_rules_RulesContext__WEBPACK_IMPORTED_MODULE_8__["default"])(context).create({
abrController: instance,
streamProcessor: streamProcessor,
currentRequest: e.request,
useBufferOccupancyABR: isUsingBufferOccupancyAbrDict[type],
useL2AABR: isUsingL2AAbrDict[type],
useLoLPABR: isUsingLoLPAbrDict[type],
videoModel: videoModel
});
var switchRequest = abrRulesCollection.shouldAbandonFragment(rulesContext, streamId);
if (switchRequest.quality > _rules_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE) {
var fragmentModel = streamProcessor.getFragmentModel();
var request = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_4__["default"].FRAGMENT_MODEL_LOADING,
index: e.request.index
})[0];
if (request) {
fragmentModel.abortRequests();
abandonmentStateDict[streamId][type].state = _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].ABANDON_LOAD;
switchHistoryDict[streamId][type].reset();
switchHistoryDict[streamId][type].push({
oldValue: getQualityFor(type, streamId),
newValue: switchRequest.quality,
confidence: 1,
reason: switchRequest.reason
});
setPlaybackQuality(type, streamController.getActiveStreamInfo(), switchRequest.quality, switchRequest.reason);
clearTimeout(abandonmentTimeout);
abandonmentTimeout = setTimeout(function () {
abandonmentStateDict[streamId][type].state = _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].ALLOW_LOAD;
abandonmentTimeout = null;
}, settings.get().streaming.abandonLoadTimeout);
}
}
}
/**
* Update dropped frames history when the quality was changed
* @param {object} e
* @private
*/
function _onQualityChangeRendered(e) {
if (e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO) {
if (playbackIndex !== undefined) {
droppedFramesHistory.push(e.streamId, playbackIndex, videoModel.getPlaybackQuality());
}
playbackIndex = e.newQuality;
}
}
/**
* When the buffer level is updated we check if we need to change the ABR strategy
* @param e
* @private
*/
function _onMetricAdded(e) {
if (e.metric === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].HTTP_REQUEST && e.value && e.value.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_14__["HTTPRequest"].MEDIA_SEGMENT_TYPE && (e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO || e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO)) {
throughputHistory.push(e.mediaType, e.value, settings.get().streaming.abr.useDeadTimeLatency);
}
if (e.metric === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].BUFFER_LEVEL && (e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO || e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO)) {
_updateAbrStrategy(e.mediaType, 0.001 * e.value.level);
}
}
/**
* Returns the highest possible index taking limitations like maxBitrate, representationRatio and portal size into account.
* @param {string} type
* @param {string} streamId
* @return {number}
*/
function getMaxAllowedIndexFor(type, streamId) {
try {
var idx;
topQualities[streamId] = topQualities[streamId] || {};
if (!topQualities[streamId].hasOwnProperty(type)) {
topQualities[streamId][type] = 0;
}
idx = _checkMaxBitrate(type, streamId);
idx = _checkMaxRepresentationRatio(idx, type, streamId);
idx = _checkPortalSize(idx, type, streamId);
return idx;
} catch (e) {
return undefined;
}
}
/**
* Returns the minimum allowed index. We consider thresholds defined in the settings, i.e. minBitrate for the corresponding media type.
* @param {string} type
* @param {string} streamId
* @return {undefined|number}
*/
function getMinAllowedIndexFor(type, streamId) {
try {
return _getMinIndexBasedOnBitrateFor(type, streamId);
} catch (e) {
return undefined;
}
}
/**
* Returns the maximum allowed index.
* @param {string} type
* @param {string} streamId
* @return {undefined|number}
*/
function _getMaxIndexBasedOnBitrateFor(type, streamId) {
try {
var maxBitrate = settings.get().streaming.abr.maxBitrate[type];
if (maxBitrate > -1) {
return getQualityForBitrate(streamProcessorDict[streamId][type].getMediaInfo(), maxBitrate, streamId);
} else {
return undefined;
}
} catch (e) {
return undefined;
}
}
/**
* Returns the minimum allowed index.
* @param {string} type
* @param {string} streamId
* @return {undefined|number}
*/
function _getMinIndexBasedOnBitrateFor(type, streamId) {
try {
var minBitrate = settings.get().streaming.abr.minBitrate[type];
if (minBitrate > -1) {
var mediaInfo = streamProcessorDict[streamId][type].getMediaInfo();
var bitrateList = getBitrateList(mediaInfo); // This returns the quality index <= for the given bitrate
var minIdx = getQualityForBitrate(mediaInfo, minBitrate, streamId);
if (bitrateList[minIdx] && minIdx < bitrateList.length - 1 && bitrateList[minIdx].bitrate < minBitrate * 1000) {
minIdx++; // Go to the next bitrate
}
return minIdx;
} else {
return undefined;
}
} catch (e) {
return undefined;
}
}
/**
* Returns the maximum possible index
* @param type
* @param streamId
* @return {number|*}
*/
function _checkMaxBitrate(type, streamId) {
var idx = topQualities[streamId][type];
var newIdx = idx;
if (!streamProcessorDict[streamId] || !streamProcessorDict[streamId][type]) {
return newIdx;
}
var minIdx = getMinAllowedIndexFor(type, streamId);
if (minIdx !== undefined) {
newIdx = Math.max(idx, minIdx);
}
var maxIdx = _getMaxIndexBasedOnBitrateFor(type, streamId);
if (maxIdx !== undefined) {
newIdx = Math.min(newIdx, maxIdx);
}
return newIdx;
}
/**
* Returns the maximum index according to maximum representation ratio
* @param idx
* @param type
* @param streamId
* @return {number|*}
* @private
*/
function _checkMaxRepresentationRatio(idx, type, streamId) {
var maxIdx = topQualities[streamId][type];
var maxRepresentationRatio = settings.get().streaming.abr.maxRepresentationRatio[type];
if (isNaN(maxRepresentationRatio) || maxRepresentationRatio >= 1 || maxRepresentationRatio < 0) {
return idx;
}
return Math.min(idx, Math.round(maxIdx * maxRepresentationRatio));
}
/**
* Returns the maximum index according to the portal size
* @param idx
* @param type
* @param streamId
* @return {number|*}
* @private
*/
function _checkPortalSize(idx, type, streamId) {
if (type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO || !settings.get().streaming.abr.limitBitrateByPortal || !streamProcessorDict[streamId] || !streamProcessorDict[streamId][type]) {
return idx;
}
if (!windowResizeEventCalled) {
setElementSize();
}
var streamInfo = streamProcessorDict[streamId][type].getStreamInfo();
var representation = adapter.getAdaptationForType(streamInfo.index, type, streamInfo).Representation;
var newIdx = idx;
if (elementWidth > 0 && elementHeight > 0) {
while (newIdx > 0 && representation[newIdx] && elementWidth < representation[newIdx].width && elementWidth - representation[newIdx - 1].width < representation[newIdx].width - elementWidth) {
newIdx = newIdx - 1;
} // Make sure that in case of multiple representation elements have same
// resolution, every such element is included
while (newIdx < representation.length - 1 && representation[newIdx].width === representation[newIdx + 1].width) {
newIdx = newIdx + 1;
}
}
return newIdx;
}
/**
* Gets top BitrateInfo for the player
* @param {string} type - 'video' or 'audio' are the type options.
* @param {string} streamId - Id of the stream
* @returns {BitrateInfo | null}
*/
function getTopBitrateInfoFor(type) {
var streamId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
if (!streamId) {
streamId = streamController.getActiveStreamInfo().id;
}
if (type && streamProcessorDict && streamProcessorDict[streamId] && streamProcessorDict[streamId][type]) {
var idx = getMaxAllowedIndexFor(type, streamId);
var bitrates = getBitrateList(streamProcessorDict[streamId][type].getMediaInfo());
return bitrates[idx] ? bitrates[idx] : null;
}
return null;
}
/**
* Returns the initial bitrate for a specific media type and stream id
* @param {string} type
* @param {string} streamId
* @returns {number} A value of the initial bitrate, kbps
* @memberof AbrController#
*/
function getInitialBitrateFor(type, streamId) {
checkConfig();
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].TEXT) {
return NaN;
}
var savedBitrate = domStorage.getSavedBitrateSettings(type);
var configBitrate = settings.get().streaming.abr.initialBitrate[type];
var configRatio = settings.get().streaming.abr.initialRepresentationRatio[type];
if (configBitrate === -1) {
if (configRatio > -1) {
var streamInfo = streamProcessorDict[streamId][type].getStreamInfo();
var representation = adapter.getAdaptationForType(streamInfo.index, type, streamInfo).Representation;
if (Array.isArray(representation)) {
var repIdx = Math.max(Math.round(representation.length * configRatio) - 1, 0);
configBitrate = representation[repIdx].bandwidth / 1000;
} else {
configBitrate = 0;
}
} else if (!isNaN(savedBitrate)) {
configBitrate = savedBitrate;
} else {
configBitrate = type === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO ? DEFAULT_VIDEO_BITRATE : DEFAULT_AUDIO_BITRATE;
}
}
return configBitrate;
}
/**
* This function is called by the scheduleControllers to check if the quality should be changed.
* Consider this the main entry point for the ABR decision logic
* @param {string} type
* @param {string} streamId
*/
function checkPlaybackQuality(type, streamId) {
try {
if (!type || !streamProcessorDict || !streamProcessorDict[streamId] || !streamProcessorDict[streamId][type]) {
return false;
}
if (droppedFramesHistory) {
var playbackQuality = videoModel.getPlaybackQuality();
if (playbackQuality) {
droppedFramesHistory.push(streamId, playbackIndex, playbackQuality);
}
} // ABR is turned off, do nothing
if (!settings.get().streaming.abr.autoSwitchBitrate[type]) {
return false;
}
var oldQuality = getQualityFor(type, streamId);
var rulesContext = Object(_rules_RulesContext__WEBPACK_IMPORTED_MODULE_8__["default"])(context).create({
abrController: instance,
switchHistory: switchHistoryDict[streamId][type],
droppedFramesHistory: droppedFramesHistory,
streamProcessor: streamProcessorDict[streamId][type],
currentValue: oldQuality,
useBufferOccupancyABR: isUsingBufferOccupancyAbrDict[type],
useL2AABR: isUsingL2AAbrDict[type],
useLoLPABR: isUsingLoLPAbrDict[type],
videoModel: videoModel
});
var minIdx = getMinAllowedIndexFor(type, streamId);
var maxIdx = getMaxAllowedIndexFor(type, streamId);
var switchRequest = abrRulesCollection.getMaxQuality(rulesContext);
var newQuality = switchRequest.quality;
if (minIdx !== undefined && (newQuality > _rules_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE ? newQuality : oldQuality) < minIdx) {
newQuality = minIdx;
}
if (newQuality > maxIdx) {
newQuality = maxIdx;
}
switchHistoryDict[streamId][type].push({
oldValue: oldQuality,
newValue: newQuality
});
if (newQuality > _rules_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE && newQuality !== oldQuality && (abandonmentStateDict[streamId][type].state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].ALLOW_LOAD || newQuality > oldQuality)) {
_changeQuality(type, oldQuality, newQuality, maxIdx, switchRequest.reason, streamId);
return true;
}
return false;
} catch (e) {
return false;
}
}
/**
* Returns the current quality for a specific media type and a specific streamId
* @param {string} type
* @param {string} streamId
* @return {number|*}
*/
function getQualityFor(type) {
var streamId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
try {
if (!streamId) {
streamId = streamController.getActiveStreamInfo().id;
}
if (type && streamProcessorDict[streamId] && streamProcessorDict[streamId][type]) {
var quality;
if (streamId) {
qualityDict[streamId] = qualityDict[streamId] || {};
if (!qualityDict[streamId].hasOwnProperty(type)) {
qualityDict[streamId][type] = QUALITY_DEFAULT;
}
quality = qualityDict[streamId][type];
return quality;
}
}
return QUALITY_DEFAULT;
} catch (e) {
return QUALITY_DEFAULT;
}
}
/**
* Sets the new playback quality. Starts from index 0.
* If the index of the new quality is the same as the old one changeQuality will not be called.
* @param {string} type
* @param {object} streamInfo
* @param {number} newQuality
* @param {string} reason
*/
function setPlaybackQuality(type, streamInfo, newQuality) {
var reason = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
if (!streamInfo || !streamInfo.id || !type) {
return;
}
var streamId = streamInfo.id;
var oldQuality = getQualityFor(type, streamId);
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_15__["checkInteger"])(newQuality);
var topQualityIdx = getMaxAllowedIndexFor(type, streamId);
if (newQuality !== oldQuality && newQuality >= 0 && newQuality <= topQualityIdx) {
_changeQuality(type, oldQuality, newQuality, topQualityIdx, reason, streamId);
}
}
/**
*
* @param {string} streamId
* @param {type} type
* @return {*|null}
*/
function getAbandonmentStateFor(streamId, type) {
return abandonmentStateDict[streamId] && abandonmentStateDict[streamId][type] ? abandonmentStateDict[streamId][type].state : null;
}
/**
* Changes the internal qualityDict values according to the new quality
* @param {string} type
* @param {number} oldQuality
* @param {number} newQuality
* @param {number} maxIdx
* @param {string} reason
* @param {object} streamId
* @private
*/
function _changeQuality(type, oldQuality, newQuality, maxIdx, reason, streamId) {
if (type && streamProcessorDict[streamId] && streamProcessorDict[streamId][type]) {
var streamInfo = streamProcessorDict[streamId][type].getStreamInfo();
var isDynamic = streamInfo && streamInfo.manifestInfo && streamInfo.manifestInfo.isDynamic;
var bufferLevel = dashMetrics.getCurrentBufferLevel(type);
logger.info('Stream ID: ' + streamId + ' [' + type + '] switch from ' + oldQuality + ' to ' + newQuality + '/' + maxIdx + ' (buffer: ' + bufferLevel + ') ' + (reason ? JSON.stringify(reason) : '.'));
qualityDict[streamId] = qualityDict[streamId] || {};
qualityDict[streamId][type] = newQuality;
var bitrateInfo = _getBitrateInfoForQuality(streamId, type, newQuality);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].QUALITY_CHANGE_REQUESTED, {
oldQuality: oldQuality,
newQuality: newQuality,
reason: reason,
streamInfo: streamInfo,
bitrateInfo: bitrateInfo,
maxIdx: maxIdx,
mediaType: type
}, {
streamId: streamInfo.id,
mediaType: type
});
var bitrate = throughputHistory.getAverageThroughput(type, isDynamic);
if (!isNaN(bitrate)) {
domStorage.setSavedBitrateSettings(type, bitrate);
}
}
}
function _getBitrateInfoForQuality(streamId, type, idx) {
if (type && streamProcessorDict && streamProcessorDict[streamId] && streamProcessorDict[streamId][type]) {
var bitrates = getBitrateList(streamProcessorDict[streamId][type].getMediaInfo());
return bitrates[idx] ? bitrates[idx] : null;
}
return null;
}
/**
* @param {MediaInfo} mediaInfo
* @param {number} bitrate A bitrate value, kbps
* @param {String} streamId Period ID
* @param {number|null} latency Expected latency of connection, ms
* @returns {number} A quality index <= for the given bitrate
* @memberof AbrController#
*/
function getQualityForBitrate(mediaInfo, bitrate, streamId) {
var latency = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var voRepresentation = mediaInfo && mediaInfo.type ? streamProcessorDict[streamId][mediaInfo.type].getRepresentationInfo() : null;
if (settings.get().streaming.abr.useDeadTimeLatency && latency && voRepresentation && voRepresentation.fragmentDuration) {
latency = latency / 1000;
var fragmentDuration = voRepresentation.fragmentDuration;
if (latency > fragmentDuration) {
return 0;
} else {
var deadTimeRatio = latency / fragmentDuration;
bitrate = bitrate * (1 - deadTimeRatio);
}
}
var bitrateList = getBitrateList(mediaInfo);
for (var i = bitrateList.length - 1; i >= 0; i--) {
var bitrateInfo = bitrateList[i];
if (bitrate * 1000 >= bitrateInfo.bitrate) {
return i;
}
}
return QUALITY_DEFAULT;
}
/**
* @param {MediaInfo} mediaInfo
* @returns {Array|null} A list of {@link BitrateInfo} objects
* @memberof AbrController#
*/
function getBitrateList(mediaInfo) {
var infoList = [];
if (!mediaInfo || !mediaInfo.bitrateList) return infoList;
var bitrateList = mediaInfo.bitrateList;
var type = mediaInfo.type;
var bitrateInfo;
for (var i = 0, ln = bitrateList.length; i < ln; i++) {
bitrateInfo = new _vo_BitrateInfo__WEBPACK_IMPORTED_MODULE_3__["default"]();
bitrateInfo.mediaType = type;
bitrateInfo.qualityIndex = i;
bitrateInfo.bitrate = bitrateList[i].bandwidth;
bitrateInfo.width = bitrateList[i].width;
bitrateInfo.height = bitrateList[i].height;
bitrateInfo.scanType = bitrateList[i].scanType;
infoList.push(bitrateInfo);
}
return infoList;
}
function _updateAbrStrategy(mediaType, bufferLevel) {
// else ABR_STRATEGY_DYNAMIC
var strategy = settings.get().streaming.abr.ABRStrategy;
if (strategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].ABR_STRATEGY_DYNAMIC) {
_updateDynamicAbrStrategy(mediaType, bufferLevel);
}
}
function _updateDynamicAbrStrategy(mediaType, bufferLevel) {
var stableBufferTime = mediaPlayerModel.getStableBufferTime();
var switchOnThreshold = stableBufferTime;
var switchOffThreshold = 0.5 * stableBufferTime;
var useBufferABR = isUsingBufferOccupancyAbrDict[mediaType];
var newUseBufferABR = bufferLevel > (useBufferABR ? switchOffThreshold : switchOnThreshold); // use hysteresis to avoid oscillating rules
isUsingBufferOccupancyAbrDict[mediaType] = newUseBufferABR;
if (newUseBufferABR !== useBufferABR) {
if (newUseBufferABR) {
logger.info('[' + mediaType + '] switching from throughput to buffer occupancy ABR rule (buffer: ' + bufferLevel.toFixed(3) + ').');
} else {
logger.info('[' + mediaType + '] switching from buffer occupancy to throughput ABR rule (buffer: ' + bufferLevel.toFixed(3) + ').');
}
}
}
function getThroughputHistory() {
return throughputHistory;
}
function updateTopQualityIndex(mediaInfo) {
var type = mediaInfo.type;
var streamId = mediaInfo.streamInfo.id;
var max = mediaInfo.representationCount - 1;
topQualities[streamId] = topQualities[streamId] || {};
topQualities[streamId][type] = max;
return max;
}
function isPlayingAtTopQuality(streamInfo) {
var streamId = streamInfo ? streamInfo.id : null;
var audioQuality = getQualityFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO, streamId);
var videoQuality = getQualityFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO, streamId);
var isAtTop = audioQuality === getMaxAllowedIndexFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIO, streamId) && videoQuality === getMaxAllowedIndexFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].VIDEO, streamId);
return isAtTop;
}
function setWindowResizeEventCalled(value) {
windowResizeEventCalled = value;
}
function setElementSize() {
if (videoModel) {
var hasPixelRatio = settings.get().streaming.abr.usePixelRatioInLimitBitrateByPortal && window.hasOwnProperty('devicePixelRatio');
var pixelRatio = hasPixelRatio ? window.devicePixelRatio : 1;
elementWidth = videoModel.getClientWidth() * pixelRatio;
elementHeight = videoModel.getClientHeight() * pixelRatio;
}
}
function clearDataForStream(streamId) {
if (droppedFramesHistory) {
droppedFramesHistory.clearForStream(streamId);
}
if (streamProcessorDict[streamId]) {
delete streamProcessorDict[streamId];
}
if (switchHistoryDict[streamId]) {
delete switchHistoryDict[streamId];
}
if (abandonmentStateDict[streamId]) {
delete abandonmentStateDict[streamId];
}
}
instance = {
initialize: initialize,
isPlayingAtTopQuality: isPlayingAtTopQuality,
updateTopQualityIndex: updateTopQualityIndex,
clearDataForStream: clearDataForStream,
getThroughputHistory: getThroughputHistory,
getBitrateList: getBitrateList,
getQualityForBitrate: getQualityForBitrate,
getTopBitrateInfoFor: getTopBitrateInfoFor,
getMinAllowedIndexFor: getMinAllowedIndexFor,
getMaxAllowedIndexFor: getMaxAllowedIndexFor,
getInitialBitrateFor: getInitialBitrateFor,
getQualityFor: getQualityFor,
getAbandonmentStateFor: getAbandonmentStateFor,
setPlaybackQuality: setPlaybackQuality,
checkPlaybackQuality: checkPlaybackQuality,
setElementSize: setElementSize,
setWindowResizeEventCalled: setWindowResizeEventCalled,
registerStreamType: registerStreamType,
unRegisterStreamType: unRegisterStreamType,
setConfig: setConfig,
reset: reset
};
setup();
return instance;
}
AbrController.__dashjs_factory_name = 'AbrController';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_7__["default"].getSingletonFactory(AbrController);
factory.QUALITY_DEFAULT = QUALITY_DEFAULT;
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_7__["default"].updateSingletonFactory(AbrController.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/controllers/BaseURLController.js":
/*!********************************************************!*\
!*** ./src/streaming/controllers/BaseURLController.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _models_BaseURLTreeModel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../models/BaseURLTreeModel */ "./src/streaming/models/BaseURLTreeModel.js");
/* harmony import */ var _utils_BaseURLSelector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/BaseURLSelector */ "./src/streaming/utils/BaseURLSelector.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _dash_vo_BaseURL__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../dash/vo/BaseURL */ "./src/dash/vo/BaseURL.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function BaseURLController() {
var instance, adapter;
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
var urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
var baseURLTreeModel, baseURLSelector;
function onBlackListChanged(e) {
baseURLTreeModel.invalidateSelectedIndexes(e.entry);
}
function setup() {
baseURLTreeModel = Object(_models_BaseURLTreeModel__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create();
baseURLSelector = Object(_utils_BaseURLSelector__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SERVICE_LOCATION_BLACKLIST_CHANGED, onBlackListChanged, instance);
}
function setConfig(config) {
if (config.baseURLTreeModel) {
baseURLTreeModel = config.baseURLTreeModel;
}
if (config.baseURLSelector) {
baseURLSelector = config.baseURLSelector;
}
if (config.adapter) {
adapter = config.adapter;
}
}
function update(manifest) {
baseURLTreeModel.update(manifest);
baseURLSelector.chooseSelector(adapter.getIsDVB(manifest));
}
function resolve(path) {
var baseUrls = baseURLTreeModel.getForPath(path);
var baseUrl = baseUrls.reduce(function (p, c) {
var b = baseURLSelector.select(c);
if (b) {
if (!urlUtils.isRelative(b.url)) {
p.url = b.url;
p.serviceLocation = b.serviceLocation;
} else {
p.url = urlUtils.resolve(b.url, p.url);
}
p.availabilityTimeOffset = b.availabilityTimeOffset;
p.availabilityTimeComplete = b.availabilityTimeComplete;
} else {
return new _dash_vo_BaseURL__WEBPACK_IMPORTED_MODULE_3__["default"]();
}
return p;
}, new _dash_vo_BaseURL__WEBPACK_IMPORTED_MODULE_3__["default"]());
if (!urlUtils.isRelative(baseUrl.url)) {
return baseUrl;
}
}
function reset() {
baseURLTreeModel.reset();
baseURLSelector.reset();
}
function initialize(data) {
// report config to baseURLTreeModel and baseURLSelector
baseURLTreeModel.setConfig({
adapter: adapter
});
update(data);
}
instance = {
reset: reset,
initialize: initialize,
resolve: resolve,
setConfig: setConfig
};
setup();
return instance;
}
BaseURLController.__dashjs_factory_name = 'BaseURLController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__["default"].getClassFactory(BaseURLController));
/***/ }),
/***/ "./src/streaming/controllers/BlacklistController.js":
/*!**********************************************************!*\
!*** ./src/streaming/controllers/BlacklistController.js ***!
\**********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function BlackListController(config) {
config = config || {};
var instance;
var blacklist = [];
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(this.context).getInstance();
var updateEventName = config.updateEventName;
var addBlacklistEventName = config.addBlacklistEventName;
function contains(query) {
if (!blacklist.length || !query || !query.length) {
return false;
}
return blacklist.indexOf(query) !== -1;
}
function add(entry) {
if (blacklist.indexOf(entry) !== -1) {
return;
}
blacklist.push(entry);
eventBus.trigger(updateEventName, {
entry: entry
});
}
function onAddBlackList(e) {
add(e.entry);
}
function setup() {
if (addBlacklistEventName) {
eventBus.on(addBlacklistEventName, onAddBlackList, instance);
}
}
function reset() {
blacklist = [];
}
instance = {
add: add,
contains: contains,
reset: reset
};
setup();
return instance;
}
BlackListController.__dashjs_factory_name = 'BlackListController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(BlackListController));
/***/ }),
/***/ "./src/streaming/controllers/BufferController.js":
/*!*******************************************************!*\
!*** ./src/streaming/controllers/BufferController.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../models/FragmentModel */ "./src/streaming/models/FragmentModel.js");
/* harmony import */ var _SourceBufferSink__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../SourceBufferSink */ "./src/streaming/SourceBufferSink.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _utils_InitCache__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../utils/InitCache */ "./src/streaming/utils/InitCache.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var BUFFER_END_THRESHOLD = 0.5;
var BUFFER_RANGE_CALCULATION_THRESHOLD = 0.01;
var QUOTA_EXCEEDED_ERROR_CODE = 22;
var BUFFER_CONTROLLER_TYPE = 'BufferController';
function BufferController(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var errHandler = config.errHandler;
var fragmentModel = config.fragmentModel;
var representationController = config.representationController;
var adapter = config.adapter;
var textController = config.textController;
var abrController = config.abrController;
var playbackController = config.playbackController;
var streamInfo = config.streamInfo;
var type = config.type;
var settings = config.settings;
var instance, logger, isBufferingCompleted, bufferLevel, criticalBufferLevel, mediaSource, maxAppendedIndex, maximumIndex, sourceBufferSink, bufferState, appendedBytesInfo, wallclockTicked, isPruningInProgress, isQuotaExceeded, initCache, pendingPruningRanges, replacingBuffer, seekTarget;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance().getLogger(instance);
initCache = Object(_utils_InitCache__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
resetInitialSettings();
}
/**
* Initialize the BufferController. Sets the media source and registers the event handlers.
* @param {object} mediaSource
*/
function initialize(mediaSource) {
setMediaSource(mediaSource);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].WALLCLOCK_TIME_UPDATED, _onWallclockTimeUpdated, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_PLAYING, _onPlaybackPlaying, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_STALLED, _onPlaybackStalled, instance);
}
/**
* Returns the stream id
* @return {string}
*/
function getStreamId() {
return streamInfo.id;
}
/**
* Returns the media type
* @return {type}
*/
function getType() {
return type;
}
/**
* Returns the type of the BufferController. We distinguish between standard buffer controllers and buffer controllers related to texttracks.
* @return {string}
*/
function getBufferControllerType() {
return BUFFER_CONTROLLER_TYPE;
}
/**
* Sets the mediasource.
* @param {object} value
*/
function setMediaSource(value) {
mediaSource = value;
}
/**
* Get the RepresentationInfo for a certain quality.
* @param {number} quality
* @return {object}
* @private
*/
function _getRepresentationInfo(quality) {
return adapter.convertRepresentationToRepresentationInfo(representationController.getRepresentationForQuality(quality));
}
/**
* Creates a SourceBufferSink object
* @param {object} mediaInfo
* @param {array} oldBufferSinks
* @return {object|null} SourceBufferSink
*/
function createBufferSink(mediaInfo) {
var oldBufferSinks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return new Promise(function (resolve, reject) {
if (!initCache || !mediaInfo || !mediaSource) {
resolve(null);
return;
}
var requiredQuality = abrController.getQualityFor(type, streamInfo.id);
sourceBufferSink = Object(_SourceBufferSink__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
mediaSource: mediaSource,
textController: textController,
eventBus: eventBus
});
_initializeSink(mediaInfo, oldBufferSinks, requiredQuality).then(function () {
return updateBufferTimestampOffset(_getRepresentationInfo(requiredQuality));
}).then(function () {
resolve(sourceBufferSink);
})["catch"](function (e) {
logger.fatal('Caught error on create SourceBuffer: ' + e);
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_9__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_10__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_MESSAGE + type));
reject(e);
});
});
}
function _initializeSink(mediaInfo, oldBufferSinks, requiredQuality) {
var selectedRepresentation = _getRepresentationInfo(requiredQuality);
if (oldBufferSinks && oldBufferSinks[type] && (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO)) {
return sourceBufferSink.initializeForStreamSwitch(mediaInfo, selectedRepresentation, oldBufferSinks[type]);
} else {
return sourceBufferSink.initializeForFirstUse(streamInfo, mediaInfo, selectedRepresentation);
}
}
/**
* Callback handler when init segment has been loaded. Based on settings, the init segment is saved to the cache, and appended to the buffer.
* @param {object} e
* @private
*/
function _onInitFragmentLoaded(e) {
if (settings.get().streaming.cacheInitSegments) {
logger.info('Init fragment finished loading saving to', type + '\'s init cache');
initCache.save(e.chunk);
}
logger.debug('Append Init fragment', type, ' with representationId:', e.chunk.representationId, ' and quality:', e.chunk.quality, ', data size:', e.chunk.bytes.byteLength);
_appendToBuffer(e.chunk);
}
/**
* Append the init segment for a certain representation to the buffer. If the init segment is cached we take the one from the cache. Otherwise the function returns false and the segment has to be requested again.
* @param {string} representationId
* @return {boolean}
*/
function appendInitSegmentFromCache(representationId) {
// Get init segment from cache
var chunk = initCache.extract(streamInfo.id, representationId);
if (!chunk) {
// Init segment not in cache, shall be requested
return false;
} // Append init segment into buffer
logger.info('Append Init fragment', type, ' with representationId:', chunk.representationId, ' and quality:', chunk.quality, ', data size:', chunk.bytes.byteLength);
_appendToBuffer(chunk);
return true;
}
/**
* Calls the _appendToBuffer function to append the segment to the buffer. In case of a track switch the buffer might be cleared.
* @param {object} e
*/
function _onMediaFragmentLoaded(e) {
_appendToBuffer(e.chunk, e.request);
}
/**
* Append data to the MSE buffer using the SourceBufferSink
* @param {object} chunk
* @private
*/
function _appendToBuffer(chunk) {
var request = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
sourceBufferSink.append(chunk, request).then(function (e) {
_onAppended(e);
})["catch"](function (e) {
_onAppended(e);
});
if (chunk.mediaInfo.type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) {
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].VIDEO_CHUNK_RECEIVED, {
chunk: chunk
});
}
}
function _showBufferRanges(ranges) {
if (ranges && ranges.length > 0) {
for (var i = 0, len = ranges.length; i < len; i++) {
logger.debug('Buffered range: ' + ranges.start(i) + ' - ' + ranges.end(i) + ', currentTime = ', playbackController.getTime());
}
}
}
function _onAppended(e) {
if (e.error) {
// If we receive a QUOTA_EXCEEDED_ERROR_CODE we should adjust the target buffer times to avoid this error in the future.
if (e.error.code === QUOTA_EXCEEDED_ERROR_CODE) {
_handleQuotaExceededError();
}
if (e.error.code === QUOTA_EXCEEDED_ERROR_CODE || !hasEnoughSpaceToAppend()) {
logger.warn('Clearing playback buffer to overcome quota exceed situation'); // Notify ScheduleController to stop scheduling until buffer has been pruned
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].QUOTA_EXCEEDED, {
criticalBufferLevel: criticalBufferLevel,
quotaExceededTime: e.chunk.start
});
clearBuffers(getClearRanges());
}
return;
} // Check if session has not been stopped in the meantime (while last segment was being appended)
if (!sourceBufferSink) return;
_updateBufferLevel();
isQuotaExceeded = false;
appendedBytesInfo = e.chunk;
if (!appendedBytesInfo || !appendedBytesInfo.endFragment) {
return;
}
if (appendedBytesInfo && !isNaN(appendedBytesInfo.index)) {
maxAppendedIndex = Math.max(appendedBytesInfo.index, maxAppendedIndex);
_checkIfBufferingCompleted();
}
var ranges = sourceBufferSink.getAllBufferRanges();
if (appendedBytesInfo.segmentType === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_11__["HTTPRequest"].MEDIA_SEGMENT_TYPE) {
_showBufferRanges(ranges);
_onPlaybackProgression();
_adjustSeekTarget();
}
if (appendedBytesInfo) {
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BYTES_APPENDED_END_FRAGMENT, {
quality: appendedBytesInfo.quality,
startTime: appendedBytesInfo.start,
index: appendedBytesInfo.index,
bufferedRanges: ranges,
segmentType: appendedBytesInfo.segmentType,
mediaType: type
});
}
}
/**
* In some cases the segment we requested might start at a different time than we initially aimed for. segments timeline/template tolerance.
* We might need to do an internal seek if there is drift.
* @private
*/
function _adjustSeekTarget() {
if (isNaN(seekTarget)) return; // Check buffered data only for audio and video
if (type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) {
seekTarget = NaN;
return;
} // Check if current buffered range already contains seek target (and current video element time)
var currentTime = playbackController.getTime();
var range = getRangeAt(seekTarget, 0);
if (currentTime === seekTarget && range) {
seekTarget = NaN;
return;
} // Get buffered range corresponding to the seek target
var segmentDuration = representationController.getCurrentRepresentation().segmentDuration;
range = getRangeAt(seekTarget, segmentDuration);
if (!range) return;
if (settings.get().streaming.buffer.enableSeekDecorrelationFix && Math.abs(currentTime - seekTarget) > segmentDuration) {
// If current video model time is decorrelated from seek target (and appended buffer) then seek video element
// (in case of live streams on some browsers/devices for which we can't set video element time at unavalaible range)
// Check if appended segment is not anterior from seek target (segments timeline/template tolerance)
if (seekTarget <= range.end) {
// Seek video element to seek target or range start if appended buffer starts after seek target (segments timeline/template tolerance)
playbackController.seek(Math.max(seekTarget, range.start), false, true);
seekTarget = NaN;
}
} else if (currentTime < range.start) {
// If appended buffer starts after seek target (segments timeline/template tolerance) then seek to range start
playbackController.seek(range.start, false, true);
seekTarget = NaN;
}
}
function _handleQuotaExceededError() {
isQuotaExceeded = true;
criticalBufferLevel = getTotalBufferedTime() * 0.8;
logger.warn('Quota exceeded, Critical Buffer: ' + criticalBufferLevel);
if (criticalBufferLevel > 0) {
// recalculate buffer lengths according to criticalBufferLevel
var bufferToKeep = Math.max(0.2 * criticalBufferLevel, 1);
var bufferAhead = criticalBufferLevel - bufferToKeep;
var bufferTimeAtTopQuality = Math.min(settings.get().streaming.buffer.bufferTimeAtTopQuality, bufferAhead * 0.9);
var bufferTimeAtTopQualityLongForm = Math.min(settings.get().streaming.buffer.bufferTimeAtTopQualityLongForm, bufferAhead * 0.9);
var s = {
streaming: {
buffer: {
bufferToKeep: parseFloat(bufferToKeep.toFixed(5)),
bufferTimeAtTopQuality: parseFloat(bufferTimeAtTopQuality.toFixed(5)),
bufferTimeAtTopQualityLongForm: parseFloat(bufferTimeAtTopQualityLongForm.toFixed(5))
}
}
};
settings.update(s);
}
} //**********************************************************************
// START Buffer Level, State & Sufficiency Handling.
//**********************************************************************
function prepareForPlaybackSeek() {
if (isBufferingCompleted) {
setIsBufferingCompleted(false);
} // Abort the current request and empty all possible segments to be appended
return sourceBufferSink.abort();
}
function prepareForReplacementTrackSwitch(codec) {
return new Promise(function (resolve, reject) {
sourceBufferSink.abort().then(function () {
return updateAppendWindow();
}).then(function () {
return sourceBufferSink.changeType(codec);
}).then(function () {
return pruneAllSafely();
}).then(function () {
setIsBufferingCompleted(false);
resolve();
})["catch"](function (e) {
reject(e);
});
});
}
function prepareForReplacementQualitySwitch() {
return new Promise(function (resolve, reject) {
sourceBufferSink.abort().then(function () {
return updateAppendWindow();
}).then(function () {
return pruneAllSafely();
}).then(function () {
setIsBufferingCompleted(false);
resolve();
})["catch"](function (e) {
reject(e);
});
});
}
function prepareForNonReplacementTrackSwitch(codec) {
return new Promise(function (resolve, reject) {
updateAppendWindow().then(function () {
return sourceBufferSink.changeType(codec);
}).then(function () {
resolve();
})["catch"](function (e) {
reject(e);
});
});
}
function pruneAllSafely() {
return new Promise(function (resolve, reject) {
var ranges = getAllRangesWithSafetyFactor();
if (!ranges || ranges.length === 0) {
_onPlaybackProgression();
resolve();
return;
}
clearBuffers(ranges).then(function () {
resolve();
})["catch"](function (e) {
reject(e);
});
});
}
function getAllRangesWithSafetyFactor(seekTime) {
var clearRanges = [];
var ranges = sourceBufferSink.getAllBufferRanges(); // no valid ranges
if (!ranges || ranges.length === 0) {
return clearRanges;
} // if no target time is provided we clear everyhing
if (!seekTime && seekTime !== 0 || isNaN(seekTime)) {
clearRanges.push({
start: ranges.start(0),
end: ranges.end(ranges.length - 1) + BUFFER_END_THRESHOLD
});
} // otherwise we need to calculate the correct pruning range
else {
var behindPruningRange = _getRangeBehindForPruning(seekTime, ranges);
var aheadPruningRange = _getRangeAheadForPruning(seekTime, ranges);
if (behindPruningRange) {
clearRanges.push(behindPruningRange);
}
if (aheadPruningRange) {
clearRanges.push(aheadPruningRange);
}
}
return clearRanges;
}
function _getRangeBehindForPruning(targetTime, ranges) {
var bufferToKeepBehind = settings.get().streaming.buffer.bufferToKeep;
var startOfBuffer = ranges.start(0); // if we do a seek ahead of the current play position we do need to prune behind the new play position
var behindDiff = targetTime - startOfBuffer;
if (behindDiff > bufferToKeepBehind) {
var rangeEnd = Math.max(0, targetTime - bufferToKeepBehind); // Ensure we keep full range of current fragment
var currentTimeRequest = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__["default"].FRAGMENT_MODEL_EXECUTED,
time: targetTime,
threshold: BUFFER_RANGE_CALCULATION_THRESHOLD
})[0];
if (currentTimeRequest) {
rangeEnd = Math.min(currentTimeRequest.startTime, rangeEnd);
}
if (rangeEnd > 0) {
return {
start: startOfBuffer,
end: rangeEnd
};
}
}
return null;
}
function _getRangeAheadForPruning(targetTime, ranges) {
// if we do a seek behind the current play position we do need to prune ahead of the new play position
var endOfBuffer = ranges.end(ranges.length - 1) + BUFFER_END_THRESHOLD;
var isLongFormContent = streamInfo.manifestInfo.duration >= settings.get().streaming.buffer.longFormContentDurationThreshold;
var bufferToKeepAhead = isLongFormContent ? settings.get().streaming.buffer.bufferTimeAtTopQualityLongForm : settings.get().streaming.buffer.bufferTimeAtTopQuality;
var aheadDiff = endOfBuffer - targetTime;
if (aheadDiff > bufferToKeepAhead) {
var rangeStart = targetTime + bufferToKeepAhead; // Ensure we keep full range of current fragment
var currentTimeRequest = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__["default"].FRAGMENT_MODEL_EXECUTED,
time: targetTime,
threshold: BUFFER_RANGE_CALCULATION_THRESHOLD
})[0];
if (currentTimeRequest) {
rangeStart = Math.max(currentTimeRequest.startTime + currentTimeRequest.duration, rangeStart);
}
if (rangeStart < endOfBuffer) {
return {
start: rangeStart,
end: endOfBuffer
};
}
}
return null;
}
function _onPlaybackProgression() {
if (!replacingBuffer || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && textController.isTextEnabled()) {
_updateBufferLevel();
}
}
function _onPlaybackStalled() {
checkIfSufficientBuffer();
}
function _onPlaybackPlaying() {
checkIfSufficientBuffer();
seekTarget = NaN;
}
function getRangeAt(time, tolerance) {
var ranges = sourceBufferSink.getAllBufferRanges();
var start = 0;
var end = 0;
var firstStart = null;
var lastEnd = null;
var gap = 0;
var len, i;
var toler = !isNaN(tolerance) ? tolerance : 0.15;
if (ranges !== null && ranges !== undefined) {
for (i = 0, len = ranges.length; i < len; i++) {
start = ranges.start(i);
end = ranges.end(i);
if (firstStart === null) {
gap = Math.abs(start - time);
if (time >= start && time < end) {
// start the range
firstStart = start;
lastEnd = end;
} else if (gap <= toler) {
// start the range even though the buffer does not contain time 0
firstStart = start;
lastEnd = end;
}
} else {
gap = start - lastEnd;
if (gap <= toler) {
// the discontinuity is smaller than the tolerance, combine the ranges
lastEnd = end;
} else {
break;
}
}
}
if (firstStart !== null) {
return {
start: firstStart,
end: lastEnd
};
}
}
return null;
}
function getBufferLength(time, tolerance) {
var range, length; // Consider gap/discontinuity limit as tolerance
if (settings.get().streaming.gaps.jumpGaps) {
tolerance = settings.get().streaming.gaps.smallGapLimit;
}
range = getRangeAt(time, tolerance);
if (range === null) {
length = 0;
} else {
length = range.end - time;
}
return length;
}
function _updateBufferLevel() {
if (playbackController) {
var tolerance = settings.get().streaming.gaps.jumpGaps && !isNaN(settings.get().streaming.gaps.smallGapLimit) ? settings.get().streaming.gaps.smallGapLimit : NaN;
bufferLevel = Math.max(getBufferLength(playbackController.getTime() || 0, tolerance), 0);
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_LEVEL_UPDATED, {
mediaType: type,
bufferLevel: bufferLevel
});
checkIfSufficientBuffer();
}
}
function _checkIfBufferingCompleted() {
var isLastIdxAppended = maxAppendedIndex >= maximumIndex - 1; // Handles 0 and non 0 based request index
var periodBuffered = playbackController.getTimeToStreamEnd(streamInfo) - bufferLevel <= 0;
if ((isLastIdxAppended || periodBuffered) && !isBufferingCompleted) {
setIsBufferingCompleted(true);
logger.debug("checkIfBufferingCompleted trigger BUFFERING_COMPLETED for stream id ".concat(streamInfo.id, " and type ").concat(type));
}
}
function checkIfSufficientBuffer() {
// No need to check buffer if type is not audio or video (for example if several errors occur during text parsing, so that the buffer cannot be filled, no error must occur on video playback)
if (type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) return; // When the player is working in low latency mode, the buffer is often below STALL_THRESHOLD.
// So, when in low latency mode, change dash.js behavior so it notifies a stall just when
// buffer reach 0 seconds
if ((!settings.get().streaming.lowLatencyEnabled && bufferLevel < settings.get().streaming.buffer.stallThreshold || bufferLevel === 0) && !isBufferingCompleted) {
_notifyBufferStateChanged(_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_EMPTY);
} else {
if (isBufferingCompleted || bufferLevel >= settings.get().streaming.buffer.stallThreshold || settings.get().streaming.lowLatencyEnabled && bufferLevel > 0) {
_notifyBufferStateChanged(_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LOADED);
}
}
}
function _notifyBufferStateChanged(state) {
if (bufferState === state || state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_EMPTY && playbackController.getTime() === 0 || // Don't trigger BUFFER_EMPTY if it's initial loading
type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !textController.isTextEnabled()) {
return;
}
bufferState = state;
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_LEVEL_STATE_CHANGED, {
state: state
});
_triggerEvent(state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LOADED ? _core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_LOADED : _core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_EMPTY);
logger.debug(state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LOADED ? 'Got enough buffer to start' : 'Waiting for more buffer before starting playback');
}
/* prune buffer on our own in background to avoid browsers pruning buffer silently */
function pruneBuffer() {
if (!sourceBufferSink || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) {
return;
}
if (!isBufferingCompleted) {
clearBuffers(getClearRanges());
}
}
function getClearRanges() {
var clearRanges = [];
var ranges = sourceBufferSink.getAllBufferRanges();
if (!ranges || ranges.length === 0) {
return clearRanges;
}
var currentTime = playbackController.getTime();
var startRangeToKeep = Math.max(0, currentTime - settings.get().streaming.buffer.bufferToKeep);
var currentTimeRequest = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__["default"].FRAGMENT_MODEL_EXECUTED,
time: currentTime,
threshold: BUFFER_RANGE_CALCULATION_THRESHOLD
})[0]; // Ensure we keep full range of current fragment
if (currentTimeRequest) {
startRangeToKeep = Math.min(currentTimeRequest.startTime, startRangeToKeep);
} else if (currentTime === 0 && playbackController.getIsDynamic()) {
// Don't prune before the live stream starts, it messes with low latency
return [];
}
if (ranges.start(0) <= startRangeToKeep) {
var behindRange = {
start: 0,
end: startRangeToKeep
};
for (var i = 0; i < ranges.length && ranges.end(i) <= startRangeToKeep; i++) {
behindRange.end = ranges.end(i);
}
if (behindRange.start < behindRange.end) {
clearRanges.push(behindRange);
}
}
return clearRanges;
}
function clearBuffers(ranges) {
return new Promise(function (resolve, reject) {
if (!ranges || !sourceBufferSink || ranges.length === 0) {
resolve();
return;
}
var promises = [];
ranges.forEach(function (range) {
promises.push(_addClearRangeWithPromise(range));
});
if (!isPruningInProgress) {
clearNextRange();
}
Promise.all(promises).then(function () {
resolve();
})["catch"](function (e) {
reject(e);
});
});
}
function _addClearRangeWithPromise(range) {
return new Promise(function (resolve, reject) {
range.resolve = resolve;
range.reject = reject;
pendingPruningRanges.push(range);
});
}
function clearNextRange() {
try {
// If there's nothing to prune reset state
if (pendingPruningRanges.length === 0 || !sourceBufferSink) {
logger.debug('Nothing to prune, halt pruning');
pendingPruningRanges = [];
isPruningInProgress = false;
return;
}
var sourceBuffer = sourceBufferSink.getBuffer(); // If there's nothing buffered any pruning is invalid, so reset our state
if (!sourceBuffer || !sourceBuffer.buffered || sourceBuffer.buffered.length === 0) {
logger.debug('SourceBuffer is empty (or does not exist), halt pruning');
pendingPruningRanges = [];
isPruningInProgress = false;
return;
}
var range = pendingPruningRanges.shift();
logger.debug("".concat(type, ": Removing buffer from: ").concat(range.start, " to ").concat(range.end));
isPruningInProgress = true; // If removing buffer ahead current playback position, update maxAppendedIndex
var currentTime = playbackController.getTime();
if (currentTime < range.end) {
setIsBufferingCompleted(false);
}
sourceBufferSink.remove(range).then(function (e) {
_onRemoved(e);
})["catch"](function (e) {
_onRemoved(e);
});
} catch (e) {
isPruningInProgress = false;
}
}
function _onRemoved(e) {
logger.debug('onRemoved buffer from:', e.from, 'to', e.to);
var ranges = sourceBufferSink.getAllBufferRanges();
_showBufferRanges(ranges);
if (pendingPruningRanges.length === 0) {
isPruningInProgress = false;
_updateBufferLevel();
}
if (e.unintended) {
logger.warn('Detected unintended removal from:', e.from, 'to', e.to, 'setting streamprocessor time to', e.from);
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SEEK_TARGET, {
time: e.from
});
}
if (isPruningInProgress) {
clearNextRange();
} else {
if (!replacingBuffer) {
_updateBufferLevel();
} else {
replacingBuffer = false;
}
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_CLEARED, {
from: e.from,
to: e.to,
unintended: e.unintended,
hasEnoughSpaceToAppend: hasEnoughSpaceToAppend(),
quotaExceeded: isQuotaExceeded
});
}
}
function updateBufferTimestampOffset(representationInfo) {
return new Promise(function (resolve) {
if (!representationInfo || representationInfo.MSETimeOffset === undefined || !sourceBufferSink || !sourceBufferSink.updateTimestampOffset) {
resolve();
return;
} // Each track can have its own @presentationTimeOffset, so we should set the offset
// if it has changed after switching the quality or updating an mpd
sourceBufferSink.updateTimestampOffset(representationInfo.MSETimeOffset).then(function () {
resolve();
})["catch"](function () {
resolve();
});
});
}
function updateAppendWindow() {
if (sourceBufferSink && !isBufferingCompleted) {
return sourceBufferSink.updateAppendWindow(streamInfo);
}
return Promise.resolve();
}
function segmentRequestingCompleted(segmentIndex) {
if (!isNaN(segmentIndex)) {
maximumIndex = segmentIndex;
_checkIfBufferingCompleted();
}
}
function _onWallclockTimeUpdated() {
wallclockTicked++;
var secondsElapsed = wallclockTicked * (settings.get().streaming.wallclockTimeUpdateInterval / 1000);
if (secondsElapsed >= settings.get().streaming.buffer.bufferPruningInterval) {
wallclockTicked = 0;
pruneBuffer();
}
}
function _onPlaybackRateChanged() {
checkIfSufficientBuffer();
}
function getBuffer() {
return sourceBufferSink;
}
function getBufferLevel() {
return bufferLevel;
}
function getMediaSource() {
return mediaSource;
}
function getIsBufferingCompleted() {
return isBufferingCompleted;
}
function setIsBufferingCompleted(value) {
if (isBufferingCompleted === value) {
return;
}
isBufferingCompleted = value;
if (isBufferingCompleted) {
_triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFERING_COMPLETED);
} else {
maximumIndex = Number.POSITIVE_INFINITY;
}
}
function getIsPruningInProgress() {
return isPruningInProgress;
}
function getTotalBufferedTime() {
try {
var ranges = sourceBufferSink.getAllBufferRanges();
var totalBufferedTime = 0;
var ln, i;
if (!ranges) return totalBufferedTime;
for (i = 0, ln = ranges.length; i < ln; i++) {
totalBufferedTime += ranges.end(i) - ranges.start(i);
}
return totalBufferedTime;
} catch (e) {
return 0;
}
}
/**
* This function returns the maximum time for which the buffer is continuous starting from a target time.
* As soon as there is a gap we return the time before the gap starts
* @param {number} targetTime
*/
function getContinuousBufferTimeForTargetTime(targetTime) {
try {
var adjustedTime = targetTime;
var ranges = sourceBufferSink.getAllBufferRanges();
if (!ranges || ranges.length === 0) {
return targetTime;
}
var i = 0;
while (adjustedTime === targetTime && i < ranges.length) {
var start = ranges.start(i);
var end = ranges.end(i);
if (adjustedTime >= start && adjustedTime <= end) {
adjustedTime = end;
}
i += 1;
}
return adjustedTime;
} catch (e) {}
}
function hasEnoughSpaceToAppend() {
var totalBufferedTime = getTotalBufferedTime();
return isNaN(totalBufferedTime) || totalBufferedTime < criticalBufferLevel;
}
function setSeekTarget(value) {
seekTarget = value;
}
function _triggerEvent(eventType, data) {
var payload = data || {};
eventBus.trigger(eventType, payload, {
streamId: streamInfo.id,
mediaType: type
});
}
function resetInitialSettings(errored, keepBuffers) {
criticalBufferLevel = Number.POSITIVE_INFINITY;
bufferState = undefined;
maximumIndex = Number.POSITIVE_INFINITY;
maxAppendedIndex = 0;
appendedBytesInfo = null;
isBufferingCompleted = false;
isPruningInProgress = false;
isQuotaExceeded = false;
bufferLevel = 0;
wallclockTicked = 0;
pendingPruningRanges = [];
seekTarget = NaN;
if (sourceBufferSink) {
if (!errored && !keepBuffers) {
sourceBufferSink.abort().then(function () {
sourceBufferSink.reset(keepBuffers);
sourceBufferSink = null;
});
} else {
sourceBufferSink = null;
}
}
replacingBuffer = false;
}
function reset(errored, keepBuffers) {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].WALLCLOCK_TIME_UPDATED, _onWallclockTimeUpdated, this);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_PLAYING, _onPlaybackPlaying, this);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, this);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, this);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, this);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].PLAYBACK_STALLED, _onPlaybackStalled, this);
resetInitialSettings(errored, keepBuffers);
}
instance = {
initialize: initialize,
getStreamId: getStreamId,
getType: getType,
getBufferControllerType: getBufferControllerType,
createBufferSink: createBufferSink,
getBuffer: getBuffer,
getBufferLevel: getBufferLevel,
getRangeAt: getRangeAt,
setMediaSource: setMediaSource,
getMediaSource: getMediaSource,
appendInitSegmentFromCache: appendInitSegmentFromCache,
getIsBufferingCompleted: getIsBufferingCompleted,
setIsBufferingCompleted: setIsBufferingCompleted,
getIsPruningInProgress: getIsPruningInProgress,
reset: reset,
prepareForPlaybackSeek: prepareForPlaybackSeek,
prepareForReplacementTrackSwitch: prepareForReplacementTrackSwitch,
prepareForNonReplacementTrackSwitch: prepareForNonReplacementTrackSwitch,
prepareForReplacementQualitySwitch: prepareForReplacementQualitySwitch,
updateAppendWindow: updateAppendWindow,
getAllRangesWithSafetyFactor: getAllRangesWithSafetyFactor,
getContinuousBufferTimeForTargetTime: getContinuousBufferTimeForTargetTime,
clearBuffers: clearBuffers,
pruneAllSafely: pruneAllSafely,
updateBufferTimestampOffset: updateBufferTimestampOffset,
setSeekTarget: setSeekTarget,
segmentRequestingCompleted: segmentRequestingCompleted
};
setup();
return instance;
}
BufferController.__dashjs_factory_name = BUFFER_CONTROLLER_TYPE;
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__["default"].getClassFactory(BufferController));
/***/ }),
/***/ "./src/streaming/controllers/EventController.js":
/*!******************************************************!*\
!*** ./src/streaming/controllers/EventController.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _net_XHRLoader__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../net/XHRLoader */ "./src/streaming/net/XHRLoader.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function EventController() {
var MPD_RELOAD_SCHEME = 'urn:mpeg:dash:event:2012';
var MPD_RELOAD_VALUE = 1;
var MPD_CALLBACK_SCHEME = 'urn:mpeg:dash:event:callback:2015';
var MPD_CALLBACK_VALUE = 1;
var REMAINING_EVENTS_THRESHOLD = 300;
var EVENT_HANDLED_STATES = {
DISCARDED: 'discarded',
UPDATED: 'updated',
ADDED: 'added'
};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
var instance, logger, inlineEvents, // Holds all Inline Events not triggered yet
inbandEvents, // Holds all Inband Events not triggered yet
eventInterval, // variable holding the setInterval
lastEventTimerCall, manifestUpdater, playbackController, settings, eventHandlingInProgress, isStarted;
/**
* Internal setup when class is instanced
*/
function _setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
_resetInitialSettings();
}
/**
* Checks if the provded configuration is valid
*/
function checkConfig() {
if (!manifestUpdater || !playbackController) {
throw new Error('setConfig function has to be called previously');
}
}
/**
* Reset to initial settings
*/
function _resetInitialSettings() {
isStarted = false;
inlineEvents = {}; // Format inlineEvents[schemeIdUri]
inbandEvents = {}; // Format inlineEvents[schemeIdUri]
eventInterval = null;
eventHandlingInProgress = false;
lastEventTimerCall = Date.now() / 1000;
}
/**
* Stops the EventController by clearing the event interval
*/
function _stop() {
try {
if (eventInterval !== null && isStarted) {
clearInterval(eventInterval);
eventInterval = null;
isStarted = false;
_onStopEventController();
}
} catch (e) {
throw e;
}
}
/**
* Starts the interval function of the EventController
*/
function start() {
try {
checkConfig();
logger.debug('Start Event Controller');
var refreshDelay = settings.get().streaming.eventControllerRefreshDelay;
if (!isStarted && !isNaN(refreshDelay)) {
isStarted = true;
eventInterval = setInterval(_onEventTimer, refreshDelay);
}
} catch (e) {
throw e;
}
}
/**
* Add MPD events to the list of events.
* Events that are not in the MPD anymore but not triggered yet will still be deleted.
* Existing events might get updated.
* @param {Array.<Object>} values
*/
function addInlineEvents(values) {
try {
checkConfig();
if (values) {
for (var i = 0; i < values.length; i++) {
var event = values[i];
var result = _addOrUpdateEvent(event, inlineEvents, true);
if (result === EVENT_HANDLED_STATES.ADDED) {
logger.debug("Added inline event with id ".concat(event.id)); // If we see the event for the first time we trigger it in onReceive mode
_startEvent(event, values, _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_RECEIVE);
} else if (result === EVENT_HANDLED_STATES.UPDATED) {
logger.debug("Updated inline event with id ".concat(event.id));
}
}
}
} catch (e) {
throw e;
}
}
/**
* Add EMSG events to the list of events
* Messages with the same id within the scope of the same scheme_id_uri and value pair are equivalent , i.e. processing of any one event message box with the same id is sufficient.
* @param {Array.<Object>} values
*/
function addInbandEvents(values) {
try {
checkConfig();
for (var i = 0; i < values.length; i++) {
var event = values[i];
var result = _addOrUpdateEvent(event, inbandEvents, false);
if (result === EVENT_HANDLED_STATES.ADDED) {
if (event.eventStream.schemeIdUri === MPD_RELOAD_SCHEME && inbandEvents[event.id] === undefined) {
_handleManifestReloadEvent(event);
}
logger.debug('Added inband event with id ' + event.id);
_startEvent(event, values, _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_RECEIVE);
} else {
logger.debug("Inband event with scheme_id_uri ".concat(event.eventStream.schemeIdUri, ", value ").concat(event.eventStream.value, " and id ").concat(event.id, " was ignored because it has been added before."));
}
}
_onEventTimer();
} catch (e) {
throw e;
}
}
/**
* Adds or updates an event to/in the list of events
* @param {object} event
* @param {object} events
* @param {boolean} shouldOverwriteExistingEvents
* @return {string}
* @private
*/
function _addOrUpdateEvent(event, events) {
var shouldOverwriteExistingEvents = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var schemeIdUri = event.eventStream.schemeIdUri;
var value = event.eventStream.value;
var id = event.id;
var eventState = EVENT_HANDLED_STATES.DISCARDED;
if (!events[schemeIdUri]) {
events[schemeIdUri] = [];
}
var indexOfExistingEvent = events[schemeIdUri].findIndex(function (e) {
return (!value || e.eventStream.value && e.eventStream.value === value) && e.id === id;
});
if (indexOfExistingEvent === -1) {
events[schemeIdUri].push(event);
eventState = EVENT_HANDLED_STATES.ADDED;
} else if (shouldOverwriteExistingEvents) {
events[schemeIdUri][indexOfExistingEvent] = event;
eventState = EVENT_HANDLED_STATES.UPDATED;
}
return eventState;
}
/**
* Triggers an MPD reload
* @param {object} event
* @private
*/
function _handleManifestReloadEvent(event) {
try {
if (event.eventStream.value == MPD_RELOAD_VALUE) {
var validUntil = event.calculatedPresentationTime;
var newDuration;
if (event.calculatedPresentationTime == 0xFFFFFFFF) {
//0xFF... means remaining duration unknown
newDuration = NaN;
} else {
newDuration = event.calculatedPresentationTime + event.duration;
} //logger.info('Manifest validity changed: Valid until: ' + validUntil + '; remaining duration: ' + newDuration);
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].MANIFEST_VALIDITY_CHANGED, {
id: event.id,
validUntil: validUntil,
newDuration: newDuration,
newManifestValidAfter: NaN //event.message_data - this is an arraybuffer with a timestring in it, but not used yet
}, {
mode: _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_START
});
}
} catch (e) {}
}
/**
* Iterate through the eventList and trigger the events
*/
function _onEventTimer() {
try {
if (!eventHandlingInProgress) {
eventHandlingInProgress = true;
var currentVideoTime = playbackController.getTime();
var presentationTimeThreshold = currentVideoTime - lastEventTimerCall; // For dynamic streams lastEventTimeCall will be large in the first iteration. Avoid firing all events at once.
presentationTimeThreshold = lastEventTimerCall > 0 ? Math.max(0, presentationTimeThreshold) : 0;
_triggerEvents(inbandEvents, presentationTimeThreshold, currentVideoTime);
_triggerEvents(inlineEvents, presentationTimeThreshold, currentVideoTime);
lastEventTimerCall = currentVideoTime;
eventHandlingInProgress = false;
}
} catch (e) {
eventHandlingInProgress = false;
}
}
/**
* When the EventController is stopped this callback is triggered. Starts the remaining events.
* @private
*/
function _onStopEventController() {
try {
// EventController might be stopped before the period is over. Before we stop the event controller we check for events that needs to be triggered at the period boundary.
_triggerRemainingEvents(inbandEvents);
_triggerRemainingEvents(inlineEvents);
} catch (e) {}
}
/**
* Iterate over a list of events and trigger the ones for which the presentation time is within the current timing interval
* @param {object} events
* @param {number} presentationTimeThreshold
* @param {number} currentVideoTime
* @private
*/
function _triggerEvents(events, presentationTimeThreshold, currentVideoTime) {
try {
var callback = function callback(event) {
if (event !== undefined) {
var duration = !isNaN(event.duration) ? event.duration : 0; // The event is either about to start or has already been started and we are within its duration
if (event.calculatedPresentationTime <= currentVideoTime && event.calculatedPresentationTime + presentationTimeThreshold + duration >= currentVideoTime) {
_startEvent(event, events, _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_START);
} else if (_eventHasExpired(currentVideoTime, duration + presentationTimeThreshold, event.calculatedPresentationTime) || _eventIsInvalid(event)) {
logger.debug("Deleting event ".concat(event.id, " as it is expired or invalid"));
_removeEvent(events, event);
}
}
};
_iterateAndTriggerCallback(events, callback);
} catch (e) {}
}
/**
* Triggers the remaining events after the EventController has been stopped
* @param {object} events
* @private
*/
function _triggerRemainingEvents(events) {
try {
var currentTime = playbackController.getTime();
var callback = function callback(event) {
var periodDuration = event.eventStream && event.eventStream.period && !isNaN(event.eventStream.period.duration) ? event.eventStream.period.duration : NaN;
var periodStart = event.eventStream && event.eventStream.period && !isNaN(event.eventStream.period.start) ? event.eventStream.period.start : NaN;
if (isNaN(periodDuration) || isNaN(periodStart)) {
return;
}
var calculatedPresentationTimeInSeconds = event.calculatedPresentationTime;
if (Math.abs(calculatedPresentationTimeInSeconds - currentTime) < REMAINING_EVENTS_THRESHOLD) {
_startEvent(event, events, _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_START);
}
};
_iterateAndTriggerCallback(events, callback);
} catch (e) {}
}
/**
* Iterates over the inline/inband event object and triggers a callback for each event
* @param {object} events
* @param {function} callback
* @private
*/
function _iterateAndTriggerCallback(events, callback) {
try {
if (events) {
var schemeIdUris = Object.keys(events);
for (var i = 0; i < schemeIdUris.length; i++) {
var schemeIdEvents = events[schemeIdUris[i]];
schemeIdEvents.forEach(function (event) {
if (event !== undefined) {
callback(event);
}
});
}
}
} catch (e) {}
}
/**
* Checks if an event is expired. For instance if the presentationTime + the duration of an event are smaller than the current video time.
* @param {number} currentVideoTime
* @param {number} threshold
* @param {number} calculatedPresentationTimeInSeconds
* @return {boolean}
* @private
*/
function _eventHasExpired(currentVideoTime, threshold, calculatedPresentationTimeInSeconds) {
try {
return currentVideoTime - threshold > calculatedPresentationTimeInSeconds;
} catch (e) {
return false;
}
}
/**
* Checks if an event is invalid. This is the case if the end time of the parent period is smaller than the presentation time of the event.
* @param {object} event
* @return {boolean}
* @private
*/
function _eventIsInvalid(event) {
try {
var periodEndTime = event.eventStream.period.start + event.eventStream.period.duration;
return event.calculatedPresentationTime > periodEndTime;
} catch (e) {
return false;
}
}
/**
* Starts an event. Depending on the schemeIdUri we distinguis between
* - MPD Reload events
* - MPD Callback events
* - Events to be dispatched to the application
* Events should be removed from the list before beeing triggered. Otherwise the event handler might cause an error and the remove function will not be called.
* @param {object} event
* @param {object} events
* @param {String} mode
* @private
*/
function _startEvent(event, events, mode) {
try {
var currentVideoTime = playbackController.getTime();
var eventId = event.id;
if (mode === _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_RECEIVE) {
logger.debug("Received event ".concat(eventId));
eventBus.trigger(event.eventStream.schemeIdUri, {
event: event
}, {
mode: mode
});
return;
}
if (event.eventStream.schemeIdUri === MPD_RELOAD_SCHEME && event.eventStream.value == MPD_RELOAD_VALUE) {
if (event.duration !== 0 || event.presentationTimeDelta !== 0) {
//If both are set to zero, it indicates the media is over at this point. Don't reload the manifest.
logger.debug("Starting manifest refresh event ".concat(eventId, " at ").concat(currentVideoTime));
_removeEvent(events, event);
_refreshManifest();
}
} else if (event.eventStream.schemeIdUri === MPD_CALLBACK_SCHEME && event.eventStream.value == MPD_CALLBACK_VALUE) {
logger.debug("Starting callback event ".concat(eventId, " at ").concat(currentVideoTime));
_removeEvent(events, event);
_sendCallbackRequest(event.messageData);
} else {
logger.debug("Starting event ".concat(eventId, " at ").concat(currentVideoTime));
_removeEvent(events, event);
eventBus.trigger(event.eventStream.schemeIdUri, {
event: event
}, {
mode: mode
});
}
} catch (e) {}
}
/**
* Removes an event from the list. If this is the last event of type "schemeIdUri" the corresponding schemeIdUri Object in the list of events is deleted.
* @param {object} events
* @param {object} event
* @private
*/
function _removeEvent(events, event) {
var schemeIdUri = event.eventStream.schemeIdUri;
var value = event.eventStream.value;
var id = event.id;
events[schemeIdUri] = events[schemeIdUri].filter(function (e) {
return value && e.eventStream.value && e.eventStream.value !== value || e.id !== id;
});
if (events[schemeIdUri].length === 0) {
delete events[schemeIdUri];
}
}
/**
* Refresh the manifest
* @private
*/
function _refreshManifest() {
try {
checkConfig();
manifestUpdater.refreshManifest();
} catch (e) {}
}
/**
* Send a callback request
* @param {String} url
* @private
*/
function _sendCallbackRequest(url) {
try {
var loader = Object(_net_XHRLoader__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({});
loader.load({
method: 'get',
url: url,
request: {
responseType: 'arraybuffer'
}
});
} catch (e) {
throw e;
}
}
/**
* Set the config of the EventController
* @param {object} config
*/
function setConfig(config) {
try {
if (!config) {
return;
}
if (config.manifestUpdater) {
manifestUpdater = config.manifestUpdater;
}
if (config.playbackController) {
playbackController = config.playbackController;
}
if (config.settings) {
settings = config.settings;
}
} catch (e) {
throw e;
}
}
/**
* Returns all inline events that have not been triggered yet
* @return {object}
*/
function getInlineEvents() {
return inlineEvents;
}
/**
* Returns all inband events that have not been triggered yet
* @return {object}
*/
function getInbandEvents() {
return inbandEvents;
}
/**
* Stop the EventController and reset all initial settings
*/
function reset() {
_stop();
_resetInitialSettings();
}
instance = {
addInlineEvents: addInlineEvents,
addInbandEvents: addInbandEvents,
getInbandEvents: getInbandEvents,
getInlineEvents: getInlineEvents,
start: start,
setConfig: setConfig,
reset: reset
};
_setup();
return instance;
}
EventController.__dashjs_factory_name = 'EventController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(EventController));
/***/ }),
/***/ "./src/streaming/controllers/FragmentController.js":
/*!*********************************************************!*\
!*** ./src/streaming/controllers/FragmentController.js ***!
\*********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _vo_DataChunk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/DataChunk */ "./src/streaming/vo/DataChunk.js");
/* harmony import */ var _models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../models/FragmentModel */ "./src/streaming/models/FragmentModel.js");
/* harmony import */ var _FragmentLoader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../FragmentLoader */ "./src/streaming/FragmentLoader.js");
/* harmony import */ var _utils_RequestModifier__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/RequestModifier */ "./src/streaming/utils/RequestModifier.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function FragmentController(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
var errHandler = config.errHandler;
var mediaPlayerModel = config.mediaPlayerModel;
var dashMetrics = config.dashMetrics;
var debug = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
var streamInfo = config.streamInfo;
var instance, logger, fragmentModels;
function setup() {
logger = debug.getLogger(instance);
resetInitialSettings();
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_PROGRESS, onFragmentLoadingCompleted, instance);
}
function getStreamId() {
return streamInfo.id;
}
function getModel(type) {
var model = fragmentModels[type];
if (!model) {
model = Object(_models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
streamInfo: streamInfo,
type: type,
dashMetrics: dashMetrics,
fragmentLoader: Object(_FragmentLoader__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
errHandler: errHandler,
requestModifier: Object(_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance(),
settings: config.settings,
boxParser: config.boxParser,
eventBus: eventBus,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"],
errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_8__["default"],
dashConstants: config.dashConstants,
urlUtils: config.urlUtils,
streamId: getStreamId()
}),
debug: debug,
eventBus: eventBus,
events: _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"]
});
fragmentModels[type] = model;
}
return model;
}
function resetInitialSettings() {
for (var model in fragmentModels) {
fragmentModels[model].reset();
}
fragmentModels = {};
}
function reset() {
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_COMPLETED, onFragmentLoadingCompleted, this);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_PROGRESS, onFragmentLoadingCompleted, this);
resetInitialSettings();
}
function createDataChunk(bytes, request, streamId, endFragment) {
var chunk = new _vo_DataChunk__WEBPACK_IMPORTED_MODULE_1__["default"]();
chunk.streamId = streamId;
chunk.mediaInfo = request.mediaInfo;
chunk.segmentType = request.type;
chunk.start = request.startTime;
chunk.duration = request.duration;
chunk.end = chunk.start + chunk.duration;
chunk.bytes = bytes;
chunk.index = request.index;
chunk.quality = request.quality;
chunk.representationId = request.representationId;
chunk.endFragment = endFragment;
return chunk;
}
function onFragmentLoadingCompleted(e) {
// Event propagation may have been stopped (see MssHandler)
if (!e.sender) return;
var request = e.request;
var bytes = e.response;
var isInit = request.isInitializationRequest();
var strInfo = request.mediaInfo.streamInfo;
if (e.error) {
if (request.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO || request.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || request.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && request.mediaInfo.isFragmented) {
// add service location to blacklist controller - only for audio or video. text should not set errors
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SERVICE_LOCATION_BLACKLIST_ADD, {
entry: e.request.serviceLocation
});
}
}
if (!bytes || !strInfo) {
logger.warn('No ' + request.mediaType + ' bytes to push or stream is inactive.');
return;
}
var chunk = createDataChunk(bytes, request, streamInfo.id, e.type !== _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].FRAGMENT_LOADING_PROGRESS);
eventBus.trigger(isInit ? _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].INIT_FRAGMENT_LOADED : _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_FRAGMENT_LOADED, {
chunk: chunk,
request: request
}, {
streamId: strInfo.id,
mediaType: request.mediaType
});
}
instance = {
getStreamId: getStreamId,
getModel: getModel,
reset: reset
};
setup();
return instance;
}
FragmentController.__dashjs_factory_name = 'FragmentController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_9__["default"].getClassFactory(FragmentController));
/***/ }),
/***/ "./src/streaming/controllers/GapController.js":
/*!****************************************************!*\
!*** ./src/streaming/controllers/GapController.js ***!
\****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var GAP_HANDLER_INTERVAL = 100;
var THRESHOLD_TO_STALLS = 10;
var GAP_JUMP_WAITING_TIME_OFFSET = 0.1;
function GapController() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance();
var instance, lastPlaybackTime, settings, wallclockTicked, gapHandlerInterval, lastGapJumpPosition, playbackController, streamController, videoModel, jumpTimeoutHandler, trackSwitchByMediaType, logger;
function initialize() {
_registerEvents();
}
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
reset();
}
function reset() {
_stopGapHandler();
_unregisterEvents();
resetInitialSettings();
}
function resetInitialSettings() {
gapHandlerInterval = null;
lastGapJumpPosition = NaN;
wallclockTicked = 0;
jumpTimeoutHandler = null;
trackSwitchByMediaType = {};
}
function setConfig(config) {
if (!config) {
return;
}
if (config.settings) {
settings = config.settings;
}
if (config.playbackController) {
playbackController = config.playbackController;
}
if (config.streamController) {
streamController = config.streamController;
}
if (config.videoModel) {
videoModel = config.videoModel;
}
}
function _registerEvents() {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].WALLCLOCK_TIME_UPDATED, _onWallclockTimeUpdated, this);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].INITIAL_STREAM_SWITCH, _onInitialStreamSwitch, this);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, this);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].BUFFER_REPLACEMENT_STARTED, _onBufferReplacementStarted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].TRACK_CHANGE_RENDERED, _onBufferReplacementEnded, instance);
}
function _unregisterEvents() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].WALLCLOCK_TIME_UPDATED, _onWallclockTimeUpdated, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].INITIAL_STREAM_SWITCH, _onInitialStreamSwitch, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, this);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].BUFFER_REPLACEMENT_STARTED, _onBufferReplacementStarted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].TRACK_CHANGE_RENDERED, _onBufferReplacementEnded, instance);
}
/**
* Clear scheduled gap jump when seeking
* @private
*/
function _onPlaybackSeeking() {
if (jumpTimeoutHandler) {
clearTimeout(jumpTimeoutHandler);
jumpTimeoutHandler = null;
}
}
/**
* If the track was changed in the current active period and the player might aggressively replace segments the buffer will be empty for a short period of time. Avoid gap jumping at that time.
* We wait until the next media fragment of the target type has been appended before activating again
* @param {object} e
* @private
*/
function _onBufferReplacementStarted(e) {
try {
if (e.streamId !== streamController.getActiveStreamInfo().id || !e.mediaType) {
return;
}
if (e.streamId === streamController.getActiveStreamInfo().id) {
trackSwitchByMediaType[e.mediaType] = true;
}
} catch (e) {
logger.error(e);
}
}
/**
* Activate gap jumping again once segment of target type has been appended
* @param {object} e
* @private
*/
function _onBufferReplacementEnded(e) {
if (!e || !e.mediaType) {
return;
}
trackSwitchByMediaType[e.mediaType] = false;
}
/**
* Activate the gap handler after the first stream switch
* @private
*/
function _onInitialStreamSwitch() {
if (!gapHandlerInterval) {
_startGapHandler();
}
}
/**
* Callback handler for when the wallclock time has been updated
* @private
*/
function _onWallclockTimeUpdated()
/*e*/
{
if (!_shouldCheckForGaps(settings.get().streaming.gaps.enableSeekFix)) {
return;
}
wallclockTicked++;
if (wallclockTicked >= THRESHOLD_TO_STALLS) {
var currentTime = playbackController.getTime();
if (lastPlaybackTime === currentTime) {
_jumpGap(currentTime, true);
} else {
lastPlaybackTime = currentTime;
lastGapJumpPosition = NaN;
}
wallclockTicked = 0;
}
}
/**
* Returns if we are supposed to check for gaps
* @param {boolean} checkSeekingState - Usually we are not checking for gaps in the videolement is in seeking state. If this flag is set to true we check for a potential exceptions of this rule.
* @return {boolean}
* @private
*/
function _shouldCheckForGaps() {
var checkSeekingState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var trackSwitchInProgress = Object.keys(trackSwitchByMediaType).some(function (key) {
return trackSwitchByMediaType[key];
});
var shouldIgnoreSeekingState = checkSeekingState ? _shouldIgnoreSeekingState() : false;
return !trackSwitchInProgress && settings.get().streaming.gaps.jumpGaps && streamController.getActiveStreamProcessors().length > 0 && (!playbackController.isSeeking() || shouldIgnoreSeekingState) && !playbackController.isPaused() && !streamController.getIsStreamSwitchInProgress() && !streamController.getHasMediaOrInitialisationError();
}
/**
* There are cases in which we never transition out of the seeking state and still need to jump a gap. For instance if the user seeks right before a gap and video element will not transition out of the seeking state.
* For now limit this to period boundaries. In this case the current period is completely buffered and we are right before the end of the period.
* @private
*/
function _shouldIgnoreSeekingState() {
var activeStream = streamController.getActiveStream();
var streamEnd = parseFloat((activeStream.getStartTime() + activeStream.getDuration()).toFixed(5));
return playbackController.getTime() + settings.get().streaming.gaps.threshold >= streamEnd;
}
/**
* Returns the index of the range object that comes after the current time
* @param {object} ranges
* @param {number} currentTime
* @private
* @return {null|number}
*/
function _getNextRangeIndex(ranges, currentTime) {
try {
if (!ranges || ranges.length <= 1 && currentTime > 0) {
return NaN;
}
var nextRangeIndex = NaN;
var j = 0;
while (isNaN(nextRangeIndex) && j < ranges.length) {
var rangeEnd = j > 0 ? ranges.end(j - 1) : 0;
if (currentTime < ranges.start(j) && rangeEnd - currentTime < settings.get().streaming.gaps.threshold) {
nextRangeIndex = j;
}
j += 1;
}
return nextRangeIndex;
} catch (e) {
return null;
}
}
/**
* Starts the interval that checks for gaps
* @private
*/
function _startGapHandler() {
try {
if (!gapHandlerInterval) {
logger.debug('Starting the gap controller');
gapHandlerInterval = setInterval(function () {
if (!_shouldCheckForGaps()) {
return;
}
var currentTime = playbackController.getTime();
_jumpGap(currentTime);
}, GAP_HANDLER_INTERVAL);
}
} catch (e) {}
}
/**
* Clears the gap interval handler
* @private
*/
function _stopGapHandler() {
logger.debug('Stopping the gap controller');
if (gapHandlerInterval) {
clearInterval(gapHandlerInterval);
gapHandlerInterval = null;
}
}
/**
* Jump a gap
* @param {number} currentTime
* @param {boolean} playbackStalled
* @private
*/
function _jumpGap(currentTime) {
var playbackStalled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var smallGapLimit = settings.get().streaming.gaps.smallGapLimit;
var jumpLargeGaps = settings.get().streaming.gaps.jumpLargeGaps;
var ranges = videoModel.getBufferRange();
var nextRangeIndex;
var seekToPosition = NaN;
var jumpToStreamEnd = false; // Get the range just after current time position
nextRangeIndex = _getNextRangeIndex(ranges, currentTime);
if (!isNaN(nextRangeIndex)) {
var start = ranges.start(nextRangeIndex);
var gap = start - currentTime;
if (gap > 0 && (gap <= smallGapLimit || jumpLargeGaps)) {
seekToPosition = start;
}
} // Playback has stalled before period end. We seek to the end of the period
var timeToStreamEnd = playbackController.getTimeToStreamEnd();
if (isNaN(seekToPosition) && playbackStalled && isFinite(timeToStreamEnd) && !isNaN(timeToStreamEnd) && timeToStreamEnd < smallGapLimit) {
seekToPosition = parseFloat(playbackController.getStreamEndTime().toFixed(5));
jumpToStreamEnd = true;
}
if (seekToPosition > 0 && lastGapJumpPosition !== seekToPosition && seekToPosition > currentTime && !jumpTimeoutHandler) {
var timeUntilGapEnd = seekToPosition - currentTime;
if (jumpToStreamEnd) {
var nextStream = streamController.getStreamForTime(seekToPosition);
var internalSeek = nextStream && !!nextStream.getPreloaded();
logger.warn("Jumping to end of stream because of gap from ".concat(currentTime, " to ").concat(seekToPosition, ". Gap duration: ").concat(timeUntilGapEnd));
playbackController.seek(seekToPosition, true, internalSeek);
} else {
var isDynamic = playbackController.getIsDynamic();
var _start = nextRangeIndex > 0 ? ranges.end(nextRangeIndex - 1) : currentTime;
var timeToWait = !isDynamic ? 0 : Math.max(0, timeUntilGapEnd - GAP_JUMP_WAITING_TIME_OFFSET) * 1000;
jumpTimeoutHandler = window.setTimeout(function () {
playbackController.seek(seekToPosition, true, true);
logger.warn("Jumping gap occuring in period ".concat(streamController.getActiveStream().getStreamId(), " starting at ").concat(_start, " and ending at ").concat(seekToPosition, ". Jumping by: ").concat(timeUntilGapEnd - timeToWait / 1000));
jumpTimeoutHandler = null;
}, timeToWait);
}
lastGapJumpPosition = seekToPosition;
}
}
instance = {
reset: reset,
setConfig: setConfig,
initialize: initialize
};
setup();
return instance;
}
GapController.__dashjs_factory_name = 'GapController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(GapController));
/***/ }),
/***/ "./src/streaming/controllers/MediaController.js":
/*!******************************************************!*\
!*** ./src/streaming/controllers/MediaController.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MediaController() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
var instance, logger, tracks, settings, initialSettings, lastSelectedTracks, domStorage, customInitialTrackSelectionFunction;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance().getLogger(instance);
reset();
}
/**
* @param {string} type
* @param {StreamInfo} streamInfo
* @memberof MediaController#
*/
function setInitialMediaSettingsForType(type, streamInfo) {
var settings = lastSelectedTracks[type] || getInitialSettings(type);
var tracksForType = getTracksFor(type, streamInfo.id);
var tracks = [];
if (!settings) {
settings = domStorage.getSavedMediaSettings(type);
setInitialSettings(type, settings);
}
if (!tracksForType || tracksForType.length === 0) return;
if (settings) {
tracksForType.forEach(function (track) {
if (matchSettings(settings, track, !!lastSelectedTracks[type])) {
tracks.push(track);
}
});
}
if (tracks.length === 0) {
setTrack(selectInitialTrack(type, tracksForType), true);
} else {
if (tracks.length > 1) {
setTrack(selectInitialTrack(type, tracks, !!lastSelectedTracks[type]));
} else {
setTrack(tracks[0]);
}
}
}
/**
* @param {MediaInfo} track
* @memberof MediaController#
*/
function addTrack(track) {
if (!track) return;
var mediaType = track.type;
if (!_isMultiTrackSupportedByType(mediaType)) return;
var streamId = track.streamInfo.id;
if (!tracks[streamId]) {
tracks[streamId] = createTrackInfo();
}
var mediaTracks = tracks[streamId][mediaType].list;
for (var i = 0, len = mediaTracks.length; i < len; ++i) {
//track is already set.
if (isTracksEqual(mediaTracks[i], track)) {
return;
}
}
mediaTracks.push(track);
}
/**
* @param {string} type
* @param {string} streamId
* @returns {Array}
* @memberof MediaController#
*/
function getTracksFor(type, streamId) {
if (!type) return [];
if (!tracks[streamId] || !tracks[streamId][type]) return [];
return tracks[streamId][type].list;
}
/**
* @param {string} type
* @param {string} streamId
* @returns {Object|null}
* @memberof MediaController#
*/
function getCurrentTrackFor(type, streamId) {
if (!type || !tracks[streamId] || !tracks[streamId][type]) return null;
return tracks[streamId][type].current;
}
/**
* @param {MediaInfo} track
* @returns {boolean}
* @memberof MediaController#
*/
function isCurrentTrack(track) {
if (!track) {
return false;
}
var type = track.type;
var id = track.streamInfo.id;
return tracks[id] && tracks[id][type] && isTracksEqual(tracks[id][type].current, track);
}
/**
* @param {MediaInfo} track
* @param {boolean} noSettingsSave specify if settings must be not be saved
* @memberof MediaController#
*/
function setTrack(track) {
var noSettingsSave = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (!track || !track.streamInfo) return;
var type = track.type;
var streamInfo = track.streamInfo;
var id = streamInfo.id;
var current = getCurrentTrackFor(type, id);
if (!tracks[id] || !tracks[id][type] || isTracksEqual(track, current)) return;
tracks[id][type].current = track;
if (tracks[id][type].current && (type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && track.isFragmented)) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].CURRENT_TRACK_CHANGED, {
oldMediaInfo: current,
newMediaInfo: track,
switchMode: settings.get().streaming.trackSwitchMode[type]
}, {
streamId: id
});
}
if (!noSettingsSave) {
var _settings = extractSettings(track);
if (!_settings || !tracks[id][type].storeLastSettings) return;
if (_settings.roles) {
_settings.role = _settings.roles[0];
delete _settings.roles;
}
if (_settings.accessibility) {
_settings.accessibility = _settings.accessibility[0];
}
if (_settings.audioChannelConfiguration) {
_settings.audioChannelConfiguration = _settings.audioChannelConfiguration[0];
}
lastSelectedTracks[type] = _settings;
domStorage.setSavedMediaSettings(type, _settings);
}
}
/**
* @param {string} type
* @param {Object} value
* @memberof MediaController#
*/
function setInitialSettings(type, value) {
if (!type || !value) return;
initialSettings[type] = value;
}
/**
* @param {string} type
* @returns {Object|null}
* @memberof MediaController#
*/
function getInitialSettings(type) {
if (!type) return null;
return initialSettings[type];
}
/**
* @memberof MediaController#
*/
function saveTextSettingsDisabled() {
domStorage.setSavedMediaSettings(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, null);
}
/**
* @param {string} type
* @returns {boolean}
* @memberof MediaController#
*/
function _isMultiTrackSupportedByType(type) {
return type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE;
}
/**
* @param {MediaInfo} t1 - first track to compare
* @param {MediaInfo} t2 - second track to compare
* @returns {boolean}
* @memberof MediaController#
*/
function isTracksEqual(t1, t2) {
if (!t1 && !t2) {
return true;
}
if (!t1 || !t2) {
return false;
}
var sameId = t1.id === t2.id;
var sameViewpoint = t1.viewpoint === t2.viewpoint;
var sameLang = t1.lang === t2.lang;
var sameCodec = t1.codec === t2.codec;
var sameRoles = t1.roles.toString() === t2.roles.toString();
var sameAccessibility = t1.accessibility.toString() === t2.accessibility.toString();
var sameAudioChannelConfiguration = t1.audioChannelConfiguration.toString() === t2.audioChannelConfiguration.toString();
return sameId && sameCodec && sameViewpoint && sameLang && sameRoles && sameAccessibility && sameAudioChannelConfiguration;
}
function setConfig(config) {
if (!config) return;
if (config.domStorage) {
domStorage = config.domStorage;
}
if (config.settings) {
settings = config.settings;
}
}
/**
* @memberof MediaController#
*/
function reset() {
tracks = {};
lastSelectedTracks = {};
customInitialTrackSelectionFunction = null;
resetInitialSettings();
}
function extractSettings(mediaInfo) {
var settings = {
lang: mediaInfo.lang,
viewpoint: mediaInfo.viewpoint,
roles: mediaInfo.roles,
accessibility: mediaInfo.accessibility,
audioChannelConfiguration: mediaInfo.audioChannelConfiguration
};
var notEmpty = settings.lang || settings.viewpoint || settings.role && settings.role.length > 0 || settings.accessibility && settings.accessibility.length > 0 || settings.audioChannelConfiguration && settings.audioChannelConfiguration.length > 0;
return notEmpty ? settings : null;
}
function matchSettings(settings, track) {
var isTrackActive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var matchLang = !settings.lang || track.lang.match(settings.lang);
var matchIndex = settings.index === undefined || settings.index === null || track.index === settings.index;
var matchViewPoint = !settings.viewpoint || settings.viewpoint === track.viewpoint;
var matchRole = !settings.role || !!track.roles.filter(function (item) {
return item === settings.role;
})[0];
var matchAccessibility = !settings.accessibility || !!track.accessibility.filter(function (item) {
return item === settings.accessibility;
})[0];
var matchAudioChannelConfiguration = !settings.audioChannelConfiguration || !!track.audioChannelConfiguration.filter(function (item) {
return item === settings.audioChannelConfiguration;
})[0];
return matchLang && matchIndex && matchViewPoint && (matchRole || track.type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && isTrackActive) && matchAccessibility && matchAudioChannelConfiguration;
}
function resetInitialSettings() {
initialSettings = {
audio: null,
video: null,
text: null
};
}
function getTracksWithHighestSelectionPriority(trackArr) {
var max = 0;
var result = [];
trackArr.forEach(function (track) {
if (!isNaN(track.selectionPriority)) {
// Higher max value. Reset list and add new entry
if (track.selectionPriority > max) {
max = track.selectionPriority;
result = [track];
} // Same max value add to list
else if (track.selectionPriority === max) {
result.push(track);
}
}
});
return result;
}
function getTracksWithHighestBitrate(trackArr) {
var max = 0;
var result = [];
var tmp;
trackArr.forEach(function (track) {
tmp = Math.max.apply(Math, track.bitrateList.map(function (obj) {
return obj.bandwidth;
}));
if (tmp > max) {
max = tmp;
result = [track];
} else if (tmp === max) {
result.push(track);
}
});
return result;
}
function getTracksWithHighestEfficiency(trackArr) {
var min = Infinity;
var result = [];
var tmp;
trackArr.forEach(function (track) {
var sum = track.bitrateList.reduce(function (acc, obj) {
var resolution = Math.max(1, obj.width * obj.height);
var efficiency = obj.bandwidth / resolution;
return acc + efficiency;
}, 0);
tmp = sum / track.bitrateList.length;
if (tmp < min) {
min = tmp;
result = [track];
} else if (tmp === min) {
result.push(track);
}
});
return result;
}
function getTracksWithWidestRange(trackArr) {
var max = 0;
var result = [];
var tmp;
trackArr.forEach(function (track) {
tmp = track.representationCount;
if (tmp > max) {
max = tmp;
result = [track];
} else if (tmp === max) {
result.push(track);
}
});
return result;
}
function setCustomInitialTrackSelectionFunction(customFunc) {
customInitialTrackSelectionFunction = customFunc;
}
function selectInitialTrack(type, tracks) {
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) return tracks[0];
var mode = settings.get().streaming.selectionModeForInitialTrack;
var tmpArr;
if (customInitialTrackSelectionFunction && typeof customInitialTrackSelectionFunction === 'function') {
tmpArr = customInitialTrackSelectionFunction(tracks);
} else {
switch (mode) {
case _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TRACK_SELECTION_MODE_HIGHEST_SELECTION_PRIORITY:
tmpArr = _trackSelectionModeHighestSelectionPriority(tracks);
break;
case _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TRACK_SELECTION_MODE_HIGHEST_BITRATE:
tmpArr = _trackSelectionModeHighestBitrate(tracks);
break;
case _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TRACK_SELECTION_MODE_FIRST_TRACK:
tmpArr = _trackSelectionModeFirstTrack(tracks);
break;
case _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TRACK_SELECTION_MODE_HIGHEST_EFFICIENCY:
tmpArr = _trackSelectionModeHighestEfficiency(tracks);
break;
case _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TRACK_SELECTION_MODE_WIDEST_RANGE:
tmpArr = _trackSelectionModeWidestRange(tracks);
break;
default:
logger.warn("Track selection mode ".concat(mode, " is not supported. Falling back to TRACK_SELECTION_MODE_FIRST_TRACK"));
tmpArr = _trackSelectionModeFirstTrack(tracks);
break;
}
}
return tmpArr.length > 0 ? tmpArr[0] : tracks[0];
}
function _trackSelectionModeHighestSelectionPriority(tracks) {
var tmpArr = getTracksWithHighestSelectionPriority(tracks);
if (tmpArr.length > 1) {
tmpArr = getTracksWithHighestBitrate(tmpArr);
}
if (tmpArr.length > 1) {
tmpArr = getTracksWithWidestRange(tmpArr);
}
return tmpArr;
}
function _trackSelectionModeHighestBitrate(tracks) {
var tmpArr = getTracksWithHighestBitrate(tracks);
if (tmpArr.length > 1) {
tmpArr = getTracksWithWidestRange(tmpArr);
}
return tmpArr;
}
function _trackSelectionModeFirstTrack(tracks) {
return tracks[0];
}
function _trackSelectionModeHighestEfficiency(tracks) {
var tmpArr = getTracksWithHighestEfficiency(tracks);
if (tmpArr.length > 1) {
tmpArr = getTracksWithHighestBitrate(tmpArr);
}
return tmpArr;
}
function _trackSelectionModeWidestRange(tracks) {
var tmpArr = getTracksWithWidestRange(tracks);
if (tmpArr.length > 1) {
tmpArr = getTracksWithHighestBitrate(tracks);
}
return tmpArr;
}
function createTrackInfo() {
return {
audio: {
list: [],
storeLastSettings: true,
current: null
},
video: {
list: [],
storeLastSettings: true,
current: null
},
text: {
list: [],
storeLastSettings: true,
current: null
},
image: {
list: [],
storeLastSettings: true,
current: null
}
};
}
instance = {
setInitialMediaSettingsForType: setInitialMediaSettingsForType,
addTrack: addTrack,
getTracksFor: getTracksFor,
getCurrentTrackFor: getCurrentTrackFor,
isCurrentTrack: isCurrentTrack,
setTrack: setTrack,
selectInitialTrack: selectInitialTrack,
setCustomInitialTrackSelectionFunction: setCustomInitialTrackSelectionFunction,
setInitialSettings: setInitialSettings,
getInitialSettings: getInitialSettings,
getTracksWithHighestBitrate: getTracksWithHighestBitrate,
getTracksWithHighestEfficiency: getTracksWithHighestEfficiency,
getTracksWithWidestRange: getTracksWithWidestRange,
isTracksEqual: isTracksEqual,
matchSettings: matchSettings,
saveTextSettingsDisabled: saveTextSettingsDisabled,
setConfig: setConfig,
reset: reset
};
setup();
return instance;
}
MediaController.__dashjs_factory_name = 'MediaController';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__["default"].getSingletonFactory(MediaController);
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__["default"].updateSingletonFactory(MediaController.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/controllers/MediaSourceController.js":
/*!************************************************************!*\
!*** ./src/streaming/controllers/MediaSourceController.js ***!
\************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MediaSourceController() {
var instance, mediaSource, logger;
var context = this.context;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
}
function createMediaSource() {
var hasWebKit = ('WebKitMediaSource' in window);
var hasMediaSource = ('MediaSource' in window);
if (hasMediaSource) {
mediaSource = new MediaSource();
} else if (hasWebKit) {
mediaSource = new WebKitMediaSource();
}
return mediaSource;
}
function attachMediaSource(videoModel) {
var objectURL = window.URL.createObjectURL(mediaSource);
videoModel.setSource(objectURL);
return objectURL;
}
function detachMediaSource(videoModel) {
videoModel.setSource(null);
}
function setDuration(value) {
if (!mediaSource || mediaSource.readyState !== 'open') return;
if (value === null && isNaN(value)) return;
if (mediaSource.duration === value) return;
if (!isBufferUpdating(mediaSource)) {
logger.info('Set MediaSource duration:' + value);
mediaSource.duration = value;
} else {
setTimeout(setDuration.bind(null, value), 50);
}
}
function setSeekable(start, end) {
if (mediaSource && typeof mediaSource.setLiveSeekableRange === 'function' && typeof mediaSource.clearLiveSeekableRange === 'function' && mediaSource.readyState === 'open' && start >= 0 && start < end) {
mediaSource.clearLiveSeekableRange();
mediaSource.setLiveSeekableRange(start, end);
}
}
function signalEndOfStream(source) {
if (!source || source.readyState !== 'open') {
return;
}
var buffers = source.sourceBuffers;
for (var i = 0; i < buffers.length; i++) {
if (buffers[i].updating) {
return;
}
if (buffers[i].buffered.length === 0) {
return;
}
}
logger.info('call to mediaSource endOfStream');
source.endOfStream();
}
function isBufferUpdating(source) {
var buffers = source.sourceBuffers;
for (var i = 0; i < buffers.length; i++) {
if (buffers[i].updating) {
return true;
}
}
return false;
}
instance = {
createMediaSource: createMediaSource,
attachMediaSource: attachMediaSource,
detachMediaSource: detachMediaSource,
setDuration: setDuration,
setSeekable: setSeekable,
signalEndOfStream: signalEndOfStream
};
setup();
return instance;
}
MediaSourceController.__dashjs_factory_name = 'MediaSourceController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(MediaSourceController));
/***/ }),
/***/ "./src/streaming/controllers/PlaybackController.js":
/*!*********************************************************!*\
!*** ./src/streaming/controllers/PlaybackController.js ***!
\*********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var LIVE_UPDATE_PLAYBACK_TIME_INTERVAL_MS = 500;
function PlaybackController() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
var instance, logger, streamController, dashMetrics, adapter, videoModel, timelineConverter, wallclockTimeIntervalId, liveDelay, streamInfo, isDynamic, mediaPlayerModel, playOnceInitialized, lastLivePlaybackTime, availabilityStartTime, seekTarget, internalSeek, isLowLatencySeekingInProgress, playbackStalled, minPlaybackRateChange, manifestUpdateInProgress, settings;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance().getLogger(instance);
reset();
}
/**
* Initializes the PlaybackController. This function is called whenever the stream is switched.
* @param {object} sInfo
* @param {boolean} periodSwitch
*/
function initialize(sInfo, periodSwitch) {
streamInfo = sInfo;
if (periodSwitch !== true) {
_initializeForFirstStream();
}
}
/**
* Initializes the PlaybackController when the first stream is to be played.
* @private
*/
function _initializeForFirstStream() {
addAllListeners();
isDynamic = streamInfo.manifestInfo.isDynamic;
isLowLatencySeekingInProgress = false;
playbackStalled = false;
internalSeek = false; // Detect safari browser (special behavior for low latency streams)
var ua = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase() : '';
var isSafari = /safari/.test(ua) && !/chrome/.test(ua);
minPlaybackRateChange = isSafari ? 0.25 : 0.02;
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].DATA_UPDATE_COMPLETED, _onDataUpdateCompleted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].LOADING_PROGRESS, _onFragmentLoadProgress, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].MANIFEST_UPDATED, _onManifestUpdated, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].STREAMS_COMPOSED, _onStreamsComposed, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance, {
priority: _core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"].EVENT_PRIORITY_HIGH
});
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_INITIALIZING, _onStreamInitializing, instance);
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].REPRESENTATION_SWITCH, _onRepresentationSwitch, instance);
if (playOnceInitialized) {
playOnceInitialized = false;
play();
}
}
function getTimeToStreamEnd() {
var sInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
return parseFloat((getStreamEndTime(sInfo) - getTime()).toFixed(5));
}
function getStreamEndTime(sInfo) {
var refInfo = sInfo ? sInfo : streamInfo;
return refInfo.start + refInfo.duration;
}
function play() {
if (streamInfo && videoModel && videoModel.getElement()) {
videoModel.play();
} else {
playOnceInitialized = true;
}
}
function isPaused() {
return streamInfo && videoModel ? videoModel.isPaused() : null;
}
function pause() {
if (streamInfo && videoModel) {
videoModel.pause();
}
}
function isSeeking() {
return streamInfo && videoModel ? videoModel.isSeeking() : null;
}
function isStalled() {
return streamInfo && videoModel ? videoModel.isStalled() : null;
}
function seek(time, stickToBuffered, internal) {
if (!streamInfo || !videoModel) return;
var currentTime = !isNaN(seekTarget) ? seekTarget : videoModel.getTime();
if (time === currentTime) return;
internalSeek = internal === true;
if (!internalSeek) {
seekTarget = time;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_SEEK_ASKED);
}
logger.info('Requesting seek to time: ' + time + (internalSeek ? ' (internal)' : ''));
videoModel.setCurrentTime(time, stickToBuffered);
}
function seekToLive() {
var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO;
var DVRMetrics = dashMetrics.getCurrentDVRInfo(type);
var DVRWindow = DVRMetrics ? DVRMetrics.range : null;
if (DVRWindow && !isNaN(DVRWindow.end)) {
seek(DVRWindow.end - mediaPlayerModel.getLiveDelay(), true, false);
}
}
function getTime() {
return streamInfo && videoModel ? videoModel.getTime() : null;
}
function getNormalizedTime() {
var t = getTime();
if (isDynamic && !isNaN(availabilityStartTime)) {
var timeOffset = availabilityStartTime / 1000; // Fix current time for firefox and safari (returned as an absolute time)
if (t > timeOffset) {
t -= timeOffset;
}
}
return t;
}
function getPlaybackRate() {
return streamInfo && videoModel ? videoModel.getPlaybackRate() : null;
}
function getPlayedRanges() {
return streamInfo && videoModel ? videoModel.getPlayedRanges() : null;
}
function getEnded() {
return streamInfo && videoModel ? videoModel.getEnded() : null;
}
function getIsDynamic() {
return isDynamic;
}
function getStreamController() {
return streamController;
}
function getIsManifestUpdateInProgress() {
return manifestUpdateInProgress;
}
/**
* Computes the desirable delay for the live edge to avoid a risk of getting 404 when playing at the bleeding edge
* @param {number} fragmentDuration - seconds?
* @param {object} manifestInfo
* @returns {number} object
* @memberof PlaybackController#
*/
function computeAndSetLiveDelay(fragmentDuration, manifestInfo) {
var delay, ret, startTime;
var END_OF_PLAYLIST_PADDING = 10;
var MIN_BUFFER_TIME_FACTOR = 4;
var FRAGMENT_DURATION_FACTOR = 4;
var adjustedFragmentDuration = !isNaN(fragmentDuration) && isFinite(fragmentDuration) ? fragmentDuration : NaN;
var suggestedPresentationDelay = adapter.getSuggestedPresentationDelay(); // Apply live delay from ServiceDescription
if (settings.get().streaming.delay.applyServiceDescription && isNaN(settings.get().streaming.delay.liveDelay) && isNaN(settings.get().streaming.delay.liveDelayFragmentCount)) {
_applyServiceDescription(manifestInfo);
}
if (mediaPlayerModel.getLiveDelay()) {
delay = mediaPlayerModel.getLiveDelay(); // If set by user, this value takes precedence
} else if (settings.get().streaming.delay.liveDelayFragmentCount !== null && !isNaN(settings.get().streaming.delay.liveDelayFragmentCount) && !isNaN(adjustedFragmentDuration)) {
delay = adjustedFragmentDuration * settings.get().streaming.delay.liveDelayFragmentCount;
} else if (settings.get().streaming.delay.useSuggestedPresentationDelay === true && suggestedPresentationDelay !== null && !isNaN(suggestedPresentationDelay) && suggestedPresentationDelay > 0) {
delay = suggestedPresentationDelay;
} else if (!isNaN(adjustedFragmentDuration)) {
delay = adjustedFragmentDuration * FRAGMENT_DURATION_FACTOR;
} else {
delay = manifestInfo && !isNaN(manifestInfo.minBufferTime) ? manifestInfo.minBufferTime * MIN_BUFFER_TIME_FACTOR : streamInfo.manifestInfo.minBufferTime * MIN_BUFFER_TIME_FACTOR;
}
startTime = adapter.getAvailabilityStartTime();
if (startTime !== null) {
availabilityStartTime = startTime;
}
if (manifestInfo && manifestInfo.dvrWindowSize > 0) {
// cap target latency to:
// - dvrWindowSize / 2 for short playlists
// - dvrWindowSize - END_OF_PLAYLIST_PADDING for longer playlists
var targetDelayCapping = Math.max(manifestInfo.dvrWindowSize - END_OF_PLAYLIST_PADDING, manifestInfo.dvrWindowSize / 2);
ret = Math.min(delay, targetDelayCapping);
} else {
ret = delay;
}
liveDelay = ret;
return ret;
}
function _applyServiceDescription(manifestInfo) {
if (!manifestInfo || !manifestInfo.serviceDescriptions) {
return;
}
var llsd = null;
for (var i = 0; i < manifestInfo.serviceDescriptions.length; i++) {
var sd = manifestInfo.serviceDescriptions[i];
if (sd.schemeIdUri === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SERVICE_DESCRIPTION_LL_SCHEME) {
llsd = sd;
break;
}
}
if (llsd) {
if (llsd.latency && llsd.latency.target > 0) {
logger.debug('Apply LL properties coming from service description. Target Latency (ms):', llsd.latency.target);
settings.update({
streaming: {
delay: {
liveDelay: llsd.latency.target / 1000
},
liveCatchup: {
minDrift: (llsd.latency.target + 500) / 1000,
maxDrift: llsd.latency.max > llsd.latency.target ? (llsd.latency.max - llsd.latency.target + 500) / 1000 : undefined
}
}
});
}
if (llsd.playbackRate && llsd.playbackRate.max > 1.0) {
logger.debug('Apply LL properties coming from service description. Max PlaybackRate:', llsd.playbackRate.max);
settings.update({
streaming: {
liveCatchup: {
playbackRate: llsd.playbackRate.max - 1.0
}
}
});
}
}
}
function getAvailabilityStartTime() {
return availabilityStartTime;
}
function getLiveDelay() {
return liveDelay;
}
function getCurrentLiveLatency() {
if (!isDynamic || isNaN(availabilityStartTime)) {
return NaN;
}
var currentTime = getNormalizedTime();
if (isNaN(currentTime) || currentTime === 0) {
return 0;
}
var now = new Date().getTime() + timelineConverter.getClientTimeOffset() * 1000;
return Math.max(((now - availabilityStartTime - currentTime * 1000) / 1000).toFixed(3), 0);
}
function reset() {
pause();
playOnceInitialized = false;
liveDelay = 0;
availabilityStartTime = 0;
manifestUpdateInProgress = false;
seekTarget = NaN;
if (videoModel) {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].DATA_UPDATE_COMPLETED, _onDataUpdateCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].LOADING_PROGRESS, _onFragmentLoadProgress, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].MANIFEST_UPDATED, _onManifestUpdated, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].STREAMS_COMPOSED, _onStreamsComposed, instance);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, instance);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, instance);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].STREAM_INITIALIZING, _onStreamInitializing, instance);
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_6__["default"].REPRESENTATION_SWITCH, _onRepresentationSwitch, instance);
videoModel.setPlaybackRate(1.0, true);
stopUpdatingWallclockTime();
removeAllListeners();
}
wallclockTimeIntervalId = null;
videoModel = null;
streamInfo = null;
isDynamic = null;
}
function setConfig(config) {
if (!config) return;
if (config.streamController) {
streamController = config.streamController;
}
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
if (config.mediaPlayerModel) {
mediaPlayerModel = config.mediaPlayerModel;
}
if (config.adapter) {
adapter = config.adapter;
}
if (config.videoModel) {
videoModel = config.videoModel;
}
if (config.timelineConverter) {
timelineConverter = config.timelineConverter;
}
if (config.settings) {
settings = config.settings;
}
}
function getActualPresentationTime(currentTime, mediatype) {
var DVRMetrics = dashMetrics.getCurrentDVRInfo(mediatype);
var DVRWindow = DVRMetrics ? DVRMetrics.range : null;
var actualTime;
if (!DVRWindow) {
return NaN;
}
if (currentTime > DVRWindow.end) {
actualTime = Math.max(DVRWindow.end - liveDelay, DVRWindow.start);
} else if (currentTime > 0 && currentTime + 0.250 < DVRWindow.start && Math.abs(currentTime - DVRWindow.start) < 315360000) {
// Checking currentTime plus 250ms as the 'timeupdate' is fired with a frequency between 4Hz and 66Hz
// https://developer.mozilla.org/en-US/docs/Web/Events/timeupdate
// http://w3c.github.io/html/single-page.html#offsets-into-the-media-resource
// Checking also duration of the DVR makes sense. We detected temporary situations in which currentTime
// is bad reported by the browser which causes playback to jump to start (315360000 = 1 year)
if (settings.get().streaming.lowLatencyEnabled) {
actualTime = Math.max(DVRWindow.end - liveDelay, DVRWindow.start);
} else {
actualTime = DVRWindow.start;
}
} else {
actualTime = currentTime;
}
return actualTime;
}
function startUpdatingWallclockTime() {
if (wallclockTimeIntervalId !== null) return;
var tick = function tick() {
_onWallclockTime();
};
wallclockTimeIntervalId = setInterval(tick, settings.get().streaming.wallclockTimeUpdateInterval);
}
function stopUpdatingWallclockTime() {
clearInterval(wallclockTimeIntervalId);
wallclockTimeIntervalId = null;
}
/**
* Compare the current time of the video against the DVR window. If we are out of the DVR window we need to seek.
* @param {object} mediaType
*/
function updateCurrentTime() {
var mediaType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
if (isPaused() || !isDynamic || videoModel.getReadyState() === 0 || isSeeking() || manifestUpdateInProgress) return; // Note: In some cases we filter certain media types completely (for instance due to an unsupported video codec). This happens after the first entry to the DVR metric has been added.
// Now the DVR window for the filtered media type is not updated anymore. Consequently, always use a mediaType that is available to get a valid DVR window.
if (!mediaType) {
mediaType = streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO;
} // Compare the current time of the video element against the range defined in the DVR window.
var currentTime = getNormalizedTime();
var actualTime = getActualPresentationTime(currentTime, mediaType);
var timeChanged = !isNaN(actualTime) && actualTime !== currentTime;
if (timeChanged && !isSeeking() && (isStalled() || playbackStalled || videoModel.getReadyState() === 1)) {
logger.debug("UpdateCurrentTime: Seek to actual time: ".concat(actualTime, " from currentTime: ").concat(currentTime));
seek(actualTime);
}
}
function _onDataUpdateCompleted(e) {
var representationInfo = adapter.convertRepresentationToRepresentationInfo(e.currentRepresentation);
var info = representationInfo ? representationInfo.mediaInfo.streamInfo : null;
if (info === null || streamInfo.id !== info.id) return;
streamInfo = info;
}
function _onCanPlay() {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].CAN_PLAY);
}
function _onCanPlayThrough() {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].CAN_PLAY_THROUGH);
}
function _onPlaybackStart() {
logger.info('Native video element event: play');
updateCurrentTime();
startUpdatingWallclockTime();
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_STARTED, {
startTime: getTime()
});
}
function _onPlaybackWaiting() {
logger.info('Native video element event: waiting');
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_WAITING, {
playingTime: getTime()
});
}
function _onPlaybackPlaying() {
logger.info('Native video element event: playing');
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_PLAYING, {
playingTime: getTime()
});
}
function _onPlaybackPaused() {
logger.info('Native video element event: pause');
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_PAUSED, {
ended: getEnded()
});
}
function _onPlaybackSeeking() {
// Check if internal seeking to be ignored
if (internalSeek) {
internalSeek = false;
return;
}
var seekTime = getTime(); // On some browsers/devices, in case of live streams, setting current time on video element fails when there is no buffered data at requested time
// Then re-set seek target time and video element will be seeked afterwhile once data is buffered (see BufferContoller)
if (!isNaN(seekTarget) && seekTarget !== seekTime) {
seekTime = seekTarget;
}
seekTarget = NaN;
logger.info('Seeking to: ' + seekTime);
startUpdatingWallclockTime();
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_SEEKING, {
seekTime: seekTime,
streamId: streamInfo.id
});
}
function _onPlaybackSeeked() {
logger.info('Native video element event: seeked');
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_SEEKED);
}
function _onPlaybackTimeUpdated() {
if (streamInfo) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_TIME_UPDATED, {
timeToEnd: getTimeToStreamEnd(),
time: getTime(),
streamId: streamInfo.id
});
}
}
function _onPlaybackProgress() {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_PROGRESS, {
streamId: streamInfo.id
});
}
function _onPlaybackRateChanged() {
var rate = getPlaybackRate();
logger.info('Native video element event: ratechange: ', rate);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_RATE_CHANGED, {
playbackRate: rate
});
}
function _onPlaybackMetaDataLoaded() {
logger.info('Native video element event: loadedmetadata');
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_METADATA_LOADED);
startUpdatingWallclockTime();
}
function _onPlaybackLoadedData() {
logger.info('Native video element event: loadeddata');
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_LOADED_DATA);
} // Event to handle the native video element ended event
function _onNativePlaybackEnded() {
logger.info('Native video element event: ended');
pause();
stopUpdatingWallclockTime();
var streamInfo = streamController ? streamController.getActiveStreamInfo() : null;
if (!streamInfo) return;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_ENDED, {
'isLast': streamInfo.isLast
});
} // Handle DASH PLAYBACK_ENDED event
function _onPlaybackEnded(e) {
if (wallclockTimeIntervalId && e.isLast) {
// PLAYBACK_ENDED was triggered elsewhere, react.
logger.info('onPlaybackEnded -- PLAYBACK_ENDED but native video element didn\'t fire ended');
var seekTime = e.seekTime ? e.seekTime : getStreamEndTime();
videoModel.setCurrentTime(seekTime);
pause();
stopUpdatingWallclockTime();
}
}
function _onPlaybackError(event) {
var target = event.target || event.srcElement;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_ERROR, {
error: target.error
});
}
function _onWallclockTime() {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].WALLCLOCK_TIME_UPDATED, {
isDynamic: isDynamic,
time: new Date()
}); // Updates playback time for paused dynamic streams
// (video element doesn't call timeupdate when the playback is paused)
if (getIsDynamic()) {
streamController.addDVRMetric();
if (isPaused()) {
_updateLivePlaybackTime();
} else {
updateCurrentTime();
}
}
}
function _updateLivePlaybackTime() {
var now = Date.now();
if (!lastLivePlaybackTime || now > lastLivePlaybackTime + LIVE_UPDATE_PLAYBACK_TIME_INTERVAL_MS) {
lastLivePlaybackTime = now;
_onPlaybackTimeUpdated();
}
}
function _onPlaybackProgression() {
if (isDynamic && _isCatchupEnabled() && settings.get().streaming.liveCatchup.playbackRate > 0 && !isPaused() && !isSeeking()) {
if (_needToCatchUp()) {
startPlaybackCatchUp();
} else {
stopPlaybackCatchUp();
}
}
}
function _isCatchupEnabled() {
return settings.get().streaming.liveCatchup.enabled || settings.get().streaming.lowLatencyEnabled;
}
function getBufferLevel() {
var bufferLevel = null;
streamController.getActiveStreamProcessors().forEach(function (p) {
var bl = p.getBufferLevel();
if (bufferLevel === null) {
bufferLevel = bl;
} else {
bufferLevel = Math.min(bufferLevel, bl);
}
});
return bufferLevel;
}
/**
* Returns the mode for live playback catchup.
* @return {String}
* @private
*/
function _getCatchupMode() {
var playbackBufferMin = settings.get().streaming.liveCatchup.playbackBufferMin;
return settings.get().streaming.liveCatchup.mode === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LIVE_CATCHUP_MODE_LOLP && playbackBufferMin !== null && !isNaN(playbackBufferMin) ? _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LIVE_CATCHUP_MODE_LOLP : _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LIVE_CATCHUP_MODE_DEFAULT;
}
/**
* Checks whether the catchup mechanism should be enabled
* @return {boolean}
*/
function _needToCatchUp() {
try {
if (_isCatchupEnabled() && settings.get().streaming.liveCatchup.playbackRate > 0 && getTime() > 0) {
var catchupMode = _getCatchupMode();
var currentLiveLatency = getCurrentLiveLatency();
var _liveDelay = mediaPlayerModel.getLiveDelay();
var liveCatchupLatencyThreshold = mediaPlayerModel.getLiveCatchupLatencyThreshold();
var liveCatchUpMinDrift = settings.get().streaming.liveCatchup.minDrift;
if (catchupMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LIVE_CATCHUP_MODE_LOLP) {
var currentBuffer = getBufferLevel();
var playbackBufferMin = settings.get().streaming.liveCatchup.playbackBufferMin;
return _lolpNeedToCatchUpCustom(currentLiveLatency, _liveDelay, liveCatchUpMinDrift, currentBuffer, playbackBufferMin, liveCatchupLatencyThreshold);
} else {
return _defaultNeedToCatchUp(currentLiveLatency, _liveDelay, liveCatchupLatencyThreshold, liveCatchUpMinDrift);
}
}
} catch (e) {
return false;
}
}
/**
* Default algorithm to determine if catchup mode should be enabled
* @param {number} currentLiveLatency
* @param {number} liveDelay
* @param {number} liveCatchupLatencyThreshold
* @param {number} minDrift
* @return {boolean}
* @private
*/
function _defaultNeedToCatchUp(currentLiveLatency, liveDelay, liveCatchupLatencyThreshold, minDrift) {
try {
var latencyDrift = Math.abs(currentLiveLatency - liveDelay);
return latencyDrift > minDrift && (isNaN(liveCatchupLatencyThreshold) || currentLiveLatency <= liveCatchupLatencyThreshold);
} catch (e) {
return false;
}
}
/**
* LoL+ logic to determine if catchup mode should be enabled
* @param {number} currentLiveLatency
* @param {number} liveDelay
* @param {number} minDrift
* @param {number} currentBuffer
* @param {number} playbackBufferMin
* @param {number} liveCatchupLatencyThreshold
* @return {boolean}
* @private
*/
function _lolpNeedToCatchUpCustom(currentLiveLatency, liveDelay, minDrift, currentBuffer, playbackBufferMin, liveCatchupLatencyThreshold) {
try {
var latencyDrift = Math.abs(currentLiveLatency - liveDelay);
return (isNaN(liveCatchupLatencyThreshold) || currentLiveLatency <= liveCatchupLatencyThreshold) && (latencyDrift > minDrift || currentBuffer < playbackBufferMin);
} catch (e) {
return false;
}
}
/**
* Apply catchup mode
*/
function startPlaybackCatchUp() {
if (videoModel) {
var results;
var currentPlaybackRate = videoModel.getPlaybackRate();
var liveCatchupPlaybackRate = settings.get().streaming.liveCatchup.playbackRate;
var currentLiveLatency = getCurrentLiveLatency();
var _liveDelay2 = mediaPlayerModel.getLiveDelay();
var bufferLevel = getBufferLevel(); // Custom playback control: Based on buffer level
if (_getCatchupMode() === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].LIVE_CATCHUP_MODE_LOLP) {
var liveCatchUpMinDrift = settings.get().streaming.liveCatchup.minDrift;
var playbackBufferMin = settings.get().streaming.liveCatchup.playbackBufferMin;
results = _calculateNewPlaybackRateLolP(liveCatchupPlaybackRate, currentLiveLatency, _liveDelay2, liveCatchUpMinDrift, playbackBufferMin, bufferLevel, currentPlaybackRate);
} else {
// Default playback control: Based on target and current latency
results = _calculateNewPlaybackRateDefault(liveCatchupPlaybackRate, currentLiveLatency, _liveDelay2, bufferLevel, currentPlaybackRate);
} // Obtain newRate and apply to video model
var newRate = results.newRate;
if (newRate) {
// non-null
videoModel.setPlaybackRate(newRate);
}
var deltaLatency = currentLiveLatency - _liveDelay2;
if (settings.get().streaming.liveCatchup.maxDrift > 0 && !isLowLatencySeekingInProgress && deltaLatency > settings.get().streaming.liveCatchup.maxDrift) {
logger.info('Low Latency catchup mechanism. Latency too high, doing a seek to live point');
isLowLatencySeekingInProgress = true;
seekToLive();
} else {
isLowLatencySeekingInProgress = false;
}
}
}
/**
* Default algorithm to calculate the new playback rate
* @param {number} liveCatchUpPlaybackRate
* @param {number} currentLiveLatency
* @param {number} liveDelay
* @param {number} bufferLevel
* @param {number} currentPlaybackRate
* @return {{newRate: number}}
* @private
*/
function _calculateNewPlaybackRateDefault(liveCatchUpPlaybackRate, currentLiveLatency, liveDelay, bufferLevel, currentPlaybackRate) {
var cpr = liveCatchUpPlaybackRate;
var deltaLatency = currentLiveLatency - liveDelay;
var d = deltaLatency * 5; // Playback rate must be between (1 - cpr) - (1 + cpr)
// ex: if cpr is 0.5, it can have values between 0.5 - 1.5
var s = cpr * 2 / (1 + Math.pow(Math.E, -d));
var newRate = 1 - cpr + s; // take into account situations in which there are buffer stalls,
// in which increasing playbackRate to reach target latency will
// just cause more and more stall situations
if (playbackStalled) {
// const bufferLevel = getBufferLevel();
if (bufferLevel > liveDelay / 2) {
// playbackStalled = false;
playbackStalled = false;
} else if (deltaLatency > 0) {
newRate = 1.0;
}
} // don't change playbackrate for small variations (don't overload element with playbackrate changes)
if (Math.abs(currentPlaybackRate - newRate) <= minPlaybackRateChange) {
newRate = null;
}
return {
newRate: newRate
};
}
/**
* Lol+ algorithm to calculate the new playback rate
* @param {number} liveCatchUpPlaybackRate
* @param {number} currentLiveLatency
* @param {number} liveDelay
* @param {number} minDrift
* @param {number} playbackBufferMin
* @param {number} bufferLevel
* @param {number} currentPlaybackRate
* @return {{newRate: number}}
* @private
*/
function _calculateNewPlaybackRateLolP(liveCatchUpPlaybackRate, currentLiveLatency, liveDelay, minDrift, playbackBufferMin, bufferLevel, currentPlaybackRate) {
var cpr = liveCatchUpPlaybackRate;
var newRate; // Hybrid: Buffer-based
if (bufferLevel < playbackBufferMin) {
// Buffer in danger, slow down
var deltaBuffer = bufferLevel - playbackBufferMin; // -ve value
var d = deltaBuffer * 5; // Playback rate must be between (1 - cpr) - (1 + cpr)
// ex: if cpr is 0.5, it can have values between 0.5 - 1.5
var s = cpr * 2 / (1 + Math.pow(Math.E, -d));
newRate = 1 - cpr + s;
logger.debug('[LoL+ playback control_buffer-based] bufferLevel: ' + bufferLevel + ', newRate: ' + newRate);
} else {
// Hybrid: Latency-based
// Buffer is safe, vary playback rate based on latency
// Check if latency is within range of target latency
var minDifference = 0.02;
if (Math.abs(currentLiveLatency - liveDelay) <= minDifference * liveDelay) {
newRate = 1;
} else {
var deltaLatency = currentLiveLatency - liveDelay;
var _d = deltaLatency * 5; // Playback rate must be between (1 - cpr) - (1 + cpr)
// ex: if cpr is 0.5, it can have values between 0.5 - 1.5
var _s = cpr * 2 / (1 + Math.pow(Math.E, -_d));
newRate = 1 - cpr + _s;
}
logger.debug('[LoL+ playback control_latency-based] latency: ' + currentLiveLatency + ', newRate: ' + newRate);
}
if (playbackStalled) {
if (bufferLevel > liveDelay / 2) {
playbackStalled = false;
}
} // don't change playbackrate for small variations (don't overload element with playbackrate changes)
if (Math.abs(currentPlaybackRate - newRate) <= minPlaybackRateChange) {
newRate = null;
}
return {
newRate: newRate
};
}
function stopPlaybackCatchUp() {
if (videoModel) {
videoModel.setPlaybackRate(1.0);
}
}
function _onFragmentLoadProgress(e) {
// If using fetch and stream mode is not available, readjust live latency so it is 20% higher than segment duration
if (e.stream === false && settings.get().streaming.lowLatencyEnabled && !isNaN(e.request.duration)) {
var minDelay = 1.2 * e.request.duration;
if (minDelay > mediaPlayerModel.getLiveDelay()) {
logger.warn('Browser does not support fetch API with StreamReader. Increasing live delay to be 20% higher than segment duration:', minDelay.toFixed(2));
settings.update({
streaming: {
delay: {
liveDelay: minDelay
}
}
});
}
}
}
function _onBufferLevelStateChanged(e) {
// do not stall playback when get an event from Stream that is not active
if (e.streamId !== streamInfo.id) return;
if (_isCatchupEnabled()) {
if (e.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_EMPTY && !isSeeking()) {
if (!playbackStalled) {
playbackStalled = true;
stopPlaybackCatchUp();
}
}
} else {
if (settings.get().streaming.buffer.setStallState) {
videoModel.setStallState(e.mediaType, e.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_EMPTY);
}
}
}
function onPlaybackStalled(e) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_STALLED, {
e: e
});
}
function _onStreamInitializing(e) {
_checkEnableLowLatency(e.mediaInfo);
}
/**
* We enable low latency playback if for the current representation availabilityTimeComplete is set to false
* @param e
* @private
*/
function _onRepresentationSwitch(e) {
var activeStreamInfo = streamController.getActiveStreamInfo();
if (!settings.get().streaming.lowLatencyEnabledByManifest || !e || !activeStreamInfo || !e.currentRepresentation || !e.streamId || e.streamId !== activeStreamInfo.id || !e.mediaType || e.mediaType !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO && e.mediaType !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO) {
return;
}
var lowLatencyEnabled = !e.currentRepresentation.availabilityTimeComplete;
if (lowLatencyEnabled) {
settings.update({
streaming: {
lowLatencyEnabled: lowLatencyEnabled
}
});
}
}
/**
* A new manifest has been loaded, updating is still in progress.
* @private
*/
function _onManifestUpdated() {
manifestUpdateInProgress = true;
}
/**
* Manifest update was completed
* @private
*/
function _onStreamsComposed() {
manifestUpdateInProgress = false;
}
function _checkEnableLowLatency(mediaInfo) {
if (mediaInfo && mediaInfo.supplementalProperties && mediaInfo.supplementalProperties[_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].SUPPLEMENTAL_PROPERTY_LL_SCHEME] === 'true') {
logger.debug('Low Latency critical SupplementalProperty set: Enabling low Latency');
settings.update({
streaming: {
lowLatencyEnabled: true
}
});
}
}
function addAllListeners() {
videoModel.addEventListener('canplay', _onCanPlay);
videoModel.addEventListener('canplaythrough', _onCanPlayThrough);
videoModel.addEventListener('play', _onPlaybackStart);
videoModel.addEventListener('waiting', _onPlaybackWaiting);
videoModel.addEventListener('playing', _onPlaybackPlaying);
videoModel.addEventListener('pause', _onPlaybackPaused);
videoModel.addEventListener('error', _onPlaybackError);
videoModel.addEventListener('seeking', _onPlaybackSeeking);
videoModel.addEventListener('seeked', _onPlaybackSeeked);
videoModel.addEventListener('timeupdate', _onPlaybackTimeUpdated);
videoModel.addEventListener('progress', _onPlaybackProgress);
videoModel.addEventListener('ratechange', _onPlaybackRateChanged);
videoModel.addEventListener('loadedmetadata', _onPlaybackMetaDataLoaded);
videoModel.addEventListener('loadeddata', _onPlaybackLoadedData);
videoModel.addEventListener('stalled', onPlaybackStalled);
videoModel.addEventListener('ended', _onNativePlaybackEnded);
}
function removeAllListeners() {
videoModel.removeEventListener('canplay', _onCanPlay);
videoModel.removeEventListener('canplaythrough', _onCanPlayThrough);
videoModel.removeEventListener('play', _onPlaybackStart);
videoModel.removeEventListener('waiting', _onPlaybackWaiting);
videoModel.removeEventListener('playing', _onPlaybackPlaying);
videoModel.removeEventListener('pause', _onPlaybackPaused);
videoModel.removeEventListener('error', _onPlaybackError);
videoModel.removeEventListener('seeking', _onPlaybackSeeking);
videoModel.removeEventListener('seeked', _onPlaybackSeeked);
videoModel.removeEventListener('timeupdate', _onPlaybackTimeUpdated);
videoModel.removeEventListener('progress', _onPlaybackProgress);
videoModel.removeEventListener('ratechange', _onPlaybackRateChanged);
videoModel.removeEventListener('loadedmetadata', _onPlaybackMetaDataLoaded);
videoModel.removeEventListener('loadeddata', _onPlaybackLoadedData);
videoModel.removeEventListener('stalled', onPlaybackStalled);
videoModel.removeEventListener('ended', _onNativePlaybackEnded);
}
instance = {
initialize: initialize,
setConfig: setConfig,
getTimeToStreamEnd: getTimeToStreamEnd,
getBufferLevel: getBufferLevel,
getTime: getTime,
getNormalizedTime: getNormalizedTime,
getIsManifestUpdateInProgress: getIsManifestUpdateInProgress,
getPlaybackRate: getPlaybackRate,
getPlayedRanges: getPlayedRanges,
getEnded: getEnded,
getIsDynamic: getIsDynamic,
getStreamController: getStreamController,
computeAndSetLiveDelay: computeAndSetLiveDelay,
getLiveDelay: getLiveDelay,
getCurrentLiveLatency: getCurrentLiveLatency,
play: play,
isPaused: isPaused,
pause: pause,
isSeeking: isSeeking,
getStreamEndTime: getStreamEndTime,
seek: seek,
reset: reset,
updateCurrentTime: updateCurrentTime,
getAvailabilityStartTime: getAvailabilityStartTime
};
setup();
return instance;
}
PlaybackController.__dashjs_factory_name = 'PlaybackController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__["default"].getSingletonFactory(PlaybackController));
/***/ }),
/***/ "./src/streaming/controllers/ScheduleController.js":
/*!*********************************************************!*\
!*** ./src/streaming/controllers/ScheduleController.js ***!
\*********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _models_FragmentModel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../models/FragmentModel */ "./src/streaming/models/FragmentModel.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ScheduleController(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
var dashMetrics = config.dashMetrics;
var mediaPlayerModel = config.mediaPlayerModel;
var fragmentModel = config.fragmentModel;
var abrController = config.abrController;
var playbackController = config.playbackController;
var textController = config.textController;
var type = config.type;
var bufferController = config.bufferController;
var settings = config.settings;
var instance, streamInfo, logger, currentRepresentationInfo, timeToLoadDelay, scheduleTimeout, hasVideoTrack, lastFragmentRequest, topQualityIndex, lastInitializedQuality, switchTrack, initSegmentRequired, checkPlaybackQuality;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance().getLogger(instance);
resetInitialSettings();
streamInfo = config.streamInfo;
}
function initialize(_hasVideoTrack) {
hasVideoTrack = _hasVideoTrack;
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].BYTES_APPENDED_END_FRAGMENT, _onBytesAppended, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].URL_RESOLUTION_FAILED, _onURLResolutionFailed, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_STARTED, _onPlaybackStarted, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
}
function getType() {
return type;
}
function getStreamId() {
return streamInfo.id;
}
function setCurrentRepresentation(representationInfo) {
currentRepresentationInfo = representationInfo;
}
function startScheduleTimer(value) {
if (bufferController.getIsBufferingCompleted()) return;
clearScheduleTimer();
var timeoutValue = !isNaN(value) ? value : 0;
scheduleTimeout = setTimeout(schedule, timeoutValue);
}
function clearScheduleTimer() {
if (scheduleTimeout) {
clearTimeout(scheduleTimeout);
scheduleTimeout = null;
}
}
function hasTopQualityChanged() {
var streamId = streamInfo.id;
var newTopQualityIndex = abrController.getMaxAllowedIndexFor(type, streamId);
if (isNaN(topQualityIndex) || topQualityIndex != newTopQualityIndex) {
logger.info('Top quality ' + type + ' index has changed from ' + topQualityIndex + ' to ' + newTopQualityIndex);
topQualityIndex = newTopQualityIndex;
return true;
}
return false;
}
/**
* Schedule the request for an init or a media segment
*/
function schedule() {
try {
// Check if we are supposed to stop scheduling
if (_shouldClearScheduleTimer()) {
clearScheduleTimer();
return;
}
if (_shouldScheduleNextRequest()) {
var qualityChange = false;
if (checkPlaybackQuality) {
// in case the playback quality is supposed to be changed, the corresponding StreamProcessor will update the currentRepresentation.
// The StreamProcessor will also start the schedule timer again once the quality switch has beeen prepared. Consequently, we only call _getNextFragment if the quality is not changed.
qualityChange = abrController.checkPlaybackQuality(type, streamInfo.id);
}
if (!qualityChange) {
_getNextFragment();
}
} else {
startScheduleTimer(settings.get().streaming.lowLatencyEnabled ? settings.get().streaming.scheduling.lowLatencyTimeout : settings.get().streaming.scheduling.defaultTimeout);
}
} catch (e) {
startScheduleTimer(settings.get().streaming.lowLatencyEnabled ? settings.get().streaming.scheduling.lowLatencyTimeout : settings.get().streaming.scheduling.defaultTimeout);
}
}
/**
* Triggers the events to start requesting an init or a media segment. This will be picked up by the corresponding StreamProcessor.
* @private
*/
function _getNextFragment() {
// A quality changed occured or we are switching the AdaptationSet. In that case we need to load a new init segment
if (initSegmentRequired || currentRepresentationInfo.quality !== lastInitializedQuality || switchTrack) {
if (switchTrack) {
logger.debug('Switch track for ' + type + ', representation id = ' + currentRepresentationInfo.id);
switchTrack = false;
} else {
logger.debug('Quality has changed, get init request for representationid = ' + currentRepresentationInfo.id);
}
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].INIT_FRAGMENT_NEEDED, {
representationId: currentRepresentationInfo.id,
sender: instance
}, {
streamId: streamInfo.id,
mediaType: type
});
checkPlaybackQuality = false;
initSegmentRequired = false;
} // Request a media segment instead
else {
logger.debug("Media segment needed for ".concat(type, " and stream id ").concat(streamInfo.id));
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_FRAGMENT_NEEDED, {}, {
streamId: streamInfo.id,
mediaType: type
});
checkPlaybackQuality = true;
}
}
/**
* Check if we need to stop scheduling for now.
* @return {boolean}
* @private
*/
function _shouldClearScheduleTimer() {
try {
return type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !textController.isTextEnabled() || playbackController.isPaused() && (!playbackController.getStreamController().getInitialPlayback() || !playbackController.getStreamController().getAutoPlay()) && !settings.get().streaming.scheduling.scheduleWhilePaused;
} catch (e) {
return false;
}
}
/**
* Check if we can start scheduling the next request
* @return {boolean}
* @private
*/
function _shouldScheduleNextRequest() {
try {
return currentRepresentationInfo && (isNaN(lastInitializedQuality) || switchTrack || hasTopQualityChanged() || _shouldBuffer());
} catch (e) {
return false;
}
}
/**
* Check if the current buffer level is below our buffer target.
* @return {boolean}
* @private
*/
function _shouldBuffer() {
if (!type || !currentRepresentationInfo) {
return true;
}
var bufferLevel = dashMetrics.getCurrentBufferLevel(type);
return bufferLevel < getBufferTarget();
}
/**
* Determine the buffer target depending on the type and whether we have audio and video AdaptationSets available
* @return {number}
*/
function getBufferTarget() {
var bufferTarget = NaN;
if (!type || !currentRepresentationInfo) {
return bufferTarget;
}
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) {
bufferTarget = _getBufferTargetForFragmentedText();
} else if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && hasVideoTrack) {
bufferTarget = _getBufferTargetForAudio();
} else {
bufferTarget = _getGenericBufferTarget();
}
return bufferTarget;
}
/**
* Returns the buffer target for fragmented text tracks
* @return {number}
* @private
*/
function _getBufferTargetForFragmentedText() {
try {
if (textController.isTextEnabled()) {
if (isNaN(currentRepresentationInfo.fragmentDuration)) {
//fragmentDuration of currentRepresentationInfo is not defined,
// call metrics function to have data in the latest scheduling info...
// if no metric, returns 0. In this case, rule will return false.
var schedulingInfo = dashMetrics.getCurrentSchedulingInfo(_constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__["default"].SCHEDULING_INFO);
return schedulingInfo ? schedulingInfo.duration : 0;
} else {
return currentRepresentationInfo.fragmentDuration;
}
} else {
// text is disabled, rule will return false
return 0;
}
} catch (e) {
return 0;
}
}
/**
* Returns the buffer target for audio tracks in case we have a video track available as well
* @return {number}
* @private
*/
function _getBufferTargetForAudio() {
try {
var videoBufferLevel = dashMetrics.getCurrentBufferLevel(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO); // For multiperiod we need to consider that audio and video segments might have different durations.
// This can lead to scenarios in which we completely buffered the video segments and the video buffer level for the current period is not changing anymore. However we might still need a small audio segment to finish buffering audio as well.
// If we set the buffer time of audio equal to the video buffer time scheduling for the remaining audio segment will only be triggered when audio fragmentDuration > videoBufferLevel. That will delay preloading of the upcoming period.
// Should find a better solution than just adding 1
if (isNaN(currentRepresentationInfo.fragmentDuration)) {
return videoBufferLevel + 1;
} else {
return Math.max(videoBufferLevel + 1, currentRepresentationInfo.fragmentDuration);
}
} catch (e) {
return 0;
}
}
/**
* Determines the generic buffer target, for instance for video tracks
* @return {number}
* @private
*/
function _getGenericBufferTarget() {
try {
var _streamInfo = currentRepresentationInfo.mediaInfo.streamInfo;
if (abrController.isPlayingAtTopQuality(_streamInfo)) {
var isLongFormContent = _streamInfo.manifestInfo.duration >= settings.get().streaming.buffer.longFormContentDurationThreshold;
return isLongFormContent ? settings.get().streaming.buffer.bufferTimeAtTopQualityLongForm : settings.get().streaming.buffer.bufferTimeAtTopQuality;
} else {
return mediaPlayerModel.getStableBufferTime();
}
} catch (e) {
return mediaPlayerModel.getStableBufferTime();
}
}
function setSwitchTrack(value) {
switchTrack = value;
}
function getSwitchStrack() {
return switchTrack;
}
function _onPlaybackTimeUpdated() {
_completeQualityChange(true);
}
function _completeQualityChange(trigger) {
if (playbackController && fragmentModel) {
var item = fragmentModel.getRequests({
state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_1__["default"].FRAGMENT_MODEL_EXECUTED,
time: playbackController.getTime(),
threshold: 0
})[0];
if (item && playbackController.getTime() >= item.startTime) {
if ((!lastFragmentRequest.mediaInfo || item.mediaInfo.type === lastFragmentRequest.mediaInfo.type && item.mediaInfo.id !== lastFragmentRequest.mediaInfo.id) && trigger) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].TRACK_CHANGE_RENDERED, {
mediaType: type,
oldMediaInfo: lastFragmentRequest.mediaInfo,
newMediaInfo: item.mediaInfo,
streamId: streamInfo.id
});
}
if ((item.quality !== lastFragmentRequest.quality || item.adaptationIndex !== lastFragmentRequest.adaptationIndex) && trigger) {
logger.debug("Quality change rendered for streamId ".concat(streamInfo.id, " and type ").concat(type));
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].QUALITY_CHANGE_RENDERED, {
mediaType: type,
oldQuality: lastFragmentRequest.quality,
newQuality: item.quality,
streamId: streamInfo.id
});
}
lastFragmentRequest = {
mediaInfo: item.mediaInfo,
quality: item.quality,
adaptationIndex: item.adaptationIndex
};
}
}
}
function _onBytesAppended(e) {
logger.debug("Appended bytes for ".concat(e.mediaType, " and stream id ").concat(streamInfo.id)); // we save the last initialized quality. That way we make sure that the media fragments we are about to append match the init segment
if (isNaN(e.index) || isNaN(lastInitializedQuality)) {
lastInitializedQuality = e.quality;
logger.info('[' + type + '] ' + 'lastInitializedRepresentationInfo changed to ' + e.quality);
}
startScheduleTimer(0);
}
function _onURLResolutionFailed() {
fragmentModel.abortRequests();
clearScheduleTimer();
}
function _onPlaybackStarted() {
if (!settings.get().streaming.scheduling.scheduleWhilePaused) {
startScheduleTimer();
}
}
function _onPlaybackRateChanged(e) {
dashMetrics.updatePlayListTraceMetrics({
playbackspeed: e.playbackRate.toString()
});
}
function setTimeToLoadDelay(value) {
timeToLoadDelay = value;
}
function getTimeToLoadDelay() {
return timeToLoadDelay;
}
function setCheckPlaybackQuality(value) {
checkPlaybackQuality = value;
}
function setInitSegmentRequired(value) {
initSegmentRequired = value;
}
function resetInitialSettings() {
checkPlaybackQuality = true;
timeToLoadDelay = 0;
lastInitializedQuality = NaN;
lastFragmentRequest = {
mediaInfo: undefined,
quality: NaN,
adaptationIndex: NaN
};
topQualityIndex = NaN;
switchTrack = false;
initSegmentRequired = false;
}
function reset() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].BYTES_APPENDED_END_FRAGMENT, _onBytesAppended, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].URL_RESOLUTION_FAILED, _onURLResolutionFailed, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_STARTED, _onPlaybackStarted, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
clearScheduleTimer();
_completeQualityChange(false);
resetInitialSettings();
streamInfo = null;
}
function getPlaybackController() {
return playbackController;
}
instance = {
initialize: initialize,
getType: getType,
getStreamId: getStreamId,
setCurrentRepresentation: setCurrentRepresentation,
setTimeToLoadDelay: setTimeToLoadDelay,
getTimeToLoadDelay: getTimeToLoadDelay,
setSwitchTrack: setSwitchTrack,
getSwitchStrack: getSwitchStrack,
startScheduleTimer: startScheduleTimer,
clearScheduleTimer: clearScheduleTimer,
reset: reset,
getBufferTarget: getBufferTarget,
getPlaybackController: getPlaybackController,
setCheckPlaybackQuality: setCheckPlaybackQuality,
setInitSegmentRequired: setInitSegmentRequired
};
setup();
return instance;
}
ScheduleController.__dashjs_factory_name = 'ScheduleController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__["default"].getClassFactory(ScheduleController));
/***/ }),
/***/ "./src/streaming/controllers/StreamController.js":
/*!*******************************************************!*\
!*** ./src/streaming/controllers/StreamController.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _Stream__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../Stream */ "./src/streaming/Stream.js");
/* harmony import */ var _ManifestUpdater__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../ManifestUpdater */ "./src/streaming/ManifestUpdater.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../vo/metrics/PlayList */ "./src/streaming/vo/metrics/PlayList.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _utils_InitCache__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils/InitCache */ "./src/streaming/utils/InitCache.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _TimeSyncController__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./TimeSyncController */ "./src/streaming/controllers/TimeSyncController.js");
/* harmony import */ var _MediaSourceController__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./MediaSourceController */ "./src/streaming/controllers/MediaSourceController.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _EventController__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./EventController */ "./src/streaming/controllers/EventController.js");
/* harmony import */ var _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../constants/ConformanceViolationConstants */ "./src/streaming/constants/ConformanceViolationConstants.js");
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var PLAYBACK_ENDED_TIMER_INTERVAL = 200;
var DVR_WAITING_OFFSET = 2;
function StreamController() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var instance, logger, capabilities, capabilitiesFilter, manifestUpdater, manifestLoader, manifestModel, adapter, dashMetrics, mediaSourceController, timeSyncController, baseURLController, segmentBaseController, uriFragmentModel, abrController, mediaController, eventController, initCache, urlUtils, errHandler, timelineConverter, streams, activeStream, protectionController, textController, protectionData, autoPlay, isStreamSwitchingInProgress, hasMediaError, hasInitialisationError, mediaSource, videoModel, playbackController, mediaPlayerModel, isPaused, initialPlayback, playbackEndedTimerInterval, bufferSinks, preloadingStreams, supportsChangeType, settings, firstLicenseIsFetched, waitForPlaybackStartTimeout, errorInformation;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance().getLogger(instance);
timeSyncController = Object(_TimeSyncController__WEBPACK_IMPORTED_MODULE_12__["default"])(context).getInstance();
mediaSourceController = Object(_MediaSourceController__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance();
initCache = Object(_utils_InitCache__WEBPACK_IMPORTED_MODULE_9__["default"])(context).getInstance();
urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
resetInitialSettings();
}
function initialize(autoPl, protData) {
_checkConfig();
autoPlay = autoPl;
protectionData = protData;
timelineConverter.initialize();
manifestUpdater = Object(_ManifestUpdater__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create();
manifestUpdater.setConfig({
manifestModel: manifestModel,
adapter: adapter,
manifestLoader: manifestLoader,
errHandler: errHandler,
settings: settings
});
manifestUpdater.initialize();
eventController = Object(_EventController__WEBPACK_IMPORTED_MODULE_16__["default"])(context).getInstance();
eventController.setConfig({
manifestUpdater: manifestUpdater,
playbackController: playbackController,
settings: settings
});
eventController.start();
timeSyncController.setConfig({
dashMetrics: dashMetrics,
baseURLController: baseURLController,
errHandler: errHandler,
settings: settings
});
timeSyncController.initialize();
if (protectionController) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PROTECTION_CREATED, {
controller: protectionController
});
protectionController.setMediaElement(videoModel.getElement());
if (protectionData) {
protectionController.setProtectionData(protectionData);
}
}
registerEvents();
}
function registerEvents() {
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_ERROR, _onPlaybackError, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_STARTED, _onPlaybackStarted, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_PAUSED, _onPlaybackPaused, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].METRIC_ADDED, _onMetricAdded, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].MANIFEST_VALIDITY_CHANGED, _onManifestValidityChanged, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_LEVEL_UPDATED, _onBufferLevelUpdated, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].QUALITY_CHANGE_REQUESTED, _onQualityChanged, instance);
if (_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].KEY_SESSION_UPDATED) {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].KEY_SESSION_UPDATED, _onKeySessionUpdated, instance);
}
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MANIFEST_UPDATED, _onManifestUpdated, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].STREAM_BUFFERING_COMPLETED, _onStreamBufferingCompleted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].TIME_SYNCHRONIZATION_COMPLETED, _onTimeSyncCompleted, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].CURRENT_TRACK_CHANGED, _onCurrentTrackChanged, instance);
}
function unRegisterEvents() {
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_ERROR, _onPlaybackError, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_STARTED, _onPlaybackStarted, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_PAUSED, _onPlaybackPaused, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].METRIC_ADDED, _onMetricAdded, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].MANIFEST_VALIDITY_CHANGED, _onManifestValidityChanged, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_LEVEL_UPDATED, _onBufferLevelUpdated, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].QUALITY_CHANGE_REQUESTED, _onQualityChanged, instance);
if (_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].KEY_SESSION_UPDATED) {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].KEY_SESSION_UPDATED, _onKeySessionUpdated, instance);
}
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MANIFEST_UPDATED, _onManifestUpdated, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].STREAM_BUFFERING_COMPLETED, _onStreamBufferingCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].TIME_SYNCHRONIZATION_COMPLETED, _onTimeSyncCompleted, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].CURRENT_TRACK_CHANGED, _onCurrentTrackChanged, instance);
}
/**
* When the UTC snychronization is completed we can compose the streams
* @private
*/
function _onTimeSyncCompleted()
/*e*/
{
_composeStreams();
}
/**
*
* @private
*/
function _onKeySessionUpdated() {
firstLicenseIsFetched = true;
}
/**
* Setup the stream objects after the stream start and each MPD reload. This function is called after the UTC sync has been done (TIME_SYNCHRONIZATION_COMPLETED)
* @private
*/
function _composeStreams() {
try {
var streamsInfo = adapter.getStreamsInfo();
if (!activeStream && streamsInfo.length === 0) {
throw new Error('There are no streams');
}
if (activeStream) {
dashMetrics.updateManifestUpdateInfo({
currentTime: playbackController.getTime(),
buffered: videoModel.getBufferRange(),
presentationStartTime: streamsInfo[0].start,
clientTimeOffset: timelineConverter.getClientTimeOffset()
});
} // Filter streams that are outdated and not included in the MPD anymore
if (streams.length > 0) {
_filterOutdatedStreams(streamsInfo);
}
var promises = [];
for (var i = 0, ln = streamsInfo.length; i < ln; i++) {
var streamInfo = streamsInfo[i];
promises.push(_initializeOrUpdateStream(streamInfo));
dashMetrics.addManifestUpdateStreamInfo(streamInfo);
}
Promise.all(promises).then(function () {
if (!activeStream) {
_initializeForFirstStream(streamsInfo);
}
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].STREAMS_COMPOSED); // Additional periods might have been added after an MPD update. Check again if we can start prebuffering.
_checkIfPrebufferingCanStart();
})["catch"](function (e) {
throw e;
});
} catch (e) {
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_15__["default"].MANIFEST_ERROR_ID_NOSTREAMS_CODE, e.message + 'nostreamscomposed', manifestModel.getValue()));
hasInitialisationError = true;
reset();
}
}
/**
* Called for each stream when composition is performed. Either a new instance of Stream is created or the existing one is updated.
* @param {object} streamInfo
* @private
*/
function _initializeOrUpdateStream(streamInfo) {
var stream = getStreamById(streamInfo.id); // If the Stream object does not exist we probably loaded the manifest the first time or it was
// introduced in the updated manifest, so we need to create a new Stream and perform all the initialization operations
if (!stream) {
stream = Object(_Stream__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
manifestModel: manifestModel,
mediaPlayerModel: mediaPlayerModel,
dashMetrics: dashMetrics,
manifestUpdater: manifestUpdater,
adapter: adapter,
timelineConverter: timelineConverter,
capabilities: capabilities,
capabilitiesFilter: capabilitiesFilter,
errHandler: errHandler,
baseURLController: baseURLController,
segmentBaseController: segmentBaseController,
textController: textController,
abrController: abrController,
playbackController: playbackController,
eventController: eventController,
mediaController: mediaController,
protectionController: protectionController,
videoModel: videoModel,
streamInfo: streamInfo,
settings: settings
});
streams.push(stream);
stream.initialize();
return Promise.resolve();
} else {
return stream.updateData(streamInfo);
}
}
/**
* Initialize playback for the first period.
* @param {object} streamsInfo
* @private
*/
function _initializeForFirstStream(streamsInfo) {
// Add the DVR window so we can calculate the right starting point
addDVRMetric(); // If the start is in the future we need to wait
var dvrRange = dashMetrics.getCurrentDVRInfo().range;
if (dvrRange.end < dvrRange.start) {
if (waitForPlaybackStartTimeout) {
clearTimeout(waitForPlaybackStartTimeout);
}
var waitingTime = Math.min(((dvrRange.end - dvrRange.start) * -1 + DVR_WAITING_OFFSET) * 1000, 2147483647);
logger.debug("Waiting for ".concat(waitingTime, " ms before playback can start"));
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].AST_IN_FUTURE, {
delay: waitingTime
});
waitForPlaybackStartTimeout = setTimeout(function () {
_initializeForFirstStream(streamsInfo);
}, waitingTime);
return;
} // Compute and set the live delay
if (adapter.getIsDynamic() && streams.length) {
var manifestInfo = streamsInfo[0].manifestInfo;
var fragmentDuration = _getFragmentDurationForLiveDelayCalculation(streamsInfo, manifestInfo);
playbackController.computeAndSetLiveDelay(fragmentDuration, manifestInfo);
} // Figure out the correct start time and the correct start period
var startTime = _getInitialStartTime();
var initialStream = getStreamForTime(startTime);
var startStream = initialStream !== null ? initialStream : streams[0];
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].INITIAL_STREAM_SWITCH, {
startTime: startTime
});
_switchStream(startStream, null, startTime);
_startPlaybackEndedTimerInterval();
}
/**
* Switch from the current stream (period) to the next stream (period).
* @param {object} stream
* @param {object} previousStream
* @param {number} seekTime
* @private
*/
function _switchStream(stream, previousStream, seekTime) {
try {
if (isStreamSwitchingInProgress || !stream || previousStream === stream && stream.getIsActive()) {
return;
}
isStreamSwitchingInProgress = true;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PERIOD_SWITCH_STARTED, {
fromStreamInfo: previousStream ? previousStream.getStreamInfo() : null,
toStreamInfo: stream.getStreamInfo()
});
var keepBuffers = false;
activeStream = stream;
if (previousStream) {
keepBuffers = _canSourceBuffersBeReused(stream, previousStream);
previousStream.deactivate(keepBuffers);
} // Determine seek time when switching to new period
// - seek at given seek time
// - or seek at period start if upcoming period is not prebuffered
seekTime = !isNaN(seekTime) ? seekTime : !keepBuffers && previousStream ? stream.getStreamInfo().start : NaN;
logger.info("Switch to stream ".concat(stream.getId(), ". Seektime is ").concat(seekTime, ", current playback time is ").concat(playbackController.getTime(), ". Seamless period switch is set to ").concat(keepBuffers));
preloadingStreams = preloadingStreams.filter(function (s) {
return s.getId() !== activeStream.getId();
});
playbackController.initialize(getActiveStreamInfo(), !!previousStream);
if (videoModel.getElement()) {
_openMediaSource(seekTime, keepBuffers);
}
} catch (e) {
isStreamSwitchingInProgress = false;
}
}
/**
* Setup the Media Source. Open MSE and attach event listeners
* @param {number} seekTime
* @param {boolean} keepBuffers
* @private
*/
function _openMediaSource(seekTime, keepBuffers) {
var sourceUrl;
function _onMediaSourceOpen() {
// Manage situations in which a call to reset happens while MediaSource is being opened
if (!mediaSource || mediaSource.readyState !== 'open') return;
logger.debug('MediaSource is open!');
window.URL.revokeObjectURL(sourceUrl);
mediaSource.removeEventListener('sourceopen', _onMediaSourceOpen);
mediaSource.removeEventListener('webkitsourceopen', _onMediaSourceOpen);
_setMediaDuration();
var dvrInfo = dashMetrics.getCurrentDVRInfo();
mediaSourceController.setSeekable(dvrInfo.range.start, dvrInfo.range.end);
_activateStream(seekTime, keepBuffers);
}
function _open() {
mediaSource.addEventListener('sourceopen', _onMediaSourceOpen, false);
mediaSource.addEventListener('webkitsourceopen', _onMediaSourceOpen, false);
sourceUrl = mediaSourceController.attachMediaSource(videoModel);
logger.debug('MediaSource attached to element. Waiting on open...');
}
if (!mediaSource) {
mediaSource = mediaSourceController.createMediaSource();
_open();
} else {
if (keepBuffers) {
_activateStream(seekTime, keepBuffers);
} else {
mediaSourceController.detachMediaSource(videoModel);
_open();
}
}
}
/**
* Activates a new stream.
* @param {number} seekTime
* @param {boolean} keepBuffers
*/
function _activateStream(seekTime, keepBuffers) {
activeStream.activate(mediaSource, keepBuffers ? bufferSinks : undefined, seekTime).then(function (sinks) {
// check if change type is supported by the browser
if (sinks) {
var keys = Object.keys(sinks);
if (keys.length > 0 && sinks[keys[0]].getBuffer().changeType) {
supportsChangeType = true;
}
bufferSinks = sinks;
} // Set the initial time for this stream in the StreamProcessor
if (!isNaN(seekTime)) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SEEK_TARGET, {
time: seekTime
}, {
streamId: activeStream.getId()
});
playbackController.seek(seekTime, false, true);
activeStream.startScheduleControllers();
}
isStreamSwitchingInProgress = false;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PERIOD_SWITCH_COMPLETED, {
toStreamInfo: getActiveStreamInfo()
});
});
}
/**
* A playback seeking event was triggered. We need to disable the preloading streams and call the respective seeking handler.
* We distinguish between inner period seeks and outer period seeks
* @param {object} e
* @private
*/
function _onPlaybackSeeking(e) {
var oldTime = playbackController.getTime();
var newTime = e.seekTime;
var seekToStream = getStreamForTime(newTime);
if (!seekToStream || seekToStream === activeStream) {
_cancelPreloading(oldTime, newTime);
_handleInnerPeriodSeek(e);
} else if (seekToStream && seekToStream !== activeStream) {
_cancelPreloading(oldTime, newTime, seekToStream);
_handleOuterPeriodSeek(e, seekToStream);
}
_createPlaylistMetrics(_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayList"].SEEK_START_REASON);
}
/**
* Cancels the preloading of certain streams based on the position we are seeking to.
* @param {number} oldTime
* @param {number} newTime
* @param {boolean} isInnerPeriodSeek
* @private
*/
function _cancelPreloading(oldTime, newTime) {
var seekToStream = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
// Inner period seek forward
if (oldTime <= newTime && !seekToStream) {
_deactivateAllPreloadingStreams();
} // Inner period seek: If we seek backwards we might need to prune the period(s) that are currently being prebuffered. For now deactivate everything
else if (oldTime > newTime && !seekToStream) {
_deactivateAllPreloadingStreams();
} // Outer period seek: Deactivate everything for now
else {
_deactivateAllPreloadingStreams();
}
}
/**
* Deactivates all preloading streams
* @private
*/
function _deactivateAllPreloadingStreams() {
if (preloadingStreams && preloadingStreams.length > 0) {
preloadingStreams.forEach(function (s) {
s.deactivate(true);
});
preloadingStreams = [];
}
}
/**
* Handle an inner period seek. Prepare all StreamProcessors for the seek.
* @param {object} e
* @private
*/
function _handleInnerPeriodSeek(e) {
var streamProcessors = activeStream.getProcessors();
streamProcessors.forEach(function (sp) {
return sp.prepareInnerPeriodPlaybackSeeking(e);
});
_flushPlaylistMetrics(_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"].USER_REQUEST_STOP_REASON);
}
/**
* Handle an outer period seek. Dispatch the corresponding event to be handled in the BufferControllers and the ScheduleControllers
* @param {object} e
* @param {object} seekToStream
* @private
*/
function _handleOuterPeriodSeek(e, seekToStream) {
// Stop segment requests
var seekTime = e && !isNaN(e.seekTime) ? e.seekTime : NaN;
var streamProcessors = activeStream.getProcessors();
var promises = streamProcessors.map(function (sp) {
// Cancel everything in case the active stream is still buffering
return sp.prepareOuterPeriodPlaybackSeeking(e);
});
Promise.all(promises).then(function () {
_switchStream(seekToStream, activeStream, seekTime);
})["catch"](function (e) {
errHandler.error(e);
});
}
/**
* A track change occured. We deactivate the preloading streams
* @param {object} e
* @private
*/
function _onCurrentTrackChanged(e) {
// Track was changed in non active stream. No need to do anything, this only happens when a stream starts preloading
if (e.newMediaInfo.streamInfo.id !== activeStream.getId()) {
return;
} // If the track was changed in the active stream we need to stop preloading and remove the already prebuffered stuff. Since we do not support preloading specific handling of specific AdaptationSets yet.
_deactivateAllPreloadingStreams();
activeStream.prepareTrackChange(e);
}
/**
* If the source buffer can be reused we can potentially start buffering the next period
* @param {object} nextStream
* @param {object} previousStream
* @return {boolean}
* @private
*/
function _canSourceBuffersBeReused(nextStream, previousStream) {
try {
// Seamless period switch allowed only if:
// - none of the periods uses contentProtection.
// - AND changeType method implemented by browser or periods use the same codec.
return settings.get().streaming.buffer.reuseExistingSourceBuffers && (previousStream.isProtectionCompatible(nextStream) || firstLicenseIsFetched) && (supportsChangeType || previousStream.isMediaCodecCompatible(nextStream, previousStream));
} catch (e) {
return false;
}
}
/**
* Initiate the preloading of the next stream
* @param {object} nextStream
* @param {object} previousStream
* @private
*/
function _onStreamCanLoadNext(nextStream) {
var previousStream = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
if (mediaSource && !nextStream.getPreloaded()) {
var seamlessPeriodSwitch = _canSourceBuffersBeReused(nextStream, previousStream);
if (seamlessPeriodSwitch) {
nextStream.startPreloading(mediaSource, bufferSinks).then(function () {
preloadingStreams.push(nextStream);
});
}
}
}
/**
* Returns the corresponding stream object for a specific presentation time.
* @param {number} time
* @return {null|object}
*/
function getStreamForTime(time) {
if (isNaN(time)) {
return null;
}
var ln = streams.length;
for (var i = 0; i < ln; i++) {
var stream = streams[i];
var streamEnd = parseFloat((stream.getStartTime() + stream.getDuration()).toFixed(5));
if (time < streamEnd) {
return stream;
}
}
return null;
}
/**
* Add the DVR window to the metric list. We need the DVR window to restrict the seeking and calculate the right start time.
*/
function addDVRMetric() {
try {
var isDynamic = adapter.getIsDynamic();
var streamsInfo = adapter.getStreamsInfo();
var manifestInfo = streamsInfo[0].manifestInfo;
var time = playbackController.getTime();
var range = timelineConverter.calcTimeShiftBufferWindow(streams, isDynamic);
var activeStreamProcessors = getActiveStreamProcessors();
if (typeof range.start === 'undefined' || typeof range.end === 'undefined') {
return;
}
if (!activeStreamProcessors || activeStreamProcessors.length === 0) {
dashMetrics.addDVRInfo(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, time, manifestInfo, range);
} else {
activeStreamProcessors.forEach(function (sp) {
dashMetrics.addDVRInfo(sp.getType(), time, manifestInfo, range);
});
}
} catch (e) {}
}
/**
* The buffer level for a certain media type has been updated. If this is the initial playback and we want to autoplay the content we check if we can start playback now.
* For livestreams we might have a drift of the target live delay compared to the current live delay because reaching the initial buffer level took time.
* @param {object} e
* @private
*/
function _onBufferLevelUpdated(e) {
// check if this is the initial playback and we reached the buffer target. If autoplay is true we start playback
if (initialPlayback && autoPlay) {
var initialBufferLevel = mediaPlayerModel.getInitialBufferLevel();
if (isNaN(initialBufferLevel) || initialBufferLevel <= playbackController.getBufferLevel() || adapter.getIsDynamic() && initialBufferLevel > playbackController.getLiveDelay()) {
initialPlayback = false;
_createPlaylistMetrics(_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayList"].INITIAL_PLAYOUT_START_REASON);
playbackController.play();
}
}
if (e && e.mediaType) {
dashMetrics.addBufferLevel(e.mediaType, new Date(), e.bufferLevel * 1000);
}
}
/**
* When the quality is changed in the currently active stream and we do an aggressive replacement we must stop prebuffering. This is similar to a replacing track switch
* Otherwise preloading can go on.
* @param e
* @private
*/
function _onQualityChanged(e) {
if (e.streamInfo.id === activeStream.getId() && e.reason && e.reason.forceReplace) {
_deactivateAllPreloadingStreams();
}
var stream = getStreamById(e.streamInfo.id);
stream.prepareQualityChange(e);
}
/**
* When the playback time is updated we add the droppedFrames metric to the dash metric object
* @private
*/
function _onPlaybackTimeUpdated()
/*e*/
{
if (hasVideoTrack()) {
var playbackQuality = videoModel.getPlaybackQuality();
if (playbackQuality) {
dashMetrics.addDroppedFrames(playbackQuality);
}
}
}
/**
* Once playback starts add playlist metrics depending on whether this was the first playback or playback resumed after pause
* @private
*/
function _onPlaybackStarted()
/*e*/
{
logger.debug('[onPlaybackStarted]');
if (!initialPlayback && isPaused) {
_createPlaylistMetrics(_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayList"].RESUME_FROM_PAUSE_START_REASON);
}
if (initialPlayback) {
initialPlayback = false;
}
isPaused = false;
}
/**
* Once playback is paused flush metrics
* @param {object} e
* @private
*/
function _onPlaybackPaused(e) {
logger.debug('[onPlaybackPaused]');
if (!e.ended) {
isPaused = true;
_flushPlaylistMetrics(_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"].USER_REQUEST_STOP_REASON);
}
}
/**
* Callback once a stream/period is completely buffered. We can either signal the end of the stream or start prebuffering the next period.
* @param {object} e
* @private
*/
function _onStreamBufferingCompleted(e) {
logger.debug("Stream with id ".concat(e.streamInfo.id, " finished buffering"));
var isLast = e.streamInfo.isLast;
if (mediaSource && isLast) {
logger.info('[onStreamBufferingCompleted] calls signalEndOfStream of mediaSourceController.');
mediaSourceController.signalEndOfStream(mediaSource);
} else {
_checkIfPrebufferingCanStart();
}
}
/**
* Check if we can start prebuffering the next period.
* @private
*/
function _checkIfPrebufferingCanStart() {
// In multiperiod situations, we can start buffering the next stream
if (!activeStream || !activeStream.getHasFinishedBuffering()) {
return;
}
var upcomingStreams = _getNextStreams(activeStream);
var i = 0;
while (i < upcomingStreams.length) {
var stream = upcomingStreams[i];
var previousStream = i === 0 ? activeStream : upcomingStreams[i - 1]; // If the preloading for the current stream is not scheduled, but its predecessor has finished buffering we can start prebuffering this stream
if (!stream.getPreloaded() && previousStream.getHasFinishedBuffering()) {
if (mediaSource) {
_onStreamCanLoadNext(stream, previousStream);
}
}
i += 1;
}
}
/**
* In some cases we need to fire the playback ended event manually
* @private
*/
function _startPlaybackEndedTimerInterval() {
if (!playbackEndedTimerInterval) {
playbackEndedTimerInterval = setInterval(function () {
if (!isStreamSwitchingInProgress && playbackController.getTimeToStreamEnd() <= 0 && !playbackController.isSeeking()) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PLAYBACK_ENDED, {
'isLast': getActiveStreamInfo().isLast
});
}
}, PLAYBACK_ENDED_TIMER_INTERVAL);
}
}
/**
* Stop the check if the playback has ended
* @private
*/
function _stopPlaybackEndedTimerInterval() {
if (playbackEndedTimerInterval) {
clearInterval(playbackEndedTimerInterval);
playbackEndedTimerInterval = null;
}
}
/**
* Returns a playhead time, in seconds, converted to be relative
* to the start of an identified stream/period or null if no such stream
* @param {number} time
* @param {string} id
* @returns {number|null}
*/
function getTimeRelativeToStreamId(time, id) {
var stream = null;
var baseStart = 0;
var streamStart = 0;
var streamDur = null;
for (var i = 0; i < streams.length; i++) {
stream = streams[i];
streamStart = stream.getStartTime();
streamDur = stream.getDuration(); // use start time, if not undefined or NaN or similar
if (Number.isFinite(streamStart)) {
baseStart = streamStart;
}
if (stream.getId() === id) {
return time - baseStart;
} else {
// use duration if not undefined or NaN or similar
if (Number.isFinite(streamDur)) {
baseStart += streamDur;
}
}
}
return null;
}
/**
* Returns the streamProcessors of the active stream.
* @return {array}
*/
function getActiveStreamProcessors() {
return activeStream ? activeStream.getProcessors() : [];
}
/**
* Once playback has ended we switch to the next stream
* @param {object} e
*/
function _onPlaybackEnded(e) {
if (activeStream && !activeStream.getIsEndedEventSignaled()) {
activeStream.setIsEndedEventSignaled(true);
var nextStream = _getNextStream();
if (nextStream) {
logger.debug("StreamController onEnded, found next stream with id ".concat(nextStream.getStreamInfo().id, ". Switching from ").concat(activeStream.getStreamInfo().id, " to ").concat(nextStream.getStreamInfo().id));
_switchStream(nextStream, activeStream, NaN);
} else {
logger.debug('StreamController no next stream found');
activeStream.setIsEndedEventSignaled(false);
}
_flushPlaylistMetrics(nextStream ? _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"].END_OF_PERIOD_STOP_REASON : _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"].END_OF_CONTENT_STOP_REASON);
}
if (e && e.isLast) {
_stopPlaybackEndedTimerInterval();
}
}
/**
* Returns the next stream to be played relative to the stream provided. If no stream is provided we use the active stream.
* In order to avoid rounding issues we should not use the duration of the periods. Instead find the stream with starttime closest to startTime of the previous stream.
* @param {object} stream
* @return {null|object}
*/
function _getNextStream() {
var stream = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var refStream = stream ? stream : activeStream ? activeStream : null;
if (!refStream) {
return null;
}
var refStreamInfo = refStream.getStreamInfo();
var start = refStreamInfo.start;
var i = 0;
var targetIndex = -1;
var lastDiff = NaN;
while (i < streams.length) {
var s = streams[i];
var sInfo = s.getStreamInfo();
var diff = sInfo.start - start;
if (diff > 0 && (isNaN(lastDiff) || diff < lastDiff) && refStreamInfo.id !== sInfo.id) {
lastDiff = diff;
targetIndex = i;
}
i += 1;
}
if (targetIndex >= 0) {
return streams[targetIndex];
}
return null;
}
/**
* Returns all upcoming streams relative to the provided stream. If no stream is provided we use the active stream.
* @param {object} stream
* @return {array}
*/
function _getNextStreams() {
var stream = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
try {
var refStream = stream ? stream : activeStream ? activeStream : null;
if (refStream) {
var refStreamInfo = refStream.getStreamInfo();
return streams.filter(function (stream) {
var sInfo = stream.getStreamInfo();
return sInfo.start > refStreamInfo.start && refStreamInfo.id !== sInfo.id;
});
}
} catch (e) {
return [];
}
}
/**
* Sets the duration attribute of the MediaSource using the MediaSourceController.
* @param {number} duration
* @private
*/
function _setMediaDuration(duration) {
var manifestDuration = duration ? duration : getActiveStreamInfo().manifestInfo.duration;
mediaSourceController.setDuration(manifestDuration);
}
/**
* Returns the active stream
* @return {object}
*/
function getActiveStream() {
return activeStream;
}
/**
* Initial playback indicates if we have called play() for the first time yet.
* @return {*}
*/
function getInitialPlayback() {
return initialPlayback;
}
/**
* Auto Play indicates if the stream starts automatically as soon as it is initialized.
* @return {boolean}
*/
function getAutoPlay() {
return autoPlay;
}
/**
* Called once the first stream has been initialized. We only use this function to seek to the right start time.
* @return {number}
* @private
*/
function _getInitialStartTime() {
// Seek new stream in priority order:
// - at start time provided in URI parameters
// - at stream/period start time (for static streams) or live start time (for dynamic streams)
var startTime;
if (adapter.getIsDynamic()) {
// For dynamic stream, start by default at (live edge - live delay)
var dvrInfo = dashMetrics.getCurrentDVRInfo();
var liveEdge = dvrInfo && dvrInfo.range ? dvrInfo.range.end : 0; // we are already in the right start period. so time should not be smaller than period@start and should not be larger than period@end
startTime = liveEdge - playbackController.getLiveDelay(); // If start time in URI, take min value between live edge time and time from URI (capped by DVR window range)
var dvrWindow = dvrInfo ? dvrInfo.range : null;
if (dvrWindow) {
// #t shall be relative to period start
var startTimeFromUri = _getStartTimeFromUriParameters(true);
if (!isNaN(startTimeFromUri)) {
logger.info('Start time from URI parameters: ' + startTimeFromUri);
startTime = Math.max(Math.min(startTime, startTimeFromUri), dvrWindow.start);
}
}
} else {
// For static stream, start by default at period start
var _streams = getStreams();
var streamInfo = _streams[0].getStreamInfo();
startTime = streamInfo.start; // If start time in URI, take max value between period start and time from URI (if in period range)
var _startTimeFromUri = _getStartTimeFromUriParameters(false);
if (!isNaN(_startTimeFromUri)) {
logger.info('Start time from URI parameters: ' + _startTimeFromUri);
startTime = Math.max(startTime, _startTimeFromUri);
}
}
return startTime;
}
/**
* 23009-1 Annex C.4 defines MPD anchors to use URI fragment syntax to start a presentation at a given time and a given state
* @param {boolean} isDynamic
* @return {number}
* @private
*/
function _getStartTimeFromUriParameters(isDynamic) {
var fragData = uriFragmentModel.getURIFragmentData();
if (!fragData || !fragData.t) {
return NaN;
}
var refStream = getStreams()[0];
var refStreamStartTime = refStream.getStreamInfo().start; // Consider only start time of MediaRange
// TODO: consider end time of MediaRange to stop playback at provided end time
fragData.t = fragData.t.split(',')[0]; // "t=<time>" : time is relative to 1st period start
// "t=posix:<time>" : time is absolute start time as number of seconds since 01-01-1970
var posix = fragData.t.indexOf('posix:') !== -1 ? fragData.t.substring(6) === 'now' ? Date.now() / 1000 : parseInt(fragData.t.substring(6)) : NaN;
var startTime = isDynamic && !isNaN(posix) ? posix - playbackController.getAvailabilityStartTime() / 1000 : parseInt(fragData.t) + refStreamStartTime;
return startTime;
}
/**
* Streams that are no longer in the manifest can be filtered
* @param {object} streamsInfo
* @private
*/
function _filterOutdatedStreams(streamsInfo) {
streams = streams.filter(function (stream) {
var isStillIncluded = streamsInfo.filter(function (sInfo) {
return sInfo.id === stream.getId();
}).length > 0;
var shouldKeepStream = isStillIncluded || stream.getId() === activeStream.getId();
if (!shouldKeepStream) {
logger.debug("Removing stream ".concat(stream.getId()));
stream.reset(true);
}
return shouldKeepStream;
});
}
/**
* In order to calculate the initial live delay we might required the duration of the segments.
* @param {array} streamInfos
* @param {object} manifestInfo
* @return {number}
* @private
*/
function _getFragmentDurationForLiveDelayCalculation(streamInfos, manifestInfo) {
try {
var fragmentDuration = NaN; // We use the maxFragmentDuration attribute if present
if (manifestInfo && !isNaN(manifestInfo.maxFragmentDuration) && isFinite(manifestInfo.maxFragmentDuration)) {
return manifestInfo.maxFragmentDuration;
} // For single period manifests we can iterate over all AS and use the maximum segment length
if (streamInfos && streamInfos.length === 1) {
var streamInfo = streamInfos[0];
var mediaTypes = [_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT];
var fragmentDurations = mediaTypes.reduce(function (acc, mediaType) {
var mediaInfo = adapter.getMediaInfoForType(streamInfo, mediaType);
if (mediaInfo && mediaInfo.isFragmented !== false) {
acc.push(mediaInfo);
}
return acc;
}, []).reduce(function (acc, mediaInfo) {
var voRepresentations = adapter.getVoRepresentations(mediaInfo);
if (voRepresentations && voRepresentations.length > 0) {
voRepresentations.forEach(function (voRepresentation) {
if (voRepresentation) {
acc.push(voRepresentation);
}
});
}
return acc;
}, []).reduce(function (acc, voRepresentation) {
var representation = adapter.convertRepresentationToRepresentationInfo(voRepresentation);
if (representation && representation.fragmentDuration && !isNaN(representation.fragmentDuration)) {
acc.push(representation.fragmentDuration);
}
return acc;
}, []);
fragmentDuration = Math.max.apply(Math, _toConsumableArray(fragmentDurations));
}
return isFinite(fragmentDuration) ? fragmentDuration : NaN;
} catch (e) {
return NaN;
}
}
/**
* Callback handler after the manifest has been updated. Trigger an update in the adapter and filter unsupported stuff.
* Finally attempt UTC sync
* @param {object} e
* @private
*/
function _onManifestUpdated(e) {
if (!e.error) {
logger.info('Manifest updated... updating data system wide.'); //Since streams are not composed yet , need to manually look up useCalculatedLiveEdgeTime to detect if stream
//is SegmentTimeline to avoid using time source
var manifest = e.manifest;
adapter.updatePeriods(manifest);
var manifestUTCTimingSources = adapter.getUTCTimingSources();
if (adapter.getIsDynamic() && (!manifestUTCTimingSources || manifestUTCTimingSources.length === 0)) {
eventBus.trigger(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_11__["default"].CONFORMANCE_VIOLATION, {
level: _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_17__["default"].LEVELS.WARNING,
event: _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_17__["default"].EVENTS.NO_UTC_TIMING_ELEMENT
});
}
var allUTCTimingSources = !adapter.getIsDynamic() ? manifestUTCTimingSources : manifestUTCTimingSources.concat(mediaPlayerModel.getUTCTimingSources());
var isHTTPS = urlUtils.isHTTPS(e.manifest.url); //If https is detected on manifest then lets apply that protocol to only the default time source(s). In the future we may find the need to apply this to more then just default so left code at this level instead of in MediaPlayer.
allUTCTimingSources.forEach(function (item) {
if (item.value.replace(/.*?:\/\//g, '') === mediaPlayerModel.getDefaultUtcTimingSource().value.replace(/.*?:\/\//g, '')) {
item.value = item.value.replace(isHTTPS ? new RegExp(/^(http:)?\/\//i) : new RegExp(/^(https:)?\/\//i), isHTTPS ? 'https://' : 'http://');
logger.debug('Matching default timing source protocol to manifest protocol: ', item.value);
}
}); // It is important to filter before initializing the baseUrlController. Otherwise we might end up with wrong references in case we remove AdaptationSets.
capabilitiesFilter.filterUnsupportedFeatures(manifest).then(function () {
baseURLController.initialize(manifest);
timeSyncController.attemptSync(allUTCTimingSources, adapter.getIsDynamic());
});
} else {
hasInitialisationError = true;
reset();
}
}
/**
* Check if the stream has a video track
* @return {boolean}
*/
function hasVideoTrack() {
return activeStream ? activeStream.getHasVideoTrack() : false;
}
/**
* Check if the stream has an audio track
* @return {boolean}
*/
function hasAudioTrack() {
return activeStream ? activeStream.getHasAudioTrack() : false;
}
function switchToVideoElement(seekTime) {
if (activeStream) {
playbackController.initialize(getActiveStreamInfo());
_openMediaSource(seekTime, false);
}
}
function _flushPlaylistMetrics(reason, time) {
time = time || new Date();
getActiveStreamProcessors().forEach(function (p) {
p.finalisePlayList(time, reason);
});
dashMetrics.addPlayList();
}
function _createPlaylistMetrics(startReason) {
dashMetrics.createPlaylistMetrics(playbackController.getTime() * 1000, startReason);
}
function _onPlaybackError(e) {
if (!e.error) return;
var msg = '';
switch (e.error.code) {
case 1:
msg = 'MEDIA_ERR_ABORTED';
break;
case 2:
msg = 'MEDIA_ERR_NETWORK';
break;
case 3:
msg = 'MEDIA_ERR_DECODE';
errorInformation.counts.mediaErrorDecode += 1;
break;
case 4:
msg = 'MEDIA_ERR_SRC_NOT_SUPPORTED';
break;
case 5:
msg = 'MEDIA_ERR_ENCRYPTED';
break;
default:
msg = 'UNKNOWN';
break;
}
if (msg === 'MEDIA_ERR_DECODE' && settings.get().errors.recoverAttempts.mediaErrorDecode >= errorInformation.counts.mediaErrorDecode) {
_handleMediaErrorDecode();
return;
}
hasMediaError = true;
if (e.error.message) {
msg += ' (' + e.error.message + ')';
}
if (e.error.msExtendedCode) {
msg += ' (0x' + (e.error.msExtendedCode >>> 0).toString(16).toUpperCase() + ')';
}
logger.fatal('Video Element Error: ' + msg);
if (e.error) {
logger.fatal(e.error);
}
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_14__["default"](e.error.code, msg));
reset();
}
/**
* Handles mediaError
* @private
*/
function _handleMediaErrorDecode() {
logger.warn('A MEDIA_ERR_DECODE occured: Resetting the MediaSource');
var time = playbackController.getTime(); // Deactivate the current stream.
activeStream.deactivate(false); // Reset MSE
logger.warn("MediaSource has been resetted. Resuming playback from time ".concat(time));
_openMediaSource(time, false);
}
function getActiveStreamInfo() {
return activeStream ? activeStream.getStreamInfo() : null;
}
function getIsStreamSwitchInProgress() {
return isStreamSwitchingInProgress;
}
function getHasMediaOrInitialisationError() {
return hasMediaError || hasInitialisationError;
}
function getStreamById(id) {
for (var i = 0, ln = streams.length; i < ln; i++) {
if (streams[i].getId() === id) {
return streams[i];
}
}
return null;
}
function _checkConfig() {
if (!manifestLoader || !manifestLoader.hasOwnProperty('load') || !timelineConverter || !timelineConverter.hasOwnProperty('initialize') || !timelineConverter.hasOwnProperty('reset') || !timelineConverter.hasOwnProperty('getClientTimeOffset') || !manifestModel || !errHandler || !dashMetrics || !playbackController) {
throw new Error(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MISSING_CONFIG_ERROR);
}
}
function _checkInitialize() {
if (!manifestUpdater || !manifestUpdater.hasOwnProperty('setManifest')) {
throw new Error('initialize function has to be called previously');
}
}
function load(url) {
_checkConfig();
manifestLoader.load(url);
}
function loadWithManifest(manifest) {
_checkInitialize();
manifestUpdater.setManifest(manifest);
}
function _onManifestValidityChanged(e) {
if (!isNaN(e.newDuration)) {
_setMediaDuration(e.newDuration);
}
}
function setConfig(config) {
if (!config) return;
if (config.capabilities) {
capabilities = config.capabilities;
}
if (config.capabilitiesFilter) {
capabilitiesFilter = config.capabilitiesFilter;
}
if (config.manifestLoader) {
manifestLoader = config.manifestLoader;
}
if (config.manifestModel) {
manifestModel = config.manifestModel;
}
if (config.mediaPlayerModel) {
mediaPlayerModel = config.mediaPlayerModel;
}
if (config.protectionController) {
protectionController = config.protectionController;
}
if (config.adapter) {
adapter = config.adapter;
}
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
if (config.errHandler) {
errHandler = config.errHandler;
}
if (config.timelineConverter) {
timelineConverter = config.timelineConverter;
}
if (config.videoModel) {
videoModel = config.videoModel;
}
if (config.playbackController) {
playbackController = config.playbackController;
}
if (config.textController) {
textController = config.textController;
}
if (config.abrController) {
abrController = config.abrController;
}
if (config.mediaController) {
mediaController = config.mediaController;
}
if (config.settings) {
settings = config.settings;
}
if (config.baseURLController) {
baseURLController = config.baseURLController;
}
if (config.uriFragmentModel) {
uriFragmentModel = config.uriFragmentModel;
}
if (config.segmentBaseController) {
segmentBaseController = config.segmentBaseController;
}
}
function setProtectionData(protData) {
protectionData = protData;
if (protectionController) {
protectionController.setProtectionData(protectionData);
}
}
function resetInitialSettings() {
streams = [];
protectionController = null;
isStreamSwitchingInProgress = false;
activeStream = null;
hasMediaError = false;
hasInitialisationError = false;
initialPlayback = true;
isPaused = false;
autoPlay = true;
playbackEndedTimerInterval = null;
firstLicenseIsFetched = false;
supportsChangeType = false;
preloadingStreams = [];
waitForPlaybackStartTimeout = null;
errorInformation = {
counts: {
mediaErrorDecode: 0
}
};
}
function reset() {
_checkConfig();
timeSyncController.reset();
_flushPlaylistMetrics(hasMediaError || hasInitialisationError ? _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"].FAILURE_STOP_REASON : _vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__["PlayListTrace"].USER_REQUEST_STOP_REASON);
for (var i = 0, ln = streams ? streams.length : 0; i < ln; i++) {
var stream = streams[i];
stream.reset(hasMediaError);
}
unRegisterEvents();
baseURLController.reset();
manifestUpdater.reset();
eventController.reset();
dashMetrics.clearAllCurrentMetrics();
manifestModel.setValue(null);
manifestLoader.reset();
timelineConverter.reset();
initCache.reset();
if (mediaSource) {
mediaSourceController.detachMediaSource(videoModel);
mediaSource = null;
}
videoModel = null;
if (protectionController) {
protectionController = null;
protectionData = null;
if (manifestModel.getValue()) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PROTECTION_DESTROYED, {
data: manifestModel.getValue().url
});
}
}
_stopPlaybackEndedTimerInterval();
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].STREAM_TEARDOWN_COMPLETE);
resetInitialSettings();
}
function _onMetricAdded(e) {
if (e.metric === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVR_INFO) {
//Match media type? How can DVR window be different for media types?
//Should we normalize and union the two?
var targetMediaType = hasAudioTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO : _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO;
if (e.mediaType === targetMediaType) {
mediaSourceController.setSeekable(e.value.range.start, e.value.range.end);
}
}
}
function getStreams() {
return streams;
}
instance = {
initialize: initialize,
getActiveStreamInfo: getActiveStreamInfo,
addDVRMetric: addDVRMetric,
hasVideoTrack: hasVideoTrack,
hasAudioTrack: hasAudioTrack,
getStreamById: getStreamById,
getStreamForTime: getStreamForTime,
getTimeRelativeToStreamId: getTimeRelativeToStreamId,
load: load,
loadWithManifest: loadWithManifest,
getActiveStreamProcessors: getActiveStreamProcessors,
setConfig: setConfig,
setProtectionData: setProtectionData,
getIsStreamSwitchInProgress: getIsStreamSwitchInProgress,
switchToVideoElement: switchToVideoElement,
getHasMediaOrInitialisationError: getHasMediaOrInitialisationError,
getStreams: getStreams,
getActiveStream: getActiveStream,
getInitialPlayback: getInitialPlayback,
getAutoPlay: getAutoPlay,
reset: reset
};
setup();
return instance;
}
StreamController.__dashjs_factory_name = 'StreamController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__["default"].getSingletonFactory(StreamController));
/***/ }),
/***/ "./src/streaming/controllers/TimeSyncController.js":
/*!*********************************************************!*\
!*** ./src/streaming/controllers/TimeSyncController.js ***!
\*********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var HTTP_TIMEOUT_MS = 5000;
var DEFAULT_MAXIMUM_ALLOWED_DRIFT = 100;
var DEFAULT_TIME_BETWEEN_SYNC_ATTEMPTS_ADJUSTMENT_FACTOR = 2;
var DEFAULT_BACKGROUND_ATTEMPTS = 2;
var DEFAULT_TIME_BETWEEN_SYNC_ATTEMPTS = 30;
var DEFAULT_MINIMUM_TIME_BETWEEN_BACKGROUND_SYNC_ATTEMPTS = 30;
var DEFAULT_MAXIMUM_TIME_BETWEEN_SYNC = 600;
var DEFAULT_MINIMUM_TIME_BETWEEN_SYNC = 2;
function TimeSyncController() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
var urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
var instance, logger, isSynchronizing, isBackgroundSynchronizing, settings, handlers, dashMetrics, backgroundSyncTimeOffsets, timingSources, timeOfLastSync, timeOfLastBackgroundSync, lastOffset, lastTimingSource, internalTimeBetweenSyncAttempts, errHandler, baseURLController;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance().getLogger(instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].ATTEMPT_BACKGROUND_SYNC, _onAttemptBackgroundSync, instance);
}
function setConfig(config) {
if (!config) return;
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
if (config.baseURLController) {
baseURLController = config.baseURLController;
}
if (config.errHandler) {
errHandler = config.errHandler;
}
if (config.settings) {
settings = config.settings;
}
}
function _resetInitialSettings() {
backgroundSyncTimeOffsets = [];
timingSources = [];
timeOfLastSync = null;
timeOfLastBackgroundSync = null;
lastTimingSource = null;
lastOffset = NaN;
isSynchronizing = false;
isBackgroundSynchronizing = false;
internalTimeBetweenSyncAttempts = settings.get().streaming.utcSynchronization.timeBetweenSyncAttempts;
}
/**
* Register the timing handler depending on the schemeIdUris. This method is called once when the StreamController is initialized
*/
function initialize() {
_resetInitialSettings(); // a list of known schemeIdUris and a method to call with @value
handlers = {
'urn:mpeg:dash:utc:http-head:2014': _httpHeadHandler,
'urn:mpeg:dash:utc:http-xsdate:2014': _httpHandler.bind(null, _xsdatetimeDecoder),
'urn:mpeg:dash:utc:http-iso:2014': _httpHandler.bind(null, _iso8601Decoder),
'urn:mpeg:dash:utc:direct:2014': _directHandler,
// some specs referencing early ISO23009-1 drafts incorrectly use
// 2012 in the URI, rather than 2014. support these for now.
'urn:mpeg:dash:utc:http-head:2012': _httpHeadHandler,
'urn:mpeg:dash:utc:http-xsdate:2012': _httpHandler.bind(null, _xsdatetimeDecoder),
'urn:mpeg:dash:utc:http-iso:2012': _httpHandler.bind(null, _iso8601Decoder),
'urn:mpeg:dash:utc:direct:2012': _directHandler,
// it isn't clear how the data returned would be formatted, and
// no public examples available so http-ntp not supported for now.
// presumably you would do an arraybuffer type xhr and decode the
// binary data returned but I would want to see a sample first.
'urn:mpeg:dash:utc:http-ntp:2014': _notSupportedHandler,
// not clear how this would be supported in javascript (in browser)
'urn:mpeg:dash:utc:ntp:2014': _notSupportedHandler,
'urn:mpeg:dash:utc:sntp:2014': _notSupportedHandler
};
}
/**
* Sync against a timing source. T
* @param {array} tSources
* @param {boolean} isDynamic
*/
function attemptSync(tSources, isDynamic) {
timingSources = tSources; // Stop if we are already synchronizing
if (isSynchronizing) {
return;
} // No synchronization required we can signal the completion immediately
if (!_shouldPerformSynchronization(isDynamic)) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].TIME_SYNCHRONIZATION_COMPLETED);
return;
}
isSynchronizing = true;
_attemptRecursiveSync();
}
/**
* Does a synchronization in the background in case the last offset should be verified or a 404 occurs
*/
function _onAttemptBackgroundSync() {
if (!settings.get().streaming.utcSynchronization.enabled || isSynchronizing || isBackgroundSynchronizing || !lastTimingSource || !lastTimingSource.value || !lastTimingSource.schemeIdUri || isNaN(lastOffset) || isNaN(settings.get().streaming.utcSynchronization.backgroundAttempts)) {
return;
}
if (timeOfLastBackgroundSync && (Date.now() - timeOfLastBackgroundSync) / 1000 < DEFAULT_MINIMUM_TIME_BETWEEN_BACKGROUND_SYNC_ATTEMPTS) {
return;
}
backgroundSyncTimeOffsets = [];
isBackgroundSynchronizing = true;
var backgroundAttempts = !isNaN(settings.get().streaming.utcSynchronization.backgroundAttempts) ? settings.get().streaming.utcSynchronization.backgroundAttempts : DEFAULT_BACKGROUND_ATTEMPTS;
_attemptBackgroundSync(backgroundAttempts);
}
/**
* Perform a defined number of background attempts
* @param {number} attempts
* @private
*/
function _attemptBackgroundSync(attempts) {
try {
if (attempts <= 0) {
_completeBackgroundTimeSyncSequence();
return;
}
var deviceTimeBeforeSync = Date.now();
handlers[lastTimingSource.schemeIdUri](lastTimingSource.value, function (serverTime) {
// the timing source returned something useful
var deviceTimeAfterSync = Date.now();
var offset = _calculateOffset(deviceTimeBeforeSync, deviceTimeAfterSync, serverTime);
backgroundSyncTimeOffsets.push(offset);
_attemptBackgroundSync(attempts - 1);
}, function () {
_completeBackgroundTimeSyncSequence();
});
} catch (e) {
_completeBackgroundTimeSyncSequence();
}
}
/**
* Sync against a timing source. This method is called recursively if the time sync for the first entry in timingSources fails.
* @param {number} sourceIndex
*/
function _attemptRecursiveSync() {
var sourceIndex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
// if called with no sourceIndex, use zero (highest priority)
var index = sourceIndex || 0; // the sources should be ordered in priority from the manifest.
// try each in turn, from the top, until either something
// sensible happens, or we run out of sources to try.
if (!timingSources || timingSources.length === 0 || index >= timingSources.length) {
_onComplete();
return;
}
var source = timingSources[index];
if (source) {
// check if there is a handler for this @schemeIdUri
if (handlers.hasOwnProperty(source.schemeIdUri)) {
// if so, call it with its @value
var deviceTimeBeforeSync = new Date().getTime();
handlers[source.schemeIdUri](source.value, function (serverTime) {
// the timing source returned something useful
var deviceTimeAfterSync = new Date().getTime();
var offset = _calculateOffset(deviceTimeBeforeSync, deviceTimeAfterSync, serverTime);
lastTimingSource = source;
_onComplete(offset);
}, function () {
// the timing source was probably uncontactable
// or returned something we can't use - try again
// with the remaining sources
_attemptRecursiveSync(index + 1);
});
} else {
// an unknown schemeIdUri must have been found
// try again with the remaining sources
_attemptRecursiveSync(index + 1);
}
} else {
// no valid time source could be found, just use device time
_onComplete();
}
}
/**
* Calculate the offset between client and server. Account for the roundtrip time
* @param {number} deviceTimeBeforeSync
* @param {number} deviceTimeAfterSync
* @param {number} serverTime
* @return {number}
* @private
*/
function _calculateOffset(deviceTimeBeforeSync, deviceTimeAfterSync, serverTime) {
var deviceReferenceTime = deviceTimeAfterSync - (deviceTimeAfterSync - deviceTimeBeforeSync) / 2;
return serverTime - deviceReferenceTime;
}
/**
* Checks if a synchronization is required
* @param {boolean} isDynamic
* @return {boolean}
* @private
*/
function _shouldPerformSynchronization(isDynamic) {
try {
if (!isDynamic || !settings.get().streaming.utcSynchronization.enabled) {
return false;
}
var timeBetweenSyncAttempts = !isNaN(internalTimeBetweenSyncAttempts) ? internalTimeBetweenSyncAttempts : DEFAULT_TIME_BETWEEN_SYNC_ATTEMPTS;
if (!timeOfLastSync || !timeBetweenSyncAttempts || isNaN(timeBetweenSyncAttempts)) {
return true;
}
return (Date.now() - timeOfLastSync) / 1000 >= timeBetweenSyncAttempts;
} catch (e) {
return true;
}
}
/**
* Callback after sync has been completed
* @param {number} offset
* @private
*/
function _onComplete() {
var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NaN;
var failed = isNaN(offset);
if (failed && settings.get().streaming.utcSynchronization.useManifestDateHeaderTimeSource) {
//Before falling back to binary search , check if date header exists on MPD. if so, use for a time source.
_checkForDateHeader();
} else {
_completeTimeSyncSequence(failed, offset);
}
}
/**
* Takes xsdatetime and returns milliseconds since UNIX epoch. May not be necessary as xsdatetime is very similar to ISO 8601 which is natively understood by javascript Date parser
* @param {string} xsdatetimeStr
* @return {number}
* @private
*/
function _alternateXsdatetimeDecoder(xsdatetimeStr) {
// taken from DashParser - should probably refactor both uses
var SECONDS_IN_MIN = 60;
var MINUTES_IN_HOUR = 60;
var MILLISECONDS_IN_SECONDS = 1000;
var datetimeRegex = /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(?::([0-9]*)(\.[0-9]*)?)?(?:([+\-])([0-9]{2})([0-9]{2}))?/;
var utcDate, timezoneOffset;
var match = datetimeRegex.exec(xsdatetimeStr); // If the string does not contain a timezone offset different browsers can interpret it either
// as UTC or as a local time so we have to parse the string manually to normalize the given date value for
// all browsers
utcDate = Date.UTC(parseInt(match[1], 10), parseInt(match[2], 10) - 1, // months start from zero
parseInt(match[3], 10), parseInt(match[4], 10), parseInt(match[5], 10), match[6] && (parseInt(match[6], 10) || 0), match[7] && parseFloat(match[7]) * MILLISECONDS_IN_SECONDS || 0); // If the date has timezone offset take it into account as well
if (match[9] && match[10]) {
timezoneOffset = parseInt(match[9], 10) * MINUTES_IN_HOUR + parseInt(match[10], 10);
utcDate += (match[8] === '+' ? -1 : +1) * timezoneOffset * SECONDS_IN_MIN * MILLISECONDS_IN_SECONDS;
}
return new Date(utcDate).getTime();
}
/**
* Try to use the built in parser, since xsdate is a constrained ISO8601 which is supported natively by Date.parse. if that fails, try a regex-based version used elsewhere in this application.
* @param {string} xsdatetimeStr
* @return {number}
*/
function _xsdatetimeDecoder(xsdatetimeStr) {
var parsedDate = Date.parse(xsdatetimeStr);
if (isNaN(parsedDate)) {
parsedDate = _alternateXsdatetimeDecoder(xsdatetimeStr);
}
return parsedDate;
}
/**
* Takes ISO 8601 timestamp and returns milliseconds since UNIX epoch
* @param {string} isoStr
* @return {number}
*/
function _iso8601Decoder(isoStr) {
return Date.parse(isoStr);
}
/**
* Takes RFC 1123 timestamp (which is same as ISO8601) and returns milliseconds since UNIX epoch
* @param {string} dateStr
* @return {number}
*/
function _rfc1123Decoder(dateStr) {
return Date.parse(dateStr);
}
/**
* Handler for unsupported scheme ids.
* @param {string} url
* @param {function} onSuccessCB
* @param {function} onFailureCB
* @private
*/
function _notSupportedHandler(url, onSuccessCB, onFailureCB) {
onFailureCB();
}
/**
* Direct handler
* @param {string} xsdatetimeStr
* @param {function} onSuccessCB
* @param {function} onFailureCB
*/
function _directHandler(xsdatetimeStr, onSuccessCB, onFailureCB) {
var time = _xsdatetimeDecoder(xsdatetimeStr);
if (!isNaN(time)) {
onSuccessCB(time);
return;
}
onFailureCB();
}
/**
* Generic http handler
* @param {function} decoder
* @param {string} url
* @param {function} onSuccessCB
* @param {function} onFailureCB
* @param {boolean} isHeadRequest
* @private
*/
function _httpHandler(decoder, url, onSuccessCB, onFailureCB, isHeadRequest) {
var oncomplete, onload;
var complete = false;
var req = new XMLHttpRequest();
var verb = isHeadRequest ? _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].HEAD : _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].GET;
var urls = url.match(/\S+/g); // according to ISO 23009-1, url could be a white-space
// separated list of URLs. just handle one at a time.
url = urls.shift();
oncomplete = function oncomplete() {
if (complete) {
return;
} // we only want to pass through here once per xhr,
// regardless of whether the load was successful.
complete = true; // if there are more urls to try, call self.
if (urls.length) {
_httpHandler(decoder, urls.join(' '), onSuccessCB, onFailureCB, isHeadRequest);
} else {
onFailureCB();
}
};
onload = function onload() {
var time, result;
if (req.status === 200) {
time = isHeadRequest ? req.getResponseHeader('Date') : req.response;
result = decoder(time); // decoder returns NaN if non-standard input
if (!isNaN(result)) {
onSuccessCB(result);
complete = true;
}
}
};
if (urlUtils.isRelative(url)) {
// passing no path to resolve will return just MPD BaseURL/baseUri
var baseUrl = baseURLController.resolve();
if (baseUrl) {
url = urlUtils.resolve(url, baseUrl.url);
}
}
req.open(verb, url);
req.timeout = HTTP_TIMEOUT_MS;
req.onload = onload;
req.onloadend = oncomplete;
req.send();
}
/**
* Handler for http-head schemeIdUri
* @param {string} url
* @param {function} onSuccessCB
* @param {function} onFailureCB
* @private
*/
function _httpHeadHandler(url, onSuccessCB, onFailureCB) {
_httpHandler(_rfc1123Decoder, url, onSuccessCB, onFailureCB, true);
}
/**
* Checks if a date header is present in the MPD response and calculates the offset based on the header
* @private
*/
function _checkForDateHeader() {
var dateHeaderValue = dashMetrics.getLatestMPDRequestHeaderValueByID('Date');
var dateHeaderTime = dateHeaderValue !== null ? new Date(dateHeaderValue).getTime() : Number.NaN;
if (!isNaN(dateHeaderTime)) {
var offsetToDeviceTimeMs = dateHeaderTime - Date.now();
_completeTimeSyncSequence(false, offsetToDeviceTimeMs);
} else {
_completeTimeSyncSequence(true);
}
}
/**
* Triggers the event to signal that the time synchronization was completed
* @param {boolean} failed
* @param {number} offset
* @private
*/
function _completeTimeSyncSequence(failed, offset) {
// Adjust the time of the next sync based on the drift between current offset and last offset
if (!isNaN(lastOffset) && !isNaN(offset) && !failed) {
_adjustTimeBetweenSyncAttempts(offset);
} // Update the internal data
if (!failed && !isNaN(offset)) {
timeOfLastSync = Date.now();
isSynchronizing = false; // if this is the first sync we are doing perform background syncs as well to confirm current offset
var shouldAttemptBackgroundSync = isNaN(lastOffset);
lastOffset = offset;
if (shouldAttemptBackgroundSync) {
_onAttemptBackgroundSync();
}
logger.debug("Completed UTC sync. Setting client - server offset to ".concat(offset));
}
if (failed) {
lastTimingSource = null;
isSynchronizing = false;
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_0__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_4__["default"].TIME_SYNC_FAILED_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_4__["default"].TIME_SYNC_FAILED_ERROR_MESSAGE));
} // Notify other classes
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].UPDATE_TIME_SYNC_OFFSET, {
offset: offset
});
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].TIME_SYNCHRONIZATION_COMPLETED);
}
function _adjustTimeBetweenSyncAttempts(offset) {
try {
var isOffsetDriftWithinThreshold = _isOffsetDriftWithinThreshold(offset);
var timeBetweenSyncAttempts = !isNaN(internalTimeBetweenSyncAttempts) ? internalTimeBetweenSyncAttempts : DEFAULT_TIME_BETWEEN_SYNC_ATTEMPTS;
var timeBetweenSyncAttemptsAdjustmentFactor = !isNaN(settings.get().streaming.utcSynchronization.timeBetweenSyncAttemptsAdjustmentFactor) ? settings.get().streaming.utcSynchronization.timeBetweenSyncAttemptsAdjustmentFactor : DEFAULT_TIME_BETWEEN_SYNC_ATTEMPTS_ADJUSTMENT_FACTOR;
var maximumTimeBetweenSyncAttempts = !isNaN(settings.get().streaming.utcSynchronization.maximumTimeBetweenSyncAttempts) ? settings.get().streaming.utcSynchronization.maximumTimeBetweenSyncAttempts : DEFAULT_MAXIMUM_TIME_BETWEEN_SYNC;
var minimumTimeBetweenSyncAttempts = !isNaN(settings.get().streaming.utcSynchronization.minimumTimeBetweenSyncAttempts) ? settings.get().streaming.utcSynchronization.minimumTimeBetweenSyncAttempts : DEFAULT_MINIMUM_TIME_BETWEEN_SYNC;
var adjustedTimeBetweenSyncAttempts;
if (isOffsetDriftWithinThreshold) {
// The drift between the current offset and the last offset is within the allowed threshold. Increase sync time
adjustedTimeBetweenSyncAttempts = Math.min(timeBetweenSyncAttempts * timeBetweenSyncAttemptsAdjustmentFactor, maximumTimeBetweenSyncAttempts);
logger.debug("Increasing timeBetweenSyncAttempts to ".concat(adjustedTimeBetweenSyncAttempts));
} else {
// Drift between the current offset and the last offset is not within the allowed threshold. Decrease sync time
adjustedTimeBetweenSyncAttempts = Math.max(timeBetweenSyncAttempts / timeBetweenSyncAttemptsAdjustmentFactor, minimumTimeBetweenSyncAttempts);
logger.debug("Decreasing timeBetweenSyncAttempts to ".concat(adjustedTimeBetweenSyncAttempts));
}
internalTimeBetweenSyncAttempts = adjustedTimeBetweenSyncAttempts;
} catch (e) {}
}
/**
* Callback after all background syncs have been completed.
* @private
*/
function _completeBackgroundTimeSyncSequence() {
if (!backgroundSyncTimeOffsets || backgroundSyncTimeOffsets.length === 0) {
return;
}
var averageOffset = backgroundSyncTimeOffsets.reduce(function (acc, curr) {
return acc + curr;
}, 0) / backgroundSyncTimeOffsets.length;
if (!_isOffsetDriftWithinThreshold(averageOffset)) {
logger.debug("Completed background UTC sync. Setting client - server offset to ".concat(averageOffset));
lastOffset = averageOffset;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].UPDATE_TIME_SYNC_OFFSET, {
offset: lastOffset
});
} else {
logger.debug("Completed background UTC sync. Offset is within allowed threshold and is not adjusted.");
}
isBackgroundSynchronizing = false;
timeOfLastBackgroundSync = Date.now();
}
function _isOffsetDriftWithinThreshold(offset) {
try {
if (isNaN(lastOffset)) {
return true;
}
var maxAllowedDrift = settings.get().streaming.utcSynchronization.maximumAllowedDrift && !isNaN(settings.get().streaming.utcSynchronization.maximumAllowedDrift) ? settings.get().streaming.utcSynchronization.maximumAllowedDrift : DEFAULT_MAXIMUM_ALLOWED_DRIFT;
var lowerBound = lastOffset - maxAllowedDrift;
var upperBound = lastOffset + maxAllowedDrift;
return offset >= lowerBound && offset <= upperBound;
} catch (e) {
return true;
}
}
function reset() {
_resetInitialSettings();
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].ATTEMPT_BACKGROUND_SYNC, _onAttemptBackgroundSync, instance);
}
instance = {
initialize: initialize,
attemptSync: attemptSync,
setConfig: setConfig,
reset: reset
};
setup();
return instance;
}
TimeSyncController.__dashjs_factory_name = 'TimeSyncController';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_5__["default"].getSingletonFactory(TimeSyncController);
factory.HTTP_TIMEOUT_MS = HTTP_TIMEOUT_MS;
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_5__["default"].updateSingletonFactory(TimeSyncController.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/controllers/XlinkController.js":
/*!******************************************************!*\
!*** ./src/streaming/controllers/XlinkController.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _XlinkLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../XlinkLoader */ "./src/streaming/XlinkLoader.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _externals_xml2json__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../externals/xml2json */ "./externals/xml2json.js");
/* harmony import */ var _utils_URLUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var RESOLVE_TYPE_ONLOAD = 'onLoad';
var RESOLVE_TYPE_ONACTUATE = 'onActuate';
var RESOLVE_TO_ZERO = 'urn:mpeg:dash:resolve-to-zero:2013';
function XlinkController(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
var urlUtils = Object(_utils_URLUtils__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
var instance, matchers, iron, manifest, converter, xlinkLoader;
function setup() {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].XLINK_ELEMENT_LOADED, onXlinkElementLoaded, instance);
xlinkLoader = Object(_XlinkLoader__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
errHandler: config.errHandler,
dashMetrics: config.dashMetrics,
mediaPlayerModel: config.mediaPlayerModel,
requestModifier: config.requestModifier,
settings: config.settings
});
}
function setMatchers(value) {
if (value) {
matchers = value;
}
}
function setIron(value) {
if (value) {
iron = value;
}
}
/**
* <p>Triggers the resolution of the xlink.onLoad attributes in the manifest file </p>
* @param {Object} mpd - the manifest
*/
function resolveManifestOnLoad(mpd) {
var elements; // First resolve all periods, so unnecessary requests inside onLoad Periods with Default content are avoided
converter = new _externals_xml2json__WEBPACK_IMPORTED_MODULE_4__["default"]({
escapeMode: false,
attributePrefix: '',
arrayAccessForm: 'property',
emptyNodeForm: 'object',
stripWhitespaces: false,
enableToStringFunc: false,
ignoreRoot: true,
matchers: matchers
});
manifest = mpd;
if (manifest.Period_asArray) {
elements = getElementsToResolve(manifest.Period_asArray, manifest, _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PERIOD, RESOLVE_TYPE_ONLOAD);
resolve(elements, _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PERIOD, RESOLVE_TYPE_ONLOAD);
} else {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].XLINK_READY, {
manifest: manifest
});
}
}
function reset() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].XLINK_ELEMENT_LOADED, onXlinkElementLoaded, instance);
if (xlinkLoader) {
xlinkLoader.reset();
xlinkLoader = null;
}
}
function resolve(elements, type, resolveType) {
var resolveObject = {};
var element, url;
resolveObject.elements = elements;
resolveObject.type = type;
resolveObject.resolveType = resolveType; // If nothing to resolve, directly call allElementsLoaded
if (resolveObject.elements.length === 0) {
onXlinkAllElementsLoaded(resolveObject);
}
for (var i = 0; i < resolveObject.elements.length; i++) {
element = resolveObject.elements[i];
if (urlUtils.isHTTPURL(element.url)) {
url = element.url;
} else {
url = element.originalContent.BaseURL + element.url;
}
xlinkLoader.load(url, element, resolveObject);
}
}
function onXlinkElementLoaded(event) {
var element, resolveObject;
var openingTag = '<response>';
var closingTag = '</response>';
var mergedContent = '';
element = event.element;
resolveObject = event.resolveObject; // if the element resolved into content parse the content
if (element.resolvedContent) {
var index = 0; // we add a parent elements so the converter is able to parse multiple elements of the same type which are not wrapped inside a container
if (element.resolvedContent.indexOf('<?xml') === 0) {
index = element.resolvedContent.indexOf('?>') + 2; //find the closing position of the xml declaration, if it exists.
}
mergedContent = element.resolvedContent.substr(0, index) + openingTag + element.resolvedContent.substr(index) + closingTag;
element.resolvedContent = converter.xml_str2json(mergedContent);
}
if (isResolvingFinished(resolveObject)) {
onXlinkAllElementsLoaded(resolveObject);
}
} // We got to wait till all elements of the current queue are resolved before merging back
function onXlinkAllElementsLoaded(resolveObject) {
var elements = [];
var i, obj;
mergeElementsBack(resolveObject);
if (resolveObject.resolveType === RESOLVE_TYPE_ONACTUATE) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].XLINK_READY, {
manifest: manifest
});
}
if (resolveObject.resolveType === RESOLVE_TYPE_ONLOAD) {
switch (resolveObject.type) {
// Start resolving the other elements. We can do Adaptation Set and EventStream in parallel
case _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PERIOD:
for (i = 0; i < manifest[_dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PERIOD + '_asArray'].length; i++) {
obj = manifest[_dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PERIOD + '_asArray'][i];
if (obj.hasOwnProperty(_dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].ADAPTATION_SET + '_asArray')) {
elements = elements.concat(getElementsToResolve(obj[_dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].ADAPTATION_SET + '_asArray'], obj, _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].ADAPTATION_SET, RESOLVE_TYPE_ONLOAD));
}
if (obj.hasOwnProperty(_dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].EVENT_STREAM + '_asArray')) {
elements = elements.concat(getElementsToResolve(obj[_dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].EVENT_STREAM + '_asArray'], obj, _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].EVENT_STREAM, RESOLVE_TYPE_ONLOAD));
}
}
resolve(elements, _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].ADAPTATION_SET, RESOLVE_TYPE_ONLOAD);
break;
case _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].ADAPTATION_SET:
// TODO: Resolve SegmentList here
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].XLINK_READY, {
manifest: manifest
});
break;
}
}
} // Returns the elements with the specific resolve Type
function getElementsToResolve(elements, parentElement, type, resolveType) {
var toResolve = [];
var element, i, xlinkObject; // first remove all the resolve-to-zero elements
for (i = elements.length - 1; i >= 0; i--) {
element = elements[i];
if (element.hasOwnProperty('xlink:href') && element['xlink:href'] === RESOLVE_TO_ZERO) {
elements.splice(i, 1);
}
} // now get the elements with the right resolve type
for (i = 0; i < elements.length; i++) {
element = elements[i];
if (element.hasOwnProperty('xlink:href') && element.hasOwnProperty('xlink:actuate') && element['xlink:actuate'] === resolveType) {
xlinkObject = createXlinkObject(element['xlink:href'], parentElement, type, i, resolveType, element);
toResolve.push(xlinkObject);
}
}
return toResolve;
}
function mergeElementsBack(resolveObject) {
var resolvedElements = [];
var element, type, obj, i, j, k; // Start merging back from the end because of index shifting. Note that the elements with the same parent have to be ordered by index ascending
for (i = resolveObject.elements.length - 1; i >= 0; i--) {
element = resolveObject.elements[i];
type = element.type + '_asArray'; // Element couldn't be resolved or is TODO Inappropriate target: Remove all Xlink attributes
if (!element.resolvedContent || isInappropriateTarget()) {
delete element.originalContent['xlink:actuate'];
delete element.originalContent['xlink:href'];
resolvedElements.push(element.originalContent);
} // Element was successfully resolved
else if (element.resolvedContent) {
for (j = 0; j < element.resolvedContent[type].length; j++) {
//TODO Contains another Xlink attribute with xlink:actuate set to onload. Remove all xLink attributes
obj = element.resolvedContent[type][j];
resolvedElements.push(obj);
}
} // Replace the old elements in the parent with the resolved ones
element.parentElement[type].splice(element.index, 1);
for (k = 0; k < resolvedElements.length; k++) {
element.parentElement[type].splice(element.index + k, 0, resolvedElements[k]);
}
resolvedElements = [];
}
if (resolveObject.elements.length > 0) {
iron.run(manifest);
}
}
function createXlinkObject(url, parentElement, type, index, resolveType, originalContent) {
return {
url: url,
parentElement: parentElement,
type: type,
index: index,
resolveType: resolveType,
originalContent: originalContent,
resolvedContent: null,
resolved: false
};
} // Check if all pending requests are finished
function isResolvingFinished(elementsToResolve) {
var i, obj;
for (i = 0; i < elementsToResolve.elements.length; i++) {
obj = elementsToResolve.elements[i];
if (obj.resolved === false) {
return false;
}
}
return true;
} // TODO : Do some syntax check here if the target is valid or not
function isInappropriateTarget() {
return false;
}
instance = {
resolveManifestOnLoad: resolveManifestOnLoad,
setMatchers: setMatchers,
setIron: setIron,
reset: reset
};
setup();
return instance;
}
XlinkController.__dashjs_factory_name = 'XlinkController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__["default"].getClassFactory(XlinkController));
/***/ }),
/***/ "./src/streaming/metrics/MetricsReporting.js":
/*!***************************************************!*\
!*** ./src/streaming/metrics/MetricsReporting.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utils_DVBErrorsTranslator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/DVBErrorsTranslator */ "./src/streaming/metrics/utils/DVBErrorsTranslator.js");
/* harmony import */ var _MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./MetricsReportingEvents */ "./src/streaming/metrics/MetricsReportingEvents.js");
/* harmony import */ var _controllers_MetricsCollectionController__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./controllers/MetricsCollectionController */ "./src/streaming/metrics/controllers/MetricsCollectionController.js");
/* harmony import */ var _metrics_MetricsHandlerFactory__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./metrics/MetricsHandlerFactory */ "./src/streaming/metrics/metrics/MetricsHandlerFactory.js");
/* harmony import */ var _reporting_ReportingFactory__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./reporting/ReportingFactory */ "./src/streaming/metrics/reporting/ReportingFactory.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MetricsReporting() {
var context = this.context;
var instance, dvbErrorsTranslator;
/**
* Create a MetricsCollectionController, and a DVBErrorsTranslator
* @param {Object} config - dependancies from owner
* @return {MetricsCollectionController} Metrics Collection Controller
*/
function createMetricsReporting(config) {
dvbErrorsTranslator = Object(_utils_DVBErrorsTranslator__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance({
eventBus: config.eventBus,
dashMetrics: config.dashMetrics,
metricsConstants: config.metricsConstants,
events: config.events
});
dvbErrorsTranslator.initialise();
return Object(_controllers_MetricsCollectionController__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create(config);
}
/**
* Get the ReportingFactory to allow new reporters to be registered
* @return {ReportingFactory} Reporting Factory
*/
function getReportingFactory() {
return Object(_reporting_ReportingFactory__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
}
/**
* Get the MetricsHandlerFactory to allow new handlers to be registered
* @return {MetricsHandlerFactory} Metrics Handler Factory
*/
function getMetricsHandlerFactory() {
return Object(_metrics_MetricsHandlerFactory__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance();
}
instance = {
createMetricsReporting: createMetricsReporting,
getReportingFactory: getReportingFactory,
getMetricsHandlerFactory: getMetricsHandlerFactory
};
return instance;
}
MetricsReporting.__dashjs_factory_name = 'MetricsReporting';
var factory = dashjs.FactoryMaker.getClassFactory(MetricsReporting);
/* jshint ignore:line */
factory.events = _MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_1__["default"];
dashjs.FactoryMaker.updateClassFactory(MetricsReporting.__dashjs_factory_name, factory);
/* jshint ignore:line */
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/metrics/MetricsReportingEvents.js":
/*!*********************************************************!*\
!*** ./src/streaming/metrics/MetricsReportingEvents.js ***!
\*********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_events_EventsBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/events/EventsBase */ "./src/core/events/EventsBase.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @implements EventsBase
*/
var MetricsReportingEvents = /*#__PURE__*/function (_EventsBase) {
_inherits(MetricsReportingEvents, _EventsBase);
var _super = _createSuper(MetricsReportingEvents);
function MetricsReportingEvents() {
var _this;
_classCallCheck(this, MetricsReportingEvents);
_this = _super.call(this);
_this.METRICS_INITIALISATION_COMPLETE = 'internal_metricsReportingInitialized';
_this.BECAME_REPORTING_PLAYER = 'internal_becameReportingPlayer';
/**
* Triggered when CMCD data was generated for a HTTP request
* @event MetricsReportingEvents#CMCD_DATA_GENERATED
*/
_this.CMCD_DATA_GENERATED = 'cmcdDataGenerated';
return _this;
}
return MetricsReportingEvents;
}(_core_events_EventsBase__WEBPACK_IMPORTED_MODULE_0__["default"]);
var metricsReportingEvents = new MetricsReportingEvents();
/* harmony default export */ __webpack_exports__["default"] = (metricsReportingEvents);
/***/ }),
/***/ "./src/streaming/metrics/controllers/MetricsCollectionController.js":
/*!**************************************************************************!*\
!*** ./src/streaming/metrics/controllers/MetricsCollectionController.js ***!
\**************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _MetricsController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./MetricsController */ "./src/streaming/metrics/controllers/MetricsController.js");
/* harmony import */ var _utils_ManifestParsing__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/ManifestParsing */ "./src/streaming/metrics/utils/ManifestParsing.js");
/* harmony import */ var _MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../MetricsReportingEvents */ "./src/streaming/metrics/MetricsReportingEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MetricsCollectionController(config) {
config = config || {};
var instance;
var metricsControllers = {};
var context = this.context;
var eventBus = config.eventBus;
var events = config.events;
function update(e) {
if (e.error) {
return;
} // start by assuming all existing controllers need removing
var controllersToRemove = Object.keys(metricsControllers);
var metrics = Object(_utils_ManifestParsing__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance({
adapter: config.adapter,
constants: config.constants
}).getMetrics(e.manifest);
metrics.forEach(function (m) {
var key = JSON.stringify(m);
if (!metricsControllers.hasOwnProperty(key)) {
try {
var controller = Object(_MetricsController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create(config);
controller.initialize(m);
metricsControllers[key] = controller;
} catch (e) {// fail quietly
}
} else {
// we still need this controller - delete from removal list
controllersToRemove.splice(key, 1);
}
}); // now remove the unwanted controllers
controllersToRemove.forEach(function (c) {
metricsControllers[c].reset();
delete metricsControllers[c];
});
eventBus.trigger(_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_2__["default"].METRICS_INITIALISATION_COMPLETE);
}
function resetMetricsControllers() {
Object.keys(metricsControllers).forEach(function (key) {
metricsControllers[key].reset();
});
metricsControllers = {};
}
function setup() {
eventBus.on(events.MANIFEST_UPDATED, update, instance);
eventBus.on(events.STREAM_TEARDOWN_COMPLETE, resetMetricsControllers, instance);
}
function reset() {
eventBus.off(events.MANIFEST_UPDATED, update, instance);
eventBus.off(events.STREAM_TEARDOWN_COMPLETE, resetMetricsControllers, instance);
}
instance = {
reset: reset
};
setup();
return instance;
}
MetricsCollectionController.__dashjs_factory_name = 'MetricsCollectionController';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(MetricsCollectionController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/controllers/MetricsController.js":
/*!****************************************************************!*\
!*** ./src/streaming/metrics/controllers/MetricsController.js ***!
\****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _RangeController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./RangeController */ "./src/streaming/metrics/controllers/RangeController.js");
/* harmony import */ var _ReportingController__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ReportingController */ "./src/streaming/metrics/controllers/ReportingController.js");
/* harmony import */ var _MetricsHandlersController__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./MetricsHandlersController */ "./src/streaming/metrics/controllers/MetricsHandlersController.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MetricsController(config) {
config = config || {};
var metricsHandlersController, reportingController, rangeController, instance;
var context = this.context;
function initialize(metricsEntry) {
try {
rangeController = Object(_RangeController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
mediaElement: config.mediaElement
});
rangeController.initialize(metricsEntry.Range);
reportingController = Object(_ReportingController__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
debug: config.debug,
metricsConstants: config.metricsConstants
});
reportingController.initialize(metricsEntry.Reporting, rangeController);
metricsHandlersController = Object(_MetricsHandlersController__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
debug: config.debug,
eventBus: config.eventBus,
metricsConstants: config.metricsConstants,
events: config.events
});
metricsHandlersController.initialize(metricsEntry.metrics, reportingController);
} catch (e) {
reset();
throw e;
}
}
function reset() {
if (metricsHandlersController) {
metricsHandlersController.reset();
}
if (reportingController) {
reportingController.reset();
}
if (rangeController) {
rangeController.reset();
}
}
instance = {
initialize: initialize,
reset: reset
};
return instance;
}
MetricsController.__dashjs_factory_name = 'MetricsController';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(MetricsController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/controllers/MetricsHandlersController.js":
/*!************************************************************************!*\
!*** ./src/streaming/metrics/controllers/MetricsHandlersController.js ***!
\************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _metrics_MetricsHandlerFactory__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../metrics/MetricsHandlerFactory */ "./src/streaming/metrics/metrics/MetricsHandlerFactory.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MetricsHandlersController(config) {
config = config || {};
var handlers = [];
var instance;
var context = this.context;
var eventBus = config.eventBus;
var Events = config.events;
var metricsHandlerFactory = Object(_metrics_MetricsHandlerFactory__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance({
debug: config.debug,
eventBus: config.eventBus,
metricsConstants: config.metricsConstants
});
function handle(e) {
handlers.forEach(function (handler) {
handler.handleNewMetric(e.metric, e.value, e.mediaType);
});
}
function initialize(metrics, reportingController) {
metrics.split(',').forEach(function (m, midx, ms) {
var handler; // there is a bug in ISO23009-1 where the metrics attribute
// is a comma-separated list but HttpList key can contain a
// comma enclosed by ().
if (m.indexOf('(') !== -1 && m.indexOf(')') === -1) {
var nextm = ms[midx + 1];
if (nextm && nextm.indexOf('(') === -1 && nextm.indexOf(')') !== -1) {
m += ',' + nextm; // delete the next metric so forEach does not visit.
delete ms[midx + 1];
}
}
handler = metricsHandlerFactory.create(m, reportingController);
if (handler) {
handlers.push(handler);
}
});
eventBus.on(Events.METRIC_ADDED, handle, instance);
eventBus.on(Events.METRIC_UPDATED, handle, instance);
}
function reset() {
eventBus.off(Events.METRIC_ADDED, handle, instance);
eventBus.off(Events.METRIC_UPDATED, handle, instance);
handlers.forEach(function (handler) {
return handler.reset();
});
handlers = [];
}
instance = {
initialize: initialize,
reset: reset
};
return instance;
}
MetricsHandlersController.__dashjs_factory_name = 'MetricsHandlersController';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(MetricsHandlersController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/controllers/RangeController.js":
/*!**************************************************************!*\
!*** ./src/streaming/metrics/controllers/RangeController.js ***!
\**************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utils_CustomTimeRanges__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/CustomTimeRanges */ "./src/streaming/utils/CustomTimeRanges.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function RangeController(config) {
config = config || {};
var useWallClockTime = false;
var context = this.context;
var instance, ranges;
var mediaElement = config.mediaElement;
function initialize(rs) {
if (rs && rs.length) {
rs.forEach(function (r) {
var start = r.starttime;
var end = start + r.duration;
ranges.add(start, end);
});
useWallClockTime = !!rs[0]._useWallClockTime;
}
}
function reset() {
ranges.clear();
}
function setup() {
ranges = Object(_utils_CustomTimeRanges__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create();
}
function isEnabled() {
var numRanges = ranges.length;
var time;
if (!numRanges) {
return true;
} // When not present, DASH Metrics reporting is requested
// for the whole duration of the content.
time = useWallClockTime ? new Date().getTime() / 1000 : mediaElement.currentTime;
for (var i = 0; i < numRanges; i += 1) {
var start = ranges.start(i);
var end = ranges.end(i);
if (start <= time && time < end) {
return true;
}
}
return false;
}
instance = {
initialize: initialize,
reset: reset,
isEnabled: isEnabled
};
setup();
return instance;
}
RangeController.__dashjs_factory_name = 'RangeController';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(RangeController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/controllers/ReportingController.js":
/*!******************************************************************!*\
!*** ./src/streaming/metrics/controllers/ReportingController.js ***!
\******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _reporting_ReportingFactory__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../reporting/ReportingFactory */ "./src/streaming/metrics/reporting/ReportingFactory.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ReportingController(config) {
var reporters = [];
var instance;
var reportingFactory = Object(_reporting_ReportingFactory__WEBPACK_IMPORTED_MODULE_0__["default"])(this.context).getInstance(config);
function initialize(reporting, rangeController) {
// "if multiple Reporting elements are present, it is expected that
// the client processes one of the recognized reporting schemes."
// to ignore this, and support multiple Reporting per Metric,
// simply change the 'some' below to 'forEach'
reporting.some(function (r) {
var reporter = reportingFactory.create(r, rangeController);
if (reporter) {
reporters.push(reporter);
return true;
}
});
}
function reset() {
reporters.forEach(function (r) {
return r.reset();
});
reporters = [];
}
function report(type, vos) {
reporters.forEach(function (r) {
return r.report(type, vos);
});
}
instance = {
initialize: initialize,
reset: reset,
report: report
};
return instance;
}
ReportingController.__dashjs_factory_name = 'ReportingController';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(ReportingController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/metrics/MetricsHandlerFactory.js":
/*!****************************************************************!*\
!*** ./src/streaming/metrics/metrics/MetricsHandlerFactory.js ***!
\****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _handlers_BufferLevelHandler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./handlers/BufferLevelHandler */ "./src/streaming/metrics/metrics/handlers/BufferLevelHandler.js");
/* harmony import */ var _handlers_DVBErrorsHandler__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./handlers/DVBErrorsHandler */ "./src/streaming/metrics/metrics/handlers/DVBErrorsHandler.js");
/* harmony import */ var _handlers_HttpListHandler__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./handlers/HttpListHandler */ "./src/streaming/metrics/metrics/handlers/HttpListHandler.js");
/* harmony import */ var _handlers_GenericMetricHandler__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./handlers/GenericMetricHandler */ "./src/streaming/metrics/metrics/handlers/GenericMetricHandler.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MetricsHandlerFactory(config) {
config = config || {};
var instance;
var logger = config.debug ? config.debug.getLogger(instance) : {}; // group 1: key, [group 3: n [, group 5: type]]
var keyRegex = /([a-zA-Z]*)(\(([0-9]*)(\,\s*([a-zA-Z]*))?\))?/;
var context = this.context;
var knownFactoryProducts = {
BufferLevel: _handlers_BufferLevelHandler__WEBPACK_IMPORTED_MODULE_0__["default"],
DVBErrors: _handlers_DVBErrorsHandler__WEBPACK_IMPORTED_MODULE_1__["default"],
HttpList: _handlers_HttpListHandler__WEBPACK_IMPORTED_MODULE_2__["default"],
PlayList: _handlers_GenericMetricHandler__WEBPACK_IMPORTED_MODULE_3__["default"],
RepSwitchList: _handlers_GenericMetricHandler__WEBPACK_IMPORTED_MODULE_3__["default"],
TcpList: _handlers_GenericMetricHandler__WEBPACK_IMPORTED_MODULE_3__["default"]
};
function create(listType, reportingController) {
var matches = listType.match(keyRegex);
var handler;
if (!matches) {
return;
}
try {
handler = knownFactoryProducts[matches[1]](context).create({
eventBus: config.eventBus,
metricsConstants: config.metricsConstants
});
handler.initialize(matches[1], reportingController, matches[3], matches[5]);
} catch (e) {
handler = null;
logger.error("MetricsHandlerFactory: Could not create handler for type ".concat(matches[1], " with args ").concat(matches[3], ", ").concat(matches[5], " (").concat(e.message, ")"));
}
return handler;
}
function register(key, handler) {
knownFactoryProducts[key] = handler;
}
function unregister(key) {
delete knownFactoryProducts[key];
}
instance = {
create: create,
register: register,
unregister: unregister
};
return instance;
}
MetricsHandlerFactory.__dashjs_factory_name = 'MetricsHandlerFactory';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(MetricsHandlerFactory));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/metrics/handlers/BufferLevelHandler.js":
/*!**********************************************************************!*\
!*** ./src/streaming/metrics/metrics/handlers/BufferLevelHandler.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utils_HandlerHelpers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/HandlerHelpers */ "./src/streaming/metrics/utils/HandlerHelpers.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function BufferLevelHandler(config) {
config = config || {};
var instance, reportingController, n, name, interval, lastReportedTime;
var context = this.context;
var handlerHelpers = Object(_utils_HandlerHelpers__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var storedVOs = [];
var metricsConstants = config.metricsConstants;
function getLowestBufferLevelVO() {
try {
return Object.keys(storedVOs).map(function (key) {
return storedVOs[key];
}).reduce(function (a, b) {
return a.level < b.level ? a : b;
});
} catch (e) {
return;
}
}
function intervalCallback() {
var vo = getLowestBufferLevelVO();
if (vo) {
if (lastReportedTime !== vo.t) {
lastReportedTime = vo.t;
reportingController.report(name, vo);
}
}
}
function initialize(basename, rc, n_ms) {
if (rc) {
// this will throw if n is invalid, to be
// caught by the initialize caller.
n = handlerHelpers.validateN(n_ms);
reportingController = rc;
name = handlerHelpers.reconstructFullMetricName(basename, n_ms);
interval = setInterval(intervalCallback, n);
}
}
function reset() {
clearInterval(interval);
interval = null;
n = 0;
reportingController = null;
lastReportedTime = null;
}
function handleNewMetric(metric, vo, type) {
if (metric === metricsConstants.BUFFER_LEVEL) {
storedVOs[type] = vo;
}
}
instance = {
initialize: initialize,
reset: reset,
handleNewMetric: handleNewMetric
};
return instance;
}
BufferLevelHandler.__dashjs_factory_name = 'BufferLevelHandler';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(BufferLevelHandler));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/metrics/handlers/DVBErrorsHandler.js":
/*!********************************************************************!*\
!*** ./src/streaming/metrics/metrics/handlers/DVBErrorsHandler.js ***!
\********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../MetricsReportingEvents */ "./src/streaming/metrics/MetricsReportingEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function DVBErrorsHandler(config) {
config = config || {};
var instance, reportingController;
var eventBus = config.eventBus;
var metricsConstants = config.metricsConstants;
function onInitialisationComplete() {
// we only want to report this once per call to initialize
eventBus.off(_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_0__["default"].METRICS_INITIALISATION_COMPLETE, onInitialisationComplete, this); // Note: A Player becoming a reporting Player is itself
// something which is recorded by the DVBErrors metric.
eventBus.trigger(_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_0__["default"].BECAME_REPORTING_PLAYER);
}
function initialize(unused, rc) {
if (rc) {
reportingController = rc;
eventBus.on(_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_0__["default"].METRICS_INITIALISATION_COMPLETE, onInitialisationComplete, this);
}
}
function reset() {
reportingController = null;
}
function handleNewMetric(metric, vo) {
// simply pass metric straight through
if (metric === metricsConstants.DVB_ERRORS) {
if (reportingController) {
reportingController.report(metric, vo);
}
}
}
instance = {
initialize: initialize,
reset: reset,
handleNewMetric: handleNewMetric
};
return instance;
}
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(DVBErrorsHandler));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/metrics/handlers/GenericMetricHandler.js":
/*!************************************************************************!*\
!*** ./src/streaming/metrics/metrics/handlers/GenericMetricHandler.js ***!
\************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @ignore
*/
function GenericMetricHandler() {
var instance, metricName, reportingController;
function initialize(name, rc) {
metricName = name;
reportingController = rc;
}
function reset() {
reportingController = null;
metricName = undefined;
}
function handleNewMetric(metric, vo) {
// simply pass metric straight through
if (metric === metricName) {
if (reportingController) {
reportingController.report(metricName, vo);
}
}
}
instance = {
initialize: initialize,
reset: reset,
handleNewMetric: handleNewMetric
};
return instance;
}
GenericMetricHandler.__dashjs_factory_name = 'GenericMetricHandler';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(GenericMetricHandler));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/metrics/handlers/HttpListHandler.js":
/*!*******************************************************************!*\
!*** ./src/streaming/metrics/metrics/handlers/HttpListHandler.js ***!
\*******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utils_HandlerHelpers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/HandlerHelpers */ "./src/streaming/metrics/utils/HandlerHelpers.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function HttpListHandler(config) {
config = config || {};
var instance, reportingController, n, type, name, interval;
var storedVos = [];
var handlerHelpers = Object(_utils_HandlerHelpers__WEBPACK_IMPORTED_MODULE_0__["default"])(this.context).getInstance();
var metricsConstants = config.metricsConstants;
function intervalCallback() {
var vos = storedVos;
if (vos.length) {
if (reportingController) {
reportingController.report(name, vos);
}
}
storedVos = [];
}
function initialize(basename, rc, n_ms, requestType) {
if (rc) {
// this will throw if n is invalid, to be
// caught by the initialize caller.
n = handlerHelpers.validateN(n_ms);
reportingController = rc;
if (requestType && requestType.length) {
type = requestType;
}
name = handlerHelpers.reconstructFullMetricName(basename, n_ms, requestType);
interval = setInterval(intervalCallback, n);
}
}
function reset() {
clearInterval(interval);
interval = null;
n = null;
type = null;
storedVos = [];
reportingController = null;
}
function handleNewMetric(metric, vo) {
if (metric === metricsConstants.HTTP_REQUEST) {
if (!type || type === vo.type) {
storedVos.push(vo);
}
}
}
instance = {
initialize: initialize,
reset: reset,
handleNewMetric: handleNewMetric
};
return instance;
}
HttpListHandler.__dashjs_factory_name = 'HttpListHandler';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(HttpListHandler));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/reporting/ReportingFactory.js":
/*!*************************************************************!*\
!*** ./src/streaming/metrics/reporting/ReportingFactory.js ***!
\*************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _reporters_DVBReporting__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./reporters/DVBReporting */ "./src/streaming/metrics/reporting/reporters/DVBReporting.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ReportingFactory(config) {
config = config || {};
var knownReportingSchemeIdUris = {
'urn:dvb:dash:reporting:2014': _reporters_DVBReporting__WEBPACK_IMPORTED_MODULE_0__["default"]
};
var context = this.context;
var instance;
var logger = config.debug ? config.debug.getLogger(instance) : {};
var metricsConstants = config.metricsConstants;
function create(entry, rangeController) {
var reporting;
try {
reporting = knownReportingSchemeIdUris[entry.schemeIdUri](context).create({
metricsConstants: metricsConstants
});
reporting.initialize(entry, rangeController);
} catch (e) {
reporting = null;
logger.error("ReportingFactory: could not create Reporting with schemeIdUri ".concat(entry.schemeIdUri, " (").concat(e.message, ")"));
}
return reporting;
}
function register(schemeIdUri, moduleName) {
knownReportingSchemeIdUris[schemeIdUri] = moduleName;
}
function unregister(schemeIdUri) {
delete knownReportingSchemeIdUris[schemeIdUri];
}
instance = {
create: create,
register: register,
unregister: unregister
};
return instance;
}
ReportingFactory.__dashjs_factory_name = 'ReportingFactory';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(ReportingFactory));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/reporting/reporters/DVBReporting.js":
/*!*******************************************************************!*\
!*** ./src/streaming/metrics/reporting/reporters/DVBReporting.js ***!
\*******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utils_MetricSerialiser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/MetricSerialiser */ "./src/streaming/metrics/utils/MetricSerialiser.js");
/* harmony import */ var _utils_RNG__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/RNG */ "./src/streaming/metrics/utils/RNG.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function DVBReporting(config) {
config = config || {};
var instance;
var context = this.context;
var metricSerialiser, randomNumberGenerator, reportingPlayerStatusDecided, isReportingPlayer, reportingUrl, rangeController;
var pendingRequests = [];
var metricsConstants = config.metricsConstants;
function setup() {
metricSerialiser = Object(_utils_MetricSerialiser__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
randomNumberGenerator = Object(_utils_RNG__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
resetInitialSettings();
}
function doGetRequest(url, successCB, failureCB) {
var req = new XMLHttpRequest();
var oncomplete = function oncomplete() {
var reqIndex = pendingRequests.indexOf(req);
if (reqIndex === -1) {
return;
} else {
pendingRequests.splice(reqIndex, 1);
}
if (req.status >= 200 && req.status < 300) {
if (successCB) {
successCB();
}
} else {
if (failureCB) {
failureCB();
}
}
};
pendingRequests.push(req);
try {
req.open('GET', url);
req.onloadend = oncomplete;
req.onerror = oncomplete;
req.send();
} catch (e) {
req.onerror();
}
}
function report(type, vos) {
if (!Array.isArray(vos)) {
vos = [vos];
} // If the Player is not a reporting Player, then the Player shall
// not report any errors.
// ... In addition to any time restrictions specified by a Range
// element within the Metrics element.
if (isReportingPlayer && rangeController.isEnabled()) {
// This reporting mechanism operates by creating one HTTP GET
// request for every entry in the top level list of the metric.
vos.forEach(function (vo) {
var url = metricSerialiser.serialise(vo); // this has been proposed for errata
if (type !== metricsConstants.DVB_ERRORS) {
url = "metricname=".concat(type, "&").concat(url);
} // Take the value of the @reportingUrl attribute, append a
// question mark ('?') character and then append the string
// created in the previous step.
url = "".concat(reportingUrl, "?").concat(url); // Make an HTTP GET request to the URL contained within the
// string created in the previous step.
doGetRequest(url, null, function () {
// If the Player is unable to make the report, for
// example because the @reportingUrl is invalid, the
// host cannot be reached, or an HTTP status code other
// than one in the 200 series is received, the Player
// shall cease being a reporting Player for the
// duration of the MPD.
isReportingPlayer = false;
});
});
}
}
function initialize(entry, rc) {
var probability;
rangeController = rc;
reportingUrl = entry.dvb_reportingUrl; // If a required attribute is missing, the Reporting descriptor may
// be ignored by the Player
if (!reportingUrl) {
throw new Error('required parameter missing (dvb:reportingUrl)');
} // A Player's status, as a reporting Player or not, shall remain
// static for the duration of the MPD, regardless of MPD updates.
// (i.e. only calling reset (or failure) changes this state)
if (!reportingPlayerStatusDecided) {
probability = entry.dvb_probability; // TS 103 285 Clause 10.12.3.4
// If the @probability attribute is set to 1000, it shall be a reporting Player.
// If the @probability attribute is absent it will take the default value of 1000.
// For any other value of the @probability attribute, it shall decide at random whether to be a
// reporting Player, such that the probability of being one is @probability/1000.
if (probability && (probability === 1000 || probability / 1000 >= randomNumberGenerator.random())) {
isReportingPlayer = true;
}
reportingPlayerStatusDecided = true;
}
}
function resetInitialSettings() {
reportingPlayerStatusDecided = false;
isReportingPlayer = false;
reportingUrl = null;
rangeController = null;
}
function reset() {
resetInitialSettings();
}
instance = {
report: report,
initialize: initialize,
reset: reset
};
setup();
return instance;
}
DVBReporting.__dashjs_factory_name = 'DVBReporting';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(DVBReporting));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/utils/DVBErrorsTranslator.js":
/*!************************************************************!*\
!*** ./src/streaming/metrics/utils/DVBErrorsTranslator.js ***!
\************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/DVBErrors */ "./src/streaming/metrics/vo/DVBErrors.js");
/* harmony import */ var _MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../MetricsReportingEvents */ "./src/streaming/metrics/MetricsReportingEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function DVBErrorsTranslator(config) {
config = config || {};
var instance, mpd;
var eventBus = config.eventBus;
var dashMetrics = config.dashMetrics;
var metricsConstants = config.metricsConstants; //MediaPlayerEvents have been added to Events in MediaPlayer class
var Events = config.events;
function report(vo) {
var o = new _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__["default"]();
if (!mpd) {
return;
}
for (var key in vo) {
if (vo.hasOwnProperty(key)) {
o[key] = vo[key];
}
}
if (!o.mpdurl) {
o.mpdurl = mpd.originalUrl || mpd.url;
}
if (!o.terror) {
o.terror = new Date();
}
dashMetrics.addDVBErrors(o);
}
function onManifestUpdate(e) {
if (e.error) {
return;
}
mpd = e.manifest;
}
function onServiceLocationChanged(e) {
report({
errorcode: _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__["default"].BASE_URL_CHANGED,
servicelocation: e.entry
});
}
function onBecameReporter() {
report({
errorcode: _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__["default"].BECAME_REPORTER
});
}
function handleHttpMetric(vo) {
if (vo.responsecode === 0 || // connection failure - unknown
vo.responsecode == null || // Generated on .catch() and when uninitialised
vo.responsecode >= 400 || // HTTP error status code
vo.responsecode < 100 || // unknown status codes
vo.responsecode >= 600) {
// unknown status codes
report({
errorcode: vo.responsecode || _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__["default"].CONNECTION_ERROR,
url: vo.url,
terror: vo.tresponse,
servicelocation: vo._serviceLocation
});
}
}
function onMetricEvent(e) {
switch (e.metric) {
case metricsConstants.HTTP_REQUEST:
handleHttpMetric(e.value);
break;
default:
break;
}
}
function onPlaybackError(e) {
var reason = e.error ? e.error.code : 0;
var errorcode;
switch (reason) {
case MediaError.MEDIA_ERR_NETWORK:
errorcode = _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__["default"].CONNECTION_ERROR;
break;
case MediaError.MEDIA_ERR_DECODE:
errorcode = _vo_DVBErrors__WEBPACK_IMPORTED_MODULE_0__["default"].CORRUPT_MEDIA_OTHER;
break;
default:
return;
}
report({
errorcode: errorcode
});
}
function initialise() {
eventBus.on(Events.MANIFEST_UPDATED, onManifestUpdate, instance);
eventBus.on(Events.SERVICE_LOCATION_BLACKLIST_CHANGED, onServiceLocationChanged, instance);
eventBus.on(Events.METRIC_ADDED, onMetricEvent, instance);
eventBus.on(Events.METRIC_UPDATED, onMetricEvent, instance);
eventBus.on(Events.PLAYBACK_ERROR, onPlaybackError, instance);
eventBus.on(_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_1__["default"].BECAME_REPORTING_PLAYER, onBecameReporter, instance);
}
function reset() {
eventBus.off(Events.MANIFEST_UPDATED, onManifestUpdate, instance);
eventBus.off(Events.SERVICE_LOCATION_BLACKLIST_CHANGED, onServiceLocationChanged, instance);
eventBus.off(Events.METRIC_ADDED, onMetricEvent, instance);
eventBus.off(Events.METRIC_UPDATED, onMetricEvent, instance);
eventBus.off(Events.PLAYBACK_ERROR, onPlaybackError, instance);
eventBus.off(_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_1__["default"].BECAME_REPORTING_PLAYER, onBecameReporter, instance);
}
instance = {
initialise: initialise,
reset: reset
};
return instance;
}
DVBErrorsTranslator.__dashjs_factory_name = 'DVBErrorsTranslator';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(DVBErrorsTranslator));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/utils/HandlerHelpers.js":
/*!*******************************************************!*\
!*** ./src/streaming/metrics/utils/HandlerHelpers.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @ignore
*/
function HandlerHelpers() {
return {
reconstructFullMetricName: function reconstructFullMetricName(key, n, type) {
var mn = key;
if (n) {
mn += '(' + n;
if (type && type.length) {
mn += ',' + type;
}
mn += ')';
}
return mn;
},
validateN: function validateN(n_ms) {
if (!n_ms) {
throw new Error('missing n');
}
if (isNaN(n_ms)) {
throw new Error('n is NaN');
} // n is a positive integer is defined to refer to the metric
// in which the buffer level is recorded every n ms.
if (n_ms < 0) {
throw new Error('n must be positive');
}
return n_ms;
}
};
}
HandlerHelpers.__dashjs_factory_name = 'HandlerHelpers';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(HandlerHelpers));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/utils/ManifestParsing.js":
/*!********************************************************!*\
!*** ./src/streaming/metrics/utils/ManifestParsing.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_Metrics__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/Metrics */ "./src/streaming/metrics/vo/Metrics.js");
/* harmony import */ var _vo_Range__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/Range */ "./src/streaming/metrics/vo/Range.js");
/* harmony import */ var _vo_Reporting__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/Reporting */ "./src/streaming/metrics/vo/Reporting.js");
function ManifestParsing(config) {
config = config || {};
var instance;
var adapter = config.adapter;
var constants = config.constants;
function getMetricsRangeStartTime(manifest, dynamic, range) {
var voPeriods, reportingStartTime;
var presentationStartTime = 0;
if (dynamic) {
// For services with MPD@type='dynamic', the start time is
// indicated in wall clock time by adding the value of this
// attribute to the value of the MPD@availabilityStartTime
// attribute.
presentationStartTime = adapter.getAvailabilityStartTime(manifest) / 1000;
} else {
// For services with MPD@type='static', the start time is indicated
// in Media Presentation time and is relative to the PeriodStart
// time of the first Period in this MPD.
voPeriods = adapter.getRegularPeriods(manifest);
if (voPeriods.length) {
presentationStartTime = voPeriods[0].start;
}
} // When not present, DASH Metrics collection is
// requested from the beginning of content
// consumption.
reportingStartTime = presentationStartTime;
if (range && range.hasOwnProperty(constants.START_TIME)) {
reportingStartTime += range.starttime;
}
return reportingStartTime;
}
function getMetrics(manifest) {
var metrics = [];
if (manifest && manifest.Metrics_asArray) {
manifest.Metrics_asArray.forEach(function (metric) {
var metricEntry = new _vo_Metrics__WEBPACK_IMPORTED_MODULE_0__["default"]();
var isDynamic = adapter.getIsDynamic(manifest);
if (metric.hasOwnProperty('metrics')) {
metricEntry.metrics = metric.metrics;
} else {
return;
}
if (metric.Range_asArray) {
metric.Range_asArray.forEach(function (range) {
var rangeEntry = new _vo_Range__WEBPACK_IMPORTED_MODULE_1__["default"]();
rangeEntry.starttime = getMetricsRangeStartTime(manifest, isDynamic, range);
if (range.hasOwnProperty('duration')) {
rangeEntry.duration = range.duration;
} else {
// if not present, the value is identical to the
// Media Presentation duration.
rangeEntry.duration = adapter.getDuration(manifest);
}
rangeEntry._useWallClockTime = isDynamic;
metricEntry.Range.push(rangeEntry);
});
}
if (metric.Reporting_asArray) {
metric.Reporting_asArray.forEach(function (reporting) {
var reportingEntry = new _vo_Reporting__WEBPACK_IMPORTED_MODULE_2__["default"]();
if (reporting.hasOwnProperty(constants.SCHEME_ID_URI)) {
reportingEntry.schemeIdUri = reporting.schemeIdUri;
} else {
// Invalid Reporting. schemeIdUri must be set. Ignore.
return;
}
if (reporting.hasOwnProperty('value')) {
reportingEntry.value = reporting.value;
}
if (reporting.hasOwnProperty(constants.DVB_REPORTING_URL)) {
reportingEntry.dvb_reportingUrl = reporting[constants.DVB_REPORTING_URL];
}
if (reporting.hasOwnProperty(constants.DVB_PROBABILITY)) {
reportingEntry.dvb_probability = reporting[constants.DVB_PROBABILITY];
}
metricEntry.Reporting.push(reportingEntry);
});
} else {
// Invalid Metrics. At least one reporting must be present. Ignore
return;
}
metrics.push(metricEntry);
});
}
return metrics;
}
instance = {
getMetrics: getMetrics
};
return instance;
}
ManifestParsing.__dashjs_factory_name = 'ManifestParsing';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(ManifestParsing));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/utils/MetricSerialiser.js":
/*!*********************************************************!*\
!*** ./src/streaming/metrics/utils/MetricSerialiser.js ***!
\*********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @ignore
*/
function MetricSerialiser() {
// For each entry in the top level list within the metric (in the case
// of the DVBErrors metric each entry corresponds to an "error event"
// described in clause 10.8.4) the Player shall:
function serialise(metric) {
var pairs = [];
var obj = [];
var key, value; // Take each (key, value) pair from the metric entry and create a
// string consisting of the name of the key, followed by an equals
// ('=') character, followed by the string representation of the
// value. The string representation of the value is created based
// on the type of the value following the instructions in Table 22.
for (key in metric) {
if (metric.hasOwnProperty(key) && key.indexOf('_') !== 0) {
value = metric[key]; // we want to ensure that keys still end up in the report
// even if there is no value
if (value === undefined || value === null) {
value = '';
} // DVB A168 10.12.4 Table 22
if (Array.isArray(value)) {
// if trace or similar is null, do not include in output
if (!value.length) {
continue;
}
obj = [];
value.forEach(function (v) {
var isBuiltIn = Object.prototype.toString.call(v).slice(8, -1) !== 'Object';
obj.push(isBuiltIn ? v : serialise(v));
});
value = obj.map(encodeURIComponent).join(',');
} else if (typeof value === 'string') {
value = encodeURIComponent(value);
} else if (value instanceof Date) {
value = value.toISOString();
} else if (typeof value === 'number') {
value = Math.round(value);
}
pairs.push(key + '=' + value);
}
} // Concatenate the strings created in the previous step with an
// ampersand ('&') character between each one.
return pairs.join('&');
}
return {
serialise: serialise
};
}
MetricSerialiser.__dashjs_factory_name = 'MetricSerialiser';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(MetricSerialiser));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/utils/RNG.js":
/*!********************************************!*\
!*** ./src/streaming/metrics/utils/RNG.js ***!
\********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @ignore
*/
function RNG() {
// check whether secure random numbers are available. if not, revert to
// using Math.random
var crypto = window.crypto || window.msCrypto; // could just as easily use any other array type by changing line below
var ArrayType = Uint32Array;
var MAX_VALUE = Math.pow(2, ArrayType.BYTES_PER_ELEMENT * 8) - 1; // currently there is only one client for this code, and that only uses
// a single random number per initialisation. may want to increase this
// number if more consumers in the future
var NUM_RANDOM_NUMBERS = 10;
var randomNumbers, index, instance;
function initialise() {
if (crypto) {
if (!randomNumbers) {
randomNumbers = new ArrayType(NUM_RANDOM_NUMBERS);
}
crypto.getRandomValues(randomNumbers);
index = 0;
}
}
function rand(min, max) {
var r;
if (!min) {
min = 0;
}
if (!max) {
max = 1;
}
if (crypto) {
if (index === randomNumbers.length) {
initialise();
}
r = randomNumbers[index] / MAX_VALUE;
index += 1;
} else {
r = Math.random();
}
return r * (max - min) + min;
}
instance = {
random: rand
};
initialise();
return instance;
}
RNG.__dashjs_factory_name = 'RNG';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(RNG));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/metrics/vo/DVBErrors.js":
/*!***********************************************!*\
!*** ./src/streaming/metrics/vo/DVBErrors.js ***!
\***********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var DVBErrors = function DVBErrors() {
_classCallCheck(this, DVBErrors);
this.mpdurl = null; // String - Absolute URL from which the MPD was originally
// retrieved (MPD updates will not change this value).
this.errorcode = null; // String - The value of errorcode depends upon the type
// of error being reported. For an error listed in the
// ErrorType column below the value is as described in the
// Value column.
//
// ErrorType Value
// --------- -----
// HTTP error status code HTTP status code
// Unknown HTTP status code HTTP status code
// SSL connection failed "SSL" followed by SSL alert value
// DNS resolution failed "C00"
// Host unreachable "C01"
// Connection refused "C02"
// Connection error Not otherwise specified "C03"
// Corrupt media ISO BMFF container cannot be parsed "M00"
// Corrupt media Not otherwise specified "M01"
// Changing Base URL in use due to errors "F00"
// Becoming an error reporting Player "S00"
this.terror = null; // Real-Time - Date and time at which error occurred in UTC,
// formatted as a combined date and time according to ISO 8601.
this.url = null; // String - Absolute URL from which data was being requested
// when this error occurred. If the error report is in relation
// to corrupt media or changing BaseURL, this may be a null
// string if the URL from which the media was obtained or
// which led to the change of BaseURL is no longer known.
this.ipaddress = null; // String - IP Address which the host name in "url" resolved to.
// If the error report is in relation to corrupt media or
// changing BaseURL, this may be a null string if the URL
// from which the media was obtained or which led to the
// change of BaseURL is no longer known.
this.servicelocation = null; // String - The value of the serviceLocation field in the
// BaseURL being used. In the event of this report indicating
// a change of BaseURL this is the value from the BaseURL
// being moved from.
};
DVBErrors.SSL_CONNECTION_FAILED_PREFIX = 'SSL';
DVBErrors.DNS_RESOLUTION_FAILED = 'C00';
DVBErrors.HOST_UNREACHABLE = 'C01';
DVBErrors.CONNECTION_REFUSED = 'C02';
DVBErrors.CONNECTION_ERROR = 'C03';
DVBErrors.CORRUPT_MEDIA_ISOBMFF = 'M00';
DVBErrors.CORRUPT_MEDIA_OTHER = 'M01';
DVBErrors.BASE_URL_CHANGED = 'F00';
DVBErrors.BECAME_REPORTER = 'S00';
/* harmony default export */ __webpack_exports__["default"] = (DVBErrors);
/***/ }),
/***/ "./src/streaming/metrics/vo/Metrics.js":
/*!*********************************************!*\
!*** ./src/streaming/metrics/vo/Metrics.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Metrics = function Metrics() {
_classCallCheck(this, Metrics);
this.metrics = '';
this.Range = [];
this.Reporting = [];
};
/* harmony default export */ __webpack_exports__["default"] = (Metrics);
/***/ }),
/***/ "./src/streaming/metrics/vo/Range.js":
/*!*******************************************!*\
!*** ./src/streaming/metrics/vo/Range.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Range = function Range() {
_classCallCheck(this, Range);
// as defined in ISO23009-1
this.starttime = 0;
this.duration = Infinity; // for internal use
this._useWallClockTime = false;
};
/* harmony default export */ __webpack_exports__["default"] = (Range);
/***/ }),
/***/ "./src/streaming/metrics/vo/Reporting.js":
/*!***********************************************!*\
!*** ./src/streaming/metrics/vo/Reporting.js ***!
\***********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
// TS 103 285 Clause 10.12.3.3
var DEFAULT_DVB_PROBABILITY = 1000;
var Reporting = function Reporting() {
_classCallCheck(this, Reporting);
this.schemeIdUri = '';
this.value = ''; // DVB Extensions
this.dvb_reportingUrl = '';
this.dvb_probability = DEFAULT_DVB_PROBABILITY;
};
/* harmony default export */ __webpack_exports__["default"] = (Reporting);
/***/ }),
/***/ "./src/streaming/models/BaseURLTreeModel.js":
/*!**************************************************!*\
!*** ./src/streaming/models/BaseURLTreeModel.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/ObjectUtils */ "./src/streaming/utils/ObjectUtils.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var DEFAULT_INDEX = NaN;
var Node = function Node(_baseUrls, _selectedIdx) {
_classCallCheck(this, Node);
this.data = {
baseUrls: _baseUrls || null,
selectedIdx: _selectedIdx || DEFAULT_INDEX
};
this.children = [];
};
function BaseURLTreeModel() {
var instance, root, adapter;
var context = this.context;
var objectUtils = Object(_utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
function setup() {
reset();
}
function setConfig(config) {
if (config.adapter) {
adapter = config.adapter;
}
}
function checkConfig() {
if (!adapter || !adapter.hasOwnProperty('getBaseURLsFromElement') || !adapter.hasOwnProperty('getRepresentationSortFunction')) {
throw new Error('setConfig function has to be called previously');
}
}
function updateChildData(node, index, element) {
var baseUrls = adapter.getBaseURLsFromElement(element);
if (!node[index]) {
node[index] = new Node(baseUrls);
} else {
if (!objectUtils.areEqual(baseUrls, node[index].data.baseUrls)) {
node[index].data.baseUrls = baseUrls;
node[index].data.selectedIdx = DEFAULT_INDEX;
}
}
}
function getBaseURLCollectionsFromManifest(manifest) {
checkConfig();
var baseUrls = adapter.getBaseURLsFromElement(manifest);
if (!objectUtils.areEqual(baseUrls, root.data.baseUrls)) {
root.data.baseUrls = baseUrls;
root.data.selectedIdx = DEFAULT_INDEX;
}
if (manifest && manifest.Period_asArray) {
manifest.Period_asArray.forEach(function (p, pi) {
updateChildData(root.children, pi, p);
if (p.AdaptationSet_asArray) {
p.AdaptationSet_asArray.forEach(function (a, ai) {
updateChildData(root.children[pi].children, ai, a);
if (a.Representation_asArray) {
a.Representation_asArray.sort(adapter.getRepresentationSortFunction()).forEach(function (r, ri) {
updateChildData(root.children[pi].children[ai].children, ri, r);
});
}
});
}
});
}
}
function walk(callback, node) {
var target = node || root;
callback(target.data);
if (target.children) {
target.children.forEach(function (child) {
return walk(callback, child);
});
}
}
function invalidateSelectedIndexes(serviceLocation) {
walk(function (data) {
if (!isNaN(data.selectedIdx)) {
if (serviceLocation === data.baseUrls[data.selectedIdx].serviceLocation) {
data.selectedIdx = DEFAULT_INDEX;
}
}
});
}
function update(manifest) {
getBaseURLCollectionsFromManifest(manifest);
}
function reset() {
root = new Node();
}
function getForPath(path) {
var target = root;
var nodes = [target.data];
if (path) {
path.forEach(function (p) {
target = target.children[p];
if (target) {
nodes.push(target.data);
}
});
}
return nodes.filter(function (n) {
return n.baseUrls.length;
});
}
instance = {
reset: reset,
update: update,
getForPath: getForPath,
invalidateSelectedIndexes: invalidateSelectedIndexes,
setConfig: setConfig
};
setup();
return instance;
}
BaseURLTreeModel.__dashjs_factory_name = 'BaseURLTreeModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(BaseURLTreeModel));
/***/ }),
/***/ "./src/streaming/models/CmcdModel.js":
/*!*******************************************!*\
!*** ./src/streaming/models/CmcdModel.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _metrics_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../metrics/MetricsReportingEvents */ "./src/streaming/metrics/MetricsReportingEvents.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _dash_models_DashManifestModel__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../dash/models/DashManifestModel */ "./src/dash/models/DashManifestModel.js");
/* harmony import */ var _core_Utils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../core/Utils */ "./src/core/Utils.js");
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var CMCD_REQUEST_FIELD_NAME = 'CMCD';
var CMCD_VERSION = 1;
var OBJECT_TYPES = {
MANIFEST: 'm',
AUDIO: 'a',
VIDEO: 'v',
INIT: 'i',
CAPTION: 'c',
ISOBMFF_TEXT_TRACK: 'tt',
ENCRYPTION_KEY: 'k',
OTHER: 'o'
};
var STREAMING_FORMATS = {
DASH: 'd',
MSS: 's'
};
var STREAM_TYPES = {
VOD: 'v',
LIVE: 'l'
};
var RTP_SAFETY_FACTOR = 5;
function CmcdModel() {
var dashManifestModel, instance, internalData, abrController, dashMetrics, playbackController, streamProcessors, _isStartup, _bufferLevelStarved, _initialMediaRequestsDone;
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
function setup() {
dashManifestModel = Object(_dash_models_DashManifestModel__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
_resetInitialSettings();
}
function initialize() {
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_LOADED, _onManifestLoaded, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].PLAYBACK_SEEKED, _onPlaybackSeeked, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].PERIOD_SWITCH_COMPLETED, _onPeriodSwitchComplete, instance);
}
function setConfig(config) {
if (!config) return;
if (config.abrController) {
abrController = config.abrController;
}
if (config.dashMetrics) {
dashMetrics = config.dashMetrics;
}
if (config.playbackController) {
playbackController = config.playbackController;
}
}
function _resetInitialSettings() {
internalData = {
pr: 1,
nor: null,
st: null,
sf: null,
sid: "".concat(_core_Utils__WEBPACK_IMPORTED_MODULE_8__["default"].generateUuid()),
cid: null
};
_bufferLevelStarved = {};
_isStartup = {};
_initialMediaRequestsDone = {};
_updateStreamProcessors();
}
function _onPeriodSwitchComplete() {
_updateStreamProcessors();
}
function _updateStreamProcessors() {
if (!playbackController) return;
var streamController = playbackController.getStreamController();
if (!streamController) return;
if (typeof streamController.getActiveStream !== 'function') return;
var activeStream = streamController.getActiveStream();
if (!activeStream) return;
streamProcessors = activeStream.getProcessors();
}
function getQueryParameter(request) {
try {
if (settings.get().streaming.cmcd && settings.get().streaming.cmcd.enabled) {
var cmcdData = _getCmcdData(request);
var finalPayloadString = _buildFinalString(cmcdData);
eventBus.trigger(_metrics_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_2__["default"].CMCD_DATA_GENERATED, {
url: request.url,
mediaType: request.mediaType,
cmcdData: cmcdData,
cmcdString: finalPayloadString
});
return {
key: CMCD_REQUEST_FIELD_NAME,
value: finalPayloadString
};
}
return null;
} catch (e) {
return null;
}
}
function _copyParameters(data, parameterNames) {
var copiedData = {};
var _iterator = _createForOfIteratorHelper(parameterNames),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var name = _step.value;
if (data[name]) {
copiedData[name] = data[name];
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return copiedData;
}
function getHeaderParameters(request) {
try {
if (settings.get().streaming.cmcd && settings.get().streaming.cmcd.enabled) {
var cmcdData = _getCmcdData(request);
var cmcdObjectHeader = _copyParameters(cmcdData, ['br', 'd', 'ot', 'tb']);
var cmcdRequestHeader = _copyParameters(cmcdData, ['bl', 'dl', 'mtp', 'nor', 'nrr', 'su']);
var cmcdStatusHeader = _copyParameters(cmcdData, ['bs', 'rtp']);
var cmcdSessionHeader = _copyParameters(cmcdData, ['cid', 'pr', 'sf', 'sid', 'st', 'v']);
var headers = {
'CMCD-Object': _buildFinalString(cmcdObjectHeader),
'CMCD-Request': _buildFinalString(cmcdRequestHeader),
'CMCD-Status': _buildFinalString(cmcdStatusHeader),
'CMCD-Session': _buildFinalString(cmcdSessionHeader)
};
eventBus.trigger(_metrics_MetricsReportingEvents__WEBPACK_IMPORTED_MODULE_2__["default"].CMCD_DATA_GENERATED, {
url: request.url,
mediaType: request.mediaType,
cmcdData: cmcdData,
headers: headers
});
return headers;
}
return null;
} catch (e) {
return null;
}
}
function _getCmcdData(request) {
try {
var cmcdData = null;
if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].MPD_TYPE) {
return _getCmcdDataForMpd(request);
} else if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].MEDIA_SEGMENT_TYPE) {
_initForMediaType(request.mediaType);
return _getCmcdDataForMediaSegment(request);
} else if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].INIT_SEGMENT_TYPE) {
return _getCmcdDataForInitSegment(request);
} else if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].OTHER_TYPE || request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].XLINK_EXPANSION_TYPE) {
return _getCmcdDataForOther(request);
} else if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_6__["HTTPRequest"].LICENSE) {
return _getCmcdDataForLicense(request);
}
return cmcdData;
} catch (e) {
return null;
}
}
function _getCmcdDataForLicense(request) {
var data = _getGenericCmcdData(request);
data.ot = OBJECT_TYPES.ENCRYPTION_KEY;
return data;
}
function _getCmcdDataForMpd() {
var data = _getGenericCmcdData();
data.ot = OBJECT_TYPES.MANIFEST;
return data;
}
function _getCmcdDataForMediaSegment(request) {
var data = _getGenericCmcdData();
var encodedBitrate = _getBitrateByRequest(request);
var d = _getObjectDurationByRequest(request);
var mtp = _getMeasuredThroughputByType(request.mediaType);
var dl = _getDeadlineByType(request.mediaType);
var bl = _getBufferLevelByType(request.mediaType);
var tb = _getTopBitrateByType(request.mediaType);
var pr = internalData.pr;
var nextRequest = _probeNextRequest(request.mediaType);
var ot;
if (request.mediaType === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].VIDEO) ot = OBJECT_TYPES.VIDEO;
if (request.mediaType === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].AUDIO) ot = OBJECT_TYPES.AUDIO;
if (request.mediaType === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].TEXT) {
if (request.mediaInfo.mimeType === 'application/mp4') {
ot = OBJECT_TYPES.ISOBMFF_TEXT_TRACK;
} else {
ot = OBJECT_TYPES.CAPTION;
}
}
var rtp = settings.get().streaming.cmcd.rtp;
if (!rtp) {
rtp = _calculateRtp(request);
}
data.rtp = rtp;
if (nextRequest) {
if (request.url !== nextRequest.url) {
data.nor = encodeURIComponent(_core_Utils__WEBPACK_IMPORTED_MODULE_8__["default"].getRelativeUrl(request.url, nextRequest.url));
} else if (nextRequest.range) {
data.nrr = nextRequest.range;
}
}
if (encodedBitrate) {
data.br = encodedBitrate;
}
if (ot) {
data.ot = ot;
}
if (!isNaN(d)) {
data.d = d;
}
if (!isNaN(mtp)) {
data.mtp = mtp;
}
if (!isNaN(dl)) {
data.dl = dl;
}
if (!isNaN(bl)) {
data.bl = bl;
}
if (!isNaN(tb)) {
data.tb = tb;
}
if (!isNaN(pr) && pr !== 1) {
data.pr = pr;
}
if (_bufferLevelStarved[request.mediaType]) {
data.bs = true;
_bufferLevelStarved[request.mediaType] = false;
}
if (_isStartup[request.mediaType] || !_initialMediaRequestsDone[request.mediaType]) {
data.su = true;
_isStartup[request.mediaType] = false;
_initialMediaRequestsDone[request.mediaType] = true;
}
return data;
}
function _initForMediaType(mediaType) {
if (!_initialMediaRequestsDone.hasOwnProperty(mediaType)) {
_initialMediaRequestsDone[mediaType] = false;
}
if (!_isStartup.hasOwnProperty(mediaType)) {
_isStartup[mediaType] = false;
}
if (!_bufferLevelStarved.hasOwnProperty(mediaType)) {
_bufferLevelStarved[mediaType] = false;
}
}
function _getCmcdDataForInitSegment() {
var data = _getGenericCmcdData();
data.ot = OBJECT_TYPES.INIT;
data.su = true;
return data;
}
function _getCmcdDataForOther() {
var data = _getGenericCmcdData();
data.ot = OBJECT_TYPES.OTHER;
return data;
}
function _getGenericCmcdData() {
var data = {};
var cid = settings.get().streaming.cmcd.cid ? settings.get().streaming.cmcd.cid : internalData.cid;
data.v = CMCD_VERSION;
data.sid = settings.get().streaming.cmcd.sid ? settings.get().streaming.cmcd.sid : internalData.sid;
data.sid = "".concat(data.sid);
if (cid) {
data.cid = "".concat(cid);
}
if (!isNaN(internalData.pr) && internalData.pr !== 1 && internalData.pr !== null) {
data.pr = internalData.pr;
}
if (internalData.st) {
data.st = internalData.st;
}
if (internalData.sf) {
data.sf = internalData.sf;
}
return data;
}
function _getBitrateByRequest(request) {
try {
var quality = request.quality;
var bitrateList = request.mediaInfo.bitrateList;
return parseInt(bitrateList[quality].bandwidth / 1000);
} catch (e) {
return null;
}
}
function _getTopBitrateByType(mediaType) {
try {
var info = abrController.getTopBitrateInfoFor(mediaType);
return Math.round(info.bitrate / 1000);
} catch (e) {
return null;
}
}
function _getObjectDurationByRequest(request) {
try {
return !isNaN(request.duration) ? Math.round(request.duration * 1000) : null;
} catch (e) {
return null;
}
}
function _getMeasuredThroughputByType(mediaType) {
try {
return parseInt(abrController.getThroughputHistory().getSafeAverageThroughput(mediaType) / 100) * 100;
} catch (e) {
return null;
}
}
function _getDeadlineByType(mediaType) {
try {
var playbackRate = internalData.pr;
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
if (!isNaN(playbackRate) && !isNaN(bufferLevel)) {
return parseInt(bufferLevel / playbackRate * 10) * 100;
}
return null;
} catch (e) {
return null;
}
}
function _getBufferLevelByType(mediaType) {
try {
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
if (!isNaN(bufferLevel)) {
return parseInt(bufferLevel * 10) * 100;
}
return null;
} catch (e) {
return null;
}
}
function _onPlaybackRateChanged(data) {
try {
internalData.pr = data.playbackRate;
} catch (e) {}
}
function _onManifestLoaded(data) {
try {
var isDynamic = dashManifestModel.getIsDynamic(data.data);
var st = isDynamic ? STREAM_TYPES.LIVE : STREAM_TYPES.VOD;
var sf = data.protocol && data.protocol === 'MSS' ? STREAMING_FORMATS.MSS : STREAMING_FORMATS.DASH;
internalData.st = "".concat(st);
internalData.sf = "".concat(sf);
} catch (e) {}
}
function _onBufferLevelStateChanged(data) {
try {
if (data.state && data.mediaType) {
if (data.state === _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_EMPTY) {
if (!_bufferLevelStarved[data.mediaType]) {
_bufferLevelStarved[data.mediaType] = true;
}
if (!_isStartup[data.mediaType]) {
_isStartup[data.mediaType] = true;
}
}
}
} catch (e) {}
}
function _onPlaybackSeeked() {
for (var key in _bufferLevelStarved) {
if (_bufferLevelStarved.hasOwnProperty(key)) {
_bufferLevelStarved[key] = true;
}
}
for (var _key in _isStartup) {
if (_isStartup.hasOwnProperty(_key)) {
_isStartup[_key] = true;
}
}
}
function _buildFinalString(cmcdData) {
try {
if (!cmcdData) {
return null;
}
var keys = Object.keys(cmcdData).sort(function (a, b) {
return a.localeCompare(b);
});
var length = keys.length;
var cmcdString = keys.reduce(function (acc, key, index) {
if (key === 'v' && cmcdData[key] === 1) return acc; // Version key should only be reported if it is != 1
if (typeof cmcdData[key] === 'string' && key !== 'ot' && key !== 'sf' && key !== 'st') {
var string = cmcdData[key].replace(/"/g, '\"');
acc += "".concat(key, "=\"").concat(string, "\"");
} else {
acc += "".concat(key, "=").concat(cmcdData[key]);
}
if (index < length - 1) {
acc += ',';
}
return acc;
}, '');
cmcdString = cmcdString.replace(/=true/g, ''); // Remove last comma at the end
cmcdString = cmcdString.replace(/,\s*$/, '');
return cmcdString;
} catch (e) {
return null;
}
}
function _probeNextRequest(mediaType) {
if (!streamProcessors || streamProcessors.length === 0) return;
var _iterator2 = _createForOfIteratorHelper(streamProcessors),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var streamProcessor = _step2.value;
if (streamProcessor.getType() === mediaType) {
return streamProcessor.probeNextRequest();
}
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
function _calculateRtp(request) {
// Get the values we need
var playbackRate = playbackController.getPlaybackRate();
if (!playbackRate) playbackRate = 1;
var quality = request.quality,
mediaType = request.mediaType,
mediaInfo = request.mediaInfo,
duration = request.duration;
var currentBufferLevel = _getBufferLevelByType(mediaType);
if (currentBufferLevel === 0) currentBufferLevel = 500;
var bitrate = mediaInfo.bitrateList[quality].bandwidth; // Calculate RTP
var segmentSize = bitrate * duration / 1000; // Calculate file size in kilobits
var timeToLoad = currentBufferLevel / playbackRate / 1000; // Calculate time available to load file in seconds
var minBandwidth = segmentSize / timeToLoad; // Calculate the exact bandwidth required
var rtpSafetyFactor = settings.get().streaming.cmcd.rtpSafetyFactor && !isNaN(settings.get().streaming.cmcd.rtpSafetyFactor) ? settings.get().streaming.cmcd.rtpSafetyFactor : RTP_SAFETY_FACTOR;
var maxBandwidth = minBandwidth * rtpSafetyFactor; // Include a safety buffer
var rtp = (parseInt(maxBandwidth / 100) + 1) * 100; // Round to the next multiple of 100
return rtp;
}
function reset() {
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, this);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_LOADED, _onManifestLoaded, this);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_1__["default"].PLAYBACK_SEEKED, _onPlaybackSeeked, instance);
_resetInitialSettings();
}
instance = {
getQueryParameter: getQueryParameter,
getHeaderParameters: getHeaderParameters,
setConfig: setConfig,
reset: reset,
initialize: initialize
};
setup();
return instance;
}
CmcdModel.__dashjs_factory_name = 'CmcdModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__["default"].getSingletonFactory(CmcdModel));
/***/ }),
/***/ "./src/streaming/models/FragmentModel.js":
/*!***********************************************!*\
!*** ./src/streaming/models/FragmentModel.js ***!
\***********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/FragmentRequest */ "./src/streaming/vo/FragmentRequest.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var FRAGMENT_MODEL_LOADING = 'loading';
var FRAGMENT_MODEL_EXECUTED = 'executed';
var FRAGMENT_MODEL_CANCELED = 'canceled';
var FRAGMENT_MODEL_FAILED = 'failed';
function FragmentModel(config) {
config = config || {};
var eventBus = config.eventBus;
var events = config.events;
var dashMetrics = config.dashMetrics;
var fragmentLoader = config.fragmentLoader;
var debug = config.debug;
var streamInfo = config.streamInfo;
var type = config.type;
var instance, logger, executedRequests, loadingRequests;
function setup() {
logger = debug.getLogger(instance);
resetInitialSettings();
eventBus.on(events.LOADING_COMPLETED, onLoadingCompleted, instance);
eventBus.on(events.LOADING_DATA_PROGRESS, onLoadingInProgress, instance);
eventBus.on(events.LOADING_ABANDONED, onLoadingAborted, instance);
}
function getStreamId() {
return streamInfo.id;
}
function getType() {
return type;
}
function isFragmentLoaded(request) {
var isEqualComplete = function isEqualComplete(req1, req2) {
return req1.action === _vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_1__["default"].ACTION_COMPLETE && req1.action === req2.action;
};
var isEqualMedia = function isEqualMedia(req1, req2) {
return !isNaN(req1.index) && req1.startTime === req2.startTime && req1.adaptationIndex === req2.adaptationIndex && req1.type === req2.type;
};
var isEqualInit = function isEqualInit(req1, req2) {
return isNaN(req1.index) && isNaN(req2.index) && req1.quality === req2.quality;
};
var check = function check(requests) {
var isLoaded = false;
requests.some(function (req) {
if (isEqualMedia(request, req) || isEqualInit(request, req) || isEqualComplete(request, req)) {
isLoaded = true;
return isLoaded;
}
});
return isLoaded;
};
if (!request) {
return false;
}
return check(executedRequests);
}
function isFragmentLoadedOrPending(request) {
var isLoaded = false;
var i = 0;
var req; // First, check if the fragment has already been loaded
isLoaded = isFragmentLoaded(request); // Then, check if the fragment is about to be loeaded
if (!isLoaded) {
for (i = 0; i < loadingRequests.length; i++) {
req = loadingRequests[i];
if (request.url === req.url && request.startTime === req.startTime) {
isLoaded = true;
}
}
}
return isLoaded;
}
/**
*
* Gets an array of {@link FragmentRequest} objects
*
* @param {Object} filter The object with properties by which the method filters the requests to be returned.
* the only mandatory property is state, which must be a value from
* other properties should match the properties of {@link FragmentRequest}. E.g.:
* getRequests({state: FragmentModel.FRAGMENT_MODEL_EXECUTED, quality: 0}) - returns
* all the requests from executedRequests array where requests.quality = filter.quality
*
* @returns {Array}
* @memberof FragmentModel#
*/
function getRequests(filter) {
var states = filter ? filter.state instanceof Array ? filter.state : [filter.state] : [];
var filteredRequests = [];
states.forEach(function (state) {
var requests = getRequestsForState(state);
filteredRequests = filteredRequests.concat(filterRequests(requests, filter));
});
return filteredRequests;
}
function getRequestThreshold(req) {
return isNaN(req.duration) ? 0.25 : Math.min(req.duration / 8, 0.5);
}
function removeExecutedRequestsBeforeTime(time) {
executedRequests = executedRequests.filter(function (req) {
var threshold = getRequestThreshold(req);
return isNaN(req.startTime) || (time !== undefined ? req.startTime >= time - threshold : false);
});
}
function removeExecutedRequestsAfterTime(time) {
executedRequests = executedRequests.filter(function (req) {
return isNaN(req.startTime) || (time !== undefined ? req.startTime < time : false);
});
}
function removeExecutedRequestsInTimeRange(start, end) {
if (end <= start + 0.5) {
return;
}
executedRequests = executedRequests.filter(function (req) {
var threshold = getRequestThreshold(req);
return isNaN(req.startTime) || req.startTime >= end - threshold || isNaN(req.duration) || req.startTime + req.duration <= start + threshold;
});
} // Remove requests that are not "represented" by any of buffered ranges
function syncExecutedRequestsWithBufferedRange(bufferedRanges, streamDuration) {
if (!bufferedRanges || bufferedRanges.length === 0) {
removeExecutedRequestsBeforeTime();
return;
}
var start = 0;
for (var i = 0, ln = bufferedRanges.length; i < ln; i++) {
removeExecutedRequestsInTimeRange(start, bufferedRanges.start(i));
start = bufferedRanges.end(i);
}
if (streamDuration > 0) {
removeExecutedRequestsInTimeRange(start, streamDuration);
}
}
function abortRequests() {
logger.debug('abort requests');
fragmentLoader.abort();
loadingRequests = [];
}
function executeRequest(request) {
switch (request.action) {
case _vo_FragmentRequest__WEBPACK_IMPORTED_MODULE_1__["default"].ACTION_DOWNLOAD:
addSchedulingInfoMetrics(request, FRAGMENT_MODEL_LOADING);
loadingRequests.push(request);
loadCurrentFragment(request);
break;
default:
logger.warn('Unknown request action.');
}
}
function loadCurrentFragment(request) {
eventBus.trigger(events.FRAGMENT_LOADING_STARTED, {
request: request
}, {
streamId: streamInfo.id,
mediaType: type
});
fragmentLoader.load(request);
}
function getRequestForTime(arr, time, threshold) {
// loop through the executed requests and pick the one for which the playback interval matches the given time
var lastIdx = arr.length - 1;
for (var i = lastIdx; i >= 0; i--) {
var req = arr[i];
var start = req.startTime;
var end = start + req.duration;
threshold = !isNaN(threshold) ? threshold : getRequestThreshold(req);
if (!isNaN(start) && !isNaN(end) && time + threshold >= start && time - threshold < end || isNaN(start) && isNaN(time)) {
return req;
}
}
return null;
}
function filterRequests(arr, filter) {
// for time use a specific filtration function
if (filter.hasOwnProperty('time')) {
return [getRequestForTime(arr, filter.time, filter.threshold)];
}
return arr.filter(function (request) {
for (var prop in filter) {
if (prop === 'state') continue;
if (filter.hasOwnProperty(prop) && request[prop] != filter[prop]) return false;
}
return true;
});
}
function getRequestsForState(state) {
var requests;
switch (state) {
case FRAGMENT_MODEL_LOADING:
requests = loadingRequests;
break;
case FRAGMENT_MODEL_EXECUTED:
requests = executedRequests;
break;
default:
requests = [];
}
return requests;
}
function addSchedulingInfoMetrics(request, state) {
dashMetrics.addSchedulingInfo(request, state);
dashMetrics.addRequestsQueue(request.mediaType, loadingRequests, executedRequests);
}
function onLoadingCompleted(e) {
if (e.sender !== fragmentLoader) return;
loadingRequests.splice(loadingRequests.indexOf(e.request), 1);
if (e.response && !e.error) {
executedRequests.push(e.request);
}
addSchedulingInfoMetrics(e.request, e.error ? FRAGMENT_MODEL_FAILED : FRAGMENT_MODEL_EXECUTED);
eventBus.trigger(events.FRAGMENT_LOADING_COMPLETED, {
request: e.request,
response: e.response,
error: e.error,
sender: this
}, {
streamId: streamInfo.id,
mediaType: type
});
}
function onLoadingInProgress(e) {
if (e.sender !== fragmentLoader) return;
eventBus.trigger(events.FRAGMENT_LOADING_PROGRESS, {
request: e.request,
response: e.response,
error: e.error,
sender: this
}, {
streamId: streamInfo.id,
mediaType: type
});
}
function onLoadingAborted(e) {
if (e.sender !== fragmentLoader) return;
eventBus.trigger(events.FRAGMENT_LOADING_ABANDONED, {
request: e.request
}, {
streamId: streamInfo.id,
mediaType: type
});
}
function resetInitialSettings() {
executedRequests = [];
loadingRequests = [];
}
function reset() {
eventBus.off(events.LOADING_COMPLETED, onLoadingCompleted, this);
eventBus.off(events.LOADING_DATA_PROGRESS, onLoadingInProgress, this);
eventBus.off(events.LOADING_ABANDONED, onLoadingAborted, this);
if (fragmentLoader) {
fragmentLoader.reset();
}
resetInitialSettings();
}
function addExecutedRequest(request) {
executedRequests.push(request);
}
instance = {
getStreamId: getStreamId,
getType: getType,
getRequests: getRequests,
isFragmentLoaded: isFragmentLoaded,
isFragmentLoadedOrPending: isFragmentLoadedOrPending,
removeExecutedRequestsBeforeTime: removeExecutedRequestsBeforeTime,
removeExecutedRequestsAfterTime: removeExecutedRequestsAfterTime,
syncExecutedRequestsWithBufferedRange: syncExecutedRequestsWithBufferedRange,
abortRequests: abortRequests,
executeRequest: executeRequest,
reset: reset,
resetInitialSettings: resetInitialSettings,
addExecutedRequest: addExecutedRequest
};
setup();
return instance;
}
FragmentModel.__dashjs_factory_name = 'FragmentModel';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(FragmentModel);
factory.FRAGMENT_MODEL_LOADING = FRAGMENT_MODEL_LOADING;
factory.FRAGMENT_MODEL_EXECUTED = FRAGMENT_MODEL_EXECUTED;
factory.FRAGMENT_MODEL_CANCELED = FRAGMENT_MODEL_CANCELED;
factory.FRAGMENT_MODEL_FAILED = FRAGMENT_MODEL_FAILED;
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].updateClassFactory(FragmentModel.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/models/LowLatencyThroughputModel.js":
/*!***********************************************************!*\
!*** ./src/streaming/models/LowLatencyThroughputModel.js ***!
\***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function LowLatencyThroughputModel() {
var LLTM_MAX_MEASUREMENTS = 10; // factor (<1) is used to reduce the real needed download time when at very bleeding live edge
var LLTM_SEMI_OPTIMISTIC_ESTIMATE_FACTOR = 0.8;
var LLTM_OPTIMISTIC_ESTIMATE_FACTOR = 0.6;
var LLTM_SLOW_SEGMENT_DOWNLOAD_TOLERANCE = 1.05;
var LLTM_MAX_DELAY_MS = 250;
var context = this.context;
var instance;
var logger;
var measurements = {};
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
}
/**
* Linear regression with least squares method to get a trend function for buffer lavel at chunk receive timestamps
* @param {*} chunkMeasurements
* @returns linear trend function
*/
function createBufferLevelTrendFunction(chunkMeasurements) {
var result = {};
var sumX = 0;
var sumY = 0;
var sumXY = 0;
var sumXSq = 0;
var N = chunkMeasurements.length;
for (var i = 0; i < N; ++i) {
sumX += chunkMeasurements[i].chunkDownloadTimeRelativeMS;
sumY += chunkMeasurements[i].bufferLevel;
sumXY += chunkMeasurements[i].chunkDownloadTimeRelativeMS * chunkMeasurements[i].bufferLevel;
sumXSq += chunkMeasurements[i].chunkDownloadTimeRelativeMS * chunkMeasurements[i].chunkDownloadTimeRelativeMS;
}
result.m = (sumXY - sumX * sumY / N) / (sumXSq - sumX * sumX / N);
result.b = sumY / N - result.m * sumX / N;
return function (x) {
return result.m * x + result.b;
};
}
function isBufferSafeAndStable(lastMeasurements) {
var isBufferSafeAndStable = true;
var lastBitrate;
var aveBufferLevelLastSegements = lastMeasurements.reduce(function (prev, curr) {
return prev + curr.bufferLevelAtSegmentEnd;
}, 0) / lastMeasurements.length;
lastMeasurements.forEach(function (m) {
// inner segment buffer stability
if (Math.abs(m.bufferLevelAtSegmentEnd / m.bufferLevelAtSegmentStart) < 0.95) {
isBufferSafeAndStable = false;
} // inter segment buffer stability
if (m.bufferLevelAtSegmentEnd / aveBufferLevelLastSegements < 0.8) {
isBufferSafeAndStable = false;
} // representation bitrate remained at least constant
if (!lastBitrate) {
lastBitrate = m.bitrate;
} else if (lastBitrate > m.bitrate) {
isBufferSafeAndStable = false;
}
});
return isBufferSafeAndStable;
}
/**
* Based on the MPD, timing and buffer information of the last recent segments and their chunks
* the most stable download time (in milliseconds) is calculated.
* @param {*} request HTTPLoader request object
* @returns download time in milliseconds of last fetched segment
*/
function getEstimatedDownloadDurationMS(request) {
var lastMeasurement = measurements[request.mediaType].slice(-1).pop();
var lastThreeMeasurements = measurements[request.mediaType].slice(-3); // calculate and remember the buffer level trend during the last fetched segment
var lastChunkRelativeTimeMS = lastMeasurement.chunkMeasurements.slice(-1).pop().chunkDownloadTimeRelativeMS;
lastMeasurement.bufferLevelAtSegmentStart = lastMeasurement.getEstimatedBufferLevel(lastChunkRelativeTimeMS / 2);
lastMeasurement.bufferLevelAtSegmentEnd = lastMeasurement.getEstimatedBufferLevel(lastChunkRelativeTimeMS);
var isBufferStable = isBufferSafeAndStable(lastThreeMeasurements);
var selectedOptimisticFactor = isBufferStable ? LLTM_OPTIMISTIC_ESTIMATE_FACTOR : LLTM_SEMI_OPTIMISTIC_ESTIMATE_FACTOR; // fetch duration was longer than segment duration, but buffer was stable
if (lastMeasurement.isBufferStable && lastMeasurement.segDurationMS * LLTM_SLOW_SEGMENT_DOWNLOAD_TOLERANCE < lastMeasurement.fetchDownloadDurationMS) {
return lastMeasurement.fetchDownloadDurationMS;
} // buffer is drying or fetch took too long
if (!isBufferStable || lastMeasurement.segDurationMS < lastMeasurement.fetchDownloadDurationMS) {
return lastMeasurement.fetchDownloadDurationMS * LLTM_SEMI_OPTIMISTIC_ESTIMATE_FACTOR;
} // did we requested a fully available segment? -> most accurate throughput calculation
// we use adjusted availability start time to decide
// Note: this "download mode" usually happens at startup and if requests are delayed artificially
if (lastMeasurement.adjustedAvailabilityStartTimeMS <= lastMeasurement.requestTimeMS + lastMeasurement.throughputCapacityDelayMS - lastMeasurement.segDurationMS) {
return lastMeasurement.fetchDownloadDurationMS * LLTM_SEMI_OPTIMISTIC_ESTIMATE_FACTOR;
} // get all chunks that have been downloaded before fetch reached bleeding live edge
// the remaining chunks loaded at production rate we will approximated
var chunkAvailablePeriod = lastMeasurement.requestTimeMS + lastMeasurement.throughputCapacityDelayMS - lastMeasurement.adjustedAvailabilityStartTimeMS;
var chunkBytesBBLE = 0; // BBLE -> Before bleeding live edge
var chunkDownloadtimeMSBBLE = 0;
var chunkCount = 0;
for (var index = 0; index < lastMeasurement.chunkMeasurements.length; index++) {
var chunk = lastMeasurement.chunkMeasurements[index];
if (chunkAvailablePeriod < chunkDownloadtimeMSBBLE + chunk.chunkDownloadDurationMS) {
break;
}
chunkDownloadtimeMSBBLE += chunk.chunkDownloadDurationMS;
chunkBytesBBLE += chunk.chunkBytes;
chunkCount++;
}
if (chunkAvailablePeriod < 0) {
logger.warn('request time was before adjusted availibitly start time');
} // there have to be some chunks available (20% of max count)
// otherwise we are at bleeding live edge and the few chunks are insufficient to estimate correctly
if (chunkBytesBBLE && chunkDownloadtimeMSBBLE && chunkCount > lastMeasurement.chunkMeasurements.length * 0.2) {
var downloadThroughput = chunkBytesBBLE / chunkDownloadtimeMSBBLE; // bytes per millesecond
var estimatedDownloadtimeMS = lastMeasurement.segmentBytes / downloadThroughput; // if real download was shorter then report this incl. semi optimistical estimate factor
if (lastMeasurement.fetchDownloadDurationMS < estimatedDownloadtimeMS) {
return lastMeasurement.fetchDownloadDurationMS * selectedOptimisticFactor;
}
return estimatedDownloadtimeMS * selectedOptimisticFactor;
} // when we are to tight at live edge and it's stable then
// we start to optimistically estimate download time
// in such a way that a switch to next rep will be possible
// optimistical estimate: assume download was fast enough for next higher rendition
var nextHigherBitrate = lastMeasurement.bitrate;
lastMeasurement.bitrateList.some(function (b) {
if (b.bandwidth > lastMeasurement.bitrate) {
nextHigherBitrate = b.bandwidth;
return true;
}
}); // already highest bitrate?
if (nextHigherBitrate === lastMeasurement.bitrate) {
return lastMeasurement.fetchDownloadDurationMS * selectedOptimisticFactor;
}
return selectedOptimisticFactor * lastMeasurement.segmentBytes * 8 * 1000 / nextHigherBitrate;
}
/**
* Get calculated value for a safe artificial delay of the next request to allow to accumulate some chunks.
* This allows better line throughput measurement.
* @param {*} request
* @param {*} currentBufferLevel current buffer level in milliseconds
* @returns delay in milliseconds
*/
function getThroughputCapacityDelayMS(request, currentBufferLevelMS) {
var lastThreeMeasurements = measurements[request.mediaType] && measurements[request.mediaType].slice(-3);
if (!lastThreeMeasurements || lastThreeMeasurements.length < 3) {
return 0;
} // in case not stable buffer, no artificially delay for the next request
if (!isBufferSafeAndStable(lastThreeMeasurements)) {
return 0;
} // allowed artificial delay is the min of quater of buffer level in milliseconds and LLTM_MAX_DELAY_MS
return currentBufferLevelMS / 4 > LLTM_MAX_DELAY_MS ? LLTM_MAX_DELAY_MS : currentBufferLevelMS / 4;
}
/**
* Add some measurement data for bookkeeping and being able to derive decisions on estimated throughput.
* @param {*} request HTTPLoader object to get MPD and media info from
* @param {*} fetchDownloadDurationMS Duration how long the fetch actually took
* @param {*} chunkMeasurements Array containing chunk timings and buffer levels
* @param {*} requestTimeMS Timestamp at which the fetch was initiated
* @param {*} throughputCapacityDelayMS An artificial delay that was used for this request
*/
function addMeasurement(request, fetchDownloadDurationMS, chunkMeasurements, requestTimeMS, throughputCapacityDelayMS) {
if (request && request.mediaType && !measurements[request.mediaType]) {
measurements[request.mediaType] = [];
}
var bitrateEntry = request.mediaInfo.bitrateList.find(function (item) {
return item.id === request.representationId;
});
measurements[request.mediaType].push({
index: request.index,
repId: request.representationId,
mediaType: request.mediaType,
requestTimeMS: requestTimeMS,
adjustedAvailabilityStartTimeMS: request.availabilityStartTime.getTime(),
segDurationMS: request.duration * 1000,
chunksDurationMS: chunkMeasurements.reduce(function (prev, curr) {
return prev + curr.chunkDownloadDurationMS;
}, 0),
segmentBytes: chunkMeasurements.reduce(function (prev, curr) {
return prev + curr.chunkBytes;
}, 0),
bitrate: bitrateEntry && bitrateEntry.bandwidth,
bitrateList: request.mediaInfo.bitrateList,
chunkMeasurements: chunkMeasurements,
fetchDownloadDurationMS: fetchDownloadDurationMS,
throughputCapacityDelayMS: throughputCapacityDelayMS,
getEstimatedBufferLevel: createBufferLevelTrendFunction(chunkMeasurements.slice(1)) // don't use first chunk's buffer level
}); // maintain only a maximum amount of most recent measurements
if (measurements[request.mediaType].length > LLTM_MAX_MEASUREMENTS) {
measurements[request.mediaType].shift();
}
}
instance = {
setup: setup,
addMeasurement: addMeasurement,
getThroughputCapacityDelayMS: getThroughputCapacityDelayMS,
getEstimatedDownloadDurationMS: getEstimatedDownloadDurationMS
};
setup();
return instance;
}
LowLatencyThroughputModel.__dashjs_factory_name = 'LowLatencyThroughputModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getSingletonFactory(LowLatencyThroughputModel));
/***/ }),
/***/ "./src/streaming/models/ManifestModel.js":
/*!***********************************************!*\
!*** ./src/streaming/models/ManifestModel.js ***!
\***********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ManifestModel() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var instance, manifest;
function getValue() {
return manifest;
}
function setValue(value) {
manifest = value;
if (value) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_LOADED, {
data: value
});
}
}
instance = {
getValue: getValue,
setValue: setValue
};
return instance;
}
ManifestModel.__dashjs_factory_name = 'ManifestModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(ManifestModel));
/***/ }),
/***/ "./src/streaming/models/MediaPlayerModel.js":
/*!**************************************************!*\
!*** ./src/streaming/models/MediaPlayerModel.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _dash_vo_UTCTiming__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../dash/vo/UTCTiming */ "./src/dash/vo/UTCTiming.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../rules/abr/ABRRulesCollection */ "./src/streaming/rules/abr/ABRRulesCollection.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var DEFAULT_MIN_BUFFER_TIME = 12;
var DEFAULT_MIN_BUFFER_TIME_FAST_SWITCH = 20;
var DEFAULT_LOW_LATENCY_LIVE_DELAY = 3.0;
var LOW_LATENCY_REDUCTION_FACTOR = 10;
var LOW_LATENCY_MULTIPLY_FACTOR = 5;
var DEFAULT_LIVE_LATENCY_CATCHUP_THRESHOLD_FACTOR = 4;
var MINIMUM_LIVE_LATENCY_CATCHUP = 5;
var DEFAULT_XHR_WITH_CREDENTIALS = false;
function MediaPlayerModel() {
var instance, UTCTimingSources, xhrWithCredentials, customABRRule;
var context = this.context;
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
function setup() {
UTCTimingSources = [];
xhrWithCredentials = {
"default": DEFAULT_XHR_WITH_CREDENTIALS
};
customABRRule = [];
} //TODO Should we use Object.define to have setters/getters? makes more readable code on other side.
function findABRCustomRuleIndex(rulename) {
var i;
for (i = 0; i < customABRRule.length; i++) {
if (customABRRule[i].rulename === rulename) {
return i;
}
}
return -1;
}
function getABRCustomRules() {
return customABRRule;
}
function addABRCustomRule(type, rulename, rule) {
if (typeof type !== 'string' || type !== _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_3__["default"].ABANDON_FRAGMENT_RULES && type !== _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_3__["default"].QUALITY_SWITCH_RULES || typeof rulename !== 'string') {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].BAD_ARGUMENT_ERROR;
}
var index = findABRCustomRuleIndex(rulename);
if (index === -1) {
// add rule
customABRRule.push({
type: type,
rulename: rulename,
rule: rule
});
} else {
// update rule
customABRRule[index].type = type;
customABRRule[index].rule = rule;
}
}
function removeABRCustomRule(rulename) {
if (rulename) {
var index = findABRCustomRuleIndex(rulename); //if no rulename custom rule has been found, do nothing
if (index !== -1) {
// remove rule
customABRRule.splice(index, 1);
}
} else {
//if no rulename is defined, remove all ABR custome rules
customABRRule = [];
}
}
function getInitialBufferLevel() {
var initialBufferLevel = settings.get().streaming.buffer.initialBufferLevel;
if (isNaN(initialBufferLevel) || initialBufferLevel < 0) {
return 0;
}
return Math.min(getStableBufferTime(), initialBufferLevel);
}
function getStableBufferTime() {
if (settings.get().streaming.lowLatencyEnabled) {
return getLiveDelay();
}
var stableBufferTime = settings.get().streaming.buffer.stableBufferTime;
return stableBufferTime > 0 ? stableBufferTime : settings.get().streaming.buffer.fastSwitchEnabled ? DEFAULT_MIN_BUFFER_TIME_FAST_SWITCH : DEFAULT_MIN_BUFFER_TIME;
}
function getRetryAttemptsForType(type) {
var lowLatencyMultiplyFactor = !isNaN(settings.get().streaming.retryAttempts.lowLatencyMultiplyFactor) ? settings.get().streaming.retryAttempts.lowLatencyMultiplyFactor : LOW_LATENCY_MULTIPLY_FACTOR;
return settings.get().streaming.lowLatencyEnabled ? settings.get().streaming.retryAttempts[type] * lowLatencyMultiplyFactor : settings.get().streaming.retryAttempts[type];
}
function getRetryIntervalsForType(type) {
var lowLatencyReductionFactor = !isNaN(settings.get().streaming.retryIntervals.lowLatencyReductionFactor) ? settings.get().streaming.retryIntervals.lowLatencyReductionFactor : LOW_LATENCY_REDUCTION_FACTOR;
return settings.get().streaming.lowLatencyEnabled ? settings.get().streaming.retryIntervals[type] / lowLatencyReductionFactor : settings.get().streaming.retryIntervals[type];
}
function getLiveDelay() {
if (settings.get().streaming.lowLatencyEnabled) {
return settings.get().streaming.delay.liveDelay || DEFAULT_LOW_LATENCY_LIVE_DELAY;
}
return settings.get().streaming.delay.liveDelay;
}
function getLiveCatchupLatencyThreshold() {
try {
var liveCatchupLatencyThreshold = settings.get().streaming.liveCatchup.latencyThreshold;
var liveDelay = getLiveDelay();
if (liveCatchupLatencyThreshold !== null && !isNaN(liveCatchupLatencyThreshold)) {
return Math.max(liveCatchupLatencyThreshold, liveDelay);
}
var liveCatchupMinDrift = settings.get().streaming.liveCatchup.minDrift;
var maximumLiveDelay = !isNaN(liveDelay) && liveDelay ? !isNaN(liveCatchupMinDrift) ? settings.get().streaming.liveCatchup.minDrift + getLiveDelay() : getLiveDelay() : NaN;
if (maximumLiveDelay && !isNaN(maximumLiveDelay)) {
return Math.max(maximumLiveDelay * DEFAULT_LIVE_LATENCY_CATCHUP_THRESHOLD_FACTOR, MINIMUM_LIVE_LATENCY_CATCHUP);
}
return NaN;
} catch (e) {
return NaN;
}
}
function addUTCTimingSource(schemeIdUri, value) {
removeUTCTimingSource(schemeIdUri, value); //check if it already exists and remove if so.
var vo = new _dash_vo_UTCTiming__WEBPACK_IMPORTED_MODULE_0__["default"]();
vo.schemeIdUri = schemeIdUri;
vo.value = value;
UTCTimingSources.push(vo);
}
function getUTCTimingSources() {
return UTCTimingSources;
}
function removeUTCTimingSource(schemeIdUri, value) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_5__["checkParameterType"])(schemeIdUri, 'string');
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_5__["checkParameterType"])(value, 'string');
UTCTimingSources.forEach(function (obj, idx) {
if (obj.schemeIdUri === schemeIdUri && obj.value === value) {
UTCTimingSources.splice(idx, 1);
}
});
}
function clearDefaultUTCTimingSources() {
UTCTimingSources = [];
}
function restoreDefaultUTCTimingSources() {
var defaultUtcTimingSource = settings.get().streaming.utcSynchronization.defaultTimingSource;
addUTCTimingSource(defaultUtcTimingSource.scheme, defaultUtcTimingSource.value);
}
function setXHRWithCredentialsForType(type, value) {
if (!type) {
Object.keys(xhrWithCredentials).forEach(function (key) {
setXHRWithCredentialsForType(key, value);
});
} else {
xhrWithCredentials[type] = !!value;
}
}
function getXHRWithCredentialsForType(type) {
var useCreds = xhrWithCredentials[type];
return useCreds === undefined ? xhrWithCredentials["default"] : useCreds;
}
function getDefaultUtcTimingSource() {
return settings.get().streaming.utcSynchronization.defaultTimingSource;
}
function reset() {//TODO need to figure out what props to persist across sessions and which to reset if any.
//setup();
}
instance = {
getABRCustomRules: getABRCustomRules,
addABRCustomRule: addABRCustomRule,
removeABRCustomRule: removeABRCustomRule,
getStableBufferTime: getStableBufferTime,
getInitialBufferLevel: getInitialBufferLevel,
getRetryAttemptsForType: getRetryAttemptsForType,
getRetryIntervalsForType: getRetryIntervalsForType,
getLiveDelay: getLiveDelay,
getLiveCatchupLatencyThreshold: getLiveCatchupLatencyThreshold,
addUTCTimingSource: addUTCTimingSource,
removeUTCTimingSource: removeUTCTimingSource,
getUTCTimingSources: getUTCTimingSources,
clearDefaultUTCTimingSources: clearDefaultUTCTimingSources,
restoreDefaultUTCTimingSources: restoreDefaultUTCTimingSources,
setXHRWithCredentialsForType: setXHRWithCredentialsForType,
getXHRWithCredentialsForType: getXHRWithCredentialsForType,
getDefaultUtcTimingSource: getDefaultUtcTimingSource,
reset: reset
};
setup();
return instance;
} //TODO see if you can move this and not export and just getter to get default value.
MediaPlayerModel.__dashjs_factory_name = 'MediaPlayerModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getSingletonFactory(MediaPlayerModel));
/***/ }),
/***/ "./src/streaming/models/MetricsModel.js":
/*!**********************************************!*\
!*** ./src/streaming/models/MetricsModel.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _vo_MetricsList__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/MetricsList */ "./src/streaming/vo/MetricsList.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _vo_metrics_RepresentationSwitch__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/metrics/RepresentationSwitch */ "./src/streaming/vo/metrics/RepresentationSwitch.js");
/* harmony import */ var _vo_metrics_BufferLevel__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/metrics/BufferLevel */ "./src/streaming/vo/metrics/BufferLevel.js");
/* harmony import */ var _vo_metrics_BufferState__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../vo/metrics/BufferState */ "./src/streaming/vo/metrics/BufferState.js");
/* harmony import */ var _vo_metrics_DVRInfo__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../vo/metrics/DVRInfo */ "./src/streaming/vo/metrics/DVRInfo.js");
/* harmony import */ var _vo_metrics_DroppedFrames__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../vo/metrics/DroppedFrames */ "./src/streaming/vo/metrics/DroppedFrames.js");
/* harmony import */ var _vo_metrics_ManifestUpdate__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../vo/metrics/ManifestUpdate */ "./src/streaming/vo/metrics/ManifestUpdate.js");
/* harmony import */ var _vo_metrics_SchedulingInfo__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../vo/metrics/SchedulingInfo */ "./src/streaming/vo/metrics/SchedulingInfo.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _vo_metrics_RequestsQueue__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../vo/metrics/RequestsQueue */ "./src/streaming/vo/metrics/RequestsQueue.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function MetricsModel(config) {
config = config || {};
var settings = config.settings;
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
var instance, streamMetrics;
function setup() {
streamMetrics = {};
}
function metricsChanged() {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_13__["default"].METRICS_CHANGED);
}
function metricChanged(mediaType) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_13__["default"].METRIC_CHANGED, {
mediaType: mediaType
});
metricsChanged();
}
function metricUpdated(mediaType, metricType, vo) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_13__["default"].METRIC_UPDATED, {
mediaType: mediaType,
metric: metricType,
value: vo
});
metricChanged(mediaType);
}
function metricAdded(mediaType, metricType, vo) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_13__["default"].METRIC_ADDED, {
mediaType: mediaType,
metric: metricType,
value: vo
});
metricChanged(mediaType);
}
function clearCurrentMetricsForType(type) {
delete streamMetrics[type];
metricChanged(type);
}
function clearAllCurrentMetrics() {
streamMetrics = {};
metricsChanged();
}
function getMetricsFor(type, readOnly) {
var metrics = null;
if (!type) {
return metrics;
}
if (streamMetrics.hasOwnProperty(type)) {
metrics = streamMetrics[type];
} else if (!readOnly) {
metrics = new _vo_MetricsList__WEBPACK_IMPORTED_MODULE_2__["default"]();
streamMetrics[type] = metrics;
}
return metrics;
}
function pushMetrics(type, list, value) {
var metrics = getMetricsFor(type);
if (metrics !== null) {
metrics[list].push(value);
if (metrics[list].length > settings.get().streaming.metrics.maxListDepth) {
metrics[list].shift();
}
}
}
function appendHttpTrace(httpRequest, s, d, b, t) {
var vo = new _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__["HTTPRequestTrace"]();
vo.s = s;
vo.d = d;
vo.b = b;
vo.t = t;
httpRequest.trace.push(vo);
if (!httpRequest.interval) {
httpRequest.interval = 0;
}
httpRequest.interval += d;
return vo;
}
function addHttpRequest(mediaType, tcpid, type, url, quality, actualurl, serviceLocation, range, trequest, tresponse, tfinish, responsecode, mediaduration, responseHeaders, traces) {
var vo = new _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__["HTTPRequest"](); // ISO 23009-1 D.4.3 NOTE 2:
// All entries for a given object will have the same URL and range
// and so can easily be correlated. If there were redirects or
// failures there will be one entry for each redirect/failure.
// The redirect-to URL or alternative url (where multiple have been
// provided in the MPD) will appear as the actualurl of the next
// entry with the same url value.
if (actualurl && actualurl !== url) {
// given the above, add an entry for the original request
addHttpRequest(mediaType, null, type, url, quality, null, null, range, trequest, null, // unknown
null, // unknown
null, // unknown, probably a 302
mediaduration, null, null);
vo.actualurl = actualurl;
}
vo.tcpid = tcpid;
vo.type = type;
vo.url = url;
vo.range = range;
vo.trequest = trequest;
vo.tresponse = tresponse;
vo.responsecode = responsecode;
vo._tfinish = tfinish;
vo._stream = mediaType;
vo._mediaduration = mediaduration;
vo._quality = quality;
vo._responseHeaders = responseHeaders;
vo._serviceLocation = serviceLocation;
if (traces) {
traces.forEach(function (trace) {
appendHttpTrace(vo, trace.s, trace.d, trace.b, trace.t);
});
} else {
// The interval and trace shall be absent for redirect and failure records.
delete vo.interval;
delete vo.trace;
}
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].HTTP_REQUEST, vo);
}
function addRepresentationSwitch(mediaType, t, mt, to, lto) {
var vo = new _vo_metrics_RepresentationSwitch__WEBPACK_IMPORTED_MODULE_4__["default"]();
vo.t = t;
vo.mt = mt;
vo.to = to;
if (lto) {
vo.lto = lto;
} else {
delete vo.lto;
}
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TRACK_SWITCH, vo);
}
function pushAndNotify(mediaType, metricType, metricObject) {
pushMetrics(mediaType, metricType, metricObject);
metricAdded(mediaType, metricType, metricObject);
}
function addBufferLevel(mediaType, t, level) {
var vo = new _vo_metrics_BufferLevel__WEBPACK_IMPORTED_MODULE_5__["default"]();
vo.t = t;
vo.level = level;
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LEVEL, vo);
}
function addBufferState(mediaType, state, target) {
var vo = new _vo_metrics_BufferState__WEBPACK_IMPORTED_MODULE_6__["default"]();
vo.target = target;
vo.state = state;
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_STATE, vo);
}
function addDVRInfo(mediaType, currentTime, mpd, range) {
var vo = new _vo_metrics_DVRInfo__WEBPACK_IMPORTED_MODULE_7__["default"]();
vo.time = currentTime;
vo.range = range;
vo.manifestInfo = mpd;
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVR_INFO, vo);
}
function addDroppedFrames(mediaType, quality) {
var vo = new _vo_metrics_DroppedFrames__WEBPACK_IMPORTED_MODULE_8__["default"]();
var list = getMetricsFor(mediaType).DroppedFrames;
if (!quality) {
return;
}
vo.time = quality.creationTime;
vo.droppedFrames = quality.droppedVideoFrames;
if (list.length > 0 && list[list.length - 1] == vo) {
return;
}
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DROPPED_FRAMES, vo);
}
function addSchedulingInfo(mediaType, t, type, startTime, availabilityStartTime, duration, quality, range, state) {
var vo = new _vo_metrics_SchedulingInfo__WEBPACK_IMPORTED_MODULE_10__["default"]();
vo.mediaType = mediaType;
vo.t = t;
vo.type = type;
vo.startTime = startTime;
vo.availabilityStartTime = availabilityStartTime;
vo.duration = duration;
vo.quality = quality;
vo.range = range;
vo.state = state;
pushAndNotify(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SCHEDULING_INFO, vo);
}
function addRequestsQueue(mediaType, loadingRequests, executedRequests) {
var vo = new _vo_metrics_RequestsQueue__WEBPACK_IMPORTED_MODULE_12__["default"]();
vo.loadingRequests = loadingRequests;
vo.executedRequests = executedRequests;
getMetricsFor(mediaType).RequestsQueue = vo;
metricAdded(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REQUESTS_QUEUE, vo);
}
function addManifestUpdate(mediaType, type, requestTime, fetchTime, availabilityStartTime, presentationStartTime, clientTimeOffset, currentTime, buffered, latency) {
var vo = new _vo_metrics_ManifestUpdate__WEBPACK_IMPORTED_MODULE_9__["ManifestUpdate"]();
vo.mediaType = mediaType;
vo.type = type;
vo.requestTime = requestTime; // when this manifest update was requested
vo.fetchTime = fetchTime; // when this manifest update was received
vo.availabilityStartTime = availabilityStartTime;
vo.presentationStartTime = presentationStartTime; // the seek point (liveEdge for dynamic, Stream[0].startTime for static)
vo.clientTimeOffset = clientTimeOffset; // the calculated difference between the server and client wall clock time
vo.currentTime = currentTime; // actual element.currentTime
vo.buffered = buffered; // actual element.ranges
vo.latency = latency; // (static is fixed value of zero. dynamic should be ((Now-@availabilityStartTime) - currentTime)
pushMetrics(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_UPDATE, vo);
metricAdded(mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_UPDATE, vo);
}
function updateManifestUpdateInfo(manifestUpdate, updatedFields) {
if (manifestUpdate) {
for (var field in updatedFields) {
manifestUpdate[field] = updatedFields[field];
}
metricUpdated(manifestUpdate.mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_UPDATE, manifestUpdate);
}
}
function addManifestUpdateStreamInfo(manifestUpdate, id, index, start, duration) {
if (manifestUpdate) {
var vo = new _vo_metrics_ManifestUpdate__WEBPACK_IMPORTED_MODULE_9__["ManifestUpdateStreamInfo"]();
vo.id = id;
vo.index = index;
vo.start = start;
vo.duration = duration;
manifestUpdate.streamInfo.push(vo);
metricUpdated(manifestUpdate.mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_UPDATE_STREAM_INFO, manifestUpdate);
}
}
function addManifestUpdateRepresentationInfo(manifestUpdate, id, index, streamIndex, mediaType, presentationTimeOffset, startNumber, fragmentInfoType) {
if (manifestUpdate && manifestUpdate.representationInfo) {
var vo = new _vo_metrics_ManifestUpdate__WEBPACK_IMPORTED_MODULE_9__["ManifestUpdateRepresentationInfo"]();
vo.id = id;
vo.index = index;
vo.streamIndex = streamIndex;
vo.mediaType = mediaType;
vo.startNumber = startNumber;
vo.fragmentInfoType = fragmentInfoType;
vo.presentationTimeOffset = presentationTimeOffset;
manifestUpdate.representationInfo.push(vo);
metricUpdated(manifestUpdate.mediaType, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].MANIFEST_UPDATE_TRACK_INFO, manifestUpdate);
}
}
function addPlayList(vo) {
if (vo.trace && Array.isArray(vo.trace)) {
vo.trace.forEach(function (trace) {
if (trace.hasOwnProperty('subreplevel') && !trace.subreplevel) {
delete trace.subreplevel;
}
});
} else {
delete vo.trace;
}
pushAndNotify(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PLAY_LIST, vo);
}
function addDVBErrors(vo) {
pushAndNotify(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM, _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DVB_ERRORS, vo);
}
instance = {
clearCurrentMetricsForType: clearCurrentMetricsForType,
clearAllCurrentMetrics: clearAllCurrentMetrics,
getMetricsFor: getMetricsFor,
addHttpRequest: addHttpRequest,
addRepresentationSwitch: addRepresentationSwitch,
addBufferLevel: addBufferLevel,
addBufferState: addBufferState,
addDVRInfo: addDVRInfo,
addDroppedFrames: addDroppedFrames,
addSchedulingInfo: addSchedulingInfo,
addRequestsQueue: addRequestsQueue,
addManifestUpdate: addManifestUpdate,
updateManifestUpdateInfo: updateManifestUpdateInfo,
addManifestUpdateStreamInfo: addManifestUpdateStreamInfo,
addManifestUpdateRepresentationInfo: addManifestUpdateRepresentationInfo,
addPlayList: addPlayList,
addDVBErrors: addDVBErrors
};
setup();
return instance;
}
MetricsModel.__dashjs_factory_name = 'MetricsModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_14__["default"].getSingletonFactory(MetricsModel));
/***/ }),
/***/ "./src/streaming/models/URIFragmentModel.js":
/*!**************************************************!*\
!*** ./src/streaming/models/URIFragmentModel.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_URIFragmentData__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/URIFragmentData */ "./src/streaming/vo/URIFragmentData.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Model class managing URI fragments.
* @ignore
*/
function URIFragmentModel() {
var instance, URIFragmentDataVO;
/**
* @param {string} uri The URI to parse for fragment extraction
* @memberof module:URIFragmentModel
* @instance
*/
function initialize(uri) {
URIFragmentDataVO = new _vo_URIFragmentData__WEBPACK_IMPORTED_MODULE_0__["default"]();
if (!uri) return null;
var hashIndex = uri.indexOf('#');
if (hashIndex !== -1) {
var fragments = uri.substr(hashIndex + 1).split('&');
for (var i = 0, len = fragments.length; i < len; ++i) {
var fragment = fragments[i];
var equalIndex = fragment.indexOf('=');
if (equalIndex !== -1) {
var key = fragment.substring(0, equalIndex);
if (URIFragmentDataVO.hasOwnProperty(key)) {
URIFragmentDataVO[key] = fragment.substr(equalIndex + 1);
}
}
}
}
}
/**
* @returns {URIFragmentData} Object containing supported URI fragments
* @memberof module:URIFragmentModel
* @instance
*/
function getURIFragmentData() {
return URIFragmentDataVO;
}
instance = {
initialize: initialize,
getURIFragmentData: getURIFragmentData
};
return instance;
}
URIFragmentModel.__dashjs_factory_name = 'URIFragmentModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getSingletonFactory(URIFragmentModel));
/***/ }),
/***/ "./src/streaming/models/VideoModel.js":
/*!********************************************!*\
!*** ./src/streaming/models/VideoModel.js ***!
\********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var READY_STATES_TO_EVENT_NAMES = new Map([[_constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_METADATA, 'loadedmetadata'], [_constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_CURRENT_DATA, 'loadeddata'], [_constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_FUTURE_DATA, 'canplay'], [_constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_ENOUGH_DATA, 'canplaythrough']]);
function VideoModel() {
var instance, logger, element, TTMLRenderingDiv;
var VIDEO_MODEL_WRONG_ELEMENT_TYPE = 'element is not video or audio DOM type!';
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
var stalledStreams = [];
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance().getLogger(instance);
}
function initialize() {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PLAYING, onPlaying, this);
}
function reset() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PLAYING, onPlaying, this);
}
function onPlaybackCanPlay() {
if (element) {
element.playbackRate = 1;
element.removeEventListener('canplay', onPlaybackCanPlay);
}
}
function setPlaybackRate(value) {
var ignoreReadyState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (!element) return;
if (!ignoreReadyState && element.readyState <= 2 && value > 0) {
// If media element hasn't loaded enough data to play yet, wait until it has
element.addEventListener('canplay', onPlaybackCanPlay);
} else {
element.playbackRate = value;
}
} //TODO Move the DVR window calculations from MediaPlayer to Here.
function setCurrentTime(currentTime, stickToBuffered) {
waitForReadyState(_constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_METADATA, function () {
if (element) {
//_currentTime = currentTime;
// We don't set the same currentTime because it can cause firing unexpected Pause event in IE11
// providing playbackRate property equals to zero.
if (element.currentTime === currentTime) {
return;
} // TODO Despite the fact that MediaSource 'open' event has been fired IE11 cannot set videoElement.currentTime
// immediately (it throws InvalidStateError). It seems that this is related to videoElement.readyState property
// Initially it is 0, but soon after 'open' event it goes to 1 and setting currentTime is allowed. Chrome allows to
// set currentTime even if readyState = 0.
// setTimeout is used to workaround InvalidStateError in IE11
try {
currentTime = stickToBuffered ? stickTimeToBuffered(currentTime) : currentTime;
element.currentTime = currentTime;
} catch (e) {
if (element.readyState === 0 && e.code === e.INVALID_STATE_ERR) {
setTimeout(function () {
element.currentTime = currentTime;
}, 400);
}
}
}
});
}
function stickTimeToBuffered(time) {
var buffered = getBufferRange();
var closestTime = time;
var closestDistance = 9999999999;
if (buffered) {
for (var i = 0; i < buffered.length; i++) {
var start = buffered.start(i);
var end = buffered.end(i);
var distanceToStart = Math.abs(start - time);
var distanceToEnd = Math.abs(end - time);
if (time >= start && time <= end) {
return time;
}
if (distanceToStart < closestDistance) {
closestDistance = distanceToStart;
closestTime = start;
}
if (distanceToEnd < closestDistance) {
closestDistance = distanceToEnd;
closestTime = end;
}
}
}
return closestTime;
}
function getElement() {
return element;
}
function setElement(value) {
//add check of value type
if (value === null || value === undefined || value && /^(VIDEO|AUDIO)$/i.test(value.nodeName)) {
element = value; // Workaround to force Firefox to fire the canplay event.
if (element) {
element.preload = 'auto';
}
} else {
throw VIDEO_MODEL_WRONG_ELEMENT_TYPE;
}
}
function setSource(source) {
if (element) {
if (source) {
element.src = source;
} else {
element.removeAttribute('src');
element.load();
}
}
}
function getSource() {
return element ? element.src : null;
}
function getTTMLRenderingDiv() {
return TTMLRenderingDiv;
}
function setTTMLRenderingDiv(div) {
TTMLRenderingDiv = div; // The styling will allow the captions to match the video window size and position.
TTMLRenderingDiv.style.position = 'absolute';
TTMLRenderingDiv.style.display = 'flex';
TTMLRenderingDiv.style.overflow = 'hidden';
TTMLRenderingDiv.style.pointerEvents = 'none';
TTMLRenderingDiv.style.top = 0;
TTMLRenderingDiv.style.left = 0;
}
function setStallState(type, state) {
stallStream(type, state);
}
function isStalled() {
return stalledStreams.length > 0;
}
function addStalledStream(type) {
if (type === null || !element || element.seeking || stalledStreams.indexOf(type) !== -1) {
return;
}
stalledStreams.push(type);
}
function removeStalledStream(type) {
var index = stalledStreams.indexOf(type);
if (type === null) {
return;
}
if (index !== -1) {
stalledStreams.splice(index, 1);
}
}
function stallStream(type, isStalled) {
if (isStalled) {
addStalledStream(type);
} else {
removeStalledStream(type);
}
} //Calling play on the element will emit playing - even if the stream is stalled. If the stream is stalled, emit a waiting event.
function onPlaying() {
if (element && isStalled() && element.playbackRate === 0) {
var event = document.createEvent('Event');
event.initEvent('waiting', true, false);
element.dispatchEvent(event);
}
}
function getPlaybackQuality() {
if (!element) {
return null;
}
var hasWebKit = 'webkitDroppedFrameCount' in element && 'webkitDecodedFrameCount' in element;
var hasQuality = ('getVideoPlaybackQuality' in element);
var result = null;
if (hasQuality) {
result = element.getVideoPlaybackQuality();
} else if (hasWebKit) {
result = {
droppedVideoFrames: element.webkitDroppedFrameCount,
totalVideoFrames: element.webkitDroppedFrameCount + element.webkitDecodedFrameCount,
creationTime: new Date()
};
}
return result;
}
function play() {
if (element) {
element.autoplay = true;
var p = element.play();
if (p && p["catch"] && typeof Promise !== 'undefined') {
p["catch"](function (e) {
if (e.name === 'NotAllowedError') {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_NOT_ALLOWED);
}
logger.warn("Caught pending play exception - continuing (".concat(e, ")"));
});
}
}
}
function isPaused() {
return element ? element.paused : null;
}
function pause() {
if (element) {
element.pause();
element.autoplay = false;
}
}
function isSeeking() {
return element ? element.seeking : null;
}
function getTime() {
return element ? element.currentTime : null;
}
function getPlaybackRate() {
return element ? element.playbackRate : null;
}
function getPlayedRanges() {
return element ? element.played : null;
}
function getEnded() {
return element ? element.ended : null;
}
function addEventListener(eventName, eventCallBack) {
if (element) {
element.addEventListener(eventName, eventCallBack);
}
}
function removeEventListener(eventName, eventCallBack) {
if (element) {
element.removeEventListener(eventName, eventCallBack);
}
}
function getReadyState() {
return element ? element.readyState : NaN;
}
function getBufferRange() {
return element ? element.buffered : null;
}
function getClientWidth() {
return element ? element.clientWidth : NaN;
}
function getClientHeight() {
return element ? element.clientHeight : NaN;
}
function getVideoWidth() {
return element ? element.videoWidth : NaN;
}
function getVideoHeight() {
return element ? element.videoHeight : NaN;
}
function getVideoRelativeOffsetTop() {
var parentElement = element.parentNode.host || element.parentNode;
return parentElement ? element.getBoundingClientRect().top - parentElement.getBoundingClientRect().top : NaN;
}
function getVideoRelativeOffsetLeft() {
var parentElement = element.parentNode.host || element.parentNode;
return parentElement ? element.getBoundingClientRect().left - parentElement.getBoundingClientRect().left : NaN;
}
function getTextTracks() {
return element ? element.textTracks : [];
}
function getTextTrack(kind, label, lang, isTTML, isEmbedded) {
if (element) {
for (var i = 0; i < element.textTracks.length; i++) {
//label parameter could be a number (due to adaptationSet), but label, the attribute of textTrack, is a string => to modify...
//label could also be undefined (due to adaptationSet)
if (element.textTracks[i].kind === kind && (label ? element.textTracks[i].label == label : true) && element.textTracks[i].language === lang && element.textTracks[i].isTTML === isTTML && element.textTracks[i].isEmbedded === isEmbedded) {
return element.textTracks[i];
}
}
}
return null;
}
function addTextTrack(kind, label, lang, isTTML, isEmbedded) {
if (!element) {
return null;
} // check if track of same type has not been already created for previous stream
// then use it (no way to remove existing text track from video element)
var track = getTextTrack(kind, label, lang, isTTML, isEmbedded);
if (!track) {
track = element.addTextTrack(kind, label, lang);
track.isEmbedded = isEmbedded;
track.isTTML = isTTML;
}
return track;
}
function appendChild(childElement) {
if (element) {
element.appendChild(childElement); //in Chrome, we need to differenciate textTrack with same lang, kind and label but different format (vtt, ttml, etc...)
if (childElement.isTTML !== undefined) {
element.textTracks[element.textTracks.length - 1].isTTML = childElement.isTTML;
element.textTracks[element.textTracks.length - 1].isEmbedded = childElement.isEmbedded;
}
}
}
function removeChild(childElement) {
if (element) {
element.removeChild(childElement);
}
}
function waitForReadyState(targetReadyState, callback) {
if (targetReadyState === _constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_NOTHING || getReadyState() >= targetReadyState) {
callback();
} else {
// wait for the appropriate callback before checking again
var event = READY_STATES_TO_EVENT_NAMES.get(targetReadyState);
_listenOnce(event, callback);
}
}
function _listenOnce(event, callback) {
var func = function func() {
// Stop listening to this event.
removeEventListener(event, func); // Call the original listener.
callback(event);
};
addEventListener(event, func);
}
instance = {
initialize: initialize,
setCurrentTime: setCurrentTime,
play: play,
isPaused: isPaused,
pause: pause,
isStalled: isStalled,
isSeeking: isSeeking,
getTime: getTime,
getPlaybackRate: getPlaybackRate,
setPlaybackRate: setPlaybackRate,
getPlayedRanges: getPlayedRanges,
getEnded: getEnded,
setStallState: setStallState,
getElement: getElement,
setElement: setElement,
setSource: setSource,
getSource: getSource,
getTTMLRenderingDiv: getTTMLRenderingDiv,
setTTMLRenderingDiv: setTTMLRenderingDiv,
getPlaybackQuality: getPlaybackQuality,
addEventListener: addEventListener,
removeEventListener: removeEventListener,
getReadyState: getReadyState,
getBufferRange: getBufferRange,
getClientWidth: getClientWidth,
getClientHeight: getClientHeight,
getTextTracks: getTextTracks,
getTextTrack: getTextTrack,
addTextTrack: addTextTrack,
appendChild: appendChild,
removeChild: removeChild,
getVideoWidth: getVideoWidth,
getVideoHeight: getVideoHeight,
getVideoRelativeOffsetTop: getVideoRelativeOffsetTop,
getVideoRelativeOffsetLeft: getVideoRelativeOffsetLeft,
reset: reset
};
setup();
return instance;
}
VideoModel.__dashjs_factory_name = 'VideoModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(VideoModel));
/***/ }),
/***/ "./src/streaming/net/FetchLoader.js":
/*!******************************************!*\
!*** ./src/streaming/net/FetchLoader.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module FetchLoader
* @ignore
* @description Manages download of resources via HTTP using fetch.
* @param {Object} cfg - dependencies from parent
*/
function FetchLoader(cfg) {
cfg = cfg || {};
var context = this.context;
var requestModifier = cfg.requestModifier;
var lowLatencyThroughputModel = cfg.lowLatencyThroughputModel;
var boxParser = cfg.boxParser;
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
var instance, dashMetrics;
function setup(cfg) {
dashMetrics = cfg.dashMetrics;
}
function load(httpRequest) {
// Variables will be used in the callback functions
var requestStartTime = new Date();
var request = httpRequest.request;
var headers = new Headers();
/*jshint ignore:line*/
if (request.range) {
headers.append('Range', 'bytes=' + request.range);
}
if (httpRequest.headers) {
for (var header in httpRequest.headers) {
var value = httpRequest.headers[header];
if (value) {
headers.append(header, value);
}
}
}
if (!request.requestStartDate) {
request.requestStartDate = requestStartTime;
}
if (requestModifier) {
// modifyRequestHeader expects a XMLHttpRequest object so,
// to keep backward compatibility, we should expose a setRequestHeader method
// TODO: Remove RequestModifier dependency on XMLHttpRequest object and define
// a more generic way to intercept/modify requests
requestModifier.modifyRequestHeader({
setRequestHeader: function setRequestHeader(header, value) {
headers.append(header, value);
}
});
}
var abortController;
if (typeof window.AbortController === 'function') {
abortController = new AbortController();
/*jshint ignore:line*/
httpRequest.abortController = abortController;
abortController.signal.onabort = httpRequest.onabort;
}
var reqOptions = {
method: httpRequest.method,
headers: headers,
credentials: httpRequest.withCredentials ? 'include' : undefined,
signal: abortController ? abortController.signal : undefined
};
var calculationMode = settings.get().streaming.abr.fetchThroughputCalculationMode;
var requestTime = Date.now();
var throughputCapacityDelayMS = 0;
new Promise(function (resolve) {
if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_AAST && lowLatencyThroughputModel) {
throughputCapacityDelayMS = lowLatencyThroughputModel.getThroughputCapacityDelayMS(request, dashMetrics.getCurrentBufferLevel(request.mediaType) * 1000);
if (throughputCapacityDelayMS) {
// safely delay the "fetch" call a bit to be able to meassure the throughput capacity of the line.
// this will lead to first few chunks downloaded at max network speed
return setTimeout(resolve, throughputCapacityDelayMS);
}
}
resolve();
}).then(function () {
var markBeforeFetch = Date.now();
fetch(httpRequest.url, reqOptions).then(function (response) {
if (!httpRequest.response) {
httpRequest.response = {};
}
httpRequest.response.status = response.status;
httpRequest.response.statusText = response.statusText;
httpRequest.response.responseURL = response.url;
if (!response.ok) {
httpRequest.onerror();
}
var responseHeaders = '';
var _iterator = _createForOfIteratorHelper(response.headers.keys()),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var key = _step.value;
responseHeaders += key + ': ' + response.headers.get(key) + '\r\n';
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
httpRequest.response.responseHeaders = responseHeaders;
if (!response.body) {
// Fetch returning a ReadableStream response body is not currently supported by all browsers.
// Browser compatibility: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
// If it is not supported, returning the whole segment when it's ready (as xhr)
return response.arrayBuffer().then(function (buffer) {
httpRequest.response.response = buffer;
var event = {
loaded: buffer.byteLength,
total: buffer.byteLength,
stream: false
};
httpRequest.progress(event);
httpRequest.onload();
httpRequest.onend();
return;
});
}
var totalBytes = parseInt(response.headers.get('Content-Length'), 10);
var bytesReceived = 0;
var signaledFirstByte = false;
var remaining = new Uint8Array();
var offset = 0;
if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_AAST && lowLatencyThroughputModel) {
var fetchMeassurement = function fetchMeassurement(stream) {
var reader = stream.getReader();
var measurement = [];
reader.read().then(function processFetch(args) {
var value = args.value;
var done = args.done;
markB = Date.now();
if (value && value.length) {
var chunkDownloadDurationMS = markB - markA;
var chunkBytes = value.length;
measurement.push({
chunkDownloadTimeRelativeMS: markB - markBeforeFetch,
chunkDownloadDurationMS: chunkDownloadDurationMS,
chunkBytes: chunkBytes,
kbps: Math.round(8 * chunkBytes / (chunkDownloadDurationMS / 1000)),
bufferLevel: dashMetrics.getCurrentBufferLevel(request.mediaType)
});
}
if (done) {
var fetchDuration = markB - markBeforeFetch;
var bytesAllChunks = measurement.reduce(function (prev, curr) {
return prev + curr.chunkBytes;
}, 0);
lowLatencyThroughputModel.addMeasurement(request, fetchDuration, measurement, requestTime, throughputCapacityDelayMS, responseHeaders);
httpRequest.progress({
loaded: bytesAllChunks,
total: bytesAllChunks,
lengthComputable: true,
time: lowLatencyThroughputModel.getEstimatedDownloadDurationMS(request),
stream: true
});
return;
}
markA = Date.now();
return reader.read().then(processFetch);
});
}; // tee'ing streams is supported by all current major browsers
// https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee
var markA = markBeforeFetch;
var markB = 0;
var _response$body$tee = response.body.tee(),
_response$body$tee2 = _slicedToArray(_response$body$tee, 2),
forMeasure = _response$body$tee2[0],
forConsumer = _response$body$tee2[1];
fetchMeassurement(forMeasure);
httpRequest.reader = forConsumer.getReader();
} else {
httpRequest.reader = response.body.getReader();
}
var downloadedData = [];
var startTimeData = [];
var endTimeData = [];
var lastChunkWasFinished = true;
var processResult = function processResult(_ref) {
var value = _ref.value,
done = _ref.done;
// Bug fix Parse whenever data is coming [value] better than 1ms looking that increase CPU
if (done) {
if (remaining) {
if (calculationMode !== _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_AAST) {
// If there is pending data, call progress so network metrics
// are correctly generated
// Same structure as https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/
var calculatedThroughput = null;
if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING) {
calculatedThroughput = calculateThroughputByChunkData(startTimeData, endTimeData);
}
httpRequest.progress({
loaded: bytesReceived,
total: isNaN(totalBytes) ? bytesReceived : totalBytes,
lengthComputable: true,
time: calculateDownloadedTime(downloadedData, bytesReceived),
throughput: calculatedThroughput,
stream: true
});
}
httpRequest.response.response = remaining.buffer;
}
httpRequest.onload();
httpRequest.onend();
return;
}
if (value && value.length > 0) {
remaining = concatTypedArray(remaining, value);
bytesReceived += value.length;
downloadedData.push({
ts: Date.now(),
bytes: value.length
});
if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING && lastChunkWasFinished) {
// Parse the payload and capture the the 'moof' box
var _boxesInfo = boxParser.findLastTopIsoBoxCompleted(['moof'], remaining, offset);
if (_boxesInfo.found) {
// Store the beginning time of each chunk download in array StartTimeData
lastChunkWasFinished = false;
startTimeData.push({
ts: performance.now(),
/* jshint ignore:line */
bytes: value.length
});
}
}
var boxesInfo = boxParser.findLastTopIsoBoxCompleted(['moov', 'mdat'], remaining, offset);
if (boxesInfo.found) {
var end = boxesInfo.lastCompletedOffset + boxesInfo.size; // Store the end time of each chunk download with its size in array EndTimeData
if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING && !lastChunkWasFinished) {
lastChunkWasFinished = true;
endTimeData.push({
ts: performance.now(),
/* jshint ignore:line */
bytes: remaining.length
});
} // If we are going to pass full buffer, avoid copying it and pass
// complete buffer. Otherwise clone the part of the buffer that is completed
// and adjust remaining buffer. A clone is needed because ArrayBuffer of a typed-array
// keeps a reference to the original data
var data;
if (end === remaining.length) {
data = remaining;
remaining = new Uint8Array();
} else {
data = new Uint8Array(remaining.subarray(0, end));
remaining = remaining.subarray(end);
} // Announce progress but don't track traces. Throughput measures are quite unstable
// when they are based in small amount of data
httpRequest.progress({
data: data.buffer,
lengthComputable: false,
noTrace: true
});
offset = 0;
} else {
offset = boxesInfo.lastCompletedOffset; // Call progress so it generates traces that will be later used to know when the first byte
// were received
if (!signaledFirstByte) {
httpRequest.progress({
lengthComputable: false,
noTrace: true
});
signaledFirstByte = true;
}
}
}
read(httpRequest, processResult);
};
read(httpRequest, processResult);
})["catch"](function (e) {
if (httpRequest.onerror) {
httpRequest.onerror(e);
}
});
});
}
function read(httpRequest, processResult) {
httpRequest.reader.read().then(processResult)["catch"](function (e) {
if (httpRequest.onerror && httpRequest.response.status === 200) {
// Error, but response code is 200, trigger error
httpRequest.onerror(e);
}
});
}
function concatTypedArray(remaining, data) {
if (remaining.length === 0) {
return data;
}
var result = new Uint8Array(remaining.length + data.length);
result.set(remaining);
result.set(data, remaining.length);
return result;
}
function abort(request) {
if (request.abortController) {
// For firefox and edge
request.abortController.abort();
} else if (request.reader) {
// For Chrome
try {
request.reader.cancel();
request.onabort();
} catch (e) {// throw exceptions (TypeError) when reader was previously closed,
// for example, because a network issue
}
}
}
function calculateDownloadedTime(downloadedData, bytesReceived) {
try {
downloadedData = downloadedData.filter(function (data) {
return data.bytes > bytesReceived / 4 / downloadedData.length;
});
if (downloadedData.length > 1) {
var time = 0;
var avgTimeDistance = (downloadedData[downloadedData.length - 1].ts - downloadedData[0].ts) / downloadedData.length;
downloadedData.forEach(function (data, index) {
// To be counted the data has to be over a threshold
var next = downloadedData[index + 1];
if (next) {
var distance = next.ts - data.ts;
time += distance < avgTimeDistance ? distance : 0;
}
});
return time;
}
return null;
} catch (e) {
return null;
}
}
function calculateThroughputByChunkData(startTimeData, endTimeData) {
try {
var datum, datumE; // Filter the last chunks in a segment in both arrays [StartTimeData and EndTimeData]
datum = startTimeData.filter(function (data, i) {
return i < startTimeData.length - 1;
});
datumE = endTimeData.filter(function (dataE, i) {
return i < endTimeData.length - 1;
});
var chunkThroughputs = []; // Compute the average throughput of the filtered chunk data
if (datum.length > 1) {
var shortDurationBytesReceived = 0;
var shortDurationStartTime = 0;
for (var i = 0; i < datum.length; i++) {
if (datum[i] && datumE[i]) {
var chunkDownloadTime = datumE[i].ts - datum[i].ts;
if (chunkDownloadTime > 1) {
chunkThroughputs.push(8 * datumE[i].bytes / chunkDownloadTime);
} else {
if (shortDurationStartTime === 0) {
shortDurationStartTime = datum[i].ts;
}
var cumulatedChunkDownloadTime = datumE[i].ts - shortDurationStartTime;
if (cumulatedChunkDownloadTime > 1) {
chunkThroughputs.push(8 * shortDurationBytesReceived / cumulatedChunkDownloadTime);
shortDurationBytesReceived = 0;
shortDurationStartTime = 0;
} else {
// continue cumulating short duration data
shortDurationBytesReceived += datumE[i].bytes;
}
}
}
}
if (chunkThroughputs.length > 0) {
var sumOfChunkThroughputs = chunkThroughputs.reduce(function (a, b) {
return a + b;
}, 0);
return sumOfChunkThroughputs / chunkThroughputs.length;
}
}
return null;
} catch (e) {
return null;
}
}
instance = {
load: load,
abort: abort,
calculateDownloadedTime: calculateDownloadedTime,
setup: setup
};
return instance;
}
FetchLoader.__dashjs_factory_name = 'FetchLoader';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(FetchLoader);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/net/HTTPLoader.js":
/*!*****************************************!*\
!*** ./src/streaming/net/HTTPLoader.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _XHRLoader__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./XHRLoader */ "./src/streaming/net/XHRLoader.js");
/* harmony import */ var _FetchLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./FetchLoader */ "./src/streaming/net/FetchLoader.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _models_CmcdModel__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../models/CmcdModel */ "./src/streaming/models/CmcdModel.js");
/* harmony import */ var _core_Utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/Utils */ "./src/core/Utils.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _models_LowLatencyThroughputModel__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../models/LowLatencyThroughputModel */ "./src/streaming/models/LowLatencyThroughputModel.js");
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module HTTPLoader
* @ignore
* @description Manages download of resources via HTTP.
* @param {Object} cfg - dependancies from parent
*/
function HTTPLoader(cfg) {
cfg = cfg || {};
var context = this.context;
var errHandler = cfg.errHandler;
var dashMetrics = cfg.dashMetrics;
var mediaPlayerModel = cfg.mediaPlayerModel;
var requestModifier = cfg.requestModifier;
var boxParser = cfg.boxParser;
var errors = cfg.errors;
var requestTimeout = cfg.requestTimeout || 0;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
var settings = Object(_core_Settings__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
var instance, requests, delayedRequests, retryRequests, downloadErrorToRequestTypeMap, cmcdModel, lowLatencyThroughputModel, logger;
function setup() {
var _downloadErrorToReque;
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance().getLogger(instance);
requests = [];
delayedRequests = [];
retryRequests = [];
cmcdModel = Object(_models_CmcdModel__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
lowLatencyThroughputModel = Object(_models_LowLatencyThroughputModel__WEBPACK_IMPORTED_MODULE_12__["default"])(context).getInstance();
downloadErrorToRequestTypeMap = (_downloadErrorToReque = {}, _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MPD_TYPE, errors.DOWNLOAD_ERROR_ID_MANIFEST_CODE), _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].XLINK_EXPANSION_TYPE, errors.DOWNLOAD_ERROR_ID_XLINK_CODE), _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].INIT_SEGMENT_TYPE, errors.DOWNLOAD_ERROR_ID_INITIALIZATION_CODE), _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MEDIA_SEGMENT_TYPE, errors.DOWNLOAD_ERROR_ID_CONTENT_CODE), _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].INDEX_SEGMENT_TYPE, errors.DOWNLOAD_ERROR_ID_CONTENT_CODE), _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].BITSTREAM_SWITCHING_SEGMENT_TYPE, errors.DOWNLOAD_ERROR_ID_CONTENT_CODE), _defineProperty(_downloadErrorToReque, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].OTHER_TYPE, errors.DOWNLOAD_ERROR_ID_CONTENT_CODE), _downloadErrorToReque);
}
function internalLoad(config, remainingAttempts) {
var request = config.request;
var traces = [];
var firstProgress = true;
var needFailureReport = true;
var requestStartTime = new Date();
var lastTraceTime = requestStartTime;
var lastTraceReceivedCount = 0;
var httpRequest;
if (!requestModifier || !dashMetrics || !errHandler) {
throw new Error('config object is not correct or missing');
}
var handleLoaded = function handleLoaded(success) {
needFailureReport = false;
request.requestStartDate = requestStartTime;
request.requestEndDate = new Date();
request.firstByteDate = request.firstByteDate || requestStartTime;
if (!request.checkExistenceOnly) {
var responseUrl = httpRequest.response ? httpRequest.response.responseURL : null;
var responseStatus = httpRequest.response ? httpRequest.response.status : null;
var responseHeaders = httpRequest.response && httpRequest.response.getAllResponseHeaders ? httpRequest.response.getAllResponseHeaders() : httpRequest.response ? httpRequest.response.responseHeaders : [];
dashMetrics.addHttpRequest(request, responseUrl, responseStatus, responseHeaders, success ? traces : null);
if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MPD_TYPE) {
dashMetrics.addManifestUpdate(request);
}
}
};
var onloadend = function onloadend() {
if (requests.indexOf(httpRequest) === -1) {
return;
} else {
requests.splice(requests.indexOf(httpRequest), 1);
}
if (needFailureReport) {
handleLoaded(false);
if (remainingAttempts > 0) {
// If we get a 404 to a media segment we should check the client clock again and perform a UTC sync in the background.
try {
if (settings.get().streaming.utcSynchronization.enableBackgroundSyncAfterSegmentDownloadError && request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MEDIA_SEGMENT_TYPE) {
// Only trigger a sync if the loading failed for the first time
var initialNumberOfAttempts = mediaPlayerModel.getRetryAttemptsForType(_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MEDIA_SEGMENT_TYPE);
if (initialNumberOfAttempts === remainingAttempts) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].ATTEMPT_BACKGROUND_SYNC);
}
}
} catch (e) {}
remainingAttempts--;
var retryRequest = {
config: config
};
retryRequests.push(retryRequest);
retryRequest.timeout = setTimeout(function () {
if (retryRequests.indexOf(retryRequest) === -1) {
return;
} else {
retryRequests.splice(retryRequests.indexOf(retryRequest), 1);
}
internalLoad(config, remainingAttempts);
}, mediaPlayerModel.getRetryIntervalsForType(request.type));
} else {
if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MSS_FRAGMENT_INFO_SEGMENT_TYPE) {
return;
}
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](downloadErrorToRequestTypeMap[request.type], request.url + ' is not available', {
request: request,
response: httpRequest.response
}));
if (config.error) {
config.error(request, 'error', httpRequest.response.statusText);
}
if (config.complete) {
config.complete(request, httpRequest.response.statusText);
}
}
}
};
var progress = function progress(event) {
var currentTime = new Date();
if (firstProgress) {
firstProgress = false;
if (!event.lengthComputable || event.lengthComputable && event.total !== event.loaded) {
request.firstByteDate = currentTime;
}
}
if (event.lengthComputable) {
request.bytesLoaded = event.loaded;
request.bytesTotal = event.total;
}
if (!event.noTrace) {
traces.push({
s: lastTraceTime,
d: event.time ? event.time : currentTime.getTime() - lastTraceTime.getTime(),
b: [event.loaded ? event.loaded - lastTraceReceivedCount : 0],
t: event.throughput
});
lastTraceTime = currentTime;
lastTraceReceivedCount = event.loaded;
}
if (config.progress && event) {
config.progress(event);
}
};
var onload = function onload() {
if (httpRequest.response.status >= 200 && httpRequest.response.status <= 299) {
handleLoaded(true);
if (config.success) {
config.success(httpRequest.response.response, httpRequest.response.statusText, httpRequest.response.responseURL);
}
if (config.complete) {
config.complete(request, httpRequest.response.statusText);
}
}
};
var onabort = function onabort() {
if (config.abort) {
config.abort(request);
}
};
var ontimeout = function ontimeout(event) {
var timeoutMessage;
if (event.lengthComputable) {
var percentageComplete = event.loaded / event.total * 100;
timeoutMessage = 'Request timeout: loaded: ' + event.loaded + ', out of: ' + event.total + ' : ' + percentageComplete.toFixed(3) + '% Completed';
} else {
timeoutMessage = 'Request timeout: non-computable download size';
}
logger.warn(timeoutMessage);
};
var loader;
if (settings.get().streaming.lowLatencyEnabled && window.fetch && request.responseType === 'arraybuffer' && request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MEDIA_SEGMENT_TYPE) {
loader = Object(_FetchLoader__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
requestModifier: requestModifier,
lowLatencyThroughputModel: lowLatencyThroughputModel,
boxParser: boxParser
});
loader.setup({
dashMetrics: dashMetrics
});
} else {
loader = Object(_XHRLoader__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
requestModifier: requestModifier
});
}
var headers = null;
var modifiedUrl = requestModifier.modifyRequestURL(request.url);
if (settings.get().streaming.cmcd && settings.get().streaming.cmcd.enabled) {
var cmcdMode = settings.get().streaming.cmcd.mode;
if (cmcdMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_11__["default"].CMCD_MODE_QUERY) {
var additionalQueryParameter = _getAdditionalQueryParameter(request);
modifiedUrl = _core_Utils__WEBPACK_IMPORTED_MODULE_6__["default"].addAditionalQueryParameterToUrl(modifiedUrl, additionalQueryParameter);
} else if (cmcdMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_11__["default"].CMCD_MODE_HEADER) {
headers = cmcdModel.getHeaderParameters(request);
}
}
request.url = modifiedUrl;
var verb = request.checkExistenceOnly ? _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].HEAD : _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].GET;
var withCredentials = mediaPlayerModel.getXHRWithCredentialsForType(request.type);
httpRequest = {
url: modifiedUrl,
method: verb,
withCredentials: withCredentials,
request: request,
onload: onload,
onend: onloadend,
onerror: onloadend,
progress: progress,
onabort: onabort,
ontimeout: ontimeout,
loader: loader,
timeout: requestTimeout,
headers: headers
}; // Adds the ability to delay single fragment loading time to control buffer.
var now = new Date().getTime();
if (isNaN(request.delayLoadingTime) || now >= request.delayLoadingTime) {
// no delay - just send
requests.push(httpRequest);
loader.load(httpRequest);
} else {
// delay
var delayedRequest = {
httpRequest: httpRequest
};
delayedRequests.push(delayedRequest);
delayedRequest.delayTimeout = setTimeout(function () {
if (delayedRequests.indexOf(delayedRequest) === -1) {
return;
} else {
delayedRequests.splice(delayedRequests.indexOf(delayedRequest), 1);
}
try {
requestStartTime = new Date();
lastTraceTime = requestStartTime;
requests.push(delayedRequest.httpRequest);
loader.load(delayedRequest.httpRequest);
} catch (e) {
delayedRequest.httpRequest.onerror();
}
}, request.delayLoadingTime - now);
}
}
function _getAdditionalQueryParameter(request) {
try {
var additionalQueryParameter = [];
var cmcdQueryParameter = cmcdModel.getQueryParameter(request);
if (cmcdQueryParameter) {
additionalQueryParameter.push(cmcdQueryParameter);
}
return additionalQueryParameter;
} catch (e) {
return [];
}
}
/**
* Initiates a download of the resource described by config.request
* @param {Object} config - contains request (FragmentRequest or derived type), and callbacks
* @memberof module:HTTPLoader
* @instance
*/
function load(config) {
if (config.request) {
internalLoad(config, mediaPlayerModel.getRetryAttemptsForType(config.request.type));
} else {
if (config.error) {
config.error(config.request, 'error');
}
}
}
/**
* Aborts any inflight downloads
* @memberof module:HTTPLoader
* @instance
*/
function abort() {
retryRequests.forEach(function (t) {
clearTimeout(t.timeout); // abort request in order to trigger LOADING_ABANDONED event
if (t.config.request && t.config.abort) {
t.config.abort(t.config.request);
}
});
retryRequests = [];
delayedRequests.forEach(function (x) {
return clearTimeout(x.delayTimeout);
});
delayedRequests = [];
requests.forEach(function (x) {
// MSS patch: ignore FragmentInfo requests
if (x.request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__["HTTPRequest"].MSS_FRAGMENT_INFO_SEGMENT_TYPE) {
return;
} // abort will trigger onloadend which we don't want
// when deliberately aborting inflight requests -
// set them to undefined so they are not called
x.onloadend = x.onerror = x.onprogress = undefined;
x.loader.abort(x);
});
requests = [];
}
instance = {
load: load,
abort: abort
};
setup();
return instance;
}
HTTPLoader.__dashjs_factory_name = 'HTTPLoader';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_3__["default"].getClassFactory(HTTPLoader);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/net/SchemeLoaderFactory.js":
/*!**************************************************!*\
!*** ./src/streaming/net/SchemeLoaderFactory.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_net_HTTPLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../streaming/net/HTTPLoader */ "./src/streaming/net/HTTPLoader.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module
* @description Choose right url loader for scheme
* @ignore
*/
function SchemeLoaderFactory() {
var instance;
var schemeLoaderMap;
function registerLoader(scheme, loader) {
schemeLoaderMap[scheme] = loader;
}
function unregisterLoader(scheme) {
if (schemeLoaderMap[scheme]) {
delete schemeLoaderMap[scheme];
}
}
function unregisterAllLoader() {
schemeLoaderMap = {};
}
function getLoader(url) {
// iterates through schemeLoaderMap to find a loader for the scheme
for (var scheme in schemeLoaderMap) {
if (schemeLoaderMap.hasOwnProperty(scheme) && url.startsWith(scheme)) {
return schemeLoaderMap[scheme];
}
}
return _streaming_net_HTTPLoader__WEBPACK_IMPORTED_MODULE_1__["default"];
}
function reset() {
unregisterAllLoader();
}
function setup() {
reset();
}
setup();
instance = {
getLoader: getLoader,
registerLoader: registerLoader,
unregisterLoader: unregisterLoader,
unregisterAllLoader: unregisterAllLoader,
reset: reset
};
return instance;
}
SchemeLoaderFactory.__dashjs_factory_name = 'SchemeLoaderFactory';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(SchemeLoaderFactory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/net/URLLoader.js":
/*!****************************************!*\
!*** ./src/streaming/net/URLLoader.js ***!
\****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _streaming_net_SchemeLoaderFactory__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../streaming/net/SchemeLoaderFactory */ "./src/streaming/net/SchemeLoaderFactory.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class URLLoader
* @description Call Offline Loader or Online Loader dependaing on URL
* @param {Object} cfg - dependances
* @ignore
*/
function URLLoader(cfg) {
cfg = cfg || {};
var context = this.context;
var instance, schemeLoaderFactory, loader;
schemeLoaderFactory = Object(_streaming_net_SchemeLoaderFactory__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
function load(config) {
if (!loader) {
var loaderFactory = schemeLoaderFactory.getLoader(config && config.request ? config.request.url : null);
loader = loaderFactory(context).create({
errHandler: cfg.errHandler,
mediaPlayerModel: cfg.mediaPlayerModel,
requestModifier: cfg.requestModifier,
dashMetrics: cfg.dashMetrics,
boxParser: cfg.boxParser ? cfg.boxParser : null,
constants: cfg.constants ? cfg.constants : null,
dashConstants: cfg.dashConstants ? cfg.dashConstants : null,
urlUtils: cfg.urlUtils ? cfg.urlUtils : null,
requestTimeout: !isNaN(cfg.requestTimeout) ? cfg.requestTimeout : 0,
errors: cfg.errors
});
}
loader.load(config);
}
function abort() {
if (loader) {
loader.abort();
}
}
instance = {
load: load,
abort: abort
};
return instance;
}
URLLoader.__dashjs_factory_name = 'URLLoader';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(URLLoader);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/net/XHRLoader.js":
/*!****************************************!*\
!*** ./src/streaming/net/XHRLoader.js ***!
\****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module XHRLoader
* @ignore
* @description Manages download of resources via HTTP.
* @param {Object} cfg - dependencies from parent
*/
function XHRLoader(cfg) {
cfg = cfg || {};
var requestModifier = cfg.requestModifier;
var instance;
function load(httpRequest) {
// Variables will be used in the callback functions
var requestStartTime = new Date();
var request = httpRequest.request;
var xhr = new XMLHttpRequest();
xhr.open(httpRequest.method, httpRequest.url, true);
if (request.responseType) {
xhr.responseType = request.responseType;
}
if (request.range) {
xhr.setRequestHeader('Range', 'bytes=' + request.range);
}
if (!request.requestStartDate) {
request.requestStartDate = requestStartTime;
}
if (requestModifier) {
xhr = requestModifier.modifyRequestHeader(xhr);
}
if (httpRequest.headers) {
for (var header in httpRequest.headers) {
var value = httpRequest.headers[header];
if (value) {
xhr.setRequestHeader(header, value);
}
}
}
xhr.withCredentials = httpRequest.withCredentials;
xhr.onload = httpRequest.onload;
xhr.onloadend = httpRequest.onend;
xhr.onerror = httpRequest.onerror;
xhr.onprogress = httpRequest.progress;
xhr.onabort = httpRequest.onabort;
xhr.ontimeout = httpRequest.ontimeout;
xhr.timeout = httpRequest.timeout;
xhr.send();
httpRequest.response = xhr;
}
function abort(request) {
var x = request.response;
x.onloadend = x.onerror = x.onprogress = undefined; //Ignore events from aborted requests.
x.abort();
}
instance = {
load: load,
abort: abort
};
return instance;
}
XHRLoader.__dashjs_factory_name = 'XHRLoader';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(XHRLoader);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/protection/CommonEncryption.js":
/*!******************************************************!*\
!*** ./src/streaming/protection/CommonEncryption.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var LICENSE_SERVER_MANIFEST_CONFIGURATIONS = {
attributes: ['Laurl', 'laurl'],
prefixes: ['clearkey', 'dashif']
};
/**
* @class
* @ignore
*/
var CommonEncryption = /*#__PURE__*/function () {
function CommonEncryption() {
_classCallCheck(this, CommonEncryption);
}
_createClass(CommonEncryption, null, [{
key: "findCencContentProtection",
value:
/**
* Find and return the ContentProtection element in the given array
* that indicates support for MPEG Common Encryption
*
* @param {Array} cpArray array of content protection elements
* @returns {Object|null} the Common Encryption content protection element or
* null if one was not found
*/
function findCencContentProtection(cpArray) {
var retVal = null;
for (var i = 0; i < cpArray.length; ++i) {
var cp = cpArray[i];
if (cp.schemeIdUri.toLowerCase() === 'urn:mpeg:dash:mp4protection:2011' && (cp.value.toLowerCase() === 'cenc' || cp.value.toLowerCase() === 'cbcs')) retVal = cp;
}
return retVal;
}
/**
* Returns just the data portion of a single PSSH
*
* @param {ArrayBuffer} pssh - the PSSH
* @return {ArrayBuffer} data portion of the PSSH
*/
}, {
key: "getPSSHData",
value: function getPSSHData(pssh) {
var offset = 8; // Box size and type fields
var view = new DataView(pssh); // Read version
var version = view.getUint8(offset);
offset += 20; // Version (1), flags (3), system ID (16)
if (version > 0) {
offset += 4 + 16 * view.getUint32(offset); // Key ID count (4) and All key IDs (16*count)
}
offset += 4; // Data size
return pssh.slice(offset);
}
/**
* Returns the PSSH associated with the given key system from the concatenated
* list of PSSH boxes in the given initData
*
* @param {KeySystem} keySystem the desired
* key system
* @param {ArrayBuffer} initData 'cenc' initialization data. Concatenated list of PSSH.
* @returns {ArrayBuffer|null} The PSSH box data corresponding to the given key system, null if not found
* or null if a valid association could not be found.
*/
}, {
key: "getPSSHForKeySystem",
value: function getPSSHForKeySystem(keySystem, initData) {
var psshList = CommonEncryption.parsePSSHList(initData);
if (keySystem && psshList.hasOwnProperty(keySystem.uuid.toLowerCase())) {
return psshList[keySystem.uuid.toLowerCase()];
}
return null;
}
/**
* Parse a standard common encryption PSSH which contains a simple
* base64-encoding of the init data
*
* @param {Object} cpData the ContentProtection element
* @param {BASE64} BASE64 reference
* @returns {ArrayBuffer|null} the init data or null if not found
*/
}, {
key: "parseInitDataFromContentProtection",
value: function parseInitDataFromContentProtection(cpData, BASE64) {
if ('pssh' in cpData) {
// Remove whitespaces and newlines from pssh text
cpData.pssh.__text = cpData.pssh.__text.replace(/\r?\n|\r/g, '').replace(/\s+/g, '');
return BASE64.decodeArray(cpData.pssh.__text).buffer;
}
return null;
}
/**
* Parses list of PSSH boxes into keysystem-specific PSSH data
*
* @param {ArrayBuffer} data - the concatenated list of PSSH boxes as provided by
* CDM as initialization data when CommonEncryption content is detected
* @returns {Object|Array} an object that has a property named according to each of
* the detected key system UUIDs (e.g. 00000000-0000-0000-0000-0000000000)
* and a ArrayBuffer (the entire PSSH box) as the property value
*/
}, {
key: "parsePSSHList",
value: function parsePSSHList(data) {
if (data === null || data === undefined) return [];
var dv = new DataView(data.buffer || data); // data.buffer first for Uint8Array support
var done = false;
var pssh = {}; // TODO: Need to check every data read for end of buffer
var byteCursor = 0;
while (!done) {
var size = void 0,
nextBox = void 0,
version = void 0,
systemID = void 0;
var boxStart = byteCursor;
if (byteCursor >= dv.buffer.byteLength) break;
/* Box size */
size = dv.getUint32(byteCursor);
nextBox = byteCursor + size;
byteCursor += 4;
/* Verify PSSH */
if (dv.getUint32(byteCursor) !== 0x70737368) {
byteCursor = nextBox;
continue;
}
byteCursor += 4;
/* Version must be 0 or 1 */
version = dv.getUint8(byteCursor);
if (version !== 0 && version !== 1) {
byteCursor = nextBox;
continue;
}
byteCursor++;
byteCursor += 3;
/* skip flags */
// 16-byte UUID/SystemID
systemID = '';
var i = void 0,
val = void 0;
for (i = 0; i < 4; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 4;
systemID += '-';
for (i = 0; i < 2; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 2;
systemID += '-';
for (i = 0; i < 2; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 2;
systemID += '-';
for (i = 0; i < 2; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 2;
systemID += '-';
for (i = 0; i < 6; i++) {
val = dv.getUint8(byteCursor + i).toString(16);
systemID += val.length === 1 ? '0' + val : val;
}
byteCursor += 6;
systemID = systemID.toLowerCase();
/* PSSH Data Size */
byteCursor += 4;
/* PSSH Data */
pssh[systemID] = dv.buffer.slice(boxStart, nextBox);
byteCursor = nextBox;
}
return pssh;
}
}, {
key: "getLicenseServerUrlFromMediaInfo",
value: function getLicenseServerUrlFromMediaInfo(mediaInfo, schemeIdUri) {
try {
if (!mediaInfo || mediaInfo.length === 0) {
return null;
}
var i = 0;
var licenseServer = null;
while (i < mediaInfo.length && !licenseServer) {
var info = mediaInfo[i];
if (info && info.contentProtection && info.contentProtection.length > 0) {
var targetProtectionData = info.contentProtection.filter(function (cp) {
return cp.schemeIdUri && cp.schemeIdUri === schemeIdUri;
});
if (targetProtectionData && targetProtectionData.length > 0) {
var j = 0;
while (j < targetProtectionData.length && !licenseServer) {
var ckData = targetProtectionData[j];
var k = 0;
while (k < LICENSE_SERVER_MANIFEST_CONFIGURATIONS.attributes.length && !licenseServer) {
var l = 0;
var attribute = LICENSE_SERVER_MANIFEST_CONFIGURATIONS.attributes[k];
while (l < LICENSE_SERVER_MANIFEST_CONFIGURATIONS.prefixes.length && !licenseServer) {
var prefix = LICENSE_SERVER_MANIFEST_CONFIGURATIONS.prefixes[l];
if (ckData[attribute] && ckData[attribute].__prefix && ckData[attribute].__prefix === prefix && ckData[attribute].__text) {
licenseServer = ckData[attribute].__text;
}
l += 1;
}
k += 1;
}
j += 1;
}
}
}
i += 1;
}
return licenseServer;
} catch (e) {
return null;
}
}
}]);
return CommonEncryption;
}();
/* harmony default export */ __webpack_exports__["default"] = (CommonEncryption);
/***/ }),
/***/ "./src/streaming/protection/Protection.js":
/*!************************************************!*\
!*** ./src/streaming/protection/Protection.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _controllers_ProtectionController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./controllers/ProtectionController */ "./src/streaming/protection/controllers/ProtectionController.js");
/* harmony import */ var _controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./controllers/ProtectionKeyController */ "./src/streaming/protection/controllers/ProtectionKeyController.js");
/* harmony import */ var _ProtectionEvents__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ProtectionEvents */ "./src/streaming/protection/ProtectionEvents.js");
/* harmony import */ var _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./errors/ProtectionErrors */ "./src/streaming/protection/errors/ProtectionErrors.js");
/* harmony import */ var _models_ProtectionModel_21Jan2015__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./models/ProtectionModel_21Jan2015 */ "./src/streaming/protection/models/ProtectionModel_21Jan2015.js");
/* harmony import */ var _models_ProtectionModel_3Feb2014__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./models/ProtectionModel_3Feb2014 */ "./src/streaming/protection/models/ProtectionModel_3Feb2014.js");
/* harmony import */ var _models_ProtectionModel_01b__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./models/ProtectionModel_01b */ "./src/streaming/protection/models/ProtectionModel_01b.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var APIS_ProtectionModel_01b = [// Un-prefixed as per spec
{
// Video Element
generateKeyRequest: 'generateKeyRequest',
addKey: 'addKey',
cancelKeyRequest: 'cancelKeyRequest',
// Events
needkey: 'needkey',
keyerror: 'keyerror',
keyadded: 'keyadded',
keymessage: 'keymessage'
}, // Webkit-prefixed (early Chrome versions and Chrome with EME disabled in chrome://flags)
{
// Video Element
generateKeyRequest: 'webkitGenerateKeyRequest',
addKey: 'webkitAddKey',
cancelKeyRequest: 'webkitCancelKeyRequest',
// Events
needkey: 'webkitneedkey',
keyerror: 'webkitkeyerror',
keyadded: 'webkitkeyadded',
keymessage: 'webkitkeymessage'
}];
var APIS_ProtectionModel_3Feb2014 = [// Un-prefixed as per spec
// Chrome 38-39 (and some earlier versions) with chrome://flags -- Enable Encrypted Media Extensions
{
// Video Element
setMediaKeys: 'setMediaKeys',
// MediaKeys
MediaKeys: 'MediaKeys',
// MediaKeySession
release: 'close',
// Events
needkey: 'needkey',
error: 'keyerror',
message: 'keymessage',
ready: 'keyadded',
close: 'keyclose'
}, // MS-prefixed (IE11, Windows 8.1)
{
// Video Element
setMediaKeys: 'msSetMediaKeys',
// MediaKeys
MediaKeys: 'MSMediaKeys',
// MediaKeySession
release: 'close',
// Events
needkey: 'msneedkey',
error: 'mskeyerror',
message: 'mskeymessage',
ready: 'mskeyadded',
close: 'mskeyclose'
}];
function Protection() {
var instance;
var context = this.context;
/**
* Create a ProtectionController and associated ProtectionModel for use with
* a single piece of content.
*
* @param {Object} config
* @return {ProtectionController} protection controller
*
*/
function createProtectionSystem(config) {
var controller = null;
var protectionKeyController = Object(_controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
protectionKeyController.setConfig({
debug: config.debug,
BASE64: config.BASE64
});
protectionKeyController.initialize();
var protectionModel = _getProtectionModel(config);
if (!controller && protectionModel) {
//TODO add ability to set external controller if still needed at all?
controller = Object(_controllers_ProtectionController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
protectionModel: protectionModel,
protectionKeyController: protectionKeyController,
eventBus: config.eventBus,
debug: config.debug,
events: config.events,
BASE64: config.BASE64,
constants: config.constants,
cmcdModel: config.cmcdModel,
settings: config.settings
});
config.capabilities.setEncryptedMediaSupported(true);
}
return controller;
}
function _getProtectionModel(config) {
var debug = config.debug;
var logger = debug.getLogger(instance);
var eventBus = config.eventBus;
var errHandler = config.errHandler;
var videoElement = config.videoModel ? config.videoModel.getElement() : null;
if ((!videoElement || videoElement.onencrypted !== undefined) && (!videoElement || videoElement.mediaKeys !== undefined)) {
logger.info('EME detected on this user agent! (ProtectionModel_21Jan2015)');
return Object(_models_ProtectionModel_21Jan2015__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
debug: debug,
eventBus: eventBus,
events: config.events
});
} else if (_getAPI(videoElement, APIS_ProtectionModel_3Feb2014)) {
logger.info('EME detected on this user agent! (ProtectionModel_3Feb2014)');
return Object(_models_ProtectionModel_3Feb2014__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
debug: debug,
eventBus: eventBus,
events: config.events,
api: _getAPI(videoElement, APIS_ProtectionModel_3Feb2014)
});
} else if (_getAPI(videoElement, APIS_ProtectionModel_01b)) {
logger.info('EME detected on this user agent! (ProtectionModel_01b)');
return Object(_models_ProtectionModel_01b__WEBPACK_IMPORTED_MODULE_6__["default"])(context).create({
debug: debug,
eventBus: eventBus,
errHandler: errHandler,
events: config.events,
api: _getAPI(videoElement, APIS_ProtectionModel_01b)
});
} else {
logger.warn('No supported version of EME detected on this user agent! - Attempts to play encrypted content will fail!');
return null;
}
}
function _getAPI(videoElement, apis) {
for (var i = 0; i < apis.length; i++) {
var api = apis[i]; // detect if api is supported by browser
// check only first function in api -> should be fine
if (typeof videoElement[api[Object.keys(api)[0]]] !== 'function') {
continue;
}
return api;
}
return null;
}
instance = {
createProtectionSystem: createProtectionSystem
};
return instance;
}
Protection.__dashjs_factory_name = 'Protection';
var factory = dashjs.FactoryMaker.getClassFactory(Protection);
/* jshint ignore:line */
factory.events = _ProtectionEvents__WEBPACK_IMPORTED_MODULE_2__["default"];
factory.errors = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"];
dashjs.FactoryMaker.updateClassFactory(Protection.__dashjs_factory_name, factory);
/* jshint ignore:line */
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/protection/ProtectionEvents.js":
/*!******************************************************!*\
!*** ./src/streaming/protection/ProtectionEvents.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_events_EventsBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/events/EventsBase */ "./src/core/events/EventsBase.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
*/
var ProtectionEvents = /*#__PURE__*/function (_EventsBase) {
_inherits(ProtectionEvents, _EventsBase);
var _super = _createSuper(ProtectionEvents);
/**
* @description Public facing external events to be used when including protection package.
* All public events will be aggregated into the MediaPlayerEvents Class and can be accessed
* via MediaPlayer.events. public_ is the prefix that we use to move event names to MediaPlayerEvents.
*/
function ProtectionEvents() {
var _this;
_classCallCheck(this, ProtectionEvents);
_this = _super.call(this);
/**
* Event ID for events delivered when the protection set receives
* a key message from the CDM
*
* @ignore
*/
_this.INTERNAL_KEY_MESSAGE = 'internalKeyMessage';
/**
* Event ID for events delivered when the status of one decryption keys has changed
* @ignore
*/
_this.INTERNAL_KEY_STATUS_CHANGED = 'internalkeyStatusChanged';
/**
* Event ID for events delivered when a new key has been added
*
* @constant
* @deprecated The latest versions of the EME specification no longer
* use this event. {@MediaPlayer.models.protectionModel.eventList.KEY_STATUSES_CHANGED}
* is preferred.
* @event ProtectionEvents#KEY_ADDED
*/
_this.KEY_ADDED = 'public_keyAdded';
/**
* Event ID for events delivered when an error is encountered by the CDM
* while processing a license server response message
* @event ProtectionEvents#KEY_ERROR
*/
_this.KEY_ERROR = 'public_keyError';
/**
* Event ID for events delivered when the protection set receives
* a key message from the CDM
* @event ProtectionEvents#KEY_MESSAGE
*/
_this.KEY_MESSAGE = 'public_keyMessage';
/**
* Event ID for events delivered when a key session close
* process has completed
* @event ProtectionEvents#KEY_SESSION_CLOSED
*/
_this.KEY_SESSION_CLOSED = 'public_keySessionClosed';
/**
* Event ID for events delivered when a new key sessions creation
* process has completed
* @event ProtectionEvents#KEY_SESSION_CREATED
*/
_this.KEY_SESSION_CREATED = 'public_keySessionCreated';
/**
* Event ID for events delivered when a key session removal
* process has completed
* @event ProtectionEvents#KEY_SESSION_REMOVED
*/
_this.KEY_SESSION_REMOVED = 'public_keySessionRemoved';
/**
* Event ID for events delivered when the status of one or more
* decryption keys has changed
* @event ProtectionEvents#KEY_STATUSES_CHANGED
*/
_this.KEY_STATUSES_CHANGED = 'public_keyStatusesChanged';
/**
* Event ID for events delivered when a key system access procedure
* has completed
* @ignore
*/
_this.KEY_SYSTEM_ACCESS_COMPLETE = 'public_keySystemAccessComplete';
/**
* Event ID for events delivered when a key system selection procedure
* completes
* @event ProtectionEvents#KEY_SYSTEM_SELECTED
*/
_this.KEY_SYSTEM_SELECTED = 'public_keySystemSelected';
/**
* Event ID for events delivered when a license request procedure
* has completed
* @event ProtectionEvents#LICENSE_REQUEST_COMPLETE
*/
_this.LICENSE_REQUEST_COMPLETE = 'public_licenseRequestComplete';
/**
* Sending a license rquest
* @event ProtectionEvents#LICENSE_REQUEST_SENDING
*/
_this.LICENSE_REQUEST_SENDING = 'public_licenseRequestSending';
/**
* Event ID for needkey/encrypted events
* @ignore
*/
_this.NEED_KEY = 'needkey';
/**
* Event ID for events delivered when the Protection system is detected and created.
* @event ProtectionEvents#PROTECTION_CREATED
*/
_this.PROTECTION_CREATED = 'public_protectioncreated';
/**
* Event ID for events delivered when the Protection system is destroyed.
* @event ProtectionEvents#PROTECTION_DESTROYED
*/
_this.PROTECTION_DESTROYED = 'public_protectiondestroyed';
/**
* Event ID for events delivered when a new server certificate has
* been delivered to the CDM
* @ignore
*/
_this.SERVER_CERTIFICATE_UPDATED = 'serverCertificateUpdated';
/**
* Event ID for events delivered when the process of shutting down
* a protection set has completed
* @ignore
*/
_this.TEARDOWN_COMPLETE = 'protectionTeardownComplete';
/**
* Event ID for events delivered when a HTMLMediaElement has been
* associated with the protection set
* @ignore
*/
_this.VIDEO_ELEMENT_SELECTED = 'videoElementSelected';
/**
* Triggered when the key session has been updated successfully
* @ignore
*/
_this.KEY_SESSION_UPDATED = 'public_keySessionUpdated';
return _this;
}
return ProtectionEvents;
}(_core_events_EventsBase__WEBPACK_IMPORTED_MODULE_0__["default"]);
var protectionEvents = new ProtectionEvents();
/* harmony default export */ __webpack_exports__["default"] = (protectionEvents);
/***/ }),
/***/ "./src/streaming/protection/controllers/ProtectionController.js":
/*!**********************************************************************!*\
!*** ./src/streaming/protection/controllers/ProtectionController.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../CommonEncryption */ "./src/streaming/protection/CommonEncryption.js");
/* harmony import */ var _vo_MediaCapability__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/MediaCapability */ "./src/streaming/protection/vo/MediaCapability.js");
/* harmony import */ var _vo_KeySystemConfiguration__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/KeySystemConfiguration */ "./src/streaming/protection/vo/KeySystemConfiguration.js");
/* harmony import */ var _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../errors/ProtectionErrors */ "./src/streaming/protection/errors/ProtectionErrors.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _vo_LicenseRequest__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/LicenseRequest */ "./src/streaming/protection/vo/LicenseRequest.js");
/* harmony import */ var _vo_LicenseResponse__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../vo/LicenseResponse */ "./src/streaming/protection/vo/LicenseResponse.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_Utils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../../core/Utils */ "./src/core/Utils.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var NEEDKEY_BEFORE_INITIALIZE_RETRIES = 5;
var NEEDKEY_BEFORE_INITIALIZE_TIMEOUT = 500;
var LICENSE_SERVER_REQUEST_RETRIES = 3;
var LICENSE_SERVER_REQUEST_RETRY_INTERVAL = 1000;
var LICENSE_SERVER_REQUEST_DEFAULT_TIMEOUT = 8000;
/**
* @module ProtectionController
* @description Provides access to media protection information and functionality. Each
* ProtectionController manages a single {@link MediaPlayer.models.ProtectionModel}
* which encapsulates a set of protection information (EME APIs, selected key system,
* key sessions). The APIs of ProtectionController mostly align with the latest EME
* APIs. Key system selection is mostly automated when combined with app-overrideable
* functionality provided in {@link ProtectionKeyController}.
* @todo ProtectionController does almost all of its tasks automatically after init() is
* called. Applications might want more control over this process and want to go through
* each step manually (key system selection, session creation, session maintenance).
* This module can be accessed using the MediaPlayer API getProtectionController()
* @param {Object} config
*/
function ProtectionController(config) {
config = config || {};
var protectionKeyController = config.protectionKeyController;
var protectionModel = config.protectionModel;
var eventBus = config.eventBus;
var events = config.events;
var debug = config.debug;
var BASE64 = config.BASE64;
var constants = config.constants;
var needkeyRetries = [];
var cmcdModel = config.cmcdModel;
var settings = config.settings;
var instance, logger, pendingKeySystemData, mediaInfoArr, protDataSet, sessionType, robustnessLevel, selectedKeySystem, keySystemSelectionInProgress, licenseRequestFilters, licenseResponseFilters;
function setup() {
logger = debug.getLogger(instance);
pendingKeySystemData = [];
mediaInfoArr = [];
sessionType = 'temporary';
robustnessLevel = '';
licenseRequestFilters = [];
licenseResponseFilters = [];
eventBus.on(events.INTERNAL_KEY_MESSAGE, _onKeyMessage, instance);
eventBus.on(events.INTERNAL_KEY_STATUS_CHANGED, _onKeyStatusChanged, instance);
}
function checkConfig() {
if (!eventBus || !eventBus.hasOwnProperty('on') || !protectionKeyController || !protectionKeyController.hasOwnProperty('getSupportedKeySystemsFromContentProtection')) {
throw new Error('Missing config parameter(s)');
}
}
/**
* Initialize this protection system for a given media type.
*
* @param {StreamInfo} [mediaInfo] Media information
* @memberof module:ProtectionController
* @instance
*/
function initializeForMedia(mediaInfo) {
// Not checking here if a session for similar KS/KID combination is already created
// because still don't know which keysystem will be selected.
// Once Keysystem is selected and before creating the session, we will do that check
// so we create the strictly necessary DRM sessions
if (!mediaInfo) {
throw new Error('mediaInfo can not be null or undefined');
}
checkConfig();
mediaInfoArr.push(mediaInfo); // ContentProtection elements are specified at the AdaptationSet level, so the CP for audio
// and video will be the same. Just use one valid MediaInfo object
var supportedKS = protectionKeyController.getSupportedKeySystemsFromContentProtection(mediaInfo.contentProtection, protDataSet, sessionType); // Reorder key systems according to priority order provided in protectionData
supportedKS = supportedKS.sort(function (ksA, ksB) {
var indexA = protDataSet && protDataSet[ksA.ks.systemString] && protDataSet[ksA.ks.systemString].priority >= 0 ? protDataSet[ksA.ks.systemString].priority : supportedKS.length;
var indexB = protDataSet && protDataSet[ksB.ks.systemString] && protDataSet[ksB.ks.systemString].priority >= 0 ? protDataSet[ksB.ks.systemString].priority : supportedKS.length;
return indexA - indexB;
});
if (supportedKS && supportedKS.length > 0) {
_selectKeySystem(supportedKS, true);
}
}
/**
* Selects a key system if we dont have any one yet. Otherwise we use the existing key system and trigger a new license request if the initdata has changed
* @param {array} supportedKS
* @param {boolean} fromManifest
* @private
*/
function _selectKeySystem(supportedKS, fromManifest) {
// We are in the process of selecting a key system, so just save the data which might be coming from additional AdaptationSets.
if (keySystemSelectionInProgress) {
pendingKeySystemData.push(supportedKS);
} // First time, so we need to select a key system
else if (!selectedKeySystem) {
_selectInitialKeySystem(supportedKS, fromManifest);
} // We already selected a key system. We only need to trigger a new license exchange if the init data has changed
else if (selectedKeySystem) {
_initiateWithExistingKeySystem(supportedKS);
}
}
/**
* We do not have a key system yet. Select one
* @param {array} supportedKS
* @param {boolean} fromManifest
* @private
*/
function _selectInitialKeySystem(supportedKS, fromManifest) {
keySystemSelectionInProgress = true;
var requestedKeySystems = [];
pendingKeySystemData.push(supportedKS); // Add all key systems to our request list since we have yet to select a key system
for (var i = 0; i < supportedKS.length; i++) {
var keySystemConfiguration = _getKeySystemConfiguration(supportedKS[i]);
requestedKeySystems.push({
ks: supportedKS[i].ks,
configs: [keySystemConfiguration]
});
}
var keySystemAccess;
protectionModel.requestKeySystemAccess(requestedKeySystems).then(function (event) {
keySystemAccess = event.data;
logger.info('DRM: KeySystem Access Granted (' + keySystemAccess.keySystem.systemString + ')! Selecting key system...');
return protectionModel.selectKeySystem(keySystemAccess);
}).then(function (keySystem) {
selectedKeySystem = keySystem;
keySystemSelectionInProgress = false;
if (!protectionModel) {
return;
}
eventBus.trigger(events.KEY_SYSTEM_SELECTED, {
data: keySystemAccess
}); // Set server certificate from protData
var protData = _getProtDataForKeySystem(selectedKeySystem);
if (protData && protData.serverCertificate && protData.serverCertificate.length > 0) {
protectionModel.setServerCertificate(BASE64.decodeArray(protData.serverCertificate).buffer);
} // Create key sessions for the different AdaptationSets
var ksIdx;
for (var _i = 0; _i < pendingKeySystemData.length; _i++) {
for (ksIdx = 0; ksIdx < pendingKeySystemData[_i].length; ksIdx++) {
if (selectedKeySystem === pendingKeySystemData[_i][ksIdx].ks) {
var current = pendingKeySystemData[_i][ksIdx];
_loadOrCreateKeySession(current);
break;
}
}
}
})["catch"](function (event) {
selectedKeySystem = null;
keySystemSelectionInProgress = false;
if (!fromManifest) {
eventBus.trigger(events.KEY_SYSTEM_SELECTED, {
data: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].KEY_SYSTEM_ACCESS_DENIED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].KEY_SYSTEM_ACCESS_DENIED_ERROR_MESSAGE + 'Error selecting key system! -- ' + event.error)
});
}
});
}
/**
* If we have already selected a keysytem we only need to create a new key session and issue a new license request if the init data has changed.
* @param {array} supportedKS
* @private
*/
function _initiateWithExistingKeySystem(supportedKS) {
var ksIdx = supportedKS.findIndex(function (entry) {
return entry.ks === selectedKeySystem;
});
var current = supportedKS[ksIdx];
if (ksIdx === -1 || !current.initData) {
return;
}
_loadOrCreateKeySession(current);
}
/**
* Loads an existing key session if we already have a session id. Otherwise we create a new key session
* @param {object} keySystemInfo
* @private
*/
function _loadOrCreateKeySession(keySystemInfo) {
// Clearkey
if (protectionKeyController.isClearKey(selectedKeySystem)) {
// For Clearkey: if parameters for generating init data was provided by the user, use them for generating
// initData and overwrite possible initData indicated in encrypted event (EME)
if (keySystemInfo.protData && keySystemInfo.protData.hasOwnProperty('clearkeys')) {
var initData = {
kids: Object.keys(keySystemInfo.protData.clearkeys)
};
keySystemInfo.initData = new TextEncoder().encode(JSON.stringify(initData));
}
} // Reuse existing KeySession
if (keySystemInfo.sessionId) {
// Load MediaKeySession with sessionId
loadKeySession(keySystemInfo);
} // Create a new KeySession
else if (keySystemInfo.initData !== null) {
// Create new MediaKeySession with initData
createKeySession(keySystemInfo);
}
}
/**
* Loads a key session with the given session ID from persistent storage. This essentially creates a new key session
*
* @param {object} ksInfo
* @memberof module:ProtectionController
* @instance
* @fires ProtectionController#KeySessionCreated
* @ignore
*/
function loadKeySession(keySystemInfo) {
checkConfig();
protectionModel.loadKeySession(keySystemInfo);
}
/**
* Create a new key session associated with the given initialization data from the MPD or from the PSSH box in the media
* For the latest version of the EME a request is generated. Once this request is ready we get notified via the INTERNAL_KEY_MESSAGE event
* @param {ArrayBuffer} initData the initialization data
* @param {Uint8Array} cdmData the custom data to provide to licenser
* @memberof module:ProtectionController
* @instance
* @fires ProtectionController#KeySessionCreated
* @ignore
*/
function createKeySession(keySystemInfo) {
var initDataForKS = _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].getPSSHForKeySystem(selectedKeySystem, keySystemInfo ? keySystemInfo.initData : null);
if (initDataForKS) {
// Check for duplicate key id
if (_isKeyIdDuplicate(keySystemInfo.keyId)) {
return;
} // Check for duplicate initData
if (_isInitDataDuplicate(initDataForKS)) {
return;
}
try {
keySystemInfo.initData = initDataForKS;
protectionModel.createKeySession(keySystemInfo);
} catch (error) {
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].KEY_SESSION_CREATED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].KEY_SESSION_CREATED_ERROR_MESSAGE + error.message)
});
}
} else if (keySystemInfo && keySystemInfo.initData) {
protectionModel.createKeySession(keySystemInfo);
} else {
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].KEY_SESSION_CREATED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].KEY_SESSION_CREATED_ERROR_MESSAGE + 'Selected key system is ' + (selectedKeySystem ? selectedKeySystem.systemString : null) + '. needkey/encrypted event contains no initData corresponding to that key system!')
});
}
}
/**
* Returns the protectionData for a specific keysystem as specified by the application.
* @param {object} keySystem
* @return {object | null}
* @private
*/
function _getProtDataForKeySystem(keySystem) {
if (keySystem) {
var keySystemString = keySystem.systemString;
if (protDataSet) {
return keySystemString in protDataSet ? protDataSet[keySystemString] : null;
}
}
return null;
}
/**
* Removes all entries from the mediaInfoArr
*/
function clearMediaInfoArray() {
mediaInfoArr = [];
}
/**
* Returns a set of supported key systems and CENC initialization data
* from the given array of ContentProtection elements. Only
* key systems that are supported by this player will be returned.
* Key systems are returned in priority order (highest first).
*
* @param {Array.<Object>} cps - array of content protection elements parsed
* from the manifest
* @returns {Array.<Object>} array of objects indicating which supported key
* systems were found. Empty array is returned if no
* supported key systems were found
* @memberof module:ProtectionKeyController
* @instance
* @ignore
*/
function getSupportedKeySystemsFromContentProtection(cps) {
checkConfig();
return protectionKeyController.getSupportedKeySystemsFromContentProtection(cps, protDataSet, sessionType);
}
/**
* Checks if a session has already created for the provided key id
* @param {string} keyId
* @return {boolean}
* @private
*/
function _isKeyIdDuplicate(keyId) {
if (!keyId) {
return false;
}
try {
var sessions = protectionModel.getSessions();
for (var i = 0; i < sessions.length; i++) {
if (sessions[i].getKeyId() === keyId) {
return true;
}
}
return false;
} catch (e) {
return false;
}
}
/**
* Checks if the provided init data is equal to one of the existing init data values
* @param {any} initDataForKS
* @return {boolean}
* @private
*/
function _isInitDataDuplicate(initDataForKS) {
if (!initDataForKS) {
return false;
}
try {
var currentInitData = protectionModel.getAllInitData();
for (var i = 0; i < currentInitData.length; i++) {
if (protectionKeyController.initDataEquals(initDataForKS, currentInitData[i])) {
logger.debug('DRM: Ignoring initData because we have already seen it!');
return true;
}
}
return false;
} catch (e) {
return false;
}
}
/**
* Removes the given key session from persistent storage and closes the session
* as if {@link ProtectionController#closeKeySession}
* was called
*
* @param {SessionToken} sessionToken the session
* token
* @memberof module:ProtectionController
* @instance
* @fires ProtectionController#KeySessionRemoved
* @fires ProtectionController#KeySessionClosed
* @ignore
*/
function removeKeySession(sessionToken) {
checkConfig();
protectionModel.removeKeySession(sessionToken);
}
/**
* Closes the key session and releases all associated decryption keys. These
* keys will no longer be available for decrypting media
*
* @param {SessionToken} sessionToken the session
* token
* @memberof module:ProtectionController
* @instance
* @fires ProtectionController#KeySessionClosed
* @ignore
*/
function closeKeySession(sessionToken) {
checkConfig();
protectionModel.closeKeySession(sessionToken);
}
/**
* Sets a server certificate for use by the CDM when signing key messages
* intended for a particular license server. This will fire
* an error event if a key system has not yet been selected.
*
* @param {ArrayBuffer} serverCertificate a CDM-specific license server
* certificate
* @memberof module:ProtectionController
* @instance
* @fires ProtectionController#ServerCertificateUpdated
*/
function setServerCertificate(serverCertificate) {
checkConfig();
protectionModel.setServerCertificate(serverCertificate);
}
/**
* Associate this protection system with the given HTMLMediaElement. This
* causes the system to register for needkey/encrypted events from the given
* element and provides a destination for setting of MediaKeys
*
* @param {HTMLMediaElement} element the media element to which the protection
* system should be associated
* @memberof module:ProtectionController
* @instance
*/
function setMediaElement(element) {
checkConfig();
if (element) {
protectionModel.setMediaElement(element);
eventBus.on(events.NEED_KEY, _onNeedKey, instance);
} else if (element === null) {
protectionModel.setMediaElement(element);
eventBus.off(events.NEED_KEY, _onNeedKey, instance);
}
}
/**
* Sets the session type to use when creating key sessions. Either "temporary" or
* "persistent-license". Default is "temporary".
*
* @param {string} value the session type
* @memberof module:ProtectionController
* @instance
*/
function setSessionType(value) {
sessionType = value;
}
/**
* Sets the robustness level for video and audio capabilities. Optional to remove Chrome warnings.
* Possible values are SW_SECURE_CRYPTO, SW_SECURE_DECODE, HW_SECURE_CRYPTO, HW_SECURE_CRYPTO, HW_SECURE_DECODE, HW_SECURE_ALL.
*
* @param {string} level the robustness level
* @memberof module:ProtectionController
* @instance
*/
function setRobustnessLevel(level) {
robustnessLevel = level;
}
/**
* Attach KeySystem-specific data to use for license acquisition with EME
*
* @param {Object} data an object containing property names corresponding to
* key system name strings (e.g. "org.w3.clearkey") and associated values
* being instances of {@link ProtectionData}
* @memberof module:ProtectionController
* @instance
* @ignore
*/
function setProtectionData(data) {
protDataSet = data;
protectionKeyController.setProtectionData(data);
}
/**
* Stop method is called when current playback is stopped/resetted.
*
* @memberof module:ProtectionController
* @instance
*/
function stop() {
if (protectionModel) {
protectionModel.stop();
}
}
/**
* Destroys all protection data associated with this protection set. This includes
* deleting all key sessions. In the case of persistent key sessions, the sessions
* will simply be unloaded and not deleted. Additionally, if this protection set is
* associated with a HTMLMediaElement, it will be detached from that element.
*
* @memberof module:ProtectionController
* @instance
* @ignore
*/
function reset() {
eventBus.off(events.INTERNAL_KEY_MESSAGE, _onKeyMessage, instance);
eventBus.off(events.INTERNAL_KEY_STATUS_CHANGED, _onKeyStatusChanged, instance);
checkConfig();
licenseRequestFilters = [];
licenseResponseFilters = [];
setMediaElement(null);
selectedKeySystem = null;
keySystemSelectionInProgress = false;
if (protectionModel) {
protectionModel.reset();
protectionModel = null;
}
needkeyRetries.forEach(function (retryTimeout) {
return clearTimeout(retryTimeout);
});
needkeyRetries = [];
mediaInfoArr = [];
pendingKeySystemData = [];
}
/**
* Returns an object corresponding to the EME MediaKeySystemConfiguration dictionary
* @param {object} keySystem
* @return {KeySystemConfiguration}
* @private
*/
function _getKeySystemConfiguration(keySystemData) {
var protData = keySystemData.protData;
var audioCapabilities = [];
var videoCapabilities = [];
var audioRobustness = protData && protData.audioRobustness && protData.audioRobustness.length > 0 ? protData.audioRobustness : robustnessLevel;
var videoRobustness = protData && protData.videoRobustness && protData.videoRobustness.length > 0 ? protData.videoRobustness : robustnessLevel;
var ksSessionType = keySystemData.sessionType;
var distinctiveIdentifier = protData && protData.distinctiveIdentifier ? protData.distinctiveIdentifier : 'optional';
var persistentState = protData && protData.persistentState ? protData.persistentState : ksSessionType === 'temporary' ? 'optional' : 'required';
mediaInfoArr.forEach(function (media) {
if (media.type === constants.AUDIO) {
audioCapabilities.push(new _vo_MediaCapability__WEBPACK_IMPORTED_MODULE_1__["default"](media.codec, audioRobustness));
} else if (media.type === constants.VIDEO) {
videoCapabilities.push(new _vo_MediaCapability__WEBPACK_IMPORTED_MODULE_1__["default"](media.codec, videoRobustness));
}
});
return new _vo_KeySystemConfiguration__WEBPACK_IMPORTED_MODULE_2__["default"](audioCapabilities, videoCapabilities, distinctiveIdentifier, persistentState, [ksSessionType]);
}
/**
* Event handler for when the status of the key has changed
* @param {object} e
* @private
*/
function _onKeyStatusChanged(e) {
if (e.error) {
eventBus.trigger(events.KEY_STATUSES_CHANGED, {
data: null,
error: e.error
});
} else {
logger.debug('DRM: key status = ' + e.status);
}
}
/**
* Event handler for the key message event. Once we have a key message we can issue a license request
* @param {object} e
* @private
*/
function _onKeyMessage(e) {
logger.debug('DRM: onKeyMessage'); // Dispatch event to applications indicating we received a key message
var keyMessage = e.data;
eventBus.trigger(events.KEY_MESSAGE, {
data: keyMessage
});
var messageType = keyMessage.messageType ? keyMessage.messageType : 'license-request';
var message = keyMessage.message;
var sessionToken = keyMessage.sessionToken;
var protData = _getProtDataForKeySystem(selectedKeySystem);
var licenseServerModelInstance = protectionKeyController.getLicenseServerModelInstance(selectedKeySystem, protData, messageType);
var eventData = {
sessionToken: sessionToken,
messageType: messageType
}; // Ensure message from CDM is not empty
if (!message || message.byteLength === 0) {
_sendLicenseRequestCompleteEvent(eventData, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_NO_CHALLENGE_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_NO_CHALLENGE_ERROR_MESSAGE));
return;
} // Message not destined for license server
if (!licenseServerModelInstance) {
logger.debug('DRM: License server request not required for this message (type = ' + e.data.messageType + '). Session ID = ' + sessionToken.getSessionId());
_sendLicenseRequestCompleteEvent(eventData);
return;
} // Perform any special handling for ClearKey
if (protectionKeyController.isClearKey(selectedKeySystem)) {
var clearkeys = protectionKeyController.processClearKeyLicenseRequest(selectedKeySystem, protData, message);
if (clearkeys) {
logger.debug('DRM: ClearKey license request handled by application!');
_sendLicenseRequestCompleteEvent(eventData);
protectionModel.updateKeySession(sessionToken, clearkeys);
return;
}
} // In all other cases we have to make a license request
_issueLicenseRequest(keyMessage, licenseServerModelInstance, protData);
}
/**
* Notify other classes that the license request was completed
* @param {object} data
* @param {object} error
* @private
*/
function _sendLicenseRequestCompleteEvent(data, error) {
eventBus.trigger(events.LICENSE_REQUEST_COMPLETE, {
data: data,
error: error
});
}
/**
* Start issuing a license request
* @param {object} keyMessage
* @param {object} licenseServerData
* @param {object} protData
* @private
*/
function _issueLicenseRequest(keyMessage, licenseServerData, protData) {
var sessionToken = keyMessage.sessionToken;
var messageType = keyMessage.messageType ? keyMessage.messageType : 'license-request';
var eventData = {
sessionToken: sessionToken,
messageType: messageType
};
var keySystemString = selectedKeySystem ? selectedKeySystem.systemString : null; // Determine license server URL
var url = _getLicenseServerUrl(protData, messageType, sessionToken, keyMessage, licenseServerData); // Ensure valid license server URL
if (!url) {
_sendLicenseRequestCompleteEvent(eventData, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_NO_LICENSE_SERVER_URL_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_NO_LICENSE_SERVER_URL_ERROR_MESSAGE));
return;
} // Set optional XMLHttpRequest headers from protection data and message
var reqHeaders = {};
var withCredentials = false;
if (protData) {
_updateHeaders(reqHeaders, protData.httpRequestHeaders);
}
var message = keyMessage.message;
var headersFromMessage = selectedKeySystem.getRequestHeadersFromMessage(message);
_updateHeaders(reqHeaders, headersFromMessage);
Object.keys(reqHeaders).forEach(function (key) {
if ('authorization' === key.toLowerCase()) {
withCredentials = true;
}
}); // Overwrite withCredentials property from protData if present
if (protData && typeof protData.withCredentials == 'boolean') {
withCredentials = protData.withCredentials;
}
var onLoad = function onLoad(xhr) {
if (!protectionModel) {
return;
}
if (xhr.status >= 200 && xhr.status <= 299) {
var responseHeaders = _core_Utils__WEBPACK_IMPORTED_MODULE_8__["default"].parseHttpHeaders(xhr.getAllResponseHeaders ? xhr.getAllResponseHeaders() : null);
var licenseResponse = new _vo_LicenseResponse__WEBPACK_IMPORTED_MODULE_6__["default"](xhr.responseURL, responseHeaders, xhr.response);
_applyFilters(licenseResponseFilters, licenseResponse).then(function () {
var licenseMessage = licenseServerData.getLicenseMessage(licenseResponse.data, keySystemString, messageType);
if (licenseMessage !== null) {
_sendLicenseRequestCompleteEvent(eventData);
protectionModel.updateKeySession(sessionToken, licenseMessage);
} else {
_reportError(xhr, eventData, keySystemString, messageType, licenseServerData);
}
});
} else {
_reportError(xhr, eventData, keySystemString, messageType, licenseServerData);
}
};
var onAbort = function onAbort(xhr) {
_sendLicenseRequestCompleteEvent(eventData, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_LICENSER_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_LICENSER_ERROR_MESSAGE + keySystemString + ' update, XHR aborted. status is "' + xhr.statusText + '" (' + xhr.status + '), readyState is ' + xhr.readyState));
};
var onError = function onError(xhr) {
_sendLicenseRequestCompleteEvent(eventData, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_LICENSER_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_LICENSER_ERROR_MESSAGE + keySystemString + ' update, XHR error. status is "' + xhr.statusText + '" (' + xhr.status + '), readyState is ' + xhr.readyState));
};
var reqPayload = selectedKeySystem.getLicenseRequestFromMessage(message);
var reqMethod = licenseServerData.getHTTPMethod(messageType);
var responseType = licenseServerData.getResponseType(keySystemString, messageType);
var timeout = protData && !isNaN(protData.httpTimeout) ? protData.httpTimeout : LICENSE_SERVER_REQUEST_DEFAULT_TIMEOUT;
var sessionId = sessionToken.getSessionId() || null;
var licenseRequest = new _vo_LicenseRequest__WEBPACK_IMPORTED_MODULE_5__["default"](url, reqMethod, responseType, reqHeaders, withCredentials, messageType, sessionId, reqPayload);
var retryAttempts = !isNaN(settings.get().streaming.retryAttempts[_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].LICENSE]) ? settings.get().streaming.retryAttempts[_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].LICENSE] : LICENSE_SERVER_REQUEST_RETRIES;
_applyFilters(licenseRequestFilters, licenseRequest).then(function () {
_doLicenseRequest(licenseRequest, retryAttempts, timeout, onLoad, onAbort, onError);
});
}
/**
* Implement license requests with a retry mechanism to avoid temporary network issues to affect playback experience
* @param {object} request
* @param {number} retriesCount
* @param {number} timeout
* @param {function} onLoad
* @param {function} onAbort
* @param {function} onError
* @private
*/
function _doLicenseRequest(request, retriesCount, timeout, onLoad, onAbort, onError) {
var xhr = new XMLHttpRequest();
if (settings.get().streaming.cmcd && settings.get().streaming.cmcd.enabled) {
var cmcdMode = settings.get().streaming.cmcd.mode;
if (cmcdMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_9__["default"].CMCD_MODE_QUERY) {
var cmcdParams = cmcdModel.getQueryParameter({
url: request.url,
type: _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].LICENSE
});
if (cmcdParams) {
request.url = _core_Utils__WEBPACK_IMPORTED_MODULE_8__["default"].addAditionalQueryParameterToUrl(request.url, [cmcdParams]);
}
}
}
xhr.open(request.method, request.url, true);
xhr.responseType = request.responseType;
xhr.withCredentials = request.withCredentials;
if (timeout > 0) {
xhr.timeout = timeout;
}
for (var key in request.headers) {
xhr.setRequestHeader(key, request.headers[key]);
}
if (settings.get().streaming.cmcd && settings.get().streaming.cmcd.enabled) {
var _cmcdMode = settings.get().streaming.cmcd.mode;
if (_cmcdMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_9__["default"].CMCD_MODE_HEADER) {
var cmcdHeaders = cmcdModel.getHeaderParameters({
url: request.url,
type: _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].LICENSE
});
if (cmcdHeaders) {
for (var header in cmcdHeaders) {
var value = cmcdHeaders[header];
if (value) {
xhr.setRequestHeader(header, value);
}
}
}
}
}
var _retryRequest = function _retryRequest() {
// fail silently and retry
retriesCount--;
var retryInterval = !isNaN(settings.get().streaming.retryIntervals[_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].LICENSE]) ? settings.get().streaming.retryIntervals[_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__["HTTPRequest"].LICENSE] : LICENSE_SERVER_REQUEST_RETRY_INTERVAL;
setTimeout(function () {
_doLicenseRequest(request, retriesCount, timeout, onLoad, onAbort, onError);
}, retryInterval);
};
xhr.onload = function () {
if (this.status >= 200 && this.status <= 299 || retriesCount <= 0) {
onLoad(this);
} else {
logger.warn('License request failed (' + this.status + '). Retrying it... Pending retries: ' + retriesCount);
_retryRequest();
}
};
xhr.ontimeout = xhr.onerror = function () {
if (retriesCount <= 0) {
onError(this);
} else {
logger.warn('License request network request failed . Retrying it... Pending retries: ' + retriesCount);
_retryRequest();
}
};
xhr.onabort = function () {
onAbort(this);
}; // deprecated, to be removed
eventBus.trigger(events.LICENSE_REQUEST_SENDING, {
url: request.url,
headers: request.headers,
payload: request.data,
sessionId: request.sessionId
});
xhr.send(request.data);
}
/**
* Returns the url of the license server
* @param {object} protData
* @param {string} messageType
* @param {object} sessionToken
* @param {object} keyMessage
* @param {object} licenseServerData
* @return {*}
* @private
*/
function _getLicenseServerUrl(protData, messageType, sessionToken, keyMessage, licenseServerData) {
var url = null;
var message = keyMessage.message; // Check if the url is defined by the application
if (protData && protData.serverURL) {
var serverURL = protData.serverURL;
if (typeof serverURL === 'string' && serverURL !== '') {
url = serverURL;
} else if (_typeof(serverURL) === 'object' && serverURL.hasOwnProperty(messageType)) {
url = serverURL[messageType];
}
} // This is the old way of providing the url
else if (protData && protData.laURL && protData.laURL !== '') {
url = protData.laURL;
} // No url provided by the app. Check the manifest and the pssh
else {
// Check for url defined in the manifest
url = _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].getLicenseServerUrlFromMediaInfo(mediaInfoArr, selectedKeySystem.schemeIdURI); // In case we are not using Clearky we can still get a url from the pssh.
if (!url && !protectionKeyController.isClearKey(selectedKeySystem)) {
var psshData = _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].getPSSHData(sessionToken.initData);
url = selectedKeySystem.getLicenseServerURLFromInitData(psshData); // Still no url, check the keymessage
if (!url) {
url = keyMessage.laURL;
}
}
} // Possibly update or override the URL based on the message
url = licenseServerData.getServerURLFromMessage(url, message, messageType);
return url;
}
/**
* Add new headers to the existing ones
* @param {array} reqHeaders
* @param {object} headers
* @private
*/
function _updateHeaders(reqHeaders, headers) {
if (headers) {
for (var key in headers) {
reqHeaders[key] = headers[key];
}
}
}
/**
* Reports an error that might have occured during the license request
* @param {object} xhr
* @param {object} eventData
* @param {string} keySystemString
* @param {string} messageType
* @param {object} licenseServerData
* @private
*/
function _reportError(xhr, eventData, keySystemString, messageType, licenseServerData) {
var errorMsg = xhr.response ? licenseServerData.getErrorResponse(xhr.response, keySystemString, messageType) : 'NONE';
_sendLicenseRequestCompleteEvent(eventData, new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_4__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_LICENSER_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEY_MESSAGE_LICENSER_ERROR_MESSAGE + keySystemString + ' update, XHR complete. status is "' + xhr.statusText + '" (' + xhr.status + '), readyState is ' + xhr.readyState + '. Response is ' + errorMsg));
}
/**
* Applies custom filters defined by the application
* @param {array} filters
* @param {object} param
* @return {Promise<void>|*}
* @private
*/
function _applyFilters(filters, param) {
if (!filters) return Promise.resolve();
return filters.reduce(function (prev, next) {
return prev.then(function () {
return next(param);
});
}, Promise.resolve());
}
/**
* Event handler for "needkey" and "encrypted" events
* @param {object} event
* @param {number} retry
*/
function _onNeedKey(event, retry) {
if (!settings.get().streaming.protection.ignoreEmeEncryptedEvent) {
logger.debug('DRM: onNeedKey'); // Ignore non-cenc initData
if (event.key.initDataType !== 'cenc') {
logger.warn('DRM: Only \'cenc\' initData is supported! Ignoring initData of type: ' + event.key.initDataType);
return;
}
if (mediaInfoArr.length === 0) {
logger.warn('DRM: onNeedKey called before initializeForMedia, wait until initialized');
retry = typeof retry === 'undefined' ? 1 : retry + 1;
if (retry < NEEDKEY_BEFORE_INITIALIZE_RETRIES) {
needkeyRetries.push(setTimeout(function () {
_onNeedKey(event, retry);
}, NEEDKEY_BEFORE_INITIALIZE_TIMEOUT));
return;
}
} // Some browsers return initData as Uint8Array (IE), some as ArrayBuffer (Chrome).
// Convert to ArrayBuffer
var abInitData = event.key.initData;
if (ArrayBuffer.isView(abInitData)) {
abInitData = abInitData.buffer;
} // If key system has already been selected and initData already seen, then do nothing
if (selectedKeySystem) {
var initDataForKS = _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].getPSSHForKeySystem(selectedKeySystem, abInitData);
if (initDataForKS) {
// Check for duplicate initData
if (_isInitDataDuplicate(initDataForKS)) {
return;
}
}
}
logger.debug('DRM: initData:', String.fromCharCode.apply(null, new Uint8Array(abInitData)));
var supportedKS = protectionKeyController.getSupportedKeySystemsFromSegmentPssh(abInitData, protDataSet, sessionType);
if (supportedKS.length === 0) {
logger.debug('DRM: Received needkey event with initData, but we don\'t support any of the key systems!');
return;
}
_selectKeySystem(supportedKS, false);
}
}
/**
* Returns all available key systems
* @return {array}
*/
function getKeySystems() {
return protectionKeyController ? protectionKeyController.getKeySystems() : [];
}
/**
* Sets all available key systems
* @param {array} keySystems
*/
function setKeySystems(keySystems) {
if (protectionKeyController) {
protectionKeyController.setKeySystems(keySystems);
}
}
/**
* Sets the request filters to be applied before the license request is made
* @param {array} filters
*/
function setLicenseRequestFilters(filters) {
licenseRequestFilters = filters;
}
/**
* Sets the response filters to be applied after the license response has been received.
* @param {array} filters
*/
function setLicenseResponseFilters(filters) {
licenseResponseFilters = filters;
}
instance = {
initializeForMedia: initializeForMedia,
clearMediaInfoArray: clearMediaInfoArray,
createKeySession: createKeySession,
loadKeySession: loadKeySession,
removeKeySession: removeKeySession,
closeKeySession: closeKeySession,
setServerCertificate: setServerCertificate,
setMediaElement: setMediaElement,
setSessionType: setSessionType,
setRobustnessLevel: setRobustnessLevel,
setProtectionData: setProtectionData,
getSupportedKeySystemsFromContentProtection: getSupportedKeySystemsFromContentProtection,
getKeySystems: getKeySystems,
setKeySystems: setKeySystems,
setLicenseRequestFilters: setLicenseRequestFilters,
setLicenseResponseFilters: setLicenseResponseFilters,
stop: stop,
reset: reset
};
setup();
return instance;
}
ProtectionController.__dashjs_factory_name = 'ProtectionController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_10__["default"].getClassFactory(ProtectionController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/controllers/ProtectionKeyController.js":
/*!*************************************************************************!*\
!*** ./src/streaming/protection/controllers/ProtectionKeyController.js ***!
\*************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../CommonEncryption */ "./src/streaming/protection/CommonEncryption.js");
/* harmony import */ var _drm_KeySystemClearKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./../drm/KeySystemClearKey */ "./src/streaming/protection/drm/KeySystemClearKey.js");
/* harmony import */ var _drm_KeySystemW3CClearKey__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../drm/KeySystemW3CClearKey */ "./src/streaming/protection/drm/KeySystemW3CClearKey.js");
/* harmony import */ var _drm_KeySystemWidevine__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../drm/KeySystemWidevine */ "./src/streaming/protection/drm/KeySystemWidevine.js");
/* harmony import */ var _drm_KeySystemPlayReady__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./../drm/KeySystemPlayReady */ "./src/streaming/protection/drm/KeySystemPlayReady.js");
/* harmony import */ var _servers_DRMToday__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../servers/DRMToday */ "./src/streaming/protection/servers/DRMToday.js");
/* harmony import */ var _servers_PlayReady__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./../servers/PlayReady */ "./src/streaming/protection/servers/PlayReady.js");
/* harmony import */ var _servers_Widevine__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../servers/Widevine */ "./src/streaming/protection/servers/Widevine.js");
/* harmony import */ var _servers_ClearKey__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../servers/ClearKey */ "./src/streaming/protection/servers/ClearKey.js");
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module ProtectionKeyController
* @ignore
* @description Media protection key system functionality that can be modified/overridden by applications
*/
function ProtectionKeyController() {
var context = this.context;
var instance, debug, logger, keySystems, BASE64, clearkeyKeySystem, clearkeyW3CKeySystem;
function setConfig(config) {
if (!config) return;
if (config.debug) {
debug = config.debug;
logger = debug.getLogger(instance);
}
if (config.BASE64) {
BASE64 = config.BASE64;
}
}
function initialize() {
keySystems = [];
var keySystem; // PlayReady
keySystem = Object(_drm_KeySystemPlayReady__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance({
BASE64: BASE64
});
keySystems.push(keySystem); // Widevine
keySystem = Object(_drm_KeySystemWidevine__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance({
BASE64: BASE64
});
keySystems.push(keySystem); // ClearKey
keySystem = Object(_drm_KeySystemClearKey__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance({
BASE64: BASE64
});
keySystems.push(keySystem);
clearkeyKeySystem = keySystem; // W3C ClearKey
keySystem = Object(_drm_KeySystemW3CClearKey__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance({
BASE64: BASE64,
debug: debug
});
keySystems.push(keySystem);
clearkeyW3CKeySystem = keySystem;
}
/**
* Returns a prioritized list of key systems supported
* by this player (not necessarily those supported by the
* user agent)
*
* @returns {Array.<KeySystem>} a prioritized
* list of key systems
* @memberof module:ProtectionKeyController
* @instance
*/
function getKeySystems() {
return keySystems;
}
/**
* Sets the prioritized list of key systems to be supported
* by this player.
*
* @param {Array.<KeySystem>} newKeySystems the new prioritized
* list of key systems
* @memberof module:ProtectionKeyController
* @instance
*/
function setKeySystems(newKeySystems) {
keySystems = newKeySystems;
}
/**
* Returns the key system associated with the given key system string
* name (i.e. 'org.w3.clearkey')
*
* @param {string} systemString the system string
* @returns {KeySystem|null} the key system
* or null if no supported key system is associated with the given key
* system string
* @memberof module:ProtectionKeyController
* @instance
*/
function getKeySystemBySystemString(systemString) {
for (var i = 0; i < keySystems.length; i++) {
if (keySystems[i].systemString === systemString) {
return keySystems[i];
}
}
return null;
}
/**
* Determines whether the given key system is ClearKey. This is
* necessary because the EME spec defines ClearKey and its method
* for providing keys to the key session; and this method has changed
* between the various API versions. Our EME-specific ProtectionModels
* must know if the system is ClearKey so that it can format the keys
* according to the particular spec version.
*
* @param {Object} keySystem the key
* @returns {boolean} true if this is the ClearKey key system, false
* otherwise
* @memberof module:ProtectionKeyController
* @instance
*/
function isClearKey(keySystem) {
return keySystem === clearkeyKeySystem || keySystem === clearkeyW3CKeySystem;
}
/**
* Check equality of initData array buffers.
*
* @param {ArrayBuffer} initData1 - first initData
* @param {ArrayBuffer} initData2 - second initData
* @returns {boolean} true if the initData arrays are equal in size and
* contents, false otherwise
* @memberof module:ProtectionKeyController
* @instance
*/
function initDataEquals(initData1, initData2) {
if (initData1.byteLength === initData2.byteLength) {
var data1 = new Uint8Array(initData1);
var data2 = new Uint8Array(initData2);
for (var j = 0; j < data1.length; j++) {
if (data1[j] !== data2[j]) {
return false;
}
}
return true;
}
return false;
}
/**
* Returns a set of supported key systems and CENC initialization data
* from the given array of ContentProtection elements. Only
* key systems that are supported by this player will be returned.
* Key systems are returned in priority order (highest first).
*
* @param {Array.<Object>} cps - array of content protection elements parsed
* from the manifest
* @param {ProtectionData} protDataSet user specified protection data - license server url etc
* supported by the content
* @param {string} default session type
* @returns {Array.<Object>} array of objects indicating which supported key
* systems were found. Empty array is returned if no
* supported key systems were found
* @memberof module:ProtectionKeyController
* @instance
*/
function getSupportedKeySystemsFromContentProtection(cps, protDataSet, sessionType) {
var cp, ks, ksIdx, cpIdx;
var supportedKS = [];
if (cps) {
var cencContentProtection = _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].findCencContentProtection(cps);
for (ksIdx = 0; ksIdx < keySystems.length; ++ksIdx) {
ks = keySystems[ksIdx]; // Get protection data that applies for current key system
var protData = _getProtDataForKeySystem(ks.systemString, protDataSet);
for (cpIdx = 0; cpIdx < cps.length; ++cpIdx) {
cp = cps[cpIdx];
if (cp.schemeIdUri.toLowerCase() === ks.schemeIdURI) {
// Look for DRM-specific ContentProtection
var initData = ks.getInitData(cp, cencContentProtection);
supportedKS.push({
ks: keySystems[ksIdx],
keyId: cp.keyId,
initData: initData,
protData: protData,
cdmData: ks.getCDMData(protData ? protData.cdmData : null),
sessionId: _getSessionId(protData, cp),
sessionType: _getSessionType(protData, sessionType)
});
}
}
}
}
return supportedKS;
}
/**
* Returns key systems supported by this player for the given PSSH
* initializationData. Key systems are returned in priority order
* (highest priority first)
*
* @param {ArrayBuffer} initData Concatenated PSSH data for all DRMs
* supported by the content
* @param {ProtectionData} protDataSet user specified protection data - license server url etc
* supported by the content
* @param {string} default session type
* @returns {Array.<Object>} array of objects indicating which supported key
* systems were found. Empty array is returned if no
* supported key systems were found
* @memberof module:ProtectionKeyController
* @instance
*/
function getSupportedKeySystemsFromSegmentPssh(initData, protDataSet, sessionType) {
var supportedKS = [];
var pssh = _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].parsePSSHList(initData);
var ks, keySystemString;
for (var ksIdx = 0; ksIdx < keySystems.length; ++ksIdx) {
ks = keySystems[ksIdx];
keySystemString = ks.systemString; // Get protection data that applies for current key system
var protData = _getProtDataForKeySystem(keySystemString, protDataSet);
if (ks.uuid in pssh) {
supportedKS.push({
ks: ks,
initData: pssh[ks.uuid],
protData: protData,
cdmData: ks.getCDMData(protData ? protData.cdmData : null),
sessionId: _getSessionId(protData),
sessionType: _getSessionType(protData, sessionType)
});
}
}
return supportedKS;
}
/**
* Returns the license server implementation data that should be used for this request.
*
* @param {KeySystem} keySystem the key system
* associated with this license request
* @param {ProtectionData} protData protection data to use for the
* request
* @param {string} [messageType="license-request"] the message type associated with this
* request. Supported message types can be found
* {@link https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType|here}.
* @returns {LicenseServer|null} the license server
* implementation that should be used for this request or null if the player should not
* pass messages of the given type to a license server
* @memberof module:ProtectionKeyController
* @instance
*
*/
function getLicenseServerModelInstance(keySystem, protData, messageType) {
// Our default server implementations do not do anything with "license-release" or
// "individualization-request" messages, so we just send a success event
if (messageType === 'license-release' || messageType === 'individualization-request') {
return null;
}
var licenseServerData = null;
if (protData && protData.hasOwnProperty('drmtoday')) {
licenseServerData = Object(_servers_DRMToday__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance({
BASE64: BASE64
});
} else if (keySystem.systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_9__["default"].WIDEVINE_KEYSTEM_STRING) {
licenseServerData = Object(_servers_Widevine__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
} else if (keySystem.systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_9__["default"].PLAYREADY_KEYSTEM_STRING) {
licenseServerData = Object(_servers_PlayReady__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
} else if (keySystem.systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_9__["default"].CLEARKEY_KEYSTEM_STRING) {
licenseServerData = Object(_servers_ClearKey__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
}
return licenseServerData;
}
/**
* Allows application-specific retrieval of ClearKey keys.
*
* @param {KeySystem} clearkeyKeySystem They exact ClearKey System to be used
* @param {ProtectionData} protData protection data to use for the
* request
* @param {ArrayBuffer} message the key message from the CDM
* @return {ClearKeyKeySet|null} the clear keys associated with
* the request or null if no keys can be returned by this function
* @memberof module:ProtectionKeyController
* @instance
*/
function processClearKeyLicenseRequest(clearkeyKeySystem, protData, message) {
try {
return clearkeyKeySystem.getClearKeysFromProtectionData(protData, message);
} catch (error) {
logger.error('Failed to retrieve clearkeys from ProtectionData');
return null;
}
}
function setProtectionData(protectionDataSet) {
var getProtectionData = function getProtectionData(keySystemString) {
var protData = null;
if (protectionDataSet) {
protData = keySystemString in protectionDataSet ? protectionDataSet[keySystemString] : null;
}
return protData;
};
for (var i = 0; i < keySystems.length; i++) {
var keySystem = keySystems[i];
if (keySystem.hasOwnProperty('init')) {
keySystem.init(getProtectionData(keySystem.systemString));
}
}
}
function _getProtDataForKeySystem(systemString, protDataSet) {
if (!protDataSet) return null;
return systemString in protDataSet ? protDataSet[systemString] : null;
}
function _getSessionId(protData, cp) {
// Get sessionId from protectionData or from manifest (ContentProtection)
if (protData && protData.sessionId) {
return protData.sessionId;
} else if (cp && cp.sessionId) {
return cp.sessionId;
}
return null;
}
function _getSessionType(protData, sessionType) {
return protData && protData.sessionType ? protData.sessionType : sessionType;
}
instance = {
initialize: initialize,
setProtectionData: setProtectionData,
isClearKey: isClearKey,
initDataEquals: initDataEquals,
getKeySystems: getKeySystems,
setKeySystems: setKeySystems,
getKeySystemBySystemString: getKeySystemBySystemString,
getSupportedKeySystemsFromContentProtection: getSupportedKeySystemsFromContentProtection,
getSupportedKeySystemsFromSegmentPssh: getSupportedKeySystemsFromSegmentPssh,
getLicenseServerModelInstance: getLicenseServerModelInstance,
processClearKeyLicenseRequest: processClearKeyLicenseRequest,
setConfig: setConfig
};
return instance;
}
ProtectionKeyController.__dashjs_factory_name = 'ProtectionKeyController';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(ProtectionKeyController));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/drm/KeySystemClearKey.js":
/*!***********************************************************!*\
!*** ./src/streaming/protection/drm/KeySystemClearKey.js ***!
\***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_KeyPair__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/KeyPair */ "./src/streaming/protection/vo/KeyPair.js");
/* harmony import */ var _vo_ClearKeyKeySet__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/ClearKeyKeySet */ "./src/streaming/protection/vo/ClearKeyKeySet.js");
/* harmony import */ var _CommonEncryption__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../CommonEncryption */ "./src/streaming/protection/CommonEncryption.js");
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var uuid = 'e2719d58-a985-b3c9-781a-b030af78d30e';
var systemString = _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_3__["default"].CLEARKEY_KEYSTEM_STRING;
var schemeIdURI = 'urn:uuid:' + uuid;
function KeySystemClearKey(config) {
config = config || {};
var instance;
var BASE64 = config.BASE64;
/**
* Returns desired clearkeys (as specified in the CDM message) from protection data
*
* @param {ProtectionData} protectionData the protection data
* @param {ArrayBuffer} message the ClearKey CDM message
* @returns {ClearKeyKeySet} the key set or null if none found
* @throws {Error} if a keyID specified in the CDM message was not found in the
* protection data
* @memberof KeySystemClearKey
*/
function getClearKeysFromProtectionData(protectionData, message) {
var clearkeySet = null;
if (protectionData) {
// ClearKey is the only system that does not require a license server URL, so we
// handle it here when keys are specified in protection data
var jsonMsg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(message)));
var keyPairs = [];
for (var i = 0; i < jsonMsg.kids.length; i++) {
var clearkeyID = jsonMsg.kids[i];
var clearkey = protectionData.clearkeys && protectionData.clearkeys.hasOwnProperty(clearkeyID) ? protectionData.clearkeys[clearkeyID] : null;
if (!clearkey) {
throw new Error('DRM: ClearKey keyID (' + clearkeyID + ') is not known!');
} // KeyIDs from CDM are not base64 padded. Keys may or may not be padded
keyPairs.push(new _vo_KeyPair__WEBPACK_IMPORTED_MODULE_0__["default"](clearkeyID, clearkey));
}
clearkeySet = new _vo_ClearKeyKeySet__WEBPACK_IMPORTED_MODULE_1__["default"](keyPairs);
}
return clearkeySet;
}
function getInitData(cp, cencContentProtection) {
try {
var initData = _CommonEncryption__WEBPACK_IMPORTED_MODULE_2__["default"].parseInitDataFromContentProtection(cp, BASE64);
if (!initData && cencContentProtection) {
var cencDefaultKid = cencDefaultKidToBase64Representation(cencContentProtection['cenc:default_KID']);
var data = {
kids: [cencDefaultKid]
};
initData = new TextEncoder().encode(JSON.stringify(data));
}
return initData;
} catch (e) {
return null;
}
}
function cencDefaultKidToBase64Representation(cencDefaultKid) {
try {
var kid = cencDefaultKid.replace(/-/g, '');
kid = btoa(kid.match(/\w{2}/g).map(function (a) {
return String.fromCharCode(parseInt(a, 16));
}).join(''));
return kid.replace(/=/g, '');
} catch (e) {
return null;
}
}
function getRequestHeadersFromMessage()
/*message*/
{
// Set content type to application/json by default
return {
'Content-Type': 'application/json'
};
}
function getLicenseRequestFromMessage(message) {
return JSON.parse(String.fromCharCode.apply(null, new Uint8Array(message)));
}
function getLicenseServerURLFromInitData()
/*initData*/
{
return null;
}
function getCDMData()
/*cdmData*/
{
return null;
}
instance = {
uuid: uuid,
schemeIdURI: schemeIdURI,
systemString: systemString,
getInitData: getInitData,
getRequestHeadersFromMessage: getRequestHeadersFromMessage,
getLicenseRequestFromMessage: getLicenseRequestFromMessage,
getLicenseServerURLFromInitData: getLicenseServerURLFromInitData,
getCDMData: getCDMData,
getClearKeysFromProtectionData: getClearKeysFromProtectionData
};
return instance;
}
KeySystemClearKey.__dashjs_factory_name = 'KeySystemClearKey';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(KeySystemClearKey));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/drm/KeySystemPlayReady.js":
/*!************************************************************!*\
!*** ./src/streaming/protection/drm/KeySystemPlayReady.js ***!
\************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../CommonEncryption */ "./src/streaming/protection/CommonEncryption.js");
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Microsoft PlayReady DRM
*
* @class
* @implements KeySystem
*/
var uuid = '9a04f079-9840-4286-ab92-e65be0885f95';
var systemString = _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PLAYREADY_KEYSTEM_STRING;
var schemeIdURI = 'urn:uuid:' + uuid;
var PRCDMData = '<PlayReadyCDMData type="LicenseAcquisition"><LicenseAcquisition version="1.0" Proactive="false"><CustomData encoding="base64encoded">%CUSTOMDATA%</CustomData></LicenseAcquisition></PlayReadyCDMData>';
function KeySystemPlayReady(config) {
config = config || {};
var instance;
var messageFormat = 'utf-16';
var BASE64 = config.BASE64;
function checkConfig() {
if (!BASE64 || !BASE64.hasOwnProperty('decodeArray') || !BASE64.hasOwnProperty('decodeArray')) {
throw new Error('Missing config parameter(s)');
}
}
function getRequestHeadersFromMessage(message) {
var msg, xmlDoc;
var headers = {};
var parser = new DOMParser();
var dataview = messageFormat === 'utf-16' ? new Uint16Array(message) : new Uint8Array(message);
msg = String.fromCharCode.apply(null, dataview);
xmlDoc = parser.parseFromString(msg, 'application/xml');
var headerNameList = xmlDoc.getElementsByTagName('name');
var headerValueList = xmlDoc.getElementsByTagName('value');
for (var i = 0; i < headerNameList.length; i++) {
headers[headerNameList[i].childNodes[0].nodeValue] = headerValueList[i].childNodes[0].nodeValue;
} // Some versions of the PlayReady CDM return 'Content' instead of 'Content-Type'.
// this is NOT w3c conform and license servers may reject the request!
// -> rename it to proper w3c definition!
if (headers.hasOwnProperty('Content')) {
headers['Content-Type'] = headers.Content;
delete headers.Content;
} // Set Content-Type header by default if not provided in the the CDM message (<PlayReadyKeyMessage/>)
// or if the message contains directly the challenge itself (Ex: LG SmartTVs)
if (!headers.hasOwnProperty('Content-Type')) {
headers['Content-Type'] = 'text/xml; charset=utf-8';
}
return headers;
}
function getLicenseRequestFromMessage(message) {
var licenseRequest = null;
var parser = new DOMParser();
var dataview = messageFormat === 'utf-16' ? new Uint16Array(message) : new Uint8Array(message);
checkConfig();
var msg = String.fromCharCode.apply(null, dataview);
var xmlDoc = parser.parseFromString(msg, 'application/xml');
if (xmlDoc.getElementsByTagName('PlayReadyKeyMessage')[0]) {
var Challenge = xmlDoc.getElementsByTagName('Challenge')[0].childNodes[0].nodeValue;
if (Challenge) {
licenseRequest = BASE64.decode(Challenge);
}
} else {
// The message from CDM is not a wrapped message as on IE11 and Edge,
// thus it contains direclty the challenge itself
// (note that the xmlDoc at this point may be unreadable since it may have been interpreted as UTF-16)
return message;
}
return licenseRequest;
}
function getLicenseServerURLFromInitData(initData) {
if (initData) {
var data = new DataView(initData);
var numRecords = data.getUint16(4, true);
var offset = 6;
var parser = new DOMParser();
for (var i = 0; i < numRecords; i++) {
// Parse the PlayReady Record header
var recordType = data.getUint16(offset, true);
offset += 2;
var recordLength = data.getUint16(offset, true);
offset += 2;
if (recordType !== 0x0001) {
offset += recordLength;
continue;
}
var recordData = initData.slice(offset, offset + recordLength);
var record = String.fromCharCode.apply(null, new Uint16Array(recordData));
var xmlDoc = parser.parseFromString(record, 'application/xml'); // First try <LA_URL>
if (xmlDoc.getElementsByTagName('LA_URL')[0]) {
var laurl = xmlDoc.getElementsByTagName('LA_URL')[0].childNodes[0].nodeValue;
if (laurl) {
return laurl;
}
} // Optionally, try <LUI_URL>
if (xmlDoc.getElementsByTagName('LUI_URL')[0]) {
var luiurl = xmlDoc.getElementsByTagName('LUI_URL')[0].childNodes[0].nodeValue;
if (luiurl) {
return luiurl;
}
}
}
}
return null;
}
function getInitData(cpData) {
// * desc@ getInitData
// * generate PSSH data from PROHeader defined in MPD file
// * PSSH format:
// * size (4)
// * box type(PSSH) (8)
// * Protection SystemID (16)
// * protection system data size (4) - length of decoded PROHeader
// * decoded PROHeader data from MPD file
var PSSHBoxType = new Uint8Array([0x70, 0x73, 0x73, 0x68, 0x00, 0x00, 0x00, 0x00]); //'PSSH' 8 bytes
var playreadySystemID = new Uint8Array([0x9a, 0x04, 0xf0, 0x79, 0x98, 0x40, 0x42, 0x86, 0xab, 0x92, 0xe6, 0x5b, 0xe0, 0x88, 0x5f, 0x95]);
var byteCursor = 0;
var uint8arraydecodedPROHeader = null;
var PROSize, PSSHSize, PSSHBoxBuffer, PSSHBox, PSSHData;
checkConfig();
if (!cpData) {
return null;
} // Handle common encryption PSSH
if ('pssh' in cpData) {
return _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].parseInitDataFromContentProtection(cpData, BASE64);
} // Handle native MS PlayReady ContentProtection elements
if ('pro' in cpData) {
uint8arraydecodedPROHeader = BASE64.decodeArray(cpData.pro.__text);
} else if ('prheader' in cpData) {
uint8arraydecodedPROHeader = BASE64.decodeArray(cpData.prheader.__text);
} else {
return null;
}
PROSize = uint8arraydecodedPROHeader.length;
PSSHSize = 0x4 + PSSHBoxType.length + playreadySystemID.length + 0x4 + PROSize;
PSSHBoxBuffer = new ArrayBuffer(PSSHSize);
PSSHBox = new Uint8Array(PSSHBoxBuffer);
PSSHData = new DataView(PSSHBoxBuffer);
PSSHData.setUint32(byteCursor, PSSHSize);
byteCursor += 0x4;
PSSHBox.set(PSSHBoxType, byteCursor);
byteCursor += PSSHBoxType.length;
PSSHBox.set(playreadySystemID, byteCursor);
byteCursor += playreadySystemID.length;
PSSHData.setUint32(byteCursor, PROSize);
byteCursor += 0x4;
PSSHBox.set(uint8arraydecodedPROHeader, byteCursor);
byteCursor += PROSize;
return PSSHBox.buffer;
}
/**
* It seems that some PlayReady implementations return their XML-based CDM
* messages using UTF16, while others return them as UTF8. Use this function
* to modify the message format to expect when parsing CDM messages.
*
* @param {string} format the expected message format. Either "utf-8" or "utf-16".
* @throws {Error} Specified message format is not one of "utf8" or "utf16"
*/
function setPlayReadyMessageFormat(format) {
if (format !== 'utf-8' && format !== 'utf-16') {
throw new Error('Specified message format is not one of "utf-8" or "utf-16"');
}
messageFormat = format;
}
/**
* Get Playready Custom data
*/
function getCDMData(_cdmData) {
var customData, cdmData, cdmDataBytes, i;
checkConfig();
if (!_cdmData) return null; // Convert custom data into multibyte string
customData = [];
for (i = 0; i < _cdmData.length; ++i) {
customData.push(_cdmData.charCodeAt(i));
customData.push(0);
}
customData = String.fromCharCode.apply(null, customData); // Encode in Base 64 the custom data string
customData = BASE64.encode(customData); // Initialize CDM data with Base 64 encoded custom data
// (see https://msdn.microsoft.com/en-us/library/dn457361.aspx)
cdmData = PRCDMData.replace('%CUSTOMDATA%', customData); // Convert CDM data into multibyte characters
cdmDataBytes = [];
for (i = 0; i < cdmData.length; ++i) {
cdmDataBytes.push(cdmData.charCodeAt(i));
cdmDataBytes.push(0);
}
return new Uint8Array(cdmDataBytes).buffer;
}
instance = {
uuid: uuid,
schemeIdURI: schemeIdURI,
systemString: systemString,
getInitData: getInitData,
getRequestHeadersFromMessage: getRequestHeadersFromMessage,
getLicenseRequestFromMessage: getLicenseRequestFromMessage,
getLicenseServerURLFromInitData: getLicenseServerURLFromInitData,
getCDMData: getCDMData,
setPlayReadyMessageFormat: setPlayReadyMessageFormat
};
return instance;
}
KeySystemPlayReady.__dashjs_factory_name = 'KeySystemPlayReady';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(KeySystemPlayReady));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/drm/KeySystemW3CClearKey.js":
/*!**************************************************************!*\
!*** ./src/streaming/protection/drm/KeySystemW3CClearKey.js ***!
\**************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_KeyPair__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/KeyPair */ "./src/streaming/protection/vo/KeyPair.js");
/* harmony import */ var _vo_ClearKeyKeySet__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/ClearKeyKeySet */ "./src/streaming/protection/vo/ClearKeyKeySet.js");
/* harmony import */ var _CommonEncryption__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../CommonEncryption */ "./src/streaming/protection/CommonEncryption.js");
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var uuid = '1077efec-c0b2-4d02-ace3-3c1e52e2fb4b';
var systemString = _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_3__["default"].CLEARKEY_KEYSTEM_STRING;
var schemeIdURI = 'urn:uuid:' + uuid;
function KeySystemW3CClearKey(config) {
var instance;
var BASE64 = config.BASE64;
var logger = config.debug.getLogger(instance);
/**
* Returns desired clearkeys (as specified in the CDM message) from protection data
*
* @param {ProtectionDataSet} protectionData the protection data
* @param {ArrayBuffer} message the ClearKey CDM message
* @returns {ClearKeyKeySet} the key set or null if none found
* @throws {Error} if a keyID specified in the CDM message was not found in the
* protection data
* @memberof KeySystemClearKey
*/
function getClearKeysFromProtectionData(protectionData, message) {
var clearkeySet = null;
if (protectionData) {
// ClearKey is the only system that does not require a license server URL, so we
// handle it here when keys are specified in protection data
var jsonMsg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(message)));
var keyPairs = [];
for (var i = 0; i < jsonMsg.kids.length; i++) {
var clearkeyID = jsonMsg.kids[i];
var clearkey = protectionData.clearkeys && protectionData.clearkeys.hasOwnProperty(clearkeyID) ? protectionData.clearkeys[clearkeyID] : null;
if (!clearkey) {
throw new Error('DRM: ClearKey keyID (' + clearkeyID + ') is not known!');
} // KeyIDs from CDM are not base64 padded. Keys may or may not be padded
keyPairs.push(new _vo_KeyPair__WEBPACK_IMPORTED_MODULE_0__["default"](clearkeyID, clearkey));
}
clearkeySet = new _vo_ClearKeyKeySet__WEBPACK_IMPORTED_MODULE_1__["default"](keyPairs);
logger.warn('ClearKey schemeIdURI is using W3C Common PSSH systemID (1077efec-c0b2-4d02-ace3-3c1e52e2fb4b) in Content Protection. See DASH-IF IOP v4.1 section 7.6.2.4');
}
return clearkeySet;
}
function getInitData(cp) {
return _CommonEncryption__WEBPACK_IMPORTED_MODULE_2__["default"].parseInitDataFromContentProtection(cp, BASE64);
}
function getRequestHeadersFromMessage()
/*message*/
{
return null;
}
function getLicenseRequestFromMessage(message) {
return new Uint8Array(message);
}
function getLicenseServerURLFromInitData()
/*initData*/
{
return null;
}
function getCDMData()
/*cdmData*/
{
return null;
}
instance = {
uuid: uuid,
schemeIdURI: schemeIdURI,
systemString: systemString,
getInitData: getInitData,
getRequestHeadersFromMessage: getRequestHeadersFromMessage,
getLicenseRequestFromMessage: getLicenseRequestFromMessage,
getLicenseServerURLFromInitData: getLicenseServerURLFromInitData,
getCDMData: getCDMData,
getClearKeysFromProtectionData: getClearKeysFromProtectionData
};
return instance;
}
KeySystemW3CClearKey.__dashjs_factory_name = 'KeySystemW3CClearKey';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(KeySystemW3CClearKey));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/drm/KeySystemWidevine.js":
/*!***********************************************************!*\
!*** ./src/streaming/protection/drm/KeySystemWidevine.js ***!
\***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../CommonEncryption */ "./src/streaming/protection/CommonEncryption.js");
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Google Widevine DRM
*
* @class
* @implements MediaPlayer.dependencies.protection.KeySystem
*/
var uuid = 'edef8ba9-79d6-4ace-a3c8-27dcd51d21ed';
var systemString = _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_1__["default"].WIDEVINE_KEYSTEM_STRING;
var schemeIdURI = 'urn:uuid:' + uuid;
function KeySystemWidevine(config) {
config = config || {};
var instance;
var BASE64 = config.BASE64;
function getInitData(cp) {
return _CommonEncryption__WEBPACK_IMPORTED_MODULE_0__["default"].parseInitDataFromContentProtection(cp, BASE64);
}
function getRequestHeadersFromMessage()
/*message*/
{
return null;
}
function getLicenseRequestFromMessage(message) {
return new Uint8Array(message);
}
function getLicenseServerURLFromInitData()
/*initData*/
{
return null;
}
function getCDMData()
/*cdmData*/
{
return null;
}
instance = {
uuid: uuid,
schemeIdURI: schemeIdURI,
systemString: systemString,
getInitData: getInitData,
getRequestHeadersFromMessage: getRequestHeadersFromMessage,
getLicenseRequestFromMessage: getLicenseRequestFromMessage,
getLicenseServerURLFromInitData: getLicenseServerURLFromInitData,
getCDMData: getCDMData
};
return instance;
}
KeySystemWidevine.__dashjs_factory_name = 'KeySystemWidevine';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(KeySystemWidevine));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/errors/ProtectionErrors.js":
/*!*************************************************************!*\
!*** ./src/streaming/protection/errors/ProtectionErrors.js ***!
\*************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_errors_ErrorsBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/errors/ErrorsBase */ "./src/core/errors/ErrorsBase.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
*/
var ProtectionErrors = /*#__PURE__*/function (_ErrorsBase) {
_inherits(ProtectionErrors, _ErrorsBase);
var _super = _createSuper(ProtectionErrors);
function ProtectionErrors() {
var _this;
_classCallCheck(this, ProtectionErrors);
_this = _super.call(this);
/**
* Generid key Error code
*/
_this.MEDIA_KEYERR_CODE = 100;
/**
* Error code returned by keyerror api for ProtectionModel_01b
*/
_this.MEDIA_KEYERR_UNKNOWN_CODE = 101;
/**
* Error code returned by keyerror api for ProtectionModel_01b
*/
_this.MEDIA_KEYERR_CLIENT_CODE = 102;
/**
* Error code returned by keyerror api for ProtectionModel_01b
*/
_this.MEDIA_KEYERR_SERVICE_CODE = 103;
/**
* Error code returned by keyerror api for ProtectionModel_01b
*/
_this.MEDIA_KEYERR_OUTPUT_CODE = 104;
/**
* Error code returned by keyerror api for ProtectionModel_01b
*/
_this.MEDIA_KEYERR_HARDWARECHANGE_CODE = 105;
/**
* Error code returned by keyerror api for ProtectionModel_01b
*/
_this.MEDIA_KEYERR_DOMAIN_CODE = 106;
/**
* Error code returned when an error occured in keymessage event for ProtectionModel_01b
*/
_this.MEDIA_KEY_MESSAGE_ERROR_CODE = 107;
/**
* Error code returned when challenge is invalid in keymessage event (event triggered by CDM)
*/
_this.MEDIA_KEY_MESSAGE_NO_CHALLENGE_ERROR_CODE = 108;
/**
* Error code returned when License server certificate has not been successfully updated
*/
_this.SERVER_CERTIFICATE_UPDATED_ERROR_CODE = 109;
/**
* Error code returned when license validity has expired
*/
_this.KEY_STATUS_CHANGED_EXPIRED_ERROR_CODE = 110;
/**
* Error code returned when no licenser url is defined
*/
_this.MEDIA_KEY_MESSAGE_NO_LICENSE_SERVER_URL_ERROR_CODE = 111;
/**
* Error code returned when key system access is denied
*/
_this.KEY_SYSTEM_ACCESS_DENIED_ERROR_CODE = 112;
/**
* Error code returned when key session has not been successfully created
*/
_this.KEY_SESSION_CREATED_ERROR_CODE = 113;
/**
* Error code returned when license request failed after a keymessage event has been triggered
*/
_this.MEDIA_KEY_MESSAGE_LICENSER_ERROR_CODE = 114;
_this.MEDIA_KEYERR_UNKNOWN_MESSAGE = 'An unspecified error occurred. This value is used for errors that don\'t match any of the other codes.';
_this.MEDIA_KEYERR_CLIENT_MESSAGE = 'The Key System could not be installed or updated.';
_this.MEDIA_KEYERR_SERVICE_MESSAGE = 'The message passed into update indicated an error from the license service.';
_this.MEDIA_KEYERR_OUTPUT_MESSAGE = 'There is no available output device with the required characteristics for the content protection system.';
_this.MEDIA_KEYERR_HARDWARECHANGE_MESSAGE = 'A hardware configuration change caused a content protection error.';
_this.MEDIA_KEYERR_DOMAIN_MESSAGE = 'An error occurred in a multi-device domain licensing configuration. The most common error is a failure to join the domain.';
_this.MEDIA_KEY_MESSAGE_ERROR_MESSAGE = 'Multiple key sessions were creates with a user-agent that does not support sessionIDs!! Unpredictable behavior ahead!';
_this.MEDIA_KEY_MESSAGE_NO_CHALLENGE_ERROR_MESSAGE = 'DRM: Empty key message from CDM';
_this.SERVER_CERTIFICATE_UPDATED_ERROR_MESSAGE = 'Error updating server certificate -- ';
_this.KEY_STATUS_CHANGED_EXPIRED_ERROR_MESSAGE = 'DRM: KeyStatusChange error! -- License has expired';
_this.MEDIA_KEY_MESSAGE_NO_LICENSE_SERVER_URL_ERROR_MESSAGE = 'DRM: No license server URL specified!';
_this.KEY_SYSTEM_ACCESS_DENIED_ERROR_MESSAGE = 'DRM: KeySystem Access Denied! -- ';
_this.KEY_SESSION_CREATED_ERROR_MESSAGE = 'DRM: unable to create session! --';
_this.MEDIA_KEY_MESSAGE_LICENSER_ERROR_MESSAGE = 'DRM: licenser error! --';
return _this;
}
return ProtectionErrors;
}(_core_errors_ErrorsBase__WEBPACK_IMPORTED_MODULE_0__["default"]);
var protectionErrors = new ProtectionErrors();
/* harmony default export */ __webpack_exports__["default"] = (protectionErrors);
/***/ }),
/***/ "./src/streaming/protection/models/ProtectionModel_01b.js":
/*!****************************************************************!*\
!*** ./src/streaming/protection/models/ProtectionModel_01b.js ***!
\****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../controllers/ProtectionKeyController */ "./src/streaming/protection/controllers/ProtectionKeyController.js");
/* harmony import */ var _vo_NeedKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/NeedKey */ "./src/streaming/protection/vo/NeedKey.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _vo_KeyMessage__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../vo/KeyMessage */ "./src/streaming/protection/vo/KeyMessage.js");
/* harmony import */ var _vo_KeySystemConfiguration__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/KeySystemConfiguration */ "./src/streaming/protection/vo/KeySystemConfiguration.js");
/* harmony import */ var _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/KeySystemAccess */ "./src/streaming/protection/vo/KeySystemAccess.js");
/* harmony import */ var _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../errors/ProtectionErrors */ "./src/streaming/protection/errors/ProtectionErrors.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Initial implementation of EME
*
* Implemented by Google Chrome prior to v36
*
* @implements ProtectionModel
* @class
*/
function ProtectionModel_01b(config) {
config = config || {};
var context = this.context;
var eventBus = config.eventBus; //Need to pass in here so we can use same instance since this is optional module
var events = config.events;
var debug = config.debug;
var api = config.api;
var errHandler = config.errHandler;
var instance, logger, videoElement, keySystem, protectionKeyController, // With this version of the EME APIs, sessionIds are not assigned to
// sessions until the first key message is received. We are assuming
// that in the case of multiple sessions, key messages will be received
// in the order that generateKeyRequest() is called.
// Holding spot for newly-created sessions until we determine whether or
// not the CDM supports sessionIds
pendingSessions, // List of sessions that have been initialized. Only the first position will
// be used in the case that the CDM does not support sessionIds
sessions, // Not all CDMs support the notion of sessionIds. Without sessionIds
// there is no way for us to differentiate between sessions, therefore
// we must only allow a single session. Once we receive the first key
// message we can set this flag to determine if more sessions are allowed
moreSessionsAllowed, // This is our main event handler for all desired HTMLMediaElement events
// related to EME. These events are translated into our API-independent
// versions of the same events
eventHandler;
function setup() {
logger = debug.getLogger(instance);
videoElement = null;
keySystem = null;
pendingSessions = [];
sessions = [];
protectionKeyController = Object(_controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
eventHandler = createEventHandler();
}
function reset() {
if (videoElement) {
removeEventListeners();
}
for (var i = 0; i < sessions.length; i++) {
closeKeySession(sessions[i]);
}
eventBus.trigger(events.TEARDOWN_COMPLETE);
}
function getAllInitData() {
var retVal = [];
for (var i = 0; i < pendingSessions.length; i++) {
retVal.push(pendingSessions[i].initData);
}
for (var _i = 0; _i < sessions.length; _i++) {
retVal.push(sessions[_i].initData);
}
return retVal;
}
function getSessions() {
return sessions.concat(pendingSessions);
}
function requestKeySystemAccess(ksConfigurations) {
return new Promise(function (resolve, reject) {
var ve = videoElement;
if (!ve) {
// Must have a video element to do this capability tests
ve = document.createElement('video');
} // Try key systems in order, first one with supported key system configuration
// is used
var found = false;
for (var ksIdx = 0; ksIdx < ksConfigurations.length; ksIdx++) {
var systemString = ksConfigurations[ksIdx].ks.systemString;
var configs = ksConfigurations[ksIdx].configs;
var supportedAudio = null;
var supportedVideo = null; // Try key system configs in order, first one with supported audio/video
// is used
for (var configIdx = 0; configIdx < configs.length; configIdx++) {
//let audios = configs[configIdx].audioCapabilities;
var videos = configs[configIdx].videoCapabilities; // Look for supported video container/codecs
if (videos && videos.length !== 0) {
supportedVideo = []; // Indicates that we have a requested video config
for (var videoIdx = 0; videoIdx < videos.length; videoIdx++) {
if (ve.canPlayType(videos[videoIdx].contentType, systemString) !== '') {
supportedVideo.push(videos[videoIdx]);
}
}
} // No supported audio or video in this configuration OR we have
// requested audio or video configuration that is not supported
if (!supportedVideo || supportedAudio && supportedAudio.length === 0 || supportedVideo && supportedVideo.length === 0) {
continue;
} // This configuration is supported
found = true;
var ksConfig = new _vo_KeySystemConfiguration__WEBPACK_IMPORTED_MODULE_4__["default"](supportedAudio, supportedVideo);
var ks = protectionKeyController.getKeySystemBySystemString(systemString);
var keySystemAccess = new _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_5__["default"](ks, ksConfig);
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
data: keySystemAccess
});
resolve({
data: keySystemAccess
});
break;
}
}
if (!found) {
var errorMessage = 'Key system access denied! -- No valid audio/video content configurations detected!';
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
error: errorMessage
});
reject({
error: errorMessage
});
}
});
}
function selectKeySystem(keySystemAccess) {
keySystem = keySystemAccess.keySystem;
return Promise.resolve(keySystem);
}
function setMediaElement(mediaElement) {
if (videoElement === mediaElement) {
return;
} // Replacing the previous element
if (videoElement) {
removeEventListeners(); // Close any open sessions - avoids memory leak on LG webOS 2016/2017 TVs
for (var i = 0; i < sessions.length; i++) {
closeKeySession(sessions[i]);
}
sessions = [];
}
videoElement = mediaElement; // Only if we are not detaching from the existing element
if (videoElement) {
videoElement.addEventListener(api.keyerror, eventHandler);
videoElement.addEventListener(api.needkey, eventHandler);
videoElement.addEventListener(api.keymessage, eventHandler);
videoElement.addEventListener(api.keyadded, eventHandler);
eventBus.trigger(events.VIDEO_ELEMENT_SELECTED);
}
}
function createKeySession(ksInfo) {
if (!keySystem) {
throw new Error('Can not create sessions until you have selected a key system');
} // Determine if creating a new session is allowed
if (moreSessionsAllowed || sessions.length === 0) {
var newSession = {
// Implements SessionToken
sessionId: null,
keyId: ksInfo.keyId,
initData: ksInfo.initData,
getKeyId: function getKeyId() {
return this.keyId;
},
getSessionId: function getSessionId() {
return this.sessionId;
},
getExpirationTime: function getExpirationTime() {
return NaN;
},
getSessionType: function getSessionType() {
return 'temporary';
}
};
pendingSessions.push(newSession); // Send our request to the CDM
videoElement[api.generateKeyRequest](keySystem.systemString, new Uint8Array(ksInfo.initData));
return newSession;
} else {
throw new Error('Multiple sessions not allowed!');
}
}
function updateKeySession(sessionToken, message) {
var sessionId = sessionToken.sessionId;
if (!protectionKeyController.isClearKey(keySystem)) {
// Send our request to the CDM
videoElement[api.addKey](keySystem.systemString, new Uint8Array(message), new Uint8Array(sessionToken.initData), sessionId);
} else {
// For clearkey, message is a ClearKeyKeySet
for (var i = 0; i < message.keyPairs.length; i++) {
videoElement[api.addKey](keySystem.systemString, message.keyPairs[i].key, message.keyPairs[i].keyID, sessionId);
}
}
eventBus.trigger(events.KEY_SESSION_UPDATED);
}
function closeKeySession(sessionToken) {
// Send our request to the CDM
try {
videoElement[api.cancelKeyRequest](keySystem.systemString, sessionToken.sessionId);
} catch (error) {
eventBus.trigger(events.KEY_SESSION_CLOSED, {
data: null,
error: 'Error closing session (' + sessionToken.sessionId + ') ' + error.message
});
}
}
function setServerCertificate()
/*serverCertificate*/
{
/* Not supported */
}
function loadKeySession()
/*ksInfo*/
{
/* Not supported */
}
function removeKeySession()
/*sessionToken*/
{
/* Not supported */
}
function createEventHandler() {
return {
handleEvent: function handleEvent(event) {
var sessionToken = null;
switch (event.type) {
case api.needkey:
var initData = ArrayBuffer.isView(event.initData) ? event.initData.buffer : event.initData;
eventBus.trigger(events.NEED_KEY, {
key: new _vo_NeedKey__WEBPACK_IMPORTED_MODULE_1__["default"](initData, 'cenc')
});
break;
case api.keyerror:
sessionToken = findSessionByID(sessions, event.sessionId);
if (!sessionToken) {
sessionToken = findSessionByID(pendingSessions, event.sessionId);
}
if (sessionToken) {
var code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_CODE;
var msg = '';
switch (event.errorCode.code) {
case 1:
code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_UNKNOWN_CODE;
msg += 'MEDIA_KEYERR_UNKNOWN - ' + _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_UNKNOWN_MESSAGE;
break;
case 2:
code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_CLIENT_CODE;
msg += 'MEDIA_KEYERR_CLIENT - ' + _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_CLIENT_MESSAGE;
break;
case 3:
code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_SERVICE_CODE;
msg += 'MEDIA_KEYERR_SERVICE - ' + _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_SERVICE_MESSAGE;
break;
case 4:
code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_OUTPUT_CODE;
msg += 'MEDIA_KEYERR_OUTPUT - ' + _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_OUTPUT_MESSAGE;
break;
case 5:
code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_HARDWARECHANGE_CODE;
msg += 'MEDIA_KEYERR_HARDWARECHANGE - ' + _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_HARDWARECHANGE_MESSAGE;
break;
case 6:
code = _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_DOMAIN_CODE;
msg += 'MEDIA_KEYERR_DOMAIN - ' + _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEYERR_DOMAIN_MESSAGE;
break;
}
msg += ' System Code = ' + event.systemCode; // TODO: Build error string based on key error
eventBus.trigger(events.KEY_ERROR, {
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_2__["default"](code, msg, sessionToken)
});
} else {
logger.error('No session token found for key error');
}
break;
case api.keyadded:
sessionToken = findSessionByID(sessions, event.sessionId);
if (!sessionToken) {
sessionToken = findSessionByID(pendingSessions, event.sessionId);
}
if (sessionToken) {
logger.debug('DRM: Key added.');
eventBus.trigger(events.KEY_ADDED, {
data: sessionToken
}); //TODO not sure anything is using sessionToken? why there?
} else {
logger.debug('No session token found for key added');
}
break;
case api.keymessage:
// If this CDM does not support session IDs, we will be limited
// to a single session
moreSessionsAllowed = event.sessionId !== null && event.sessionId !== undefined; // SessionIDs supported
if (moreSessionsAllowed) {
// Attempt to find an uninitialized token with this sessionId
sessionToken = findSessionByID(sessions, event.sessionId);
if (!sessionToken && pendingSessions.length > 0) {
// This is the first message for our latest session, so set the
// sessionId and add it to our list
sessionToken = pendingSessions.shift();
sessions.push(sessionToken);
sessionToken.sessionId = event.sessionId;
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: sessionToken
});
}
} else if (pendingSessions.length > 0) {
// SessionIDs not supported
sessionToken = pendingSessions.shift();
sessions.push(sessionToken);
if (pendingSessions.length !== 0) {
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_2__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEY_MESSAGE_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_KEY_MESSAGE_ERROR_MESSAGE));
}
}
if (sessionToken) {
var message = ArrayBuffer.isView(event.message) ? event.message.buffer : event.message; // For ClearKey, the spec mandates that you pass this message to the
// addKey method, so we always save it to the token since there is no
// way to tell which key system is in use
sessionToken.keyMessage = message;
eventBus.trigger(events.INTERNAL_KEY_MESSAGE, {
data: new _vo_KeyMessage__WEBPACK_IMPORTED_MODULE_3__["default"](sessionToken, message, event.defaultURL)
});
} else {
logger.warn('No session token found for key message');
}
break;
}
}
};
}
/**
* Helper function to retrieve the stored session token based on a given
* sessionId value
*
* @param {Array} sessionArray - the array of sessions to search
* @param {*} sessionId - the sessionId to search for
* @returns {*} the session token with the given sessionId
*/
function findSessionByID(sessionArray, sessionId) {
if (!sessionId || !sessionArray) {
return null;
} else {
var len = sessionArray.length;
for (var i = 0; i < len; i++) {
if (sessionArray[i].sessionId == sessionId) {
return sessionArray[i];
}
}
return null;
}
}
function removeEventListeners() {
videoElement.removeEventListener(api.keyerror, eventHandler);
videoElement.removeEventListener(api.needkey, eventHandler);
videoElement.removeEventListener(api.keymessage, eventHandler);
videoElement.removeEventListener(api.keyadded, eventHandler);
}
instance = {
getAllInitData: getAllInitData,
getSessions: getSessions,
requestKeySystemAccess: requestKeySystemAccess,
selectKeySystem: selectKeySystem,
setMediaElement: setMediaElement,
createKeySession: createKeySession,
updateKeySession: updateKeySession,
closeKeySession: closeKeySession,
setServerCertificate: setServerCertificate,
loadKeySession: loadKeySession,
removeKeySession: removeKeySession,
stop: reset,
reset: reset
};
setup();
return instance;
}
ProtectionModel_01b.__dashjs_factory_name = 'ProtectionModel_01b';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(ProtectionModel_01b));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/models/ProtectionModel_21Jan2015.js":
/*!**********************************************************************!*\
!*** ./src/streaming/protection/models/ProtectionModel_21Jan2015.js ***!
\**********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../controllers/ProtectionKeyController */ "./src/streaming/protection/controllers/ProtectionKeyController.js");
/* harmony import */ var _vo_NeedKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/NeedKey */ "./src/streaming/protection/vo/NeedKey.js");
/* harmony import */ var _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../errors/ProtectionErrors */ "./src/streaming/protection/errors/ProtectionErrors.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _vo_KeyMessage__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/KeyMessage */ "./src/streaming/protection/vo/KeyMessage.js");
/* harmony import */ var _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/KeySystemAccess */ "./src/streaming/protection/vo/KeySystemAccess.js");
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Most recent EME implementation
*
* Implemented by Google Chrome v36+ (Windows, OSX, Linux)
*
* @implements ProtectionModel
* @class
*/
function ProtectionModel_21Jan2015(config) {
config = config || {};
var context = this.context;
var eventBus = config.eventBus; //Need to pass in here so we can use same instance since this is optional module
var events = config.events;
var debug = config.debug;
var instance, logger, keySystem, videoElement, mediaKeys, sessions, eventHandler, protectionKeyController;
function setup() {
logger = debug.getLogger(instance);
keySystem = null;
videoElement = null;
mediaKeys = null;
sessions = [];
protectionKeyController = Object(_controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
eventHandler = createEventHandler();
}
function reset() {
var numSessions = sessions.length;
var session;
if (numSessions !== 0) {
(function () {
// Called when we are done closing a session. Success or fail
var done = function done(session) {
removeSession(session);
if (sessions.length === 0) {
if (videoElement) {
videoElement.removeEventListener('encrypted', eventHandler);
videoElement.setMediaKeys(null).then(function () {
eventBus.trigger(events.TEARDOWN_COMPLETE);
});
} else {
eventBus.trigger(events.TEARDOWN_COMPLETE);
}
}
};
for (var i = 0; i < numSessions; i++) {
session = sessions[i];
(function (s) {
// Override closed promise resolver
session.session.closed.then(function () {
done(s);
}); // Close the session and handle errors, otherwise promise
// resolver above will be called
_closeKeySessionInternal(session)["catch"](function () {
done(s);
});
})(session);
}
})();
} else {
eventBus.trigger(events.TEARDOWN_COMPLETE);
}
}
function stop() {
// Close and remove not usable sessions
var session;
for (var i = 0; i < sessions.length; i++) {
session = sessions[i];
if (!session.getUsable()) {
_closeKeySessionInternal(session)["catch"](function () {
removeSession(session);
});
}
}
}
function getAllInitData() {
var retVal = [];
for (var i = 0; i < sessions.length; i++) {
if (sessions[i].initData) {
retVal.push(sessions[i].initData);
}
}
return retVal;
}
function getSessions() {
return sessions;
}
function requestKeySystemAccess(ksConfigurations) {
return new Promise(function (resolve, reject) {
_requestKeySystemAccessInternal(ksConfigurations, 0, resolve, reject);
});
}
/**
* Initializes access to a key system. Once we found a valid configuration we get a mediaKeySystemAccess object
* @param ksConfigurations
* @param idx
* @param resolve
* @param reject
* @private
*/
function _requestKeySystemAccessInternal(ksConfigurations, idx, resolve, reject) {
if (navigator.requestMediaKeySystemAccess === undefined || typeof navigator.requestMediaKeySystemAccess !== 'function') {
var msg = 'Insecure origins are not allowed';
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
error: msg
});
reject({
error: msg
});
return;
}
var keySystem = ksConfigurations[idx].ks;
var configs = ksConfigurations[idx].configs;
var systemString = keySystem.systemString; // Patch to support persistent licenses on Edge browser (see issue #2658)
if (systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYREADY_KEYSTEM_STRING && configs[0].persistentState === 'required') {
systemString += '.recommendation';
}
navigator.requestMediaKeySystemAccess(systemString, configs).then(function (mediaKeySystemAccess) {
var configuration = typeof mediaKeySystemAccess.getConfiguration === 'function' ? mediaKeySystemAccess.getConfiguration() : null;
var keySystemAccess = new _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_5__["default"](keySystem, configuration);
keySystemAccess.mksa = mediaKeySystemAccess;
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
data: keySystemAccess
});
resolve({
data: keySystemAccess
});
})["catch"](function (error) {
if (idx + 1 < ksConfigurations.length) {
_requestKeySystemAccessInternal(ksConfigurations, idx + 1, resolve, reject);
} else {
var errorMessage = 'Key system access denied! ';
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
error: errorMessage + error.message
});
reject({
error: errorMessage + error.message
});
}
});
}
/**
* Selects a key system by creating the mediaKeys and adding them to the video element
* @param keySystemAccess
* @return {Promise<unknown>}
*/
function selectKeySystem(keySystemAccess) {
return new Promise(function (resolve, reject) {
keySystemAccess.mksa.createMediaKeys().then(function (mkeys) {
keySystem = keySystemAccess.keySystem;
mediaKeys = mkeys;
if (videoElement) {
return videoElement.setMediaKeys(mediaKeys);
} else {
return Promise.resolve();
}
}).then(function () {
resolve(keySystem);
})["catch"](function () {
reject({
error: 'Error selecting keys system (' + keySystemAccess.keySystem.systemString + ')! Could not create MediaKeys -- TODO'
});
});
});
}
function setMediaElement(mediaElement) {
if (videoElement === mediaElement) return; // Replacing the previous element
if (videoElement) {
videoElement.removeEventListener('encrypted', eventHandler);
if (videoElement.setMediaKeys) {
videoElement.setMediaKeys(null);
}
}
videoElement = mediaElement; // Only if we are not detaching from the existing element
if (videoElement) {
videoElement.addEventListener('encrypted', eventHandler);
if (videoElement.setMediaKeys && mediaKeys) {
videoElement.setMediaKeys(mediaKeys);
}
}
}
function setServerCertificate(serverCertificate) {
if (!keySystem || !mediaKeys) {
throw new Error('Can not set server certificate until you have selected a key system');
}
mediaKeys.setServerCertificate(serverCertificate).then(function () {
logger.info('DRM: License server certificate successfully updated.');
eventBus.trigger(events.SERVER_CERTIFICATE_UPDATED);
})["catch"](function (error) {
eventBus.trigger(events.SERVER_CERTIFICATE_UPDATED, {
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].SERVER_CERTIFICATE_UPDATED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].SERVER_CERTIFICATE_UPDATED_ERROR_MESSAGE + error.name)
});
});
}
/**
* Create a key session, a session token and initialize a request by calling generateRequest
* @param ksInfo
*/
function createKeySession(ksInfo) {
if (!keySystem || !mediaKeys) {
throw new Error('Can not create sessions until you have selected a key system');
}
var session = mediaKeys.createSession(ksInfo.sessionType);
var sessionToken = createSessionToken(session, ksInfo); // The "keyids" type is used for Clearkey when keys are provided directly in the protection data and a request to a license server is not needed
var dataType = keySystem.systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CLEARKEY_KEYSTEM_STRING && (ksInfo.initData || ksInfo.protData && ksInfo.protData.clearkeys) ? _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].INITIALIZATION_DATA_TYPE_KEYIDS : _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].INITIALIZATION_DATA_TYPE_CENC;
session.generateRequest(dataType, ksInfo.initData).then(function () {
logger.debug('DRM: Session created. SessionID = ' + sessionToken.getSessionId());
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: sessionToken
});
})["catch"](function (error) {
removeSession(sessionToken);
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_SESSION_CREATED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_SESSION_CREATED_ERROR_MESSAGE + 'Error generating key request -- ' + error.name)
});
});
}
function updateKeySession(sessionToken, message) {
var session = sessionToken.session; // Send our request to the key session
if (protectionKeyController.isClearKey(keySystem)) {
message = message.toJWK();
}
session.update(message).then(function () {
eventBus.trigger(events.KEY_SESSION_UPDATED);
})["catch"](function (error) {
eventBus.trigger(events.KEY_ERROR, {
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].MEDIA_KEYERR_CODE, 'Error sending update() message! ' + error.name, sessionToken)
});
});
}
function loadKeySession(ksInfo) {
if (!keySystem || !mediaKeys) {
throw new Error('Can not load sessions until you have selected a key system');
}
var sessionId = ksInfo.sessionId; // Check if session Id is not already loaded or loading
for (var i = 0; i < sessions.length; i++) {
if (sessionId === sessions[i].sessionId) {
logger.warn('DRM: Ignoring session ID because we have already seen it!');
return;
}
}
var session = mediaKeys.createSession(ksInfo.sessionType);
var sessionToken = createSessionToken(session, ksInfo); // Load persisted session data into our newly created session object
session.load(sessionId).then(function (success) {
if (success) {
logger.debug('DRM: Session loaded. SessionID = ' + sessionToken.getSessionId());
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: sessionToken
});
} else {
removeSession(sessionToken);
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_SESSION_CREATED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_SESSION_CREATED_ERROR_MESSAGE + 'Could not load session! Invalid Session ID (' + sessionId + ')')
});
}
})["catch"](function (error) {
removeSession(sessionToken);
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: null,
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_SESSION_CREATED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_SESSION_CREATED_ERROR_MESSAGE + 'Could not load session (' + sessionId + ')! ' + error.name)
});
});
}
function removeKeySession(sessionToken) {
var session = sessionToken.session;
session.remove().then(function () {
logger.debug('DRM: Session removed. SessionID = ' + sessionToken.getSessionId());
eventBus.trigger(events.KEY_SESSION_REMOVED, {
data: sessionToken.getSessionId()
});
}, function (error) {
eventBus.trigger(events.KEY_SESSION_REMOVED, {
data: null,
error: 'Error removing session (' + sessionToken.getSessionId() + '). ' + error.name
});
});
}
function closeKeySession(sessionToken) {
// Send our request to the key session
_closeKeySessionInternal(sessionToken)["catch"](function (error) {
removeSession(sessionToken);
eventBus.trigger(events.KEY_SESSION_CLOSED, {
data: null,
error: 'Error closing session (' + sessionToken.getSessionId() + ') ' + error.name
});
});
}
function _closeKeySessionInternal(sessionToken) {
var session = sessionToken.session; // Remove event listeners
session.removeEventListener('keystatuseschange', sessionToken);
session.removeEventListener('message', sessionToken); // Send our request to the key session
return session.close();
} // This is our main event handler for all desired HTMLMediaElement events
// related to EME. These events are translated into our API-independent
// versions of the same events
function createEventHandler() {
return {
handleEvent: function handleEvent(event) {
switch (event.type) {
case 'encrypted':
if (event.initData) {
var initData = ArrayBuffer.isView(event.initData) ? event.initData.buffer : event.initData;
eventBus.trigger(events.NEED_KEY, {
key: new _vo_NeedKey__WEBPACK_IMPORTED_MODULE_1__["default"](initData, event.initDataType)
});
}
break;
}
}
};
}
function removeSession(token) {
// Remove from our session list
for (var i = 0; i < sessions.length; i++) {
if (sessions[i] === token) {
sessions.splice(i, 1);
break;
}
}
}
function parseKeyStatus(args) {
// Edge and Chrome implement different version of keystatues, param are not on same order
var status, keyId;
if (args && args.length > 0) {
if (args[0]) {
if (typeof args[0] === 'string') {
status = args[0];
} else {
keyId = args[0];
}
}
if (args[1]) {
if (typeof args[1] === 'string') {
status = args[1];
} else {
keyId = args[1];
}
}
}
return {
status: status,
keyId: keyId
};
} // Function to create our session token objects which manage the EME
// MediaKeySession and session-specific event handler
function createSessionToken(session, ksInfo) {
var token = {
// Implements SessionToken
session: session,
keyId: ksInfo.keyId,
initData: ksInfo.initData,
sessionId: ksInfo.sessionId,
sessionType: ksInfo.sessionType,
// This is our main event handler for all desired MediaKeySession events
// These events are translated into our API-independent versions of the
// same events
handleEvent: function handleEvent(event) {
switch (event.type) {
case 'keystatuseschange':
eventBus.trigger(events.KEY_STATUSES_CHANGED, {
data: this
});
event.target.keyStatuses.forEach(function () {
var keyStatus = parseKeyStatus(arguments);
switch (keyStatus.status) {
case 'expired':
eventBus.trigger(events.INTERNAL_KEY_STATUS_CHANGED, {
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_3__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_STATUS_CHANGED_EXPIRED_ERROR_CODE, _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_2__["default"].KEY_STATUS_CHANGED_EXPIRED_ERROR_MESSAGE)
});
break;
default:
eventBus.trigger(events.INTERNAL_KEY_STATUS_CHANGED, keyStatus);
break;
}
});
break;
case 'message':
var message = ArrayBuffer.isView(event.message) ? event.message.buffer : event.message;
eventBus.trigger(events.INTERNAL_KEY_MESSAGE, {
data: new _vo_KeyMessage__WEBPACK_IMPORTED_MODULE_4__["default"](this, message, undefined, event.messageType)
});
break;
}
},
getKeyId: function getKeyId() {
return this.keyId;
},
getSessionId: function getSessionId() {
return session.sessionId;
},
getSessionType: function getSessionType() {
return this.sessionType;
},
getExpirationTime: function getExpirationTime() {
return session.expiration;
},
getKeyStatuses: function getKeyStatuses() {
return session.keyStatuses;
},
getUsable: function getUsable() {
var usable = false;
session.keyStatuses.forEach(function () {
var keyStatus = parseKeyStatus(arguments);
if (keyStatus.status === 'usable') {
usable = true;
}
});
return usable;
}
}; // Add all event listeners
session.addEventListener('keystatuseschange', token);
session.addEventListener('message', token); // Register callback for session closed Promise
session.closed.then(function () {
removeSession(token);
logger.debug('DRM: Session closed. SessionID = ' + token.getSessionId());
eventBus.trigger(events.KEY_SESSION_CLOSED, {
data: token.getSessionId()
});
}); // Add to our session list
sessions.push(token);
return token;
}
instance = {
getAllInitData: getAllInitData,
getSessions: getSessions,
requestKeySystemAccess: requestKeySystemAccess,
selectKeySystem: selectKeySystem,
setMediaElement: setMediaElement,
setServerCertificate: setServerCertificate,
createKeySession: createKeySession,
updateKeySession: updateKeySession,
loadKeySession: loadKeySession,
removeKeySession: removeKeySession,
closeKeySession: closeKeySession,
stop: stop,
reset: reset
};
setup();
return instance;
}
ProtectionModel_21Jan2015.__dashjs_factory_name = 'ProtectionModel_21Jan2015';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(ProtectionModel_21Jan2015));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/models/ProtectionModel_3Feb2014.js":
/*!*********************************************************************!*\
!*** ./src/streaming/protection/models/ProtectionModel_3Feb2014.js ***!
\*********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../controllers/ProtectionKeyController */ "./src/streaming/protection/controllers/ProtectionKeyController.js");
/* harmony import */ var _vo_NeedKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/NeedKey */ "./src/streaming/protection/vo/NeedKey.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../errors/ProtectionErrors */ "./src/streaming/protection/errors/ProtectionErrors.js");
/* harmony import */ var _vo_KeyMessage__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/KeyMessage */ "./src/streaming/protection/vo/KeyMessage.js");
/* harmony import */ var _vo_KeySystemConfiguration__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/KeySystemConfiguration */ "./src/streaming/protection/vo/KeySystemConfiguration.js");
/* harmony import */ var _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../vo/KeySystemAccess */ "./src/streaming/protection/vo/KeySystemAccess.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Implementation of the EME APIs as of the 3 Feb 2014 state of the specification.
*
* Implemented by Internet Explorer 11 (Windows 8.1)
*
* @implements ProtectionModel
* @class
*/
function ProtectionModel_3Feb2014(config) {
config = config || {};
var context = this.context;
var eventBus = config.eventBus; //Need to pass in here so we can use same instance since this is optional module
var events = config.events;
var debug = config.debug;
var api = config.api;
var instance, logger, videoElement, keySystem, mediaKeys, keySystemAccess, sessions, eventHandler, protectionKeyController;
function setup() {
logger = debug.getLogger(instance);
videoElement = null;
keySystem = null;
mediaKeys = null;
keySystemAccess = null;
sessions = [];
protectionKeyController = Object(_controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
eventHandler = createEventHandler();
}
function reset() {
try {
for (var i = 0; i < sessions.length; i++) {
closeKeySession(sessions[i]);
}
if (videoElement) {
videoElement.removeEventListener(api.needkey, eventHandler);
}
eventBus.trigger(events.TEARDOWN_COMPLETE);
} catch (error) {
eventBus.trigger(events.TEARDOWN_COMPLETE, {
error: 'Error tearing down key sessions and MediaKeys! -- ' + error.message
});
}
}
function getAllInitData() {
var retVal = [];
for (var i = 0; i < sessions.length; i++) {
retVal.push(sessions[i].initData);
}
return retVal;
}
function getSessions() {
return sessions;
}
function requestKeySystemAccess(ksConfigurations) {
return new Promise(function (resolve, reject) {
// Try key systems in order, first one with supported key system configuration
// is used
var found = false;
for (var ksIdx = 0; ksIdx < ksConfigurations.length; ksIdx++) {
var systemString = ksConfigurations[ksIdx].ks.systemString;
var configs = ksConfigurations[ksIdx].configs;
var supportedAudio = null;
var supportedVideo = null; // Try key system configs in order, first one with supported audio/video
// is used
for (var configIdx = 0; configIdx < configs.length; configIdx++) {
var audios = configs[configIdx].audioCapabilities;
var videos = configs[configIdx].videoCapabilities; // Look for supported audio container/codecs
if (audios && audios.length !== 0) {
supportedAudio = []; // Indicates that we have a requested audio config
for (var audioIdx = 0; audioIdx < audios.length; audioIdx++) {
if (window[api.MediaKeys].isTypeSupported(systemString, audios[audioIdx].contentType)) {
supportedAudio.push(audios[audioIdx]);
}
}
} // Look for supported video container/codecs
if (videos && videos.length !== 0) {
supportedVideo = []; // Indicates that we have a requested video config
for (var videoIdx = 0; videoIdx < videos.length; videoIdx++) {
if (window[api.MediaKeys].isTypeSupported(systemString, videos[videoIdx].contentType)) {
supportedVideo.push(videos[videoIdx]);
}
}
} // No supported audio or video in this configuration OR we have
// requested audio or video configuration that is not supported
if (!supportedAudio && !supportedVideo || supportedAudio && supportedAudio.length === 0 || supportedVideo && supportedVideo.length === 0) {
continue;
} // This configuration is supported
found = true;
var ksConfig = new _vo_KeySystemConfiguration__WEBPACK_IMPORTED_MODULE_5__["default"](supportedAudio, supportedVideo);
var ks = protectionKeyController.getKeySystemBySystemString(systemString);
var _keySystemAccess = new _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_6__["default"](ks, ksConfig);
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
data: _keySystemAccess
});
resolve({
data: _keySystemAccess
});
break;
}
}
if (!found) {
var errorMessage = 'Key system access denied! -- No valid audio/video content configurations detected!';
eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
error: errorMessage
});
reject({
error: errorMessage
});
}
});
}
function selectKeySystem(ksAccess) {
return new Promise(function (resolve, reject) {
try {
mediaKeys = ksAccess.mediaKeys = new window[api.MediaKeys](ksAccess.keySystem.systemString);
keySystem = ksAccess.keySystem;
keySystemAccess = ksAccess;
if (videoElement) {
setMediaKeys();
}
resolve(keySystem);
} catch (error) {
reject({
error: 'Error selecting keys system (' + keySystem.systemString + ')! Could not create MediaKeys -- TODO'
});
}
});
}
function setMediaElement(mediaElement) {
if (videoElement === mediaElement) return; // Replacing the previous element
if (videoElement) {
videoElement.removeEventListener(api.needkey, eventHandler);
}
videoElement = mediaElement; // Only if we are not detaching from the existing element
if (videoElement) {
videoElement.addEventListener(api.needkey, eventHandler);
if (mediaKeys) {
setMediaKeys();
}
}
}
function createKeySession(ksInfo) {
if (!keySystem || !mediaKeys || !keySystemAccess) {
throw new Error('Can not create sessions until you have selected a key system');
} // Use the first video capability for the contentType.
// TODO: Not sure if there is a way to concatenate all capability data into a RFC6386-compatible format
// If player is trying to playback Audio only stream - don't error out.
var capabilities = null;
if (keySystemAccess.ksConfiguration.videoCapabilities && keySystemAccess.ksConfiguration.videoCapabilities.length > 0) {
capabilities = keySystemAccess.ksConfiguration.videoCapabilities[0];
}
if (capabilities === null && keySystemAccess.ksConfiguration.audioCapabilities && keySystemAccess.ksConfiguration.audioCapabilities.length > 0) {
capabilities = keySystemAccess.ksConfiguration.audioCapabilities[0];
}
if (capabilities === null) {
throw new Error('Can not create sessions for unknown content types.');
}
var contentType = capabilities.contentType;
var session = mediaKeys.createSession(contentType, new Uint8Array(ksInfo.initData), ksInfo.cdmData ? new Uint8Array(ksInfo.cdmData) : null);
var sessionToken = createSessionToken(session, ksInfo); // Add all event listeners
session.addEventListener(api.error, sessionToken);
session.addEventListener(api.message, sessionToken);
session.addEventListener(api.ready, sessionToken);
session.addEventListener(api.close, sessionToken); // Add to our session list
sessions.push(sessionToken);
logger.debug('DRM: Session created. SessionID = ' + sessionToken.getSessionId());
eventBus.trigger(events.KEY_SESSION_CREATED, {
data: sessionToken
});
}
function updateKeySession(sessionToken, message) {
var session = sessionToken.session;
if (!protectionKeyController.isClearKey(keySystem)) {
// Send our request to the key session
session.update(new Uint8Array(message));
} else {
// For clearkey, message is a ClearKeyKeySet
session.update(new Uint8Array(message.toJWK()));
}
eventBus.trigger(events.KEY_SESSION_UPDATED);
}
/**
* Close the given session and release all associated keys. Following
* this call, the sessionToken becomes invalid
*
* @param {Object} sessionToken - the session token
*/
function closeKeySession(sessionToken) {
var session = sessionToken.session; // Remove event listeners
session.removeEventListener(api.error, sessionToken);
session.removeEventListener(api.message, sessionToken);
session.removeEventListener(api.ready, sessionToken);
session.removeEventListener(api.close, sessionToken); // Remove from our session list
for (var i = 0; i < sessions.length; i++) {
if (sessions[i] === sessionToken) {
sessions.splice(i, 1);
break;
}
} // Send our request to the key session
session[api.release]();
}
function setServerCertificate()
/*serverCertificate*/
{
/* Not supported */
}
function loadKeySession()
/*ksInfo*/
{
/* Not supported */
}
function removeKeySession()
/*sessionToken*/
{
/* Not supported */
}
function createEventHandler() {
return {
handleEvent: function handleEvent(event) {
switch (event.type) {
case api.needkey:
if (event.initData) {
var initData = ArrayBuffer.isView(event.initData) ? event.initData.buffer : event.initData;
eventBus.trigger(events.NEED_KEY, {
key: new _vo_NeedKey__WEBPACK_IMPORTED_MODULE_1__["default"](initData, 'cenc')
});
}
break;
}
}
};
} // IE11 does not let you set MediaKeys until it has entered a certain
// readyState, so we need this logic to ensure we don't set the keys
// too early
function setMediaKeys() {
var boundDoSetKeys = null;
var doSetKeys = function doSetKeys() {
videoElement.removeEventListener('loadedmetadata', boundDoSetKeys);
videoElement[api.setMediaKeys](mediaKeys);
eventBus.trigger(events.VIDEO_ELEMENT_SELECTED);
};
if (videoElement.readyState >= 1) {
doSetKeys();
} else {
boundDoSetKeys = doSetKeys.bind(this);
videoElement.addEventListener('loadedmetadata', boundDoSetKeys);
}
} // Function to create our session token objects which manage the EME
// MediaKeySession and session-specific event handler
function createSessionToken(keySession, ksInfo) {
return {
// Implements SessionToken
session: keySession,
keyId: ksInfo.keyId,
initData: ksInfo.initData,
getKeyId: function getKeyId() {
return this.keyId;
},
getSessionId: function getSessionId() {
return this.session.sessionId;
},
getExpirationTime: function getExpirationTime() {
return NaN;
},
getSessionType: function getSessionType() {
return 'temporary';
},
// This is our main event handler for all desired MediaKeySession events
// These events are translated into our API-independent versions of the
// same events
handleEvent: function handleEvent(event) {
switch (event.type) {
case api.error:
var errorStr = 'KeyError'; // TODO: Make better string from event
eventBus.trigger(events.KEY_ERROR, {
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_2__["default"](_errors_ProtectionErrors__WEBPACK_IMPORTED_MODULE_3__["default"].MEDIA_KEYERR_CODE, errorStr, this)
});
break;
case api.message:
var message = ArrayBuffer.isView(event.message) ? event.message.buffer : event.message;
eventBus.trigger(events.INTERNAL_KEY_MESSAGE, {
data: new _vo_KeyMessage__WEBPACK_IMPORTED_MODULE_4__["default"](this, message, event.destinationURL)
});
break;
case api.ready:
logger.debug('DRM: Key added.');
eventBus.trigger(events.KEY_ADDED);
break;
case api.close:
logger.debug('DRM: Session closed. SessionID = ' + this.getSessionId());
eventBus.trigger(events.KEY_SESSION_CLOSED, {
data: this.getSessionId()
});
break;
}
}
};
}
instance = {
getAllInitData: getAllInitData,
getSessions: getSessions,
requestKeySystemAccess: requestKeySystemAccess,
selectKeySystem: selectKeySystem,
setMediaElement: setMediaElement,
createKeySession: createKeySession,
updateKeySession: updateKeySession,
closeKeySession: closeKeySession,
setServerCertificate: setServerCertificate,
loadKeySession: loadKeySession,
removeKeySession: removeKeySession,
stop: reset,
reset: reset
};
setup();
return instance;
}
ProtectionModel_3Feb2014.__dashjs_factory_name = 'ProtectionModel_3Feb2014';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getClassFactory(ProtectionModel_3Feb2014));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/servers/ClearKey.js":
/*!******************************************************!*\
!*** ./src/streaming/protection/servers/ClearKey.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_KeyPair__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/KeyPair */ "./src/streaming/protection/vo/KeyPair.js");
/* harmony import */ var _vo_ClearKeyKeySet__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/ClearKeyKeySet */ "./src/streaming/protection/vo/ClearKeyKeySet.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* CableLabs ClearKey license server implementation
*
* For testing purposes and evaluating potential uses for ClearKey, we have developed
* a dirt-simple API for requesting ClearKey licenses from a remote server.
*
* @implements LicenseServer
* @class
*/
function ClearKey() {
var instance;
function getServerURLFromMessage(url
/* message, messageType*/
) {
return url;
}
function getHTTPMethod()
/*messageType*/
{
return 'POST';
}
function getResponseType()
/*keySystemStr*/
{
return 'json';
}
function getLicenseMessage(serverResponse
/*, keySystemStr, messageType*/
) {
if (!serverResponse.hasOwnProperty('keys')) {
return null;
}
var keyPairs = [];
for (var i = 0; i < serverResponse.keys.length; i++) {
var keypair = serverResponse.keys[i];
var keyid = keypair.kid.replace(/=/g, '');
var key = keypair.k.replace(/=/g, '');
keyPairs.push(new _vo_KeyPair__WEBPACK_IMPORTED_MODULE_0__["default"](keyid, key));
}
return new _vo_ClearKeyKeySet__WEBPACK_IMPORTED_MODULE_1__["default"](keyPairs);
}
function getErrorResponse(serverResponse
/*, keySystemStr, messageType*/
) {
return String.fromCharCode.apply(null, new Uint8Array(serverResponse));
}
instance = {
getServerURLFromMessage: getServerURLFromMessage,
getHTTPMethod: getHTTPMethod,
getResponseType: getResponseType,
getLicenseMessage: getLicenseMessage,
getErrorResponse: getErrorResponse
};
return instance;
}
ClearKey.__dashjs_factory_name = 'ClearKey';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(ClearKey));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/servers/DRMToday.js":
/*!******************************************************!*\
!*** ./src/streaming/protection/servers/DRMToday.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../constants/ProtectionConstants */ "./src/streaming/constants/ProtectionConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* CastLabs DRMToday License Server implementation
*
* @implements LicenseServer
* @class
*/
function DRMToday(config) {
config = config || {};
var BASE64 = config.BASE64;
var keySystems = {};
keySystems[_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_0__["default"].WIDEVINE_KEYSTEM_STRING] = {
responseType: 'json',
getLicenseMessage: function getLicenseMessage(response) {
return BASE64.decodeArray(response.license);
},
getErrorResponse: function getErrorResponse(response) {
return response;
}
};
keySystems[_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_0__["default"].PLAYREADY_KEYSTEM_STRING] = {
responseType: 'arraybuffer',
getLicenseMessage: function getLicenseMessage(response) {
return response;
},
getErrorResponse: function getErrorResponse(response) {
return String.fromCharCode.apply(null, new Uint8Array(response));
}
};
var instance;
function checkConfig() {
if (!BASE64 || !BASE64.hasOwnProperty('decodeArray')) {
throw new Error('Missing config parameter(s)');
}
}
function getServerURLFromMessage(url
/*, message, messageType*/
) {
return url;
}
function getHTTPMethod()
/*messageType*/
{
return 'POST';
}
function getResponseType(keySystemStr
/*, messageType*/
) {
return keySystems[keySystemStr].responseType;
}
function getLicenseMessage(serverResponse, keySystemStr
/*, messageType*/
) {
checkConfig();
return keySystems[keySystemStr].getLicenseMessage(serverResponse);
}
function getErrorResponse(serverResponse, keySystemStr
/*, messageType*/
) {
return keySystems[keySystemStr].getErrorResponse(serverResponse);
}
instance = {
getServerURLFromMessage: getServerURLFromMessage,
getHTTPMethod: getHTTPMethod,
getResponseType: getResponseType,
getLicenseMessage: getLicenseMessage,
getErrorResponse: getErrorResponse
};
return instance;
}
DRMToday.__dashjs_factory_name = 'DRMToday';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(DRMToday));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/servers/PlayReady.js":
/*!*******************************************************!*\
!*** ./src/streaming/protection/servers/PlayReady.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* global escape: true */
/**
* Microsoft PlayReady Test License Server
*
* For testing content that uses the PlayReady test server at
*
* @implements LicenseServer
* @class
* @ignore
*/
function PlayReady() {
var instance;
var soap = 'http://schemas.xmlsoap.org/soap/envelope/';
function uintToString(arrayBuffer) {
var encodedString = String.fromCharCode.apply(null, new Uint8Array(arrayBuffer));
var decodedString = decodeURIComponent(escape(encodedString));
return decodedString;
}
function parseServerResponse(serverResponse) {
if (window.DOMParser) {
var stringResponse = uintToString(serverResponse);
var parser = new window.DOMParser();
var xmlDoc = parser.parseFromString(stringResponse, 'text/xml');
var envelope = xmlDoc ? xmlDoc.getElementsByTagNameNS(soap, 'Envelope')[0] : null;
var body = envelope ? envelope.getElementsByTagNameNS(soap, 'Body')[0] : null;
var fault = body ? body.getElementsByTagNameNS(soap, 'Fault')[0] : null;
if (fault) {
return null;
}
}
return serverResponse;
}
function parseErrorResponse(serverResponse) {
var faultstring = '';
var statusCode = '';
var message = '';
var idStart = -1;
var idEnd = -1;
if (window.DOMParser) {
var stringResponse = uintToString(serverResponse);
var parser = new window.DOMParser();
var xmlDoc = parser.parseFromString(stringResponse, 'text/xml');
var envelope = xmlDoc ? xmlDoc.getElementsByTagNameNS(soap, 'Envelope')[0] : null;
var body = envelope ? envelope.getElementsByTagNameNS(soap, 'Body')[0] : null;
var fault = body ? body.getElementsByTagNameNS(soap, 'Fault')[0] : null;
var detail = fault ? fault.getElementsByTagName('detail')[0] : null;
var exception = detail ? detail.getElementsByTagName('Exception')[0] : null;
var node = null;
if (fault === null) {
return stringResponse;
}
node = fault.getElementsByTagName('faultstring')[0].firstChild;
faultstring = node ? node.nodeValue : null;
if (exception !== null) {
node = exception.getElementsByTagName('StatusCode')[0];
statusCode = node ? node.firstChild.nodeValue : null;
node = exception.getElementsByTagName('Message')[0];
message = node ? node.firstChild.nodeValue : null;
idStart = message ? message.lastIndexOf('[') + 1 : -1;
idEnd = message ? message.indexOf(']') : -1;
message = message ? message.substring(idStart, idEnd) : '';
}
}
var errorString = "code: ".concat(statusCode, ", name: ").concat(faultstring);
if (message) {
errorString += ", message: ".concat(message);
}
return errorString;
}
function getServerURLFromMessage(url
/*, message, messageType*/
) {
return url;
}
function getHTTPMethod()
/*messageType*/
{
return 'POST';
}
function getResponseType()
/*keySystemStr, messageType*/
{
return 'arraybuffer';
}
function getLicenseMessage(serverResponse
/*, keySystemStr, messageType*/
) {
return parseServerResponse.call(this, serverResponse);
}
function getErrorResponse(serverResponse
/*, keySystemStr, messageType*/
) {
return parseErrorResponse.call(this, serverResponse);
}
instance = {
getServerURLFromMessage: getServerURLFromMessage,
getHTTPMethod: getHTTPMethod,
getResponseType: getResponseType,
getLicenseMessage: getLicenseMessage,
getErrorResponse: getErrorResponse
};
return instance;
}
PlayReady.__dashjs_factory_name = 'PlayReady';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(PlayReady));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/servers/Widevine.js":
/*!******************************************************!*\
!*** ./src/streaming/protection/servers/Widevine.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @ignore
*/
function Widevine() {
var instance;
function getServerURLFromMessage(url
/*, message, messageType*/
) {
return url;
}
function getHTTPMethod()
/*messageType*/
{
return 'POST';
}
function getResponseType()
/*keySystemStr, messageType*/
{
return 'arraybuffer';
}
function getLicenseMessage(serverResponse
/*, keySystemStr, messageType*/
) {
return serverResponse;
}
function getErrorResponse(serverResponse
/*, keySystemStr, messageType*/
) {
return String.fromCharCode.apply(null, new Uint8Array(serverResponse));
}
instance = {
getServerURLFromMessage: getServerURLFromMessage,
getHTTPMethod: getHTTPMethod,
getResponseType: getResponseType,
getLicenseMessage: getLicenseMessage,
getErrorResponse: getErrorResponse
};
return instance;
}
Widevine.__dashjs_factory_name = 'Widevine';
/* harmony default export */ __webpack_exports__["default"] = (dashjs.FactoryMaker.getSingletonFactory(Widevine));
/* jshint ignore:line */
/***/ }),
/***/ "./src/streaming/protection/vo/ClearKeyKeySet.js":
/*!*******************************************************!*\
!*** ./src/streaming/protection/vo/ClearKeyKeySet.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc A collection of ClearKey encryption keys with an (optional) associated
* type
* @ignore
*/
var ClearKeyKeySet = /*#__PURE__*/function () {
/**
* @param {Array.<KeyPair>} keyPairs
* @param {string} type the type of keys in this set. One of either 'persistent'
* or 'temporary'. Can also be null or undefined.
* @class
* @ignore
*/
function ClearKeyKeySet(keyPairs, type) {
_classCallCheck(this, ClearKeyKeySet);
if (type && type !== 'persistent' && type !== 'temporary') throw new Error('Invalid ClearKey key set type! Must be one of \'persistent\' or \'temporary\'');
this.keyPairs = keyPairs;
this.type = type;
}
/**
* Convert this key set to its JSON Web Key (JWK) representation
*
* @return {ArrayBuffer} JWK object UTF-8 encoded as ArrayBuffer
*/
_createClass(ClearKeyKeySet, [{
key: "toJWK",
value: function toJWK() {
var i;
var numKeys = this.keyPairs.length;
var jwk = {
keys: []
};
for (i = 0; i < numKeys; i++) {
var key = {
kty: 'oct',
alg: 'A128KW',
kid: this.keyPairs[i].keyID,
k: this.keyPairs[i].key
};
jwk.keys.push(key);
}
if (this.type) {
jwk.type = this.type;
}
var jwkString = JSON.stringify(jwk);
var len = jwkString.length; // Convert JSON string to ArrayBuffer
var buf = new ArrayBuffer(len);
var bView = new Uint8Array(buf);
for (i = 0; i < len; i++) {
bView[i] = jwkString.charCodeAt(i);
}
return buf;
}
}]);
return ClearKeyKeySet;
}();
/* harmony default export */ __webpack_exports__["default"] = (ClearKeyKeySet);
/***/ }),
/***/ "./src/streaming/protection/vo/KeyMessage.js":
/*!***************************************************!*\
!*** ./src/streaming/protection/vo/KeyMessage.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc EME-independent KeyMessage
* @ignore
*/
var KeyMessage =
/**
* @param {SessionToken} sessionToken the session
* to which the key message is associated
* @param {ArrayBuffer} message the key message
* @param {string} defaultURL license acquisition URL provided by the CDM
* @param {string} messageType Supported message types can be found
* {@link https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType|here}.
* @class
*/
function KeyMessage(sessionToken, message, defaultURL, messageType) {
_classCallCheck(this, KeyMessage);
this.sessionToken = sessionToken;
this.message = message;
this.defaultURL = defaultURL;
this.messageType = messageType ? messageType : 'license-request';
};
/* harmony default export */ __webpack_exports__["default"] = (KeyMessage);
/***/ }),
/***/ "./src/streaming/protection/vo/KeyPair.js":
/*!************************************************!*\
!*** ./src/streaming/protection/vo/KeyPair.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Represents a 128-bit keyID and 128-bit encryption key
* @ignore
*/
var KeyPair =
/**
* @param {string} keyID 128-bit key ID, base64 encoded, with no padding
* @param {string} key 128-bit encryption key, base64 encoded, with no padding
* @class
* @ignore
*/
function KeyPair(keyID, key) {
_classCallCheck(this, KeyPair);
this.keyID = keyID;
this.key = key;
};
/* harmony default export */ __webpack_exports__["default"] = (KeyPair);
/***/ }),
/***/ "./src/streaming/protection/vo/KeySystemAccess.js":
/*!********************************************************!*\
!*** ./src/streaming/protection/vo/KeySystemAccess.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Creates a new key system access token. Represents a valid key system for
* given piece of content and key system requirements. Used to initialize license
* acquisition operations.
* @ignore
*/
var KeySystemAccess =
/**
* @param {MediaPlayer.dependencies.protection.KeySystem} keySystem the key system
* @param {KeySystemConfiguration} ksConfiguration the
* subset of configurations passed to the key system access request that are supported
* by this user agent
* @class
* @ignore
*/
function KeySystemAccess(keySystem, ksConfiguration) {
_classCallCheck(this, KeySystemAccess);
this.keySystem = keySystem;
this.ksConfiguration = ksConfiguration;
};
/* harmony default export */ __webpack_exports__["default"] = (KeySystemAccess);
/***/ }),
/***/ "./src/streaming/protection/vo/KeySystemConfiguration.js":
/*!***************************************************************!*\
!*** ./src/streaming/protection/vo/KeySystemConfiguration.js ***!
\***************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Represents a set of configurations that describe the capabilities desired for
* support by a given CDM
* @ignore
*/
var KeySystemConfiguration =
/**
* @param {Array.<MediaCapability>} audioCapabilities array of
* desired audio capabilities. Higher preference capabilities should be placed earlier
* in the array.
* @param {Array.<MediaCapability>} videoCapabilities array of
* desired video capabilities. Higher preference capabilities should be placed earlier
* in the array.
* @param {string} distinctiveIdentifier desired use of distinctive identifiers.
* One of "required", "optional", or "not-allowed"
* @param {string} persistentState desired support for persistent storage of
* key systems. One of "required", "optional", or "not-allowed"
* @param {Array.<string>} sessionTypes List of session types that must
* be supported by the key system
* @class
*/
function KeySystemConfiguration(audioCapabilities, videoCapabilities, distinctiveIdentifier, persistentState, sessionTypes) {
_classCallCheck(this, KeySystemConfiguration);
this.initDataTypes = ['cenc'];
if (audioCapabilities && audioCapabilities.length) {
this.audioCapabilities = audioCapabilities;
}
if (videoCapabilities && videoCapabilities.length) {
this.videoCapabilities = videoCapabilities;
}
this.distinctiveIdentifier = distinctiveIdentifier;
this.persistentState = persistentState;
this.sessionTypes = sessionTypes;
};
/* harmony default export */ __webpack_exports__["default"] = (KeySystemConfiguration);
/***/ }),
/***/ "./src/streaming/protection/vo/LicenseRequest.js":
/*!*******************************************************!*\
!*** ./src/streaming/protection/vo/LicenseRequest.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Defines a license request
* @ignore
*/
var LicenseRequest =
/**
* Defines a license request
*
* @class
*/
function LicenseRequest(url, method, responseType, headers, withCredentials, messageType, sessionId, data) {
_classCallCheck(this, LicenseRequest);
/**
* The license request url
*/
this.url = url;
/**
* The HTTP method
*/
this.method = method;
/**
* The HTTP response type
*/
this.responseType = responseType;
/**
* The HTP request headers
*/
this.headers = headers;
/**
* Wether request is done using credentials (cross-site cookies)
*/
this.withCredentials = withCredentials;
/**
* The license request message type (see https://www.w3.org/TR/encrypted-media/#dom-mediakeymessagetype)
*/
this.messageType = messageType;
/**
* The corresponding EME session ID
*/
this.sessionId = sessionId;
/**
* The license request data
*/
this.data = data;
};
/* harmony default export */ __webpack_exports__["default"] = (LicenseRequest);
/***/ }),
/***/ "./src/streaming/protection/vo/LicenseResponse.js":
/*!********************************************************!*\
!*** ./src/streaming/protection/vo/LicenseResponse.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc Defines a license response
*/
var LicenseResponse =
/**
* Defines a license request
*
* @class
* @ignore
*/
function LicenseResponse(url, headers, data) {
_classCallCheck(this, LicenseResponse);
/**
* The url that was loaded, that can be redirected from original request url
*/
this.url = url;
/**
* The HTP response headers
*/
this.headers = headers;
/**
* The license response data
*/
this.data = data;
};
/* harmony default export */ __webpack_exports__["default"] = (LicenseResponse);
/***/ }),
/***/ "./src/streaming/protection/vo/MediaCapability.js":
/*!********************************************************!*\
!*** ./src/streaming/protection/vo/MediaCapability.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc A media capability
* @ignore
*/
var MediaCapability =
/**
* @param {string} contentType MIME type and codecs (RFC6386)
* @param {string} robustness
* @class
* @ignore
*/
function MediaCapability(contentType, robustness) {
_classCallCheck(this, MediaCapability);
this.contentType = contentType;
this.robustness = robustness;
};
/* harmony default export */ __webpack_exports__["default"] = (MediaCapability);
/***/ }),
/***/ "./src/streaming/protection/vo/NeedKey.js":
/*!************************************************!*\
!*** ./src/streaming/protection/vo/NeedKey.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc NeedKey
* @ignore
*/
var NeedKey =
/**
* @param {ArrayBuffer} initData the initialization data
* @param {string} initDataType initialization data type
* @class
*/
function NeedKey(initData, initDataType) {
_classCallCheck(this, NeedKey);
this.initData = initData;
this.initDataType = initDataType;
};
/* harmony default export */ __webpack_exports__["default"] = (NeedKey);
/***/ }),
/***/ "./src/streaming/rules/DroppedFramesHistory.js":
/*!*****************************************************!*\
!*** ./src/streaming/rules/DroppedFramesHistory.js ***!
\*****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
function DroppedFramesHistory() {
var values = {};
var lastDroppedFrames = {};
var lastTotalFrames = {};
function push(streamId, index, playbackQuality) {
if (!index) {
return;
}
if (!values[streamId]) {
values[streamId] = [];
lastDroppedFrames[streamId] = 0;
lastTotalFrames[streamId] = 0;
}
var droppedVideoFrames = playbackQuality && playbackQuality.droppedVideoFrames ? playbackQuality.droppedVideoFrames : 0;
var totalVideoFrames = playbackQuality && playbackQuality.totalVideoFrames ? playbackQuality.totalVideoFrames : 0;
var intervalDroppedFrames = droppedVideoFrames - lastDroppedFrames;
lastDroppedFrames[streamId] = droppedVideoFrames;
var intervalTotalFrames = totalVideoFrames - lastTotalFrames;
lastTotalFrames[streamId] = totalVideoFrames;
var current = values[streamId];
if (!isNaN(index)) {
if (!current[index]) {
current[index] = {
droppedVideoFrames: intervalDroppedFrames,
totalVideoFrames: intervalTotalFrames
};
} else {
current[index].droppedVideoFrames += intervalDroppedFrames;
current[index].totalVideoFrames += intervalTotalFrames;
}
}
}
function getFrameHistory(streamId) {
return values[streamId];
}
function clearForStream(streamId) {
try {
delete values[streamId];
delete lastDroppedFrames[streamId];
delete lastTotalFrames[streamId];
} catch (e) {}
}
function reset() {
values = {};
lastDroppedFrames = {};
lastTotalFrames = {};
}
return {
push: push,
getFrameHistory: getFrameHistory,
clearForStream: clearForStream,
reset: reset
};
}
DroppedFramesHistory.__dashjs_factory_name = 'DroppedFramesHistory';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(DroppedFramesHistory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/rules/RulesContext.js":
/*!*********************************************!*\
!*** ./src/streaming/rules/RulesContext.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function RulesContext(config) {
config = config || {};
var instance;
var abrController = config.abrController;
var switchHistory = config.switchHistory;
var droppedFramesHistory = config.droppedFramesHistory;
var currentRequest = config.currentRequest;
var bufferOccupancyABR = config.useBufferOccupancyABR;
var l2AABR = config.useL2AABR;
var loLP = config.useLoLPABR;
var scheduleController = config.streamProcessor ? config.streamProcessor.getScheduleController() : null;
var representationInfo = config.streamProcessor ? config.streamProcessor.getRepresentationInfo() : null;
var videoModel = config.videoModel ? config.videoModel : null;
function getMediaType() {
var mediaInfo = getMediaInfo();
return mediaInfo ? mediaInfo.type : null;
}
function getStreamInfo() {
var mediaInfo = getMediaInfo();
return mediaInfo ? mediaInfo.streamInfo : null;
}
function getMediaInfo() {
return representationInfo ? representationInfo.mediaInfo : null;
}
function getRepresentationInfo() {
return representationInfo;
}
function getScheduleController() {
return scheduleController;
}
function getAbrController() {
return abrController;
}
function getSwitchHistory() {
return switchHistory;
}
function getVideoModel() {
return videoModel;
}
function getDroppedFramesHistory() {
return droppedFramesHistory;
}
function getCurrentRequest() {
return currentRequest;
}
function useBufferOccupancyABR() {
return bufferOccupancyABR;
}
function useL2AABR() {
return l2AABR;
}
function useLoLPABR() {
return loLP;
}
instance = {
getMediaType: getMediaType,
getMediaInfo: getMediaInfo,
getDroppedFramesHistory: getDroppedFramesHistory,
getCurrentRequest: getCurrentRequest,
getSwitchHistory: getSwitchHistory,
getStreamInfo: getStreamInfo,
getScheduleController: getScheduleController,
getAbrController: getAbrController,
getRepresentationInfo: getRepresentationInfo,
useBufferOccupancyABR: useBufferOccupancyABR,
useL2AABR: useL2AABR,
useLoLPABR: useLoLPABR,
getVideoModel: getVideoModel
};
return instance;
}
RulesContext.__dashjs_factory_name = 'RulesContext';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(RulesContext));
/***/ }),
/***/ "./src/streaming/rules/SwitchRequest.js":
/*!**********************************************!*\
!*** ./src/streaming/rules/SwitchRequest.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var NO_CHANGE = -1;
var PRIORITY = {
DEFAULT: 0.5,
STRONG: 1,
WEAK: 0
};
function SwitchRequest(q, r, p) {
//TODO refactor all the calls to this to use config to be like everything else.
var instance, quality, priority, reason; // check priority value
function getPriority(p) {
var ret = PRIORITY.DEFAULT; // check that p is one of declared priority value
if (p === PRIORITY.DEFAULT || p === PRIORITY.STRONG || p === PRIORITY.WEAK) {
ret = p;
}
return ret;
} // init attributes
quality = q === undefined ? NO_CHANGE : q;
priority = getPriority(p);
reason = r === undefined ? null : r;
instance = {
quality: quality,
reason: reason,
priority: priority
};
return instance;
}
SwitchRequest.__dashjs_factory_name = 'SwitchRequest';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(SwitchRequest);
factory.NO_CHANGE = NO_CHANGE;
factory.PRIORITY = PRIORITY;
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].updateClassFactory(SwitchRequest.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/rules/SwitchRequestHistory.js":
/*!*****************************************************!*\
!*** ./src/streaming/rules/SwitchRequestHistory.js ***!
\*****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var SWITCH_REQUEST_HISTORY_DEPTH = 8; // must be > SwitchHistoryRule SAMPLE_SIZE to enable rule
function SwitchRequestHistory() {
var switchRequests = []; // running total
var srHistory = []; // history of each switch
function push(switchRequest) {
if (switchRequest.newValue === _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"].NO_CHANGE) {
switchRequest.newValue = switchRequest.oldValue;
}
if (!switchRequests[switchRequest.oldValue]) {
switchRequests[switchRequest.oldValue] = {
noDrops: 0,
drops: 0,
dropSize: 0
};
} // Set switch details
var indexDiff = switchRequest.newValue - switchRequest.oldValue;
var drop = indexDiff < 0 ? 1 : 0;
var dropSize = drop ? -indexDiff : 0;
var noDrop = drop ? 0 : 1; // Update running totals
switchRequests[switchRequest.oldValue].drops += drop;
switchRequests[switchRequest.oldValue].dropSize += dropSize;
switchRequests[switchRequest.oldValue].noDrops += noDrop; // Save to history
srHistory.push({
idx: switchRequest.oldValue,
noDrop: noDrop,
drop: drop,
dropSize: dropSize
}); // Shift earliest switch off srHistory and readjust to keep depth of running totals constant
if (srHistory.length > SWITCH_REQUEST_HISTORY_DEPTH) {
var srHistoryFirst = srHistory.shift();
switchRequests[srHistoryFirst.idx].drops -= srHistoryFirst.drop;
switchRequests[srHistoryFirst.idx].dropSize -= srHistoryFirst.dropSize;
switchRequests[srHistoryFirst.idx].noDrops -= srHistoryFirst.noDrop;
}
}
function getSwitchRequests() {
return switchRequests;
}
function reset() {
switchRequests = [];
srHistory = [];
}
return {
push: push,
getSwitchRequests: getSwitchRequests,
reset: reset
};
}
SwitchRequestHistory.__dashjs_factory_name = 'SwitchRequestHistory';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(SwitchRequestHistory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/rules/ThroughputHistory.js":
/*!**************************************************!*\
!*** ./src/streaming/rules/ThroughputHistory.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2017, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// throughput generally stored in kbit/s
// latency generally stored in ms
function ThroughputHistory(config) {
config = config || {}; // sliding window constants
var MAX_MEASUREMENTS_TO_KEEP = 20;
var AVERAGE_THROUGHPUT_SAMPLE_AMOUNT_LIVE = 3;
var AVERAGE_THROUGHPUT_SAMPLE_AMOUNT_VOD = 4;
var AVERAGE_LATENCY_SAMPLE_AMOUNT = 4;
var THROUGHPUT_DECREASE_SCALE = 1.3;
var THROUGHPUT_INCREASE_SCALE = 1.3; // EWMA constants
var EWMA_THROUGHPUT_SLOW_HALF_LIFE_SECONDS = 8;
var EWMA_THROUGHPUT_FAST_HALF_LIFE_SECONDS = 3;
var EWMA_LATENCY_SLOW_HALF_LIFE_COUNT = 2;
var EWMA_LATENCY_FAST_HALF_LIFE_COUNT = 1;
var settings = config.settings;
var throughputDict, latencyDict, ewmaThroughputDict, ewmaLatencyDict, ewmaHalfLife;
function setup() {
ewmaHalfLife = {
throughputHalfLife: {
fast: EWMA_THROUGHPUT_FAST_HALF_LIFE_SECONDS,
slow: EWMA_THROUGHPUT_SLOW_HALF_LIFE_SECONDS
},
latencyHalfLife: {
fast: EWMA_LATENCY_FAST_HALF_LIFE_COUNT,
slow: EWMA_LATENCY_SLOW_HALF_LIFE_COUNT
}
};
reset();
}
function isCachedResponse(mediaType, latencyMs, downloadTimeMs) {
if (mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) {
return downloadTimeMs < settings.get().streaming.cacheLoadThresholds[_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO];
} else if (mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO) {
return downloadTimeMs < settings.get().streaming.cacheLoadThresholds[_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO];
}
}
function push(mediaType, httpRequest, useDeadTimeLatency) {
if (!httpRequest.trace || !httpRequest.trace.length) {
return;
}
var latencyTimeInMilliseconds = httpRequest.tresponse.getTime() - httpRequest.trequest.getTime() || 1;
var downloadTimeInMilliseconds = httpRequest._tfinish.getTime() - httpRequest.tresponse.getTime() || 1; //Make sure never 0 we divide by this value. Avoid infinity!
var downloadBytes = httpRequest.trace.reduce(function (a, b) {
return a + b.b[0];
}, 0);
var throughputMeasureTime = 0,
throughput = 0;
if (settings.get().streaming.lowLatencyEnabled) {
var calculationMode = settings.get().streaming.abr.fetchThroughputCalculationMode;
if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING) {
var sumOfThroughputValues = httpRequest.trace.reduce(function (a, b) {
return a + b.t;
}, 0);
throughput = Math.round(sumOfThroughputValues / httpRequest.trace.length);
}
if (throughput === 0) {
throughputMeasureTime = httpRequest.trace.reduce(function (a, b) {
return a + b.d;
}, 0);
}
} else {
throughputMeasureTime = useDeadTimeLatency ? downloadTimeInMilliseconds : latencyTimeInMilliseconds + downloadTimeInMilliseconds;
}
if (throughputMeasureTime !== 0) {
throughput = Math.round(8 * downloadBytes / throughputMeasureTime); // bits/ms = kbits/s
}
checkSettingsForMediaType(mediaType);
if (isCachedResponse(mediaType, latencyTimeInMilliseconds, downloadTimeInMilliseconds)) {
if (throughputDict[mediaType].length > 0 && !throughputDict[mediaType].hasCachedEntries) {
// already have some entries which are not cached entries
// prevent cached fragment loads from skewing the average values
return;
} else {
// have no entries || have cached entries
// no uncached entries yet, rely on cached entries because ABR rules need something to go by
throughputDict[mediaType].hasCachedEntries = true;
}
} else if (throughputDict[mediaType] && throughputDict[mediaType].hasCachedEntries) {
// if we are here then we have some entries already, but they are cached, and now we have a new uncached entry
clearSettingsForMediaType(mediaType);
}
throughputDict[mediaType].push(throughput);
if (throughputDict[mediaType].length > MAX_MEASUREMENTS_TO_KEEP) {
throughputDict[mediaType].shift();
}
latencyDict[mediaType].push(latencyTimeInMilliseconds);
if (latencyDict[mediaType].length > MAX_MEASUREMENTS_TO_KEEP) {
latencyDict[mediaType].shift();
}
updateEwmaEstimate(ewmaThroughputDict[mediaType], throughput, 0.001 * downloadTimeInMilliseconds, ewmaHalfLife.throughputHalfLife);
updateEwmaEstimate(ewmaLatencyDict[mediaType], latencyTimeInMilliseconds, 1, ewmaHalfLife.latencyHalfLife);
}
function updateEwmaEstimate(ewmaObj, value, weight, halfLife) {
// Note about startup:
// Estimates start at 0, so early values are underestimated.
// This effect is countered in getAverageEwma() by dividing the estimates by:
// 1 - Math.pow(0.5, ewmaObj.totalWeight / halfLife)
var fastAlpha = Math.pow(0.5, weight / halfLife.fast);
ewmaObj.fastEstimate = (1 - fastAlpha) * value + fastAlpha * ewmaObj.fastEstimate;
var slowAlpha = Math.pow(0.5, weight / halfLife.slow);
ewmaObj.slowEstimate = (1 - slowAlpha) * value + slowAlpha * ewmaObj.slowEstimate;
ewmaObj.totalWeight += weight;
}
function getSampleSize(isThroughput, mediaType, isDynamic) {
var arr, sampleSize;
if (isThroughput) {
arr = throughputDict[mediaType];
sampleSize = isDynamic ? AVERAGE_THROUGHPUT_SAMPLE_AMOUNT_LIVE : AVERAGE_THROUGHPUT_SAMPLE_AMOUNT_VOD;
} else {
arr = latencyDict[mediaType];
sampleSize = AVERAGE_LATENCY_SAMPLE_AMOUNT;
}
if (!arr) {
sampleSize = 0;
} else if (sampleSize >= arr.length) {
sampleSize = arr.length;
} else if (isThroughput) {
// if throughput samples vary a lot, average over a wider sample
for (var i = 1; i < sampleSize; ++i) {
var ratio = arr[arr.length - i] / arr[arr.length - i - 1];
if (ratio >= THROUGHPUT_INCREASE_SCALE || ratio <= 1 / THROUGHPUT_DECREASE_SCALE) {
sampleSize += 1;
if (sampleSize === arr.length) {
// cannot increase sampleSize beyond arr.length
break;
}
}
}
}
return sampleSize;
}
function getAverage(isThroughput, mediaType, isDynamic) {
// only two moving average methods defined at the moment
return settings.get().streaming.abr.movingAverageMethod !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].MOVING_AVERAGE_SLIDING_WINDOW ? getAverageEwma(isThroughput, mediaType) : getAverageSlidingWindow(isThroughput, mediaType, isDynamic);
}
function getAverageSlidingWindow(isThroughput, mediaType, isDynamic) {
var sampleSize = getSampleSize(isThroughput, mediaType, isDynamic);
var dict = isThroughput ? throughputDict : latencyDict;
var arr = dict[mediaType];
if (sampleSize === 0 || !arr || arr.length === 0) {
return NaN;
}
arr = arr.slice(-sampleSize); // still works if sampleSize too large
// arr.length >= 1
return arr.reduce(function (total, elem) {
return total + elem;
}) / arr.length;
}
function getAverageEwma(isThroughput, mediaType) {
var halfLife = isThroughput ? ewmaHalfLife.throughputHalfLife : ewmaHalfLife.latencyHalfLife;
var ewmaObj = isThroughput ? ewmaThroughputDict[mediaType] : ewmaLatencyDict[mediaType];
if (!ewmaObj || ewmaObj.totalWeight <= 0) {
return NaN;
} // to correct for startup, divide by zero factor = 1 - Math.pow(0.5, ewmaObj.totalWeight / halfLife)
var fastEstimate = ewmaObj.fastEstimate / (1 - Math.pow(0.5, ewmaObj.totalWeight / halfLife.fast));
var slowEstimate = ewmaObj.slowEstimate / (1 - Math.pow(0.5, ewmaObj.totalWeight / halfLife.slow));
return isThroughput ? Math.min(fastEstimate, slowEstimate) : Math.max(fastEstimate, slowEstimate);
}
function getAverageThroughput(mediaType, isDynamic) {
return getAverage(true, mediaType, isDynamic);
}
function getSafeAverageThroughput(mediaType, isDynamic) {
var average = getAverageThroughput(mediaType, isDynamic);
if (!isNaN(average)) {
average *= settings.get().streaming.abr.bandwidthSafetyFactor;
}
return average;
}
function getAverageLatency(mediaType) {
return getAverage(false, mediaType);
}
function checkSettingsForMediaType(mediaType) {
throughputDict[mediaType] = throughputDict[mediaType] || [];
latencyDict[mediaType] = latencyDict[mediaType] || [];
ewmaThroughputDict[mediaType] = ewmaThroughputDict[mediaType] || {
fastEstimate: 0,
slowEstimate: 0,
totalWeight: 0
};
ewmaLatencyDict[mediaType] = ewmaLatencyDict[mediaType] || {
fastEstimate: 0,
slowEstimate: 0,
totalWeight: 0
};
}
function clearSettingsForMediaType(mediaType) {
delete throughputDict[mediaType];
delete latencyDict[mediaType];
delete ewmaThroughputDict[mediaType];
delete ewmaLatencyDict[mediaType];
checkSettingsForMediaType(mediaType);
}
function reset() {
throughputDict = {};
latencyDict = {};
ewmaThroughputDict = {};
ewmaLatencyDict = {};
}
var instance = {
push: push,
getAverageThroughput: getAverageThroughput,
getSafeAverageThroughput: getSafeAverageThroughput,
getAverageLatency: getAverageLatency,
reset: reset
};
setup();
return instance;
}
ThroughputHistory.__dashjs_factory_name = 'ThroughputHistory';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(ThroughputHistory));
/***/ }),
/***/ "./src/streaming/rules/abr/ABRRulesCollection.js":
/*!*******************************************************!*\
!*** ./src/streaming/rules/abr/ABRRulesCollection.js ***!
\*******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _ThroughputRule__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ThroughputRule */ "./src/streaming/rules/abr/ThroughputRule.js");
/* harmony import */ var _InsufficientBufferRule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./InsufficientBufferRule */ "./src/streaming/rules/abr/InsufficientBufferRule.js");
/* harmony import */ var _AbandonRequestsRule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./AbandonRequestsRule */ "./src/streaming/rules/abr/AbandonRequestsRule.js");
/* harmony import */ var _DroppedFramesRule__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./DroppedFramesRule */ "./src/streaming/rules/abr/DroppedFramesRule.js");
/* harmony import */ var _SwitchHistoryRule__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SwitchHistoryRule */ "./src/streaming/rules/abr/SwitchHistoryRule.js");
/* harmony import */ var _BolaRule__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./BolaRule */ "./src/streaming/rules/abr/BolaRule.js");
/* harmony import */ var _L2ARule_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./L2ARule.js */ "./src/streaming/rules/abr/L2ARule.js");
/* harmony import */ var _lolp_LoLpRule_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./lolp/LoLpRule.js */ "./src/streaming/rules/abr/lolp/LoLpRule.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var QUALITY_SWITCH_RULES = 'qualitySwitchRules';
var ABANDON_FRAGMENT_RULES = 'abandonFragmentRules';
function ABRRulesCollection(config) {
config = config || {};
var context = this.context;
var mediaPlayerModel = config.mediaPlayerModel;
var dashMetrics = config.dashMetrics;
var settings = config.settings;
var instance, qualitySwitchRules, abandonFragmentRules;
function initialize() {
qualitySwitchRules = [];
abandonFragmentRules = [];
if (settings.get().streaming.abr.useDefaultABRRules) {
// If L2A is used we only need this one rule
if (settings.get().streaming.abr.ABRStrategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_10__["default"].ABR_STRATEGY_L2A) {
qualitySwitchRules.push(Object(_L2ARule_js__WEBPACK_IMPORTED_MODULE_6__["default"])(context).create({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
settings: settings
}));
} // If LoLP is used we only need this one rule
else if (settings.get().streaming.abr.ABRStrategy === _constants_Constants__WEBPACK_IMPORTED_MODULE_10__["default"].ABR_STRATEGY_LoLP) {
qualitySwitchRules.push(Object(_lolp_LoLpRule_js__WEBPACK_IMPORTED_MODULE_7__["default"])(context).create({
dashMetrics: dashMetrics
}));
} else {
// Only one of BolaRule and ThroughputRule will give a switchRequest.quality !== SwitchRequest.NO_CHANGE.
// This is controlled by useBufferOccupancyABR mechanism in AbrController.
qualitySwitchRules.push(Object(_BolaRule__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
settings: settings
}));
qualitySwitchRules.push(Object(_ThroughputRule__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
dashMetrics: dashMetrics
}));
if (settings.get().streaming.abr.additionalAbrRules.insufficientBufferRule) {
qualitySwitchRules.push(Object(_InsufficientBufferRule__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
dashMetrics: dashMetrics,
settings: settings
}));
}
if (settings.get().streaming.abr.additionalAbrRules.switchHistoryRule) {
qualitySwitchRules.push(Object(_SwitchHistoryRule__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create());
}
if (settings.get().streaming.abr.additionalAbrRules.droppedFramesRule) {
qualitySwitchRules.push(Object(_DroppedFramesRule__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create());
}
if (settings.get().streaming.abr.additionalAbrRules.abandonRequestsRule) {
abandonFragmentRules.push(Object(_AbandonRequestsRule__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
dashMetrics: dashMetrics,
mediaPlayerModel: mediaPlayerModel,
settings: settings
}));
}
}
} // add custom ABR rules if any
var customRules = mediaPlayerModel.getABRCustomRules();
customRules.forEach(function (rule) {
if (rule.type === QUALITY_SWITCH_RULES) {
qualitySwitchRules.push(rule.rule(context).create());
}
if (rule.type === ABANDON_FRAGMENT_RULES) {
abandonFragmentRules.push(rule.rule(context).create());
}
});
}
function _getRulesWithChange(srArray) {
return srArray.filter(function (sr) {
return sr.quality > _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE;
});
}
/**
*
* @param {array} srArray
* @return {object} SwitchRequest
*/
function getMinSwitchRequest(srArray) {
var values = {};
var newSwitchReq = null;
var i, len, req, quality, reason;
if (srArray.length === 0) {
return;
}
values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.STRONG] = {
quality: _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE,
reason: null
};
values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.WEAK] = {
quality: _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE,
reason: null
};
values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.DEFAULT] = {
quality: _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE,
reason: null
};
for (i = 0, len = srArray.length; i < len; i += 1) {
req = srArray[i];
if (req.quality !== _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE) {
// We only use the new quality in case it is lower than the already saved one or if no new quality has been selected for the respective priority
if (values[req.priority].quality === _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE || values[req.priority].quality > req.quality) {
values[req.priority].quality = req.quality;
values[req.priority].reason = req.reason || null;
}
}
}
if (values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.WEAK].quality !== _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE) {
newSwitchReq = values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.WEAK];
}
if (values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.DEFAULT].quality !== _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE) {
newSwitchReq = values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.DEFAULT];
}
if (values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.STRONG].quality !== _SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].NO_CHANGE) {
newSwitchReq = values[_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"].PRIORITY.STRONG];
}
if (newSwitchReq) {
quality = newSwitchReq.quality;
reason = newSwitchReq.reason;
}
return Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"])(context).create(quality, reason);
}
function getMaxQuality(rulesContext) {
var switchRequestArray = qualitySwitchRules.map(function (rule) {
return rule.getMaxIndex(rulesContext);
});
var activeRules = _getRulesWithChange(switchRequestArray);
var maxQuality = getMinSwitchRequest(activeRules);
return maxQuality || Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"])(context).create();
}
function shouldAbandonFragment(rulesContext, streamId) {
var abandonRequestArray = abandonFragmentRules.map(function (rule) {
return rule.shouldAbandon(rulesContext, streamId);
});
var activeRules = _getRulesWithChange(abandonRequestArray);
var shouldAbandon = getMinSwitchRequest(activeRules);
return shouldAbandon || Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_9__["default"])(context).create();
}
function reset() {
[qualitySwitchRules, abandonFragmentRules].forEach(function (rules) {
if (rules && rules.length) {
rules.forEach(function (rule) {
return rule.reset && rule.reset();
});
}
});
qualitySwitchRules = [];
abandonFragmentRules = [];
}
function getQualitySwitchRules() {
return qualitySwitchRules;
}
instance = {
initialize: initialize,
reset: reset,
getMaxQuality: getMaxQuality,
getMinSwitchRequest: getMinSwitchRequest,
shouldAbandonFragment: shouldAbandonFragment,
getQualitySwitchRules: getQualitySwitchRules
};
return instance;
}
ABRRulesCollection.__dashjs_factory_name = 'ABRRulesCollection';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_8__["default"].getClassFactory(ABRRulesCollection);
factory.QUALITY_SWITCH_RULES = QUALITY_SWITCH_RULES;
factory.ABANDON_FRAGMENT_RULES = ABANDON_FRAGMENT_RULES;
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_8__["default"].updateSingletonFactory(ABRRulesCollection.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/rules/abr/AbandonRequestsRule.js":
/*!********************************************************!*\
!*** ./src/streaming/rules/abr/AbandonRequestsRule.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../core/Debug */ "./src/core/Debug.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function AbandonRequestsRule(config) {
config = config || {};
var ABANDON_MULTIPLIER = 1.8;
var GRACE_TIME_THRESHOLD = 500;
var MIN_LENGTH_TO_AVERAGE = 5;
var context = this.context;
var mediaPlayerModel = config.mediaPlayerModel;
var dashMetrics = config.dashMetrics;
var settings = config.settings;
var instance, logger, fragmentDict, abandonDict, throughputArray;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance().getLogger(instance);
reset();
}
function setFragmentRequestDict(type, id) {
fragmentDict[type] = fragmentDict[type] || {};
fragmentDict[type][id] = fragmentDict[type][id] || {};
}
function storeLastRequestThroughputByType(type, throughput) {
throughputArray[type] = throughputArray[type] || [];
throughputArray[type].push(throughput);
}
function shouldAbandon(rulesContext) {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create(_SwitchRequest__WEBPACK_IMPORTED_MODULE_0__["default"].NO_CHANGE, {
name: AbandonRequestsRule.__dashjs_factory_name
});
if (!rulesContext || !rulesContext.hasOwnProperty('getMediaInfo') || !rulesContext.hasOwnProperty('getMediaType') || !rulesContext.hasOwnProperty('getCurrentRequest') || !rulesContext.hasOwnProperty('getRepresentationInfo') || !rulesContext.hasOwnProperty('getAbrController')) {
return switchRequest;
}
var mediaInfo = rulesContext.getMediaInfo();
var mediaType = rulesContext.getMediaType();
var streamInfo = rulesContext.getStreamInfo();
var streamId = streamInfo ? streamInfo.id : null;
var req = rulesContext.getCurrentRequest();
if (!isNaN(req.index)) {
setFragmentRequestDict(mediaType, req.index);
var stableBufferTime = mediaPlayerModel.getStableBufferTime();
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
if (bufferLevel > stableBufferTime) {
return switchRequest;
}
var fragmentInfo = fragmentDict[mediaType][req.index];
if (fragmentInfo === null || req.firstByteDate === null || abandonDict.hasOwnProperty(fragmentInfo.id)) {
return switchRequest;
} //setup some init info based on first progress event
if (fragmentInfo.firstByteTime === undefined) {
throughputArray[mediaType] = [];
fragmentInfo.firstByteTime = req.firstByteDate.getTime();
fragmentInfo.segmentDuration = req.duration;
fragmentInfo.bytesTotal = req.bytesTotal;
fragmentInfo.id = req.index;
}
fragmentInfo.bytesLoaded = req.bytesLoaded;
fragmentInfo.elapsedTime = new Date().getTime() - fragmentInfo.firstByteTime;
if (fragmentInfo.bytesLoaded > 0 && fragmentInfo.elapsedTime > 0) {
storeLastRequestThroughputByType(mediaType, Math.round(fragmentInfo.bytesLoaded * 8 / fragmentInfo.elapsedTime));
}
if (throughputArray[mediaType].length >= MIN_LENGTH_TO_AVERAGE && fragmentInfo.elapsedTime > GRACE_TIME_THRESHOLD && fragmentInfo.bytesLoaded < fragmentInfo.bytesTotal) {
var totalSampledValue = throughputArray[mediaType].reduce(function (a, b) {
return a + b;
}, 0);
fragmentInfo.measuredBandwidthInKbps = Math.round(totalSampledValue / throughputArray[mediaType].length);
fragmentInfo.estimatedTimeOfDownload = +(fragmentInfo.bytesTotal * 8 / fragmentInfo.measuredBandwidthInKbps / 1000).toFixed(2);
if (fragmentInfo.estimatedTimeOfDownload < fragmentInfo.segmentDuration * ABANDON_MULTIPLIER || rulesContext.getRepresentationInfo().quality === 0) {
return switchRequest;
} else if (!abandonDict.hasOwnProperty(fragmentInfo.id)) {
var abrController = rulesContext.getAbrController();
var bytesRemaining = fragmentInfo.bytesTotal - fragmentInfo.bytesLoaded;
var bitrateList = abrController.getBitrateList(mediaInfo);
var quality = abrController.getQualityForBitrate(mediaInfo, fragmentInfo.measuredBandwidthInKbps * settings.get().streaming.abr.bandwidthSafetyFactor, streamId);
var minQuality = abrController.getMinAllowedIndexFor(mediaType, streamId);
var newQuality = minQuality !== undefined ? Math.max(minQuality, quality) : quality;
var estimateOtherBytesTotal = fragmentInfo.bytesTotal * bitrateList[newQuality].bitrate / bitrateList[abrController.getQualityFor(mediaType, streamId)].bitrate;
if (bytesRemaining > estimateOtherBytesTotal) {
switchRequest.quality = newQuality;
switchRequest.reason.throughput = fragmentInfo.measuredBandwidthInKbps;
switchRequest.reason.fragmentID = fragmentInfo.id;
abandonDict[fragmentInfo.id] = fragmentInfo;
logger.debug('[' + mediaType + '] frag id', fragmentInfo.id, ' is asking to abandon and switch to quality to ', newQuality, ' measured bandwidth was', fragmentInfo.measuredBandwidthInKbps);
delete fragmentDict[mediaType][fragmentInfo.id];
}
}
} else if (fragmentInfo.bytesLoaded === fragmentInfo.bytesTotal) {
delete fragmentDict[mediaType][fragmentInfo.id];
}
}
return switchRequest;
}
function reset() {
fragmentDict = {};
abandonDict = {};
throughputArray = [];
}
instance = {
shouldAbandon: shouldAbandon,
reset: reset
};
setup();
return instance;
}
AbandonRequestsRule.__dashjs_factory_name = 'AbandonRequestsRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(AbandonRequestsRule));
/***/ }),
/***/ "./src/streaming/rules/abr/BolaRule.js":
/*!*********************************************!*\
!*** ./src/streaming/rules/abr/BolaRule.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2016, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// For a description of the BOLA adaptive bitrate (ABR) algorithm, see http://arxiv.org/abs/1601.06748
// BOLA_STATE_ONE_BITRATE : If there is only one bitrate (or initialization failed), always return NO_CHANGE.
// BOLA_STATE_STARTUP : Set placeholder buffer such that we download fragments at most recently measured throughput.
// BOLA_STATE_STEADY : Buffer primed, we switch to steady operation.
// TODO: add BOLA_STATE_SEEK and tune BOLA behavior on seeking
var BOLA_STATE_ONE_BITRATE = 0;
var BOLA_STATE_STARTUP = 1;
var BOLA_STATE_STEADY = 2;
var MINIMUM_BUFFER_S = 10; // BOLA should never add artificial delays if buffer is less than MINIMUM_BUFFER_S.
var MINIMUM_BUFFER_PER_BITRATE_LEVEL_S = 2; // E.g. if there are 5 bitrates, BOLA switches to top bitrate at buffer = 10 + 5 * 2 = 20s.
// If Schedule Controller does not allow buffer to reach that level, it can be achieved through the placeholder buffer level.
var PLACEHOLDER_BUFFER_DECAY = 0.99; // Make sure placeholder buffer does not stick around too long.
function BolaRule(config) {
config = config || {};
var context = this.context;
var dashMetrics = config.dashMetrics;
var mediaPlayerModel = config.mediaPlayerModel;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var instance, logger, bolaStateDict;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance().getLogger(instance);
resetInitialSettings();
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].BUFFER_EMPTY, onBufferEmpty, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_SEEKING, onPlaybackSeeking, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].METRIC_ADDED, onMetricAdded, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].QUALITY_CHANGE_REQUESTED, onQualityChangeRequested, instance);
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_ABANDONED, onFragmentLoadingAbandoned, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MEDIA_FRAGMENT_LOADED, onMediaFragmentLoaded, instance);
}
function utilitiesFromBitrates(bitrates) {
return bitrates.map(function (b) {
return Math.log(b);
}); // no need to worry about offset, utilities will be offset (uniformly) anyway later
} // NOTE: in live streaming, the real buffer level can drop below minimumBufferS, but bola should not stick to lowest bitrate by using a placeholder buffer level
function calculateBolaParameters(stableBufferTime, bitrates, utilities) {
var highestUtilityIndex = utilities.reduce(function (highestIndex, u, uIndex) {
return u > utilities[highestIndex] ? uIndex : highestIndex;
}, 0);
if (highestUtilityIndex === 0) {
// if highestUtilityIndex === 0, then always use lowest bitrate
return null;
}
var bufferTime = Math.max(stableBufferTime, MINIMUM_BUFFER_S + MINIMUM_BUFFER_PER_BITRATE_LEVEL_S * bitrates.length); // TODO: Investigate if following can be better if utilities are not the default Math.log utilities.
// If using Math.log utilities, we can choose Vp and gp to always prefer bitrates[0] at minimumBufferS and bitrates[max] at bufferTarget.
// (Vp * (utility + gp) - bufferLevel) / bitrate has the maxima described when:
// Vp * (utilities[0] + gp - 1) === minimumBufferS and Vp * (utilities[max] + gp - 1) === bufferTarget
// giving:
var gp = (utilities[highestUtilityIndex] - 1) / (bufferTime / MINIMUM_BUFFER_S - 1);
var Vp = MINIMUM_BUFFER_S / gp; // note that expressions for gp and Vp assume utilities[0] === 1, which is true because of normalization
return {
gp: gp,
Vp: Vp
};
}
function getInitialBolaState(rulesContext) {
var initialState = {};
var mediaInfo = rulesContext.getMediaInfo();
var bitrates = mediaInfo.bitrateList.map(function (b) {
return b.bandwidth;
});
var utilities = utilitiesFromBitrates(bitrates);
utilities = utilities.map(function (u) {
return u - utilities[0] + 1;
}); // normalize
var stableBufferTime = mediaPlayerModel.getStableBufferTime();
var params = calculateBolaParameters(stableBufferTime, bitrates, utilities);
if (!params) {
// only happens when there is only one bitrate level
initialState.state = BOLA_STATE_ONE_BITRATE;
} else {
initialState.state = BOLA_STATE_STARTUP;
initialState.bitrates = bitrates;
initialState.utilities = utilities;
initialState.stableBufferTime = stableBufferTime;
initialState.Vp = params.Vp;
initialState.gp = params.gp;
initialState.lastQuality = 0;
clearBolaStateOnSeek(initialState);
}
return initialState;
}
function clearBolaStateOnSeek(bolaState) {
bolaState.placeholderBuffer = 0;
bolaState.mostAdvancedSegmentStart = NaN;
bolaState.lastSegmentWasReplacement = false;
bolaState.lastSegmentStart = NaN;
bolaState.lastSegmentDurationS = NaN;
bolaState.lastSegmentRequestTimeMs = NaN;
bolaState.lastSegmentFinishTimeMs = NaN;
} // If the buffer target is changed (can this happen mid-stream?), then adjust BOLA parameters accordingly.
function checkBolaStateStableBufferTime(bolaState, mediaType) {
var stableBufferTime = mediaPlayerModel.getStableBufferTime();
if (bolaState.stableBufferTime !== stableBufferTime) {
var params = calculateBolaParameters(stableBufferTime, bolaState.bitrates, bolaState.utilities);
if (params.Vp !== bolaState.Vp || params.gp !== bolaState.gp) {
// correct placeholder buffer using two criteria:
// 1. do not change effective buffer level at effectiveBufferLevel === MINIMUM_BUFFER_S ( === Vp * gp )
// 2. scale placeholder buffer by Vp subject to offset indicated in 1.
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
var effectiveBufferLevel = bufferLevel + bolaState.placeholderBuffer;
effectiveBufferLevel -= MINIMUM_BUFFER_S;
effectiveBufferLevel *= params.Vp / bolaState.Vp;
effectiveBufferLevel += MINIMUM_BUFFER_S;
bolaState.stableBufferTime = stableBufferTime;
bolaState.Vp = params.Vp;
bolaState.gp = params.gp;
bolaState.placeholderBuffer = Math.max(0, effectiveBufferLevel - bufferLevel);
}
}
}
function getBolaState(rulesContext) {
var mediaType = rulesContext.getMediaType();
var bolaState = bolaStateDict[mediaType];
if (!bolaState) {
bolaState = getInitialBolaState(rulesContext);
bolaStateDict[mediaType] = bolaState;
} else if (bolaState.state !== BOLA_STATE_ONE_BITRATE) {
checkBolaStateStableBufferTime(bolaState, mediaType);
}
return bolaState;
} // The core idea of BOLA.
function getQualityFromBufferLevel(bolaState, bufferLevel) {
var bitrateCount = bolaState.bitrates.length;
var quality = NaN;
var score = NaN;
for (var i = 0; i < bitrateCount; ++i) {
var s = (bolaState.Vp * (bolaState.utilities[i] + bolaState.gp) - bufferLevel) / bolaState.bitrates[i];
if (isNaN(score) || s >= score) {
score = s;
quality = i;
}
}
return quality;
} // maximum buffer level which prefers to download at quality rather than wait
function maxBufferLevelForQuality(bolaState, quality) {
return bolaState.Vp * (bolaState.utilities[quality] + bolaState.gp);
} // the minimum buffer level that would cause BOLA to choose quality rather than a lower bitrate
function minBufferLevelForQuality(bolaState, quality) {
var qBitrate = bolaState.bitrates[quality];
var qUtility = bolaState.utilities[quality];
var min = 0;
for (var i = quality - 1; i >= 0; --i) {
// for each bitrate less than bitrates[quality], BOLA should prefer quality (unless other bitrate has higher utility)
if (bolaState.utilities[i] < bolaState.utilities[quality]) {
var iBitrate = bolaState.bitrates[i];
var iUtility = bolaState.utilities[i];
var level = bolaState.Vp * (bolaState.gp + (qBitrate * iUtility - iBitrate * qUtility) / (qBitrate - iBitrate));
min = Math.max(min, level); // we want min to be small but at least level(i) for all i
}
}
return min;
}
/*
* The placeholder buffer increases the effective buffer that is used to calculate the bitrate.
* There are two main reasons we might want to increase the placeholder buffer:
*
* 1. When a segment finishes downloading, we would expect to get a call on getMaxIndex() regarding the quality for
* the next segment. However, there might be a delay before the next call. E.g. when streaming live content, the
* next segment might not be available yet. If the call to getMaxIndex() does happens after a delay, we don't
* want the delay to change the BOLA decision - we only want to factor download time to decide on bitrate level.
*
* 2. It is possible to get a call to getMaxIndex() without having a segment download. The buffer target in dash.js
* is different for top-quality segments and lower-quality segments. If getMaxIndex() returns a lower-than-top
* quality, then the buffer controller might decide not to download a segment. When dash.js is ready for the next
* segment, getMaxIndex() will be called again. We don't want this extra delay to factor in the bitrate decision.
*/
function updatePlaceholderBuffer(bolaState, mediaType) {
var nowMs = Date.now();
if (!isNaN(bolaState.lastSegmentFinishTimeMs)) {
// compensate for non-bandwidth-derived delays, e.g., live streaming availability, buffer controller
var delay = 0.001 * (nowMs - bolaState.lastSegmentFinishTimeMs);
bolaState.placeholderBuffer += Math.max(0, delay);
} else if (!isNaN(bolaState.lastCallTimeMs)) {
// no download after last call, compensate for delay between calls
var _delay = 0.001 * (nowMs - bolaState.lastCallTimeMs);
bolaState.placeholderBuffer += Math.max(0, _delay);
}
bolaState.lastCallTimeMs = nowMs;
bolaState.lastSegmentStart = NaN;
bolaState.lastSegmentRequestTimeMs = NaN;
bolaState.lastSegmentFinishTimeMs = NaN;
checkBolaStateStableBufferTime(bolaState, mediaType);
}
function onBufferEmpty() {
// if we rebuffer, we don't want the placeholder buffer to artificially raise BOLA quality
for (var mediaType in bolaStateDict) {
if (bolaStateDict.hasOwnProperty(mediaType) && bolaStateDict[mediaType].state === BOLA_STATE_STEADY) {
bolaStateDict[mediaType].placeholderBuffer = 0;
}
}
}
function onPlaybackSeeking() {
// TODO: 1. Verify what happens if we seek mid-fragment.
// TODO: 2. If e.g. we have 10s fragments and seek, we might want to download the first fragment at a lower quality to restart playback quickly.
for (var mediaType in bolaStateDict) {
if (bolaStateDict.hasOwnProperty(mediaType)) {
var bolaState = bolaStateDict[mediaType];
if (bolaState.state !== BOLA_STATE_ONE_BITRATE) {
bolaState.state = BOLA_STATE_STARTUP; // TODO: BOLA_STATE_SEEK?
clearBolaStateOnSeek(bolaState);
}
}
}
}
function onMediaFragmentLoaded(e) {
if (e && e.chunk && e.chunk.mediaInfo) {
var bolaState = bolaStateDict[e.chunk.mediaInfo.type];
if (bolaState && bolaState.state !== BOLA_STATE_ONE_BITRATE) {
var start = e.chunk.start;
if (isNaN(bolaState.mostAdvancedSegmentStart) || start > bolaState.mostAdvancedSegmentStart) {
bolaState.mostAdvancedSegmentStart = start;
bolaState.lastSegmentWasReplacement = false;
} else {
bolaState.lastSegmentWasReplacement = true;
}
bolaState.lastSegmentStart = start;
bolaState.lastSegmentDurationS = e.chunk.duration;
bolaState.lastQuality = e.chunk.quality;
checkNewSegment(bolaState, e.chunk.mediaInfo.type);
}
}
}
function onMetricAdded(e) {
if (e && e.metric === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_0__["default"].HTTP_REQUEST && e.value && e.value.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__["HTTPRequest"].MEDIA_SEGMENT_TYPE && e.value.trace && e.value.trace.length) {
var bolaState = bolaStateDict[e.mediaType];
if (bolaState && bolaState.state !== BOLA_STATE_ONE_BITRATE) {
bolaState.lastSegmentRequestTimeMs = e.value.trequest.getTime();
bolaState.lastSegmentFinishTimeMs = e.value._tfinish.getTime();
checkNewSegment(bolaState, e.mediaType);
}
}
}
/*
* When a new segment is downloaded, we get two notifications: onMediaFragmentLoaded() and onMetricAdded(). It is
* possible that the quality for the downloaded segment was lower (not higher) than the quality indicated by BOLA.
* This might happen because of other rules such as the DroppedFramesRule. When this happens, we trim the
* placeholder buffer to make BOLA more stable. This mechanism also avoids inflating the buffer when BOLA itself
* decides not to increase the quality to avoid oscillations.
*
* We should also check for replacement segments (fast switching). In this case, a segment is downloaded but does
* not grow the actual buffer. Fast switching might cause the buffer to deplete, causing BOLA to drop the bitrate.
* We avoid this by growing the placeholder buffer.
*/
function checkNewSegment(bolaState, mediaType) {
if (!isNaN(bolaState.lastSegmentStart) && !isNaN(bolaState.lastSegmentRequestTimeMs) && !isNaN(bolaState.placeholderBuffer)) {
bolaState.placeholderBuffer *= PLACEHOLDER_BUFFER_DECAY; // Find what maximum buffer corresponding to last segment was, and ensure placeholder is not relatively larger.
if (!isNaN(bolaState.lastSegmentFinishTimeMs)) {
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
var bufferAtLastSegmentRequest = bufferLevel + 0.001 * (bolaState.lastSegmentFinishTimeMs - bolaState.lastSegmentRequestTimeMs); // estimate
var maxEffectiveBufferForLastSegment = maxBufferLevelForQuality(bolaState, bolaState.lastQuality);
var maxPlaceholderBuffer = Math.max(0, maxEffectiveBufferForLastSegment - bufferAtLastSegmentRequest);
bolaState.placeholderBuffer = Math.min(maxPlaceholderBuffer, bolaState.placeholderBuffer);
} // then see if we should grow placeholder buffer
if (bolaState.lastSegmentWasReplacement && !isNaN(bolaState.lastSegmentDurationS)) {
// compensate for segments that were downloaded but did not grow the buffer
bolaState.placeholderBuffer += bolaState.lastSegmentDurationS;
}
bolaState.lastSegmentStart = NaN;
bolaState.lastSegmentRequestTimeMs = NaN;
}
}
function onQualityChangeRequested(e) {
// Useful to store change requests when abandoning a download.
if (e) {
var bolaState = bolaStateDict[e.mediaType];
if (bolaState && bolaState.state !== BOLA_STATE_ONE_BITRATE) {
bolaState.abrQuality = e.newQuality;
}
}
}
function onFragmentLoadingAbandoned(e) {
if (e) {
var bolaState = bolaStateDict[e.mediaType];
if (bolaState && bolaState.state !== BOLA_STATE_ONE_BITRATE) {
// deflate placeholderBuffer - note that we want to be conservative when abandoning
var bufferLevel = dashMetrics.getCurrentBufferLevel(e.mediaType);
var wantEffectiveBufferLevel;
if (bolaState.abrQuality > 0) {
// deflate to point where BOLA just chooses newQuality over newQuality-1
wantEffectiveBufferLevel = minBufferLevelForQuality(bolaState, bolaState.abrQuality);
} else {
wantEffectiveBufferLevel = MINIMUM_BUFFER_S;
}
var maxPlaceholderBuffer = Math.max(0, wantEffectiveBufferLevel - bufferLevel);
bolaState.placeholderBuffer = Math.min(bolaState.placeholderBuffer, maxPlaceholderBuffer);
}
}
}
function getMaxIndex(rulesContext) {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
if (!rulesContext || !rulesContext.hasOwnProperty('getMediaInfo') || !rulesContext.hasOwnProperty('getMediaType') || !rulesContext.hasOwnProperty('getScheduleController') || !rulesContext.hasOwnProperty('getStreamInfo') || !rulesContext.hasOwnProperty('getAbrController') || !rulesContext.hasOwnProperty('useBufferOccupancyABR')) {
return switchRequest;
}
var mediaInfo = rulesContext.getMediaInfo();
var mediaType = rulesContext.getMediaType();
var scheduleController = rulesContext.getScheduleController();
var streamInfo = rulesContext.getStreamInfo();
var abrController = rulesContext.getAbrController();
var throughputHistory = abrController.getThroughputHistory();
var streamId = streamInfo ? streamInfo.id : null;
var isDynamic = streamInfo && streamInfo.manifestInfo && streamInfo.manifestInfo.isDynamic;
var useBufferOccupancyABR = rulesContext.useBufferOccupancyABR();
switchRequest.reason = switchRequest.reason || {};
if (!useBufferOccupancyABR) {
return switchRequest;
}
scheduleController.setTimeToLoadDelay(0);
var bolaState = getBolaState(rulesContext);
if (bolaState.state === BOLA_STATE_ONE_BITRATE) {
// shouldn't even have been called
return switchRequest;
}
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
var throughput = throughputHistory.getAverageThroughput(mediaType, isDynamic);
var safeThroughput = throughputHistory.getSafeAverageThroughput(mediaType, isDynamic);
var latency = throughputHistory.getAverageLatency(mediaType);
var quality;
switchRequest.reason.state = bolaState.state;
switchRequest.reason.throughput = throughput;
switchRequest.reason.latency = latency;
if (isNaN(throughput)) {
// isNaN(throughput) === isNaN(safeThroughput) === isNaN(latency)
// still starting up - not enough information
return switchRequest;
}
switch (bolaState.state) {
case BOLA_STATE_STARTUP:
quality = abrController.getQualityForBitrate(mediaInfo, safeThroughput, streamId, latency);
switchRequest.quality = quality;
switchRequest.reason.throughput = safeThroughput;
bolaState.placeholderBuffer = Math.max(0, minBufferLevelForQuality(bolaState, quality) - bufferLevel);
bolaState.lastQuality = quality;
if (!isNaN(bolaState.lastSegmentDurationS) && bufferLevel >= bolaState.lastSegmentDurationS) {
bolaState.state = BOLA_STATE_STEADY;
}
break;
// BOLA_STATE_STARTUP
case BOLA_STATE_STEADY:
// NB: The placeholder buffer is added to bufferLevel to come up with a bitrate.
// This might lead BOLA to be too optimistic and to choose a bitrate that would lead to rebuffering -
// if the real buffer bufferLevel runs out, the placeholder buffer cannot prevent rebuffering.
// However, the InsufficientBufferRule takes care of this scenario.
updatePlaceholderBuffer(bolaState, mediaType);
quality = getQualityFromBufferLevel(bolaState, bufferLevel + bolaState.placeholderBuffer); // we want to avoid oscillations
// We implement the "BOLA-O" variant: when network bandwidth lies between two encoded bitrate levels, stick to the lowest level.
var qualityForThroughput = abrController.getQualityForBitrate(mediaInfo, safeThroughput, streamId, latency);
if (quality > bolaState.lastQuality && quality > qualityForThroughput) {
// only intervene if we are trying to *increase* quality to an *unsustainable* level
// we are only avoid oscillations - do not drop below last quality
quality = Math.max(qualityForThroughput, bolaState.lastQuality);
} // We do not want to overfill buffer with low quality chunks.
// Note that there will be no delay if buffer level is below MINIMUM_BUFFER_S, probably even with some margin higher than MINIMUM_BUFFER_S.
var delayS = Math.max(0, bufferLevel + bolaState.placeholderBuffer - maxBufferLevelForQuality(bolaState, quality)); // First reduce placeholder buffer, then tell schedule controller to pause.
if (delayS <= bolaState.placeholderBuffer) {
bolaState.placeholderBuffer -= delayS;
delayS = 0;
} else {
delayS -= bolaState.placeholderBuffer;
bolaState.placeholderBuffer = 0;
if (quality < abrController.getMaxAllowedIndexFor(mediaType, streamId)) {
// At top quality, allow schedule controller to decide how far to fill buffer.
scheduleController.setTimeToLoadDelay(1000 * delayS);
} else {
delayS = 0;
}
}
switchRequest.quality = quality;
switchRequest.reason.throughput = throughput;
switchRequest.reason.latency = latency;
switchRequest.reason.bufferLevel = bufferLevel;
switchRequest.reason.placeholderBuffer = bolaState.placeholderBuffer;
switchRequest.reason.delay = delayS;
bolaState.lastQuality = quality; // keep bolaState.state === BOLA_STATE_STEADY
break;
// BOLA_STATE_STEADY
default:
logger.debug('BOLA ABR rule invoked in bad state.'); // should not arrive here, try to recover
switchRequest.quality = abrController.getQualityForBitrate(mediaInfo, safeThroughput, streamId, latency);
switchRequest.reason.state = bolaState.state;
switchRequest.reason.throughput = safeThroughput;
switchRequest.reason.latency = latency;
bolaState.state = BOLA_STATE_STARTUP;
clearBolaStateOnSeek(bolaState);
}
return switchRequest;
}
function resetInitialSettings() {
bolaStateDict = {};
}
function reset() {
resetInitialSettings();
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].BUFFER_EMPTY, onBufferEmpty, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_SEEKING, onPlaybackSeeking, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].METRIC_ADDED, onMetricAdded, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].QUALITY_CHANGE_REQUESTED, onQualityChangeRequested, instance);
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_ABANDONED, onFragmentLoadingAbandoned, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MEDIA_FRAGMENT_LOADED, onMediaFragmentLoaded, instance);
}
instance = {
getMaxIndex: getMaxIndex,
reset: reset
};
setup();
return instance;
}
BolaRule.__dashjs_factory_name = 'BolaRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(BolaRule));
/***/ }),
/***/ "./src/streaming/rules/abr/DroppedFramesRule.js":
/*!******************************************************!*\
!*** ./src/streaming/rules/abr/DroppedFramesRule.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../core/Debug */ "./src/core/Debug.js");
function DroppedFramesRule() {
var context = this.context;
var instance, logger;
var DROPPED_PERCENTAGE_FORBID = 0.15;
var GOOD_SAMPLE_SIZE = 375; //Don't apply the rule until this many frames have been rendered(and counted under those indices).
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance().getLogger(instance);
}
function getMaxIndex(rulesContext) {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
if (!rulesContext || !rulesContext.hasOwnProperty('getDroppedFramesHistory')) {
return switchRequest;
}
var droppedFramesHistory = rulesContext.getDroppedFramesHistory();
var streamId = rulesContext.getStreamInfo().id;
if (droppedFramesHistory) {
var dfh = droppedFramesHistory.getFrameHistory(streamId);
if (!dfh || dfh.length === 0) {
return switchRequest;
}
var droppedFrames = 0;
var totalFrames = 0;
var maxIndex = _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"].NO_CHANGE; //No point in measuring dropped frames for the zeroeth index.
for (var i = 1; i < dfh.length; i++) {
if (dfh[i]) {
droppedFrames = dfh[i].droppedVideoFrames;
totalFrames = dfh[i].totalVideoFrames;
if (totalFrames > GOOD_SAMPLE_SIZE && droppedFrames / totalFrames > DROPPED_PERCENTAGE_FORBID) {
maxIndex = i - 1;
logger.debug('index: ' + maxIndex + ' Dropped Frames: ' + droppedFrames + ' Total Frames: ' + totalFrames);
break;
}
}
}
return Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create(maxIndex, {
droppedFrames: droppedFrames
});
}
return switchRequest;
}
instance = {
getMaxIndex: getMaxIndex
};
setup();
return instance;
}
DroppedFramesRule.__dashjs_factory_name = 'DroppedFramesRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(DroppedFramesRule));
/***/ }),
/***/ "./src/streaming/rules/abr/InsufficientBufferRule.js":
/*!***********************************************************!*\
!*** ./src/streaming/rules/abr/InsufficientBufferRule.js ***!
\***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function InsufficientBufferRule(config) {
config = config || {};
var INSUFFICIENT_BUFFER_SAFETY_FACTOR = 0.5;
var SEGMENT_IGNORE_COUNT = 2;
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var dashMetrics = config.dashMetrics;
var settings = config.settings;
var instance, logger, bufferStateDict;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance().getLogger(instance);
resetInitialSettings();
eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].BYTES_APPENDED_END_FRAGMENT, _onBytesAppended, instance);
}
function checkConfig() {
if (!dashMetrics || !dashMetrics.hasOwnProperty('getCurrentBufferLevel') || !dashMetrics.hasOwnProperty('getCurrentBufferState')) {
throw new Error(_constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].MISSING_CONFIG_ERROR);
}
}
/**
* If a BUFFER_EMPTY event happens, then InsufficientBufferRule returns switchRequest.quality=0 until BUFFER_LOADED happens.
* Otherwise InsufficientBufferRule gives a maximum bitrate depending on throughput and bufferLevel such that
* a whole fragment can be downloaded before the buffer runs out, subject to a conservative safety factor of 0.5.
* If the bufferLevel is low, then InsufficientBufferRule avoids rebuffering risk.
* If the bufferLevel is high, then InsufficientBufferRule give a high MaxIndex allowing other rules to take over.
* @param rulesContext
* @return {object}
*/
function getMaxIndex(rulesContext) {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create();
if (!rulesContext || !rulesContext.hasOwnProperty('getMediaType')) {
return switchRequest;
}
checkConfig();
var mediaType = rulesContext.getMediaType();
var currentBufferState = dashMetrics.getCurrentBufferState(mediaType);
var representationInfo = rulesContext.getRepresentationInfo();
var fragmentDuration = representationInfo.fragmentDuration;
var streamInfo = rulesContext.getStreamInfo();
var streamId = streamInfo ? streamInfo.id : null;
var isDynamic = streamInfo && streamInfo.manifestInfo && streamInfo.manifestInfo.isDynamic; // Don't ask for a bitrate change if there is not info about buffer state or if fragmentDuration is not defined
if (shouldIgnore(mediaType) || !fragmentDuration) {
return switchRequest;
}
if (currentBufferState && currentBufferState.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_EMPTY) {
logger.debug('[' + mediaType + '] Switch to index 0; buffer is empty.');
switchRequest.quality = 0;
switchRequest.reason = 'InsufficientBufferRule: Buffer is empty';
} else {
var mediaInfo = rulesContext.getMediaInfo();
var abrController = rulesContext.getAbrController();
var throughputHistory = abrController.getThroughputHistory();
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType);
var throughput = throughputHistory.getAverageThroughput(mediaType, isDynamic);
var latency = throughputHistory.getAverageLatency(mediaType);
var bitrate = throughput * (bufferLevel / fragmentDuration) * INSUFFICIENT_BUFFER_SAFETY_FACTOR;
switchRequest.quality = abrController.getQualityForBitrate(mediaInfo, bitrate, streamId, latency);
switchRequest.reason = 'InsufficientBufferRule: being conservative to avoid immediate rebuffering';
}
return switchRequest;
}
function shouldIgnore(mediaType) {
return !settings.get().streaming.lowLatencyEnabled && bufferStateDict[mediaType].ignoreCount > 0;
}
function resetInitialSettings() {
bufferStateDict = {};
bufferStateDict[_constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].VIDEO] = {
ignoreCount: SEGMENT_IGNORE_COUNT
};
bufferStateDict[_constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].AUDIO] = {
ignoreCount: SEGMENT_IGNORE_COUNT
};
}
function _onPlaybackSeeking() {
resetInitialSettings();
}
function _onBytesAppended(e) {
if (!isNaN(e.startTime) && (e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].AUDIO || e.mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].VIDEO)) {
if (bufferStateDict[e.mediaType].ignoreCount > 0) {
bufferStateDict[e.mediaType].ignoreCount--;
}
}
}
function reset() {
resetInitialSettings();
eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].BYTES_APPENDED_END_FRAGMENT, _onBytesAppended, instance);
}
instance = {
getMaxIndex: getMaxIndex,
reset: reset
};
setup();
return instance;
}
InsufficientBufferRule.__dashjs_factory_name = 'InsufficientBufferRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(InsufficientBufferRule));
/***/ }),
/***/ "./src/streaming/rules/abr/L2ARule.js":
/*!********************************************!*\
!*** ./src/streaming/rules/abr/L2ARule.js ***!
\********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2020, Unified Streaming.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// For a description of the Learn2Adapt-LowLatency (L2A-LL) bitrate adaptation algorithm, see https://github.com/unifiedstreaming/Learn2Adapt-LowLatency/blob/master/Online_learning_for_bitrate_adaptation_in_low_latency_live_streaming_CR.pdf
var L2A_STATE_ONE_BITRATE = 0; // If there is only one bitrate (or initialization failed), always return NO_CHANGE.
var L2A_STATE_STARTUP = 1; // Set placeholder buffer such that we download fragments at most recently measured throughput.
var L2A_STATE_STEADY = 2; // Buffer primed, we switch to steady operation.
function L2ARule(config) {
config = config || {};
var context = this.context;
var dashMetrics = config.dashMetrics;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var instance, l2AStateDict, l2AParameterDict, logger;
/**
* Setup function to initialize L2ARule
*/
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance().getLogger(instance);
_resetInitialSettings();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].METRIC_ADDED, _onMetricAdded, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].QUALITY_CHANGE_REQUESTED, _onQualityChangeRequested, instance);
}
/**
* Sets the initial state of the algorithm. Calls the initialize function for the paramteters.
* @param {object} rulesContext
* @return {object} initialState
* @private
*/
function _getInitialL2AState(rulesContext) {
var initialState = {};
var mediaInfo = rulesContext.getMediaInfo();
var bitrates = mediaInfo.bitrateList.map(function (b) {
return b.bandwidth / 1000;
});
initialState.state = L2A_STATE_STARTUP;
initialState.bitrates = bitrates;
initialState.lastQuality = 0;
_initializeL2AParameters(mediaInfo);
_clearL2AStateOnSeek(initialState);
return initialState;
}
/**
* Initializes the parameters of the algorithm. This will be done once for each media type.
* @param {object} mediaInfo
* @private
*/
function _initializeL2AParameters(mediaInfo) {
if (!mediaInfo || !mediaInfo.type) {
return;
}
l2AParameterDict[mediaInfo.type] = {};
l2AParameterDict[mediaInfo.type].w = []; //Vector of probabilities associated with bitrate decisions
l2AParameterDict[mediaInfo.type].prev_w = []; //Vector of probabilities associated with bitrate decisions calculated in the previous step
l2AParameterDict[mediaInfo.type].Q = 0; //Initialization of Lagrangian multiplier (This keeps track of the buffer displacement)
l2AParameterDict[mediaInfo.type].segment_request_start_s = 0;
l2AParameterDict[mediaInfo.type].segment_download_finish_s = 0;
l2AParameterDict[mediaInfo.type].B_target = 1.5; //Target buffer level
}
/**
* Clears the state object
* @param {object} l2AState
* @private
*/
function _clearL2AStateOnSeek(l2AState) {
l2AState.placeholderBuffer = 0;
l2AState.mostAdvancedSegmentStart = NaN;
l2AState.lastSegmentWasReplacement = false;
l2AState.lastSegmentStart = NaN;
l2AState.lastSegmentDurationS = NaN;
l2AState.lastSegmentRequestTimeMs = NaN;
l2AState.lastSegmentFinishTimeMs = NaN;
}
/**
* Returns the state object for a fiven media type. If the state object is not yet defined _getInitialL2AState is called
* @param {object} rulesContext
* @return {object} l2AState
* @private
*/
function _getL2AState(rulesContext) {
var mediaType = rulesContext.getMediaType();
var l2AState = l2AStateDict[mediaType];
if (!l2AState) {
l2AState = _getInitialL2AState(rulesContext);
l2AStateDict[mediaType] = l2AState;
}
return l2AState;
}
/**
* Event handler for the seeking event.
* @private
*/
function _onPlaybackSeeking() {
for (var mediaType in l2AStateDict) {
if (l2AStateDict.hasOwnProperty(mediaType)) {
var l2aState = l2AStateDict[mediaType];
if (l2aState.state !== L2A_STATE_ONE_BITRATE) {
l2aState.state = L2A_STATE_STARTUP;
_clearL2AStateOnSeek(l2aState);
}
}
}
}
/**
* Event handler for the mediaFragmentLoaded event
* @param {object} e
* @private
*/
function _onMediaFragmentLoaded(e) {
if (e && e.chunk && e.chunk.mediaInfo) {
var l2AState = l2AStateDict[e.chunk.mediaInfo.type];
var l2AParameters = l2AParameterDict[e.chunk.mediaInfo.type];
if (l2AState && l2AState.state !== L2A_STATE_ONE_BITRATE) {
var start = e.chunk.start;
if (isNaN(l2AState.mostAdvancedSegmentStart) || start > l2AState.mostAdvancedSegmentStart) {
l2AState.mostAdvancedSegmentStart = start;
l2AState.lastSegmentWasReplacement = false;
} else {
l2AState.lastSegmentWasReplacement = true;
}
l2AState.lastSegmentStart = start;
l2AState.lastSegmentDurationS = e.chunk.duration;
l2AState.lastQuality = e.chunk.quality;
_checkNewSegment(l2AState, l2AParameters);
}
}
}
/**
* Event handler for the metricAdded event
* @param {object} e
* @private
*/
function _onMetricAdded(e) {
if (e && e.metric === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_0__["default"].HTTP_REQUEST && e.value && e.value.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__["HTTPRequest"].MEDIA_SEGMENT_TYPE && e.value.trace && e.value.trace.length) {
var l2AState = l2AStateDict[e.mediaType];
var l2AParameters = l2AParameterDict[e.mediaType];
if (l2AState && l2AState.state !== L2A_STATE_ONE_BITRATE) {
l2AState.lastSegmentRequestTimeMs = e.value.trequest.getTime();
l2AState.lastSegmentFinishTimeMs = e.value._tfinish.getTime();
_checkNewSegment(l2AState, l2AParameters);
}
}
}
/**
* When a new metric has been added or a media fragment has been loaded the state is adjusted accordingly
* @param {object} L2AState
* @param {object} l2AParameters
* @private
*/
function _checkNewSegment(L2AState, l2AParameters) {
if (!isNaN(L2AState.lastSegmentStart) && !isNaN(L2AState.lastSegmentRequestTimeMs)) {
l2AParameters.segment_request_start_s = 0.001 * L2AState.lastSegmentRequestTimeMs;
l2AParameters.segment_download_finish_s = 0.001 * L2AState.lastSegmentFinishTimeMs;
L2AState.lastSegmentStart = NaN;
L2AState.lastSegmentRequestTimeMs = NaN;
}
}
/**
* Event handler for the qualityChangeRequested event
* @param {object} e
* @private
*/
function _onQualityChangeRequested(e) {
// Useful to store change requests when abandoning a download.
if (e && e.mediaType) {
var L2AState = l2AStateDict[e.mediaType];
if (L2AState && L2AState.state !== L2A_STATE_ONE_BITRATE) {
L2AState.abrQuality = e.newQuality;
}
}
}
/**
* Dot multiplication of two arrays
* @param {array} arr1
* @param {array} arr2
* @return {number} sumdot
* @private
*/
function _dotmultiplication(arr1, arr2) {
if (arr1.length !== arr2.length) {
return -1;
}
var sumdot = 0;
for (var i = 0; i < arr1.length; i++) {
sumdot = sumdot + arr1[i] * arr2[i];
}
return sumdot;
}
/**
* Project an n-dim vector y to the simplex Dn
* Dn = { x : x n-dim, 1 >= x >= 0, sum(x) = 1}
* Algorithm is explained at http://arxiv.org/abs/1101.6081
* @param {array} arr
* @return {array}
*/
function euclideanProjection(arr) {
var m = arr.length;
var bget = false;
var arr2 = [];
for (var ii = 0; ii < m; ++ii) {
arr2[ii] = arr[ii];
}
var s = arr.sort(function (a, b) {
return b - a;
});
var tmpsum = 0;
var tmax = 0;
var x = [];
for (var _ii = 0; _ii < m - 1; ++_ii) {
tmpsum = tmpsum + s[_ii];
tmax = (tmpsum - 1) / (_ii + 1);
if (tmax >= s[_ii + 1]) {
bget = true;
break;
}
}
if (!bget) {
tmax = (tmpsum + s[m - 1] - 1) / m;
}
for (var _ii2 = 0; _ii2 < m; ++_ii2) {
x[_ii2] = Math.max(arr2[_ii2] - tmax, 0);
}
return x;
}
/**
* Returns a switch request object indicating which quality is to be played
* @param {object} rulesContext
* @return {object}
*/
function getMaxIndex(rulesContext) {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
var horizon = 4; // Optimization horizon (The amount of steps required to achieve convergence)
var vl = Math.pow(horizon, 0.99); // Cautiousness parameter, used to control aggressiveness of the bitrate decision process.
var alpha = Math.max(Math.pow(horizon, 1), vl * Math.sqrt(horizon)); // Step size, used for gradient descent exploration granularity
var mediaInfo = rulesContext.getMediaInfo();
var mediaType = rulesContext.getMediaType();
var bitrates = mediaInfo.bitrateList.map(function (b) {
return b.bandwidth;
});
var bitrateCount = bitrates.length;
var scheduleController = rulesContext.getScheduleController();
var streamInfo = rulesContext.getStreamInfo();
var abrController = rulesContext.getAbrController();
var throughputHistory = abrController.getThroughputHistory();
var isDynamic = streamInfo && streamInfo.manifestInfo && streamInfo.manifestInfo.isDynamic;
var useL2AABR = rulesContext.useL2AABR();
var bufferLevel = dashMetrics.getCurrentBufferLevel(mediaType, true);
var safeThroughput = throughputHistory.getSafeAverageThroughput(mediaType, isDynamic);
var throughput = throughputHistory.getAverageThroughput(mediaType, isDynamic); // In kbits/s
var react = 2; // Reactiveness to volatility (abrupt throughput drops), used to re-calibrate Lagrangian multiplier Q
var latency = throughputHistory.getAverageLatency(mediaType);
var videoModel = rulesContext.getVideoModel();
var quality;
var currentPlaybackRate = videoModel.getPlaybackRate();
if (!rulesContext || !rulesContext.hasOwnProperty('getMediaInfo') || !rulesContext.hasOwnProperty('getMediaType') || !rulesContext.hasOwnProperty('getScheduleController') || !rulesContext.hasOwnProperty('getStreamInfo') || !rulesContext.hasOwnProperty('getAbrController') || !rulesContext.hasOwnProperty('useL2AABR')) {
return switchRequest;
}
switchRequest.reason = switchRequest.reason || {};
if (!useL2AABR || mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_7__["default"].AUDIO) {
// L2A decides bitrate only for video. Audio to be included in decision process in a later stage
return switchRequest;
}
scheduleController.setTimeToLoadDelay(0);
var l2AState = _getL2AState(rulesContext);
if (l2AState.state === L2A_STATE_ONE_BITRATE) {
// shouldn't even have been called
return switchRequest;
}
var l2AParameter = l2AParameterDict[mediaType];
if (!l2AParameter) {
return switchRequest;
}
switchRequest.reason.state = l2AState.state;
switchRequest.reason.throughput = throughput;
switchRequest.reason.latency = latency;
if (isNaN(throughput)) {
// still starting up - not enough information
return switchRequest;
}
switch (l2AState.state) {
case L2A_STATE_STARTUP:
quality = abrController.getQualityForBitrate(mediaInfo, safeThroughput, streamInfo.id, latency); //During strat-up phase abr.controller is responsible for bitrate decisions.
switchRequest.quality = quality;
switchRequest.reason.throughput = safeThroughput;
l2AState.lastQuality = quality;
if (!isNaN(l2AState.lastSegmentDurationS) && bufferLevel >= l2AParameter.B_target) {
l2AState.state = L2A_STATE_STEADY;
l2AParameter.Q = vl; // Initialization of Q langrangian multiplier
// Update of probability vector w, to be used in main adaptation logic of L2A below (steady state)
for (var i = 0; i < bitrateCount; ++i) {
if (i === l2AState.lastQuality) {
l2AParameter.prev_w[i] = 1;
} else {
l2AParameter.prev_w[i] = 0;
}
}
}
break;
// L2A_STATE_STARTUP
case L2A_STATE_STEADY:
var diff1 = []; //Used to calculate the difference between consecutive decisions (w-w_prev)
// Manual calculation of latency and throughput during previous request
var throughputMeasureTime = dashMetrics.getCurrentHttpRequest(mediaType).trace.reduce(function (a, b) {
return a + b.d;
}, 0);
var downloadBytes = dashMetrics.getCurrentHttpRequest(mediaType).trace.reduce(function (a, b) {
return a + b.b[0];
}, 0);
var lastthroughput = Math.round(8 * downloadBytes / throughputMeasureTime); // bits/ms = kbits/s
if (lastthroughput < 1) {
lastthroughput = 1;
} //To avoid division with 0 (avoid infinity) in case of an absolute network outage
var V = l2AState.lastSegmentDurationS;
var sign = 1; //Main adaptation logic of L2A-LL
for (var _i = 0; _i < bitrateCount; ++_i) {
bitrates[_i] = bitrates[_i] / 1000; // Originally in bps, now in Kbps
if (currentPlaybackRate * bitrates[_i] > lastthroughput) {
// In this case buffer would deplete, leading to a stall, which increases latency and thus the particular probability of selsection of bitrate[i] should be decreased.
sign = -1;
} // The objective of L2A is to minimize the overall latency=request-response time + buffer length after download+ potential stalling (if buffer less than chunk downlad time)
l2AParameter.w[_i] = l2AParameter.prev_w[_i] + sign * (V / (2 * alpha)) * ((l2AParameter.Q + vl) * (currentPlaybackRate * bitrates[_i] / lastthroughput)); //Lagrangian descent
} // Apply euclidean projection on w to ensure w expresses a probability distribution
l2AParameter.w = euclideanProjection(l2AParameter.w);
for (var _i2 = 0; _i2 < bitrateCount; ++_i2) {
diff1[_i2] = l2AParameter.w[_i2] - l2AParameter.prev_w[_i2];
l2AParameter.prev_w[_i2] = l2AParameter.w[_i2];
} // Lagrangian multiplier Q calculation:
l2AParameter.Q = Math.max(0, l2AParameter.Q - V + V * currentPlaybackRate * ((_dotmultiplication(bitrates, l2AParameter.prev_w) + _dotmultiplication(bitrates, diff1)) / lastthroughput)); // Quality is calculated as argmin of the absolute difference between available bitrates (bitrates[i]) and bitrate estimation (dotmultiplication(w,bitrates)).
var temp = [];
for (var _i3 = 0; _i3 < bitrateCount; ++_i3) {
temp[_i3] = Math.abs(bitrates[_i3] - _dotmultiplication(l2AParameter.w, bitrates));
} // Quality is calculated based on the probability distribution w (the output of L2A)
quality = temp.indexOf(Math.min.apply(Math, temp)); // We employ a cautious -stepwise- ascent
if (quality > l2AState.lastQuality) {
if (bitrates[l2AState.lastQuality + 1] <= lastthroughput) {
quality = l2AState.lastQuality + 1;
}
} // Provision against bitrate over-estimation, by re-calibrating the Lagrangian multiplier Q, to be taken into account for the next chunk
if (bitrates[quality] >= lastthroughput) {
l2AParameter.Q = react * Math.max(vl, l2AParameter.Q);
}
switchRequest.quality = quality;
switchRequest.reason.throughput = throughput;
switchRequest.reason.latency = latency;
switchRequest.reason.bufferLevel = bufferLevel;
l2AState.lastQuality = switchRequest.quality;
break;
default:
// should not arrive here, try to recover
logger.debug('L2A ABR rule invoked in bad state.');
switchRequest.quality = abrController.getQualityForBitrate(mediaInfo, safeThroughput, streamInfo.id, latency);
switchRequest.reason.state = l2AState.state;
switchRequest.reason.throughput = safeThroughput;
switchRequest.reason.latency = latency;
l2AState.state = L2A_STATE_STARTUP;
_clearL2AStateOnSeek(l2AState);
}
return switchRequest;
}
/**
* Reset objects to their initial state
* @private
*/
function _resetInitialSettings() {
l2AStateDict = {};
l2AParameterDict = {};
}
/**
* Reset the rule
*/
function reset() {
_resetInitialSettings();
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].METRIC_ADDED, _onMetricAdded, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].QUALITY_CHANGE_REQUESTED, _onQualityChangeRequested, instance);
}
instance = {
getMaxIndex: getMaxIndex,
reset: reset
};
setup();
return instance;
}
L2ARule.__dashjs_factory_name = 'L2ARule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(L2ARule));
/***/ }),
/***/ "./src/streaming/rules/abr/SwitchHistoryRule.js":
/*!******************************************************!*\
!*** ./src/streaming/rules/abr/SwitchHistoryRule.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
function SwitchHistoryRule() {
var context = this.context;
var instance, logger; //MAX_SWITCH is the number of drops made. It doesn't consider the size of the drop.
var MAX_SWITCH = 0.075; //Before this number of switch requests(no switch or actual), don't apply the rule.
//must be < SwitchRequestHistory SWITCH_REQUEST_HISTORY_DEPTH to enable rule
var SAMPLE_SIZE = 6;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
}
function getMaxIndex(rulesContext) {
var switchRequestHistory = rulesContext ? rulesContext.getSwitchHistory() : null;
var switchRequests = switchRequestHistory ? switchRequestHistory.getSwitchRequests() : [];
var drops = 0;
var noDrops = 0;
var dropSize = 0;
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create();
for (var i = 0; i < switchRequests.length; i++) {
if (switchRequests[i] !== undefined) {
drops += switchRequests[i].drops;
noDrops += switchRequests[i].noDrops;
dropSize += switchRequests[i].dropSize;
if (drops + noDrops >= SAMPLE_SIZE && drops / noDrops > MAX_SWITCH) {
switchRequest.quality = i > 0 && switchRequests[i].drops > 0 ? i - 1 : i;
switchRequest.reason = {
index: switchRequest.quality,
drops: drops,
noDrops: noDrops,
dropSize: dropSize
};
logger.debug('Switch history rule index: ' + switchRequest.quality + ' samples: ' + (drops + noDrops) + ' drops: ' + drops);
break;
}
}
}
return switchRequest;
}
instance = {
getMaxIndex: getMaxIndex
};
setup();
return instance;
}
SwitchHistoryRule.__dashjs_factory_name = 'SwitchHistoryRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(SwitchHistoryRule));
/***/ }),
/***/ "./src/streaming/rules/abr/ThroughputRule.js":
/*!***************************************************!*\
!*** ./src/streaming/rules/abr/ThroughputRule.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ThroughputRule(config) {
config = config || {};
var context = this.context;
var dashMetrics = config.dashMetrics;
var instance;
function checkConfig() {
if (!dashMetrics || !dashMetrics.hasOwnProperty('getCurrentBufferState')) {
throw new Error(_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].MISSING_CONFIG_ERROR);
}
}
function getMaxIndex(rulesContext) {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
if (!rulesContext || !rulesContext.hasOwnProperty('getMediaInfo') || !rulesContext.hasOwnProperty('getMediaType') || !rulesContext.hasOwnProperty('useBufferOccupancyABR') || !rulesContext.hasOwnProperty('getAbrController') || !rulesContext.hasOwnProperty('getScheduleController')) {
return switchRequest;
}
checkConfig();
var mediaInfo = rulesContext.getMediaInfo();
var mediaType = rulesContext.getMediaType();
var currentBufferState = dashMetrics.getCurrentBufferState(mediaType);
var scheduleController = rulesContext.getScheduleController();
var abrController = rulesContext.getAbrController();
var streamInfo = rulesContext.getStreamInfo();
var streamId = streamInfo ? streamInfo.id : null;
var isDynamic = streamInfo && streamInfo.manifestInfo ? streamInfo.manifestInfo.isDynamic : null;
var throughputHistory = abrController.getThroughputHistory();
var throughput = throughputHistory.getSafeAverageThroughput(mediaType, isDynamic);
var latency = throughputHistory.getAverageLatency(mediaType);
var useBufferOccupancyABR = rulesContext.useBufferOccupancyABR();
if (isNaN(throughput) || !currentBufferState || useBufferOccupancyABR) {
return switchRequest;
}
if (abrController.getAbandonmentStateFor(streamId, mediaType) !== _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].ABANDON_LOAD) {
if (currentBufferState.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_3__["default"].BUFFER_LOADED || isDynamic) {
switchRequest.quality = abrController.getQualityForBitrate(mediaInfo, throughput, streamId, latency);
scheduleController.setTimeToLoadDelay(0);
switchRequest.reason = {
throughput: throughput,
latency: latency
};
}
}
return switchRequest;
}
function reset() {// no persistent information to reset
}
instance = {
getMaxIndex: getMaxIndex,
reset: reset
};
return instance;
}
ThroughputRule.__dashjs_factory_name = 'ThroughputRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(ThroughputRule));
/***/ }),
/***/ "./src/streaming/rules/abr/lolp/LearningAbrController.js":
/*!***************************************************************!*\
!*** ./src/streaming/rules/abr/lolp/LearningAbrController.js ***!
\***************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../core/Debug */ "./src/core/Debug.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Authors:
* Abdelhak Bentaleb | National University of Singapore | bentaleb@comp.nus.edu.sg
* Mehmet N. Akcay | Ozyegin University | necmettin.akcay@ozu.edu.tr
* May Lim | National University of Singapore | maylim@comp.nus.edu.sg
*/
var WEIGHT_SELECTION_MODES = {
MANUAL: 'manual_weight_selection',
RANDOM: 'random_weight_selection',
DYNAMIC: 'dynamic_weight_selection'
};
function LearningAbrController() {
var context = this.context;
var instance, logger, somBitrateNeurons, bitrateNormalizationFactor, latencyNormalizationFactor, minBitrate, weights, sortedCenters, weightSelectionMode;
/**
* Setup the class
*/
function _setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
_resetInitialSettings();
}
/**
* Reset all values
*/
function reset() {
_resetInitialSettings();
}
/**
* Reset to initial settings
* @private
*/
function _resetInitialSettings() {
somBitrateNeurons = null;
bitrateNormalizationFactor = 1;
latencyNormalizationFactor = 100;
minBitrate = 0;
weights = null;
sortedCenters = null;
weightSelectionMode = WEIGHT_SELECTION_MODES.DYNAMIC;
}
/**
* Returns the maximum throughput
* @return {number}
* @private
*/
function _getMaxThroughput() {
var maxThroughput = 0;
if (somBitrateNeurons) {
for (var i = 0; i < somBitrateNeurons.length; i++) {
var neuron = somBitrateNeurons[i];
if (neuron.state.throughput > maxThroughput) {
maxThroughput = neuron.state.throughput;
}
}
}
return maxThroughput;
}
/**
*
* @param {array} w
* @return {number}
* @private
*/
function _getMagnitude(w) {
var magnitude = w.map(function (x) {
return Math.pow(x, 2);
}).reduce(function (sum, now) {
return sum + now;
});
return Math.sqrt(magnitude);
}
/**
*
* @param {array} a
* @param {array} b
* @param {array} w
* @return {number}
* @private
*/
function _getDistance(a, b, w) {
var sum = a.map(function (x, i) {
return w[i] * Math.pow(x - b[i], 2);
}) // square the difference*w
.reduce(function (sum, now) {
return sum + now;
}); // sum
var sign = sum < 0 ? -1 : 1;
return sign * Math.sqrt(Math.abs(sum));
}
/**
*
* @param {object} a
* @param {object} b
* @return {number}
* @private
*/
function _getNeuronDistance(a, b) {
var aState = [a.state.throughput, a.state.latency, a.state.rebuffer, a.state["switch"]];
var bState = [b.state.throughput, b.state.latency, b.state.rebuffer, b.state["switch"]];
return _getDistance(aState, bState, [1, 1, 1, 1]);
}
/**
*
* @param {object} winnerNeuron
* @param {array} somElements
* @param {array} x
* @private
*/
function _updateNeurons(winnerNeuron, somElements, x) {
for (var i = 0; i < somElements.length; i++) {
var somNeuron = somElements[i];
var sigma = 0.1;
var neuronDistance = _getNeuronDistance(somNeuron, winnerNeuron);
var neighbourHood = Math.exp(-1 * Math.pow(neuronDistance, 2) / (2 * Math.pow(sigma, 2)));
_updateNeuronState(somNeuron, x, neighbourHood);
}
}
/**
*
* @param {object} neuron
* @param {array} x
* @param {object} neighbourHood
* @private
*/
function _updateNeuronState(neuron, x, neighbourHood) {
var state = neuron.state;
var w = [0.01, 0.01, 0.01, 0.01]; // learning rate
state.throughput = state.throughput + (x[0] - state.throughput) * w[0] * neighbourHood;
state.latency = state.latency + (x[1] - state.latency) * w[1] * neighbourHood;
state.rebuffer = state.rebuffer + (x[2] - state.rebuffer) * w[2] * neighbourHood;
state["switch"] = state["switch"] + (x[3] - state["switch"]) * w[3] * neighbourHood;
}
/**
*
* @param {object} currentNeuron
* @param {number} currentThroughput
* @return {object}
* @private
*/
function _getDownShiftNeuron(currentNeuron, currentThroughput) {
var maxSuitableBitrate = 0;
var result = currentNeuron;
if (somBitrateNeurons) {
for (var i = 0; i < somBitrateNeurons.length; i++) {
var n = somBitrateNeurons[i];
if (n.bitrate < currentNeuron.bitrate && n.bitrate > maxSuitableBitrate && currentThroughput > n.bitrate) {
// possible downshiftable neuron
maxSuitableBitrate = n.bitrate;
result = n;
}
}
}
return result;
}
/**
*
* @param {object} mediaInfo
* @param {number} throughput
* @param {number} latency
* @param {number} bufferSize
* @param {number} playbackRate
* @param {number} currentQualityIndex
* @param {object} dynamicWeightsSelector
* @return {null|*}
*/
function getNextQuality(mediaInfo, throughput, latency, bufferSize, playbackRate, currentQualityIndex, dynamicWeightsSelector) {
// For Dynamic Weights Selector
var currentLatency = latency;
var currentBuffer = bufferSize;
var currentThroughput = throughput;
var somElements = _getSomBitrateNeurons(mediaInfo); // normalize throughput
var throughputNormalized = throughput / bitrateNormalizationFactor; // saturate values higher than 1
if (throughputNormalized > 1) {
throughputNormalized = _getMaxThroughput();
} // normalize latency
latency = latency / latencyNormalizationFactor;
var targetLatency = 0;
var targetRebufferLevel = 0;
var targetSwitch = 0; // 10K + video encoding is the recommended throughput
var throughputDelta = 10000;
logger.debug("getNextQuality called throughput:".concat(throughputNormalized, " latency:").concat(latency, " bufferSize:").concat(bufferSize, " currentQualityIndex:").concat(currentQualityIndex, " playbackRate:").concat(playbackRate));
var currentNeuron = somElements[currentQualityIndex];
var downloadTime = currentNeuron.bitrate * dynamicWeightsSelector.getSegmentDuration() / currentThroughput;
var rebuffer = Math.max(0, downloadTime - currentBuffer); // check buffer for possible stall
if (currentBuffer - downloadTime < dynamicWeightsSelector.getMinBuffer()) {
logger.debug("Buffer is low for bitrate= ".concat(currentNeuron.bitrate, " downloadTime=").concat(downloadTime, " currentBuffer=").concat(currentBuffer, " rebuffer=").concat(rebuffer));
return _getDownShiftNeuron(currentNeuron, currentThroughput).qualityIndex;
}
switch (weightSelectionMode) {
case WEIGHT_SELECTION_MODES.MANUAL:
_manualWeightSelection();
break;
case WEIGHT_SELECTION_MODES.RANDOM:
_randomWeightSelection(somElements);
break;
case WEIGHT_SELECTION_MODES.DYNAMIC:
_dynamicWeightSelection(dynamicWeightsSelector, somElements, currentLatency, currentBuffer, rebuffer, currentThroughput, playbackRate);
break;
default:
_dynamicWeightSelection(dynamicWeightsSelector, somElements, currentLatency, currentBuffer, rebuffer, currentThroughput, playbackRate);
}
var minDistance = null;
var minIndex = null;
var winnerNeuron = null;
for (var i = 0; i < somElements.length; i++) {
var somNeuron = somElements[i];
var somNeuronState = somNeuron.state;
var somData = [somNeuronState.throughput, somNeuronState.latency, somNeuronState.rebuffer, somNeuronState["switch"]];
var distanceWeights = weights.slice();
var nextBuffer = dynamicWeightsSelector.getNextBufferWithBitrate(somNeuron.bitrate, currentBuffer, currentThroughput);
var isBufferLow = nextBuffer < dynamicWeightsSelector.getMinBuffer();
if (isBufferLow) {
logger.debug("Buffer is low for bitrate=".concat(somNeuron.bitrate, " downloadTime=").concat(downloadTime, " currentBuffer=").concat(currentBuffer, " nextBuffer=").concat(nextBuffer));
} // special condition downshift immediately
if (somNeuron.bitrate > throughput - throughputDelta || isBufferLow) {
if (somNeuron.bitrate !== minBitrate) {
// encourage to pick smaller bitrates throughputWeight=100
distanceWeights[0] = 100;
}
} // calculate the distance with the target
var distance = _getDistance(somData, [throughputNormalized, targetLatency, targetRebufferLevel, targetSwitch], distanceWeights);
if (minDistance === null || distance < minDistance) {
minDistance = distance;
minIndex = somNeuron.qualityIndex;
winnerNeuron = somNeuron;
}
} // update current neuron and the neighbourhood with the calculated QoE
// will punish current if it is not picked
var bitrateSwitch = Math.abs(currentNeuron.bitrate - winnerNeuron.bitrate) / bitrateNormalizationFactor;
_updateNeurons(currentNeuron, somElements, [throughputNormalized, latency, rebuffer, bitrateSwitch]); // update bmu and neighbours with targetQoE=1, targetLatency=0
_updateNeurons(winnerNeuron, somElements, [throughputNormalized, targetLatency, targetRebufferLevel, bitrateSwitch]);
return minIndex;
}
/**
* Option 1: Manual weights
* @private
*/
function _manualWeightSelection() {
var throughputWeight = 0.4;
var latencyWeight = 0.4;
var bufferWeight = 0.4;
var switchWeight = 0.4;
weights = [throughputWeight, latencyWeight, bufferWeight, switchWeight]; // throughput, latency, buffer, switch
}
/**
* Option 2: Random (Xavier) weights
* @param {array} somElements
* @private
*/
function _randomWeightSelection(somElements) {
weights = _getXavierWeights(somElements.length, 4);
}
/**
* Dynamic Weight Selector weights
* @param {object} dynamicWeightsSelector
* @param {array} somElements
* @param {number} currentLatency
* @param {number} currentBuffer
* @param {number} rebuffer
* @param {number} currentThroughput
* @param {number} playbackRate
* @private
*/
function _dynamicWeightSelection(dynamicWeightsSelector, somElements, currentLatency, currentBuffer, rebuffer, currentThroughput, playbackRate) {
if (!weights) {
weights = sortedCenters[sortedCenters.length - 1];
} // Dynamic Weights Selector (step 2/2: find weights)
var weightVector = dynamicWeightsSelector.findWeightVector(somElements, currentLatency, currentBuffer, rebuffer, currentThroughput, playbackRate);
if (weightVector !== null && weightVector !== -1) {
// null: something went wrong, -1: constraints not met
weights = weightVector;
}
}
/**
*
* @param {number }neuronCount
* @param {number }weightCount
* @return {array}
* @private
*/
function _getXavierWeights(neuronCount, weightCount) {
var W = [];
var upperBound = Math.sqrt(2 / neuronCount);
for (var i = 0; i < weightCount; i++) {
W.push(Math.random() * upperBound);
}
weights = W;
return weights;
}
/**
*
* @param {object} mediaInfo
* @return {array}
* @private
*/
function _getSomBitrateNeurons(mediaInfo) {
if (!somBitrateNeurons) {
somBitrateNeurons = [];
var bitrateList = mediaInfo.bitrateList;
var bitrateVector = [];
minBitrate = bitrateList[0].bandwidth;
bitrateList.forEach(function (element) {
bitrateVector.push(element.bandwidth);
if (element.bandwidth < minBitrate) {
minBitrate = element.bandwidth;
}
});
bitrateNormalizationFactor = _getMagnitude(bitrateVector);
for (var i = 0; i < bitrateList.length; i++) {
var neuron = {
qualityIndex: i,
bitrate: bitrateList[i].bandwidth,
state: {
// normalize throughputs
throughput: bitrateList[i].bandwidth / bitrateNormalizationFactor,
latency: 0,
rebuffer: 0,
"switch": 0
}
};
somBitrateNeurons.push(neuron);
}
sortedCenters = _getInitialKmeansPlusPlusCenters(somBitrateNeurons);
}
return somBitrateNeurons;
}
/**
*
* @param {number} size
* @return {array}
* @private
*/
function _getRandomData(size) {
var dataArray = [];
for (var i = 0; i < size; i++) {
var data = [Math.random() * _getMaxThroughput(), //throughput
Math.random(), //latency
Math.random(), //buffersize
Math.random() //switch
];
dataArray.push(data);
}
return dataArray;
}
/**
*
* @param {array} somElements
* @return {array}
* @private
*/
function _getInitialKmeansPlusPlusCenters(somElements) {
var centers = [];
var randomDataSet = _getRandomData(Math.pow(somElements.length, 2));
centers.push(randomDataSet[0]);
var distanceWeights = [1, 1, 1, 1];
for (var k = 1; k < somElements.length; k++) {
var nextPoint = null;
var _maxDistance = null;
for (var i = 0; i < randomDataSet.length; i++) {
var currentPoint = randomDataSet[i];
var minDistance = null;
for (var j = 0; j < centers.length; j++) {
var distance = _getDistance(currentPoint, centers[j], distanceWeights);
if (minDistance === null || distance < minDistance) {
minDistance = distance;
}
}
if (_maxDistance === null || minDistance > _maxDistance) {
nextPoint = currentPoint;
_maxDistance = minDistance;
}
}
centers.push(nextPoint);
} // find the least similar center
var maxDistance = null;
var leastSimilarIndex = null;
for (var _i = 0; _i < centers.length; _i++) {
var _distance = 0;
for (var _j = 0; _j < centers.length; _j++) {
if (_i === _j) continue;
_distance += _getDistance(centers[_i], centers[_j], distanceWeights);
}
if (maxDistance === null || _distance > maxDistance) {
maxDistance = _distance;
leastSimilarIndex = _i;
}
} // move centers to sortedCenters
var sortedCenters = [];
sortedCenters.push(centers[leastSimilarIndex]);
centers.splice(leastSimilarIndex, 1);
while (centers.length > 0) {
var _minDistance = null;
var minIndex = null;
for (var _i2 = 0; _i2 < centers.length; _i2++) {
var _distance2 = _getDistance(sortedCenters[0], centers[_i2], distanceWeights);
if (_minDistance === null || _distance2 < _minDistance) {
_minDistance = _distance2;
minIndex = _i2;
}
}
sortedCenters.push(centers[minIndex]);
centers.splice(minIndex, 1);
}
return sortedCenters;
}
instance = {
getNextQuality: getNextQuality,
reset: reset
};
_setup();
return instance;
}
LearningAbrController.__dashjs_factory_name = 'LearningAbrController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(LearningAbrController));
/***/ }),
/***/ "./src/streaming/rules/abr/lolp/LoLpQoEEvaluator.js":
/*!**********************************************************!*\
!*** ./src/streaming/rules/abr/lolp/LoLpQoEEvaluator.js ***!
\**********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _QoeInfo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./QoeInfo */ "./src/streaming/rules/abr/lolp/QoeInfo.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Authors:
* Abdelhak Bentaleb | National University of Singapore | bentaleb@comp.nus.edu.sg
* Mehmet N. Akcay | Ozyegin University | necmettin.akcay@ozu.edu.tr
* May Lim | National University of Singapore | maylim@comp.nus.edu.sg
*/
function LoLpQoeEvaluator() {
var instance, voPerSegmentQoeInfo, segmentDuration, maxBitrateKbps, minBitrateKbps;
function _setup() {
_resetInitialSettings();
}
function _resetInitialSettings() {
voPerSegmentQoeInfo = null;
segmentDuration = null;
maxBitrateKbps = null;
minBitrateKbps = null;
}
function setupPerSegmentQoe(sDuration, maxBrKbps, minBrKbps) {
// Set up Per Segment QoeInfo
voPerSegmentQoeInfo = _createQoeInfo('segment', sDuration, maxBrKbps, minBrKbps);
segmentDuration = sDuration;
maxBitrateKbps = maxBrKbps;
minBitrateKbps = minBrKbps;
}
function _createQoeInfo(fragmentType, fragmentDuration, maxBitrateKbps, minBitrateKbps) {
/*
* [Weights][Source: Abdelhak Bentaleb, 2020 (last updated: 30 Mar 2020)]
* bitrateReward: segment duration, e.g. 0.5s
* bitrateSwitchPenalty: 0.02s or 1s if the bitrate switch is too important
* rebufferPenalty: max encoding bitrate, e.g. 1000kbps
* latencyPenalty: if L ≤ 1.1 seconds then = min encoding bitrate * 0.05, otherwise = max encoding bitrate * 0.1
* playbackSpeedPenalty: min encoding bitrate, e.g. 200kbps
*/
// Create new QoeInfo object
var qoeInfo = new _QoeInfo__WEBPACK_IMPORTED_MODULE_1__["default"]();
qoeInfo.type = fragmentType; // Set weight: bitrateReward
// set some safe value, else consider throwing error
if (!fragmentDuration) {
qoeInfo.weights.bitrateReward = 1;
} else {
qoeInfo.weights.bitrateReward = fragmentDuration;
} // Set weight: bitrateSwitchPenalty
// qoeInfo.weights.bitrateSwitchPenalty = 0.02;
qoeInfo.weights.bitrateSwitchPenalty = 1; // Set weight: rebufferPenalty
// set some safe value, else consider throwing error
if (!maxBitrateKbps) {
qoeInfo.weights.rebufferPenalty = 1000;
} else {
qoeInfo.weights.rebufferPenalty = maxBitrateKbps;
} // Set weight: latencyPenalty
qoeInfo.weights.latencyPenalty = [];
qoeInfo.weights.latencyPenalty.push({
threshold: 1.1,
penalty: minBitrateKbps * 0.05
});
qoeInfo.weights.latencyPenalty.push({
threshold: 100000000,
penalty: maxBitrateKbps * 0.1
}); // Set weight: playbackSpeedPenalty
if (!minBitrateKbps) qoeInfo.weights.playbackSpeedPenalty = 200; // set some safe value, else consider throwing error
else qoeInfo.weights.playbackSpeedPenalty = minBitrateKbps;
return qoeInfo;
}
function logSegmentMetrics(segmentBitrate, segmentRebufferTime, currentLatency, currentPlaybackSpeed) {
if (voPerSegmentQoeInfo) {
_logMetricsInQoeInfo(segmentBitrate, segmentRebufferTime, currentLatency, currentPlaybackSpeed, voPerSegmentQoeInfo);
}
}
function _logMetricsInQoeInfo(bitrate, rebufferTime, latency, playbackSpeed, qoeInfo) {
// Update: bitrate Weighted Sum value
qoeInfo.bitrateWSum += qoeInfo.weights.bitrateReward * bitrate; // Update: bitrateSwitch Weighted Sum value
if (qoeInfo.lastBitrate) {
qoeInfo.bitrateSwitchWSum += qoeInfo.weights.bitrateSwitchPenalty * Math.abs(bitrate - qoeInfo.lastBitrate);
}
qoeInfo.lastBitrate = bitrate; // Update: rebuffer Weighted Sum value
qoeInfo.rebufferWSum += qoeInfo.weights.rebufferPenalty * rebufferTime; // Update: latency Weighted Sum value
for (var i = 0; i < qoeInfo.weights.latencyPenalty.length; i++) {
var latencyRange = qoeInfo.weights.latencyPenalty[i];
if (latency <= latencyRange.threshold) {
qoeInfo.latencyWSum += latencyRange.penalty * latency;
break;
}
} // Update: playbackSpeed Weighted Sum value
qoeInfo.playbackSpeedWSum += qoeInfo.weights.playbackSpeedPenalty * Math.abs(1 - playbackSpeed); // Update: Total Qoe value
qoeInfo.totalQoe = qoeInfo.bitrateWSum - qoeInfo.bitrateSwitchWSum - qoeInfo.rebufferWSum - qoeInfo.latencyWSum - qoeInfo.playbackSpeedWSum;
} // Returns current Per Segment QoeInfo
function getPerSegmentQoe() {
return voPerSegmentQoeInfo;
} // For one-time use only
// Returns totalQoe based on a single set of metrics.
function calculateSingleUseQoe(segmentBitrate, segmentRebufferTime, currentLatency, currentPlaybackSpeed) {
var singleUseQoeInfo = null;
if (segmentDuration && maxBitrateKbps && minBitrateKbps) {
singleUseQoeInfo = _createQoeInfo('segment', segmentDuration, maxBitrateKbps, minBitrateKbps);
}
if (singleUseQoeInfo) {
_logMetricsInQoeInfo(segmentBitrate, segmentRebufferTime, currentLatency, currentPlaybackSpeed, singleUseQoeInfo);
return singleUseQoeInfo.totalQoe;
} else {
// Something went wrong..
return 0;
}
}
function reset() {
_resetInitialSettings();
}
instance = {
setupPerSegmentQoe: setupPerSegmentQoe,
logSegmentMetrics: logSegmentMetrics,
getPerSegmentQoe: getPerSegmentQoe,
calculateSingleUseQoe: calculateSingleUseQoe,
reset: reset
};
_setup();
return instance;
}
LoLpQoeEvaluator.__dashjs_factory_name = 'LoLpQoeEvaluator';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(LoLpQoeEvaluator));
/***/ }),
/***/ "./src/streaming/rules/abr/lolp/LoLpRule.js":
/*!**************************************************!*\
!*** ./src/streaming/rules/abr/lolp/LoLpRule.js ***!
\**************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _LearningAbrController__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./LearningAbrController */ "./src/streaming/rules/abr/lolp/LearningAbrController.js");
/* harmony import */ var _LoLpQoEEvaluator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./LoLpQoEEvaluator */ "./src/streaming/rules/abr/lolp/LoLpQoEEvaluator.js");
/* harmony import */ var _SwitchRequest__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../SwitchRequest */ "./src/streaming/rules/SwitchRequest.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _LoLpWeightSelector__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./LoLpWeightSelector */ "./src/streaming/rules/abr/lolp/LoLpWeightSelector.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../../constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Authors:
* Abdelhak Bentaleb | National University of Singapore | bentaleb@comp.nus.edu.sg
* Mehmet N. Akcay | Ozyegin University | necmettin.akcay@ozu.edu.tr
* May Lim | National University of Singapore | maylim@comp.nus.edu.sg
*/
var DWS_TARGET_LATENCY = 1.5;
var DWS_BUFFER_MIN = 0.3;
function LoLPRule(config) {
config = config || {};
var dashMetrics = config.dashMetrics;
var context = this.context;
var logger, instance, learningController, qoeEvaluator;
function _setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
learningController = Object(_LearningAbrController__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create();
qoeEvaluator = Object(_LoLpQoEEvaluator__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create();
}
function getMaxIndex(rulesContext) {
try {
var switchRequest = Object(_SwitchRequest__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create();
var mediaType = rulesContext.getMediaInfo().type;
var abrController = rulesContext.getAbrController();
var streamInfo = rulesContext.getStreamInfo();
var currentQuality = abrController.getQualityFor(mediaType, streamInfo.id);
var mediaInfo = rulesContext.getMediaInfo();
var bufferStateVO = dashMetrics.getCurrentBufferState(mediaType);
var scheduleController = rulesContext.getScheduleController();
var currentBufferLevel = dashMetrics.getCurrentBufferLevel(mediaType, true);
var isDynamic = streamInfo && streamInfo.manifestInfo ? streamInfo.manifestInfo.isDynamic : null;
var playbackController = scheduleController.getPlaybackController();
var latency = playbackController.getCurrentLiveLatency();
if (!rulesContext.useLoLPABR() || mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_7__["default"].AUDIO) {
return switchRequest;
}
if (!latency) {
latency = 0;
}
var playbackRate = playbackController.getPlaybackRate();
var throughputHistory = abrController.getThroughputHistory();
var throughput = throughputHistory.getSafeAverageThroughput(mediaType, isDynamic);
logger.debug("Throughput ".concat(Math.round(throughput), " kbps"));
if (isNaN(throughput) || !bufferStateVO) {
return switchRequest;
}
if (abrController.getAbandonmentStateFor(streamInfo.id, mediaType) === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_5__["default"].ABANDON_LOAD) {
return switchRequest;
} // QoE parameters
var bitrateList = mediaInfo.bitrateList; // [{bandwidth: 200000, width: 640, height: 360}, ...]
var segmentDuration = rulesContext.getRepresentationInfo().fragmentDuration;
var minBitrateKbps = bitrateList[0].bandwidth / 1000.0; // min bitrate level
var maxBitrateKbps = bitrateList[bitrateList.length - 1].bandwidth / 1000.0; // max bitrate level
for (var i = 0; i < bitrateList.length; i++) {
// in case bitrateList is not sorted as expected
var b = bitrateList[i].bandwidth / 1000.0;
if (b > maxBitrateKbps) maxBitrateKbps = b;else if (b < minBitrateKbps) {
minBitrateKbps = b;
}
} // Learning rule pre-calculations
var currentBitrate = bitrateList[currentQuality].bandwidth;
var currentBitrateKbps = currentBitrate / 1000.0;
var httpRequest = dashMetrics.getCurrentHttpRequest(mediaType, true);
var lastFragmentDownloadTime = (httpRequest.tresponse.getTime() - httpRequest.trequest.getTime()) / 1000;
var segmentRebufferTime = lastFragmentDownloadTime > segmentDuration ? lastFragmentDownloadTime - segmentDuration : 0;
qoeEvaluator.setupPerSegmentQoe(segmentDuration, maxBitrateKbps, minBitrateKbps);
qoeEvaluator.logSegmentMetrics(currentBitrateKbps, segmentRebufferTime, latency, playbackRate);
/*
* Dynamic Weights Selector (step 1/2: initialization)
*/
var dynamicWeightsSelector = Object(_LoLpWeightSelector__WEBPACK_IMPORTED_MODULE_6__["default"])(context).create({
targetLatency: DWS_TARGET_LATENCY,
bufferMin: DWS_BUFFER_MIN,
segmentDuration: segmentDuration,
qoeEvaluator: qoeEvaluator
});
/*
* Select next quality
*/
switchRequest.quality = learningController.getNextQuality(mediaInfo, throughput * 1000, latency, currentBufferLevel, playbackRate, currentQuality, dynamicWeightsSelector);
switchRequest.reason = {
throughput: throughput,
latency: latency
};
switchRequest.priority = _SwitchRequest__WEBPACK_IMPORTED_MODULE_4__["default"].PRIORITY.STRONG;
scheduleController.setTimeToLoadDelay(0);
if (switchRequest.quality !== currentQuality) {
console.log('[TgcLearningRule][' + mediaType + '] requesting switch to index: ', switchRequest.quality, 'Average throughput', Math.round(throughput), 'kbps');
}
return switchRequest;
} catch (e) {
throw e;
}
}
/**
* Reset objects to their initial state
* @private
*/
function _resetInitialSettings() {
learningController.reset();
qoeEvaluator.reset();
}
/**
* Reset the rule
*/
function reset() {
_resetInitialSettings();
}
instance = {
getMaxIndex: getMaxIndex,
reset: reset
};
_setup();
return instance;
}
LoLPRule.__dashjs_factory_name = 'LoLPRule';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(LoLPRule));
/***/ }),
/***/ "./src/streaming/rules/abr/lolp/LoLpWeightSelector.js":
/*!************************************************************!*\
!*** ./src/streaming/rules/abr/lolp/LoLpWeightSelector.js ***!
\************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Authors:
* Abdelhak Bentaleb | National University of Singapore | bentaleb@comp.nus.edu.sg
* Mehmet N. Akcay | Ozyegin University | necmettin.akcay@ozu.edu.tr
* May Lim | National University of Singapore | maylim@comp.nus.edu.sg
*/
function LoLpWeightSelector(config) {
var targetLatency = config.targetLatency;
var bufferMin = config.bufferMin;
var segmentDuration = config.segmentDuration;
var qoeEvaluator = config.qoeEvaluator;
var instance, valueList, weightTypeCount, weightOptions, previousLatency;
/**
*
* @private
*/
function _setup() {
_resetInitialSettings();
}
/**
*
* @private
*/
function _resetInitialSettings() {
valueList = [0.2, 0.4, 0.6, 0.8, 1];
weightTypeCount = 4;
weightOptions = _getPermutations(valueList, weightTypeCount);
previousLatency = 0;
}
/**
* Next, at each segment boundary, ABR to input current neurons and target state (only used in Method II) to find the desired weight vector
* @param {array} neurons
* @param {number} currentLatency
* @param {number} currentBuffer
* @param {number} currentRebuffer
* @param {number} currentThroughput
* @param {number} playbackRate
* @return {null}
* @private
*/
function findWeightVector(neurons, currentLatency, currentBuffer, currentRebuffer, currentThroughput, playbackRate) {
var maxQoE = null;
var winnerWeights = null;
var winnerBitrate = null;
var deltaLatency = Math.abs(currentLatency - previousLatency); // For each neuron, m
neurons.forEach(function (neuron) {
// For each possible weight vector, z
// E.g. For [ throughput, latency, buffer, playbackRate, QoE ]
// Possible weightVector = [ 0.2, 0.4, 0.2, 0, 0.2 ]
weightOptions.forEach(function (weightVector) {
// Apply weightVector to neuron, compute utility and determine winnerWeights
// Method I: Utility based on QoE given current state
var weightsObj = {
throughput: weightVector[0],
latency: weightVector[1],
buffer: weightVector[2],
"switch": weightVector[3]
};
var downloadTime = neuron.bitrate * segmentDuration / currentThroughput;
var nextBuffer = getNextBuffer(currentBuffer, downloadTime);
var rebuffer = Math.max(0.00001, downloadTime - nextBuffer);
var wt;
if (weightsObj.buffer === 0) {
wt = 10;
} else {
wt = 1 / weightsObj.buffer;
}
var weightedRebuffer = wt * rebuffer;
if (weightsObj.latency === 0) {
wt = 10;
} else {
wt = 1 / weightsObj.latency; // inverse the weight because wt and latency should have positive relationship, i.e., higher latency = higher wt
}
var weightedLatency = wt * neuron.state.latency;
var totalQoE = qoeEvaluator.calculateSingleUseQoe(neuron.bitrate, weightedRebuffer, weightedLatency, playbackRate);
if ((maxQoE === null || totalQoE > maxQoE) && _checkConstraints(currentLatency, nextBuffer, deltaLatency)) {
maxQoE = totalQoE;
winnerWeights = weightVector;
winnerBitrate = neuron.bitrate;
}
});
}); // winnerWeights was found, check if constraints are satisfied
if (winnerWeights === null && winnerBitrate === null) {
winnerWeights = -1;
}
previousLatency = currentLatency;
return winnerWeights;
}
/**
*
* @param {number} nextLatency
* @param {number} nextBuffer
* @param {number} deltaLatency
* @return {boolean}
* @private
*/
function _checkConstraints(nextLatency, nextBuffer, deltaLatency) {
// A1
// disabled till we find a better way of estimating latency
// fails for all with current value
if (nextLatency > targetLatency + deltaLatency) {
return false;
}
return nextBuffer >= bufferMin;
}
/**
*
* @param {array} list
* @param {number} length
* @return {*}
* @private
*/
function _getPermutations(list, length) {
// Copy initial values as arrays
var perm = list.map(function (val) {
return [val];
}); // Our permutation generator
var generate = function generate(perm, length, currLen) {
// Reached desired length
if (currLen === length) {
return perm;
} // For each existing permutation
var len = perm.length;
for (var i = 0; i < len; i++) {
var currPerm = perm.shift(); // Create new permutation
for (var k = 0; k < list.length; k++) {
perm.push(currPerm.concat(list[k]));
}
} // Recurse
return generate(perm, length, currLen + 1);
}; // Start with size 1 because of initial values
return generate(perm, length, 1);
}
/**
*
* @return {number}
*/
function getMinBuffer() {
return bufferMin;
}
/**
*
* @return {number}
*/
function getSegmentDuration() {
return segmentDuration;
}
/**
*
* @param {number} bitrateToDownload
* @param {number} currentBuffer
* @param {number} currentThroughput
* @return {number}
*/
function getNextBufferWithBitrate(bitrateToDownload, currentBuffer, currentThroughput) {
var downloadTime = bitrateToDownload * segmentDuration / currentThroughput;
return getNextBuffer(currentBuffer, downloadTime);
}
/**
*
* @param {number} currentBuffer
* @param {number} downloadTime
* @return {number}
*/
function getNextBuffer(currentBuffer, downloadTime) {
var segmentDuration = getSegmentDuration();
var nextBuffer;
if (downloadTime > segmentDuration) {
nextBuffer = currentBuffer - segmentDuration;
} else {
nextBuffer = currentBuffer + segmentDuration - downloadTime;
}
return nextBuffer;
}
instance = {
getMinBuffer: getMinBuffer,
getSegmentDuration: getSegmentDuration,
getNextBufferWithBitrate: getNextBufferWithBitrate,
getNextBuffer: getNextBuffer,
findWeightVector: findWeightVector
};
_setup();
return instance;
}
LoLpWeightSelector.__dashjs_factory_name = 'LoLpWeightSelector';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(LoLpWeightSelector));
/***/ }),
/***/ "./src/streaming/rules/abr/lolp/QoeInfo.js":
/*!*************************************************!*\
!*** ./src/streaming/rules/abr/lolp/QoeInfo.js ***!
\*************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var QoeInfo = function QoeInfo() {
_classCallCheck(this, QoeInfo);
// Type e.g. 'segment'
this.type = null; // Store lastBitrate for calculation of bitrateSwitchWSum
this.lastBitrate = null; // Weights for each Qoe factor
this.weights = {};
this.weights.bitrateReward = null;
this.weights.bitrateSwitchPenalty = null;
this.weights.rebufferPenalty = null;
this.weights.latencyPenalty = null;
this.weights.playbackSpeedPenalty = null; // Weighted Sum for each Qoe factor
this.bitrateWSum = 0; // kbps
this.bitrateSwitchWSum = 0; // kbps
this.rebufferWSum = 0; // seconds
this.latencyWSum = 0; // seconds
this.playbackSpeedWSum = 0; // e.g. 0.95, 1.0, 1.05
// Store total Qoe value based on current Weighted Sum values
this.totalQoe = 0;
};
/* harmony default export */ __webpack_exports__["default"] = (QoeInfo);
/***/ }),
/***/ "./src/streaming/text/EmbeddedTextHtmlRender.js":
/*!******************************************************!*\
!*** ./src/streaming/text/EmbeddedTextHtmlRender.js ***!
\******************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function EmbeddedTextHtmlRender() {
var captionId = 0;
var instance;
/* HTML Rendering functions */
function checkIndent(chars) {
var line = '';
for (var c = 0; c < chars.length; ++c) {
var uc = chars[c];
line += uc.uchar;
}
var l = line.length;
var ll = line.replace(/^\s+/, '').length;
return l - ll;
}
function getRegionProperties(region) {
return 'left: ' + region.x * 3.125 + '%; top: ' + region.y1 * 6.66 + '%; width: ' + (100 - region.x * 3.125) + '%; height: ' + Math.max(region.y2 - 1 - region.y1, 1) * 6.66 + '%; align-items: flex-start; overflow: visible; -webkit-writing-mode: horizontal-tb;';
}
function createRGB(color) {
if (color === 'red') {
return 'rgb(255, 0, 0)';
} else if (color === 'green') {
return 'rgb(0, 255, 0)';
} else if (color === 'blue') {
return 'rgb(0, 0, 255)';
} else if (color === 'cyan') {
return 'rgb(0, 255, 255)';
} else if (color === 'magenta') {
return 'rgb(255, 0, 255)';
} else if (color === 'yellow') {
return 'rgb(255, 255, 0)';
} else if (color === 'white') {
return 'rgb(255, 255, 255)';
} else if (color === 'black') {
return 'rgb(0, 0, 0)';
}
return color;
}
function getStyle(videoElement, style) {
var fontSize = videoElement.videoHeight / 15.0;
if (style) {
return 'font-size: ' + fontSize + 'px; font-family: Menlo, Consolas, \'Cutive Mono\', monospace; color: ' + (style.foreground ? createRGB(style.foreground) : 'rgb(255, 255, 255)') + '; font-style: ' + (style.italics ? 'italic' : 'normal') + '; text-decoration: ' + (style.underline ? 'underline' : 'none') + '; white-space: pre; background-color: ' + (style.background ? createRGB(style.background) : 'transparent') + ';';
} else {
return 'font-size: ' + fontSize + 'px; font-family: Menlo, Consolas, \'Cutive Mono\', monospace; justify-content: flex-start; text-align: left; color: rgb(255, 255, 255); font-style: normal; white-space: pre; line-height: normal; font-weight: normal; text-decoration: none; width: 100%; display: flex;';
}
}
function ltrim(s) {
return s.replace(/^\s+/g, '');
}
function rtrim(s) {
return s.replace(/\s+$/g, '');
}
function createHTMLCaptionsFromScreen(videoElement, startTime, endTime, captionScreen) {
var currRegion = null;
var existingRegion = null;
var lastRowHasText = false;
var lastRowIndentL = -1;
var currP = {
start: startTime,
end: endTime,
spans: []
};
var currentStyle = 'style_cea608_white_black';
var seenRegions = {};
var styleStates = {};
var regions = [];
var r, s;
for (r = 0; r < 15; ++r) {
var row = captionScreen.rows[r];
var line = '';
var prevPenState = null;
if (false === row.isEmpty()) {
/* Row is not empty */
/* Get indentation of this row */
var rowIndent = checkIndent(row.chars);
/* Create a new region is there is none */
if (currRegion === null) {
currRegion = {
x: rowIndent,
y1: r,
y2: r + 1,
p: []
};
}
/* Check if indentation has changed and we had text of last row */
if (rowIndent !== lastRowIndentL && lastRowHasText) {
currRegion.p.push(currP);
currP = {
start: startTime,
end: endTime,
spans: []
};
currRegion.y2 = r;
currRegion.name = 'region_' + currRegion.x + '_' + currRegion.y1 + '_' + currRegion.y2;
if (false === seenRegions.hasOwnProperty(currRegion.name)) {
regions.push(currRegion);
seenRegions[currRegion.name] = currRegion;
} else {
existingRegion = seenRegions[currRegion.name];
existingRegion.p.contat(currRegion.p);
}
currRegion = {
x: rowIndent,
y1: r,
y2: r + 1,
p: []
};
}
for (var c = 0; c < row.chars.length; ++c) {
var uc = row.chars[c];
var currPenState = uc.penState;
if (prevPenState === null || !currPenState.equals(prevPenState)) {
if (line.trim().length > 0) {
currP.spans.push({
name: currentStyle,
line: line,
row: r
});
line = '';
}
var currPenStateString = 'style_cea608_' + currPenState.foreground + '_' + currPenState.background;
if (currPenState.underline) {
currPenStateString += '_underline';
}
if (currPenState.italics) {
currPenStateString += '_italics';
}
if (!styleStates.hasOwnProperty(currPenStateString)) {
styleStates[currPenStateString] = JSON.parse(JSON.stringify(currPenState));
}
prevPenState = currPenState;
currentStyle = currPenStateString;
}
line += uc.uchar;
}
if (line.trim().length > 0) {
currP.spans.push({
name: currentStyle,
line: line,
row: r
});
}
lastRowHasText = true;
lastRowIndentL = rowIndent;
} else {
/* Row is empty */
lastRowHasText = false;
lastRowIndentL = -1;
if (currRegion) {
currRegion.p.push(currP);
currP = {
start: startTime,
end: endTime,
spans: []
};
currRegion.y2 = r;
currRegion.name = 'region_' + currRegion.x + '_' + currRegion.y1 + '_' + currRegion.y2;
if (false === seenRegions.hasOwnProperty(currRegion.name)) {
regions.push(currRegion);
seenRegions[currRegion.name] = currRegion;
} else {
existingRegion = seenRegions[currRegion.name];
existingRegion.p.contat(currRegion.p);
}
currRegion = null;
}
}
}
if (currRegion) {
currRegion.p.push(currP);
currRegion.y2 = r + 1;
currRegion.name = 'region_' + currRegion.x + '_' + currRegion.y1 + '_' + currRegion.y2;
if (false === seenRegions.hasOwnProperty(currRegion.name)) {
regions.push(currRegion);
seenRegions[currRegion.name] = currRegion;
} else {
existingRegion = seenRegions[currRegion.name];
existingRegion.p.contat(currRegion.p);
}
currRegion = null;
}
var captionsArray = [];
/* Loop thru regions */
for (r = 0; r < regions.length; ++r) {
var region = regions[r];
var cueID = 'sub_cea608_' + captionId++;
var finalDiv = document.createElement('div');
finalDiv.id = cueID;
var cueRegionProperties = getRegionProperties(region);
finalDiv.style.cssText = 'position: absolute; margin: 0; display: flex; box-sizing: border-box; pointer-events: none;' + cueRegionProperties;
var bodyDiv = document.createElement('div');
bodyDiv.className = 'paragraph bodyStyle';
bodyDiv.style.cssText = getStyle(videoElement);
var cueUniWrapper = document.createElement('div');
cueUniWrapper.className = 'cueUniWrapper';
cueUniWrapper.style.cssText = 'unicode-bidi: normal; direction: ltr;';
for (var p = 0; p < region.p.length; ++p) {
var ptag = region.p[p];
var lastSpanRow = 0;
for (s = 0; s < ptag.spans.length; ++s) {
var span = ptag.spans[s];
if (span.line.length > 0) {
if (s !== 0 && lastSpanRow != span.row) {
var brElement = document.createElement('br');
brElement.className = 'lineBreak';
cueUniWrapper.appendChild(brElement);
}
var sameRow = false;
if (lastSpanRow === span.row) {
sameRow = true;
}
lastSpanRow = span.row;
var spanStyle = styleStates[span.name];
var spanElement = document.createElement('span');
spanElement.className = 'spanPadding ' + span.name + ' customSpanColor';
spanElement.style.cssText = getStyle(videoElement, spanStyle);
/* If this is not the first span, and it's on the same
* row as the last one */
if (s !== 0 && sameRow) {
/* and it's the last span on this row */
if (s === ptag.spans.length - 1) {
/* trim only the right side */
spanElement.textContent = rtrim(span.line);
} else {
/* don't trim at all */
spanElement.textContent = span.line;
}
} else {
/* if there is more than 1 span and this isn't the last span */
if (ptag.spans.length > 1 && s < ptag.spans.length - 1) {
/* Check if next text is on same row */
if (span.row === ptag.spans[s + 1].row) {
/* Next element on same row, trim start */
spanElement.textContent = ltrim(span.line);
} else {
/* Different rows, trim both */
spanElement.textContent = span.line.trim();
}
} else {
spanElement.textContent = span.line.trim();
}
}
cueUniWrapper.appendChild(spanElement);
}
}
}
bodyDiv.appendChild(cueUniWrapper);
finalDiv.appendChild(bodyDiv);
var fontSize = {
'bodyStyle': ['%', 90]
};
for (var _s in styleStates) {
if (styleStates.hasOwnProperty(_s)) {
fontSize[_s] = ['%', 90];
}
}
captionsArray.push({
type: 'html',
start: startTime,
end: endTime,
cueHTMLElement: finalDiv,
cueID: cueID,
cellResolution: [32, 15],
isFromCEA608: true,
fontSize: fontSize,
lineHeight: {},
linePadding: {}
});
}
return captionsArray;
}
instance = {
createHTMLCaptionsFromScreen: createHTMLCaptionsFromScreen
};
return instance;
}
EmbeddedTextHtmlRender.__dashjs_factory_name = 'EmbeddedTextHtmlRender';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(EmbeddedTextHtmlRender));
/***/ }),
/***/ "./src/streaming/text/NotFragmentedTextBufferController.js":
/*!*****************************************************************!*\
!*** ./src/streaming/text/NotFragmentedTextBufferController.js ***!
\*****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _utils_InitCache__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/InitCache */ "./src/streaming/utils/InitCache.js");
/* harmony import */ var _SourceBufferSink__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../SourceBufferSink */ "./src/streaming/SourceBufferSink.js");
/* harmony import */ var _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../streaming/vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var BUFFER_CONTROLLER_TYPE = 'NotFragmentedTextBufferController';
function NotFragmentedTextBufferController(config) {
config = config || {};
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
var textController = config.textController;
var errHandler = config.errHandler;
var streamInfo = config.streamInfo;
var type = config.type;
var instance, isBufferingCompleted, initialized, mediaSource, sourceBufferSink, initCache;
function setup() {
initialized = false;
mediaSource = null;
isBufferingCompleted = false;
initCache = Object(_utils_InitCache__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, instance);
}
function getBufferControllerType() {
return BUFFER_CONTROLLER_TYPE;
}
function initialize(source) {
setMediaSource(source);
}
function createBufferSink(mediaInfo) {
return new Promise(function (resolve, reject) {
try {
sourceBufferSink = Object(_SourceBufferSink__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
mediaSource: mediaSource,
textController: textController,
eventBus: eventBus
});
sourceBufferSink.initializeForFirstUse(streamInfo, mediaInfo);
if (!initialized) {
if (sourceBufferSink.getBuffer() && typeof sourceBufferSink.getBuffer().initialize === 'function') {
sourceBufferSink.getBuffer().initialize();
}
initialized = true;
}
resolve(sourceBufferSink);
} catch (e) {
errHandler.error(new _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_5__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_MESSAGE + type));
reject(e);
}
});
}
function getStreamId() {
return streamInfo.id;
}
function getType() {
return type;
}
function getBuffer() {
return sourceBufferSink;
}
function setMediaSource(value) {
mediaSource = value;
}
function getMediaSource() {
return mediaSource;
}
function getIsPruningInProgress() {
return false;
}
function getBufferLevel() {
return 0;
}
function getIsBufferingCompleted() {
return isBufferingCompleted;
}
function setIsBufferingCompleted(value) {
if (isBufferingCompleted === value) {
return;
}
isBufferingCompleted = value;
if (isBufferingCompleted) {
triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFERING_COMPLETED);
}
}
function reset(errored) {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, instance);
if (!errored && sourceBufferSink) {
sourceBufferSink.abort();
sourceBufferSink.reset();
sourceBufferSink = null;
}
}
function appendInitSegmentFromCache(representationId) {
// If text data file already in cache then no need to append it again
return initCache.extract(streamInfo.id, representationId) !== null;
}
function _onInitFragmentLoaded(e) {
if (!e.chunk.bytes || isBufferingCompleted) return;
initCache.save(e.chunk);
sourceBufferSink.append(e.chunk);
setIsBufferingCompleted(true);
}
function getRangeAt() {
return null;
}
function getAllRangesWithSafetyFactor() {
return [];
}
function getContinuousBufferTimeForTargetTime() {
return Number.POSITIVE_INFINITY;
}
function clearBuffers() {
return Promise.resolve();
}
function updateBufferTimestampOffset() {
return Promise.resolve();
}
function prepareForPlaybackSeek() {
return Promise.resolve();
}
function prepareForReplacementTrackSwitch() {
isBufferingCompleted = false;
return Promise.resolve();
}
function updateAppendWindow() {
return Promise.resolve();
}
function setSeekTarget() {}
function segmentRequestingCompleted() {}
function pruneAllSafely() {
return Promise.resolve();
}
function triggerEvent(eventType, data) {
var payload = data || {};
eventBus.trigger(eventType, payload, {
streamId: streamInfo.id,
mediaType: type
});
}
instance = {
initialize: initialize,
getStreamId: getStreamId,
getType: getType,
getBufferControllerType: getBufferControllerType,
createBufferSink: createBufferSink,
getBuffer: getBuffer,
getBufferLevel: getBufferLevel,
getRangeAt: getRangeAt,
getAllRangesWithSafetyFactor: getAllRangesWithSafetyFactor,
getContinuousBufferTimeForTargetTime: getContinuousBufferTimeForTargetTime,
setMediaSource: setMediaSource,
getMediaSource: getMediaSource,
appendInitSegmentFromCache: appendInitSegmentFromCache,
getIsBufferingCompleted: getIsBufferingCompleted,
setIsBufferingCompleted: setIsBufferingCompleted,
getIsPruningInProgress: getIsPruningInProgress,
reset: reset,
clearBuffers: clearBuffers,
prepareForPlaybackSeek: prepareForPlaybackSeek,
prepareForReplacementTrackSwitch: prepareForReplacementTrackSwitch,
setSeekTarget: setSeekTarget,
updateAppendWindow: updateAppendWindow,
pruneAllSafely: pruneAllSafely,
updateBufferTimestampOffset: updateBufferTimestampOffset,
segmentRequestingCompleted: segmentRequestingCompleted
};
setup();
return instance;
}
NotFragmentedTextBufferController.__dashjs_factory_name = BUFFER_CONTROLLER_TYPE;
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(NotFragmentedTextBufferController));
/***/ }),
/***/ "./src/streaming/text/TextController.js":
/*!**********************************************!*\
!*** ./src/streaming/text/TextController.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _TextSourceBuffer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TextSourceBuffer */ "./src/streaming/text/TextSourceBuffer.js");
/* harmony import */ var _TextTracks__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./TextTracks */ "./src/streaming/text/TextTracks.js");
/* harmony import */ var _utils_VTTParser__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/VTTParser */ "./src/streaming/utils/VTTParser.js");
/* harmony import */ var _utils_TTMLParser__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/TTMLParser */ "./src/streaming/utils/TTMLParser.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TextController(config) {
var context = this.context;
var adapter = config.adapter;
var errHandler = config.errHandler;
var manifestModel = config.manifestModel;
var mediaController = config.mediaController;
var videoModel = config.videoModel;
var settings = config.settings;
var instance, streamData, textSourceBuffers, textTracks, vttParser, ttmlParser, eventBus, defaultSettings, initialSettingsSet, allTracksAreDisabled, forceTextStreaming, textTracksAdded, disableTextBeforeTextTracksAdded;
function setup() {
defaultSettings = null;
forceTextStreaming = false;
textTracksAdded = false;
initialSettingsSet = false;
disableTextBeforeTextTracksAdded = false;
vttParser = Object(_utils_VTTParser__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
ttmlParser = Object(_utils_TTMLParser__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
resetInitialSettings();
}
function initialize() {
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].CURRENT_TRACK_CHANGED, _onCurrentTrackChanged, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);
}
function initializeForStream(streamInfo) {
var streamId = streamInfo.id;
var tracks = Object(_TextTracks__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
videoModel: videoModel,
streamInfo: streamInfo
});
tracks.initialize();
textTracks[streamId] = tracks;
var textSourceBuffer = Object(_TextSourceBuffer__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
errHandler: errHandler,
adapter: adapter,
manifestModel: manifestModel,
mediaController: mediaController,
videoModel: videoModel,
textTracks: tracks,
vttParser: vttParser,
ttmlParser: ttmlParser,
streamInfo: streamInfo
});
textSourceBuffer.initialize();
textSourceBuffers[streamId] = textSourceBuffer;
streamData[streamId] = {};
streamData[streamId].lastEnabledIndex = -1;
}
/**
* All media infos have been added. Start creating the track objects
* @param {object} streamInfo
*/
function createTracks(streamInfo) {
var streamId = streamInfo.id;
if (!textTracks[streamId]) {
return;
}
textTracks[streamId].createTracks();
}
/**
* Adds the new mediaInfo objects to the textSourceBuffer.
* @param {object} streamInfo
* @param {array} mInfos
* @param {string|null} mimeType
* @param {object} fragmentModel
*/
function addMediaInfosToBuffer(streamInfo, type, mInfos) {
var fragmentModel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var streamId = streamInfo.id;
if (!textSourceBuffers[streamId]) {
return;
}
textSourceBuffers[streamId].addMediaInfos(type, mInfos, fragmentModel);
}
function getTextSourceBuffer(streamInfo) {
var streamId = streamInfo.id;
if (textSourceBuffers && textSourceBuffers[streamId]) {
return textSourceBuffers[streamId];
}
}
function getAllTracksAreDisabled() {
return allTracksAreDisabled;
}
function addEmbeddedTrack(streamInfo, mediaInfo) {
var streamId = streamInfo.id;
if (!textSourceBuffers[streamId]) {
return;
}
textSourceBuffers[streamId].addEmbeddedTrack(mediaInfo);
}
function setInitialSettings(settings) {
defaultSettings = settings;
initialSettingsSet = true;
}
function _onTextTracksAdded(e) {
var tracks = e.tracks;
var index = e.index;
var streamId = e.streamId;
var textDefaultEnabled = settings.get().streaming.text.defaultEnabled;
if (textDefaultEnabled === false && !isTextEnabled() || disableTextBeforeTextTracksAdded) {
// disable text at startup if explicitly configured with setTextDefaultEnabled(false) or if there is no defaultSettings (configuration or from domStorage)
setTextTrack(streamId, -1);
} else {
if (defaultSettings) {
tracks.some(function (item, idx) {
// matchSettings is compatible with setTextDefaultLanguage and setInitialSettings
if (mediaController.matchSettings(defaultSettings, item)) {
setTextTrack(streamId, idx);
index = idx;
return true;
}
});
}
allTracksAreDisabled = false;
}
streamData[streamId].lastEnabledIndex = index;
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_8__["default"].TEXT_TRACKS_ADDED, {
enabled: isTextEnabled(),
index: index,
tracks: tracks,
streamId: streamId
});
textTracksAdded = true;
}
function _onCurrentTrackChanged(event) {
if (!initialSettingsSet && event && event.newMediaInfo) {
var mediaInfo = event.newMediaInfo;
if (mediaInfo.type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) {
defaultSettings = {
lang: mediaInfo.lang,
role: mediaInfo.roles[0],
index: mediaInfo.index,
codec: mediaInfo.codec,
accessibility: mediaInfo.accessibility[0]
};
}
}
}
function enableText(streamId, enable) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_9__["checkParameterType"])(enable, 'boolean');
if (isTextEnabled() !== enable) {
// change track selection
if (enable) {
// apply last enabled track
setTextTrack(streamId, streamData[streamId].lastEnabledIndex);
}
if (!enable) {
// keep last index and disable text track
streamData[streamId].lastEnabledIndex = getCurrentTrackIdx(streamId);
if (!textTracksAdded) {
disableTextBeforeTextTracksAdded = true;
} else {
setTextTrack(streamId, -1);
}
}
}
}
function isTextEnabled() {
var enabled = true;
if (allTracksAreDisabled && !forceTextStreaming) {
enabled = false;
}
return enabled;
} // when set to true ScheduleController will allow schedule of chunks even if tracks are all disabled. Allowing streaming to hidden track for external players to work with.
function enableForcedTextStreaming(enable) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_9__["checkParameterType"])(enable, 'boolean');
forceTextStreaming = enable;
}
function setTextTrack(streamId, idx) {
// For external time text file, the only action needed to change a track is marking the track mode to showing.
// Fragmented text tracks need the additional step of calling TextController.setTextTrack();
allTracksAreDisabled = idx === -1;
if (allTracksAreDisabled && mediaController) {
mediaController.saveTextSettingsDisabled();
}
var oldTrackIdx = getCurrentTrackIdx(streamId); // No change, no action required
if (oldTrackIdx === idx || !textTracks[streamId]) {
return;
}
textTracks[streamId].setModeForTrackIdx(oldTrackIdx, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_HIDDEN);
textTracks[streamId].setCurrentTrackIdx(idx);
textTracks[streamId].setModeForTrackIdx(idx, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_SHOWING);
var currentTrackInfo = textTracks[streamId].getCurrentTrackInfo();
if (currentTrackInfo && currentTrackInfo.isFragmented && !currentTrackInfo.isEmbedded) {
_setFragmentedTextTrack(streamId, currentTrackInfo, oldTrackIdx);
} else if (currentTrackInfo && !currentTrackInfo.isFragmented) {
_setNonFragmentedTextTrack(streamId, currentTrackInfo);
}
mediaController.setTrack(currentTrackInfo);
}
function _setFragmentedTextTrack(streamId, currentTrackInfo, oldTrackIdx) {
if (!textSourceBuffers[streamId]) {
return;
}
var config = textSourceBuffers[streamId].getConfig();
var fragmentedTracks = config.fragmentedTracks;
for (var i = 0; i < fragmentedTracks.length; i++) {
var mediaInfo = fragmentedTracks[i];
if (currentTrackInfo.lang === mediaInfo.lang && (mediaInfo.id ? currentTrackInfo.id === mediaInfo.id : currentTrackInfo.index === mediaInfo.index)) {
var currentFragTrack = mediaController.getCurrentTrackFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, streamId);
if (mediaInfo.id ? currentFragTrack.id !== mediaInfo.id : currentFragTrack.index !== mediaInfo.index) {
textTracks[streamId].deleteCuesFromTrackIdx(oldTrackIdx);
textSourceBuffers[streamId].setCurrentFragmentedTrackIdx(i);
} else if (oldTrackIdx === -1) {
// in fragmented use case, if the user selects the older track (the one selected before disabled text track)
// no CURRENT_TRACK_CHANGED event will be triggered because the mediaInfo in the StreamProcessor is equal to the one we are selecting
// For that reason we reactivate the StreamProcessor and the ScheduleController
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].SET_FRAGMENTED_TEXT_AFTER_DISABLED, {}, {
streamId: streamId,
mediaType: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT
});
}
}
}
}
function _setNonFragmentedTextTrack(streamId, currentTrackInfo) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].SET_NON_FRAGMENTED_TEXT, {
currentTrackInfo: currentTrackInfo
}, {
streamId: streamId,
mediaType: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT
});
}
function getCurrentTrackIdx(streamId) {
return textTracks[streamId].getCurrentTrackIdx();
}
function deactivateStream(streamInfo) {
if (!streamInfo) {
return;
}
var streamId = streamInfo.id;
if (textSourceBuffers[streamId]) {
textSourceBuffers[streamId].resetMediaInfos();
}
if (textTracks[streamId]) {
textTracks[streamId].deleteAllTextTracks();
}
}
function resetInitialSettings() {
textSourceBuffers = {};
textTracks = {};
streamData = {};
allTracksAreDisabled = true;
textTracksAdded = false;
disableTextBeforeTextTracksAdded = false;
}
function reset() {
resetInitialSettings();
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].CURRENT_TRACK_CHANGED, _onCurrentTrackChanged, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_7__["default"].TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);
Object.keys(textSourceBuffers).forEach(function (key) {
textSourceBuffers[key].resetEmbedded();
textSourceBuffers[key].reset();
});
}
instance = {
deactivateStream: deactivateStream,
initialize: initialize,
initializeForStream: initializeForStream,
createTracks: createTracks,
getTextSourceBuffer: getTextSourceBuffer,
getAllTracksAreDisabled: getAllTracksAreDisabled,
addEmbeddedTrack: addEmbeddedTrack,
setInitialSettings: setInitialSettings,
enableText: enableText,
isTextEnabled: isTextEnabled,
setTextTrack: setTextTrack,
getCurrentTrackIdx: getCurrentTrackIdx,
enableForcedTextStreaming: enableForcedTextStreaming,
addMediaInfosToBuffer: addMediaInfosToBuffer,
reset: reset
};
setup();
return instance;
}
TextController.__dashjs_factory_name = 'TextController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(TextController));
/***/ }),
/***/ "./src/streaming/text/TextSourceBuffer.js":
/*!************************************************!*\
!*** ./src/streaming/text/TextSourceBuffer.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _vo_TextTrackInfo__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/TextTrackInfo */ "./src/streaming/vo/TextTrackInfo.js");
/* harmony import */ var _utils_BoxParser__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/BoxParser */ "./src/streaming/utils/BoxParser.js");
/* harmony import */ var _utils_CustomTimeRanges__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/CustomTimeRanges */ "./src/streaming/utils/CustomTimeRanges.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _EmbeddedTextHtmlRender__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./EmbeddedTextHtmlRender */ "./src/streaming/text/EmbeddedTextHtmlRender.js");
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! codem-isoboxer */ "./node_modules/codem-isoboxer/dist/iso_boxer.js");
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(codem_isoboxer__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../../externals/cea608-parser */ "./externals/cea608-parser.js");
/* harmony import */ var _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(_externals_cea608_parser__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TextSourceBuffer(config) {
var errHandler = config.errHandler;
var manifestModel = config.manifestModel;
var mediaController = config.mediaController;
var videoModel = config.videoModel;
var textTracks = config.textTracks;
var vttParser = config.vttParser;
var ttmlParser = config.ttmlParser;
var streamInfo = config.streamInfo;
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
var embeddedInitialized = false;
var instance, logger, boxParser, parser, mediaInfos, fragmentModel, initializationSegmentReceived, timescale, fragmentedTracks, firstFragmentedSubtitleStart, currFragmentedTrackIdx, embeddedTracks, embeddedTimescale, embeddedLastSequenceNumber, embeddedCea608FieldParsers, embeddedTextHtmlRender;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance().getLogger(instance);
boxParser = Object(_utils_BoxParser__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance();
resetInitialSettings();
}
function getStreamId() {
return streamInfo.id;
}
function _resetFragmented() {
fragmentModel = null;
timescale = NaN;
fragmentedTracks = [];
firstFragmentedSubtitleStart = null;
initializationSegmentReceived = false;
}
function resetInitialSettings() {
_resetFragmented();
mediaInfos = [];
parser = null;
}
function initialize() {
if (!embeddedInitialized) {
_initEmbedded();
}
}
/**
* There might be media infos of different types. For instance text and fragmentedText.
* @param {string} type
* @param {array} mInfos
* @param {object} fModel
*/
function addMediaInfos(type, mInfos, fModel) {
mediaInfos = mediaInfos.concat(mInfos);
if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && mInfos[0].isFragmented && !mInfos[0].isEmbedded) {
fragmentModel = fModel;
instance.buffered = Object(_utils_CustomTimeRanges__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create();
fragmentedTracks = mediaController.getTracksFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, streamInfo.id).filter(function (track) {
return track.isFragmented;
});
var currFragTrack = mediaController.getCurrentTrackFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, streamInfo.id);
for (var i = 0; i < fragmentedTracks.length; i++) {
if (fragmentedTracks[i] === currFragTrack) {
setCurrentFragmentedTrackIdx(i);
break;
}
}
}
for (var _i = 0; _i < mInfos.length; _i++) {
_createTextTrackFromMediaInfo(mInfos[_i]);
}
}
/**
* Create a new track based on the mediaInfo information
* @param {object} mediaInfo
* @private
*/
function _createTextTrackFromMediaInfo(mediaInfo) {
var textTrackInfo = new _vo_TextTrackInfo__WEBPACK_IMPORTED_MODULE_2__["default"]();
var trackKindMap = {
subtitle: 'subtitles',
caption: 'captions'
}; //Dash Spec has no "s" on end of KIND but HTML needs plural.
for (var key in mediaInfo) {
textTrackInfo[key] = mediaInfo[key];
}
textTrackInfo.labels = mediaInfo.labels;
textTrackInfo.defaultTrack = getIsDefault(mediaInfo);
textTrackInfo.isFragmented = mediaInfo.isFragmented;
textTrackInfo.isEmbedded = !!mediaInfo.isEmbedded;
textTrackInfo.isTTML = _checkTtml(mediaInfo);
textTrackInfo.kind = _getKind(mediaInfo, trackKindMap);
textTracks.addTextTrack(textTrackInfo);
}
function abort() {}
function reset() {
resetInitialSettings();
mediaInfos = [];
boxParser = null;
}
function _onVideoChunkReceived(e) {
var chunk = e.chunk;
if (chunk.mediaInfo.embeddedCaptions) {
append(chunk.bytes, chunk);
}
}
function _initEmbedded() {
embeddedTracks = [];
currFragmentedTrackIdx = null;
embeddedTimescale = 0;
embeddedCea608FieldParsers = [];
embeddedLastSequenceNumber = null;
embeddedInitialized = true;
embeddedTextHtmlRender = Object(_EmbeddedTextHtmlRender__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].VIDEO_CHUNK_RECEIVED, _onVideoChunkReceived, instance);
eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_CLEARED, onVideoBufferCleared, instance);
}
function resetEmbedded() {
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].VIDEO_CHUNK_RECEIVED, _onVideoChunkReceived, instance);
eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BUFFER_CLEARED, onVideoBufferCleared, instance);
if (textTracks) {
textTracks.deleteAllTextTracks();
}
embeddedInitialized = false;
embeddedTracks = [];
embeddedCea608FieldParsers = [null, null];
embeddedLastSequenceNumber = null;
}
function addEmbeddedTrack(mediaInfo) {
if (!embeddedInitialized) {
return;
}
if (mediaInfo) {
if (mediaInfo.id === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].CC1 || mediaInfo.id === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].CC3) {
for (var i = 0; i < embeddedTracks.length; i++) {
if (embeddedTracks[i].id === mediaInfo.id) {
return;
}
}
embeddedTracks.push(mediaInfo);
} else {
logger.warn('Embedded track ' + mediaInfo.id + ' not supported!');
}
}
}
function getConfig() {
var config = {
fragmentModel: fragmentModel,
fragmentedTracks: fragmentedTracks,
videoModel: videoModel
};
return config;
}
function setCurrentFragmentedTrackIdx(idx) {
currFragmentedTrackIdx = idx;
}
function _checkTtml(mediaInfo) {
return mediaInfo.codec && mediaInfo.codec.search(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STPP) >= 0 || mediaInfo.mimeType && mediaInfo.mimeType.search(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TTML) >= 0;
}
function _getKind(mediaInfo, trackKindMap) {
var kind = mediaInfo.roles && mediaInfo.roles.length > 0 ? trackKindMap[mediaInfo.roles[0]] : trackKindMap.caption;
kind = kind === trackKindMap.caption || kind === trackKindMap.subtitle ? kind : trackKindMap.caption;
return kind;
}
function append(bytes, chunk) {
var mediaInfo = chunk.mediaInfo;
var mediaType = mediaInfo.type;
var mimeType = mediaInfo.mimeType;
var codecType = mediaInfo.codec || mimeType;
if (!codecType) {
logger.error('No text type defined');
return;
}
if (mediaInfo.codec.indexOf('application/mp4') !== -1) {
_appendFragmentedText(bytes, chunk, codecType);
} else if (mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) {
_appendEmbeddedText(bytes, chunk);
} else {
_appendText(bytes, chunk, codecType);
}
}
function _appendFragmentedText(bytes, chunk, codecType) {
var sampleList, samplesInfo;
if (chunk.segmentType === 'InitializationSegment') {
initializationSegmentReceived = true;
timescale = boxParser.getMediaTimescaleFromMoov(bytes);
} else {
if (!initializationSegmentReceived) {
return;
}
samplesInfo = boxParser.getSamplesInfo(bytes);
sampleList = samplesInfo.sampleList;
if (sampleList.length > 0) {
firstFragmentedSubtitleStart = sampleList[0].cts - chunk.start * timescale;
}
if (codecType.search(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STPP) >= 0) {
_appendFragmentedSttp(bytes, sampleList, codecType);
} else {
_appendFragmentedWebVtt(bytes, sampleList);
}
}
}
function _appendFragmentedSttp(bytes, sampleList, codecType) {
var i, j;
parser = parser !== null ? parser : getParser(codecType);
for (i = 0; i < sampleList.length; i++) {
var sample = sampleList[i];
var sampleStart = sample.cts;
var timestampOffset = _getTimestampOffset();
var start = timestampOffset + sampleStart / timescale;
var end = start + sample.duration / timescale;
instance.buffered.add(start, end);
var dataView = new DataView(bytes, sample.offset, sample.subSizes[0]);
var ccContent = codem_isoboxer__WEBPACK_IMPORTED_MODULE_8___default.a.Utils.dataViewToString(dataView, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].UTF8);
var images = [];
var subOffset = sample.offset + sample.subSizes[0];
for (j = 1; j < sample.subSizes.length; j++) {
var inData = new Uint8Array(bytes, subOffset, sample.subSizes[j]);
var raw = String.fromCharCode.apply(null, inData);
images.push(raw);
subOffset += sample.subSizes[j];
}
try {
var manifest = manifestModel.getValue(); // Only used for Miscrosoft Smooth Streaming support - caption time is relative to sample time. In this case, we apply an offset.
var offsetTime = manifest.ttmlTimeIsRelative ? sampleStart / timescale : 0;
var result = parser.parse(ccContent, offsetTime, sampleStart / timescale, (sampleStart + sample.duration) / timescale, images);
textTracks.addCaptions(currFragmentedTrackIdx, timestampOffset, result);
} catch (e) {
fragmentModel.removeExecutedRequestsBeforeTime();
this.remove();
logger.error('TTML parser error: ' + e.message);
}
}
}
function _appendFragmentedWebVtt(bytes, sampleList) {
var i, j, k;
var captionArray = [];
for (i = 0; i < sampleList.length; i++) {
var sample = sampleList[i];
sample.cts -= firstFragmentedSubtitleStart;
var timestampOffset = _getTimestampOffset();
var start = timestampOffset + sample.cts / timescale;
var end = start + sample.duration / timescale;
instance.buffered.add(start, end);
var sampleData = bytes.slice(sample.offset, sample.offset + sample.size); // There are boxes inside the sampleData, so we need a ISOBoxer to get at it.
var sampleBoxes = codem_isoboxer__WEBPACK_IMPORTED_MODULE_8___default.a.parseBuffer(sampleData);
for (j = 0; j < sampleBoxes.boxes.length; j++) {
var box1 = sampleBoxes.boxes[j];
logger.debug('VTT box1: ' + box1.type);
if (box1.type === 'vtte') {
continue; //Empty box
}
if (box1.type === 'vttc') {
logger.debug('VTT vttc boxes.length = ' + box1.boxes.length);
for (k = 0; k < box1.boxes.length; k++) {
var box2 = box1.boxes[k];
logger.debug('VTT box2: ' + box2.type);
if (box2.type === 'payl') {
var cue_text = box2.cue_text;
logger.debug('VTT cue_text = ' + cue_text);
var start_time = sample.cts / timescale;
var end_time = (sample.cts + sample.duration) / timescale;
captionArray.push({
start: start_time,
end: end_time,
data: cue_text,
styles: {}
});
logger.debug('VTT ' + start_time + '-' + end_time + ' : ' + cue_text);
}
}
}
}
}
if (captionArray.length > 0) {
textTracks.addCaptions(currFragmentedTrackIdx, 0, captionArray);
}
}
function _appendText(bytes, chunk, codecType) {
var result, ccContent;
var dataView = new DataView(bytes, 0, bytes.byteLength);
ccContent = codem_isoboxer__WEBPACK_IMPORTED_MODULE_8___default.a.Utils.dataViewToString(dataView, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].UTF8);
try {
result = getParser(codecType).parse(ccContent, 0);
textTracks.addCaptions(textTracks.getCurrentTrackIdx(), 0, result);
if (instance.buffered) {
instance.buffered.add(chunk.start, chunk.end);
}
} catch (e) {
errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_12__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__["default"].TIMED_TEXT_ERROR_ID_PARSE_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_13__["default"].TIMED_TEXT_ERROR_MESSAGE_PARSE + e.message, ccContent));
}
}
function _appendEmbeddedText(bytes, chunk) {
var i, samplesInfo; // Init segment
if (chunk.segmentType === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].INIT_SEGMENT_TYPE) {
if (embeddedTimescale === 0) {
embeddedTimescale = boxParser.getMediaTimescaleFromMoov(bytes);
}
} // MediaSegment
else if (chunk.segmentType === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_1__["HTTPRequest"].MEDIA_SEGMENT_TYPE) {
if (embeddedTimescale === 0) {
logger.warn('CEA-608: No timescale for embeddedTextTrack yet');
return;
}
samplesInfo = boxParser.getSamplesInfo(bytes);
var sequenceNumber = samplesInfo.lastSequenceNumber;
if (!embeddedCea608FieldParsers[0] && !embeddedCea608FieldParsers[1]) {
_setupCeaParser();
}
if (embeddedTimescale) {
if (embeddedLastSequenceNumber !== null && sequenceNumber !== embeddedLastSequenceNumber + samplesInfo.numSequences) {
for (i = 0; i < embeddedCea608FieldParsers.length; i++) {
if (embeddedCea608FieldParsers[i]) {
embeddedCea608FieldParsers[i].reset();
}
}
}
var allCcData = _extractCea608Data(bytes, samplesInfo.sampleList);
for (var fieldNr = 0; fieldNr < embeddedCea608FieldParsers.length; fieldNr++) {
var ccData = allCcData.fields[fieldNr];
var fieldParser = embeddedCea608FieldParsers[fieldNr];
if (fieldParser) {
for (i = 0; i < ccData.length; i++) {
fieldParser.addData(ccData[i][0] / embeddedTimescale, ccData[i][1]);
}
}
}
embeddedLastSequenceNumber = sequenceNumber;
}
}
}
function _setupCeaParser() {
// Time to setup the CEA-608 parsing
var trackIdx;
for (var i = 0; i < embeddedTracks.length; i++) {
trackIdx = textTracks.getTrackIdxForId(embeddedTracks[i].id);
if (trackIdx === -1) {
logger.warn('CEA-608: data before track is ready.');
return;
}
var handler = _makeCueAdderForIndex(trackIdx);
embeddedCea608FieldParsers[i] = new _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_9___default.a.Cea608Parser(i + 1, {
newCue: handler
}, null);
}
}
function _makeCueAdderForIndex(trackIndex) {
function newCue(startTime, endTime, captionScreen) {
var captionsArray;
if (videoModel.getTTMLRenderingDiv()) {
captionsArray = embeddedTextHtmlRender.createHTMLCaptionsFromScreen(videoModel.getElement(), startTime, endTime, captionScreen);
} else {
var text = captionScreen.getDisplayText();
captionsArray = [{
start: startTime,
end: endTime,
data: text,
styles: {}
}];
}
if (captionsArray) {
textTracks.addCaptions(trackIndex, 0, captionsArray);
}
}
return newCue;
}
/**
* Extract CEA-608 data from a buffer of data.
* @param {ArrayBuffer} data
* @param {Array} samples cue information
* @returns {Object|null} ccData corresponding to one segment.
*/
function _extractCea608Data(data, samples) {
if (samples.length === 0) {
return null;
}
var allCcData = {
splits: [],
fields: [[], []]
};
var raw = new DataView(data);
for (var i = 0; i < samples.length; i++) {
var sample = samples[i];
var cea608Ranges = _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_9___default.a.findCea608Nalus(raw, sample.offset, sample.size);
var lastSampleTime = null;
var idx = 0;
for (var j = 0; j < cea608Ranges.length; j++) {
var ccData = _externals_cea608_parser__WEBPACK_IMPORTED_MODULE_9___default.a.extractCea608DataFromRange(raw, cea608Ranges[j]);
for (var k = 0; k < 2; k++) {
if (ccData[k].length > 0) {
if (sample.cts !== lastSampleTime) {
idx = 0;
} else {
idx += 1;
}
var timestampOffset = _getTimestampOffset();
allCcData.fields[k].push([sample.cts + timestampOffset * embeddedTimescale, ccData[k], idx]);
lastSampleTime = sample.cts;
}
}
}
} // Sort by sampleTime ascending order
// If two packets have the same sampleTime, use them in the order
// they were received
allCcData.fields.forEach(function sortField(field) {
field.sort(function (a, b) {
if (a[0] === b[0]) {
return a[2] - b[2];
}
return a[0] - b[0];
});
});
return allCcData;
}
function _getTimestampOffset() {
return !isNaN(instance.timestampOffset) ? instance.timestampOffset : 0;
}
function getIsDefault(mediaInfo) {
//TODO How to tag default. currently same order as listed in manifest.
// Is there a way to mark a text adaptation set as the default one? DASHIF meeting talk about using role which is being used for track KIND
// Eg subtitles etc. You can have multiple role tags per adaptation Not defined in the spec yet.
var isDefault = false;
if (embeddedTracks.length > 1 && mediaInfo.isEmbedded) {
isDefault = mediaInfo.id && mediaInfo.id === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].CC1; // CC1 if both CC1 and CC3 exist
} else if (embeddedTracks.length === 1) {
if (mediaInfo.id && typeof mediaInfo.id === 'string' && mediaInfo.id.substring(0, 2) === 'CC') {
// Either CC1 or CC3
isDefault = true;
}
} else if (embeddedTracks.length === 0) {
isDefault = mediaInfo.index === mediaInfos[0].index;
}
return isDefault;
}
function getParser(codecType) {
var parser;
if (codecType.search(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VTT) >= 0) {
parser = vttParser;
} else if (codecType.search(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TTML) >= 0 || codecType.search(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STPP) >= 0) {
parser = ttmlParser;
}
return parser;
}
function remove(start, end) {
//if start and end are not defined, remove all
if (start === undefined && start === end) {
start = instance.buffered.start(0);
end = instance.buffered.end(instance.buffered.length - 1);
}
instance.buffered.remove(start, end);
textTracks.deleteCuesFromTrackIdx(currFragmentedTrackIdx, start, end);
}
function onVideoBufferCleared(e) {
embeddedTracks.forEach(function (track) {
var trackIdx = textTracks.getTrackIdxForId(track.id);
if (trackIdx >= 0) {
textTracks.deleteCuesFromTrackIdx(trackIdx, e.from, e.to);
}
});
}
function resetMediaInfos() {
mediaInfos = [];
}
instance = {
initialize: initialize,
addMediaInfos: addMediaInfos,
resetMediaInfos: resetMediaInfos,
getStreamId: getStreamId,
append: append,
abort: abort,
addEmbeddedTrack: addEmbeddedTrack,
resetEmbedded: resetEmbedded,
getConfig: getConfig,
setCurrentFragmentedTrackIdx: setCurrentFragmentedTrackIdx,
remove: remove,
reset: reset
};
setup();
return instance;
}
TextSourceBuffer.__dashjs_factory_name = 'TextSourceBuffer';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_5__["default"].getClassFactory(TextSourceBuffer));
/***/ }),
/***/ "./src/streaming/text/TextTracks.js":
/*!******************************************!*\
!*** ./src/streaming/text/TextTracks.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var imsc__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! imsc */ "./node_modules/imsc/src/main/js/main.js");
/* harmony import */ var imsc__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(imsc__WEBPACK_IMPORTED_MODULE_6__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TextTracks(config) {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
var videoModel = config.videoModel;
var streamInfo = config.streamInfo;
var instance, logger, Cue, textTrackQueue, nativeTrackElementArr, currentTrackIdx, actualVideoLeft, actualVideoTop, actualVideoWidth, actualVideoHeight, captionContainer, videoSizeCheckInterval, fullscreenAttribute, displayCCOnTop, previousISDState, topZIndex, resizeObserver;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance().getLogger(instance);
}
function initialize() {
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
return;
}
Cue = window.VTTCue || window.TextTrackCue;
textTrackQueue = [];
nativeTrackElementArr = [];
currentTrackIdx = -1;
actualVideoLeft = 0;
actualVideoTop = 0;
actualVideoWidth = 0;
actualVideoHeight = 0;
captionContainer = null;
videoSizeCheckInterval = null;
displayCCOnTop = false;
topZIndex = 2147483647;
previousISDState = null;
if (document.fullscreenElement !== undefined) {
fullscreenAttribute = 'fullscreenElement'; // Standard and Edge
} else if (document.webkitIsFullScreen !== undefined) {
fullscreenAttribute = 'webkitIsFullScreen'; // Chrome and Safari (and Edge)
} else if (document.msFullscreenElement) {
// IE11
fullscreenAttribute = 'msFullscreenElement';
} else if (document.mozFullScreen) {
// Firefox
fullscreenAttribute = 'mozFullScreen';
}
}
function getStreamId() {
return streamInfo.id;
}
function _createTrackForUserAgent(element) {
var kind = element.kind;
var label = element.id !== undefined ? element.id : element.lang;
var lang = element.lang;
var isTTML = element.isTTML;
var isEmbedded = element.isEmbedded;
var track = videoModel.addTextTrack(kind, label, lang, isTTML, isEmbedded);
return track;
}
function addTextTrack(textTrackInfoVO) {
textTrackQueue.push(textTrackInfoVO);
}
function createTracks() {
//Sort in same order as in manifest
textTrackQueue.sort(function (a, b) {
return a.index - b.index;
});
captionContainer = videoModel.getTTMLRenderingDiv();
var defaultIndex = -1;
for (var i = 0; i < textTrackQueue.length; i++) {
var track = _createTrackForUserAgent(textTrackQueue[i]); //used to remove tracks from video element when added manually
nativeTrackElementArr.push(track);
if (textTrackQueue[i].defaultTrack) {
// track.default is an object property identifier that is a reserved word
// The following jshint directive is used to suppressed the warning "Expected an identifier and instead saw 'default' (a reserved word)"
/*jshint -W024 */
track["default"] = true;
defaultIndex = i;
}
var textTrack = getTrackByIdx(i);
if (textTrack) {
//each time a track is created, its mode should be showing by default
//sometime, it's not on Chrome
textTrack.mode = _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_SHOWING;
if (captionContainer && (textTrackQueue[i].isTTML || textTrackQueue[i].isEmbedded)) {
textTrack.renderingType = 'html';
} else {
textTrack.renderingType = 'default';
}
}
addCaptions(i, 0, textTrackQueue[i].captionData);
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].TEXT_TRACK_ADDED);
} //set current track index in textTrackQueue array
setCurrentTrackIdx.call(this, defaultIndex);
if (defaultIndex >= 0) {
var onMetadataLoaded = function onMetadataLoaded() {
var track = getTrackByIdx(defaultIndex);
if (track && track.renderingType === 'html') {
checkVideoSize.call(this, track, true);
}
eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_METADATA_LOADED, onMetadataLoaded, this);
};
eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].PLAYBACK_METADATA_LOADED, onMetadataLoaded, this);
for (var idx = 0; idx < textTrackQueue.length; idx++) {
var videoTextTrack = getTrackByIdx(idx);
if (videoTextTrack) {
videoTextTrack.mode = idx === defaultIndex ? _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_SHOWING : _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_HIDDEN;
}
}
}
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].TEXT_TRACKS_QUEUE_INITIALIZED, {
index: currentTrackIdx,
tracks: textTrackQueue,
streamId: streamInfo.id
});
}
function getVideoVisibleVideoSize(viewWidth, viewHeight, videoWidth, videoHeight, aspectRatio, use80Percent) {
var viewAspectRatio = viewWidth / viewHeight;
var videoAspectRatio = videoWidth / videoHeight;
var videoPictureWidth = 0;
var videoPictureHeight = 0;
if (viewAspectRatio > videoAspectRatio) {
videoPictureHeight = viewHeight;
videoPictureWidth = videoPictureHeight / videoHeight * videoWidth;
} else {
videoPictureWidth = viewWidth;
videoPictureHeight = videoPictureWidth / videoWidth * videoHeight;
}
var videoPictureXAspect = 0;
var videoPictureYAspect = 0;
var videoPictureWidthAspect = 0;
var videoPictureHeightAspect = 0;
var videoPictureAspect = videoPictureWidth / videoPictureHeight;
if (videoPictureAspect > aspectRatio) {
videoPictureHeightAspect = videoPictureHeight;
videoPictureWidthAspect = videoPictureHeight * aspectRatio;
} else {
videoPictureWidthAspect = videoPictureWidth;
videoPictureHeightAspect = videoPictureWidth / aspectRatio;
}
videoPictureXAspect = (viewWidth - videoPictureWidthAspect) / 2;
videoPictureYAspect = (viewHeight - videoPictureHeightAspect) / 2;
if (use80Percent) {
return {
x: videoPictureXAspect + videoPictureWidthAspect * 0.1,
y: videoPictureYAspect + videoPictureHeightAspect * 0.1,
w: videoPictureWidthAspect * 0.8,
h: videoPictureHeightAspect * 0.8
};
/* Maximal picture size in videos aspect ratio */
} else {
return {
x: videoPictureXAspect,
y: videoPictureYAspect,
w: videoPictureWidthAspect,
h: videoPictureHeightAspect
};
/* Maximal picture size in videos aspect ratio */
}
}
function checkVideoSize(track, forceDrawing) {
var clientWidth = videoModel.getClientWidth();
var clientHeight = videoModel.getClientHeight();
var videoWidth = videoModel.getVideoWidth();
var videoHeight = videoModel.getVideoHeight();
var videoOffsetTop = videoModel.getVideoRelativeOffsetTop();
var videoOffsetLeft = videoModel.getVideoRelativeOffsetLeft();
if (videoWidth !== 0 && videoHeight !== 0) {
var aspectRatio = videoWidth / videoHeight;
var use80Percent = false;
if (track.isFromCEA608) {
// If this is CEA608 then use predefined aspect ratio
aspectRatio = 3.5 / 3.0;
use80Percent = true;
}
var realVideoSize = getVideoVisibleVideoSize.call(this, clientWidth, clientHeight, videoWidth, videoHeight, aspectRatio, use80Percent);
var newVideoWidth = realVideoSize.w;
var newVideoHeight = realVideoSize.h;
var newVideoLeft = realVideoSize.x;
var newVideoTop = realVideoSize.y;
if (newVideoWidth != actualVideoWidth || newVideoHeight != actualVideoHeight || newVideoLeft != actualVideoLeft || newVideoTop != actualVideoTop || forceDrawing) {
actualVideoLeft = newVideoLeft + videoOffsetLeft;
actualVideoTop = newVideoTop + videoOffsetTop;
actualVideoWidth = newVideoWidth;
actualVideoHeight = newVideoHeight;
if (captionContainer) {
var containerStyle = captionContainer.style;
if (containerStyle) {
containerStyle.left = actualVideoLeft + 'px';
containerStyle.top = actualVideoTop + 'px';
containerStyle.width = actualVideoWidth + 'px';
containerStyle.height = actualVideoHeight + 'px';
containerStyle.zIndex = fullscreenAttribute && document[fullscreenAttribute] || displayCCOnTop ? topZIndex : null;
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].CAPTION_CONTAINER_RESIZE);
}
} // Video view has changed size, so resize any active cues
var activeCues = track.activeCues;
if (activeCues) {
var len = activeCues.length;
for (var i = 0; i < len; ++i) {
var cue = activeCues[i];
cue.scaleCue(cue);
}
}
}
}
}
function scaleCue(activeCue) {
var videoWidth = actualVideoWidth;
var videoHeight = actualVideoHeight;
var key, replaceValue, valueFontSize, valueLineHeight, elements;
if (activeCue.cellResolution) {
var cellUnit = [videoWidth / activeCue.cellResolution[0], videoHeight / activeCue.cellResolution[1]];
if (activeCue.linePadding) {
for (key in activeCue.linePadding) {
if (activeCue.linePadding.hasOwnProperty(key)) {
var valueLinePadding = activeCue.linePadding[key];
replaceValue = (valueLinePadding * cellUnit[0]).toString(); // Compute the CellResolution unit in order to process properties using sizing (fontSize, linePadding, etc).
var elementsSpan = document.getElementsByClassName('spanPadding');
for (var i = 0; i < elementsSpan.length; i++) {
elementsSpan[i].style.cssText = elementsSpan[i].style.cssText.replace(/(padding-left\s*:\s*)[\d.,]+(?=\s*px)/gi, '$1' + replaceValue);
elementsSpan[i].style.cssText = elementsSpan[i].style.cssText.replace(/(padding-right\s*:\s*)[\d.,]+(?=\s*px)/gi, '$1' + replaceValue);
}
}
}
}
if (activeCue.fontSize) {
for (key in activeCue.fontSize) {
if (activeCue.fontSize.hasOwnProperty(key)) {
if (activeCue.fontSize[key][0] === '%') {
valueFontSize = activeCue.fontSize[key][1] / 100;
} else if (activeCue.fontSize[key][0] === 'c') {
valueFontSize = activeCue.fontSize[key][1];
}
replaceValue = (valueFontSize * cellUnit[1]).toString();
if (key !== 'defaultFontSize') {
elements = document.getElementsByClassName(key);
} else {
elements = document.getElementsByClassName('paragraph');
}
for (var j = 0; j < elements.length; j++) {
elements[j].style.cssText = elements[j].style.cssText.replace(/(font-size\s*:\s*)[\d.,]+(?=\s*px)/gi, '$1' + replaceValue);
}
}
}
if (activeCue.lineHeight) {
for (key in activeCue.lineHeight) {
if (activeCue.lineHeight.hasOwnProperty(key)) {
if (activeCue.lineHeight[key][0] === '%') {
valueLineHeight = activeCue.lineHeight[key][1] / 100;
} else if (activeCue.fontSize[key][0] === 'c') {
valueLineHeight = activeCue.lineHeight[key][1];
}
replaceValue = (valueLineHeight * cellUnit[1]).toString();
elements = document.getElementsByClassName(key);
for (var k = 0; k < elements.length; k++) {
elements[k].style.cssText = elements[k].style.cssText.replace(/(line-height\s*:\s*)[\d.,]+(?=\s*px)/gi, '$1' + replaceValue);
}
}
}
}
}
}
if (activeCue.isd) {
var htmlCaptionDiv = document.getElementById(activeCue.cueID);
if (htmlCaptionDiv) {
captionContainer.removeChild(htmlCaptionDiv);
}
renderCaption(activeCue);
}
}
function renderCaption(cue) {
if (captionContainer) {
var finalCue = document.createElement('div');
captionContainer.appendChild(finalCue);
previousISDState = Object(imsc__WEBPACK_IMPORTED_MODULE_6__["renderHTML"])(cue.isd, finalCue, function (uri) {
var imsc1ImgUrnTester = /^(urn:)(mpeg:[a-z0-9][a-z0-9-]{0,31}:)(subs:)([0-9]+)$/;
var smpteImgUrnTester = /^#(.*)$/;
if (imsc1ImgUrnTester.test(uri)) {
var match = imsc1ImgUrnTester.exec(uri);
var imageId = parseInt(match[4], 10) - 1;
var imageData = btoa(cue.images[imageId]);
var dataUrl = 'data:image/png;base64,' + imageData;
return dataUrl;
} else if (smpteImgUrnTester.test(uri)) {
var _match = smpteImgUrnTester.exec(uri);
var _imageId = _match[1];
var _dataUrl = 'data:image/png;base64,' + cue.embeddedImages[_imageId];
return _dataUrl;
} else {
return null;
}
}, captionContainer.clientHeight, captionContainer.clientWidth, false
/*displayForcedOnlyMode*/
, function (err) {
logger.info('renderCaption :', err); //TODO add ErrorHandler management
}, previousISDState, true
/*enableRollUp*/
);
finalCue.id = cue.cueID;
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].CAPTION_RENDERED, {
captionDiv: finalCue,
currentTrackIdx: currentTrackIdx
});
}
}
/*
* Add captions to track, store for later adding, or add captions added before
*/
function addCaptions(trackIdx, timeOffset, captionData) {
var track = getTrackByIdx(trackIdx);
var self = this;
if (!track) {
return;
}
if (!Array.isArray(captionData) || captionData.length === 0) {
return;
}
for (var item = 0; item < captionData.length; item++) {
var cue = void 0;
var currentItem = captionData[item];
track.cellResolution = currentItem.cellResolution;
track.isFromCEA608 = currentItem.isFromCEA608;
if (currentItem.type === 'html' && captionContainer && !isNaN(currentItem.start) && !isNaN(currentItem.end)) {
cue = new Cue(currentItem.start + timeOffset, currentItem.end + timeOffset, '');
cue.cueHTMLElement = currentItem.cueHTMLElement;
cue.isd = currentItem.isd;
cue.images = currentItem.images;
cue.embeddedImages = currentItem.embeddedImages;
cue.cueID = currentItem.cueID;
cue.scaleCue = scaleCue.bind(self); //useful parameters for cea608 subtitles, not for TTML one.
cue.cellResolution = currentItem.cellResolution;
cue.lineHeight = currentItem.lineHeight;
cue.linePadding = currentItem.linePadding;
cue.fontSize = currentItem.fontSize;
captionContainer.style.left = actualVideoLeft + 'px';
captionContainer.style.top = actualVideoTop + 'px';
captionContainer.style.width = actualVideoWidth + 'px';
captionContainer.style.height = actualVideoHeight + 'px';
cue.onenter = function () {
if (track.mode === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_SHOWING) {
if (this.isd) {
renderCaption(this);
logger.debug('Cue enter id:' + this.cueID);
} else {
captionContainer.appendChild(this.cueHTMLElement);
scaleCue.call(self, this);
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].CAPTION_RENDERED, {
captionDiv: this.cueHTMLElement,
currentTrackIdx: currentTrackIdx
});
}
}
};
cue.onexit = function () {
if (captionContainer) {
var divs = captionContainer.childNodes;
for (var i = 0; i < divs.length; ++i) {
if (divs[i].id === this.cueID) {
logger.debug('Cue exit id:' + divs[i].id);
captionContainer.removeChild(divs[i]);
--i;
}
}
}
};
} else {
if (currentItem.data && !isNaN(currentItem.start) && !isNaN(currentItem.end)) {
cue = new Cue(currentItem.start - timeOffset, currentItem.end - timeOffset, currentItem.data);
if (currentItem.styles) {
if (currentItem.styles.align !== undefined && 'align' in cue) {
cue.align = currentItem.styles.align;
}
if (currentItem.styles.line !== undefined && 'line' in cue) {
cue.line = currentItem.styles.line;
}
if (currentItem.styles.position !== undefined && 'position' in cue) {
cue.position = currentItem.styles.position;
}
if (currentItem.styles.size !== undefined && 'size' in cue) {
cue.size = currentItem.styles.size;
}
}
cue.onenter = function () {
if (track.mode === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_SHOWING) {
eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].CAPTION_RENDERED, {
currentTrackIdx: currentTrackIdx
});
}
};
}
}
try {
if (cue) {
if (!cueInTrack(track, cue)) {
track.addCue(cue);
}
} else {
logger.error('impossible to display subtitles.');
}
} catch (e) {
// Edge crash, delete everything and start adding again
// @see https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11979877/
deleteTrackCues(track);
track.addCue(cue);
throw e;
}
}
}
function getTrackByIdx(idx) {
return idx >= 0 && textTrackQueue[idx] ? videoModel.getTextTrack(textTrackQueue[idx].kind, textTrackQueue[idx].id, textTrackQueue[idx].lang, textTrackQueue[idx].isTTML, textTrackQueue[idx].isEmbedded) : null;
}
function getCurrentTrackIdx() {
return currentTrackIdx;
}
function getTrackIdxForId(trackId) {
var idx = -1;
for (var i = 0; i < textTrackQueue.length; i++) {
if (textTrackQueue[i].id === trackId) {
idx = i;
break;
}
}
return idx;
}
function setCurrentTrackIdx(idx) {
var _this = this;
if (idx === currentTrackIdx) {
return;
}
currentTrackIdx = idx;
var track = getTrackByIdx(currentTrackIdx);
setCueStyleOnTrack.call(this, track);
if (videoSizeCheckInterval) {
clearInterval(videoSizeCheckInterval);
videoSizeCheckInterval = null;
}
if (track && track.renderingType === 'html') {
checkVideoSize.call(this, track, true);
if (window.ResizeObserver) {
resizeObserver = new window.ResizeObserver(function () {
checkVideoSize.call(_this, track, true);
});
resizeObserver.observe(videoModel.getElement());
} else {
videoSizeCheckInterval = setInterval(checkVideoSize.bind(this, track), 500);
}
}
}
function setCueStyleOnTrack(track) {
clearCaptionContainer.call(this);
if (track) {
if (track.renderingType === 'html') {
setNativeCueStyle.call(this);
} else {
removeNativeCueStyle.call(this);
}
} else {
removeNativeCueStyle.call(this);
}
}
function cueInTrack(track, cue) {
if (!track.cues) return false;
for (var i = 0; i < track.cues.length; i++) {
if (track.cues[i].startTime === cue.startTime && track.cues[i].endTime === cue.endTime) {
return true;
}
}
return false;
}
function cueInRange(cue, start, end) {
return (isNaN(start) || cue.startTime >= start) && (isNaN(end) || cue.endTime <= end);
}
function deleteTrackCues(track, start, end) {
if (track.cues) {
var cues = track.cues;
var lastIdx = cues.length - 1;
for (var r = lastIdx; r >= 0; r--) {
if (cueInRange(cues[r], start, end)) {
if (cues[r].onexit) {
cues[r].onexit();
}
track.removeCue(cues[r]);
}
}
}
}
function deleteCuesFromTrackIdx(trackIdx, start, end) {
var track = getTrackByIdx(trackIdx);
if (track) {
deleteTrackCues(track, start, end);
}
}
function deleteAllTextTracks() {
var ln = nativeTrackElementArr ? nativeTrackElementArr.length : 0;
for (var i = 0; i < ln; i++) {
var track = getTrackByIdx(i);
if (track) {
deleteTrackCues.call(this, track, streamInfo.start, streamInfo.start + streamInfo.duration);
}
}
nativeTrackElementArr = [];
textTrackQueue = [];
if (videoSizeCheckInterval) {
clearInterval(videoSizeCheckInterval);
videoSizeCheckInterval = null;
}
if (resizeObserver && videoModel) {
resizeObserver.unobserve(videoModel.getElement());
resizeObserver = null;
}
currentTrackIdx = -1;
clearCaptionContainer.call(this);
}
function deleteTextTrack(idx) {
videoModel.removeChild(nativeTrackElementArr[idx]);
nativeTrackElementArr.splice(idx, 1);
}
/* Set native cue style to transparent background to avoid it being displayed. */
function setNativeCueStyle() {
var styleElement = document.getElementById('native-cue-style');
if (styleElement) {
return; //Already set
}
styleElement = document.createElement('style');
styleElement.id = 'native-cue-style';
document.head.appendChild(styleElement);
var stylesheet = styleElement.sheet;
var video = videoModel.getElement();
try {
if (video) {
if (video.id) {
stylesheet.insertRule('#' + video.id + '::cue {background: transparent}', 0);
} else if (video.classList.length !== 0) {
stylesheet.insertRule('.' + video.className + '::cue {background: transparent}', 0);
} else {
stylesheet.insertRule('video::cue {background: transparent}', 0);
}
}
} catch (e) {
logger.info('' + e.message);
}
}
/* Remove the extra cue style with transparent background for native cues. */
function removeNativeCueStyle() {
var styleElement = document.getElementById('native-cue-style');
if (styleElement) {
document.head.removeChild(styleElement);
}
}
function clearCaptionContainer() {
if (captionContainer) {
while (captionContainer.firstChild) {
captionContainer.removeChild(captionContainer.firstChild);
}
}
}
function setModeForTrackIdx(idx, mode) {
var track = getTrackByIdx(idx);
if (track && track.mode !== mode) {
track.mode = mode;
}
}
function getCurrentTrackInfo() {
return textTrackQueue[currentTrackIdx];
}
instance = {
initialize: initialize,
getStreamId: getStreamId,
addTextTrack: addTextTrack,
addCaptions: addCaptions,
createTracks: createTracks,
getCurrentTrackIdx: getCurrentTrackIdx,
setCurrentTrackIdx: setCurrentTrackIdx,
getTrackIdxForId: getTrackIdxForId,
getCurrentTrackInfo: getCurrentTrackInfo,
setModeForTrackIdx: setModeForTrackIdx,
deleteCuesFromTrackIdx: deleteCuesFromTrackIdx,
deleteAllTextTracks: deleteAllTextTracks,
deleteTextTrack: deleteTextTrack
};
setup();
return instance;
}
TextTracks.__dashjs_factory_name = 'TextTracks';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_4__["default"].getClassFactory(TextTracks));
/***/ }),
/***/ "./src/streaming/thumbnail/ThumbnailController.js":
/*!********************************************************!*\
!*** ./src/streaming/thumbnail/ThumbnailController.js ***!
\********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _vo_Thumbnail__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../vo/Thumbnail */ "./src/streaming/vo/Thumbnail.js");
/* harmony import */ var _ThumbnailTracks__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./ThumbnailTracks */ "./src/streaming/thumbnail/ThumbnailTracks.js");
/* harmony import */ var _vo_BitrateInfo__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/BitrateInfo */ "./src/streaming/vo/BitrateInfo.js");
/* harmony import */ var _dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../dash/utils/SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function ThumbnailController(config) {
var context = this.context;
var streamInfo = config.streamInfo;
var instance, thumbnailTracks;
function setup() {
reset();
thumbnailTracks = Object(_ThumbnailTracks__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
streamInfo: streamInfo,
adapter: config.adapter,
baseURLController: config.baseURLController,
timelineConverter: config.timelineConverter,
debug: config.debug,
eventBus: config.eventBus,
events: config.events,
dashConstants: config.dashConstants,
dashMetrics: config.dashMetrics,
segmentBaseController: config.segmentBaseController
});
}
function initialize() {
thumbnailTracks.addTracks();
var tracks = thumbnailTracks.getTracks();
if (tracks && tracks.length > 0) {
setTrackByIndex(0);
}
}
function getStreamId() {
return streamInfo.id;
}
function provide(time, callback) {
if (typeof callback !== 'function') {
return;
}
var track = thumbnailTracks.getCurrentTrack();
var offset, request;
if (!track || track.segmentDuration <= 0 || time === undefined || time === null) {
callback(null);
return;
}
request = thumbnailTracks.getThumbnailRequestForTime(time);
if (request) {
track.segmentDuration = request.duration;
}
offset = time % track.segmentDuration;
var thumbIndex = Math.floor(offset * track.tilesHor * track.tilesVert / track.segmentDuration); // Create and return the thumbnail
var thumbnail = new _vo_Thumbnail__WEBPACK_IMPORTED_MODULE_2__["default"]();
thumbnail.width = Math.floor(track.widthPerTile);
thumbnail.height = Math.floor(track.heightPerTile);
thumbnail.x = Math.floor(thumbIndex % track.tilesHor) * track.widthPerTile;
thumbnail.y = Math.floor(thumbIndex / track.tilesHor) * track.heightPerTile;
if ('readThumbnail' in track) {
return track.readThumbnail(time, function (url) {
thumbnail.url = url;
callback(thumbnail);
});
} else {
if (!request) {
var seq = Math.floor(time / track.segmentDuration);
thumbnail.url = _buildUrlFromTemplate(track, seq);
} else {
thumbnail.url = request.url;
track.segmentDuration = NaN;
}
callback(thumbnail);
}
}
function _buildUrlFromTemplate(track, seq) {
var seqIdx = seq + track.startNumber;
var url = Object(_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__["replaceTokenForTemplate"])(track.templateUrl, 'Number', seqIdx);
url = Object(_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__["replaceTokenForTemplate"])(url, 'Time', (seqIdx - 1) * track.segmentDuration * track.timescale);
url = Object(_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__["replaceTokenForTemplate"])(url, 'Bandwidth', track.bandwidth);
return Object(_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__["unescapeDollarsInTemplate"])(url);
}
function setTrackByIndex(index) {
thumbnailTracks.setTrackByIndex(index);
}
function getCurrentTrackIndex() {
return thumbnailTracks.getCurrentTrackIndex();
}
function getBitrateList() {
var tracks = thumbnailTracks.getTracks();
var i = 0;
return tracks.map(function (t) {
var bitrateInfo = new _vo_BitrateInfo__WEBPACK_IMPORTED_MODULE_4__["default"]();
bitrateInfo.mediaType = _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].IMAGE;
bitrateInfo.qualityIndex = i++;
bitrateInfo.bitrate = t.bitrate;
bitrateInfo.width = t.width;
bitrateInfo.height = t.height;
return bitrateInfo;
});
}
function reset() {
if (thumbnailTracks) {
thumbnailTracks.reset();
}
}
instance = {
getStreamId: getStreamId,
initialize: initialize,
provide: provide,
setTrackByIndex: setTrackByIndex,
getCurrentTrackIndex: getCurrentTrackIndex,
getBitrateList: getBitrateList,
reset: reset
};
setup();
return instance;
}
ThumbnailController.__dashjs_factory_name = 'ThumbnailController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(ThumbnailController));
/***/ }),
/***/ "./src/streaming/thumbnail/ThumbnailTracks.js":
/*!****************************************************!*\
!*** ./src/streaming/thumbnail/ThumbnailTracks.js ***!
\****************************************************/
/*! exports provided: THUMBNAILS_SCHEME_ID_URIS, default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "THUMBNAILS_SCHEME_ID_URIS", function() { return THUMBNAILS_SCHEME_ID_URIS; });
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../dash/constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_ThumbnailTrackInfo__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../vo/ThumbnailTrackInfo */ "./src/streaming/vo/ThumbnailTrackInfo.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../dash/utils/SegmentsUtils */ "./src/dash/utils/SegmentsUtils.js");
/* harmony import */ var _streaming_utils_BoxParser__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../streaming/utils/BoxParser */ "./src/streaming/utils/BoxParser.js");
/* harmony import */ var _streaming_net_XHRLoader__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../streaming/net/XHRLoader */ "./src/streaming/net/XHRLoader.js");
/* harmony import */ var _dash_DashHandler__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../dash/DashHandler */ "./src/dash/DashHandler.js");
/* harmony import */ var _dash_controllers_SegmentsController__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../dash/controllers/SegmentsController */ "./src/dash/controllers/SegmentsController.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var THUMBNAILS_SCHEME_ID_URIS = ['http://dashif.org/thumbnail_tile', 'http://dashif.org/guidelines/thumbnail_tile'];
function ThumbnailTracks(config) {
var context = this.context;
var adapter = config.adapter;
var baseURLController = config.baseURLController;
var streamInfo = config.streamInfo;
var timelineConverter = config.timelineConverter;
var debug = config.debug;
var eventBus = config.eventBus;
var events = config.events;
var dashConstants = config.dashConstants;
var urlUtils = Object(_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
var instance, tracks, dashHandler, currentTrackIndex, mediaInfo, segmentsController, loader, boxParser;
function setup() {
reset();
loader = Object(_streaming_net_XHRLoader__WEBPACK_IMPORTED_MODULE_7__["default"])(context).create({});
boxParser = Object(_streaming_utils_BoxParser__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
segmentsController = Object(_dash_controllers_SegmentsController__WEBPACK_IMPORTED_MODULE_9__["default"])(context).create({
events: events,
eventBus: eventBus,
streamInfo: streamInfo,
timelineConverter: timelineConverter,
dashConstants: dashConstants,
dashMetrics: config.dashMetrics,
segmentBaseController: config.segmentBaseController,
type: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE
});
dashHandler = Object(_dash_DashHandler__WEBPACK_IMPORTED_MODULE_8__["default"])(context).create({
streamInfo: streamInfo,
type: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE,
timelineConverter: timelineConverter,
segmentsController: segmentsController,
baseURLController: baseURLController,
debug: debug,
eventBus: eventBus,
events: events,
dashConstants: dashConstants,
urlUtils: urlUtils
}); // initialize controllers
dashHandler.initialize(adapter ? adapter.getIsDynamic() : false);
}
function addTracks() {
if (!streamInfo || !adapter) {
return;
} // Extract thumbnail tracks
mediaInfo = adapter.getMediaInfoForType(streamInfo, _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE);
if (!mediaInfo) {
return;
}
var voReps = adapter.getVoRepresentations(mediaInfo);
if (voReps && voReps.length > 0) {
voReps.forEach(function (rep) {
if (rep.segmentInfoType === _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TEMPLATE && rep.segmentDuration > 0 && rep.media || rep.segmentInfoType === _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE) {
_createTrack(rep);
}
if (rep.segmentInfoType === _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_BASE) {
_createTrack(rep, true);
}
});
}
if (tracks.length > 0) {
// Sort bitrates and select the lowest bitrate rendition
tracks.sort(function (a, b) {
return a.bitrate - b.bitrate;
});
}
}
function _createTrack(representation, useSegmentBase) {
var track = new _vo_ThumbnailTrackInfo__WEBPACK_IMPORTED_MODULE_3__["default"]();
track.id = representation.id;
track.bitrate = representation.bandwidth;
track.width = representation.width;
track.height = representation.height;
track.tilesHor = 1;
track.tilesVert = 1;
if (representation.essentialProperties) {
representation.essentialProperties.forEach(function (p) {
if (THUMBNAILS_SCHEME_ID_URIS.indexOf(p.schemeIdUri) >= 0 && p.value) {
var vars = p.value.split('x');
if (vars.length === 2 && !isNaN(vars[0]) && !isNaN(vars[1])) {
track.tilesHor = parseInt(vars[0], 10);
track.tilesVert = parseInt(vars[1], 10);
}
}
});
}
if (useSegmentBase) {
segmentsController.updateSegmentData(representation).then(function (data) {
_handleUpdatedSegmentData(track, representation, data);
});
} else {
track.startNumber = representation.startNumber;
track.segmentDuration = representation.segmentDuration;
track.timescale = representation.timescale;
track.templateUrl = buildTemplateUrl(representation);
}
if (track.tilesHor > 0 && track.tilesVert > 0) {
// Precalculate width and heigth per tile for perf reasons
track.widthPerTile = track.width / track.tilesHor;
track.heightPerTile = track.height / track.tilesVert;
tracks.push(track);
}
}
function _handleUpdatedSegmentData(track, representation, data) {
var cache = [];
var segments = _normalizeSegments(data, representation);
representation.segments = segments;
track.segmentDuration = representation.segments[0].duration; //assume all segments have the same duration
track.readThumbnail = function (time, callback) {
var cached = null;
cache.some(function (el) {
if (el.start <= time && el.end > time) {
cached = el.url;
return true;
}
});
if (cached) {
callback(cached);
} else {
representation.segments.some(function (ss) {
if (ss.mediaStartTime <= time && ss.mediaStartTime + ss.duration > time) {
var baseURL = baseURLController.resolve(representation.path);
loader.load({
method: 'get',
url: baseURL.url,
request: {
range: ss.mediaRange,
responseType: 'arraybuffer'
},
onload: function onload(e) {
var info = boxParser.getSamplesInfo(e.target.response);
var blob = new Blob([e.target.response.slice(info.sampleList[0].offset, info.sampleList[0].offset + info.sampleList[0].size)], {
type: 'image/jpeg'
});
var imageUrl = window.URL.createObjectURL(blob);
cache.push({
start: ss.mediaStartTime,
end: ss.mediaStartTime + ss.duration,
url: imageUrl
});
if (callback) callback(imageUrl);
}
});
return true;
}
});
}
};
}
function _normalizeSegments(data, representation) {
var segments = [];
var count = 0;
var i, len, s, seg;
for (i = 0, len = data.segments.length; i < len; i++) {
s = data.segments[i];
seg = Object(_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__["getTimeBasedSegment"])(timelineConverter, adapter.getIsDynamic(), representation, s.startTime, s.duration, s.timescale, s.media, s.mediaRange, count);
if (seg) {
segments.push(seg);
seg = null;
count++;
}
}
return segments;
}
function buildTemplateUrl(representation) {
var templateUrl = urlUtils.isRelative(representation.media) ? urlUtils.resolve(representation.media, baseURLController.resolve(representation.path).url) : representation.media;
if (!templateUrl) {
return '';
}
return Object(_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__["replaceIDForTemplate"])(templateUrl, representation.id);
}
function getTracks() {
return tracks;
}
function getCurrentTrackIndex() {
return currentTrackIndex;
}
function getCurrentTrack() {
if (currentTrackIndex < 0) {
return null;
}
return tracks[currentTrackIndex];
}
function setTrackByIndex(index) {
if (!tracks || tracks.length === 0) {
return;
} // select highest bitrate in case selected index is higher than bitrate list length
if (index >= tracks.length) {
index = tracks.length - 1;
}
currentTrackIndex = index;
}
function getThumbnailRequestForTime(time) {
var currentVoRep;
var voReps = adapter.getVoRepresentations(mediaInfo);
for (var i = 0; i < voReps.length; i++) {
if (tracks[currentTrackIndex].id === voReps[i].id) {
currentVoRep = voReps[i];
break;
}
}
return dashHandler.getSegmentRequestForTime(mediaInfo, currentVoRep, time);
}
function reset() {
tracks = [];
currentTrackIndex = -1;
mediaInfo = null;
}
instance = {
getTracks: getTracks,
addTracks: addTracks,
reset: reset,
setTrackByIndex: setTrackByIndex,
getCurrentTrack: getCurrentTrack,
getCurrentTrackIndex: getCurrentTrackIndex,
getThumbnailRequestForTime: getThumbnailRequestForTime
};
setup();
return instance;
}
ThumbnailTracks.__dashjs_factory_name = 'ThumbnailTracks';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(ThumbnailTracks));
/***/ }),
/***/ "./src/streaming/utils/BaseURLSelector.js":
/*!************************************************!*\
!*** ./src/streaming/utils/BaseURLSelector.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../controllers/BlacklistController */ "./src/streaming/controllers/BlacklistController.js");
/* harmony import */ var _baseUrlResolution_DVBSelector__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./baseUrlResolution/DVBSelector */ "./src/streaming/utils/baseUrlResolution/DVBSelector.js");
/* harmony import */ var _baseUrlResolution_BasicSelector__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./baseUrlResolution/BasicSelector */ "./src/streaming/utils/baseUrlResolution/BasicSelector.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function BaseURLSelector() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
var instance, serviceLocationBlacklistController, basicSelector, dvbSelector, selector;
function setup() {
serviceLocationBlacklistController = Object(_controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
updateEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].SERVICE_LOCATION_BLACKLIST_CHANGED,
addBlacklistEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].SERVICE_LOCATION_BLACKLIST_ADD
});
basicSelector = Object(_baseUrlResolution_BasicSelector__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
blacklistController: serviceLocationBlacklistController
});
dvbSelector = Object(_baseUrlResolution_DVBSelector__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
blacklistController: serviceLocationBlacklistController
});
selector = basicSelector;
}
function setConfig(config) {
if (config.selector) {
selector = config.selector;
}
}
function chooseSelector(isDVB) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_8__["checkParameterType"])(isDVB, 'boolean');
selector = isDVB ? dvbSelector : basicSelector;
}
function select(data) {
if (!data) {
return;
}
var baseUrls = data.baseUrls;
var selectedIdx = data.selectedIdx; // Once a random selection has been carried out amongst a group of BaseURLs with the same
// @priority attribute value, then that choice should be re-used if the selection needs to be made again
// unless the blacklist has been modified or the available BaseURLs have changed.
if (!isNaN(selectedIdx)) {
return baseUrls[selectedIdx];
}
var selectedBaseUrl = selector.select(baseUrls);
if (!selectedBaseUrl) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].URL_RESOLUTION_FAILED, {
error: new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_7__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_0__["default"].URL_RESOLUTION_FAILED_GENERIC_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_0__["default"].URL_RESOLUTION_FAILED_GENERIC_ERROR_MESSAGE)
});
if (selector === basicSelector) {
reset();
}
return;
}
data.selectedIdx = baseUrls.indexOf(selectedBaseUrl);
return selectedBaseUrl;
}
function reset() {
serviceLocationBlacklistController.reset();
}
instance = {
chooseSelector: chooseSelector,
select: select,
reset: reset,
setConfig: setConfig
};
setup();
return instance;
}
BaseURLSelector.__dashjs_factory_name = 'BaseURLSelector';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_6__["default"].getClassFactory(BaseURLSelector));
/***/ }),
/***/ "./src/streaming/utils/BoxParser.js":
/*!******************************************!*\
!*** ./src/streaming/utils/BoxParser.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _IsoFile__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./IsoFile */ "./src/streaming/utils/IsoFile.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! codem-isoboxer */ "./node_modules/codem-isoboxer/dist/iso_boxer.js");
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(codem_isoboxer__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/IsoBoxSearchInfo */ "./src/streaming/vo/IsoBoxSearchInfo.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function BoxParser()
/*config*/
{
var logger, instance;
var context = this.context;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
}
/**
* @param {ArrayBuffer} data
* @returns {IsoFile|null}
* @memberof BoxParser#
*/
function parse(data) {
if (!data) return null;
if (data.fileStart === undefined) {
data.fileStart = 0;
}
var parsedFile = codem_isoboxer__WEBPACK_IMPORTED_MODULE_3___default.a.parseBuffer(data);
var dashIsoFile = Object(_IsoFile__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
dashIsoFile.setData(parsedFile);
return dashIsoFile;
}
/**
* From the list of type boxes to look for, returns the latest one that is fully completed (header + payload). This
* method only looks into the list of top boxes and doesn't analyze nested boxes.
* @param {string[]} types
* @param {ArrayBuffer|uint8Array} buffer
* @param {number} offset
* @returns {IsoBoxSearchInfo}
* @memberof BoxParser#
*/
function findLastTopIsoBoxCompleted(types, buffer, offset) {
if (offset === undefined) {
offset = 0;
} // 8 = size (uint32) + type (4 characters)
if (!buffer || offset + 8 >= buffer.byteLength) {
return new _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__["default"](0, false);
}
var data = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : buffer;
var boxInfo;
var lastCompletedOffset = 0;
while (offset < data.byteLength) {
var boxSize = parseUint32(data, offset);
var boxType = parseIsoBoxType(data, offset + 4);
if (boxSize === 0) {
break;
}
if (offset + boxSize <= data.byteLength) {
if (types.indexOf(boxType) >= 0) {
boxInfo = new _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__["default"](offset, true, boxSize);
} else {
lastCompletedOffset = offset + boxSize;
}
}
offset += boxSize;
}
if (!boxInfo) {
return new _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__["default"](lastCompletedOffset, false);
}
return boxInfo;
}
function getSamplesInfo(ab) {
if (!ab || ab.byteLength === 0) {
return {
sampleList: [],
lastSequenceNumber: NaN,
totalDuration: NaN,
numSequences: NaN
};
}
var isoFile = parse(ab); // zero or more moofs
var moofBoxes = isoFile.getBoxes('moof'); // exactly one mfhd per moof
var mfhdBoxes = isoFile.getBoxes('mfhd');
var sampleDuration, sampleCompositionTimeOffset, sampleCount, sampleSize, sampleDts, sampleList, sample, i, j, k, l, m, n, dataOffset, lastSequenceNumber, numSequences, totalDuration;
numSequences = isoFile.getBoxes('moof').length;
lastSequenceNumber = mfhdBoxes[mfhdBoxes.length - 1].sequence_number;
sampleCount = 0;
sampleList = [];
var subsIndex = -1;
var nextSubsSample = -1;
for (l = 0; l < moofBoxes.length; l++) {
var moofBox = moofBoxes[l]; // zero or more trafs per moof
var trafBoxes = moofBox.getChildBoxes('traf');
for (j = 0; j < trafBoxes.length; j++) {
var trafBox = trafBoxes[j]; // exactly one tfhd per traf
var tfhdBox = trafBox.getChildBox('tfhd'); // zero or one tfdt per traf
var tfdtBox = trafBox.getChildBox('tfdt');
sampleDts = tfdtBox.baseMediaDecodeTime; // zero or more truns per traf
var trunBoxes = trafBox.getChildBoxes('trun'); // zero or more subs per traf
var subsBoxes = trafBox.getChildBoxes('subs');
for (k = 0; k < trunBoxes.length; k++) {
var trunBox = trunBoxes[k];
sampleCount = trunBox.sample_count;
dataOffset = (tfhdBox.base_data_offset || 0) + (trunBox.data_offset || 0);
for (i = 0; i < sampleCount; i++) {
sample = trunBox.samples[i];
sampleDuration = sample.sample_duration !== undefined ? sample.sample_duration : tfhdBox.default_sample_duration;
sampleSize = sample.sample_size !== undefined ? sample.sample_size : tfhdBox.default_sample_size;
sampleCompositionTimeOffset = sample.sample_composition_time_offset !== undefined ? sample.sample_composition_time_offset : 0;
var sampleData = {
'dts': sampleDts,
'cts': sampleDts + sampleCompositionTimeOffset,
'duration': sampleDuration,
'offset': moofBox.offset + dataOffset,
'size': sampleSize,
'subSizes': [sampleSize]
};
if (subsBoxes) {
for (m = 0; m < subsBoxes.length; m++) {
var subsBox = subsBoxes[m];
if (subsIndex < subsBox.entry_count - 1 && i > nextSubsSample) {
subsIndex++;
nextSubsSample += subsBox.entries[subsIndex].sample_delta;
}
if (i == nextSubsSample) {
sampleData.subSizes = [];
var entry = subsBox.entries[subsIndex];
for (n = 0; n < entry.subsample_count; n++) {
sampleData.subSizes.push(entry.subsamples[n].subsample_size);
}
}
}
}
sampleList.push(sampleData);
dataOffset += sampleSize;
sampleDts += sampleDuration;
}
}
totalDuration = sampleDts - tfdtBox.baseMediaDecodeTime;
}
}
return {
sampleList: sampleList,
lastSequenceNumber: lastSequenceNumber,
totalDuration: totalDuration,
numSequences: numSequences
};
}
function getMediaTimescaleFromMoov(ab) {
var isoFile = parse(ab);
var mdhdBox = isoFile ? isoFile.getBox('mdhd') : undefined;
return mdhdBox ? mdhdBox.timescale : NaN;
}
function parseUint32(data, offset) {
return data[offset + 3] >>> 0 | data[offset + 2] << 8 >>> 0 | data[offset + 1] << 16 >>> 0 | data[offset] << 24 >>> 0;
}
function parseIsoBoxType(data, offset) {
return String.fromCharCode(data[offset++]) + String.fromCharCode(data[offset++]) + String.fromCharCode(data[offset++]) + String.fromCharCode(data[offset]);
}
function findInitRange(data) {
var initRange = null;
var start, end;
var isoFile = parse(data);
if (!isoFile) {
return initRange;
}
var ftyp = isoFile.getBox('ftyp');
var moov = isoFile.getBox('moov');
logger.debug('Searching for initialization.');
if (moov && moov.isComplete) {
start = ftyp ? ftyp.offset : moov.offset;
end = moov.offset + moov.size - 1;
initRange = start + '-' + end;
logger.debug('Found the initialization. Range: ' + initRange);
}
return initRange;
}
/**
* Real-time parsing (whenever data is loaded in the buffer payload) of the payload to capture the moof of a chunk
* @param {array} types
* @param {ArrayBuffer} buffer
* @param {number} offset
* @return {IsoBoxSearchInfo}
*/
function parsePayload(types, buffer, offset) {
if (offset === undefined) {
offset = 0;
}
if (!buffer || offset + 8 >= buffer.byteLength) {
return new _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__["default"](0, false);
}
var data = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : buffer;
var boxInfo;
var lastCompletedOffset = 0;
while (offset < data.byteLength) {
var boxSize = parseUint32(data, offset);
var boxType = parseIsoBoxType(data, offset + 4);
if (boxSize === 0) {
break;
}
if (offset + boxSize <= data.byteLength) {
if (types.indexOf(boxType) >= 0) {
boxInfo = new _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__["default"](offset, true, boxSize, boxType);
} else {
lastCompletedOffset = offset + boxSize;
}
}
offset += boxSize;
}
if (!boxInfo) {
return new _vo_IsoBoxSearchInfo__WEBPACK_IMPORTED_MODULE_4__["default"](lastCompletedOffset, false);
}
return boxInfo;
}
instance = {
parse: parse,
findLastTopIsoBoxCompleted: findLastTopIsoBoxCompleted,
getMediaTimescaleFromMoov: getMediaTimescaleFromMoov,
getSamplesInfo: getSamplesInfo,
findInitRange: findInitRange,
parsePayload: parsePayload
};
setup();
return instance;
}
BoxParser.__dashjs_factory_name = 'BoxParser';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(BoxParser));
/***/ }),
/***/ "./src/streaming/utils/Capabilities.js":
/*!*********************************************!*\
!*** ./src/streaming/utils/Capabilities.js ***!
\*********************************************/
/*! exports provided: supportsMediaSource, default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "supportsMediaSource", function() { return supportsMediaSource; });
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _thumbnail_ThumbnailTracks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../thumbnail/ThumbnailTracks */ "./src/streaming/thumbnail/ThumbnailTracks.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var codecCompatibilityTable = [{
'codec': 'avc1',
'compatibleCodecs': ['avc3']
}, {
'codec': 'avc3',
'compatibleCodecs': ['avc1']
}];
function supportsMediaSource() {
var hasWebKit = ('WebKitMediaSource' in window);
var hasMediaSource = ('MediaSource' in window);
return hasWebKit || hasMediaSource;
}
function Capabilities() {
var instance, settings, encryptedMediaSupported;
function setup() {
encryptedMediaSupported = false;
}
function setConfig(config) {
if (!config) {
return;
}
if (config.settings) {
settings = config.settings;
}
}
/**
* Returns whether Encrypted Media Extensions are supported on this
* user agent
*
* @return {boolean} true if EME is supported, false otherwise
*/
function supportsEncryptedMedia() {
return encryptedMediaSupported;
}
/**
*
* @param {boolean} value
*/
function setEncryptedMediaSupported(value) {
encryptedMediaSupported = value;
}
/**
* Check if a codec is supported by the MediaSource. We use the MediaCapabilities API or the MSE to check.
* @param {object} config
* @param {string} type
* @return {Promise<boolean>}
*/
function supportsCodec(config, type) {
if (type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].AUDIO && type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].VIDEO) {
return Promise.resolve(true);
}
if (_canUseMediaCapabilitiesApi(config, type)) {
return _checkCodecWithMediaCapabilities(config, type);
}
return _checkCodecWithMse(config);
}
/**
* MediaCapabilitiesAPI throws an error if one of the attribute is missing. We only use it if we have all required information.
* @param {object} config
* @param {string} type
* @return {*|boolean|boolean}
* @private
*/
function _canUseMediaCapabilitiesApi(config, type) {
return settings.get().streaming.capabilities.useMediaCapabilitiesApi && navigator.mediaCapabilities && navigator.mediaCapabilities.decodingInfo && (config.codec && type === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].AUDIO || type === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].VIDEO && config.codec && config.width && config.height && config.bitrate && config.framerate);
}
/**
* Check codec support using the MSE
* @param {object} config
* @return {Promise<void> | Promise<boolean>}
* @private
*/
function _checkCodecWithMse(config) {
return new Promise(function (resolve) {
if (!config || !config.codec) {
resolve(false);
return;
}
var codec = config.codec;
if (config.width && config.height) {
codec += ';width="' + config.width + '";height="' + config.height + '"';
}
if ('MediaSource' in window && MediaSource.isTypeSupported(codec)) {
resolve(true);
return;
} else if ('WebKitMediaSource' in window && WebKitMediaSource.isTypeSupported(codec)) {
resolve(true);
return;
}
resolve(false);
});
}
/**
* Check codec support using the MediaCapabilities API
* @param {object} config
* @param {string} type
* @return {Promise<boolean>}
* @private
*/
function _checkCodecWithMediaCapabilities(config, type) {
return new Promise(function (resolve) {
if (!config || !config.codec) {
resolve(false);
return;
}
var configuration = {
type: 'media-source'
};
configuration[type] = {};
configuration[type].contentType = config.codec;
configuration[type].width = config.width;
configuration[type].height = config.height;
configuration[type].bitrate = parseInt(config.bitrate);
configuration[type].framerate = parseFloat(config.framerate);
navigator.mediaCapabilities.decodingInfo(configuration).then(function (result) {
resolve(result.supported);
})["catch"](function () {
resolve(false);
});
});
}
/**
* Check if a specific EssentialProperty is supported
* @param {object} ep
* @return {boolean}
*/
function supportsEssentialProperty(ep) {
try {
return _thumbnail_ThumbnailTracks__WEBPACK_IMPORTED_MODULE_1__["THUMBNAILS_SCHEME_ID_URIS"].indexOf(ep.schemeIdUri) !== -1;
} catch (e) {
return true;
}
}
/**
* Check if the root of the old codec is the same as the new one, or if it's declared as compatible in the compat table
* @param {string} codec1
* @param {string} codec2
* @return {boolean}
*/
function codecRootCompatibleWithCodec(codec1, codec2) {
var codecRoot = codec1.split('.')[0];
var rootCompatible = codec2.indexOf(codecRoot) === 0;
var compatTableCodec;
for (var i = 0; i < codecCompatibilityTable.length; i++) {
if (codecCompatibilityTable[i].codec === codecRoot) {
compatTableCodec = codecCompatibilityTable[i];
break;
}
}
if (compatTableCodec) {
return rootCompatible || compatTableCodec.compatibleCodecs.some(function (compatibleCodec) {
return codec2.indexOf(compatibleCodec) === 0;
});
}
return rootCompatible;
}
instance = {
setConfig: setConfig,
supportsMediaSource: supportsMediaSource,
supportsEncryptedMedia: supportsEncryptedMedia,
supportsCodec: supportsCodec,
setEncryptedMediaSupported: setEncryptedMediaSupported,
supportsEssentialProperty: supportsEssentialProperty,
codecRootCompatibleWithCodec: codecRootCompatibleWithCodec
};
setup();
return instance;
}
Capabilities.__dashjs_factory_name = 'Capabilities';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(Capabilities));
/***/ }),
/***/ "./src/streaming/utils/CapabilitiesFilter.js":
/*!***************************************************!*\
!*** ./src/streaming/utils/CapabilitiesFilter.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
function CapabilitiesFilter() {
var context = this.context;
var instance, adapter, capabilities, settings, logger, customCapabilitiesFilters;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
}
function setConfig(config) {
if (!config) {
return;
}
if (config.adapter) {
adapter = config.adapter;
}
if (config.capabilities) {
capabilities = config.capabilities;
}
if (config.settings) {
settings = config.settings;
}
}
function filterUnsupportedFeatures(manifest) {
return new Promise(function (resolve) {
var promises = [];
promises.push(_filterUnsupportedCodecs(_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].VIDEO, manifest));
promises.push(_filterUnsupportedCodecs(_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].AUDIO, manifest));
Promise.all(promises).then(function () {
if (settings.get().streaming.capabilities.filterUnsupportedEssentialProperties) {
_filterUnsupportedEssentialProperties(manifest);
}
_applyCustomFilters(manifest);
resolve();
})["catch"](function () {
resolve();
});
});
}
function _filterUnsupportedCodecs(type, manifest) {
if (!manifest || !manifest.Period_asArray || manifest.Period_asArray.length === 0) {
return Promise.resolve();
}
var promises = [];
manifest.Period_asArray.forEach(function (period) {
promises.push(_filterUnsupportedAdaptationSetsOfPeriod(period, type));
});
return Promise.all(promises);
}
function _filterUnsupportedAdaptationSetsOfPeriod(period, type) {
return new Promise(function (resolve) {
if (!period || !period.AdaptationSet_asArray || period.AdaptationSet_asArray.length === 0) {
resolve();
return;
}
var promises = [];
period.AdaptationSet_asArray.forEach(function (as) {
if (adapter.getIsTypeOf(as, type)) {
promises.push(_filterUnsupportedRepresentationsOfAdaptation(as, type));
}
});
Promise.all(promises).then(function () {
period.AdaptationSet_asArray = period.AdaptationSet_asArray.filter(function (as) {
var supported = as.Representation_asArray && as.Representation_asArray.length > 0;
if (!supported) {
logger.warn("AdaptationSet has been removed because of no supported Representation");
}
return supported;
});
resolve();
})["catch"](function () {
resolve();
});
});
}
function _filterUnsupportedRepresentationsOfAdaptation(as, type) {
return new Promise(function (resolve) {
if (!as.Representation_asArray || as.Representation_asArray.length === 0) {
resolve();
return;
}
var promises = [];
var configurations = [];
as.Representation_asArray.forEach(function (rep, i) {
var codec = adapter.getCodec(as, i, false);
var config = _createConfiguration(type, rep, codec);
configurations.push(config);
promises.push(capabilities.supportsCodec(config, type));
});
Promise.all(promises).then(function (supported) {
as.Representation_asArray = as.Representation_asArray.filter(function (_, i) {
if (!supported[i]) {
logger.debug("[Stream] Codec ".concat(configurations[i].codec, " not supported "));
}
return supported[i];
});
resolve();
})["catch"](function () {
resolve();
});
});
}
function _createConfiguration(type, rep, codec) {
switch (type) {
case _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].VIDEO:
return _createVideoConfiguration(rep, codec);
case _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].AUDIO:
return _createAudioConfiguration(rep, codec);
default:
return null;
}
}
function _createVideoConfiguration(rep, codec) {
var width = rep.width || null;
var height = rep.height || null;
var framerate = rep.frameRate || null;
var bitrate = rep.bandwidth || null;
return {
codec: codec,
width: width,
height: height,
framerate: framerate,
bitrate: bitrate
};
}
function _createAudioConfiguration(rep, codec) {
var samplerate = rep.audioSamplingRate || null;
var bitrate = rep.bandwidth || null;
return {
codec: codec,
bitrate: bitrate,
samplerate: samplerate
};
}
function _filterUnsupportedEssentialProperties(manifest) {
if (!manifest || !manifest.Period_asArray || manifest.Period_asArray.length === 0) {
return;
}
manifest.Period_asArray.forEach(function (period) {
period.AdaptationSet_asArray = period.AdaptationSet_asArray.filter(function (as) {
if (!as.Representation_asArray || as.Representation_asArray.length === 0) {
return true;
}
as.Representation_asArray = as.Representation_asArray.filter(function (rep) {
var essentialProperties = adapter.getEssentialPropertiesForRepresentation(rep);
if (essentialProperties && essentialProperties.length > 0) {
var i = 0;
while (i < essentialProperties.length) {
if (!capabilities.supportsEssentialProperty(essentialProperties[i])) {
logger.debug('[Stream] EssentialProperty not supported: ' + essentialProperties[i].schemeIdUri);
return false;
}
i += 1;
}
}
return true;
});
return as.Representation_asArray && as.Representation_asArray.length > 0;
});
});
}
function _applyCustomFilters(manifest) {
if (!customCapabilitiesFilters || customCapabilitiesFilters.length === 0 || !manifest || !manifest.Period_asArray || manifest.Period_asArray.length === 0) {
return;
}
manifest.Period_asArray.forEach(function (period) {
period.AdaptationSet_asArray = period.AdaptationSet_asArray.filter(function (as) {
if (!as.Representation_asArray || as.Representation_asArray.length === 0) {
return true;
}
as.Representation_asArray = as.Representation_asArray.filter(function (representation) {
return !customCapabilitiesFilters.some(function (customFilter) {
return !customFilter(representation);
});
});
return as.Representation_asArray && as.Representation_asArray.length > 0;
});
});
}
function setCustomCapabilitiesFilters(customFilters) {
customCapabilitiesFilters = customFilters;
}
instance = {
setConfig: setConfig,
filterUnsupportedFeatures: filterUnsupportedFeatures,
setCustomCapabilitiesFilters: setCustomCapabilitiesFilters
};
setup();
return instance;
}
CapabilitiesFilter.__dashjs_factory_name = 'CapabilitiesFilter';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(CapabilitiesFilter));
/***/ }),
/***/ "./src/streaming/utils/CustomTimeRanges.js":
/*!*************************************************!*\
!*** ./src/streaming/utils/CustomTimeRanges.js ***!
\*************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function CustomTimeRanges()
/*config*/
{
var customTimeRangeArray = [];
var length = 0;
function add(start, end) {
var i = 0;
for (i = 0; i < this.customTimeRangeArray.length && start > this.customTimeRangeArray[i].start; i++) {
}
this.customTimeRangeArray.splice(i, 0, {
start: start,
end: end
});
for (i = 0; i < this.customTimeRangeArray.length - 1; i++) {
if (this.mergeRanges(i, i + 1)) {
i--;
}
}
this.length = this.customTimeRangeArray.length;
}
function clear() {
this.customTimeRangeArray = [];
this.length = 0;
}
function remove(start, end) {
for (var i = 0; i < this.customTimeRangeArray.length; i++) {
if (start <= this.customTimeRangeArray[i].start && end >= this.customTimeRangeArray[i].end) {
// |--------------Range i-------|
//|---------------Range to remove ---------------|
// or
//|--------------Range i-------|
//|--------------Range to remove ---------------|
// or
// |--------------Range i-------|
//|--------------Range to remove ---------------|
this.customTimeRangeArray.splice(i, 1);
i--;
} else if (start > this.customTimeRangeArray[i].start && end < this.customTimeRangeArray[i].end) {
//|-----------------Range i----------------|
// |-------Range to remove -----|
this.customTimeRangeArray.splice(i + 1, 0, {
start: end,
end: this.customTimeRangeArray[i].end
});
this.customTimeRangeArray[i].end = start;
break;
} else if (start > this.customTimeRangeArray[i].start && start < this.customTimeRangeArray[i].end) {
//|-----------Range i----------|
// |---------Range to remove --------|
// or
//|-----------------Range i----------------|
// |-------Range to remove -----|
this.customTimeRangeArray[i].end = start;
} else if (end > this.customTimeRangeArray[i].start && end < this.customTimeRangeArray[i].end) {
// |-----------Range i----------|
//|---------Range to remove --------|
// or
//|-----------------Range i----------------|
//|-------Range to remove -----|
this.customTimeRangeArray[i].start = end;
}
}
this.length = this.customTimeRangeArray.length;
}
function mergeRanges(rangeIndex1, rangeIndex2) {
var range1 = this.customTimeRangeArray[rangeIndex1];
var range2 = this.customTimeRangeArray[rangeIndex2];
if (range1.start <= range2.start && range2.start <= range1.end && range1.end <= range2.end) {
//|-----------Range1----------|
// |-----------Range2----------|
range1.end = range2.end;
this.customTimeRangeArray.splice(rangeIndex2, 1);
return true;
} else if (range2.start <= range1.start && range1.start <= range2.end && range2.end <= range1.end) {
// |-----------Range1----------|
//|-----------Range2----------|
range1.start = range2.start;
this.customTimeRangeArray.splice(rangeIndex2, 1);
return true;
} else if (range2.start <= range1.start && range1.start <= range2.end && range1.end <= range2.end) {
// |--------Range1-------|
//|---------------Range2--------------|
this.customTimeRangeArray.splice(rangeIndex1, 1);
return true;
} else if (range1.start <= range2.start && range2.start <= range1.end && range2.end <= range1.end) {
//|-----------------Range1--------------|
// |-----------Range2----------|
this.customTimeRangeArray.splice(rangeIndex2, 1);
return true;
}
return false;
}
function start(index) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_1__["checkInteger"])(index);
if (index >= this.customTimeRangeArray.length || index < 0) {
return NaN;
}
return this.customTimeRangeArray[index].start;
}
function end(index) {
Object(_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_1__["checkInteger"])(index);
if (index >= this.customTimeRangeArray.length || index < 0) {
return NaN;
}
return this.customTimeRangeArray[index].end;
}
return {
customTimeRangeArray: customTimeRangeArray,
length: length,
add: add,
clear: clear,
remove: remove,
mergeRanges: mergeRanges,
start: start,
end: end
};
}
CustomTimeRanges.__dashjs_factory_name = 'CustomTimeRanges';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(CustomTimeRanges));
/***/ }),
/***/ "./src/streaming/utils/DOMStorage.js":
/*!*******************************************!*\
!*** ./src/streaming/utils/DOMStorage.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var legacyKeysAndReplacements = [{
oldKey: 'dashjs_vbitrate',
newKey: 'dashjs_video_bitrate'
}, {
oldKey: 'dashjs_abitrate',
newKey: 'dashjs_audio_bitrate'
}, {
oldKey: 'dashjs_vsettings',
newKey: 'dashjs_video_settings'
}, {
oldKey: 'dashjs_asettings',
newKey: 'dashjs_audio_settings'
}];
var LOCAL_STORAGE_BITRATE_KEY_TEMPLATE = 'dashjs_?_bitrate';
var LOCAL_STORAGE_SETTINGS_KEY_TEMPLATE = 'dashjs_?_settings';
var STORAGE_TYPE_LOCAL = 'localStorage';
var STORAGE_TYPE_SESSION = 'sessionStorage';
var LAST_BITRATE = 'lastBitrate';
var LAST_MEDIA_SETTINGS = 'lastMediaSettings';
function DOMStorage(config) {
config = config || {};
var context = this.context;
var settings = config.settings;
var instance, logger, supported;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
translateLegacyKeys();
} //type can be local, session
function isSupported(type) {
if (supported !== undefined) return supported;
supported = false;
var testKey = '1';
var testValue = '1';
var storage;
try {
if (typeof window !== 'undefined') {
storage = window[type];
}
} catch (error) {
logger.warn('DOMStorage access denied: ' + error.message);
return supported;
}
if (!storage || type !== STORAGE_TYPE_LOCAL && type !== STORAGE_TYPE_SESSION) {
return supported;
}
/* When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage is available, but trying to call setItem throws an exception.
http://stackoverflow.com/questions/14555347/html5-localstorage-error-with-safari-quota-exceeded-err-dom-exception-22-an
Check if the storage can be used
*/
try {
storage.setItem(testKey, testValue);
storage.removeItem(testKey);
supported = true;
} catch (error) {
logger.warn('DOMStorage is supported, but cannot be used: ' + error.message);
}
return supported;
}
function translateLegacyKeys() {
if (isSupported(STORAGE_TYPE_LOCAL)) {
legacyKeysAndReplacements.forEach(function (entry) {
var value = localStorage.getItem(entry.oldKey);
if (value) {
localStorage.removeItem(entry.oldKey);
try {
localStorage.setItem(entry.newKey, value);
} catch (e) {
logger.error(e.message);
}
}
});
}
} // Return current epoch time, ms, rounded to the nearest 10m to avoid fingerprinting user
function getTimestamp() {
var ten_minutes_ms = 60 * 1000 * 10;
return Math.round(new Date().getTime() / ten_minutes_ms) * ten_minutes_ms;
}
function canStore(storageType, key) {
return isSupported(storageType) && settings.get().streaming[key + 'CachingInfo'].enabled;
}
function checkConfig() {
if (!settings) {
throw new Error(_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].MISSING_CONFIG_ERROR);
}
}
function getSavedMediaSettings(type) {
var mediaSettings = null;
checkConfig(); //Checks local storage to see if there is valid, non-expired media settings
if (canStore(STORAGE_TYPE_LOCAL, LAST_MEDIA_SETTINGS)) {
var key = LOCAL_STORAGE_SETTINGS_KEY_TEMPLATE.replace(/\?/, type);
try {
var obj = JSON.parse(localStorage.getItem(key)) || {};
var isExpired = new Date().getTime() - parseInt(obj.timestamp, 10) >= settings.get().streaming.lastMediaSettingsCachingInfo.ttl || false;
mediaSettings = obj.settings;
if (isExpired) {
localStorage.removeItem(key);
mediaSettings = null;
}
} catch (e) {
return null;
}
}
return mediaSettings;
}
function getSavedBitrateSettings(type) {
var savedBitrate = NaN;
checkConfig(); //Checks local storage to see if there is valid, non-expired bit rate
//hinting from the last play session to use as a starting bit rate.
if (canStore(STORAGE_TYPE_LOCAL, LAST_BITRATE)) {
var key = LOCAL_STORAGE_BITRATE_KEY_TEMPLATE.replace(/\?/, type);
try {
var obj = JSON.parse(localStorage.getItem(key)) || {};
var isExpired = new Date().getTime() - parseInt(obj.timestamp, 10) >= settings.get().streaming.lastBitrateCachingInfo.ttl || false;
var bitrate = parseFloat(obj.bitrate);
if (!isNaN(bitrate) && !isExpired) {
savedBitrate = bitrate;
logger.debug('Last saved bitrate for ' + type + ' was ' + bitrate);
} else if (isExpired) {
localStorage.removeItem(key);
}
} catch (e) {
return null;
}
}
return savedBitrate;
}
function setSavedMediaSettings(type, value) {
if (canStore(STORAGE_TYPE_LOCAL, LAST_MEDIA_SETTINGS)) {
var key = LOCAL_STORAGE_SETTINGS_KEY_TEMPLATE.replace(/\?/, type);
try {
localStorage.setItem(key, JSON.stringify({
settings: value,
timestamp: getTimestamp()
}));
} catch (e) {
logger.error(e.message);
}
}
}
function setSavedBitrateSettings(type, bitrate) {
if (canStore(STORAGE_TYPE_LOCAL, LAST_BITRATE) && bitrate) {
var key = LOCAL_STORAGE_BITRATE_KEY_TEMPLATE.replace(/\?/, type);
try {
localStorage.setItem(key, JSON.stringify({
bitrate: bitrate.toFixed(3),
timestamp: getTimestamp()
}));
} catch (e) {
logger.error(e.message);
}
}
}
instance = {
getSavedBitrateSettings: getSavedBitrateSettings,
setSavedBitrateSettings: setSavedBitrateSettings,
getSavedMediaSettings: getSavedMediaSettings,
setSavedMediaSettings: setSavedMediaSettings
};
setup();
return instance;
}
DOMStorage.__dashjs_factory_name = 'DOMStorage';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(DOMStorage);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/utils/DefaultURLUtils.js":
/*!************************************************!*\
!*** ./src/streaming/utils/DefaultURLUtils.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module DefaultURLUtils
* @description Provides utility functions for operating on URLs.
* Initially this is simply a method to determine the Base URL of a URL, but
* should probably include other things provided all over the place such as
* determining whether a URL is relative/absolute, resolving two paths etc.
* @ignore
*/
function DefaultURLUtils() {
var resolveFunction;
var schemeRegex = /^[a-z][a-z0-9+\-_.]*:/i;
var httpUrlRegex = /^https?:\/\//i;
var httpsUrlRegex = /^https:\/\//i;
var originRegex = /^([a-z][a-z0-9+\-_.]*:\/\/[^\/]+)\/?/i;
/**
* Resolves a url given an optional base url
* Uses window.URL to do the resolution.
*
* @param {string} url
* @param {string} [baseUrl]
* @return {string}
* @memberof module:DefaultURLUtils
* @instance
* @private
*/
var nativeURLResolver = function nativeURLResolver(url, baseUrl) {
try {
return new window.URL(url, baseUrl).toString();
} catch (e) {
return url;
}
};
/**
* Resolves a url given an optional base url
* Does not resolve ./, ../ etc but will do enough to construct something
* which will satisfy XHR etc when window.URL is not available ie
* IE11/node etc.
*
* @param {string} url
* @param {string} [baseUrl]
* @return {string}
* @memberof module:DefaultURLUtils
* @instance
* @private
*/
var dumbURLResolver = function dumbURLResolver(url, baseUrl) {
var baseUrlParseFunc = parseBaseUrl;
if (!baseUrl) {
return url;
}
if (!isRelative(url)) {
return url;
}
if (isPathAbsolute(url)) {
baseUrlParseFunc = parseOrigin;
}
if (isSchemeRelative(url)) {
baseUrlParseFunc = parseScheme;
}
var base = baseUrlParseFunc(baseUrl);
var joinChar = base.charAt(base.length - 1) !== '/' && url.charAt(0) !== '/' ? '/' : '';
return [base, url].join(joinChar);
};
function setup() {
try {
var u = new window.URL('x', 'http://y'); // eslint-disable-line
resolveFunction = nativeURLResolver;
} catch (e) {// must be IE11/Node etc
} finally {
resolveFunction = resolveFunction || dumbURLResolver;
}
}
/**
* Returns a string that contains the Base URL of a URL, if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:DefaultURLUtils
* @instance
*/
function parseBaseUrl(url) {
var slashIndex = url.indexOf('/');
var lastSlashIndex = url.lastIndexOf('/');
if (slashIndex !== -1) {
// if there is only '//'
if (lastSlashIndex === slashIndex + 1) {
return url;
}
if (url.indexOf('?') !== -1) {
url = url.substring(0, url.indexOf('?'));
}
return url.substring(0, lastSlashIndex + 1);
}
return '';
}
/**
* Returns a string that contains the scheme and origin of a URL,
* if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:DefaultURLUtils
* @instance
*/
function parseOrigin(url) {
var matches = url.match(originRegex);
if (matches) {
return matches[1];
}
return '';
}
/**
* Returns a string that contains the fragment of a URL without scheme,
* if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:DefaultURLUtils
* @instance
*/
function removeHostname(url) {
var urlParts = /^(?:\w+\:\/\/)?([^\/]+)(.*)$/.exec(url); //[1] = host / [2] = path
return urlParts[2].substring(1);
}
/**
* Returns a string that contains the scheme of a URL, if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:DefaultURLUtils
* @instance
*/
function parseScheme(url) {
var matches = url.match(schemeRegex);
if (matches) {
return matches[0];
}
return '';
}
/**
* Determines whether the url is relative.
* @return {boolean}
* @param {string} url
* @memberof module:DefaultURLUtils
* @instance
*/
function isRelative(url) {
return !schemeRegex.test(url);
}
/**
* Determines whether the url is path-absolute.
* @return {bool}
* @param {string} url
* @memberof module:DefaultURLUtils
* @instance
*/
function isPathAbsolute(url) {
return isRelative(url) && url.charAt(0) === '/';
}
/**
* Determines whether the url is scheme-relative.
* @return {bool}
* @param {string} url
* @memberof module:DefaultURLUtils
* @instance
*/
function isSchemeRelative(url) {
return url.indexOf('//') === 0;
}
/**
* Determines whether the url is an HTTP-URL as defined in ISO/IEC
* 23009-1:2014 3.1.15. ie URL with a fixed scheme of http or https
* @return {bool}
* @param {string} url
* @memberof module:DefaultURLUtils
* @instance
*/
function isHTTPURL(url) {
return httpUrlRegex.test(url);
}
/**
* Determines whether the supplied url has https scheme
* @return {bool}
* @param {string} url
* @memberof module:DefaultURLUtils
* @instance
*/
function isHTTPS(url) {
return httpsUrlRegex.test(url);
}
/**
* Resolves a url given an optional base url
* @return {string}
* @param {string} url
* @param {string} [baseUrl]
* @memberof module:DefaultURLUtils
* @instance
*/
function resolve(url, baseUrl) {
return resolveFunction(url, baseUrl);
}
setup();
var instance = {
parseBaseUrl: parseBaseUrl,
parseOrigin: parseOrigin,
parseScheme: parseScheme,
isRelative: isRelative,
isPathAbsolute: isPathAbsolute,
isSchemeRelative: isSchemeRelative,
isHTTPURL: isHTTPURL,
isHTTPS: isHTTPS,
removeHostname: removeHostname,
resolve: resolve
};
return instance;
}
DefaultURLUtils.__dashjs_factory_name = 'DefaultURLUtils';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(DefaultURLUtils));
/***/ }),
/***/ "./src/streaming/utils/EBMLParser.js":
/*!*******************************************!*\
!*** ./src/streaming/utils/EBMLParser.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* Creates an instance of an EBMLParser class which implements a large subset
* of the functionality required to parse Matroska EBML
*
* @param {Object} config object with data member which is the buffer to parse
* @ignore
*/
function EBMLParser(config) {
config = config || {};
var instance;
var data = new DataView(config.data);
var pos = 0;
function getPos() {
return pos;
}
function setPos(value) {
pos = value;
}
/**
* Consumes an EBML tag from the data stream.
*
* @param {Object} tag to parse, A tag is an object with at least a {number} tag and
* {boolean} required flag.
* @param {boolean} test whether or not the function should throw if a required
* tag is not found
* @return {boolean} whether or not the tag was found
* @throws will throw an exception if a required tag is not found and test
* param is false or undefined, or if the stream is malformed.
* @memberof EBMLParser
*/
function consumeTag(tag, test) {
var found = true;
var bytesConsumed = 0;
var p1, p2;
if (test === undefined) {
test = false;
}
if (tag.tag > 0xFFFFFF) {
if (data.getUint32(pos) !== tag.tag) {
found = false;
}
bytesConsumed = 4;
} else if (tag.tag > 0xFFFF) {
// 3 bytes
p1 = data.getUint16(pos);
p2 = data.getUint8(pos + 2); // shift p1 over a byte and add p2
if (p1 * 256 + p2 !== tag.tag) {
found = false;
}
bytesConsumed = 3;
} else if (tag.tag > 0xFF) {
if (data.getUint16(pos) !== tag.tag) {
found = false;
}
bytesConsumed = 2;
} else {
if (data.getUint8(pos) !== tag.tag) {
found = false;
}
bytesConsumed = 1;
}
if (!found && tag.required && !test) {
throw new Error('required tag not found');
}
if (found) {
pos += bytesConsumed;
}
return found;
}
/**
* Consumes an EBML tag from the data stream. If the tag is found then this
* function will also remove the size field which follows the tag from the
* data stream.
*
* @param {Object} tag to parse, A tag is an object with at least a {number} tag and
* {boolean} required flag.
* @param {boolean} test whether or not the function should throw if a required
* tag is not found
* @return {boolean} whether or not the tag was found
* @throws will throw an exception if a required tag is not found and test
* param is false or undefined, or if the stream is malformedata.
* @memberof EBMLParser
*/
function consumeTagAndSize(tag, test) {
var found = consumeTag(tag, test);
if (found) {
getMatroskaCodedNum();
}
return found;
}
/**
* Consumes an EBML tag from the data stream. If the tag is found then this
* function will also remove the size field which follows the tag from the
* data stream. It will use the value of the size field to parse a binary
* field, using a parser defined in the tag itself
*
* @param {Object} tag to parse, A tag is an object with at least a {number} tag,
* {boolean} required flag, and a parse function which takes a size parameter
* @return {boolean} whether or not the tag was found
* @throws will throw an exception if a required tag is not found,
* or if the stream is malformed
* @memberof EBMLParser
*/
function parseTag(tag) {
var size;
consumeTag(tag);
size = getMatroskaCodedNum();
return instance[tag.parse](size);
}
/**
* Consumes an EBML tag from the data stream. If the tag is found then this
* function will also remove the size field which follows the tag from the
* data stream. It will use the value of the size field to skip over the
* entire section of EBML encapsulated by the tag.
*
* @param {Object} tag to parse, A tag is an object with at least a {number} tag, and
* {boolean} required flag
* @param {boolean} test a flag to indicate if an exception should be thrown
* if a required tag is not found
* @return {boolean} whether or not the tag was found
* @throws will throw an exception if a required tag is not found and test is
* false or undefined or if the stream is malformed
* @memberof EBMLParser
*/
function skipOverElement(tag, test) {
var found = consumeTag(tag, test);
var headerSize;
if (found) {
headerSize = getMatroskaCodedNum();
pos += headerSize;
}
return found;
}
/**
* Returns and consumes a number encoded according to the Matroska EBML
* specification from the bitstream.
*
* @param {boolean} retainMSB whether or not to retain the Most Significant Bit (the
* first 1). this is usually true when reading Tag IDs.
* @return {number} the decoded number
* @throws will throw an exception if the bit stream is malformed or there is
* not enough data
* @memberof EBMLParser
*/
function getMatroskaCodedNum(retainMSB) {
var bytesUsed = 1;
var mask = 0x80;
var maxBytes = 8;
var extraBytes = -1;
var num = 0;
var ch = data.getUint8(pos);
var i = 0;
for (i = 0; i < maxBytes; i += 1) {
if ((ch & mask) === mask) {
num = retainMSB === undefined ? ch & ~mask : ch;
extraBytes = i;
break;
}
mask >>= 1;
}
for (i = 0; i < extraBytes; i += 1, bytesUsed += 1) {
num = num << 8 | 0xff & data.getUint8(pos + bytesUsed);
}
pos += bytesUsed;
return num;
}
/**
* Returns and consumes a float from the bitstream.
*
* @param {number} size 4 or 8 byte floats are supported
* @return {number} the decoded number
* @throws will throw an exception if the bit stream is malformed or there is
* not enough data
* @memberof EBMLParser
*/
function getMatroskaFloat(size) {
var outFloat;
switch (size) {
case 4:
outFloat = data.getFloat32(pos);
pos += 4;
break;
case 8:
outFloat = data.getFloat64(pos);
pos += 8;
break;
}
return outFloat;
}
/**
* Consumes and returns an unsigned int from the bitstream.
*
* @param {number} size 1 to 8 bytes
* @return {number} the decoded number
* @throws will throw an exception if the bit stream is malformed or there is
* not enough data
* @memberof EBMLParser
*/
function getMatroskaUint(size) {
var val = 0;
for (var i = 0; i < size; i += 1) {
val <<= 8;
val |= data.getUint8(pos + i) & 0xff;
}
pos += size;
return val;
}
/**
* Tests whether there is more data in the bitstream for parsing
*
* @return {boolean} whether there is more data to parse
* @memberof EBMLParser
*/
function moreData() {
return pos < data.byteLength;
}
instance = {
getPos: getPos,
setPos: setPos,
consumeTag: consumeTag,
consumeTagAndSize: consumeTagAndSize,
parseTag: parseTag,
skipOverElement: skipOverElement,
getMatroskaCodedNum: getMatroskaCodedNum,
getMatroskaFloat: getMatroskaFloat,
getMatroskaUint: getMatroskaUint,
moreData: moreData
};
return instance;
}
EBMLParser.__dashjs_factory_name = 'EBMLParser';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(EBMLParser));
/***/ }),
/***/ "./src/streaming/utils/ErrorHandler.js":
/*!*********************************************!*\
!*** ./src/streaming/utils/ErrorHandler.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module ErrorHandler
* @ignore
*/
function ErrorHandler() {
var instance;
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
/**
* @param {object} err DashJSError with code, message and data attributes
* @memberof module:ErrorHandler
*/
function error(err) {
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_1__["default"].ERROR, {
error: err
});
}
instance = {
error: error
};
return instance;
}
ErrorHandler.__dashjs_factory_name = 'ErrorHandler';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getSingletonFactory(ErrorHandler));
/***/ }),
/***/ "./src/streaming/utils/InitCache.js":
/*!******************************************!*\
!*** ./src/streaming/utils/InitCache.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Represents data structure to keep and drive {DataChunk}
*/
function InitCache() {
var data = {};
function save(chunk) {
var id = chunk.streamId;
var representationId = chunk.representationId;
data[id] = data[id] || {};
data[id][representationId] = chunk;
}
function extract(streamId, representationId) {
if (data && data[streamId] && data[streamId][representationId]) {
return data[streamId][representationId];
} else {
return null;
}
}
function reset() {
data = {};
}
var instance = {
save: save,
extract: extract,
reset: reset
};
return instance;
}
InitCache.__dashjs_factory_name = 'InitCache';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(InitCache));
/***/ }),
/***/ "./src/streaming/utils/IsoFile.js":
/*!****************************************!*\
!*** ./src/streaming/utils/IsoFile.js ***!
\****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_IsoBox__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/IsoBox */ "./src/streaming/vo/IsoBox.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function IsoFile() {
var instance, parsedIsoFile;
/**
* @param {string} type
* @returns {IsoBox|null}
* @memberof IsoFile#
*/
function getBox(type) {
if (!type || !parsedIsoFile || !parsedIsoFile.boxes || parsedIsoFile.boxes.length === 0 || typeof parsedIsoFile.fetch !== 'function') return null;
return convertToDashIsoBox(parsedIsoFile.fetch(type));
}
/**
* @param {string} type
* @returns {Array|null} array of {@link IsoBox}
* @memberof IsoFile#
*/
function getBoxes(type) {
var boxes = [];
if (!type || !parsedIsoFile || typeof parsedIsoFile.fetchAll !== 'function') {
return boxes;
}
var boxData = parsedIsoFile.fetchAll(type);
var box;
for (var i = 0, ln = boxData.length; i < ln; i++) {
box = convertToDashIsoBox(boxData[i]);
if (box) {
boxes.push(box);
}
}
return boxes;
}
/**
* @param {string} value
* @memberof IsoFile#
*/
function setData(value) {
parsedIsoFile = value;
}
/**
* @returns {IsoBox|null}
* @memberof IsoFile#
*/
function getLastBox() {
if (!parsedIsoFile || !parsedIsoFile.boxes || !parsedIsoFile.boxes.length) return null;
var type = parsedIsoFile.boxes[parsedIsoFile.boxes.length - 1].type;
var boxes = getBoxes(type);
return boxes.length > 0 ? boxes[boxes.length - 1] : null;
}
function convertToDashIsoBox(boxData) {
if (!boxData) return null;
var box = new _vo_IsoBox__WEBPACK_IMPORTED_MODULE_0__["default"](boxData);
if (boxData.hasOwnProperty('_incomplete')) {
box.isComplete = !boxData._incomplete;
}
return box;
}
instance = {
getBox: getBox,
getBoxes: getBoxes,
setData: setData,
getLastBox: getLastBox
};
return instance;
}
IsoFile.__dashjs_factory_name = 'IsoFile';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(IsoFile));
/***/ }),
/***/ "./src/streaming/utils/ObjectUtils.js":
/*!********************************************!*\
!*** ./src/streaming/utils/ObjectUtils.js ***!
\********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var fast_deep_equal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! fast-deep-equal */ "./node_modules/fast-deep-equal/index.js");
/* harmony import */ var fast_deep_equal__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fast_deep_equal__WEBPACK_IMPORTED_MODULE_1__);
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module ObjectUtils
* @ignore
* @description Provides utility functions for objects
*/
function ObjectUtils() {
var instance;
/**
* Returns true if objects are equal
* @return {boolean}
* @param {object} obj1
* @param {object} obj2
* @memberof module:ObjectUtils
* @instance
*/
function areEqual(obj1, obj2) {
return fast_deep_equal__WEBPACK_IMPORTED_MODULE_1___default()(obj1, obj2);
}
instance = {
areEqual: areEqual
};
return instance;
}
ObjectUtils.__dashjs_factory_name = 'ObjectUtils';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(ObjectUtils));
/***/ }),
/***/ "./src/streaming/utils/RequestModifier.js":
/*!************************************************!*\
!*** ./src/streaming/utils/RequestModifier.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function RequestModifier() {
var instance;
function modifyRequestURL(url) {
return url;
}
function modifyRequestHeader(request) {
return request;
}
instance = {
modifyRequestURL: modifyRequestURL,
modifyRequestHeader: modifyRequestHeader
};
return instance;
}
RequestModifier.__dashjs_factory_name = 'RequestModifier';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(RequestModifier));
/***/ }),
/***/ "./src/streaming/utils/SupervisorTools.js":
/*!************************************************!*\
!*** ./src/streaming/utils/SupervisorTools.js ***!
\************************************************/
/*! exports provided: checkParameterType, checkInteger, checkRange, checkIsVideoOrAudioType */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkParameterType", function() { return checkParameterType; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkInteger", function() { return checkInteger; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkRange", function() { return checkRange; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "checkIsVideoOrAudioType", function() { return checkIsVideoOrAudioType; });
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function checkParameterType(parameter, type) {
if (_typeof(parameter) !== type) {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].BAD_ARGUMENT_ERROR;
}
}
function checkInteger(parameter) {
var isInt = parameter !== null && !isNaN(parameter) && parameter % 1 === 0;
if (!isInt) {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].BAD_ARGUMENT_ERROR + ' : argument is not an integer';
}
}
function checkRange(parameter, min, max) {
if (parameter < min || parameter > max) {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].BAD_ARGUMENT_ERROR + ' : argument out of range';
}
}
function checkIsVideoOrAudioType(type) {
if (typeof type !== 'string' || type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO) {
throw _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].BAD_ARGUMENT_ERROR;
}
}
/***/ }),
/***/ "./src/streaming/utils/TTMLParser.js":
/*!*******************************************!*\
!*** ./src/streaming/utils/TTMLParser.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var imsc__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! imsc */ "./node_modules/imsc/src/main/js/main.js");
/* harmony import */ var imsc__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(imsc__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../constants/ConformanceViolationConstants */ "./src/streaming/constants/ConformanceViolationConstants.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function TTMLParser() {
var context = this.context;
var eventBus = Object(_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
/*
* This TTML parser follows "EBU-TT-D SUBTITLING DISTRIBUTION FORMAT - tech3380" spec - https://tech.ebu.ch/docs/tech/tech3380.pdf.
* */
var instance, logger;
var cueCounter = 0; // Used to give every cue a unique ID.
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
}
function getCueID() {
var id = 'cue_TTML_' + cueCounter;
cueCounter++;
return id;
}
/**
* Parse the raw data and process it to return the HTML element representing the cue.
* Return the region to be processed and controlled (hide/show) by the caption controller.
* @param {string} data - raw data received from the TextSourceBuffer
* @param {number} offsetTime - offset time to apply to cue time
* @param {integer} startTimeSegment - startTime for the current segment
* @param {integer} endTimeSegment - endTime for the current segment
* @param {Array} images - images array referenced by subs MP4 box
*/
function parse(data, offsetTime, startTimeSegment, endTimeSegment, images) {
var errorMsg = '';
var captionArray = [];
var startTime, endTime, i;
var content = {};
var embeddedImages = {};
var currentImageId = '';
var accumulated_image_data = '';
var metadataHandler = {
onOpenTag: function onOpenTag(ns, name, attrs) {
// cope with existing non-compliant content
if (attrs[' imagetype'] && !attrs[' imageType']) {
eventBus.trigger(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].CONFORMANCE_VIOLATION, {
level: _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_6__["default"].LEVELS.ERROR,
event: _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_6__["default"].EVENTS.NON_COMPLIANT_SMPTE_IMAGE_ATTRIBUTE
});
attrs[' imageType'] = attrs[' imagetype'];
}
if (name === 'image' && (ns === 'http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt' || ns === 'http://www.smpte-ra.org/schemas/2052-1/2013/smpte-tt')) {
if (!attrs[' imageType'] || attrs[' imageType'].value !== 'PNG') {
logger.warn('smpte-tt imageType != PNG. Discarded');
return;
}
currentImageId = attrs['http://www.w3.org/XML/1998/namespace id'].value;
}
},
onCloseTag: function onCloseTag() {
if (currentImageId) {
embeddedImages[currentImageId] = accumulated_image_data.trim();
}
accumulated_image_data = '';
currentImageId = '';
},
onText: function onText(contents) {
if (currentImageId) {
accumulated_image_data = accumulated_image_data + contents;
}
}
};
if (!data) {
errorMsg = 'no ttml data to parse';
throw new Error(errorMsg);
}
content.data = data;
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].TTML_TO_PARSE, content);
var imsc1doc = Object(imsc__WEBPACK_IMPORTED_MODULE_4__["fromXML"])(content.data, function (msg) {
errorMsg = msg;
}, metadataHandler);
eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_3__["default"].TTML_PARSED, {
ttmlString: content.data,
ttmlDoc: imsc1doc
});
var mediaTimeEvents = imsc1doc.getMediaTimeEvents();
for (i = 0; i < mediaTimeEvents.length; i++) {
var isd = Object(imsc__WEBPACK_IMPORTED_MODULE_4__["generateISD"])(imsc1doc, mediaTimeEvents[i], function (error) {
errorMsg = error;
});
if (isd.contents.some(function (topLevelContents) {
return topLevelContents.contents.length;
})) {
//be sure that mediaTimeEvents values are in the mp4 segment time ranges.
startTime = mediaTimeEvents[i] + offsetTime < startTimeSegment ? startTimeSegment : mediaTimeEvents[i] + offsetTime;
endTime = mediaTimeEvents[i + 1] + offsetTime > endTimeSegment ? endTimeSegment : mediaTimeEvents[i + 1] + offsetTime;
if (startTime < endTime) {
captionArray.push({
start: startTime,
end: endTime,
type: 'html',
cueID: getCueID(),
isd: isd,
images: images,
embeddedImages: embeddedImages
});
}
}
}
if (errorMsg !== '') {
logger.error(errorMsg);
throw new Error(errorMsg);
}
return captionArray;
}
instance = {
parse: parse
};
setup();
return instance;
}
TTMLParser.__dashjs_factory_name = 'TTMLParser';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(TTMLParser));
/***/ }),
/***/ "./src/streaming/utils/URLUtils.js":
/*!*****************************************!*\
!*** ./src/streaming/utils/URLUtils.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _DefaultURLUtils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./DefaultURLUtils */ "./src/streaming/utils/DefaultURLUtils.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @module URLUtils
* @ignore
* @description Provides utility functions for operating on URLs.
* Initially this is simply a method to determine the Base URL of a URL, but
* should probably include other things provided all over the place such as
* determining whether a URL is relative/absolute, resolving two paths etc.
*/
function URLUtils() {
var instance;
var defaultURLUtils;
var regexUtils = [];
var context = this.context;
function getUtils(url) {
var i;
for (i = 0; i < regexUtils.length; i++) {
var regex = regexUtils[i].regex;
if (regex.test(url)) {
return regexUtils[i].utils;
}
}
return defaultURLUtils;
}
function setup() {
defaultURLUtils = Object(_DefaultURLUtils__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
}
/**
* Register a module to handle specific url.
* @param {regex} regex - url regex
* @param {object} utils - object that handles the regex
* @memberof module:URLUtils
* @instance
*/
function registerUrlRegex(regex, utils) {
regexUtils.push({
regex: regex,
utils: utils
});
}
function internalCall(functionName, url, baseUrl) {
var utils = getUtils(baseUrl || url);
return utils && typeof utils[functionName] === 'function' ? utils[functionName](url, baseUrl) : defaultURLUtils[functionName](url, baseUrl);
}
/**
* Returns a string that contains the Base URL of a URL, if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:URLUtils
* @instance
*/
function parseBaseUrl(url) {
return internalCall('parseBaseUrl', url);
}
/**
* Returns a string that contains the scheme and origin of a URL,
* if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:URLUtils
* @instance
*/
function parseOrigin(url) {
return internalCall('parseOrigin', url);
}
/**
* Returns a string that contains the fragment of a URL without scheme,
* if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:URLUtils
* @instance
*/
function removeHostname(url) {
return internalCall('removeHostname', url);
}
/**
* Returns a string that contains the scheme of a URL, if determinable.
* @param {string} url - full url
* @return {string}
* @memberof module:URLUtils
* @instance
*/
function parseScheme(url) {
return internalCall('parseScheme', url);
}
/**
* Determines whether the url is relative.
* @return {boolean}
* @param {string} url
* @memberof module:URLUtils
* @instance
*/
function isRelative(url) {
return internalCall('isRelative', url);
}
/**
* Determines whether the url is path-absolute.
* @return {bool}
* @param {string} url
* @memberof module:URLUtils
* @instance
*/
function isPathAbsolute(url) {
return internalCall('isPathAbsolute', url);
}
/**
* Determines whether the url is scheme-relative.
* @return {bool}
* @param {string} url
* @memberof module:URLUtils
* @instance
*/
function isSchemeRelative(url) {
return internalCall('isSchemeRelative', url);
}
/**
* Determines whether the url is an HTTP-URL as defined in ISO/IEC
* 23009-1:2014 3.1.15. ie URL with a fixed scheme of http or https
* @return {bool}
* @param {string} url
* @memberof module:URLUtils
* @instance
*/
function isHTTPURL(url) {
return internalCall('isHTTPURL', url);
}
/**
* Determines whether the supplied url has https scheme
* @return {bool}
* @param {string} url
* @memberof module:URLUtils
* @instance
*/
function isHTTPS(url) {
return internalCall('isHTTPS', url);
}
/**
* Resolves a url given an optional base url
* @return {string}
* @param {string} url
* @param {string} [baseUrl]
* @memberof module:URLUtils
* @instance
*/
function resolve(url, baseUrl) {
return internalCall('resolve', url, baseUrl);
}
setup();
instance = {
registerUrlRegex: registerUrlRegex,
parseBaseUrl: parseBaseUrl,
parseOrigin: parseOrigin,
parseScheme: parseScheme,
isRelative: isRelative,
isPathAbsolute: isPathAbsolute,
isSchemeRelative: isSchemeRelative,
isHTTPURL: isHTTPURL,
isHTTPS: isHTTPS,
removeHostname: removeHostname,
resolve: resolve
};
return instance;
}
URLUtils.__dashjs_factory_name = 'URLUtils';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(URLUtils);
/* harmony default export */ __webpack_exports__["default"] = (factory);
/***/ }),
/***/ "./src/streaming/utils/VTTParser.js":
/*!******************************************!*\
!*** ./src/streaming/utils/VTTParser.js ***!
\******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
var WEBVTT = 'WEBVTT';
function VTTParser() {
var context = this.context;
var instance, logger, regExNewLine, regExToken, regExWhiteSpace, regExWhiteSpaceWordBoundary;
function setup() {
logger = Object(_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);
regExNewLine = /(?:\r\n|\r|\n)/gm;
regExToken = /-->/;
regExWhiteSpace = /(^[\s]+|[\s]+$)/g;
regExWhiteSpaceWordBoundary = /\s\b/g;
}
function parse(data) {
var captionArray = [];
var len, lastStartTime;
if (!data) {
return captionArray;
}
data = data.split(regExNewLine);
len = data.length;
lastStartTime = -1;
for (var i = 0; i < len; i++) {
var item = data[i];
if (item.length > 0 && item !== WEBVTT) {
if (item.match(regExToken)) {
var attributes = parseItemAttributes(item);
var cuePoints = attributes.cuePoints;
var styles = attributes.styles;
var text = getSublines(data, i + 1);
var startTime = convertCuePointTimes(cuePoints[0].replace(regExWhiteSpace, ''));
var endTime = convertCuePointTimes(cuePoints[1].replace(regExWhiteSpace, ''));
if (!isNaN(startTime) && !isNaN(endTime) && startTime >= lastStartTime && endTime > startTime) {
if (text !== '') {
lastStartTime = startTime; //TODO Make VO external so other parsers can use.
captionArray.push({
start: startTime,
end: endTime,
data: text,
styles: styles
});
} else {
logger.error('Skipping cue due to empty/malformed cue text');
}
} else {
logger.error('Skipping cue due to incorrect cue timing');
}
}
}
}
return captionArray;
}
function convertCuePointTimes(time) {
var timeArray = time.split(':');
var len = timeArray.length - 1;
time = parseInt(timeArray[len - 1], 10) * 60 + parseFloat(timeArray[len]);
if (len === 2) {
time += parseInt(timeArray[0], 10) * 3600;
}
return time;
}
function parseItemAttributes(data) {
var vttCuePoints = data.split(regExToken);
var arr = vttCuePoints[1].split(regExWhiteSpaceWordBoundary);
arr.shift(); //remove first array index it is empty...
vttCuePoints[1] = arr[0];
arr.shift();
return {
cuePoints: vttCuePoints,
styles: getCaptionStyles(arr)
};
}
function getCaptionStyles(arr) {
var styleObject = {};
arr.forEach(function (element) {
if (element.split(/:/).length > 1) {
var val = element.split(/:/)[1];
if (val && val.search(/%/) != -1) {
val = parseInt(val.replace(/%/, ''), 10);
}
if (element.match(/align/) || element.match(/A/)) {
styleObject.align = val;
}
if (element.match(/line/) || element.match(/L/)) {
styleObject.line = val;
}
if (element.match(/position/) || element.match(/P/)) {
styleObject.position = val;
}
if (element.match(/size/) || element.match(/S/)) {
styleObject.size = val;
}
}
});
return styleObject;
}
/*
* VTT can have multiple lines to display per cuepoint.
*/
function getSublines(data, idx) {
var i = idx;
var subline = '';
var lineData = '';
var lineCount;
while (data[i] !== '' && i < data.length) {
i++;
}
lineCount = i - idx;
if (lineCount > 1) {
for (var j = 0; j < lineCount; j++) {
lineData = data[idx + j];
if (!lineData.match(regExToken)) {
subline += lineData;
if (j !== lineCount - 1) {
subline += '\n';
}
} else {
// caption text should not have '-->' in it
subline = '';
break;
}
}
} else {
lineData = data[idx];
if (!lineData.match(regExToken)) subline = lineData;
}
return subline;
}
instance = {
parse: parse
};
setup();
return instance;
}
VTTParser.__dashjs_factory_name = 'VTTParser';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(VTTParser));
/***/ }),
/***/ "./src/streaming/utils/baseUrlResolution/BasicSelector.js":
/*!****************************************************************!*\
!*** ./src/streaming/utils/baseUrlResolution/BasicSelector.js ***!
\****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function BasicSelector(config) {
config = config || {};
var instance;
var blacklistController = config.blacklistController;
function select(baseUrls) {
var index = 0;
var selectedBaseUrl;
if (baseUrls && baseUrls.some(function (baseUrl, idx) {
index = idx;
return !blacklistController.contains(baseUrl.serviceLocation);
})) {
selectedBaseUrl = baseUrls[index];
}
return selectedBaseUrl;
}
instance = {
select: select
};
return instance;
}
BasicSelector.__dashjs_factory_name = 'BasicSelector';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(BasicSelector));
/***/ }),
/***/ "./src/streaming/utils/baseUrlResolution/DVBSelector.js":
/*!**************************************************************!*\
!*** ./src/streaming/utils/baseUrlResolution/DVBSelector.js ***!
\**************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
function DVBSelector(config) {
config = config || {};
var instance;
var blacklistController = config.blacklistController;
function getNonBlacklistedBaseUrls(urls) {
var removedPriorities = [];
var samePrioritiesFilter = function samePrioritiesFilter(el) {
if (removedPriorities.length) {
if (el.dvb_priority && removedPriorities.indexOf(el.dvb_priority) !== -1) {
return false;
}
}
return true;
};
var serviceLocationFilter = function serviceLocationFilter(baseUrl) {
if (blacklistController.contains(baseUrl.serviceLocation)) {
// whenever a BaseURL is removed from the available list of
// BaseURLs, any other BaseURL with the same @priority
// value as the BaseURL being removed shall also be removed
if (baseUrl.dvb_priority) {
removedPriorities.push(baseUrl.dvb_priority);
} // all URLs in the list which have a @serviceLocation
// attribute matching an entry in the blacklist shall be
// removed from the available list of BaseURLs
return false;
}
return true;
};
return urls.filter(serviceLocationFilter).filter(samePrioritiesFilter);
}
function selectByWeight(availableUrls) {
var prioritySorter = function prioritySorter(a, b) {
var diff = a.dvb_priority - b.dvb_priority;
return isNaN(diff) ? 0 : diff;
};
var topPriorityFilter = function topPriorityFilter(baseUrl, idx, arr) {
return !idx || arr[0].dvb_priority && baseUrl.dvb_priority && arr[0].dvb_priority === baseUrl.dvb_priority;
};
var totalWeight = 0;
var cumulWeights = [];
var idx = 0;
var rn, urls; // It shall begin by taking the set of resolved BaseURLs present or inherited at the current
// position in the MPD, resolved and filtered as described in 10.8.2.1, that have the lowest
// @priority attribute value.
urls = availableUrls.sort(prioritySorter).filter(topPriorityFilter);
if (urls.length) {
if (urls.length > 1) {
// If there is more than one BaseURL with this lowest @priority attribute value then the Player
// shall select one of them at random such that the probability of each BaseURL being chosen
// is proportional to the value of its @weight attribute. The method described in RFC 2782
// [26] or picking from a number of weighted entries is suitable for this, but there may be other
// algorithms which achieve the same effect.
// add all the weights together, storing the accumulated weight per entry
urls.forEach(function (baseUrl) {
totalWeight += baseUrl.dvb_weight;
cumulWeights.push(totalWeight);
}); // pick a random number between zero and totalWeight
rn = Math.floor(Math.random() * (totalWeight - 1)); // select the index for the range rn falls within
cumulWeights.every(function (limit, index) {
idx = index;
if (rn < limit) {
return false;
}
return true;
});
}
return urls[idx];
}
}
function select(baseUrls) {
return baseUrls && selectByWeight(getNonBlacklistedBaseUrls(baseUrls));
}
instance = {
select: select
};
return instance;
}
DVBSelector.__dashjs_factory_name = 'DVBSelector';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(DVBSelector));
/***/ }),
/***/ "./src/streaming/vo/BitrateInfo.js":
/*!*****************************************!*\
!*** ./src/streaming/vo/BitrateInfo.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var BitrateInfo = function BitrateInfo() {
_classCallCheck(this, BitrateInfo);
this.mediaType = null;
this.bitrate = null;
this.width = null;
this.height = null;
this.scanType = null;
this.qualityIndex = NaN;
};
/* harmony default export */ __webpack_exports__["default"] = (BitrateInfo);
/***/ }),
/***/ "./src/streaming/vo/DashJSError.js":
/*!*****************************************!*\
!*** ./src/streaming/vo/DashJSError.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var DashJSError = function DashJSError(code, message, data) {
_classCallCheck(this, DashJSError);
this.code = code || null;
this.message = message || null;
this.data = data || null;
};
/* harmony default export */ __webpack_exports__["default"] = (DashJSError);
/***/ }),
/***/ "./src/streaming/vo/DataChunk.js":
/*!***************************************!*\
!*** ./src/streaming/vo/DataChunk.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var DataChunk = //Represents a data structure that keep all the necessary info about a single init/media segment
function DataChunk() {
_classCallCheck(this, DataChunk);
this.streamId = null;
this.mediaInfo = null;
this.segmentType = null;
this.quality = NaN;
this.index = NaN;
this.bytes = null;
this.start = NaN;
this.end = NaN;
this.duration = NaN;
this.representationId = null;
this.endFragment = null;
};
/* harmony default export */ __webpack_exports__["default"] = (DataChunk);
/***/ }),
/***/ "./src/streaming/vo/FragmentRequest.js":
/*!*********************************************!*\
!*** ./src/streaming/vo/FragmentRequest.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var FragmentRequest = /*#__PURE__*/function () {
function FragmentRequest(url) {
_classCallCheck(this, FragmentRequest);
this.action = FragmentRequest.ACTION_DOWNLOAD;
this.startTime = NaN;
this.mediaStartTime = NaN;
this.mediaType = null;
this.mediaInfo = null;
this.type = null;
this.duration = NaN;
this.timescale = NaN;
this.range = null;
this.url = url || null;
this.serviceLocation = null;
this.requestStartDate = null;
this.firstByteDate = null;
this.requestEndDate = null;
this.quality = NaN;
this.index = NaN;
this.availabilityStartTime = null;
this.availabilityEndTime = null;
this.wallStartTime = null;
this.bytesLoaded = NaN;
this.bytesTotal = NaN;
this.delayLoadingTime = NaN;
this.responseType = 'arraybuffer';
this.representationId = null;
}
_createClass(FragmentRequest, [{
key: "isInitializationRequest",
value: function isInitializationRequest() {
return this.type && this.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_0__["HTTPRequest"].INIT_SEGMENT_TYPE;
}
}, {
key: "setInfo",
value: function setInfo(info) {
this.type = info && info.init ? _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_0__["HTTPRequest"].INIT_SEGMENT_TYPE : _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_0__["HTTPRequest"].MEDIA_SEGMENT_TYPE;
this.url = info && info.url ? info.url : null;
this.range = info && info.range ? info.range.start + '-' + info.range.end : null;
this.mediaType = info && info.mediaType ? info.mediaType : null;
}
}]);
return FragmentRequest;
}();
FragmentRequest.ACTION_DOWNLOAD = 'download';
FragmentRequest.ACTION_COMPLETE = 'complete';
/* harmony default export */ __webpack_exports__["default"] = (FragmentRequest);
/***/ }),
/***/ "./src/streaming/vo/HeadRequest.js":
/*!*****************************************!*\
!*** ./src/streaming/vo/HeadRequest.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _FragmentRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./FragmentRequest */ "./src/streaming/vo/FragmentRequest.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var HeadRequest = /*#__PURE__*/function (_FragmentRequest) {
_inherits(HeadRequest, _FragmentRequest);
var _super = _createSuper(HeadRequest);
function HeadRequest(url) {
var _this;
_classCallCheck(this, HeadRequest);
_this = _super.call(this, url);
_this.checkForExistenceOnly = true;
return _this;
}
return HeadRequest;
}(_FragmentRequest__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (HeadRequest);
/***/ }),
/***/ "./src/streaming/vo/IsoBox.js":
/*!************************************!*\
!*** ./src/streaming/vo/IsoBox.js ***!
\************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var IsoBox = /*#__PURE__*/function () {
function IsoBox(boxData) {
_classCallCheck(this, IsoBox);
this.offset = boxData._offset;
this.type = boxData.type;
this.size = boxData.size;
this.boxes = [];
if (boxData.boxes) {
for (var i = 0; i < boxData.boxes.length; i++) {
this.boxes.push(new IsoBox(boxData.boxes[i]));
}
}
this.isComplete = true;
switch (boxData.type) {
case 'sidx':
this.timescale = boxData.timescale;
this.earliest_presentation_time = boxData.earliest_presentation_time;
this.first_offset = boxData.first_offset;
this.references = boxData.references;
if (boxData.references) {
this.references = [];
for (var _i = 0; _i < boxData.references.length; _i++) {
var reference = {
reference_type: boxData.references[_i].reference_type,
referenced_size: boxData.references[_i].referenced_size,
subsegment_duration: boxData.references[_i].subsegment_duration
};
this.references.push(reference);
}
}
break;
case 'emsg':
this.id = boxData.id;
this.version = boxData.version === 1 ? 1 : 0;
this.value = boxData.value;
this.timescale = boxData.timescale;
this.scheme_id_uri = boxData.scheme_id_uri;
this.presentation_time_delta = boxData.version === 1 ? boxData.presentation_time : boxData.presentation_time_delta;
this.event_duration = boxData.event_duration;
this.message_data = boxData.message_data;
break;
case 'mdhd':
this.timescale = boxData.timescale;
break;
case 'mfhd':
this.sequence_number = boxData.sequence_number;
break;
case 'subs':
this.entry_count = boxData.entry_count;
this.entries = boxData.entries;
break;
case 'tfhd':
this.base_data_offset = boxData.base_data_offset;
this.sample_description_index = boxData.sample_description_index;
this.default_sample_duration = boxData.default_sample_duration;
this.default_sample_size = boxData.default_sample_size;
this.default_sample_flags = boxData.default_sample_flags;
this.flags = boxData.flags;
break;
case 'tfdt':
this.version = boxData.version;
this.baseMediaDecodeTime = boxData.baseMediaDecodeTime;
this.flags = boxData.flags;
break;
case 'trun':
this.sample_count = boxData.sample_count;
this.first_sample_flags = boxData.first_sample_flags;
this.data_offset = boxData.data_offset;
this.flags = boxData.flags;
this.samples = boxData.samples;
if (boxData.samples) {
this.samples = [];
for (var _i2 = 0, ln = boxData.samples.length; _i2 < ln; _i2++) {
var sample = {
sample_size: boxData.samples[_i2].sample_size,
sample_duration: boxData.samples[_i2].sample_duration,
sample_composition_time_offset: boxData.samples[_i2].sample_composition_time_offset
};
this.samples.push(sample);
}
}
break;
}
}
_createClass(IsoBox, [{
key: "getChildBox",
value: function getChildBox(type) {
for (var i = 0; i < this.boxes.length; i++) {
if (this.boxes[i].type === type) {
return this.boxes[i];
}
}
}
}, {
key: "getChildBoxes",
value: function getChildBoxes(type) {
var boxes = [];
for (var i = 0; i < this.boxes.length; i++) {
if (this.boxes[i].type === type) {
boxes.push(this.boxes[i]);
}
}
return boxes;
}
}]);
return IsoBox;
}();
/* harmony default export */ __webpack_exports__["default"] = (IsoBox);
/***/ }),
/***/ "./src/streaming/vo/IsoBoxSearchInfo.js":
/*!**********************************************!*\
!*** ./src/streaming/vo/IsoBoxSearchInfo.js ***!
\**********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var IsoBoxSearchInfo = function IsoBoxSearchInfo(lastCompletedOffset, found, size) {
_classCallCheck(this, IsoBoxSearchInfo);
this.lastCompletedOffset = lastCompletedOffset;
this.found = found;
this.size = size;
};
/* harmony default export */ __webpack_exports__["default"] = (IsoBoxSearchInfo);
/***/ }),
/***/ "./src/streaming/vo/MetricsList.js":
/*!*****************************************!*\
!*** ./src/streaming/vo/MetricsList.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var MetricsList = function MetricsList() {
_classCallCheck(this, MetricsList);
this.TcpList = [];
this.HttpList = [];
this.RepSwitchList = [];
this.BufferLevel = [];
this.BufferState = [];
this.PlayList = [];
this.DroppedFrames = [];
this.SchedulingInfo = [];
this.DVRInfo = [];
this.ManifestUpdate = [];
this.RequestsQueue = null;
this.DVBErrors = [];
};
/* harmony default export */ __webpack_exports__["default"] = (MetricsList);
/***/ }),
/***/ "./src/streaming/vo/TextRequest.js":
/*!*****************************************!*\
!*** ./src/streaming/vo/TextRequest.js ***!
\*****************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _FragmentRequest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./FragmentRequest */ "./src/streaming/vo/FragmentRequest.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var TextRequest = /*#__PURE__*/function (_FragmentRequest) {
_inherits(TextRequest, _FragmentRequest);
var _super = _createSuper(TextRequest);
function TextRequest(url, type) {
var _this;
_classCallCheck(this, TextRequest);
_this = _super.call(this);
_this.url = url || null;
_this.type = type || null;
_this.mediaType = _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].STREAM;
_this.responseType = ''; //'text' value returns a bad encoding response in Firefox
return _this;
}
return TextRequest;
}(_FragmentRequest__WEBPACK_IMPORTED_MODULE_1__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (TextRequest);
/***/ }),
/***/ "./src/streaming/vo/TextTrackInfo.js":
/*!*******************************************!*\
!*** ./src/streaming/vo/TextTrackInfo.js ***!
\*******************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _dash_vo_MediaInfo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./../../dash/vo/MediaInfo */ "./src/dash/vo/MediaInfo.js");
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var TextTrackInfo = /*#__PURE__*/function (_MediaInfo) {
_inherits(TextTrackInfo, _MediaInfo);
var _super = _createSuper(TextTrackInfo);
function TextTrackInfo() {
var _this;
_classCallCheck(this, TextTrackInfo);
_this = _super.call(this);
_this.captionData = null;
_this.label = null;
_this.defaultTrack = false;
_this.kind = null;
_this.isFragmented = false;
_this.isEmbedded = false;
_this.isTTML = null;
return _this;
}
return TextTrackInfo;
}(_dash_vo_MediaInfo__WEBPACK_IMPORTED_MODULE_0__["default"]);
/* harmony default export */ __webpack_exports__["default"] = (TextTrackInfo);
/***/ }),
/***/ "./src/streaming/vo/Thumbnail.js":
/*!***************************************!*\
!*** ./src/streaming/vo/Thumbnail.js ***!
\***************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var Thumbnail = function Thumbnail() {
_classCallCheck(this, Thumbnail);
this.url = null;
this.width = null;
this.height = null;
this.x = null;
this.y = null;
};
/* harmony default export */ __webpack_exports__["default"] = (Thumbnail);
/***/ }),
/***/ "./src/streaming/vo/ThumbnailTrackInfo.js":
/*!************************************************!*\
!*** ./src/streaming/vo/ThumbnailTrackInfo.js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var ThumbnailTrackInfo = function ThumbnailTrackInfo() {
_classCallCheck(this, ThumbnailTrackInfo);
this.bitrate = 0;
this.width = 0;
this.height = 0;
this.tilesHor = 0;
this.tilesVert = 0;
this.widthPerTile = 0;
this.heightPerTile = 0;
this.startNumber = 0;
this.segmentDuration = 0;
this.timescale = 0;
this.templateUrl = '';
this.id = '';
};
/* harmony default export */ __webpack_exports__["default"] = (ThumbnailTrackInfo);
/***/ }),
/***/ "./src/streaming/vo/URIFragmentData.js":
/*!*********************************************!*\
!*** ./src/streaming/vo/URIFragmentData.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var URIFragmentData = function URIFragmentData() {
_classCallCheck(this, URIFragmentData);
this.t = null;
this.xywh = null;
this.track = null;
this.id = null;
this.s = null;
this.r = null;
};
/* harmony default export */ __webpack_exports__["default"] = (URIFragmentData);
/*
From Spec http://www.w3.org/TR/media-frags/
temporal (t) - This dimension denotes a specific time range in the original media, such as "starting at second 10, continuing until second 20";
spatial (xywh) - this dimension denotes a specific range of pixels in the original media, such as "a rectangle with size (100,100) with its top-left at coordinate (10,10)";
Media fragments support also addressing the media along two additional dimensions (in the advanced version defined in Media Fragments 1.0 URI (advanced)):
track (track) - this dimension denotes one or more tracks in the original media, such as "the english audio and the video track";
id (id) - this dimension denotes a named temporal fragment within the original media, such as "chapter 2", and can be seen as a convenient way of specifying a temporal fragment.
## Note
Akamai is purposing to add #s=X to the ISO standard.
- (X) Value would be a start time to seek to at startup instead of starting at 0 or live edge
- Allows for seeking back before the start time unlike a temporal clipping.
*/
/***/ }),
/***/ "./src/streaming/vo/metrics/BufferLevel.js":
/*!*************************************************!*\
!*** ./src/streaming/vo/metrics/BufferLevel.js ***!
\*************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var BufferLevel =
/**
* @description This Object holds reference to the current buffer level and the time it was recorded.
*/
function BufferLevel() {
_classCallCheck(this, BufferLevel);
/**
* Real-Time | Time of the measurement of the buffer level.
* @public
*/
this.t = null;
/**
* Level of the buffer in milliseconds. Indicates the playout duration for which
* media data of all active media components is available starting from the
* current playout time.
* @public
*/
this.level = null;
};
/* harmony default export */ __webpack_exports__["default"] = (BufferLevel);
/***/ }),
/***/ "./src/streaming/vo/metrics/BufferState.js":
/*!*************************************************!*\
!*** ./src/streaming/vo/metrics/BufferState.js ***!
\*************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var BufferState =
/**
* @description This Object holds reference to the current buffer state of the video element.
*/
function BufferState() {
_classCallCheck(this, BufferState);
/**
* The Buffer Level Target determined by the BufferLevelRule.
* @public
*/
this.target = null;
/**
* Current buffer state. Will be MetricsConstants.BUFFER_EMPTY or MetricsConstants.BUFFER_LOADED.
* @public
*/
this.state = _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_0__["default"].BUFFER_EMPTY;
};
/* harmony default export */ __webpack_exports__["default"] = (BufferState);
/***/ }),
/***/ "./src/streaming/vo/metrics/DVRInfo.js":
/*!*********************************************!*\
!*** ./src/streaming/vo/metrics/DVRInfo.js ***!
\*********************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var DVRInfo =
/**
* @description This Object holds reference to DVR availability window information.
*/
function DVRInfo() {
_classCallCheck(this, DVRInfo);
/**
* The current time of the video element when this was created.
* @public
*/
this.time = null;
/**
* The current Segment Availability Range as an object with start and end properties.
* It's delta defined by the timeShiftBufferDepth MPD attribute.
* @public
*/
this.range = null;
/**
* Reference to the internal ManifestInfo.js VO.
* @public
*/
this.manifestInfo = null;
};
/* harmony default export */ __webpack_exports__["default"] = (DVRInfo);
/***/ }),
/***/ "./src/streaming/vo/metrics/DroppedFrames.js":
/*!***************************************************!*\
!*** ./src/streaming/vo/metrics/DroppedFrames.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var DroppedFrames =
/**
* @description This Object holds reference to DroppedFrames count and the time it was recorded.
*/
function DroppedFrames() {
_classCallCheck(this, DroppedFrames);
/**
* Real-Time | Time of the measurement of the dropped frames.
* @public
*/
this.time = null;
/**
* Number of dropped frames
* @public
*/
this.droppedFrames = null;
};
/* harmony default export */ __webpack_exports__["default"] = (DroppedFrames);
/***/ }),
/***/ "./src/streaming/vo/metrics/HTTPRequest.js":
/*!*************************************************!*\
!*** ./src/streaming/vo/metrics/HTTPRequest.js ***!
\*************************************************/
/*! exports provided: HTTPRequest, HTTPRequestTrace */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HTTPRequest", function() { return HTTPRequest; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HTTPRequestTrace", function() { return HTTPRequestTrace; });
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc This Object holds reference to the HTTPRequest for manifest, fragment and xlink loading.
* Members which are not defined in ISO23009-1 Annex D should be prefixed by a _ so that they are ignored
* by Metrics Reporting code.
* @ignore
*/
var HTTPRequest =
/**
* @class
*/
function HTTPRequest() {
_classCallCheck(this, HTTPRequest);
/**
* Identifier of the TCP connection on which the HTTP request was sent.
* @public
*/
this.tcpid = null;
/**
* This is an optional parameter and should not be included in HTTP request/response transactions for progressive download.
* The type of the request:
* - MPD
* - XLink expansion
* - Initialization Fragment
* - Index Fragment
* - Media Fragment
* - Bitstream Switching Fragment
* - other
* @public
*/
this.type = null;
/**
* The original URL (before any redirects or failures)
* @public
*/
this.url = null;
/**
* The actual URL requested, if different from above
* @public
*/
this.actualurl = null;
/**
* The contents of the byte-range-spec part of the HTTP Range header.
* @public
*/
this.range = null;
/**
* Real-Time | The real time at which the request was sent.
* @public
*/
this.trequest = null;
/**
* Real-Time | The real time at which the first byte of the response was received.
* @public
*/
this.tresponse = null;
/**
* The HTTP response code.
* @public
*/
this.responsecode = null;
/**
* The duration of the throughput trace intervals (ms), for successful requests only.
* @public
*/
this.interval = null;
/**
* Throughput traces, for successful requests only.
* @public
*/
this.trace = [];
/**
* Type of stream ("audio" | "video" etc..)
* @public
*/
this._stream = null;
/**
* Real-Time | The real time at which the request finished.
* @public
*/
this._tfinish = null;
/**
* The duration of the media requests, if available, in seconds.
* @public
*/
this._mediaduration = null;
/**
* The media segment quality
* @public
*/
this._quality = null;
/**
* all the response headers from request.
* @public
*/
this._responseHeaders = null;
/**
* The selected service location for the request. string.
* @public
*/
this._serviceLocation = null;
};
/**
* @classdesc This Object holds reference to the progress of the HTTPRequest.
* @ignore
*/
var HTTPRequestTrace =
/**
* @class
*/
function HTTPRequestTrace() {
_classCallCheck(this, HTTPRequestTrace);
/**
* Real-Time | Measurement stream start.
* @public
*/
this.s = null;
/**
* Measurement stream duration (ms).
* @public
*/
this.d = null;
/**
* List of integers counting the bytes received in each trace interval within the measurement stream.
* @public
*/
this.b = [];
/**
* Measurement throughput in kbits/s
* @public
*/
this.t = null;
};
HTTPRequest.GET = 'GET';
HTTPRequest.HEAD = 'HEAD';
HTTPRequest.MPD_TYPE = 'MPD';
HTTPRequest.XLINK_EXPANSION_TYPE = 'XLinkExpansion';
HTTPRequest.INIT_SEGMENT_TYPE = 'InitializationSegment';
HTTPRequest.INDEX_SEGMENT_TYPE = 'IndexSegment';
HTTPRequest.MEDIA_SEGMENT_TYPE = 'MediaSegment';
HTTPRequest.BITSTREAM_SWITCHING_SEGMENT_TYPE = 'BitstreamSwitchingSegment';
HTTPRequest.MSS_FRAGMENT_INFO_SEGMENT_TYPE = 'FragmentInfoSegment';
HTTPRequest.LICENSE = 'license';
HTTPRequest.OTHER_TYPE = 'other';
/***/ }),
/***/ "./src/streaming/vo/metrics/ManifestUpdate.js":
/*!****************************************************!*\
!*** ./src/streaming/vo/metrics/ManifestUpdate.js ***!
\****************************************************/
/*! exports provided: ManifestUpdate, ManifestUpdateStreamInfo, ManifestUpdateRepresentationInfo */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ManifestUpdate", function() { return ManifestUpdate; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ManifestUpdateStreamInfo", function() { return ManifestUpdateStreamInfo; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ManifestUpdateRepresentationInfo", function() { return ManifestUpdateRepresentationInfo; });
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc This Object holds reference to the manifest update information.
* @ignore
*/
var ManifestUpdate =
/**
* @class
*/
function ManifestUpdate() {
_classCallCheck(this, ManifestUpdate);
/**
* Media Type Video | Audio | FragmentedText
* @public
*/
this.mediaType = null;
/**
* MPD Type static | dynamic
* @public
*/
this.type = null;
/**
* When this manifest update was requested
* @public
*/
this.requestTime = null;
/**
* When this manifest update was received
* @public
*/
this.fetchTime = null;
/**
* Calculated Availability Start time of the stream.
* @public
*/
this.availabilityStartTime = null;
/**
* the seek point (liveEdge for dynamic, Stream[0].startTime for static)
* @public
*/
this.presentationStartTime = 0;
/**
* The calculated difference between the server and client wall clock time
* @public
*/
this.clientTimeOffset = 0;
/**
* Actual element.currentTime
* @public
*/
this.currentTime = null;
/**
* Actual element.ranges
* @public
*/
this.buffered = null;
/**
* Static is fixed value of zero. dynamic should be ((Now-@availabilityStartTime) - elementCurrentTime)
* @public
*/
this.latency = 0;
/**
* Array holding list of StreamInfo VO Objects
* @public
*/
this.streamInfo = [];
/**
* Array holding list of RepresentationInfo VO Objects
* @public
*/
this.representationInfo = [];
};
/**
* @classdesc This Object holds reference to the current period's stream information when the manifest was updated.
* @ignore
*/
var ManifestUpdateStreamInfo =
/**
* @class
*/
function ManifestUpdateStreamInfo() {
_classCallCheck(this, ManifestUpdateStreamInfo);
/**
* Stream@id
* @public
*/
this.id = null;
/**
* Period Index
* @public
*/
this.index = null;
/**
* Stream@start
* @public
*/
this.start = null;
/**
* Stream@duration
* @public
*/
this.duration = null;
};
/**
* @classdesc This Object holds reference to the current representation's info when the manifest was updated.
* @ignore
*/
var ManifestUpdateRepresentationInfo =
/**
* @class
*/
function ManifestUpdateRepresentationInfo() {
_classCallCheck(this, ManifestUpdateRepresentationInfo);
/**
* Track@id
* @public
*/
this.id = null;
/**
* Representation Index
* @public
*/
this.index = null;
/**
* Media Type Video | Audio | FragmentedText
* @public
*/
this.mediaType = null;
/**
* Which representation
* @public
*/
this.streamIndex = null;
/**
* Holds reference to @presentationTimeOffset
* @public
*/
this.presentationTimeOffset = null;
/**
* Holds reference to @startNumber
* @public
*/
this.startNumber = null;
/**
* list|template|timeline
* @public
*/
this.fragmentInfoType = null;
};
/***/ }),
/***/ "./src/streaming/vo/metrics/PlayList.js":
/*!**********************************************!*\
!*** ./src/streaming/vo/metrics/PlayList.js ***!
\**********************************************/
/*! exports provided: PlayList, PlayListTrace */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PlayList", function() { return PlayList; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PlayListTrace", function() { return PlayListTrace; });
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @classdesc a PlayList from ISO23009-1 Annex D, this Object holds reference to the playback session information
* @ignore
*/
var PlayList =
/**
* @class
*/
function PlayList() {
_classCallCheck(this, PlayList);
/**
* Timestamp of the user action that starts the playback stream...
* @public
*/
this.start = null;
/**
* Presentation time at which playout was requested by the user...
* @public
*/
this.mstart = null;
/**
* Type of user action which triggered playout
* - New playout request (e.g. initial playout or seeking)
* - Resume from pause
* - Other user request (e.g. user-requested quality change)
* - Start of a metrics collection stream (hence earlier entries in the play list not collected)
* @public
*/
this.starttype = null;
/**
* List of streams of continuous rendering of decoded samples.
* @public
*/
this.trace = [];
};
/* Public Static Constants */
PlayList.INITIAL_PLAYOUT_START_REASON = 'initial_playout';
PlayList.SEEK_START_REASON = 'seek';
PlayList.RESUME_FROM_PAUSE_START_REASON = 'resume';
PlayList.METRICS_COLLECTION_START_REASON = 'metrics_collection_start';
/**
* @classdesc a PlayList.Trace from ISO23009-1 Annex D
* @ignore
*/
var PlayListTrace =
/**
* @class
*/
function PlayListTrace() {
_classCallCheck(this, PlayListTrace);
/**
* The value of the Representation@id of the Representation from which the samples were taken.
* @type {string}
* @public
*/
this.representationid = null;
/**
* If not present, this metrics concerns the Representation as a whole.
* If present, subreplevel indicates the greatest value of any
* Subrepresentation@level being rendered.
* @type {number}
* @public
*/
this.subreplevel = null;
/**
* The time at which the first sample was rendered
* @type {number}
* @public
*/
this.start = null;
/**
* The presentation time of the first sample rendered.
* @type {number}
* @public
*/
this.mstart = null;
/**
* The duration of the continuously presented samples (which is the same in real time and media time). "Continuously presented" means that the media clock continued to advance at the playout speed throughout the interval. NOTE: the spec does not call out the units, but all other durations etc are in ms, and we use ms too.
* @type {number}
* @public
*/
this.duration = null;
/**
* The playback speed relative to normal playback speed (i.e.normal forward playback speed is 1.0).
* @type {number}
* @public
*/
this.playbackspeed = null;
/**
* The reason why continuous presentation of this Representation was stopped.
* representation switch
* rebuffering
* user request
* end of Period
* end of Stream
* end of content
* end of a metrics collection period
*
* @type {string}
* @public
*/
this.stopreason = null;
};
PlayListTrace.REPRESENTATION_SWITCH_STOP_REASON = 'representation_switch';
PlayListTrace.REBUFFERING_REASON = 'rebuffering';
PlayListTrace.USER_REQUEST_STOP_REASON = 'user_request';
PlayListTrace.END_OF_PERIOD_STOP_REASON = 'end_of_period';
PlayListTrace.END_OF_CONTENT_STOP_REASON = 'end_of_content';
PlayListTrace.METRICS_COLLECTION_STOP_REASON = 'metrics_collection_end';
PlayListTrace.FAILURE_STOP_REASON = 'failure';
/***/ }),
/***/ "./src/streaming/vo/metrics/RepresentationSwitch.js":
/*!**********************************************************!*\
!*** ./src/streaming/vo/metrics/RepresentationSwitch.js ***!
\**********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var RepresentationSwitch =
/**
* @description This Object holds reference to the info at quality switch between two representations.
*/
function RepresentationSwitch() {
_classCallCheck(this, RepresentationSwitch);
/**
* Time of the switch event.
* @public
*/
this.t = null;
/**
* The media presentation time of the earliest access unit
* (out of all media content components) played out from
* the Representation.
*
* @public
*/
this.mt = null;
/**
* Value of Representation@id identifying the switch-to Representation.
* @public
*/
this.to = null;
/**
* If not present, this metrics concerns the Representation as a whole.
* If present, lto indicates the value of SubRepresentation@level within
* Representation identifying the switch-to level of the Representation.
*
* @public
*/
this.lto = null;
};
/* harmony default export */ __webpack_exports__["default"] = (RepresentationSwitch);
/***/ }),
/***/ "./src/streaming/vo/metrics/RequestsQueue.js":
/*!***************************************************!*\
!*** ./src/streaming/vo/metrics/RequestsQueue.js ***!
\***************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var RequestsQueue =
/**
* @description This Object holds reference to Fragment Model's request queues
*/
function RequestsQueue() {
_classCallCheck(this, RequestsQueue);
/**
* Array of all of the requests that have begun to load
* This request may not make it into the executed queue if it is abandon due to ABR rules for example.
* @public
*/
this.loadingRequests = [];
/**
* Array of the The requests that have completed
* @public
*/
this.executedRequests = [];
};
/* harmony default export */ __webpack_exports__["default"] = (RequestsQueue);
/***/ }),
/***/ "./src/streaming/vo/metrics/SchedulingInfo.js":
/*!****************************************************!*\
!*** ./src/streaming/vo/metrics/SchedulingInfo.js ***!
\****************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @class
* @ignore
*/
var SchedulingInfo =
/**
* @description This Object holds reference to the index handling of the current fragment being loaded or executed.
*/
function SchedulingInfo() {
_classCallCheck(this, SchedulingInfo);
/**
* Type of stream Audio | Video | FragmentedText
* @public
*/
this.mediaType = null;
/**
* Time of the scheduling event.
* @public
*/
this.t = null;
/**
* Type of fragment (initialization | media)
* @public
*/
this.type = null;
/**
* Presentation start time of fragment
* @public
*/
this.startTime = null;
/**
* Availability start time of fragment
* @public
*/
this.availabilityStartTime = null;
/**
* Duration of fragment
* @public
*/
this.duration = null;
/**
* Bit Rate Quality of fragment
* @public
*/
this.quality = null;
/**
* Range of fragment
* @public
*/
this.range = null;
/**
* Current state of fragment
* @public
*/
this.state = null;
};
/* harmony default export */ __webpack_exports__["default"] = (SchedulingInfo);
/***/ }),
/***/ 0:
/*!**********************!*\
!*** util (ignored) ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports) {
/* (ignored) */
/***/ }),
/***/ 1:
/*!**********************!*\
!*** util (ignored) ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports) {
/* (ignored) */
/***/ })
/******/ })["default"];
});
});
var dashjs$1 = unwrapExports(dash_all_debug);
/**
* Setup audio tracks. Take the tracks from dash and add the tracks to videojs. Listen for when
* videojs changes tracks and apply that to the dash player because videojs doesn't do this
* natively.
*
* @private
* @param {videojs} player the videojs player instance
* @param {videojs.tech} tech the videojs tech being used
*/
function handlePlaybackMetadataLoaded(player, tech) {
var mediaPlayer = player.dash.mediaPlayer;
var dashAudioTracks = mediaPlayer.getTracksFor('audio');
var videojsAudioTracks = player.audioTracks();
function generateIdFromTrackIndex(index) {
return "dash-audio-" + index;
}
function findDashAudioTrack(subDashAudioTracks, videojsAudioTrack) {
return subDashAudioTracks.find(function (_ref) {
var index = _ref.index;
return generateIdFromTrackIndex(index) === videojsAudioTrack.id;
});
} // Safari creates a single native `AudioTrack` (not `videojs.AudioTrack`) when loading. Clear all
// automatically generated audio tracks so we can create them all ourself.
if (videojsAudioTracks.length) {
tech.clearTracks(['audio']);
}
var currentAudioTrack = mediaPlayer.getCurrentTrackFor('audio');
dashAudioTracks.forEach(function (dashTrack) {
var localizedLabel;
if (Array.isArray(dashTrack.labels)) {
for (var i = 0; i < dashTrack.labels.length; i++) {
if (dashTrack.labels[i].lang && player.language().indexOf(dashTrack.labels[i].lang.toLowerCase()) !== -1) {
localizedLabel = dashTrack.labels[i];
break;
}
}
}
var label;
if (localizedLabel) {
label = localizedLabel.text;
} else if (Array.isArray(dashTrack.labels) && dashTrack.labels.length === 1) {
label = dashTrack.labels[0].text;
} else {
label = dashTrack.lang;
if (dashTrack.roles && dashTrack.roles.length) {
label += ' (' + dashTrack.roles.join(', ') + ')';
}
} // Add the track to the player's audio track list.
videojsAudioTracks.addTrack(new videojs.AudioTrack({
enabled: dashTrack === currentAudioTrack,
id: generateIdFromTrackIndex(dashTrack.index),
kind: dashTrack.kind || 'main',
label: label,
language: dashTrack.lang
}));
});
var audioTracksChangeHandler = function audioTracksChangeHandler() {
for (var i = 0; i < videojsAudioTracks.length; i++) {
var track = videojsAudioTracks[i];
if (track.enabled) {
// Find the audio track we just selected by the id
var dashAudioTrack = findDashAudioTrack(dashAudioTracks, track); // Set is as the current track
mediaPlayer.setCurrentTrack(dashAudioTrack); // Stop looping
continue;
}
}
};
videojsAudioTracks.addEventListener('change', audioTracksChangeHandler);
player.dash.mediaPlayer.on(dashjs$1.MediaPlayer.events.STREAM_TEARDOWN_COMPLETE, function () {
videojsAudioTracks.removeEventListener('change', audioTracksChangeHandler);
});
}
/*
* Call `handlePlaybackMetadataLoaded` when `mediaPlayer` emits
* `dashjs.MediaPlayer.events.PLAYBACK_METADATA_LOADED`.
*/
function setupAudioTracks(player, tech) {
// When `dashjs` finishes loading metadata, create audio tracks for `video.js`.
player.dash.mediaPlayer.on(dashjs$1.MediaPlayer.events.PLAYBACK_METADATA_LOADED, handlePlaybackMetadataLoaded.bind(null, player, tech));
}
function find(l, f) {
for (var i = 0; i < l.length; i++) {
if (f(l[i])) {
return l[i];
}
}
}
/*
* Attach text tracks from dash.js to videojs
*
* @param {videojs} player the videojs player instance
* @param {array} tracks the tracks loaded by dash.js to attach to videojs
*
* @private
*/
function attachDashTextTracksToVideojs(player, tech, tracks) {
var trackDictionary = []; // Add remote tracks
var tracksAttached = tracks // Map input data to match HTMLTrackElement spec
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement
.map(function (track) {
var localizedLabel;
if (Array.isArray(track.labels)) {
for (var i = 0; i < track.labels.length; i++) {
if (track.labels[i].lang && player.language().indexOf(track.labels[i].lang.toLowerCase()) !== -1) {
localizedLabel = track.labels[i];
break;
}
}
}
var label;
if (localizedLabel) {
label = localizedLabel.text;
} else if (Array.isArray(track.labels) && track.labels.length === 1) {
label = track.labels[0].text;
} else {
label = track.lang || track.label;
}
return {
dashTrack: track,
trackConfig: {
label: label,
language: track.lang,
srclang: track.lang,
kind: track.kind
}
};
}) // Add track to videojs track list
.map(function (_ref) {
var trackConfig = _ref.trackConfig,
dashTrack = _ref.dashTrack;
if (dashTrack.isTTML && !player.getChild('TTMLTextTrackDisplay')) {
return null;
}
var remoteTextTrack = player.addRemoteTextTrack(trackConfig, false);
trackDictionary.push({
textTrack: remoteTextTrack.track,
dashTrack: dashTrack
}); // Don't add the cues becuase we're going to let dash handle it natively. This will ensure
// that dash handle external time text files and fragmented text tracks.
//
// Example file with external time text files:
// https://storage.googleapis.com/shaka-demo-assets/sintel-mp4-wvtt/dash.mpd
return remoteTextTrack;
}).filter(function (el) {
return el !== null;
});
/*
* Scan `videojs.textTracks()` to find one that is showing. Set the dash text track.
*/
function updateActiveDashTextTrack() {
var dashMediaPlayer = player.dash.mediaPlayer;
var textTracks = player.textTracks();
var activeTextTrackIndex = -1; // Iterate through the tracks and find the one marked as showing. If none are showing,
// `activeTextTrackIndex` will be set to `-1`, disabling text tracks.
var _loop = function _loop(i) {
var textTrack = textTracks[i];
if (textTrack.mode === 'showing') {
// Find the dash track we want to use
/* jshint loopfunc: true */
var dictionaryLookupResult = find(trackDictionary, function (track) {
return track.textTrack === textTrack;
});
/* jshint loopfunc: false */
var dashTrackToActivate = dictionaryLookupResult ? dictionaryLookupResult.dashTrack : null; // If we found a track, get it's index.
if (dashTrackToActivate) {
activeTextTrackIndex = tracks.indexOf(dashTrackToActivate);
}
}
};
for (var i = 0; i < textTracks.length; i += 1) {
_loop(i);
} // If the text track has changed, then set it in dash
if (activeTextTrackIndex !== dashMediaPlayer.getCurrentTextTrackIndex()) {
dashMediaPlayer.setTextTrack(activeTextTrackIndex);
}
} // Update dash when videojs's selected text track changes.
player.textTracks().on('change', updateActiveDashTextTrack); // Cleanup event listeners whenever we start loading a new source
player.dash.mediaPlayer.on(dashjs$1.MediaPlayer.events.STREAM_TEARDOWN_COMPLETE, function () {
player.textTracks().off('change', updateActiveDashTextTrack);
}); // Initialize the text track on our first run-through
updateActiveDashTextTrack();
return tracksAttached;
}
/*
* Wait for dash to emit `TEXT_TRACKS_ADDED` and then attach the text tracks loaded by dash if
* we're not using native text tracks.
*
* @param {videojs} player the videojs player instance
* @private
*/
function setupTextTracks(player, tech, options) {
// Clear VTTCue if it was shimmed by vttjs and let dash.js use TextTrackCue.
// This is necessary because dash.js creates text tracks
// using addTextTrack which is incompatible with vttjs.VTTCue in IE11
if (window$1.VTTCue && !/\[native code\]/.test(window$1.VTTCue.toString())) {
window$1.VTTCue = false;
} // Store the tracks that we've added so we can remove them later.
var dashTracksAttachedToVideoJs = []; // We're relying on the user to disable native captions. Show an error if they didn't do so.
if (tech.featuresNativeTextTracks) {
videojs.log.error('You must pass {html: {nativeCaptions: false}} in the videojs constructor ' + 'to use text tracks in videojs-contrib-dash');
return;
}
var mediaPlayer = player.dash.mediaPlayer; // Clear the tracks that we added. We don't clear them all because someone else can add tracks.
function clearDashTracks() {
dashTracksAttachedToVideoJs.forEach(player.removeRemoteTextTrack.bind(player));
dashTracksAttachedToVideoJs = [];
}
function handleTextTracksAdded(_ref2) {
var index = _ref2.index,
tracks = _ref2.tracks;
// Stop listening for this event. We only want to hear it once.
mediaPlayer.off(dashjs$1.MediaPlayer.events.TEXT_TRACKS_ADDED, handleTextTracksAdded); // Cleanup old tracks
clearDashTracks();
if (!tracks.length) {
// Don't try to add text tracks if there aren't any
return;
} // Save the tracks so we can remove them later
dashTracksAttachedToVideoJs = attachDashTextTracksToVideojs(player, tech, tracks, options);
} // Attach dash text tracks whenever we dash emits `TEXT_TRACKS_ADDED`.
mediaPlayer.on(dashjs$1.MediaPlayer.events.TEXT_TRACKS_ADDED, handleTextTracksAdded); // When the player can play, remove the initialization events. We might not have received
// TEXT_TRACKS_ADDED` so we have to stop listening for it or we'll get errors when we load new
// videos and are listening for the same event in multiple places, including cleaned up
// mediaPlayers.
mediaPlayer.on(dashjs$1.MediaPlayer.events.CAN_PLAY, function () {
mediaPlayer.off(dashjs$1.MediaPlayer.events.TEXT_TRACKS_ADDED, handleTextTracksAdded);
});
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
var Component = videojs.getComponent('Component');
var darkGray = '#222';
var lightGray = '#ccc';
var fontMap = {
monospace: 'monospace',
sansSerif: 'sans-serif',
serif: 'serif',
monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
monospaceSerif: '"Courier New", monospace',
proportionalSansSerif: 'sans-serif',
proportionalSerif: 'serif',
casual: '"Comic Sans MS", Impact, fantasy',
script: '"Monotype Corsiva", cursive',
smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
};
/**
* Try to update the style of a DOM element. Some style changes will throw an error,
* particularly in IE8. Those should be noops.
*
* @param {Element} el
* The DOM element to be styled.
*
* @param {string} style
* The CSS property on the element that should be styled.
*
* @param {string} rule
* The style rule that should be applied to the property.
*
* @private
*/
function tryUpdateStyle(el, style, rule) {
try {
el.style[style] = rule;
} catch (e) {
// Satisfies linter.
return;
}
}
function removeStyle(el) {
if (el.style) {
el.style.left = null;
el.style.width = '100%';
}
for (var i in el.children) {
removeStyle(el.children[i]);
}
}
/**
* Construct an rgba color from a given hex color code.
*
* @param {number} color
* Hex number for color, like #f0e or #f604e2.
*
* @param {number} opacity
* Value for opacity, 0.0 - 1.0.
*
* @return {string}
* The rgba color that was created, like 'rgba(255, 0, 0, 0.3)'.
*/
function constructColor(color, opacity) {
var hex;
if (color.length === 4) {
// color looks like "#f0e"
hex = color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
} else if (color.length === 7) {
// color looks like "#f604e2"
hex = color.slice(1);
} else {
throw new Error('Invalid color code provided, ' + color + '; must be formatted as e.g. #f0e or #f604e2.');
}
return 'rgba(' + parseInt(hex.slice(0, 2), 16) + ',' + parseInt(hex.slice(2, 4), 16) + ',' + parseInt(hex.slice(4, 6), 16) + ',' + opacity + ')';
}
/**
* The component for displaying text track cues.
*
* @extends Component
*/
var TTMLTextTrackDisplay = /*#__PURE__*/function (_Component) {
_inheritsLoose(TTMLTextTrackDisplay, _Component);
/**
* Creates an instance of this class.
*
* @param {Player} player
* The `Player` that this class should be attached to.
*
* @param {Object} [options]
* The key/value store of player options.
*
* @param {Component~ReadyCallback} [ready]
* The function to call when `TextTrackDisplay` is ready.
*/
function TTMLTextTrackDisplay(player, options, ready) {
var _this;
_this = _Component.call(this, player, videojs.mergeOptions(options, {
playerOptions: {}
}), ready) || this;
var selects = player.getChild('TextTrackSettings').$$('select');
for (var i = 0; i < selects.length; i++) {
_this.on(selects[i], 'change', _this.updateStyle.bind(_assertThisInitialized(_this)));
}
player.dash.mediaPlayer.on(dashjs$1.MediaPlayer.events.CAPTION_RENDERED, _this.updateStyle.bind(_assertThisInitialized(_this)));
return _this;
}
/**
* Create the {@link Component}'s DOM element.
*
* @return {Element}
* The element that was created.
*/
var _proto = TTMLTextTrackDisplay.prototype;
_proto.createEl = function createEl() {
var newEl = _Component.prototype.createEl.call(this, 'div', {
className: 'vjs-text-track-display-ttml'
}, {
'aria-live': 'off',
'aria-atomic': 'true'
});
newEl.style.position = 'absolute';
newEl.style.left = '0';
newEl.style.right = '0';
newEl.style.top = '0';
newEl.style.bottom = '0';
newEl.style.margin = '1.5%';
return newEl;
};
_proto.updateStyle = function updateStyle(_ref) {
var captionDiv = _ref.captionDiv;
if (!this.player_.textTrackSettings) {
return;
}
var overrides = this.player_.textTrackSettings.getValues();
captionDiv = captionDiv || this.player_.getChild('TTMLTextTrackDisplay').el().firstChild;
if (!captionDiv) {
return;
}
removeStyle(captionDiv);
var spans = captionDiv.getElementsByTagName('span');
for (var i = 0; i < spans.length; i++) {
var span = spans[i];
span.parentNode.style.textAlign = 'center';
if (overrides.color) {
span.style.color = overrides.color;
}
if (overrides.textOpacity) {
tryUpdateStyle(span, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
}
if (overrides.backgroundColor) {
span.style.backgroundColor = overrides.backgroundColor;
}
if (overrides.backgroundOpacity) {
tryUpdateStyle(span, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
}
if (overrides.windowColor) {
if (overrides.windowOpacity) {
tryUpdateStyle(span.parentNode, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
} else {
span.parent.style.backgroundColor = overrides.windowColor;
}
}
if (overrides.edgeStyle) {
if (overrides.edgeStyle === 'dropshadow') {
span.style.textShadow = "2px 2px 3px " + darkGray + ", 2px 2px 4px " + darkGray + ", 2px 2px 5px " + darkGray;
} else if (overrides.edgeStyle === 'raised') {
span.style.textShadow = "1px 1px " + darkGray + ", 2px 2px " + darkGray + ", 3px 3px " + darkGray;
} else if (overrides.edgeStyle === 'depressed') {
span.style.textShadow = "1px 1px " + lightGray + ", 0 1px " + lightGray + ", -1px -1px " + darkGray + ", 0 -1px " + darkGray;
} else if (overrides.edgeStyle === 'uniform') {
span.style.textShadow = "0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray;
}
}
if (overrides.fontPercent && overrides.fontPercent !== 1) {
var fontSize = window$1.parseFloat(span.style.fontSize);
span.style.fontSize = fontSize * overrides.fontPercent + 'px';
span.style.height = 'auto';
span.style.top = 'auto';
span.style.bottom = '2px';
}
if (overrides.fontFamily && overrides.fontFamily !== 'default') {
if (overrides.fontFamily === 'small-caps') {
span.style.fontVariant = 'small-caps';
} else {
span.style.fontFamily = fontMap[overrides.fontFamily];
}
}
}
};
return TTMLTextTrackDisplay;
}(Component);
videojs.registerComponent('TTMLTextTrackDisplay', TTMLTextTrackDisplay);
/**
* videojs-contrib-dash
*
* Use Dash.js to playback DASH content inside of Video.js via a SourceHandler
*/
var Html5DashJS = /*#__PURE__*/function () {
function Html5DashJS(source, tech, options) {
var _this = this;
// Get options from tech if not provided for backwards compatibility
options = options || tech.options_;
this.player = videojs(options.playerId);
this.player.dash = this.player.dash || {};
this.tech_ = tech;
this.el_ = tech.el();
this.elParent_ = this.el_.parentNode;
this.hasFiniteDuration_ = false; // Do nothing if the src is falsey
if (!source.src) {
return;
} // While the manifest is loading and Dash.js has not finished initializing
// we must defer events and functions calls with isReady_ and then `triggerReady`
// again later once everything is setup
tech.isReady_ = false;
if (Html5DashJS.updateSourceData) {
videojs.log.warn('updateSourceData has been deprecated.' + ' Please switch to using hook("updatesource", callback).');
source = Html5DashJS.updateSourceData(source);
} // call updatesource hooks
Html5DashJS.hooks('updatesource').forEach(function (hook) {
source = hook(source);
});
var manifestSource = source.src;
this.keySystemOptions_ = Html5DashJS.buildDashJSProtData(source.keySystemOptions);
this.player.dash.mediaPlayer = dashjs$1.MediaPlayer().create();
this.mediaPlayer_ = this.player.dash.mediaPlayer; // Log MedaPlayer messages through video.js
if (Html5DashJS.useVideoJSDebug) {
videojs.log.warn('useVideoJSDebug has been deprecated.' + ' Please switch to using hook("beforeinitialize", callback).');
Html5DashJS.useVideoJSDebug(this.mediaPlayer_);
}
if (Html5DashJS.beforeInitialize) {
videojs.log.warn('beforeInitialize has been deprecated.' + ' Please switch to using hook("beforeinitialize", callback).');
Html5DashJS.beforeInitialize(this.player, this.mediaPlayer_);
}
Html5DashJS.hooks('beforeinitialize').forEach(function (hook) {
hook(_this.player, _this.mediaPlayer_);
}); // Must run controller before these two lines or else there is no
// element to bind to.
this.mediaPlayer_.initialize(); // Retrigger a dash.js-specific error event as a player error
// See src/streaming/utils/ErrorHandler.js in dash.js code
// Handled with error (playback is stopped):
// - capabilityError
// - downloadError
// - manifestError
// - mediaSourceError
// - mediaKeySessionError
// Not handled:
// - timedTextError (video can still play)
// - mediaKeyMessageError (only fires under 'might not work' circumstances)
this.retriggerError_ = function (event) {
if (event.error === 'capability' && event.event === 'mediasource') {
// No support for MSE
_this.player.error({
code: 4,
message: 'The media cannot be played because it requires a feature ' + 'that your browser does not support.'
});
} else if (event.error === 'manifestError' && ( // Manifest type not supported
event.event.id === 'createParser' || // Codec(s) not supported
event.event.id === 'codec' || // No streams available to stream
event.event.id === 'nostreams' || // Error creating Stream object
event.event.id === 'nostreamscomposed' || // syntax error parsing the manifest
event.event.id === 'parse' || // a stream has multiplexed audio+video
event.event.id === 'multiplexedrep')) {
// These errors have useful error messages, so we forward it on
_this.player.error({
code: 4,
message: event.event.message
});
} else if (event.error === 'mediasource') {
// This error happens when dash.js fails to allocate a SourceBuffer
// OR the underlying video element throws a `MediaError`.
// If it's a buffer allocation fail, the message states which buffer
// (audio/video/text) failed allocation.
// If it's a `MediaError`, dash.js inspects the error object for
// additional information to append to the error type.
if (event.event.match('MEDIA_ERR_ABORTED')) {
_this.player.error({
code: 1,
message: event.event
});
} else if (event.event.match('MEDIA_ERR_NETWORK')) {
_this.player.error({
code: 2,
message: event.event
});
} else if (event.event.match('MEDIA_ERR_DECODE')) {
_this.player.error({
code: 3,
message: event.event
});
} else if (event.event.match('MEDIA_ERR_SRC_NOT_SUPPORTED')) {
_this.player.error({
code: 4,
message: event.event
});
} else if (event.event.match('MEDIA_ERR_ENCRYPTED')) {
_this.player.error({
code: 5,
message: event.event
});
} else if (event.event.match('UNKNOWN')) {
// We shouldn't ever end up here, since this would mean a
// `MediaError` thrown by the video element that doesn't comply
// with the W3C spec. But, since we should handle the error,
// throwing a MEDIA_ERR_SRC_NOT_SUPPORTED is probably the
// most reasonable thing to do.
_this.player.error({
code: 4,
message: event.event
});
} else {
// Buffer allocation error
_this.player.error({
code: 4,
message: event.event
});
}
} else if (event.error === 'capability' && event.event === 'encryptedmedia') {
// Browser doesn't support EME
_this.player.error({
code: 5,
message: 'The media cannot be played because it requires encryption ' + 'features that your browser does not support.'
});
} else if (event.error === 'key_session') {
// This block handles pretty much all errors thrown by the
// encryption subsystem
_this.player.error({
code: 5,
message: event.event
});
} else if (event.error === 'download') {
_this.player.error({
code: 2,
message: 'The media playback was aborted because too many consecutive ' + 'download errors occurred.'
});
} else if (event.error === 'mssError') {
_this.player.error({
code: 3,
message: event.event
});
} else {
// ignore the error
return;
} // only reset the dash player in 10ms async, so that the rest of the
// calling function finishes
setTimeout(function () {
_this.mediaPlayer_.reset();
}, 10);
};
this.mediaPlayer_.on(dashjs$1.MediaPlayer.events.ERROR, this.retriggerError_);
this.getDuration_ = function (event) {
var periods = event.data.Period_asArray;
var oldHasFiniteDuration = _this.hasFiniteDuration_;
if (event.data.mediaPresentationDuration || periods[periods.length - 1].duration) {
_this.hasFiniteDuration_ = true;
} else {
// in case we run into a weird situation where we're VOD but then
// switch to live
_this.hasFiniteDuration_ = false;
}
if (_this.hasFiniteDuration_ !== oldHasFiniteDuration) {
_this.player.trigger('durationchange');
}
};
this.mediaPlayer_.on(dashjs$1.MediaPlayer.events.MANIFEST_LOADED, this.getDuration_); // Apply all dash options that are set
if (options.dash) {
Object.keys(options.dash).forEach(function (key) {
var _this$mediaPlayer_;
if (key === 'useTTML') {
return;
}
var dashOptionsKey = 'set' + key.charAt(0).toUpperCase() + key.slice(1);
var value = options.dash[key];
if (_this.mediaPlayer_.hasOwnProperty(dashOptionsKey)) {
// Providing a key without `set` prefix is now deprecated.
videojs.log.warn('Using dash options in videojs-contrib-dash without the set prefix ' + ("has been deprecated. Change '" + key + "' to '" + dashOptionsKey + "'")); // Set key so it will still work
key = dashOptionsKey;
}
if (!_this.mediaPlayer_.hasOwnProperty(key)) {
videojs.log.warn("Warning: dash configuration option unrecognized: " + key);
return;
} // Guarantee `value` is an array
if (!Array.isArray(value)) {
value = [value];
}
(_this$mediaPlayer_ = _this.mediaPlayer_)[key].apply(_this$mediaPlayer_, value);
});
}
this.mediaPlayer_.attachView(this.el_);
if (options.dash && options.dash.useTTML) {
this.ttmlContainer_ = this.player.addChild('TTMLTextTrackDisplay');
this.mediaPlayer_.attachTTMLRenderingDiv(this.ttmlContainer_.el());
} // Dash.js autoplays by default, video.js will handle autoplay
this.mediaPlayer_.setAutoPlay(false); // Setup audio tracks
setupAudioTracks.call(null, this.player, tech); // Setup text tracks
setupTextTracks.call(null, this.player, tech, options); // Attach the source with any protection data
this.mediaPlayer_.setProtectionData(this.keySystemOptions_);
this.mediaPlayer_.attachSource(manifestSource);
this.tech_.triggerReady();
}
/*
* Iterate over the `keySystemOptions` array and convert each object into
* the type of object Dash.js expects in the `protData` argument.
*
* Also rename 'licenseUrl' property in the options to an 'serverURL' property
*/
Html5DashJS.buildDashJSProtData = function buildDashJSProtData(keySystemOptions) {
var output = {};
if (!keySystemOptions || !Array.isArray(keySystemOptions)) {
return null;
}
for (var i = 0; i < keySystemOptions.length; i++) {
var keySystem = keySystemOptions[i];
var options = videojs.mergeOptions({}, keySystem.options);
if (options.licenseUrl) {
options.serverURL = options.licenseUrl;
delete options.licenseUrl;
}
output[keySystem.name] = options;
}
return output;
};
var _proto = Html5DashJS.prototype;
_proto.dispose = function dispose() {
if (this.mediaPlayer_) {
this.mediaPlayer_.off(dashjs$1.MediaPlayer.events.ERROR, this.retriggerError_);
this.mediaPlayer_.off(dashjs$1.MediaPlayer.events.MANIFEST_LOADED, this.getDuration_);
this.mediaPlayer_.reset();
}
if (this.player.dash) {
delete this.player.dash;
}
if (this.ttmlContainer_) {
this.ttmlContainer_.dispose();
this.player.removeChild('TTMLTextTrackDisplay');
}
};
_proto.duration = function duration() {
if (this.mediaPlayer_.isDynamic() && !this.hasFiniteDuration_) {
return Infinity;
}
return this.mediaPlayer_.duration();
}
/**
* Get a list of hooks for a specific lifecycle
*
* @param {string} type the lifecycle to get hooks from
* @param {Function|Function[]} [hook] Optionally add a hook tothe lifecycle
* @return {Array} an array of hooks or epty if none
* @method hooks
*/
;
Html5DashJS.hooks = function hooks(type, hook) {
Html5DashJS.hooks_[type] = Html5DashJS.hooks_[type] || [];
if (hook) {
Html5DashJS.hooks_[type] = Html5DashJS.hooks_[type].concat(hook);
}
return Html5DashJS.hooks_[type];
}
/**
* Add a function hook to a specific dash lifecycle
*
* @param {string} type the lifecycle to hook the function to
* @param {Function|Function[]} hook the function or array of functions to attach
* @method hook
*/
;
Html5DashJS.hook = function hook(type, _hook) {
Html5DashJS.hooks(type, _hook);
}
/**
* Remove a hook from a specific dash lifecycle.
*
* @param {string} type the lifecycle that the function hooked to
* @param {Function} hook The hooked function to remove
* @return {boolean} True if the function was removed, false if not found
* @method removeHook
*/
;
Html5DashJS.removeHook = function removeHook(type, hook) {
var index = Html5DashJS.hooks(type).indexOf(hook);
if (index === -1) {
return false;
}
Html5DashJS.hooks_[type] = Html5DashJS.hooks_[type].slice();
Html5DashJS.hooks_[type].splice(index, 1);
return true;
};
return Html5DashJS;
}();
Html5DashJS.hooks_ = {};
var canHandleKeySystems = function canHandleKeySystems(source) {
// copy the source
source = JSON.parse(JSON.stringify(source));
if (Html5DashJS.updateSourceData) {
videojs.log.warn('updateSourceData has been deprecated.' + ' Please switch to using hook("updatesource", callback).');
source = Html5DashJS.updateSourceData(source);
} // call updatesource hooks
Html5DashJS.hooks('updatesource').forEach(function (hook) {
source = hook(source);
});
var videoEl = document$1.createElement('video');
if (source.keySystemOptions && !(window$1.navigator.requestMediaKeySystemAccess || // IE11 Win 8.1
videoEl.msSetMediaKeys)) {
return false;
}
return true;
};
videojs.DashSourceHandler = function () {
return {
canHandleSource: function canHandleSource(source) {
var dashExtRE = /\.mpd/i;
if (!canHandleKeySystems(source)) {
return '';
}
if (videojs.DashSourceHandler.canPlayType(source.type)) {
return 'probably';
} else if (dashExtRE.test(source.src)) {
return 'maybe';
}
return '';
},
handleSource: function handleSource(source, tech, options) {
return new Html5DashJS(source, tech, options);
},
canPlayType: function canPlayType(type) {
return videojs.DashSourceHandler.canPlayType(type);
}
};
};
videojs.DashSourceHandler.canPlayType = function (type) {
var dashTypeRE = /^application\/dash\+xml/i;
if (dashTypeRE.test(type)) {
return 'probably';
}
return '';
}; // Only add the SourceHandler if the browser supports MediaSourceExtensions
if (window$1.MediaSource) {
videojs.getTech('Html5').registerSourceHandler(videojs.DashSourceHandler(), 0);
}
videojs.Html5DashJS = Html5DashJS;
return Html5DashJS;
})));