(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define([], factory);
	else if(typeof exports === 'object')
		exports["dashjs"] = factory();
	else
		root["dashjs"] = factory();
})(self, function() {
return /******/ (function() { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ "./externals/base64.js":
/*!*****************************!*\
  !*** ./externals/base64.js ***!
  \*****************************/
/***/ (function(__unused_webpack_module, exports) {

/* $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) {// no need to mask byte
    } 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;
}
*/


if (true) {
  exports.decode = BASE64.decode;
  exports.decodeArray = BASE64.decodeArray;
  exports.encode = BASE64.encode;
  exports.encodeASCII = BASE64.encodeASCII;
}

/***/ }),

/***/ "./externals/cea608-parser.js":
/*!************************************!*\
  !*** ./externals/cea608-parser.js ***!
  \************************************/
/***/ (function(__unused_webpack_module, 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) 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) {
  "use strict";
  /**
   *  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,
          charCode2 = 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;
})( false ? 0 : exports);

/***/ }),

/***/ "./externals/xml2json.js":
/*!*******************************!*\
  !*** ./externals/xml2json.js ***!
  \*******************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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) {
  'use strict';

  var VERSION = "1.2.0";
  config = config || {};
  initConfigDefaults();
  initRequiredPolyfills();

  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 initRequiredPolyfills() {}

  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 unescapeXmlChars(str) {
    return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, '&');
  }

  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();
      var parsererrorNS = null;

      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_mediaplayerOnly.js":
/*!**********************************!*\
  !*** ./index_mediaplayerOnly.js ***!
  \**********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Debug": function() { return /* reexport safe */ _src_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"]; },
/* harmony export */   "FactoryMaker": function() { return /* reexport safe */ _src_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"]; },
/* harmony export */   "MediaPlayer": function() { return /* reexport safe */ _src_streaming_MediaPlayer__WEBPACK_IMPORTED_MODULE_0__["default"]; }
/* harmony export */ });
/* harmony import */ var _src_streaming_MediaPlayer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./src/streaming/MediaPlayer */ "./src/streaming/MediaPlayer.js");
/* harmony import */ var _src_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./src/core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _src_core_Debug__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./src/core/Debug */ "./src/core/Debug.js");
/* 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 || __webpack_require__.g;
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 = (0,_src_core_Version__WEBPACK_IMPORTED_MODULE_3__.getVersionString)();
/* harmony default export */ __webpack_exports__["default"] = (dashjs);


/***/ }),

/***/ "./src/core/Debug.js":
/*!***************************!*\
  !*** ./src/core/Debug.js ***!
  \***************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 && 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 ***!
  \******************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \******************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _EventBus__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _events_Events__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./events/Events */ "./src/core/events/Events.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,
 *            manifestUpdateRetryInterval: 100,
 *            cacheInitSegments: false,
 *            applyServiceDescription: true,
 *            applyProducerReferenceTime: true,
 *            applyContentSteering: true,
 *            eventControllerRefreshDelay: 100,
 *            enableManifestDurationMismatchFix: true,
 *            enableManifestTimescaleMismatchFix: false,
 *            parseInbandPrft: false,
 *            capabilities: {
 *               filterUnsupportedEssentialProperties: true,
 *               useMediaCapabilitiesApi: false
 *            },
 *            timeShiftBuffer: {
 *                calcFromSegmentTimeline: false,
 *                fallbackToSegmentTimeline: true
 *            },
 *            metrics: {
 *              maxListDepth: 100
 *            },
 *            delay: {
 *                liveDelayFragmentCount: NaN,
 *                liveDelay: NaN,
 *                useSuggestedPresentationDelay: true
 *            },
 *            protection: {
 *                keepProtectionMediaKeys: false,
 *                ignoreEmeEncryptedEvent: false,
 *                detectPlayreadyMessageFormat: true,
 *            },
 *            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,
 *                avoidCurrentTimeRangePruning: false,
 *                useChangeTypeForTrackSwitch: true,
 *                mediaSourceDurationInfinity: true,
 *                resetSourceBuffersForTrackSwitch: false
 *            },
 *            gaps: {
 *                jumpGaps: true,
 *                jumpLargeGaps: true,
 *                smallGapLimit: 1.5,
 *                threshold: 0.3,
 *                enableSeekFix: true,
 *                enableStallFix: false,
 *                stallSeek: 0.1
 *            },
 *            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: 500,
 *                lowLatencyTimeout: 0,
 *                scheduleWhilePaused: true
 *            },
 *            text: {
 *                defaultEnabled: true,
 *                extendSegmentedCues: true,
 *                webvtt: {
 *                    customRenderingEnabled: false
 *                }
 *            },
 *            liveCatchup: {
 *                maxDrift: NaN,
 *                playbackRate: {min: NaN, max: NaN},
 *                playbackBufferMin: 0.5,
 *                enabled: null,
 *                mode: Constants.LIVE_CATCHUP_MODE_DEFAULT
 *            },
 *            lastBitrateCachingInfo: { enabled: true, ttl: 360000 },
 *            lastMediaSettingsCachingInfo: { enabled: true, ttl: 360000 },
 *            saveLastMediaSettingsForCurrentStreamingSession: true,
 *            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: 20000,
 *            fragmentRequestProgressTimeout: -1,
 *            manifestRequestTimeout: 10000,
 *            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: true,
 *                   switchHistoryRule: true,
 *                   droppedFramesRule: true,
 *                   abandonRequestsRule: true
 *                },
 *                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,
 *                enabledKeys: ['br', 'd', 'ot', 'tb' , 'bl', 'dl', 'mtp', 'nor', 'nrr', 'su' , 'bs', 'rtp' , 'cid', 'pr', 'sf', 'sid', 'st', 'v']
 *            },
 *            cmsd: {
 *                enabled: false,
 *                abr: {
 *                    applyMb: false,
 *                    etpWeightRatio: 0
 *                }
 *           }
 *          },
 *          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=NaN]
 * 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.
 */

/**
 * @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=true]
 * Specifies if we fire manual waiting events once the stall threshold is reached
 * @property {boolean} [avoidCurrentTimeRangePruning=false]
 * Avoids pruning of the buffered range that contains the current playback time.
 *
 * That buffered range is likely to have been enqueued for playback. Pruning it causes a flush and reenqueue in WPE and WebKitGTK based browsers. This stresses the video decoder and can cause stuttering on embedded platforms.
 * @property {boolean} [useChangeTypeForTrackSwitch=true]
 * If this flag is set to true then dash.js will use the MSE v.2 API call "changeType()" before switching to a different track.
 * Note that some platforms might not implement the changeType functio. dash.js is checking for the availability before trying to call it.
 * @property {boolean} [mediaSourceDurationInfinity=true]
 * If this flag is set to true then dash.js will allow `Infinity` to be set as the MediaSource duration otherwise the duration will be set to `Math.pow(2,32)` instead of `Infinity` to allow appending segments indefinitely. 
 * Some platforms such as WebOS 4.x have issues with seeking when duration is set to `Infinity`, setting this flag to false resolve this.
 * @property {boolean} [resetSourceBuffersForTrackSwitch=false]
 * When switching to a track that is not compatible with the currently active MSE SourceBuffers, MSE will be reset. This happens when we switch codecs on a system
 * that does not properly implement "changeType()", such as webOS 4.0 and before.
 */

/**
 * @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=true]
 * 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.
 * @property {boolean} [enableStallFix=false]
 * If playback stalled in a buffered range this fix will perform a seek by the value defined in stallSeek to trigger playback again.
 * @property {number} [stallSeek=0.1]
 * Value to be used in case enableStallFix is set to true
 */

/**
 * @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=500]
 * Default timeout between two consecutive segment scheduling attempts
 * @property {number} [lowLatencyTimeout=0]
 * 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 {boolean} [defaultEnabled=true]
 * Enable/disable subtitle rendering by default.
 * @property {boolean} [extendSegmentedCues=true]
 * Enable/disable patching of segmented cues in order to merge as a single cue by extending cue end time.
 * @property {object} [webvtt={customRenderingEnabled=false}]
 * Enables the custom rendering for WebVTT captions. For details refer to the "Subtitles and Captions" sample section of dash.js.
 * Custom WebVTT rendering requires the external library vtt.js that can be found in the contrib folder.
 */

/**
 * @typedef {Object} LiveCatchupSettings
 * @property {number} [maxDrift=NaN]
 * 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={min: NaN, max: NaN}]
 * Use this parameter to set the minimum and maximum catch up rates, as percentages, 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 min catch up rate are in the range -0.5 to 0 (-50% to 0% playback rate decrease)
 *
 * Valid values for max catch up rate are in the range 0 to 1 (0% to 100% playback rate increase).
 *
 * Set min and max to NaN to turn off live catch up feature.
 *
 * These playback rate limits take precedence over any PlaybackRate values in ServiceDescription elements in an MPD. If only one of the min/max properties is given a value, the property without a value will not fall back to a ServiceDescription value. Its default value of NaN will be used.
 *
 * Note: Catch-up mechanism is only applied when playing low latency live streams.
 * @property {number} [playbackBufferMin=0.5]
 * Use this parameter to specify the minimum buffer which is used for LoL+ based playback rate reduction.
 *
 *
 * @property {boolean} [enabled=null]
 * 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=false]
 * If set to true the player will ignore "encrypted" and "needkey" events thrown by the EME.
 *
 * @property {boolean} [detectPlayreadyMessageFormat=true]
 * If set to true the player will use the raw unwrapped message from the Playready CDM
 */

/**
 * @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: true,switchHistoryRule: true,droppedFramesRule: true,abandonRequestsRule: true}]
 * 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. This value is specified in kbps.
 *
 * Use -1 for no limit.
 * @property {module:Settings~AudioVideoSettings} [minBitrate={audio: -1, video: -1}]
 * The minimum bitrate that the ABR algorithms will choose. This value is specified in kbps.
 *
 * Use -1 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. This value is specified in kbps.
 *
 * Use -1 to let the player decide.
 * @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=5]
 * 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="query"]
 * 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'.
 * @property {Array.<string>} [enabledKeys]
 * This value is used to specify the desired CMCD parameters. Parameters not included in this list are not reported.
 */

/**
 * @typedef {Object} module:Settings~CmsdSettings
 * @property {boolean} [enabled=false]
 * Enable or disable the CMSD response headers parsing.
 * @property {module:Settings~CmsdAbrSettings} [abr]
 * Sets additional ABR rules based on CMSD response headers.
 */

/**
 * @typedef {Object} CmsdAbrSettings
 * @property {boolean} [applyMb=false]
 * Set to true if dash.js should apply CMSD maximum suggested bitrate in ABR logic.
 * @property {number} [etpWeightRatio=0]
 * Sets the weight ratio (between 0 and 1) that shall be applied on CMSD estimated throuhgput compared to measured throughput when calculating throughput.
 */

/**
 * @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=100]
 * How frequently the wallclockTimeUpdated internal event is triggered (in milliseconds).
 * @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=false]
 * Enables the caching of init segments to avoid requesting the init segments before each representation switch.
 * @property {boolean} [applyServiceDescription=true]
 * Set to true if dash.js should use the parameters defined in ServiceDescription elements
 * @property {boolean} [applyProducerReferenceTime=true]
 * Set to true if dash.js should use the parameters defined in ProducerReferenceTime elements in combination with ServiceDescription elements.
 * @property {boolean} [applyContentSteering=true]
 * Set to true if dash.js should apply content steering during playback.
 * @property {number} [eventControllerRefreshDelay=100]
 * For multi-period streams, overwrite the manifest mediaPresentationDuration attribute with the sum of period durations if the manifest mediaPresentationDuration is greater than the sum of period durations
 * @property {boolean} [enableManifestDurationMismatchFix=true]
 * Overwrite the manifest segments base information timescale attributes with the timescale set in initialization segments
 * @property {boolean} [enableManifestTimescaleMismatchFix=false]
 * Defines the delay in milliseconds between two consecutive checks for events to be fired.
 * @property {boolean} [parseInbandPrft=false]
 * Set to true if dash.js should parse inband prft boxes (ProducerReferenceTime) and trigger events.
 * @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~CachingInfoSettings} [lastMediaSettingsCachingInfo={enabled: true, ttl: 360000}]
 * Set to false if you would like to disable the last media settings from being stored to localStorage during playback and used to set the initial track for subsequent playback within the expiration window.
 *
 * The default expiration is one hour, defined in milliseconds.
 * @property {boolean} [saveLastMediaSettingsForCurrentStreamingSession=true]
 * Set to true if dash.js should save media settings from last selected track for incoming track selection during current streaming 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="highestSelectionPriority"]
 * 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=20000]
 * Time in milliseconds before timing out on loading a media fragment.
 *
 * @property {number} [fragmentRequestProgressTimeout=-1]
 * Time in milliseconds before timing out on loading progress of a media fragment.
 *
 * @property {number} [manifestRequestTimeout=10000]
 * Time in milliseconds before timing out on loading a manifest.
 *
 * 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.
 * @property {module:Settings~CmsdSettings} cmsd
 * Settings related to Common Media Server Data parsing.
 */

/**
 * @class
 * @ignore
 */

function Settings() {
  var _retryIntervals, _retryAttempts;

  var instance;
  var context = this.context;
  var eventBus = (0,_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
  var DISPATCH_KEY_MAP = {
    'streaming.delay.liveDelay': _events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SETTING_UPDATED_LIVE_DELAY,
    'streaming.delay.liveDelayFragmentCount': _events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SETTING_UPDATED_LIVE_DELAY_FRAGMENT_COUNT,
    'streaming.liveCatchup.enabled': _events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SETTING_UPDATED_CATCHUP_ENABLED,
    'streaming.liveCatchup.playbackRate.min': _events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SETTING_UPDATED_PLAYBACK_RATE_MIN,
    'streaming.liveCatchup.playbackRate.max': _events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SETTING_UPDATED_PLAYBACK_RATE_MAX
  };
  /**
   * @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,
      manifestUpdateRetryInterval: 100,
      cacheInitSegments: false,
      applyServiceDescription: true,
      applyProducerReferenceTime: true,
      applyContentSteering: true,
      eventControllerRefreshDelay: 100,
      enableManifestDurationMismatchFix: true,
      parseInbandPrft: false,
      enableManifestTimescaleMismatchFix: false,
      capabilities: {
        filterUnsupportedEssentialProperties: true,
        useMediaCapabilitiesApi: false
      },
      timeShiftBuffer: {
        calcFromSegmentTimeline: false,
        fallbackToSegmentTimeline: true
      },
      metrics: {
        maxListDepth: 100
      },
      delay: {
        liveDelayFragmentCount: NaN,
        liveDelay: NaN,
        useSuggestedPresentationDelay: true
      },
      protection: {
        keepProtectionMediaKeys: false,
        ignoreEmeEncryptedEvent: false,
        detectPlayreadyMessageFormat: true
      },
      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,
        avoidCurrentTimeRangePruning: false,
        useChangeTypeForTrackSwitch: true,
        mediaSourceDurationInfinity: true,
        resetSourceBuffersForTrackSwitch: false
      },
      gaps: {
        jumpGaps: true,
        jumpLargeGaps: true,
        smallGapLimit: 1.5,
        threshold: 0.3,
        enableSeekFix: true,
        enableStallFix: false,
        stallSeek: 0.1
      },
      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,
        extendSegmentedCues: true,
        webvtt: {
          customRenderingEnabled: false
        }
      },
      liveCatchup: {
        maxDrift: NaN,
        playbackRate: {
          min: NaN,
          max: NaN
        },
        playbackBufferMin: 0.5,
        enabled: null,
        mode: _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].LIVE_CATCHUP_MODE_DEFAULT
      },
      lastBitrateCachingInfo: {
        enabled: true,
        ttl: 360000
      },
      lastMediaSettingsCachingInfo: {
        enabled: true,
        ttl: 360000
      },
      saveLastMediaSettingsForCurrentStreamingSession: true,
      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: 20000,
      fragmentRequestProgressTimeout: -1,
      manifestRequestTimeout: 10000,
      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: true
        },
        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,
        enabledKeys: ['br', 'd', 'ot', 'tb', 'bl', 'dl', 'mtp', 'nor', 'nrr', 'su', 'bs', 'rtp', 'cid', 'pr', 'sf', 'sid', 'st', 'v']
      },
      cmsd: {
        enabled: false,
        abr: {
          applyMb: false,
          etpWeightRatio: 0
        }
      }
    },
    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] instanceof Array) && source[n] !== null) {
            mixinSettings(source[n], dest[n], path.slice() + n + '.');
          } else {
            dest[n] = _Utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].clone(source[n]);

            if (DISPATCH_KEY_MAP[path + n]) {
              eventBus.trigger(DISPATCH_KEY_MAP[path + n]);
            }
          }
        } else {
          console.error('Settings parameter ' + path + n + ' is not supported');
        }
      }
    }
  }
  /**
   * 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 ***!
  \***************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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__);
/* harmony import */ var ua_parser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ua-parser-js */ "./node_modules/ua-parser-js/src/ua-parser.js");
/* harmony import */ var ua_parser_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(ua_parser_js__WEBPACK_IMPORTED_MODULE_1__);
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} originalUrl
     * @param {string} targetUrl
     * @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().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;
      }
    }
  }, {
    key: "parseUserAgent",
    value: function parseUserAgent() {
      var ua = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

      try {
        var uaString = ua === null ? typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase() : '' : '';
        return (0,ua_parser_js__WEBPACK_IMPORTED_MODULE_1__.UAParser)(uaString);
      } catch (e) {
        return {};
      }
    }
    /**
     * Checks for existence of "http" or "https" in a string
     * @param string
     * @returns {boolean}
     */

  }, {
    key: "stringHasProtocol",
    value: function stringHasProtocol(string) {
      return /(http(s?)):\/\//i.test(string);
    }
  }]);

  return Utils;
}();

/* harmony default export */ __webpack_exports__["default"] = (Utils);

/***/ }),

/***/ "./src/core/Version.js":
/*!*****************************!*\
  !*** ./src/core/Version.js ***!
  \*****************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "getVersionString": function() { return /* binding */ getVersionString; }
/* harmony export */ });
var VERSION = '4.7.2';
function getVersionString() {
  return VERSION;
}

/***/ }),

/***/ "./src/core/errors/Errors.js":
/*!***********************************!*\
  !*** ./src/core/errors/Errors.js ***!
  \***********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.CMSD_STATIC_HEADER = 'cmsdStaticHeader';
    _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_BASE_URL_BLACKLIST_ADD = 'serviceLocationBlacklistAdd';
    _this.SERVICE_LOCATION_BASE_URL_BLACKLIST_CHANGED = 'serviceLocationBlacklistChanged';
    _this.SERVICE_LOCATION_LOCATION_BLACKLIST_ADD = 'serviceLocationLocationBlacklistAdd';
    _this.SERVICE_LOCATION_LOCATION_BLACKLIST_CHANGED = 'serviceLocationLocationBlacklistChanged';
    _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';
    _this.SETTING_UPDATED_LIVE_DELAY = 'settingUpdatedLiveDelay';
    _this.SETTING_UPDATED_LIVE_DELAY_FRAGMENT_COUNT = 'settingUpdatedLiveDelayFragmentCount';
    _this.SETTING_UPDATED_CATCHUP_ENABLED = 'settingUpdatedCatchupEnabled';
    _this.SETTING_UPDATED_PLAYBACK_RATE_MIN = 'settingUpdatedPlaybackRateMin';
    _this.SETTING_UPDATED_PLAYBACK_RATE_MAX = 'settingUpdatedPlaybackRateMax';
    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 ***!
  \***********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var bcp_47_normalize__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! bcp-47-normalize */ "./node_modules/bcp-47-normalize/index.js");
/* harmony import */ var bcp_47_normalize__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(bcp_47_normalize__WEBPACK_IMPORTED_MODULE_9__);
/**
 * 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 = (0,_models_DashManifestModel__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
    patchManifestModel = (0,_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}
   * @memberof module:DashAdapter
   * @instance
   */


  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 sameViewpointWithSchemeIdUri = JSON.stringify(mInfoOne.viewpointsWithSchemeIdUri) === JSON.stringify(mInfoTwo.viewpointsWithSchemeIdUri);
    var sameLang = mInfoOne.lang === mInfoTwo.lang;
    var sameRoles = mInfoOne.roles.toString() === mInfoTwo.roles.toString();
    var sameRolesWithSchemeIdUri = JSON.stringify(mInfoOne.rolesWithSchemeIdUri) === JSON.stringify(mInfoTwo.rolesWithSchemeIdUri);
    var sameAccessibility = mInfoOne.accessibility.toString() === mInfoTwo.accessibility.toString();
    var sameAccessibilityWithSchemeIdUri = JSON.stringify(mInfoOne.accessibilitiesWithSchemeIdUri) === JSON.stringify(mInfoTwo.accessibilitiesWithSchemeIdUri);
    var sameAudioChannelConfiguration = mInfoOne.audioChannelConfiguration.toString() === mInfoTwo.audioChannelConfiguration.toString();
    var sameAudioChannelConfigurationWithSchemeIdUri = JSON.stringify(mInfoOne.audioChannelConfigurationsWithSchemeIdUri) === JSON.stringify(mInfoTwo.audioChannelConfigurationsWithSchemeIdUri);
    return sameId && sameCodec && sameViewpoint && sameViewpointWithSchemeIdUri && sameLang && sameRoles && sameRolesWithSchemeIdUri && sameAccessibility && sameAccessibilityWithSchemeIdUri && sameAudioChannelConfiguration && sameAudioChannelConfigurationWithSchemeIdUri;
  }

  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;
  }
  /**
   * Returns the ProducerReferenceTimes as saved in the DashManifestModel if present
   * @param {object} streamInfo
   * @param {object} mediaInfo
   * @returns {object} producerReferenceTimes
   * @memberOf module:DashAdapter
   * @instance
   */


  function getProducerReferenceTimes(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);
    }

    if (!realAdaptation) return [];
    return dashManifestModel.getProducerReferenceTimesForAdaptation(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}
   * @memberOf module:DashAdapter
   * @instance
   */


  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 - Specified in seconds
   * @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]; // The PTO in voRepresentation is already specified in seconds

      var presentationTimeOffset = !isNaN(voRepresentation.presentationTimeOffset) ? voRepresentation.presentationTimeOffset : !isNaN(eventStream.presentationTimeOffset) ? eventStream.presentationTimeOffset : 0; // In case of version 1 events the presentation_time is parsed as presentation_time_delta

      var presentationTimeDelta = eventBox.presentation_time_delta / timescale;
      var calculatedPresentationTime;

      if (eventBox.version === 0) {
        calculatedPresentationTime = periodStart + mediaStartTime - presentationTimeOffset + presentationTimeDelta;
      } else {
        calculatedPresentationTime = periodStart - presentationTimeOffset + presentationTimeDelta;
      }

      var duration = eventBox.event_duration / timescale;
      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, streamInfo) {
    var events = [];

    if (voPeriods.length > 0) {
      var manifest = voPeriods[0].mpd.manifest;

      if (info instanceof _vo_StreamInfo__WEBPACK_IMPORTED_MODULE_3__["default"]) {
        var period = getPeriodForStreamInfo(info, voPeriods);
        events = dashManifestModel.getEventsForPeriod(period);
      } else if (info instanceof _vo_MediaInfo__WEBPACK_IMPORTED_MODULE_2__["default"]) {
        var _period = getPeriodForStreamInfo(streamInfo, voPeriods);

        events = dashManifestModel.getEventStreamForAdaptationSet(manifest, getAdaptationForMediaInfo(info), _period);
      } else if (info instanceof _vo_RepresentationInfo__WEBPACK_IMPORTED_MODULE_1__["default"]) {
        var _period2 = getPeriodForStreamInfo(streamInfo, voPeriods);

        events = dashManifestModel.getEventStreamForRepresentation(manifest, voRepresentation, _period2);
      }
    }

    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 {number} 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 ContentSteering element of the MPD
   * @param {object} manifest
   * @returns {object} contentSteering
   * @memberOf module:DashAdapter
   * @instance
   */


  function getContentSteering(manifest) {
    return dashManifestModel.getContentSteering(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 locations of the MPD if existing and if they are still valid
   * @param {object} manifest
   * @returns {PatchLocation[]} patch location
   * @memberOf module:DashAdapter
   * @instance
   */


  function getPatchLocation(manifest) {
    var patchLocations = dashManifestModel.getPatchLocation(manifest);
    var publishTime = dashManifestModel.getPublishTime(manifest); // short-circuit when no patch location or publish time exists

    if (!patchLocations || patchLocations.length === 0 || !publishTime) {
      return [];
    }

    return patchLocations.filter(function (patchLocation) {
      // check if the patch location has expired, if so do not consider it
      return isNaN(patchLocation.ttl) || publishTime.getTime() + patchLocation.ttl > new Date().getTime();
    });
  }
  /**
   * 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}
   * @memberOf module:DashAdapter
   * @instance
   */


  function getIsPatch(manifest) {
    return patchManifestModel.getIsPatch(manifest);
  }
  /**
   * Returns the base urls for a given element
   * @param {object} node
   * @returns {BaseURL[]}
   * @memberOf module:DashAdapter
   * @instance
   * @ignore
   */


  function getBaseURLsFromElement(node) {
    return dashManifestModel.getBaseURLsFromElement(node);
  }
  /**
   * Returns the function to sort the Representations
   * @returns {function}
   * @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}
   * @memberOf module:DashAdapter
   * @instance
   */


  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}
   * @memberOf module:DashAdapter
   * @instance
   */


  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}
   * @memberOf module:DashAdapter
   * @instance
   */


  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
   * @memberOf module:DashAdapter
   * @instance
   */


  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 and text replacement

      if (operation.xpath.findsAttribute() || name === '__text') {
        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, acc, acc_rep, roles, accessibility;
    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);
    mediaInfo.segmentAlignment = dashManifestModel.getSegmentAlignment(realAdaptation);
    mediaInfo.subSegmentAlignment = dashManifestModel.getSubSegmentAlignment(realAdaptation);
    viewpoint = dashManifestModel.getViewpointForAdaptation(realAdaptation);
    mediaInfo.viewpoint = viewpoint.length ? viewpoint[0].value : undefined;
    mediaInfo.viewpointsWithSchemeIdUri = viewpoint;
    accessibility = dashManifestModel.getAccessibilityForAdaptation(realAdaptation);
    mediaInfo.accessibility = accessibility.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.accessibilitiesWithSchemeIdUri = accessibility;
    acc = dashManifestModel.getAudioChannelConfigurationForAdaptation(realAdaptation);
    mediaInfo.audioChannelConfiguration = acc.map(function (audioChannelConfiguration) {
      return audioChannelConfiguration.value;
    });
    mediaInfo.audioChannelConfigurationsWithSchemeIdUri = acc;

    if (mediaInfo.audioChannelConfiguration.length === 0 && Array.isArray(realAdaptation.Representation_asArray) && realAdaptation.Representation_asArray.length > 0) {
      acc_rep = dashManifestModel.getAudioChannelConfigurationForRepresentation(realAdaptation.Representation_asArray[0]);
      mediaInfo.audioChannelConfiguration = acc_rep.map(function (audioChannelConfiguration) {
        return audioChannelConfiguration.value;
      });
      mediaInfo.audioChannelConfigurationsWithSchemeIdUri = acc_rep;
    }

    roles = dashManifestModel.getRolesForAdaptation(realAdaptation);
    mediaInfo.roles = roles.map(function (role) {
      return role.value;
    });
    mediaInfo.rolesWithSchemeIdUri = roles;
    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.getSupplementalPropertiesForAdaptation(realAdaptation);

    if ((!mediaInfo.supplementalProperties || Object.keys(mediaInfo.supplementalProperties).length === 0) && Array.isArray(realAdaptation.Representation_asArray) && realAdaptation.Representation_asArray.length > 0) {
      var arr = realAdaptation.Representation_asArray.map(function (repr) {
        return dashManifestModel.getSupplementalPropertiesForRepresentation(repr);
      });

      if (arr.every(function (v) {
        return JSON.stringify(v) === JSON.stringify(arr[0]);
      })) {
        // only output Representation.supplementalProperties to mediaInfo, if they are present on all Representations
        mediaInfo.supplementalProperties = arr[0];
      }
    }

    mediaInfo.supplementalPropertiesAsArray = dashManifestModel.getSupplementalPropertiesAsArrayForAdaptation(realAdaptation);

    if ((!mediaInfo.supplementalPropertiesAsArray || mediaInfo.supplementalPropertiesAsArray.length === 0) && Array.isArray(realAdaptation.Representation_asArray) && realAdaptation.Representation_asArray.length > 0) {
      var _arr = realAdaptation.Representation_asArray.map(function (repr) {
        return dashManifestModel.getSupplementalPropertiesAsArrayForRepresentation(repr);
      });

      if (_arr.every(function (v) {
        return JSON.stringify(v) === JSON.stringify(_arr[0]);
      })) {
        // only output Representation.supplementalProperties to mediaInfo, if they are present on all Representations
        mediaInfo.supplementalPropertiesAsArray = _arr[0];
      }
    }

    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 = bcp_47_normalize__WEBPACK_IMPORTED_MODULE_9___default()(lang);
    mediaInfo.roles = ['caption'];
    mediaInfo.rolesWithSchemeIdUri = [{
      schemeIdUri: 'urn:mpeg:dash:role:2011',
      value: '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,
    getProducerReferenceTimes: getProducerReferenceTimes,
    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,
    getContentSteering: getContentSteering,
    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 ***!
  \*********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;
var SEGMENT_START_TIME_DELTA = 0.001;

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,
        queryParams = {};

    if (!baseURL || destination === baseURL.url || !urlUtils.isRelative(destination)) {
      url = destination;
    } else {
      url = baseURL.url;
      serviceLocation = baseURL.serviceLocation;
      queryParams = baseURL.queryParams;

      if (destination) {
        url = urlUtils.resolve(destination, url);
      }
    }

    if (urlUtils.isRelative(url)) {
      return false;
    }

    request.url = url;
    request.serviceLocation = serviceLocation;
    request.queryParams = queryParams;
    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 = (0,_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 = (0,_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__.replaceTokenForTemplate)(url, 'Number', segment.replacementNumber);
    url = (0,_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__.replaceTokenForTemplate)(url, 'Time', segment.replacementTime);
    url = (0,_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__.replaceTokenForTemplate)(url, 'Bandwidth', bandwidth);
    url = (0,_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_4__.replaceIDForTemplate)(url, representation.id);
    url = (0,_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.availabilityTimeComplete = representation.availabilityTimeComplete;
    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 larger than the current time for which we can generate a request.
   * This is useful in scenarios in which the user seeks into a gap in a dynamic Timeline manifest. 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
   * @return {number}
   */


  function getValidTimeAheadOfTargetTime(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;
      }

      if (representation.adaptation.period.start + representation.adaptation.period.duration < time) {
        return NaN;
      } // If we have a duration look until the end of the duration, otherwise maximum 30 seconds


      var end = isFinite(representation.adaptation.period.duration) ? representation.adaptation.period.start + representation.adaptation.period.duration : time + 30;
      var currentUpperTime = Math.min(time + targetThreshold, end);
      var adjustedTime = NaN;
      var targetRequest = null;

      while (currentUpperTime <= end) {
        var upperRequest = null;

        if (currentUpperTime <= end) {
          upperRequest = getSegmentRequestForTime(mediaInfo, representation, currentUpperTime);
        }

        if (upperRequest) {
          adjustedTime = currentUpperTime;
          targetRequest = upperRequest;
          break;
        }

        currentUpperTime += 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 (!isNaN(targetRequest.startTime) && time < targetRequest.startTime && adjustedTime > targetRequest.startTime) {
          // Apply delta to segment start time to get around rounding issues
          return targetRequest.startTime + SEGMENT_START_TIME_DELTA;
        }

        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,
    getValidTimeAheadOfTargetTime: getValidTimeAheadOfTargetTime
  };
  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 ***!
  \*********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 || (0,_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, cmsd) {
    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, request.fileLoaderType, cmsd);
  }
  /**
   * @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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 setup() {}

  function initialize() {
    urlLoader = (0,_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
  };
  setup();
  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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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 = (0,_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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.SUPPLEMENTAL_PROPERTY_ASARRAY = 'SupplementalProperty_asArray';
      this.INBAND_EVENT_STREAM = 'InbandEventStream';
      this.PRODUCER_REFERENCE_TIME = 'ProducerReferenceTime';
      this.INBAND = 'inband';
      this.TYPE = 'type';
      this.ACCESSIBILITY = 'Accessibility';
      this.ROLE = 'Role';
      this.RATING = 'Rating';
      this.CONTENT_COMPONENT = 'ContentComponent';
      this.SUBSET = 'Subset';
      this.LANG = 'lang';
      this.VIEWPOINT = 'Viewpoint';
      this.VIEWPOINT_ASARRAY = 'Viewpoint_asArray';
      this.ROLE_ASARRAY = 'Role_asArray';
      this.REPRESENTATION_ASARRAY = 'Representation_asArray';
      this.PRODUCERREFERENCETIME_ASARRAY = 'ProducerReferenceTime_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.SERVICE_DESCRIPTION_OPERATING_QUALITY = 'OperatingQuality';
      this.SERVICE_DESCRIPTION_OPERATING_BANDWIDTH = 'OperatingBandwidth';
      this.PATCH_LOCATION = 'PatchLocation';
      this.PATCH_LOCATION_AS_ARRAY = 'PatchLocation_asArray';
      this.LOCATION = 'Location';
      this.LOCATION_AS_ARRAY = 'Location_asArray';
      this.PUBLISH_TIME = 'publishTime';
      this.ORIGINAL_PUBLISH_TIME = 'originalPublishTime';
      this.ORIGINAL_MPD_ID = 'mpdId';
      this.WALL_CLOCK_TIME = 'wallClockTime';
      this.PRESENTATION_TIME = 'presentationTime';
      this.LABEL = 'Label';
      this.GROUP_LABEL = 'GroupLabel';
      this.CONTENT_STEERING = 'ContentSteering';
      this.CONTENT_STEERING_AS_ARRAY = 'ContentSteering_asArray';
      this.DEFAULT_SERVICE_LOCATION = 'defaultServiceLocation';
      this.QUERY_BEFORE_START = 'queryBeforeStart';
      this.CLIENT_REQUIREMENT = 'clientRequirement';
      this.TTL = 'ttl';
      this.CONTENT_STEERING_RESPONSE = {
        VERSION: 'VERSION',
        TTL: 'TTL',
        RELOAD_URI: 'RELOAD-URI',
        PATHWAY_PRIORITY: 'PATHWAY-PRIORITY',
        PATHWAY_CLONES: 'PATHWAY-CLONES',
        BASE_ID: 'BASE-ID',
        ID: 'ID',
        URI_REPLACEMENT: 'URI-REPLACEMENT',
        HOST: 'HOST',
        PARAMS: 'PARAMS'
      };
      this.PRODUCER_REFERENCE_TIME_TYPE = {
        ENCODER: 'encoder',
        CAPTURED: 'captured',
        APPLICATION: 'application'
      };
      this.SEGMENT_ALIGNMENT = 'segmentAlignment';
      this.SUB_SEGMENT_ALIGNMENT = 'subsegmentAlignment';
    }
  }]);

  return DashConstants;
}();

var constants = new DashConstants();
/* harmony default export */ __webpack_exports__["default"] = (constants);

/***/ }),

/***/ "./src/dash/controllers/ContentSteeringController.js":
/*!***********************************************************!*\
  !*** ./src/dash/controllers/ContentSteeringController.js ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _streaming_net_URLLoader__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../streaming/net/URLLoader */ "./src/streaming/net/URLLoader.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _vo_ContentSteeringRequest__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../vo/ContentSteeringRequest */ "./src/dash/vo/ContentSteeringRequest.js");
/* harmony import */ var _vo_ContentSteeringResponse__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../vo/ContentSteeringResponse */ "./src/dash/vo/ContentSteeringResponse.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../constants/DashConstants */ "./src/dash/constants/DashConstants.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _vo_BaseURL__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../vo/BaseURL */ "./src/dash/vo/BaseURL.js");
/* harmony import */ var _vo_MpdLocation__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../vo/MpdLocation */ "./src/dash/vo/MpdLocation.js");
/* harmony import */ var _core_Utils_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../core/Utils.js */ "./src/core/Utils.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 QUERY_PARAMETER_KEYS = {
  THROUGHPUT: '_DASH_throughput',
  PATHWAY: '_DASH_pathway',
  URL: 'url'
};
var THROUGHPUT_SAMPLES = 4;

function ContentSteeringController() {
  var context = this.context;
  var urlUtils = (0,_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
  var instance, logger, currentSteeringResponseData, serviceLocationList, throughputList, nextRequestTimer, urlLoader, errHandler, dashMetrics, mediaPlayerModel, manifestModel, requestModifier, serviceDescriptionController, eventBus, adapter;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);

    _resetInitialSettings();
  }

  function setConfig(config) {
    if (!config) return;

    if (config.adapter) {
      adapter = config.adapter;
    }

    if (config.errHandler) {
      errHandler = config.errHandler;
    }

    if (config.dashMetrics) {
      dashMetrics = config.dashMetrics;
    }

    if (config.mediaPlayerModel) {
      mediaPlayerModel = config.mediaPlayerModel;
    }

    if (config.requestModifier) {
      requestModifier = config.requestModifier;
    }

    if (config.manifestModel) {
      manifestModel = config.manifestModel;
    }

    if (config.serviceDescriptionController) {
      serviceDescriptionController = config.serviceDescriptionController;
    }

    if (config.eventBus) {
      eventBus = config.eventBus;
    }
  }
  /**
   * Initialize the steering controller by instantiating classes and registering observer callback
   */


  function initialize() {
    urlLoader = (0,_streaming_net_URLLoader__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
      errHandler: errHandler,
      dashMetrics: dashMetrics,
      mediaPlayerModel: mediaPlayerModel,
      requestModifier: requestModifier,
      errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_3__["default"]
    });
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_STARTED, _onFragmentLoadingStarted, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].MANIFEST_LOADING_STARTED, _onManifestLoadingStarted, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].MANIFEST_LOADING_FINISHED, _onManifestLoadingFinished, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].THROUGHPUT_MEASUREMENT_STORED, _onThroughputMeasurementStored, instance);
  }
  /**
   * When loading of a fragment starts we store its serviceLocation in our list
   * @param {object} e
   * @private
   */


  function _onFragmentLoadingStarted(e) {
    _addToServiceLocationList(e, 'baseUrl');
  }
  /**
   * When loading of a manifest starts we store its serviceLocation in our list
   * @param {object} e
   * @private
   */


  function _onManifestLoadingStarted(e) {
    _addToServiceLocationList(e, 'location');
  }
  /**
   * Basic throughput calculation for manifest requests
   * @param {object} e
   * @private
   */


  function _onManifestLoadingFinished(e) {
    if (!e || !e.request || !e.request.serviceLocation || !e.request.requestStartDate || !e.request.requestEndDate || isNaN(e.request.bytesTotal)) {
      return;
    }

    var serviceLocation = e.request.serviceLocation;
    var elapsedTime = e.request.requestEndDate.getTime() - e.request.requestStartDate.getTime();
    var throughput = parseInt(e.request.bytesTotal * 8 / elapsedTime * 1000); // bit/s

    _storeThroughputForServiceLocation(serviceLocation, throughput);
  }
  /**
   * When a throughput measurement for fragments was stored in ThroughputHistory we save it as well
   * @param {object} e
   * @private
   */


  function _onThroughputMeasurementStored(e) {
    if (!e || !e.httpRequest || !e.httpRequest._serviceLocation || isNaN(e.throughput)) {
      return;
    }

    var serviceLocation = e.httpRequest._serviceLocation;
    var throughput = e.throughput * 1000;

    _storeThroughputForServiceLocation(serviceLocation, throughput);
  }
  /**
   * Helper function to store a throughput value from the corresponding serviceLocation
   * @param {string} serviceLocation
   * @param {number} throughput
   * @private
   */


  function _storeThroughputForServiceLocation(serviceLocation, throughput) {
    if (!throughputList[serviceLocation]) {
      throughputList[serviceLocation] = [];
    }

    throughputList[serviceLocation].push(throughput);

    if (throughputList[serviceLocation].length > THROUGHPUT_SAMPLES) {
      throughputList[serviceLocation].shift();
    }
  }
  /**
   * Adds a new service location entry to our list
   * @param {object} e
   * @param {string} type
   * @private
   */


  function _addToServiceLocationList(e, type) {
    if (e && e.request && e.request.serviceLocation) {
      var serviceLocation = e.request.serviceLocation;

      if (serviceLocationList[type].all.indexOf(serviceLocation) === -1) {
        serviceLocationList[type].all.push(serviceLocation);
      }

      serviceLocationList[type].current = serviceLocation;
    }
  }
  /**
   * Query DashAdapter and Service Description Controller to get the steering information defined in the manifest
   * @returns {object}
   */


  function getSteeringDataFromManifest() {
    var manifest = manifestModel.getValue();
    var contentSteeringData = adapter.getContentSteering(manifest);

    if (!contentSteeringData) {
      contentSteeringData = serviceDescriptionController.getServiceDescriptionSettings().contentSteering;
    }

    return contentSteeringData;
  }
  /**
   * Should query steering server prior to playback start
   * @returns {boolean}
   */


  function shouldQueryBeforeStart() {
    var steeringDataFromManifest = getSteeringDataFromManifest();
    return !!steeringDataFromManifest && steeringDataFromManifest.queryBeforeStart;
  }
  /**
   * Load the steering data from the steering server
   * @returns {Promise}
   */


  function loadSteeringData() {
    return new Promise(function (resolve) {
      try {
        var steeringDataFromManifest = getSteeringDataFromManifest();

        if (!steeringDataFromManifest || !steeringDataFromManifest.serverUrl) {
          resolve();
          return;
        }

        var url = _getSteeringServerUrl(steeringDataFromManifest);

        var request = new _vo_ContentSteeringRequest__WEBPACK_IMPORTED_MODULE_4__["default"](url);
        urlLoader.load({
          request: request,
          success: function success(data) {
            _handleSteeringResponse(data);

            eventBus.trigger(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].CONTENT_STEERING_REQUEST_COMPLETED, {
              currentSteeringResponseData: currentSteeringResponseData,
              url: url
            });
            resolve();
          },
          error: function error(e, _error, statusText, response) {
            _handleSteeringResponseError(e, response);

            resolve(e);
          },
          complete: function complete() {
            // Clear everything except for the current entry
            serviceLocationList.baseUrl.all = _getClearedServiceLocationListAfterSteeringRequest(serviceLocationList.baseUrl);
            serviceLocationList.location.all = _getClearedServiceLocationListAfterSteeringRequest(serviceLocationList.location);
          }
        });
      } catch (e) {
        resolve(e);
      }
    });
  }
  /**
   * Return the cleared data of our serviceLocationList after the steering request was completed
   * @param {object} data
   * @returns {Object[]}
   * @private
   */


  function _getClearedServiceLocationListAfterSteeringRequest(data) {
    if (!data.all || data.all.length === 0 || !data.current) {
      return [];
    }

    return data.all.filter(function (entry) {
      return entry === data.current;
    });
  }
  /**
   * Returns the adjusted steering server url enhanced by pathway and throughput parameter
   * @param {object} steeringDataFromManifest
   * @returns {string}
   * @private
   */


  function _getSteeringServerUrl(steeringDataFromManifest) {
    var url = steeringDataFromManifest.serverUrl;

    if (currentSteeringResponseData && currentSteeringResponseData.reloadUri) {
      if (urlUtils.isRelative(currentSteeringResponseData.reloadUri)) {
        url = urlUtils.resolve(currentSteeringResponseData.reloadUri, steeringDataFromManifest.serverUrl);
      } else {
        url = currentSteeringResponseData.reloadUri;
      }
    }

    var additionalQueryParameter = [];
    var serviceLocations = serviceLocationList.baseUrl.all.concat(serviceLocationList.location.all);

    if (serviceLocations.length > 0) {
      // Derive throughput for each service Location
      var data = serviceLocations.map(function (serviceLocation) {
        var throughput = _calculateThroughputForServiceLocation(serviceLocation);

        return {
          serviceLocation: serviceLocation,
          throughput: throughput
        };
      }); // Sort in descending order to put all elements without throughput (-1) in the end

      data.sort(function (a, b) {
        return b.throughput - a.throughput;
      });
      var pathwayString = '';
      var throughputString = '';
      data.forEach(function (entry, index) {
        if (index !== 0) {
          pathwayString = "".concat(pathwayString, ",");

          if (entry.throughput > -1) {
            throughputString = "".concat(throughputString, ",");
          }
        }

        pathwayString = "".concat(pathwayString).concat(entry.serviceLocation);

        if (entry.throughput > -1) {
          throughputString = "".concat(throughputString).concat(entry.throughput);
        }
      });
      additionalQueryParameter.push({
        key: QUERY_PARAMETER_KEYS.PATHWAY,
        value: "\"".concat(pathwayString, "\"")
      });
      additionalQueryParameter.push({
        key: QUERY_PARAMETER_KEYS.THROUGHPUT,
        value: throughputString
      });
    }

    url = _core_Utils_js__WEBPACK_IMPORTED_MODULE_11__["default"].addAditionalQueryParameterToUrl(url, additionalQueryParameter);
    return url;
  }
  /**
   * Calculate the arithmetic mean of the last throughput samples
   * @param {string} serviceLocation
   * @returns {number}
   * @private
   */


  function _calculateThroughputForServiceLocation(serviceLocation) {
    if (!serviceLocation || !throughputList[serviceLocation] || throughputList[serviceLocation].length === 0) {
      return -1;
    }

    var throughput = throughputList[serviceLocation].reduce(function (acc, curr) {
      return acc + curr;
    }) / throughputList[serviceLocation].length;
    return parseInt(throughput);
  }
  /**
   * Parse the steering response and create instance of model ContentSteeringResponse
   * @param {object} data
   * @private
   */


  function _handleSteeringResponse(data) {
    if (!data || !data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.VERSION] || parseInt(data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.VERSION]) !== 1) {
      return;
    } // Update the data for other classes to use


    currentSteeringResponseData = new _vo_ContentSteeringResponse__WEBPACK_IMPORTED_MODULE_5__["default"]();
    currentSteeringResponseData.version = data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.VERSION];

    if (data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.TTL] && !isNaN(data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.TTL])) {
      currentSteeringResponseData.ttl = data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.TTL];
    }

    if (data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.RELOAD_URI]) {
      currentSteeringResponseData.reloadUri = data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.RELOAD_URI];
    }

    if (data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.PATHWAY_PRIORITY]) {
      currentSteeringResponseData.pathwayPriority = data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.PATHWAY_PRIORITY];
    }

    if (data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.PATHWAY_CLONES]) {
      currentSteeringResponseData.pathwayClones = data[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.PATHWAY_CLONES];
      currentSteeringResponseData.pathwayClones = currentSteeringResponseData.pathwayClones.filter(function (pathwayClone) {
        return _isValidPathwayClone(pathwayClone);
      });
    }

    _startSteeringRequestTimer();
  }
  /**
   * Checks if object is a valid PathwayClone
   * @param {object} pathwayClone
   * @returns {boolean}
   * @private
   */


  function _isValidPathwayClone(pathwayClone) {
    return pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.BASE_ID] && pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.ID] && pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.URI_REPLACEMENT] && pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.URI_REPLACEMENT][_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.HOST];
  }
  /**
   * Returns synthesized BaseURL elements based on Pathway Cloning
   * @param {BaseURL[]}referenceElements
   * @returns {BaseURL[]}
   */


  function getSynthesizedBaseUrlElements(referenceElements) {
    try {
      var synthesizedElements = _getSynthesizedElements(referenceElements);

      return synthesizedElements.map(function (element) {
        var synthesizedBaseUrl = new _vo_BaseURL__WEBPACK_IMPORTED_MODULE_9__["default"](element.synthesizedUrl, element.serviceLocation);
        synthesizedBaseUrl.queryParams = element.queryParams;
        synthesizedBaseUrl.dvb_priority = element.reference.dvb_priority;
        synthesizedBaseUrl.dvb_weight = element.reference.dvb_weight;
        synthesizedBaseUrl.availabilityTimeOffset = element.reference.availabilityTimeOffset;
        synthesizedBaseUrl.availabilityTimeComplete = element.reference.availabilityTimeComplete;
        return synthesizedBaseUrl;
      });
    } catch (e) {
      logger.error(e);
      return [];
    }
  }
  /**
   * Returns synthesized Location elements based on Pathway Cloning
   * @param {MpdLocation[]} referenceElements
   * @returns {MpdLocation[]}
   */


  function getSynthesizedLocationElements(referenceElements) {
    try {
      var synthesizedElements = _getSynthesizedElements(referenceElements);

      return synthesizedElements.map(function (element) {
        var synthesizedLocation = new _vo_MpdLocation__WEBPACK_IMPORTED_MODULE_10__["default"](element.synthesizedUrl, element.serviceLocation);
        synthesizedLocation.queryParams = element.queryParams;
        return synthesizedLocation;
      });
    } catch (e) {
      logger.error(e);
      return [];
    }
  }
  /**
   * Helper function to synthesize elements
   * @param {array} referenceElements
   * @returns {array}
   * @private
   */


  function _getSynthesizedElements(referenceElements) {
    try {
      var synthesizedElements = [];

      if (!referenceElements || referenceElements.length === 0 || !currentSteeringResponseData || !currentSteeringResponseData.pathwayClones || currentSteeringResponseData.pathwayClones.length === 0) {
        return synthesizedElements;
      }

      currentSteeringResponseData.pathwayClones.forEach(function (pathwayClone) {
        var baseElements = referenceElements.filter(function (source) {
          return pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.BASE_ID] === source.serviceLocation;
        });
        var reference = null;

        if (baseElements && baseElements.length > 0) {
          reference = baseElements[0];
        }

        if (reference) {
          var referenceUrl = new URL(reference.url);
          var host = pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.URI_REPLACEMENT][_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.HOST];
          host = _core_Utils_js__WEBPACK_IMPORTED_MODULE_11__["default"].stringHasProtocol(host) ? host : "".concat(referenceUrl.protocol, "//").concat(host);
          var synthesizedElement = {
            synthesizedUrl: "".concat(host).concat(referenceUrl.pathname),
            serviceLocation: pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.ID],
            queryParams: pathwayClone[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.URI_REPLACEMENT][_constants_DashConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CONTENT_STEERING_RESPONSE.PARAMS],
            reference: reference
          };
          synthesizedElements.push(synthesizedElement);
        }
      });
      return synthesizedElements;
    } catch (e) {
      logger.error(e);
      return [];
    }
  }
  /**
   * Start timeout for next steering request
   * @private
   */


  function _startSteeringRequestTimer() {
    // Start timer for next request
    if (currentSteeringResponseData && currentSteeringResponseData.ttl && !isNaN(currentSteeringResponseData.ttl)) {
      if (nextRequestTimer) {
        clearTimeout(nextRequestTimer);
      }

      nextRequestTimer = setTimeout(function () {
        loadSteeringData();
      }, currentSteeringResponseData.ttl * 1000);
    }
  }
  /**
   * Stop timeout for next steering request
   */


  function stopSteeringRequestTimer() {
    if (nextRequestTimer) {
      clearTimeout(nextRequestTimer);
    }

    nextRequestTimer = null;
  }
  /**
   * Handle errors that occured when querying the steering server
   * @param {object} e
   * @param {object} response
   * @private
   */


  function _handleSteeringResponseError(e, response) {
    try {
      logger.warn("Error fetching data from content steering server", e);
      var statusCode = response.status;

      switch (statusCode) {
        // 410 response code. Stop steering
        case 410:
          break;
        // 429 Too Many Requests. Replace existing TTL value with Retry-After header if present

        case 429:
          var retryAfter = response && response.getResponseHeader ? response.getResponseHeader('retry-after') : null;

          if (retryAfter !== null) {
            if (!currentSteeringResponseData) {
              currentSteeringResponseData = {};
            }

            currentSteeringResponseData.ttl = parseInt(retryAfter);
          }

          _startSteeringRequestTimer();

          break;

        default:
          _startSteeringRequestTimer();

          break;
      }
    } catch (e) {
      logger.error(e);
    }
  }
  /**
   * Returns the currentSteeringResponseData
   * @returns {ContentSteeringResponse}
   */


  function getCurrentSteeringResponseData() {
    return currentSteeringResponseData;
  }

  function reset() {
    _resetInitialSettings();

    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].FRAGMENT_LOADING_STARTED, _onFragmentLoadingStarted, instance);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].MANIFEST_LOADING_STARTED, _onManifestLoadingStarted, instance);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].MANIFEST_LOADING_FINISHED, _onManifestLoadingFinished, instance);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].THROUGHPUT_MEASUREMENT_STORED, _onThroughputMeasurementStored, instance);
  }

  function _resetInitialSettings() {
    currentSteeringResponseData = null;
    throughputList = {};
    serviceLocationList = {
      baseUrl: {
        current: null,
        all: []
      },
      location: {
        current: null,
        all: []
      }
    };
    stopSteeringRequestTimer();
  }

  instance = {
    reset: reset,
    setConfig: setConfig,
    loadSteeringData: loadSteeringData,
    getCurrentSteeringResponseData: getCurrentSteeringResponseData,
    shouldQueryBeforeStart: shouldQueryBeforeStart,
    getSteeringDataFromManifest: getSteeringDataFromManifest,
    stopSteeringRequestTimer: stopSteeringRequestTimer,
    getSynthesizedBaseUrlElements: getSynthesizedBaseUrlElements,
    getSynthesizedLocationElements: getSynthesizedLocationElements,
    initialize: initialize
  };
  setup();
  return instance;
}

ContentSteeringController.__dashjs_factory_name = 'ContentSteeringController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(ContentSteeringController));

/***/ }),

/***/ "./src/dash/controllers/RepresentationController.js":
/*!**********************************************************!*\
  !*** ./src/dash/controllers/RepresentationController.js ***!
  \**********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 adapter = config.adapter;
  var instance, realAdaptation, updating, voAvailableRepresentations, currentRepresentationInfo, 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 getCurrentRepresentationInfo() {
    return currentRepresentationInfo;
  }

  function resetInitialSettings() {
    realAdaptation = null;
    updating = true;
    voAvailableRepresentations = [];
    currentRepresentationInfo = null;
  }

  function reset() {
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_2__["default"].MANIFEST_VALIDITY_CHANGED, onManifestValidityChanged, instance);
    resetInitialSettings();
  }

  function updateData(newRealAdaptation, availableRepresentations, type, isFragmented, quality) {
    return new Promise(function (resolve, reject) {
      updating = true;
      voAvailableRepresentations = availableRepresentations;
      realAdaptation = newRealAdaptation;
      var rep = getRepresentationForQuality(quality);

      _setCurrentVoRepresentation(rep);

      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();
        resolve();
        return;
      }

      var promises = [];

      for (var i = 0, ln = voAvailableRepresentations.length; i < ln; i++) {
        var currentRep = voAvailableRepresentations[i];
        promises.push(_updateRepresentation(currentRep));
      }

      Promise.all(promises).then(function () {
        // Update the current representation again as we have now the reference to the segments
        var rep = getRepresentationForQuality(quality);

        _setCurrentVoRepresentation(rep);

        resolve();
      })["catch"](function (e) {
        reject(e);
      });
    });
  }

  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 = (0,_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;
    currentRepresentationInfo = adapter.convertRepresentationToRepresentationInfo(currentVoRepresentation);
  }

  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,
    getCurrentRepresentationInfo: getCurrentRepresentationInfo,
    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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_SegmentBaseLoader__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
    webmSegmentBaseLoader = (0,_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 ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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] = (0,_utils_TimelineSegmentsGetter__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create(config, isDynamic);
    getters[dashConstants.SEGMENT_TEMPLATE] = (0,_utils_TemplateSegmentsGetter__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create(config, isDynamic);
    getters[dashConstants.SEGMENT_LIST] = (0,_utils_ListSegmentsGetter__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create(config, isDynamic);
    getters[dashConstants.SEGMENT_BASE] = (0,_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/controllers/ServiceDescriptionController.js":
/*!**************************************************************!*\
  !*** ./src/dash/controllers/ServiceDescriptionController.js ***!
  \**************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../streaming/constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__ = __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 SUPPORTED_SCHEMES = [_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].SERVICE_DESCRIPTION_DVB_LL_SCHEME];
var MEDIA_TYPES = {
  VIDEO: 'video',
  AUDIO: 'audio',
  ANY: 'any',
  ALL: 'all'
};

function ServiceDescriptionController() {
  var context = this.context;
  var instance, serviceDescriptionSettings, prftOffsets, logger, adapter;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);

    _resetInitialSettings();
  }

  function setConfig(config) {
    if (!config) return;

    if (config.adapter) {
      adapter = config.adapter;
    }
  }

  function reset() {
    _resetInitialSettings();
  }

  function _resetInitialSettings() {
    serviceDescriptionSettings = {
      liveDelay: NaN,
      liveCatchup: {
        maxDrift: NaN,
        playbackRate: {
          min: NaN,
          max: NaN
        }
      },
      minBitrate: {},
      maxBitrate: {},
      initialBitrate: {},
      contentSteering: null
    };
    prftOffsets = [];
  }
  /**
   * Returns the service description settings for latency, catchup and bandwidth
   */


  function getServiceDescriptionSettings() {
    return serviceDescriptionSettings;
  }
  /**
   * Check for potential ServiceDescriptor elements in the MPD and update the settings accordingly
   * @param {object} manifestInfo
   * @private
   */


  function applyServiceDescription(manifestInfo) {
    if (!manifestInfo || !manifestInfo.serviceDescriptions) {
      return;
    }

    var supportedServiceDescriptions = manifestInfo.serviceDescriptions.filter(function (sd) {
      return SUPPORTED_SCHEMES.includes(sd.schemeIdUri);
    });
    var allClientsServiceDescriptions = manifestInfo.serviceDescriptions.filter(function (sd) {
      return sd.schemeIdUri == null;
    });
    var sd = supportedServiceDescriptions.length > 0 ? supportedServiceDescriptions[supportedServiceDescriptions.length - 1] : allClientsServiceDescriptions[allClientsServiceDescriptions.length - 1];
    if (!sd) return;

    if (sd.latency && sd.latency.target > 0) {
      _applyServiceDescriptionLatency(sd);
    }

    if (sd.playbackRate) {
      _applyServiceDescriptionPlaybackRate(sd);
    }

    if (sd.operatingQuality) {
      _applyServiceDescriptionOperatingQuality(sd);
    }

    if (sd.operatingBandwidth) {
      _applyServiceDescriptionOperatingBandwidth(sd);
    }

    if (sd.contentSteering) {
      _applyServiceDescriptionContentSteering(sd);
    }
  }
  /**
   * Adjust the latency targets for the service.
   * @param {object} sd - service description element
   * @private
   */


  function _applyServiceDescriptionLatency(sd) {
    var params;

    if (sd.schemeIdUri === _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].SERVICE_DESCRIPTION_DVB_LL_SCHEME) {
      params = _getDvbServiceDescriptionLatencyParameters(sd);
    } else {
      params = _getStandardServiceDescriptionLatencyParameters(sd);
    }

    if (prftOffsets.length > 0) {
      var _calculateTimeOffset2 = _calculateTimeOffset(params),
          to = _calculateTimeOffset2.to,
          id = _calculateTimeOffset2.id; // TS 103 285 Clause 10.20.4. 3) Subtract calculated offset from Latency@target converted from milliseconds
      // liveLatency does not consider ST@availabilityTimeOffset so leave out that step
      // Since maxDrift is a difference rather than absolute it does not need offset applied


      serviceDescriptionSettings.liveDelay = params.liveDelay - to;
      serviceDescriptionSettings.liveCatchup.maxDrift = params.maxDrift;
      logger.debug("\n                Found latency properties coming from service description. Applied time offset of ".concat(to, " from ProducerReferenceTime element with id ").concat(id, ".\n                Live Delay: ").concat(params.liveDelay - to, ", Live catchup max drift: ").concat(params.maxDrift, "\n            "));
    } else {
      serviceDescriptionSettings.liveDelay = params.liveDelay;
      serviceDescriptionSettings.liveCatchup.maxDrift = params.maxDrift;
      logger.debug("Found latency properties coming from service description: Live Delay: ".concat(params.liveDelay, ", Live catchup max drift: ").concat(params.maxDrift));
    }
  }
  /**
   * Get default parameters for liveDelay,maxDrift
   * @param {object} sd
   * @return {{maxDrift: (number|undefined), liveDelay: number, referenceId: (number|undefined)}}
   * @private
   */


  function _getStandardServiceDescriptionLatencyParameters(sd) {
    var liveDelay = sd.latency.target / 1000;
    var maxDrift = !isNaN(sd.latency.max) && sd.latency.max > sd.latency.target ? (sd.latency.max - sd.latency.target + 500) / 1000 : NaN;
    var referenceId = sd.latency.referenceId || NaN;
    return {
      liveDelay: liveDelay,
      maxDrift: maxDrift,
      referenceId: referenceId
    };
  }
  /**
   * Get DVB DASH parameters for liveDelay,maxDrift
   * @param sd
   * @return {{maxDrift: (number|undefined), liveDelay: number, referenceId: (number|undefined)}}
   * @private
   */


  function _getDvbServiceDescriptionLatencyParameters(sd) {
    var liveDelay = sd.latency.target / 1000;
    var maxDrift = !isNaN(sd.latency.max) && sd.latency.max > sd.latency.target ? (sd.latency.max - sd.latency.target + 500) / 1000 : NaN;
    var referenceId = sd.latency.referenceId || NaN;
    return {
      liveDelay: liveDelay,
      maxDrift: maxDrift,
      referenceId: referenceId
    };
  }
  /**
   * Adjust the playback rate targets for the service
   * @param {object} sd
   * @private
   */


  function _applyServiceDescriptionPlaybackRate(sd) {
    // Convert each playback rate into a difference from 1. i.e 0.8 becomes -0.2.
    var min = sd.playbackRate.min ? Math.round((sd.playbackRate.min - 1.0) * 1000) / 1000 : NaN;
    var max = sd.playbackRate.max ? Math.round((sd.playbackRate.max - 1.0) * 1000) / 1000 : NaN;
    serviceDescriptionSettings.liveCatchup.playbackRate.min = min;
    serviceDescriptionSettings.liveCatchup.playbackRate.max = max;
    logger.debug("Found latency properties coming from service description: Live catchup min playback rate: ".concat(min));
    logger.debug("Found latency properties coming from service description: Live catchup max playback rate: ".concat(max));
  }
  /**
   * Used to specify a quality ranking. We do not support this yet.
   * @private
   */


  function _applyServiceDescriptionOperatingQuality() {
    return;
  }
  /**
   * Adjust the operating quality targets for the service
   * @param {object} sd
   * @private
   */


  function _applyServiceDescriptionOperatingBandwidth(sd) {
    // Aggregation of media types is not supported yet
    if (!sd || !sd.operatingBandwidth || !sd.operatingBandwidth.mediaType || sd.operatingBandwidth.mediaType === MEDIA_TYPES.ALL) {
      return;
    }

    var params = {};
    params.minBandwidth = sd.operatingBandwidth.min;
    params.maxBandwidth = sd.operatingBandwidth.max;
    params.targetBandwidth = sd.operatingBandwidth.target;
    var mediaTypesToApply = [];

    if (sd.operatingBandwidth.mediaType === MEDIA_TYPES.VIDEO || sd.operatingBandwidth.mediaType === MEDIA_TYPES.AUDIO) {
      mediaTypesToApply.push(sd.operatingBandwidth.mediaType);
    } else if (sd.operatingBandwidth.mediaType === MEDIA_TYPES.ANY) {
      mediaTypesToApply.push(MEDIA_TYPES.AUDIO);
      mediaTypesToApply.push(MEDIA_TYPES.VIDEO);
    }

    mediaTypesToApply.forEach(function (mediaType) {
      if (!isNaN(params.minBandwidth)) {
        _updateBandwidthSetting('minBitrate', mediaType, params.minBandwidth);
      }

      if (!isNaN(params.maxBandwidth)) {
        _updateBandwidthSetting('maxBitrate', mediaType, params.maxBandwidth);
      }

      if (!isNaN(params.targetBandwidth)) {
        _updateBandwidthSetting('initialBitrate', mediaType, params.targetBandwidth);
      }
    });
  }
  /**
   * Update the bandwidth settings vor a specific field and media type
   * @param {string} field
   * @param {string} mediaType
   * @param {number} value
   * @private
   */


  function _updateBandwidthSetting(field, mediaType, value) {
    try {
      // Service description values are specified in bps. Settings expect the value in kbps
      serviceDescriptionSettings[field][mediaType] = value / 1000;
    } catch (e) {
      logger.error(e);
    }
  }
  /**
   * Add information about content steering element. Handling is up to the ContentSteeringController
   *  @param {object} sd
   *  @private
   */


  function _applyServiceDescriptionContentSteering(sd) {
    serviceDescriptionSettings.contentSteering = sd.contentSteering;
  }
  /**
   * Returns the current calculated time offsets based on ProducerReferenceTime elements
   * @returns {array}
   */


  function getProducerReferenceTimeOffsets() {
    return prftOffsets;
  }
  /**
   * Calculates an array of time offsets each with matching ProducerReferenceTime id.
   * Call before applyServiceDescription if producer reference time elements should be considered.
   * @param {array} streamInfos
   * @returns {array}
   * @private
   */


  function calculateProducerReferenceTimeOffsets(streamInfos) {
    try {
      var timeOffsets = [];

      if (streamInfos && streamInfos.length > 0) {
        var mediaTypes = [_streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].VIDEO, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].AUDIO, _streaming_constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].TEXT];
        var astInSeconds = adapter.getAvailabilityStartTime() / 1000;
        streamInfos.forEach(function (streamInfo) {
          var offsets = mediaTypes.reduce(function (acc, mediaType) {
            acc = acc.concat(adapter.getAllMediaInfoForType(streamInfo, mediaType));
            return acc;
          }, []).reduce(function (acc, mediaInfo) {
            var prts = adapter.getProducerReferenceTimes(streamInfo, mediaInfo);
            prts.forEach(function (prt) {
              var voRepresentations = adapter.getVoRepresentations(mediaInfo);

              if (voRepresentations && voRepresentations.length > 0 && voRepresentations[0].adaptation && voRepresentations[0].segmentInfoType === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].SEGMENT_TEMPLATE) {
                var voRep = voRepresentations[0];
                var d = new Date(prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].WALL_CLOCK_TIME]);
                var wallClockTime = d.getTime() / 1000; // TS 103 285 Clause 10.20.4
                // 1) Calculate PRT0
                // i) take the PRT@presentationTime and subtract any ST@presentationTimeOffset
                // ii) convert this time to seconds by dividing by ST@timescale
                // iii) Add this to start time of period that contains PRT.
                // N.B presentationTimeOffset is already divided by timescale at this point

                var prt0 = wallClockTime - (prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].PRESENTATION_TIME] / voRep[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].TIMESCALE] - voRep[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].PRESENTATION_TIME_OFFSET] + streamInfo.start); // 2) Calculate TO between PRT at the start of MPD timeline and the AST

                var to = astInSeconds - prt0; // 3) Not applicable as liveLatency does not consider ST@availabilityTimeOffset

                acc.push({
                  id: prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_3__["default"].ID],
                  to: to
                });
              }
            });
            return acc;
          }, []);
          timeOffsets = timeOffsets.concat(offsets);
        });
      }

      prftOffsets = timeOffsets;
    } catch (e) {
      logger.error(e);
      prftOffsets = [];
    }
  }

  ;
  /**
   * Calculates offset to apply to live delay as described in TS 103 285 Clause 10.20.4
   * @param {object} sdLatency - service description latency element
   * @returns {number}
   * @private
   */

  function _calculateTimeOffset(sdLatency) {
    var to = 0,
        id;
    var offset = prftOffsets.filter(function (prt) {
      return prt.id === sdLatency.referenceId;
    }); // If only one ProducerReferenceTime to generate one TO, then use that regardless of matching ids

    if (offset.length === 0) {
      to = prftOffsets.length > 0 ? prftOffsets[0].to : 0;
      id = prftOffsets[0].id || NaN;
    } else {
      // If multiple id matches, use the first but this should be invalid
      to = offset[0].to || 0;
      id = offset[0].id || NaN;
    }

    return {
      to: to,
      id: id
    };
  }

  instance = {
    getServiceDescriptionSettings: getServiceDescriptionSettings,
    getProducerReferenceTimeOffsets: getProducerReferenceTimeOffsets,
    calculateProducerReferenceTimeOffsets: calculateProducerReferenceTimeOffsets,
    applyServiceDescription: applyServiceDescription,
    reset: reset,
    setConfig: setConfig
  };
  setup();
  return instance;
}

ServiceDescriptionController.__dashjs_factory_name = 'ServiceDescriptionController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(ServiceDescriptionController));

/***/ }),

/***/ "./src/dash/models/DashManifestModel.js":
/*!**********************************************!*\
  !*** ./src/dash/models/DashManifestModel.js ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _vo_ProducerReferenceTime__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../vo/ProducerReferenceTime */ "./src/dash/vo/ProducerReferenceTime.js");
/* harmony import */ var _vo_ContentSteering__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../vo/ContentSteering */ "./src/dash/vo/ContentSteering.js");
/* harmony import */ var _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../vo/DescriptorType */ "./src/dash/vo/DescriptorType.js");
/* harmony import */ var _streaming_utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../streaming/utils/ObjectUtils */ "./src/streaming/utils/ObjectUtils.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _streaming_vo_DashJSError__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../../streaming/vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _streaming_thumbnail_ThumbnailTracks__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../../streaming/thumbnail/ThumbnailTracks */ "./src/streaming/thumbnail/ThumbnailTracks.js");
/* harmony import */ var _vo_MpdLocation__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../vo/MpdLocation */ "./src/dash/vo/MpdLocation.js");
/* harmony import */ var _vo_PatchLocation__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../vo/PatchLocation */ "./src/dash/vo/PatchLocation.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 _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.
 */























function DashManifestModel() {
  var instance, logger, errHandler, BASE64;
  var context = this.context;
  var urlUtils = (0,_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_14__["default"])(context).getInstance();

  var isInteger = Number.isInteger || function (value) {
    return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  };

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_16__["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_19__.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 getProducerReferenceTimesForAdaptation(adaptation) {
    var prtArray = adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCERREFERENCETIME_ASARRAY) ? adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCERREFERENCETIME_ASARRAY] : []; // ProducerReferenceTime elements can also be contained in Representations

    var representationsArray = adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION_ASARRAY) ? adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION_ASARRAY] : [];
    representationsArray.forEach(function (rep) {
      if (rep.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCERREFERENCETIME_ASARRAY)) {
        prtArray.push.apply(prtArray, _toConsumableArray(rep[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCERREFERENCETIME_ASARRAY]));
      }
    });
    var prtsForAdaptation = []; // Unlikely to have multiple ProducerReferenceTimes.

    prtArray.forEach(function (prt) {
      var entry = new _vo_ProducerReferenceTime__WEBPACK_IMPORTED_MODULE_10__["default"]();

      if (prt.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID)) {
        entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID] = prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ID];
      } else {
        // Ignore. Missing mandatory attribute
        return;
      }

      if (prt.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].WALL_CLOCK_TIME)) {
        entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].WALL_CLOCK_TIME] = prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].WALL_CLOCK_TIME];
      } else {
        // Ignore. Missing mandatory attribute
        return;
      }

      if (prt.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME)) {
        entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME] = prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRESENTATION_TIME];
      } else {
        // Ignore. Missing mandatory attribute
        return;
      }

      if (prt.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INBAND)) {
        entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INBAND] = prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].INBAND] !== 'false';
      }

      if (prt.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TYPE)) {
        entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TYPE] = prt[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TYPE];
      } // Not interested in other attributes for now
      // UTC element contained must be same as that in the MPD


      prtsForAdaptation.push(entry);
    });
    return prtsForAdaptation;
  }

  function getLanguageForAdaptation(adaptation) {
    var lang = '';

    if (adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG)) {
      lang = adaptation.lang;
    }

    return lang;
  }

  function getViewpointForAdaptation(adaptation) {
    if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VIEWPOINT_ASARRAY) || !adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VIEWPOINT_ASARRAY].length) return [];
    return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].VIEWPOINT_ASARRAY].map(function (viewpoint) {
      var vp = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return vp.init(viewpoint);
    });
  }

  function getRolesForAdaptation(adaptation) {
    if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ROLE_ASARRAY) || !adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ROLE_ASARRAY].length) return [];
    return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ROLE_ASARRAY].map(function (role) {
      var r = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return r.init(role);
    });
  }

  function getAccessibilityForAdaptation(adaptation) {
    if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ACCESSIBILITY_ASARRAY) || !adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ACCESSIBILITY_ASARRAY].length) return [];
    return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ACCESSIBILITY_ASARRAY].map(function (accessibility) {
      var a = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return a.init(accessibility);
    });
  }

  function getAudioChannelConfigurationForAdaptation(adaptation) {
    if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY) || !adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY].length) return [];
    return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY].map(function (audioChanCfg) {
      var acc = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return acc.init(audioChanCfg);
    });
  }

  function getAudioChannelConfigurationForRepresentation(representation) {
    if (!representation || !representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY) || !representation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY].length) return [];
    return representation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].AUDIOCHANNELCONFIGURATION_ASARRAY].map(function (audioChanCfg) {
      var acc = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return acc.init(audioChanCfg);
    });
  }

  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 = (0,_streaming_utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_13__["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 getSegmentAlignment(adaptation) {
    if (adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_ALIGNMENT)) {
      return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_ALIGNMENT] === 'true';
    }

    return false;
  }

  function getSubSegmentAlignment(adaptation) {
    if (adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUB_SEGMENT_ALIGNMENT)) {
      return adaptation[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUB_SEGMENT_ALIGNMENT] === 'true';
    }

    return false;
  }

  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 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_17__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_18__["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;
          } else {
            event.id = null;
          }

          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.__cdata || currentMpdEvent.__text;
          }

          events.push(event);
        }
      }
    }

    return events;
  }

  function getEventStreams(inbandStreams, representation, period) {
    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);
      eventStream.period = period;
    }

    return eventStreams;
  }

  function getEventStreamForAdaptationSet(manifest, adaptation, period) {
    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, period);
  }

  function getEventStreamForRepresentation(manifest, representation, period) {
    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, period);
  }

  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 getContentSteering(manifest) {
    if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_STEERING_AS_ARRAY)) {
      // Only one ContentSteering element is supported on MPD level
      var element = manifest[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_STEERING_AS_ARRAY][0];
      return _createContentSteeringInstance(element);
    }

    return undefined;
  }

  function _createContentSteeringInstance(element) {
    var entry = new _vo_ContentSteering__WEBPACK_IMPORTED_MODULE_11__["default"]();
    entry.serverUrl = element.__text;

    if (element.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DEFAULT_SERVICE_LOCATION)) {
      entry.defaultServiceLocation = element[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].DEFAULT_SERVICE_LOCATION];
      entry.defaultServiceLocationArray = entry.defaultServiceLocation.split(' ');
    }

    if (element.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].QUERY_BEFORE_START)) {
      entry.queryBeforeStart = element[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].QUERY_BEFORE_START].toLowerCase() === 'true';
    }

    if (element.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CLIENT_REQUIREMENT)) {
      entry.clientRequirement = element[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CLIENT_REQUIREMENT].toLowerCase() !== 'false';
    }

    return entry;
  }

  function getLocation(manifest) {
    if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LOCATION_AS_ARRAY)) {
      return manifest[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LOCATION_AS_ARRAY].map(function (entry) {
        var text = entry.__text || entry;
        var serviceLocation = entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_LOCATION) ? entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_LOCATION] : null;
        return new _vo_MpdLocation__WEBPACK_IMPORTED_MODULE_20__["default"](text, serviceLocation);
      });
    }

    return [];
  }

  function getPatchLocation(manifest) {
    if (manifest && manifest.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PATCH_LOCATION_AS_ARRAY)) {
      return manifest[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PATCH_LOCATION_AS_ARRAY].map(function (entry) {
        var text = entry.__text || entry;
        var serviceLocation = entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_LOCATION) ? entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_LOCATION] : null;
        var ttl = entry.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TTL) ? parseFloat(entry[_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].TTL]) * 1000 : NaN;
        return new _vo_PatchLocation__WEBPACK_IMPORTED_MODULE_21__["default"](text, serviceLocation, ttl);
      });
    }

    return [];
  }

  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 = null,
              schemeIdUri = null,
              latency = null,
              playbackRate = null,
              operatingQuality = null,
              operatingBandwidth = null,
              contentSteering = null;

          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: parseInt(sd[prop].target),
                  max: parseInt(sd[prop].max),
                  min: parseInt(sd[prop].min),
                  referenceId: parseInt(sd[prop].referenceId)
                };
              } else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION_PLAYBACK_RATE) {
                playbackRate = {
                  max: parseFloat(sd[prop].max),
                  min: parseFloat(sd[prop].min)
                };
              } else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION_OPERATING_QUALITY) {
                operatingQuality = {
                  mediaType: sd[prop].mediaType,
                  max: parseInt(sd[prop].max),
                  min: parseInt(sd[prop].min),
                  target: parseInt(sd[prop].target),
                  type: sd[prop].type,
                  maxQualityDifference: parseInt(sd[prop].maxQualityDifference)
                };
              } else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SERVICE_DESCRIPTION_OPERATING_BANDWIDTH) {
                operatingBandwidth = {
                  mediaType: sd[prop].mediaType,
                  max: parseInt(sd[prop].max),
                  min: parseInt(sd[prop].min),
                  target: parseInt(sd[prop].target)
                };
              } else if (prop === _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_STEERING) {
                contentSteering = _createContentSteeringInstance(sd[prop]);
              }
            }
          }

          serviceDescriptions.push({
            id: id,
            schemeIdUri: schemeIdUri,
            latency: latency,
            playbackRate: playbackRate,
            operatingQuality: operatingQuality,
            operatingBandwidth: operatingBandwidth,
            contentSteering: contentSteering
          });
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
    }

    return serviceDescriptions;
  }

  function getSupplementalPropertiesForAdaptation(adaptation) {
    var supplementalProperties = {};

    if (adaptation && adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY_ASARRAY)) {
      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 getSupplementalPropertiesAsArrayForAdaptation(adaptation) {
    if (!adaptation || !adaptation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY_ASARRAY) || !adaptation.SupplementalProperty_asArray.length) return [];
    return adaptation.SupplementalProperty_asArray.map(function (supp) {
      var s = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return s.init(supp);
    });
  }

  function getSupplementalPropertiesForRepresentation(representation) {
    var supplementalProperties = {};

    if (representation && representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY_ASARRAY)) {
      var _iterator3 = _createForOfIteratorHelper(representation.SupplementalProperty_asArray),
          _step3;

      try {
        for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
          var sp = _step3.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) {
        _iterator3.e(err);
      } finally {
        _iterator3.f();
      }
    }

    return supplementalProperties;
  }

  function getSupplementalPropertiesAsArrayForRepresentation(representation) {
    if (!representation || !representation.hasOwnProperty(_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SUPPLEMENTAL_PROPERTY_ASARRAY) || !representation.SupplementalProperty_asArray.length) return [];
    return representation.SupplementalProperty_asArray.map(function (supp) {
      var s = new _vo_DescriptorType__WEBPACK_IMPORTED_MODULE_12__["default"]();
      return s.init(supp);
    });
  }

  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,
    getProducerReferenceTimesForAdaptation: getProducerReferenceTimesForAdaptation,
    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,
    getContentSteering: getContentSteering,
    getLocation: getLocation,
    getPatchLocation: getPatchLocation,
    getSuggestedPresentationDelay: getSuggestedPresentationDelay,
    getAvailabilityStartTime: getAvailabilityStartTime,
    getServiceDescriptions: getServiceDescriptions,
    getSegmentAlignment: getSegmentAlignment,
    getSubSegmentAlignment: getSubSegmentAlignment,
    getSupplementalPropertiesForAdaptation: getSupplementalPropertiesForAdaptation,
    getSupplementalPropertiesAsArrayForAdaptation: getSupplementalPropertiesAsArrayForAdaptation,
    getSupplementalPropertiesForRepresentation: getSupplementalPropertiesForRepresentation,
    getSupplementalPropertiesAsArrayForRepresentation: getSupplementalPropertiesAsArrayForRepresentation,
    setConfig: setConfig
  };
  setup();
  return instance;
}

DashManifestModel.__dashjs_factory_name = 'DashManifestModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_15__["default"].getSingletonFactory(DashManifestModel));

/***/ }),

/***/ "./src/dash/models/PatchManifestModel.js":
/*!***********************************************!*\
  !*** ./src/dash/models/PatchManifestModel.js ***!
  \***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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() || xpath.findsTextReplace()) {
        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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _matchers_LangMatcher__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./matchers/LangMatcher */ "./src/dash/parser/matchers/LangMatcher.js");
/* harmony import */ var _maps_RepresentationBaseValuesMap__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./maps/RepresentationBaseValuesMap */ "./src/dash/parser/maps/RepresentationBaseValuesMap.js");
/* harmony import */ var _maps_SegmentValuesMap__WEBPACK_IMPORTED_MODULE_9__ = __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_LangMatcher__WEBPACK_IMPORTED_MODULE_7__["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 = (0,_objectiron__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
      adaptationset: new _maps_RepresentationBaseValuesMap__WEBPACK_IMPORTED_MODULE_8__["default"](),
      period: new _maps_SegmentValuesMap__WEBPACK_IMPORTED_MODULE_9__["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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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"].ESSENTIAL_PROPERTY + '_asArray', _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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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/LangMatcher.js":
/*!*************************************************!*\
  !*** ./src/dash/parser/matchers/LangMatcher.js ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var bcp_47_normalize__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! bcp-47-normalize */ "./node_modules/bcp-47-normalize/index.js");
/* harmony import */ var bcp_47_normalize__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(bcp_47_normalize__WEBPACK_IMPORTED_MODULE_2__);
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 any ISO 639 language tag to BCP-47 language tags
 */




var LangMatcher = /*#__PURE__*/function (_BaseMatcher) {
  _inherits(LangMatcher, _BaseMatcher);

  var _super = _createSuper(LangMatcher);

  function LangMatcher() {
    _classCallCheck(this, LangMatcher);

    return _super.call(this, function (attr, nodeName) {
      var _stringAttrsInElement;

      var stringAttrsInElements = (_stringAttrsInElement = {}, _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].ADAPTATION_SET, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].REPRESENTATION, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].CONTENT_COMPONENT, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LABEL, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG]), _defineProperty(_stringAttrsInElement, _constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].GROUP_LABEL, [_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].LANG]), _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) {
      var lang = bcp_47_normalize__WEBPACK_IMPORTED_MODULE_2___default()(str);

      if (lang !== undefined) {
        return lang;
      }

      return String(str);
    });
  }

  return LangMatcher;
}(_BaseMatcher__WEBPACK_IMPORTED_MODULE_0__["default"]);

/* harmony default export */ __webpack_exports__["default"] = (LangMatcher);

/***/ }),

/***/ "./src/dash/parser/matchers/NumericMatcher.js":
/*!****************************************************!*\
  !*** ./src/dash/parser/matchers/NumericMatcher.js ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \***********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": function() { return /* binding */ Round10; }
/* harmony export */ });
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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "getIndexBasedSegment": function() { return /* binding */ getIndexBasedSegment; },
/* harmony export */   "getTimeBasedSegment": function() { return /* binding */ getTimeBasedSegment; },
/* harmony export */   "replaceIDForTemplate": function() { return /* binding */ replaceIDForTemplate; },
/* harmony export */   "replaceTokenForTemplate": function() { return /* binding */ replaceTokenForTemplate; },
/* harmony export */   "unescapeDollarsInTemplate": function() { return /* binding */ unescapeDollarsInTemplate; }
/* harmony export */ });
/* 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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__.replaceTokenForTemplate)(url, 'Number', seg.replacementNumber);
      url = (0,_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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
  var settings = (0,_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 = (0,_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 base = representation.SegmentTemplate || representation.SegmentList;
    var timeline = base.SegmentTimeline;
    var timescale = base.timescale;
    var segments = timeline.S_asArray;
    var range = {
      start: 0,
      end: 0
    };
    var segmentTime = segments[0].t;
    var hasValidSegmentTime = !isNaN(segmentTime);
    var enhancedSegmentTime = hasValidSegmentTime ? segmentTime : 0;
    var d = 0;
    var segment, repeat, i, len;

    if (hasValidSegmentTime) {
      range.start = calcPresentationTimeFromMediaTime(enhancedSegmentTime / 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 * (1 + repeat);
    }

    range.end = calcPresentationTimeFromMediaTime((enhancedSegmentTime + d) / timescale, voRepresentation);
    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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 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;
      } // 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, time / fTimescale);
      }

      for (j = 0; j <= repeat && !breakIterator; j++) {
        relativeIdx++;
        breakIterator = iterFunc(time, base, list, frag, fTimescale, relativeIdx, i);

        if (breakIterator) {
          representation.segmentDuration = frag.d / fTimescale;
        }

        time += frag.d;
      }
    }
  }

  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, 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 = (0,_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__.getTimeBasedSegment)(timelineConverter, isDynamic, representation, time, frag.d, fTimescale, media, mediaRange, relativeIdx, frag.tManifest);
        return true;
      } else if (time >= lastSegmentTime * fTimescale - frag.d * 0.5) {
        // same logic, if deviation is
        // 50% of segment duration, segment is found if time 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, 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.
      var scaledMediaTime = precisionRound(requiredMediaTime * fTimescale);

      if (scaledMediaTime < time + frag.d && scaledMediaTime >= time) {
        var media = base.media;
        var mediaRange = frag.mediaRange;

        if (list) {
          media = list[i].media || '';
          mediaRange = list[i].mediaRange;
        }

        segment = (0,_SegmentsUtils__WEBPACK_IMPORTED_MODULE_2__.getTimeBasedSegment)(timelineConverter, isDynamic, representation, time, frag.d, fTimescale, media, mediaRange, relativeIdx, frag.tManifest);
        return true;
      }

      return false;
    });
    return segment;
  }

  function precisionRound(number) {
    return parseFloat(number.toPrecision(15));
  }

  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 ***!
  \**************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;
  this.queryParams = {}; // This is an attribute that might be set when synthesizing BaseURLs with content steering

  /* 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/ContentSteering.js":
/*!****************************************!*\
  !*** ./src/dash/vo/ContentSteering.js ***!
  \****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ContentSteering = function ContentSteering() {
  _classCallCheck(this, ContentSteering);

  this.defaultServiceLocation = null;
  this.defaultServiceLocationArray = [];
  this.queryBeforeStart = false;
  this.serverUrl = null;
  this.clientRequirement = true;
};

/* harmony default export */ __webpack_exports__["default"] = (ContentSteering);

/***/ }),

/***/ "./src/dash/vo/ContentSteeringRequest.js":
/*!***********************************************!*\
  !*** ./src/dash/vo/ContentSteeringRequest.js ***!
  \***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../streaming/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"); } }

/**
 * 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 ContentSteeringRequest = function ContentSteeringRequest(url) {
  _classCallCheck(this, ContentSteeringRequest);

  this.url = url || null;
  this.type = _streaming_vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_0__.HTTPRequest.CONTENT_STEERING_TYPE;
  this.responseType = 'json';
};

/* harmony default export */ __webpack_exports__["default"] = (ContentSteeringRequest);

/***/ }),

/***/ "./src/dash/vo/ContentSteeringResponse.js":
/*!************************************************!*\
  !*** ./src/dash/vo/ContentSteeringResponse.js ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ContentSteeringResponse = function ContentSteeringResponse() {
  _classCallCheck(this, ContentSteeringResponse);

  this.version = null;
  this.ttl = 300;
  this.reloadUri = null;
  this.pathwayPriority = [];
  this.pathwayClones = [];
};

/* harmony default export */ __webpack_exports__["default"] = (ContentSteeringResponse);

/***/ }),

/***/ "./src/dash/vo/DescriptorType.js":
/*!***************************************!*\
  !*** ./src/dash/vo/DescriptorType.js ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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) 2023, 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 DescriptorType = /*#__PURE__*/function () {
  function DescriptorType() {
    _classCallCheck(this, DescriptorType);

    this.schemeIdUri = null;
    this.value = null;
    this.id = null;
  }

  _createClass(DescriptorType, [{
    key: "init",
    value: function init(data) {
      if (data) {
        this.schemeIdUri = data.schemeIdUri ? data.schemeIdUri : null;
        this.value = data.value ? data.value : null;
        this.id = data.id ? data.id : null;
      }

      return this;
    }
  }]);

  return DescriptorType;
}();

/* harmony default export */ __webpack_exports__["default"] = (DescriptorType);

/***/ }),

/***/ "./src/dash/vo/Event.js":
/*!******************************!*\
  !*** ./src/dash/vo/Event.js ***!
  \******************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.type = '';
  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 ***!
  \************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;
  this.serviceDescriptions = [];
  this.protocol = null;
};

/* harmony default export */ __webpack_exports__["default"] = (ManifestInfo);

/***/ }),

/***/ "./src/dash/vo/MediaInfo.js":
/*!**********************************!*\
  !*** ./src/dash/vo/MediaInfo.js ***!
  \**********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.viewpointsWithSchemeIdUri = null;
  this.accessibility = null;
  this.accessibilitiesWithSchemeIdUri = null;
  this.audioChannelConfiguration = null;
  this.audioChannelConfigurationsWithSchemeIdUri = null;
  this.roles = null;
  this.rolesWithSchemeIdUri = null;
  this.codec = null;
  this.mimeType = null;
  this.contentProtection = null;
  this.isText = false;
  this.KID = null;
  this.bitrateList = null;
  this.isFragmented = null;
  this.isEmbedded = null;
  this.selectionPriority = 1;
  this.supplementalProperties = {};
  this.supplementalPropertiesAsArray = [];
  this.segmentAlignment = false;
  this.subSegmentAlignment = false;
};

/* harmony default export */ __webpack_exports__["default"] = (MediaInfo);

/***/ }),

/***/ "./src/dash/vo/Mpd.js":
/*!****************************!*\
  !*** ./src/dash/vo/Mpd.js ***!
  \****************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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/MpdLocation.js":
/*!************************************!*\
  !*** ./src/dash/vo/MpdLocation.js ***!
  \************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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) 2023, 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 MpdLocation = function MpdLocation(url, serviceLocation) {
  _classCallCheck(this, MpdLocation);

  this.url = url || '';
  this.serviceLocation = serviceLocation || null;
  this.queryParams = {}; // This is an attribute that might be set when synthesizing Locations with content steering
};

/* harmony default export */ __webpack_exports__["default"] = (MpdLocation);

/***/ }),

/***/ "./src/dash/vo/PatchLocation.js":
/*!**************************************!*\
  !*** ./src/dash/vo/PatchLocation.js ***!
  \**************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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) 2023, 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 PatchLocation = function PatchLocation(url, serviceLocation, ttl) {
  _classCallCheck(this, PatchLocation);

  this.url = url || '';
  this.serviceLocation = serviceLocation || null;
  this.ttl = ttl || NaN;
  this.queryParams = {}; // This is an attribute that might be set when synthesizing Locations with content steering
};

/* harmony default export */ __webpack_exports__["default"] = (PatchLocation);

/***/ }),

/***/ "./src/dash/vo/PatchOperation.js":
/*!***************************************!*\
  !*** ./src/dash/vo/PatchOperation.js ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*******************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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/ProducerReferenceTime.js":
/*!**********************************************!*\
  !*** ./src/dash/vo/ProducerReferenceTime.js ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ProducerReferenceTime = function ProducerReferenceTime() {
  _classCallCheck(this, ProducerReferenceTime);

  this.id = null;
  this.inband = false;
  this.type = 'encoder';
  this.applicationScheme = null;
  this.wallClockTime = null;
  this.presentationTime = NaN;
  this.UTCTiming = null;
};

/* harmony default export */ __webpack_exports__["default"] = (ProducerReferenceTime);

/***/ }),

/***/ "./src/dash/vo/Representation.js":
/*!***************************************!*\
  !*** ./src/dash/vo/Representation.js ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;
    this.frameRate = null;
  }

  _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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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: "findsTextReplace",
    value: function findsTextReplace() {
      return this.path[this.path.length - 1].name === 'text()';
    }
  }, {
    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 or a text selector

        if (level !== this.path.length - 1 || !name.startsWith('@') && name !== 'text()') {
          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
        };
      } // for replacing a text node the target is the leaf node, the name is __text
      else if (name === 'text()') {
        return {
          name: '__text',
          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 ***!
  \***********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 settings = config.settings;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
  var urlUtils = (0,_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 = (0,_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"],
      requestTimeout: config.settings.get().streaming.manifestRequestTimeout
    });
    xlinkController = (0,_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.createMssFragmentProcessor();
        mssHandler.registerEvents();
      }

      return parser;
    } else if (data.indexOf('MPD') > -1 || data.indexOf('Patch') > -1) {
      return (0,_dash_parser_DashParser__WEBPACK_IMPORTED_MODULE_12__["default"])(context).create({
        debug: debug
      });
    } else {
      return parser;
    }
  }

  function load(url) {
    var serviceLocation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
    var queryParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
    var requestStartDate = new Date();
    var request = new _vo_TextRequest__WEBPACK_IMPORTED_MODULE_5__["default"](url, _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_7__.HTTPRequest.MPD_TYPE);

    if (serviceLocation) {
      request.serviceLocation = serviceLocation;
    }

    if (queryParams) {
      request.queryParams = queryParams;
    }

    if (!request.requestStartDate) {
      request.requestStartDate = requestStartDate;
    }

    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_9__["default"].MANIFEST_LOADING_STARTED, {
      request: request
    });
    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;
          } // If there is a mismatch between the manifest's specified duration and the total duration of all periods,
          // and the specified duration is greater than the total duration of all periods,
          // overwrite the manifest's duration attribute. This is a patch for if a manifest is generated incorrectly.


          if (settings && settings.get().streaming.enableManifestDurationMismatchFix && manifest.mediaPresentationDuration && manifest.Period_asArray.length > 1) {
            var sumPeriodDurations = manifest.Period_asArray.reduce(function (totalDuration, period) {
              return totalDuration + period.duration;
            }, 0);

            if (!isNaN(sumPeriodDurations) && manifest.mediaPresentationDuration > sumPeriodDurations) {
              logger.warn('Media presentation duration greater than duration of all periods. Setting duration to total period duration');
              manifest.mediaPresentationDuration = sumPeriodDurations;
            }
          }

          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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _utils_LocationSelector__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./utils/LocationSelector */ "./src/streaming/utils/LocationSelector.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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
  var urlUtils = (0,_utils_URLUtils__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
  var instance, logger, refreshDelay, refreshTimer, isPaused, isStopped, isUpdating, manifestLoader, manifestModel, locationSelector, adapter, errHandler, contentSteeringController, settings;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance().getLogger(instance);
    locationSelector = (0,_utils_LocationSelector__WEBPACK_IMPORTED_MODULE_8__["default"])(context).create();
  }

  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.locationSelector) {
      locationSelector = config.locationSelector;
    }

    if (config.settings) {
      settings = config.settings;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }
  }

  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 serviceLocation = null;
    var availablePatchLocations = adapter.getPatchLocation(manifest);
    var patchLocation = locationSelector.select(availablePatchLocations);
    var queryParams = null;

    if (patchLocation && !ignorePatch) {
      url = patchLocation.url;
      serviceLocation = patchLocation.serviceLocation;
      queryParams = patchLocation.queryParams;
    } else {
      var availableMpdLocations = _getAvailableMpdLocations(manifest);

      var mpdLocation = locationSelector.select(availableMpdLocations);

      if (mpdLocation) {
        url = mpdLocation.url;
        serviceLocation = mpdLocation.serviceLocation;
        queryParams = mpdLocation.queryParams;
      }
    } // if one of the alternatives was relative, convert to absolute


    if (urlUtils.isRelative(url)) {
      url = urlUtils.resolve(url, manifest.url);
    }

    manifestLoader.load(url, serviceLocation, queryParams);
  }

  function _getAvailableMpdLocations(manifest) {
    var manifestLocations = adapter.getLocation(manifest);
    var synthesizedElements = contentSteeringController.getSynthesizedLocationElements(manifestLocations);
    return manifestLocations.concat(synthesizedElements);
  }

  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() {
    isPaused = false;
    startManifestRefreshTimer();
  }

  function onPlaybackPaused() {
    isPaused = !settings.get().streaming.scheduling.scheduleWhilePaused;

    if (isPaused) {
      stopManifestRefreshTimer();
    }
  }

  function onStreamsComposed() {
    // 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 ***!
  \**************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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_CatchupController__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./controllers/CatchupController */ "./src/streaming/controllers/CatchupController.js");
/* harmony import */ var _dash_controllers_ServiceDescriptionController__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../dash/controllers/ServiceDescriptionController */ "./src/dash/controllers/ServiceDescriptionController.js");
/* harmony import */ var _dash_controllers_ContentSteeringController__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../dash/controllers/ContentSteeringController */ "./src/dash/controllers/ContentSteeringController.js");
/* harmony import */ var _controllers_MediaController__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./controllers/MediaController */ "./src/streaming/controllers/MediaController.js");
/* harmony import */ var _controllers_BaseURLController__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./controllers/BaseURLController */ "./src/streaming/controllers/BaseURLController.js");
/* harmony import */ var _ManifestLoader__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./ManifestLoader */ "./src/streaming/ManifestLoader.js");
/* harmony import */ var _utils_ErrorHandler__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./utils/ErrorHandler */ "./src/streaming/utils/ErrorHandler.js");
/* harmony import */ var _utils_Capabilities__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./utils/Capabilities */ "./src/streaming/utils/Capabilities.js");
/* harmony import */ var _utils_CapabilitiesFilter__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./utils/CapabilitiesFilter */ "./src/streaming/utils/CapabilitiesFilter.js");
/* harmony import */ var _utils_RequestModifier__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./utils/RequestModifier */ "./src/streaming/utils/RequestModifier.js");
/* harmony import */ var _models_URIFragmentModel__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./models/URIFragmentModel */ "./src/streaming/models/URIFragmentModel.js");
/* harmony import */ var _models_ManifestModel__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./models/ManifestModel */ "./src/streaming/models/ManifestModel.js");
/* harmony import */ var _models_MediaPlayerModel__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./models/MediaPlayerModel */ "./src/streaming/models/MediaPlayerModel.js");
/* harmony import */ var _controllers_AbrController__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./controllers/AbrController */ "./src/streaming/controllers/AbrController.js");
/* harmony import */ var _net_SchemeLoaderFactory__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./net/SchemeLoaderFactory */ "./src/streaming/net/SchemeLoaderFactory.js");
/* harmony import */ var _models_VideoModel__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./models/VideoModel */ "./src/streaming/models/VideoModel.js");
/* harmony import */ var _models_CmcdModel__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./models/CmcdModel */ "./src/streaming/models/CmcdModel.js");
/* harmony import */ var _models_CmsdModel__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./models/CmsdModel */ "./src/streaming/models/CmsdModel.js");
/* harmony import */ var _utils_DOMStorage__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ./utils/DOMStorage */ "./src/streaming/utils/DOMStorage.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ./../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ./../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ./../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ./../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ./MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _core_Version__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ../core/Version */ "./src/core/Version.js");
/* harmony import */ var _dash_controllers_SegmentBaseController__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ../dash/controllers/SegmentBaseController */ "./src/dash/controllers/SegmentBaseController.js");
/* harmony import */ var _dash_DashAdapter__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ../dash/DashAdapter */ "./src/dash/DashAdapter.js");
/* harmony import */ var _dash_DashMetrics__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! ../dash/DashMetrics */ "./src/dash/DashMetrics.js");
/* harmony import */ var _dash_utils_TimelineConverter__WEBPACK_IMPORTED_MODULE_37__ = __webpack_require__(/*! ../dash/utils/TimelineConverter */ "./src/dash/utils/TimelineConverter.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_38__ = __webpack_require__(/*! ./vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _externals_base64__WEBPACK_IMPORTED_MODULE_39__ = __webpack_require__(/*! ../../externals/base64 */ "./externals/base64.js");
/* harmony import */ var codem_isoboxer__WEBPACK_IMPORTED_MODULE_40__ = __webpack_require__(/*! codem-isoboxer */ "./node_modules/codem-isoboxer/dist/iso_boxer.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_41__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_42__ = __webpack_require__(/*! ./utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/* harmony import */ var _ManifestUpdater__WEBPACK_IMPORTED_MODULE_43__ = __webpack_require__(/*! ./ManifestUpdater */ "./src/streaming/ManifestUpdater.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_44__ = __webpack_require__(/*! ../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.js");
/* harmony import */ var _utils_BoxParser__WEBPACK_IMPORTED_MODULE_45__ = __webpack_require__(/*! ./utils/BoxParser */ "./src/streaming/utils/BoxParser.js");
/* harmony import */ var _text_TextController__WEBPACK_IMPORTED_MODULE_46__ = __webpack_require__(/*! ./text/TextController */ "./src/streaming/text/TextController.js");
/* harmony import */ var _models_CustomParametersModel__WEBPACK_IMPORTED_MODULE_47__ = __webpack_require__(/*! ./models/CustomParametersModel */ "./src/streaming/models/CustomParametersModel.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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_28__["default"])(context).getInstance();
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_32__["default"])(context).getInstance();
  var debug = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_26__["default"])(context).getInstance({
    settings: settings
  });
  var instance, logger, source, protectionData, mediaPlayerInitialized, streamingInitialized, playbackInitialized, autoPlay, providedStartTime, abrController, schemeLoaderFactory, timelineConverter, mediaController, protectionController, metricsReportingController, mssHandler, offlineController, adapter, mediaPlayerModel, customParametersModel, errHandler, baseURLController, capabilities, capabilitiesFilter, streamController, textController, gapController, playbackController, serviceDescriptionController, contentSteeringController, catchupController, dashMetrics, manifestModel, cmcdModel, cmsdModel, videoModel, uriFragmentModel, domStorage, segmentBaseController;
  /*
  ---------------------------------------------------------------------------
       INIT FUNCTIONS
   ---------------------------------------------------------------------------
  */

  function setup() {
    logger = debug.getLogger(instance);
    mediaPlayerInitialized = false;
    playbackInitialized = false;
    streamingInitialized = false;
    autoPlay = true;
    providedStartTime = NaN;
    protectionController = null;
    offlineController = null;
    protectionData = null;
    adapter = null;
    segmentBaseController = null;
    _core_events_Events__WEBPACK_IMPORTED_MODULE_29__["default"].extend(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_30__["default"]);
    mediaPlayerModel = (0,_models_MediaPlayerModel__WEBPACK_IMPORTED_MODULE_19__["default"])(context).getInstance();
    customParametersModel = (0,_models_CustomParametersModel__WEBPACK_IMPORTED_MODULE_47__["default"])(context).getInstance();
    videoModel = (0,_models_VideoModel__WEBPACK_IMPORTED_MODULE_22__["default"])(context).getInstance();
    uriFragmentModel = (0,_models_URIFragmentModel__WEBPACK_IMPORTED_MODULE_17__["default"])(context).getInstance();
  }
  /**
   * 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.serviceDescriptionController) {
      serviceDescriptionController = config.serviceDescriptionController;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }

    if (config.catchupController) {
      catchupController = config.catchupController;
    }

    if (config.mediaPlayerModel) {
      mediaPlayerModel = config.mediaPlayerModel;
    }

    if (config.customParametersModel) {
      customParametersModel = config.customParametersModel;
    }

    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()}
   * @param {number|string} startTime - For VoD content the start time is relative to the start time of the first period.
   * For live content
   * If the parameter starts from prefix posix: it signifies the absolute time range defined in seconds of Coordinated Universal Time (ITU-R TF.460-6). This is the number of seconds since 01-01-1970 00:00:00 UTC. Fractions of seconds may be optionally specified down to the millisecond level.
   * If no posix prefix is used the starttime is relative to MPD@availabilityStartTime
   * @see {@link module:MediaPlayer#attachSource attachSource()}
   * @see {@link module:MediaPlayer#setAutoPlay setAutoPlay()}
   * @memberof module:MediaPlayer
   * @instance
   */


  function initialize(view, source, autoPlay) {
    var startTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : NaN;

    if (!capabilities) {
      capabilities = (0,_utils_Capabilities__WEBPACK_IMPORTED_MODULE_14__["default"])(context).getInstance();
      capabilities.setConfig({
        settings: settings
      });
    }

    if (!errHandler) {
      errHandler = (0,_utils_ErrorHandler__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance();
    }

    if (!capabilities.supportsMediaSource()) {
      errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_41__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"].CAPABILITY_MEDIASOURCE_ERROR_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"].CAPABILITY_MEDIASOURCE_ERROR_MESSAGE));
      return;
    }

    if (!mediaPlayerInitialized) {
      mediaPlayerInitialized = true; // init some controllers and models

      timelineConverter = (0,_dash_utils_TimelineConverter__WEBPACK_IMPORTED_MODULE_37__["default"])(context).getInstance();

      if (!abrController) {
        abrController = (0,_controllers_AbrController__WEBPACK_IMPORTED_MODULE_20__["default"])(context).getInstance();
        abrController.setConfig({
          settings: settings
        });
      }

      if (!schemeLoaderFactory) {
        schemeLoaderFactory = (0,_net_SchemeLoaderFactory__WEBPACK_IMPORTED_MODULE_21__["default"])(context).getInstance();
      }

      if (!playbackController) {
        playbackController = (0,_controllers_PlaybackController__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
      }

      if (!mediaController) {
        mediaController = (0,_controllers_MediaController__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
      }

      if (!streamController) {
        streamController = (0,_controllers_StreamController__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
      }

      if (!gapController) {
        gapController = (0,_controllers_GapController__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
      }

      if (!catchupController) {
        catchupController = (0,_controllers_CatchupController__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
      }

      if (!serviceDescriptionController) {
        serviceDescriptionController = (0,_dash_controllers_ServiceDescriptionController__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance();
      }

      if (!contentSteeringController) {
        contentSteeringController = (0,_dash_controllers_ContentSteeringController__WEBPACK_IMPORTED_MODULE_9__["default"])(context).getInstance();
      }

      if (!capabilitiesFilter) {
        capabilitiesFilter = (0,_utils_CapabilitiesFilter__WEBPACK_IMPORTED_MODULE_15__["default"])(context).getInstance();
      }

      adapter = (0,_dash_DashAdapter__WEBPACK_IMPORTED_MODULE_35__["default"])(context).getInstance();
      manifestModel = (0,_models_ManifestModel__WEBPACK_IMPORTED_MODULE_18__["default"])(context).getInstance();
      cmcdModel = (0,_models_CmcdModel__WEBPACK_IMPORTED_MODULE_23__["default"])(context).getInstance();
      cmsdModel = (0,_models_CmsdModel__WEBPACK_IMPORTED_MODULE_24__["default"])(context).getInstance();
      dashMetrics = (0,_dash_DashMetrics__WEBPACK_IMPORTED_MODULE_36__["default"])(context).getInstance({
        settings: settings
      });
      domStorage = (0,_utils_DOMStorage__WEBPACK_IMPORTED_MODULE_25__["default"])(context).getInstance({
        settings: settings
      });
      adapter.setConfig({
        constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
        cea608parser: (_externals_cea608_parser__WEBPACK_IMPORTED_MODULE_0___default()),
        errHandler: errHandler,
        BASE64: _externals_base64__WEBPACK_IMPORTED_MODULE_39__
      });

      if (!baseURLController) {
        baseURLController = (0,_controllers_BaseURLController__WEBPACK_IMPORTED_MODULE_11__["default"])(context).create();
      }

      baseURLController.setConfig({
        adapter: adapter,
        contentSteeringController: contentSteeringController
      });
      serviceDescriptionController.setConfig({
        adapter: adapter
      });

      if (!segmentBaseController) {
        segmentBaseController = (0,_dash_controllers_SegmentBaseController__WEBPACK_IMPORTED_MODULE_34__["default"])(context).getInstance({
          dashMetrics: dashMetrics,
          mediaPlayerModel: mediaPlayerModel,
          errHandler: errHandler,
          baseURLController: baseURLController,
          events: _core_events_Events__WEBPACK_IMPORTED_MODULE_29__["default"],
          eventBus: eventBus,
          debug: debug,
          boxParser: (0,_utils_BoxParser__WEBPACK_IMPORTED_MODULE_45__["default"])(context).getInstance(),
          requestModifier: (0,_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_16__["default"])(context).getInstance(),
          errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"]
        });
      } // configure controllers


      mediaController.setConfig({
        domStorage: domStorage,
        settings: settings,
        customParametersModel: customParametersModel
      });
      mediaPlayerModel.setConfig({
        playbackController: playbackController,
        serviceDescriptionController: serviceDescriptionController
      });
      contentSteeringController.setConfig({
        adapter: adapter,
        errHandler: errHandler,
        dashMetrics: dashMetrics,
        mediaPlayerModel: mediaPlayerModel,
        manifestModel: manifestModel,
        serviceDescriptionController: serviceDescriptionController,
        eventBus: eventBus,
        requestModifier: (0,_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_16__["default"])(context).getInstance()
      });
      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, startTime);
    }

    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;
    }

    if (customParametersModel) {
      customParametersModel.reset();
    }

    settings.reset();

    if (offlineController) {
      offlineController.reset();
      offlineController = null;
    }
  }
  /**
   * Completely destroys the media player and frees all memory.
   *
   * @memberof module:MediaPlayer
   * @instance
   */


  function destroy() {
    reset();
    _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_31__["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 (0,_core_Version__WEBPACK_IMPORTED_MODULE_33__.getVersionString)();
  }
  /**
   * Use this method to access the dash.js logging class.
   *
   * @returns {Debug}
   * @memberof module:MediaPlayer
   * @instance
   */


  function getDebug() {
    return debug;
  }
  /*
  ---------------------------------------------------------------------------
       PLAYBACK FUNCTIONS
   ---------------------------------------------------------------------------
  */

  /**
   * Causes the player to begin streaming the media as set by the {@link module:MediaPlayer#attachSource attachSource()}
   * method in preparation for playing. It specifically does not require a view to be attached with {@link module:MediaPlayer#attachSource attachView()} to begin preloading.
   * When a view is attached after preloading, the buffered data is transferred to the attached mediaSource buffers.
   *
   * @see {@link module:MediaPlayer#attachSource attachSource()}
   * @see {@link module:MediaPlayer#attachView attachView()}
   * @memberof module:MediaPlayer
   * @throws {@link module:MediaPlayer~SOURCE_NOT_ATTACHED_ERROR SOURCE_NOT_ATTACHED_ERROR} if called before attachSource function
   * @instance
   */


  function preload() {
    if (videoModel.getElement() || streamingInitialized) {
      return;
    }

    if (source) {
      _initializePlayback(providedStartTime);
    } else {
      throw SOURCE_NOT_ATTACHED_ERROR;
    }
  }
  /**
   * 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(true);
    }
  }
  /**
   * 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.
   * For dynamic streams duration() returns DVRWindow.end - DVRWindow.start. Consequently, the value provided to this function should be relative to DVRWindow.start.
   * @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;
    }

    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_42__.checkParameterType)(value, 'number');

    if (isNaN(value)) {
      throw _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"].BAD_ARGUMENT_ERROR;
    }

    if (value < 0) {
      value = 0;
    }

    var s = playbackController.getIsDynamic() ? getDVRSeekOffset(value) : value; // For VoD limit the seek to the duration of the content

    var videoElement = getVideoElement();

    if (!playbackController.getIsDynamic() && videoElement.duration) {
      s = Math.min(videoElement.duration, s);
    }

    playbackController.seek(s, false, false, true);
  }
  /**
   * Seeks back to the original live edge (live edge as calculated at playback start). Only applies to live streams, for VoD streams this call will be ignored.
   */


  function seekToOriginalLive() {
    if (!playbackInitialized || !isDynamic()) {
      return;
    }

    playbackController.seekToOriginalLive();
  }
  /**
   * 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();
  }
  /**
   * Returns a boolean that indicates whether the player is operating in low latency mode.
   * @return {boolean}
   * @memberof module:MediaPlayer
   * @instance
   */


  function getLowLatencyModeEnabled() {
    if (!playbackInitialized) {
      throw PLAYBACK_NOT_INITIALIZED_ERROR;
    }

    return playbackController.getLowLatencyModeEnabled();
  }
  /**
   * 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) {
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_42__.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.getOriginalLiveDelay();
    var val = metric.range.start + value;

    if (val > metric.range.end - liveDelay) {
      val = metric.range.end - liveDelay;
    }

    return val;
  }
  /**
   * Returns the target live delay
   * @returns {number} The target live delay
   * @memberof module:MediaPlayer
   * @instance
   */


  function getTargetLiveDelay() {
    if (!playbackInitialized) {
      throw PLAYBACK_NOT_INITIALIZED_ERROR;
    }

    return playbackController.getOriginalLiveDelay();
  }
  /**
   * 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) {
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_42__.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) {
    customParametersModel.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) {
    customParametersModel.removeAbrCustomRule(rulename);
  }
  /**
   * Remove all ABR custom rules
   * @memberof module:MediaPlayer
   * @instance
   */


  function removeAllABRCustomRule() {
    customParametersModel.removeAllAbrCustomRule();
  }
  /**
   * Returns all ABR custom rules
   * @return {Array}
   */


  function getABRCustomRules() {
    return customParametersModel.getAbrCustomRules();
  }
  /**
   * <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) {
    customParametersModel.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) {
    customParametersModel.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() {
    customParametersModel.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() {
    customParametersModel.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) {
    customParametersModel.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 customParametersModel.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(providedStartTime);
      }
    }

    if (playbackInitialized) {
      //Reset if we have been playing before, so this is a new element.
      _resetPlaybackControllers();
    }

    _initializePlayback(providedStartTime);
  }
  /**
   * 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);
  }

  function attachVttRenderingDiv(div) {
    if (!videoModel.getElement()) {
      throw ELEMENT_NOT_ATTACHED_ERROR;
    }

    videoModel.setVttRenderingDiv(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 primitive, a string object, or a RegExp object 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}
   * @param {boolean} [noSettingsSave] - specify if settings from the track must not be saved for incoming track selection
   * @memberof module:MediaPlayer
   * @throws {@link module:MediaPlayer~STREAMING_NOT_INITIALIZED_ERROR STREAMING_NOT_INITIALIZED_ERROR} if called before initializePlayback function
   * @instance
   */


  function setCurrentTrack(track) {
    var noSettingsSave = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

    if (!streamingInitialized) {
      throw STREAMING_NOT_INITIALIZED_ERROR;
    }

    mediaController.setTrack(track, noSettingsSave);
  }
  /*
  ---------------------------------------------------------------------------
       Custom filter and callback functions
   ---------------------------------------------------------------------------
  */

  /**
   * 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) {
    customParametersModel.registerCustomCapabilitiesFilter(filter);
  }
  /**
   * Unregisters a custom capabilities filter.
   * @param {function} filter - the custom capabilities filter callback
   * @memberof module:MediaPlayer
   * @instance
   */


  function unregisterCustomCapabilitiesFilter(filter) {
    customParametersModel.unregisterCustomCapabilitiesFilter(filter);
  }
  /**
   * 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) {
    customParametersModel.setCustomInitialTrackSelectionFunction(customFunc);
  }
  /**
   * Resets the custom initial track selection
   */


  function resetCustomInitialTrackSelectionFunction() {
    customParametersModel.resetCustomInitialTrackSelectionFunction(null);
  }
  /**
   * 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) {
    customParametersModel.registerLicenseRequestFilter(filter);
  }
  /**
   * 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) {
    customParametersModel.registerLicenseResponseFilter(filter);
  }
  /**
   * Unregisters a license request filter.
   * @param {function} filter - the license request filter callback
   * @memberof module:MediaPlayer
   * @instance
   */


  function unregisterLicenseRequestFilter(filter) {
    customParametersModel.unregisterLicenseRequestFilter(filter);
  }
  /**
   * Unregisters a license response filter.
   * @param {function} filter - the license response filter callback
   * @memberof module:MediaPlayer
   * @instance
   */


  function unregisterLicenseResponseFilter(filter) {
    customParametersModel.unregisterLicenseResponseFilter(filter);
  }
  /*
  ---------------------------------------------------------------------------
       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);
    }
  }
  /*
  ---------------------------------------------------------------------------
       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;
    }

    return thumbnailController.provide(s, callback);
  }
  /*
  ---------------------------------------------------------------------------
       TOOLS AND OTHERS FUNCTIONS
   ---------------------------------------------------------------------------
  */

  /**
   * Allows application to retrieve a manifest.  Manifest loading is asynchronous 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_29__["default"].INTERNAL_MANIFEST_LOADED, handler, self);
      manifestLoader.reset();
    };

    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_29__["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;
  }
  /**
   * Sets the source to a new manifest URL or object without reloading
   * Useful for updating CDN tokens
   * @param urlOrManifest
   */


  function updateSource(urlOrManifest) {
    source = urlOrManifest;
    streamController.load(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.
   * @param {number|string} startTime - For VoD content the start time is relative to the start time of the first period.
   * For live content
   * If the parameter starts from prefix posix: it signifies the absolute time range defined in seconds of Coordinated Universal Time (ITU-R TF.460-6). This is the number of seconds since 01-01-1970 00:00:00 UTC. Fractions of seconds may be optionally specified down to the millisecond level.
   * If no posix prefix is used the starttime is relative to MPD@availabilityStartTime
   *
   * @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) {
    var startTime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NaN;

    if (!mediaPlayerInitialized) {
      throw MEDIA_PLAYER_NOT_INITIALIZED_ERROR;
    }

    if (typeof urlOrManifest === 'string') {
      uriFragmentModel.initialize(urlOrManifest);
    }

    if (startTime == null) {
      startTime = NaN;
    }

    if (!isNaN(startTime)) {
      startTime = Math.max(0, startTime);
    }

    providedStartTime = startTime;
    source = urlOrManifest;

    if (streamingInitialized || playbackInitialized) {
      _resetPlaybackControllers();
    }

    if (isReady()) {
      _initializePlayback(providedStartTime);
    }
  }
  /**
   * 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_31__["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;
  }
  /**
   * Triggers a request to the content steering server to update the steering information.
   * @return {Promise<any>}
   */


  function triggerSteeringRequest() {
    if (contentSteeringController) {
      return contentSteeringController.loadSteeringData();
    }
  }
  /**
   * Returns the current response data of the content steering server
   * @return {object}
   */


  function getCurrentSteeringResponseData() {
    if (contentSteeringController) {
      return contentSteeringController.getCurrentSteeringResponseData();
    }
  }
  /**
   * Returns all BaseURLs that are available including synthesized elements (e.g by content steering)
   * @returns {BaseURL[]}
   */


  function getAvailableBaseUrls() {
    var manifest = manifestModel.getValue();

    if (!manifest) {
      return [];
    }

    return baseURLController.getBaseUrls(manifest);
  }
  /**
   * Returns the available location elements including synthesized elements (e.g by content steering)
   * @returns {MpdLocation[]}
   */


  function getAvailableLocations() {
    var manifest = manifestModel.getValue();

    if (!manifest) {
      return [];
    }

    var manifestLocations = adapter.getLocation(manifest);
    var synthesizedElements = contentSteeringController.getSynthesizedLocationElements(manifestLocations);
    return manifestLocations.concat(synthesizedElements);
  } //***********************************
  // PRIVATE METHODS
  //***********************************


  function _resetPlaybackControllers() {
    playbackInitialized = false;
    streamingInitialized = false;
    adapter.reset();
    streamController.reset();
    gapController.reset();
    catchupController.reset();
    playbackController.reset();
    serviceDescriptionController.reset();
    contentSteeringController.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();
    cmsdModel.reset();
  }

  function _createPlaybackControllers() {
    // creates or get objects instances
    var manifestLoader = _createManifestLoader();

    if (!streamController) {
      streamController = (0,_controllers_StreamController__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
    }

    if (!textController) {
      textController = (0,_text_TextController__WEBPACK_IMPORTED_MODULE_46__["default"])(context).create({
        errHandler: errHandler,
        manifestModel: manifestModel,
        adapter: adapter,
        mediaController: mediaController,
        videoModel: videoModel,
        settings: settings
      });
    }

    capabilitiesFilter.setConfig({
      capabilities: capabilities,
      customParametersModel: customParametersModel,
      adapter: adapter,
      settings: settings,
      manifestModel: manifestModel,
      errHandler: errHandler
    });
    streamController.setConfig({
      capabilities: capabilities,
      capabilitiesFilter: capabilitiesFilter,
      manifestLoader: manifestLoader,
      manifestModel: manifestModel,
      mediaPlayerModel: mediaPlayerModel,
      customParametersModel: customParametersModel,
      protectionController: protectionController,
      textController: textController,
      adapter: adapter,
      dashMetrics: dashMetrics,
      errHandler: errHandler,
      timelineConverter: timelineConverter,
      videoModel: videoModel,
      playbackController: playbackController,
      serviceDescriptionController: serviceDescriptionController,
      contentSteeringController: contentSteeringController,
      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,
      serviceDescriptionController: serviceDescriptionController,
      dashMetrics: dashMetrics,
      adapter: adapter,
      videoModel: videoModel,
      timelineConverter: timelineConverter,
      settings: settings
    });
    catchupController.setConfig({
      streamController: streamController,
      playbackController: playbackController,
      mediaPlayerModel: mediaPlayerModel,
      videoModel: videoModel,
      settings: settings
    });
    abrController.setConfig({
      streamController: streamController,
      domStorage: domStorage,
      mediaPlayerModel: mediaPlayerModel,
      customParametersModel: customParametersModel,
      cmsdModel: cmsdModel,
      dashMetrics: dashMetrics,
      adapter: adapter,
      videoModel: videoModel,
      settings: settings
    });
    cmcdModel.setConfig({
      abrController: abrController,
      dashMetrics: dashMetrics,
      playbackController: playbackController
    });
    cmsdModel.setConfig({}); // initializes controller

    abrController.initialize();
    streamController.initialize(autoPlay, protectionData);
    textController.initialize();
    gapController.initialize();
    catchupController.initialize();
    cmcdModel.initialize();
    cmsdModel.initialize();
    contentSteeringController.initialize();
    segmentBaseController.initialize();
  }

  function _createManifestLoader() {
    return (0,_ManifestLoader__WEBPACK_IMPORTED_MODULE_12__["default"])(context).create({
      debug: debug,
      errHandler: errHandler,
      dashMetrics: dashMetrics,
      mediaPlayerModel: mediaPlayerModel,
      requestModifier: (0,_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_16__["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_29__["default"].extend(Protection.events);
      _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_30__["default"].extend(Protection.events, {
        publicOnly: true
      });
      _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"].extend(Protection.errors);

      if (!capabilities) {
        capabilities = (0,_utils_Capabilities__WEBPACK_IMPORTED_MODULE_14__["default"])(context).getInstance();
      }

      protectionController = protection.createProtectionSystem({
        debug: debug,
        errHandler: errHandler,
        videoModel: videoModel,
        customParametersModel: customParametersModel,
        capabilities: capabilities,
        eventBus: eventBus,
        events: _core_events_Events__WEBPACK_IMPORTED_MODULE_29__["default"],
        BASE64: _externals_base64__WEBPACK_IMPORTED_MODULE_39__,
        constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
        cmcdModel: cmcdModel,
        settings: settings
      });
      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,
        mediaPlayerModel: mediaPlayerModel,
        events: _core_events_Events__WEBPACK_IMPORTED_MODULE_29__["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_27__["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_29__["default"],
        constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
        debug: debug,
        initSegmentType: _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_38__.HTTPRequest.INIT_SEGMENT_TYPE,
        BASE64: _externals_base64__WEBPACK_IMPORTED_MODULE_39__,
        ISOBoxer: codem_isoboxer__WEBPACK_IMPORTED_MODULE_40__,
        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_29__["default"].extend(OfflineController.events);
      _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_30__["default"].extend(OfflineController.events, {
        publicOnly: true
      });
      _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"].extend(OfflineController.errors);

      var manifestLoader = _createManifestLoader();

      var manifestUpdater = (0,_ManifestUpdater__WEBPACK_IMPORTED_MODULE_43__["default"])(context).create();
      manifestUpdater.setConfig({
        manifestModel: manifestModel,
        adapter: adapter,
        manifestLoader: manifestLoader,
        errHandler: errHandler,
        contentSteeringController: contentSteeringController
      });
      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_29__["default"],
        errors: _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"],
        constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_1__["default"],
        settings: settings,
        dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_2__["default"],
        urlUtils: (0,_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_44__["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;
  }
  /**
   *
   * @private
   */


  function _initializePlayback() {
    var startTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NaN;

    if (offlineController) {
      offlineController.resetRecords();
    }

    if (!streamingInitialized && source) {
      streamingInitialized = true;
      logger.info('Streaming Initialized');

      _createPlaybackControllers();

      if (typeof source === 'string') {
        streamController.load(source, startTime);
      } else {
        streamController.loadWithManifest(source, startTime);
      }
    }

    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,
    preload: preload,
    play: play,
    isPaused: isPaused,
    pause: pause,
    isSeeking: isSeeking,
    isDynamic: isDynamic,
    getLowLatencyModeEnabled: getLowLatencyModeEnabled,
    seek: seek,
    seekToOriginalLive: seekToOriginalLive,
    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,
    getAvailableBaseUrls: getAvailableBaseUrls,
    getAvailableLocations: getAvailableLocations,
    getTargetLiveDelay: getTargetLiveDelay,
    convertToTimeCode: convertToTimeCode,
    formatUTC: formatUTC,
    getVersion: getVersion,
    getDebug: getDebug,
    getBufferLength: getBufferLength,
    getTTMLRenderingDiv: getTTMLRenderingDiv,
    getVideoElement: getVideoElement,
    getSource: getSource,
    updateSource: updateSource,
    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,
    getABRCustomRules: getABRCustomRules,
    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,
    attachVttRenderingDiv: attachVttRenderingDiv,
    getCurrentTextTrackIndex: getCurrentTextTrackIndex,
    provideThumbnail: provideThumbnail,
    getDashAdapter: getDashAdapter,
    getOfflineController: getOfflineController,
    triggerSteeringRequest: triggerSteeringRequest,
    getCurrentSteeringResponseData: getCurrentSteeringResponseData,
    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_31__["default"].getClassFactory(MediaPlayer);
factory.events = _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_30__["default"];
factory.errors = _core_errors_Errors__WEBPACK_IMPORTED_MODULE_27__["default"];
_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_31__["default"].updateClassFactory(MediaPlayer.__dashjs_factory_name, factory);
/* harmony default export */ __webpack_exports__["default"] = (factory);

/***/ }),

/***/ "./src/streaming/MediaPlayerEvents.js":
/*!********************************************!*\
  !*** ./src/streaming/MediaPlayerEvents.js ***!
  \********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 BaseURLs have been updated.
     * @event MediaPlayerEvents#BASE_URLS_UPDATED
     */

    _this.BASE_URLS_UPDATED = 'baseUrlsUpdated';
    /**
     * 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 started
     * @event MediaPlayerEvents#MANIFEST_LOADING_STARTED
     */

    _this.MANIFEST_LOADING_STARTED = 'manifestLoadingStarted';
    /**
     * Triggered when the manifest loading is finished, providing the request object information
     * @event MediaPlayerEvents#MANIFEST_LOADING_FINISHED
     */

    _this.MANIFEST_LOADING_FINISHED = 'manifestLoadingFinished';
    /**
     * Triggered when the manifest load is complete, providing the payload
     * @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 throughput measurement based on the last segment request has been stored
     * @event MediaPlayerEvents#THROUGHPUT_MEASUREMENT_STORED
     */

    _this.THROUGHPUT_MEASUREMENT_STORED = 'throughputMeasurementStored';
    /**
     * 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 event is fired when the frame at the current playback position of the media has finished loading;
     * often the first frame
     * @event MediaPlayerEvents#PLAYBACK_LOADED_DATA
     */

    _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 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 video element reports that the volume has changed
     * @event MediaPlayerEvents#PLAYBACK_VOLUME_CHANGED
     */

    _this.PLAYBACK_VOLUME_CHANGED = 'playbackVolumeChanged';
    /**
     * 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';
    /**
     * Event that is dispatched whenever an adaptation set is removed due to all representations not being supported.
     * @event MediaPlayerEvents#ADAPTATION_SET_REMOVED_NO_CAPABILITIES
     */

    _this.ADAPTATION_SET_REMOVED_NO_CAPABILITIES = 'adaptationSetRemovedNoCapabilities';
    /**
     * Triggered when a content steering request has completed.
     * @event MediaPlayerEvents#CONTENT_STEERING_REQUEST_COMPLETED
     */

    _this.CONTENT_STEERING_REQUEST_COMPLETED = 'contentSteeringRequestCompleted';
    /**
     * Triggered when an inband prft (ProducerReferenceTime) boxes has been received.
     * @event MediaPlayerEvents#INBAND_PRFT
     */

    _this.INBAND_PRFT = 'inbandPrft';
    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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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/PreBufferSink.js":
/*!****************************************!*\
  !*** ./src/streaming/PreBufferSink.js ***!
  \****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.
 */


/**
 * This is a sink that is used to temporarily hold onto media chunks before a video element is added.
 * The discharge() function is used to get the chunks out of the PreBuffer for adding to a real SourceBuffer.
 *
 * @class PreBufferSink
 * @ignore
 * @implements FragmentSink
 */

function PreBufferSink(onAppendedCallback) {
  var context = this.context;
  var instance, logger, outstandingInit;
  var chunks = [];
  var onAppended = onAppendedCallback;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
  }

  function reset() {
    chunks = [];
    outstandingInit = null;
    onAppended = null;
  }

  function append(chunk) {
    if (chunk.segmentType !== 'InitializationSegment') {
      //Init segments are stored in the initCache.
      chunks.push(chunk);
      chunks.sort(function (a, b) {
        return a.start - b.start;
      });
      outstandingInit = null;
    } else {
      //We need to hold an init chunk for when a corresponding media segment is being downloaded when the discharge happens.
      outstandingInit = chunk;
    }

    logger.debug('PreBufferSink appended chunk s: ' + chunk.start + '; e: ' + chunk.end);

    if (onAppended) {
      onAppended({
        chunk: chunk
      });
    }

    return Promise.resolve();
  }

  function remove(start, end) {
    chunks = chunks.filter(function (a) {
      return !((isNaN(end) || a.start < end) && (isNaN(start) || a.end > start));
    }); //The opposite of the getChunks predicate.

    return Promise.resolve();
  } //Nothing async, nothing to abort.


  function abort() {
    return Promise.resolve();
  }

  function getAllBufferRanges() {
    var ranges = [];

    for (var i = 0; i < chunks.length; i++) {
      var chunk = chunks[i];

      if (ranges.length === 0 || chunk.start > ranges[ranges.length - 1].end) {
        ranges.push({
          start: chunk.start,
          end: chunk.end
        });
      } else {
        ranges[ranges.length - 1].end = chunk.end;
      }
    } //Implements TimeRanges interface. So acts just like sourceBuffer.buffered.


    var timeranges = {
      start: function start(n) {
        return ranges[n].start;
      },
      end: function end(n) {
        return ranges[n].end;
      }
    };
    Object.defineProperty(timeranges, 'length', {
      get: function get() {
        return ranges.length;
      }
    });
    return timeranges;
  }

  function updateTimestampOffset() {
    return Promise.resolve();
  }

  function getBuffer() {
    return this;
  }
  /**
   * Return the all chunks in the buffer the lie between times start and end.
   * Because a chunk cannot be split, this returns the full chunk if any part of its time lies in the requested range.
   * Chunks are removed from the buffer when they are discharged.
   * @function PreBufferSink#discharge
   * @param {?Number} start The start time from which to discharge from the buffer. If NaN, it is regarded as unbounded.
   * @param {?Number} end The end time from which to discharge from the buffer. If NaN, it is regarded as unbounded.
   * @returns {Array} The set of chunks from the buffer within the time ranges.
   */


  function discharge(start, end) {
    var result = getChunksAt(start, end);

    if (outstandingInit) {
      result.push(outstandingInit);
      outstandingInit = null;
    }

    remove(start, end);
    return result;
  }

  function getChunksAt(start, end) {
    return chunks.filter(function (a) {
      return (isNaN(end) || a.start < end) && (isNaN(start) || a.end > start);
    });
  }

  function waitForUpdateEnd(callback) {
    callback();
  }

  instance = {
    getAllBufferRanges: getAllBufferRanges,
    append: append,
    remove: remove,
    abort: abort,
    discharge: discharge,
    reset: reset,
    updateTimestampOffset: updateTimestampOffset,
    waitForUpdateEnd: waitForUpdateEnd,
    getBuffer: getBuffer
  };
  setup();
  return instance;
}

PreBufferSink.__dashjs_factory_name = 'PreBufferSink';
var factory = _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getClassFactory(PreBufferSink);
/* harmony default export */ __webpack_exports__["default"] = (factory);

/***/ }),

/***/ "./src/streaming/SourceBufferSink.js":
/*!*******************************************!*\
  !*** ./src/streaming/SourceBufferSink.js ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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));

    if (settings.get().streaming.buffer.useChangeTypeForTrackSwitch) {
      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 || codec.indexOf('text/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 ***!
  \*********************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
  var urlUtils = (0,_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 = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
      logger = debug.getLogger(instance);
      resetInitialSettings();
      boxParser = (0,_utils_BoxParser__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
      segmentBlacklistController = (0,_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 = (0,_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);
      });
    });
  }

  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 _initializeMedia(mediaSource, previousBufferSinks) {
    return _commonMediaInitialization(mediaSource, previousBufferSinks);
  }
  /**
   *
   * @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();
      var promises = [];
      MEDIA_TYPES.forEach(function (mediaType) {
        // If we are preloading without a video element we can not start texttrack handling.
        if (!(mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !mediaSource) && (mediaType !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO || !element || element && /^VIDEO$/i.test(element.nodeName))) {
          promises.push(_initializeMediaForType(mediaType, mediaSource));
        }
      });
      Promise.all(promises).then(function () {
        return _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();
        }

        if (mediaSource) {
          // 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);
      });
    });
  }
  /**
   * We call this function if segments have been preloaded without a video element. Once the video element is attached MSE is available
   * @param mediaSource
   * @returns {Promise<unknown>}
   */


  function initializeForTextWithMediaSource(mediaSource) {
    return new Promise(function (resolve, reject) {
      _initializeMediaForType(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, mediaSource).then(function () {
        return createBufferSinkForText();
      }).then(function () {
        textController.createTracks(streamInfo);
        resolve();
      })["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 Promise.resolve();
    }

    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.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 Promise.resolve();
    }

    if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].IMAGE) {
      thumbnailController = (0,_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 Promise.resolve();
    }

    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

      return streamProcessor.selectMediaInfo(type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT || !initialMediaInfo.isEmbedded ? initialMediaInfo : allMediaForType[0]);
    }

    return Promise.resolve();
  }

  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 {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 = (0,_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);
      });
    });
  }

  function createBufferSinkForText() {
    var sp = _getProcessorByType(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT);

    if (sp) {
      return sp.createBufferSinks();
    }

    return Promise.resolve();
  }
  /**
   * 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) {
    return new Promise(function (resolve, reject) {
      var promises = [];

      for (var i = 0; i < streamProcessors.length;) {
        if (_isMediaSupported(streamProcessors[i].getMediaInfo())) {
          promises.push(streamProcessors[i].setMediaSource(mediaSource));
          i++;
        } else {
          streamProcessors[i].reset();
          streamProcessors.splice(i, 1);
        }
      }

      Promise.all(promises).then(function () {
        for (var _i = 0; _i < streamProcessors.length; _i++) {
          //Adding of new tracks to a stream processor isn't guaranteed by the spec after the METADATA_LOADED state
          //so do this after the buffers are created above.
          streamProcessors[_i].dischargePreBuffer();
        }

        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);
        }

        resolve();
      })["catch"](function (e) {
        logger.error(e);
        reject(e);
      });
    });
  }

  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);

      if (events && events.length > 0) {
        eventController.addInlineEvents(events, streamInfo.id);
      }
    }
  }

  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 _i2 = 0; _i2 < ln && streamProcessors[_i2]; _i2++) {
        var type = streamProcessors[_i2].getType();

        var mediaInfo = streamProcessors[_i2].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[_i2].getMediaInfo();

          if (_mediaInfo) {
            protectionController.initializeForMedia(_mediaInfo);
          }
        }
      }

      protectionController.handleKeySystemFromManifest();
    }

    if (error) {
      errHandler.error(error);
    } else if (!isInitialized) {
      isInitialized = true;
      videoModel.waitForReadyState(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_METADATA, function () {
        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, streamInfo.id);
    }
  }

  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()); // Filter out embedded text track before updating media info in  StreamProcessor

        allMediaForType = allMediaForType.filter(function (mediaInfo) {
          return !mediaInfo.isEmbedded;
        }); // 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());
          promises.push(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_asArray && adaptation.Representation_asArray.length > 0 && adaptation.Representation_asArray[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,
    initializeForTextWithMediaSource: initializeForTextWithMediaSource,
    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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _dash_DashHandler__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../dash/DashHandler */ "./src/dash/DashHandler.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _utils_RequestModifier__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./utils/RequestModifier */ "./src/streaming/utils/RequestModifier.js");
/* harmony import */ var _streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../streaming/utils/URLUtils */ "./src/streaming/utils/URLUtils.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");
/* harmony import */ var _utils_TimeUtils__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./utils/TimeUtils */ "./src/streaming/utils/TimeUtils.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 = (0,_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, pendingSwitchToRepresentationInfo;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_16__["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"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, 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);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BYTES_APPENDED_END_FRAGMENT, _onBytesAppended, instance);
  }

  function initialize(mediaSource, hasVideoTrack, isFragmented) {
    segmentsController = (0,_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 = (0,_dash_DashHandler__WEBPACK_IMPORTED_MODULE_13__["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_14__["default"],
      debug: (0,_core_Debug__WEBPACK_IMPORTED_MODULE_16__["default"])(context).getInstance(),
      requestModifier: (0,_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_17__["default"])(context).getInstance(),
      dashConstants: _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"],
      constants: _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"],
      urlUtils: (0,_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_18__["default"])(context).getInstance()
    });
    isDynamic = streamInfo.manifestInfo.isDynamic; // Create/initialize controllers

    dashHandler.initialize(isDynamic);
    abrController.registerStreamType(type, instance);
    representationController = (0,_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_14__["default"],
      isDynamic: isDynamic,
      adapter: adapter,
      segmentsController: segmentsController
    });
    bufferController = _createBufferControllerForType(type, isFragmented);

    if (bufferController) {
      bufferController.initialize(mediaSource);
    }

    scheduleController = (0,_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,
      representationController: representationController,
      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;
    pendingSwitchToRepresentationInfo = null;
  }

  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"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, 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);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].BYTES_APPENDED_END_FRAGMENT, _onBytesAppended, 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
   * @returns {Promise<any>}
   */


  function prepareInnerPeriodPlaybackSeeking(e) {
    return new Promise(function (resolve) {
      // If we seek to a buffered area we can keep requesting where we left before the seek
      // If we seek back then forwards buffering will stop until we are below our buffer goal
      // If we seek forwards then pruneBuffer() will make sure that the bufferToKeep setting is respected
      var hasBufferAtTargetTime = bufferController.hasBufferAtTime(e.seekTime);

      if (hasBufferAtTargetTime) {
        bufferController.pruneBuffer();
        var continuousBufferTime = bufferController.getContinuousBufferTimeForTargetTime(e.seekTime);

        if (_shouldSetBufferingComplete(continuousBufferTime)) {
          bufferController.setIsBufferingCompleted(true);
        }

        resolve();
        return;
      } // 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 continuousBufferTime = 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 (_shouldSetBufferingComplete(continuousBufferTime)) {
          bufferController.setIsBufferingCompleted(true);
          resolve();
        } else {
          var targetTime = isNaN(continuousBufferTime) ? e.seekTime : continuousBufferTime;
          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);
      });
    });
  }

  function _shouldSetBufferingComplete(continuousBufferTime) {
    return !isNaN(continuousBufferTime) && !isNaN(streamInfo.duration) && isFinite(streamInfo.duration) && continuousBufferTime >= streamInfo.start + streamInfo.duration;
  }
  /**
   * 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 {object} e
   * @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 might be 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.
    // For dynamic manifests this can also happen especially if we jump over the gap in the previous period and are using SegmentTimeline and in case there is a positive eptDelta at the beginning of the period we are stuck.

    if (settings.get().streaming.gaps.enableSeekFix && (shouldUseExplicitTimeForRequest || playbackController.getTime() === 0)) {
      var adjustedTime;

      if (!isDynamic) {
        adjustedTime = dashHandler.getValidTimeAheadOfTargetTime(bufferingTime, mediaInfo, representation, settings.get().streaming.gaps.threshold);
      } else if (isDynamic && representation.segmentInfoType === _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].SEGMENT_TIMELINE) {
        // If we find a valid request ahead of the current time then we are in a gap. Segments are only added at the end of the timeline
        adjustedTime = dashHandler.getValidTimeAheadOfTargetTime(bufferingTime, mediaInfo, representation, settings.get().streaming.gaps.threshold);
      }

      if (!isNaN(adjustedTime) && adjustedTime !== bufferingTime) {
        if (playbackController.isSeeking() || playbackController.getTime() === 0) {
          // If we are seeking then playback is stalled. Do a seek to get out of this situation
          logger.warn("Adjusting playback time ".concat(adjustedTime, " because of gap in the manifest. Seeking by ").concat(adjustedTime - bufferingTime));
          playbackController.seek(adjustedTime, false, false);
        } else {
          // If we are not seeking we should still be playing but we cant find anything to buffer. So we adjust the buffering time and leave the gap jump to the GapController
          logger.warn("Adjusting buffering time ".concat(adjustedTime, " because of gap in the manifest. Adjusting time by ").concat(adjustedTime - bufferingTime));
          setExplicitBufferingTime(adjustedTime);

          if (rescheduleIfNoRequest) {
            _noValidRequest();
          }
        }

        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;
    }

    if (dashHandler) {
      var representation = representationController && representationInfo ? representationController.getRepresentationForQuality(representationInfo.quality) : null;

      if (shouldUseExplicitTimeForRequest) {
        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(playbackController.getLowLatencyModeEnabled() ? settings.get().streaming.scheduling.lowLatencyTimeout : settings.get().streaming.scheduling.defaultTimeout);
  }

  function _onDataUpdateCompleted(e) {
    if (!e.error) {
      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);
  }

  function _onBytesAppended(e) {
    logger.debug("Appended bytes for ".concat(e.mediaType, " and stream id ").concat(e.streamId)); // 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 (e.segmentType === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_21__.HTTPRequest.INIT_SEGMENT_TYPE) {
      var lastInitializedQuality = e.quality;
      scheduleController.setLastInitializedQuality(lastInitializedQuality);
      logger.info('[' + type + '] ' + 'lastInitializedRepresentationInfo changed to ' + e.quality);
    }

    if (pendingSwitchToRepresentationInfo) {
      _prepareForDefaultQualitySwitch(pendingSwitchToRepresentationInfo);
    } else {
      scheduleController.startScheduleTimer(0);
    }
  }
  /**
   * 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
   */


  function prepareQualityChange(e) {
    if (pendingSwitchToRepresentationInfo) {
      logger.warning("Canceling queued representation switch to ".concat(pendingSwitchToRepresentationInfo.quality, " for ").concat(type));
    }

    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();
    representationController.prepareQualityChange(newQuality);
    var representationInfo = getRepresentationInfo(newQuality); // If the switch should occur immediately we need to replace existing stuff in the buffer

    if (e.reason && e.reason.forceReplace) {
      _prepareForForceReplacementQualitySwitch(representationInfo);
    } // 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(representationInfo);
    }

    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 _prepareForForceReplacementQualitySwitch(representationInfo) {
    // Abort the current request to avoid inconsistencies and in case a rule such as AbandonRequestRule has forced a quality switch. 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(); // 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.prepareForForceReplacementQualitySwitch(representationInfo).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 * (!isNaN(representationInfo.fragmentDuration) ? representationInfo.fragmentDuration : 1);
    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); // The quality we originally requested was lower than the new quality

      if (request.quality < representationInfo.quality && bufferLevel >= safeBufferLevel && abandonmentState !== _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_2__["default"].ABANDON_LOAD) {
        bufferController.updateBufferTimestampOffset(representationInfo).then(function () {
          // Abort the current request to avoid inconsistencies and in case a rule such as AbandonRequestRule has forced a quality switch. 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
          fragmentModel.abortRequests();
          var targetTime = time + safeBufferLevel;
          setExplicitBufferingTime(targetTime);
          scheduleController.setCheckPlaybackQuality(false);
          scheduleController.startScheduleTimer();
          qualityChangeInProgress = false;
        })["catch"](function () {
          qualityChangeInProgress = false;
        });
      } // If we have buffered a higher quality do not replace anything
      else {
        _prepareForDefaultQualitySwitch(representationInfo);
      }
    } else {
      scheduleController.startScheduleTimer();
      qualityChangeInProgress = false;
    }
  }

  function _prepareForDefaultQualitySwitch(representationInfo) {
    // We are not canceling the current request. Check if there is still an ongoing request.
    // If so we wait for the request to be finished and the media to be appended
    var ongoingRequests = fragmentModel.getRequests({
      state: _models_FragmentModel__WEBPACK_IMPORTED_MODULE_3__["default"].FRAGMENT_MODEL_LOADING
    });

    if (ongoingRequests && ongoingRequests.length > 0) {
      logger.debug('Preparing for default quality switch: Waiting for ongoing segment request to be finished before applying switch.');
      pendingSwitchToRepresentationInfo = representationInfo;
      return;
    }

    bufferController.updateBufferTimestampOffset(representationInfo).then(function () {
      if (mediaInfo.segmentAlignment || mediaInfo.subSegmentAlignment) {
        scheduleController.startScheduleTimer();
      } else {
        _bufferClearedForNonReplacement();
      }

      pendingSwitchToRepresentationInfo = null;
      qualityChangeInProgress = false;
    })["catch"](function () {
      pendingSwitchToRepresentationInfo = null;
      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.getSwitchTrack() && !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 dischargePreBuffer() {
    bufferController.dischargePreBuffer();
  }

  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) {
    return bufferController.setMediaSource(mediaSource, mediaInfo);
  }

  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) {
      (0,_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;
    return dashHandler.getNextSegmentRequestIdempotent(mediaInfo, representation);
  }

  function _onInitFragmentLoaded(e) {
    if (!settings.get().streaming.enableManifestTimescaleMismatchFix) {
      return;
    }

    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 (currentRepresentation && voRepresentation) {
      voRepresentation.timescale = boxParser.getMediaTimescaleFromMoov(bytes);
    }
  }

  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 isoFile; // Check for inband prft on media segment (if enabled)

      if (settings.get().streaming.parseInbandPrft && e.request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_21__.HTTPRequest.MEDIA_SEGMENT_TYPE) {
        isoFile = isoFile ? isoFile : boxParser.parse(bytes);
        var timescale = voRepresentation.timescale;

        var prfts = _handleInbandPrfts(isoFile, timescale);

        if (prfts && prfts.length) {
          eventBus.trigger(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_12__["default"].INBAND_PRFT, {
            data: prfts
          }, {
            streamId: streamInfo.id,
            mediaType: type
          });
        }
      }

      var eventStreamMedia = adapter.getEventsFor(currentRepresentation.mediaInfo, null, streamInfo);
      var eventStreamTrack = adapter.getEventsFor(currentRepresentation, voRepresentation, streamInfo);

      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];
        isoFile = isoFile ? isoFile : boxParser.parse(bytes);

        var events = _handleInbandEvents(isoFile, request, eventStreamMedia, eventStreamTrack);

        eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_11__["default"].INBAND_EVENTS, {
          events: events
        }, {
          streamId: streamInfo.id
        });
      }
    }
  }

  function _handleInbandPrfts(isoFile, timescale) {
    var prftBoxes = isoFile.getBoxes('prft');
    var prfts = [];
    prftBoxes.forEach(function (prft) {
      prfts.push(_parsePrftBox(prft, timescale));
    });
    return prfts;
  }

  function _parsePrftBox(prft, timescale) {
    // Get prft type according to box flags
    var type = 'unknown';

    switch (prft.flags) {
      case 0:
        type = _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCER_REFERENCE_TIME_TYPE.ENCODER;
        break;

      case 16:
        type = _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCER_REFERENCE_TIME_TYPE.APPLICATION;
        break;

      case 24:
        type = _dash_constants_DashConstants__WEBPACK_IMPORTED_MODULE_1__["default"].PRODUCER_REFERENCE_TIME_TYPE.CAPTURED;
        break;

      default:
        break;
    } // Get NPT timestamp according to IETF RFC 5905, relative to 1/1/1900


    var ntpTimestamp = prft.ntp_timestamp_sec * 1000 + prft.ntp_timestamp_frac / Math.pow(2, 32) * 1000;
    ntpTimestamp = (0,_utils_TimeUtils__WEBPACK_IMPORTED_MODULE_22__["default"])(context).getInstance().ntpToUTC(ntpTimestamp);
    var mediaTime = prft.media_time / timescale;
    return {
      type: type,
      ntpTimestamp: ntpTimestamp,
      mediaTime: mediaTime
    };
  }

  function _handleInbandEvents(isoFile, 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 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 continuousBufferTime = bufferController.getContinuousBufferTimeForTargetTime(time);
    var targetTime = isNaN(continuousBufferTime) ? time : continuousBufferTime;
    setExplicitBufferingTime(targetTime);
    scheduleController.startScheduleTimer();
  }

  function _createBufferControllerForType(type, isFragmented) {
    var controller = null;

    if (!type) {
      errHandler.error(new _vo_DashJSError__WEBPACK_IMPORTED_MODULE_15__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_14__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_14__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_MESSAGE + 'not properly defined'));
      return null;
    }

    if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !isFragmented) {
      controller = (0,_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 = (0,_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,
    dischargePreBuffer: dischargePreBuffer,
    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 ***!
  \**************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
  var urlLoader = (0,_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 ***!
  \******************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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} Content Steering
       *  @memberof Constants#
       *  @static
       */

      this.CONTENT_STEERING = 'contentSteering';
      /**
       *  @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.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_DVB_LL_SCHEME = 'urn:dvb:dash:lowlatency:scope:2019';
      this.SUPPLEMENTAL_PROPERTY_DVB_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
      };
      this.FILE_LOADER_TYPES = {
        FETCH: 'fetch_loader',
        XHR: 'xhr_loader'
      };
    }
  }]);

  return Constants;
}();

var constants = new Constants();
/* harmony default export */ __webpack_exports__["default"] = (constants);

/***/ }),

/***/ "./src/streaming/constants/MetricsConstants.js":
/*!*****************************************************!*\
  !*** ./src/streaming/constants/MetricsConstants.js ***!
  \*****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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';
      this.HTTP_REQUEST_DVB_REPORTING_TYPE = 'DVBReporting';
    }
  }]);

  return MetricsConstants;
}();

var constants = new MetricsConstants();
/* harmony default export */ __webpack_exports__["default"] = (constants);

/***/ }),

/***/ "./src/streaming/constants/ProtectionConstants.js":
/*!********************************************************!*\
  !*** ./src/streaming/constants/ProtectionConstants.js ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.PLAYREADY_RECOMMENDATION_KEYSTEM_STRING = 'com.microsoft.playready.recommendation';
      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 ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance();
  var eventBus = (0,_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, customParametersModel, cmsdModel, 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 = (0,_rules_DroppedFramesHistory__WEBPACK_IMPORTED_MODULE_11__["default"])(context).create();
    throughputHistory = (0,_rules_ThroughputHistory__WEBPACK_IMPORTED_MODULE_12__["default"])(context).create({
      settings: settings
    });
    abrRulesCollection = (0,_rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
      dashMetrics: dashMetrics,
      customParametersModel: customParametersModel,
      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] = (0,_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.customParametersModel) {
      customParametersModel = config.customParametersModel;
    }

    if (config.cmsdModel) {
      cmsdModel = config.cmsdModel;
    }

    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 = (0,_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) {
        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 {undefined|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); // Apply maximum suggested bitrate from CMSD headers if enabled 

      if (settings.get().streaming.cmsd.enabled && settings.get().streaming.cmsd.abr.applyMb) {
        idx = _checkCmsdMaxBitrate(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 = mediaPlayerModel.getAbrBitrateParameter('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 = mediaPlayerModel.getAbrBitrateParameter('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 possible index from CMSD model
   * @param type
   * @param streamId
   * @return {number|*}
   */


  function _checkCmsdMaxBitrate(idx, type, streamId) {
    // Check CMSD max suggested bitrate only for video segments
    if (type !== 'video') {
      return idx;
    } // Get max suggested bitrate


    var maxCmsdBitrate = cmsdModel.getMaxBitrate(type);

    if (maxCmsdBitrate < 0) {
      return idx;
    } // Substract audio bitrate


    var audioBitrate = _getBitrateInfoForQuality(streamId, 'audio', getQualityFor('audio', streamId));

    maxCmsdBitrate -= audioBitrate ? audioBitrate.bitrate / 1000 : 0;
    var maxIdx = getQualityForBitrate(streamProcessorDict[streamId][type].getMediaInfo(), maxCmsdBitrate, streamId);
    logger.debug('Stream ID: ' + streamId + ' [' + type + '] Apply max bit rate from CMSD: ' + maxCmsdBitrate);
    return Math.min(idx, maxIdx);
  }
  /**
   * 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_asArray;
    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 = mediaPlayerModel.getAbrBitrateParameter('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_asArray;

        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 = (0,_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);
    (0,_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) {
    try {
      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) + ').');
        }
      }
    } catch (e) {
      logger.error(e);
    }
  }

  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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* 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 BaseURLController() {
  var instance, adapter;
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
  var urlUtils = (0,_utils_URLUtils__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
  var baseURLTreeModel, baseURLSelector, contentSteeringController;

  function onBlackListChanged(e) {
    baseURLTreeModel.invalidateSelectedIndexes(e.entry);
  }

  function setup() {
    baseURLTreeModel = (0,_models_BaseURLTreeModel__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create();
    baseURLSelector = (0,_utils_BaseURLSelector__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create();
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].SERVICE_LOCATION_BASE_URL_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;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }
  }

  function update(manifest) {
    baseURLTreeModel.update(manifest);
    baseURLSelector.chooseSelector(adapter.getIsDVB(manifest));
    eventBus.trigger(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_7__["default"].BASE_URLS_UPDATED, {
      baseUrls: getBaseUrls(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;
        p.queryParams = b.queryParams;
      } 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 getBaseUrls(manifest) {
    return baseURLTreeModel.getBaseUrls(manifest);
  }

  function initialize(data) {
    // report config to baseURLTreeModel and baseURLSelector
    baseURLTreeModel.setConfig({
      adapter: adapter,
      contentSteeringController: contentSteeringController
    });
    update(data);
  }

  instance = {
    reset: reset,
    initialize: initialize,
    resolve: resolve,
    setConfig: setConfig,
    getBaseUrls: getBaseUrls,
    update: update
  };
  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 ***!
  \**********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _PreBufferSink__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../PreBufferSink */ "./src/streaming/PreBufferSink.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 _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 _vo_DashJSError__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../vo/metrics/HTTPRequest */ "./src/streaming/vo/metrics/HTTPRequest.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__ = __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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["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, dischargeBuffer, isPrebuffering, dischargeFragments, bufferState, appendedBytesInfo, wallclockTicked, isPruningInProgress, isQuotaExceeded, initCache, pendingPruningRanges, replacingBuffer, seekTarget;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance().getLogger(instance);
    initCache = (0,_utils_InitCache__WEBPACK_IMPORTED_MODULE_9__["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_6__["default"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].WALLCLOCK_TIME_UPDATED, _onWallclockTimeUpdated, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_PLAYING, _onPlaybackPlaying, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["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
   * @param {object} mediaInfo
   */


  function setMediaSource(value) {
    var mediaInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
    return new Promise(function (resolve, reject) {
      mediaSource = value; // if we have a prebuffer, we should prepare to discharge it, and make a new sourceBuffer ready

      if (sourceBufferSink && mediaInfo && typeof sourceBufferSink.discharge === 'function') {
        dischargeBuffer = sourceBufferSink;
        createBufferSink(mediaInfo).then(function () {
          resolve();
        })["catch"](function (e) {
          reject(e);
        });
      } else {
        resolve();
      }
    });
  }
  /**
   * 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 {Promise<Object>} SourceBufferSink
   */


  function createBufferSink(mediaInfo) {
    var oldBufferSinks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    return new Promise(function (resolve, reject) {
      if (!initCache || !mediaInfo) {
        resolve(null);
        return;
      }

      if (mediaSource) {
        isPrebuffering = false;

        _initializeSinkForMseBuffering(mediaInfo, oldBufferSinks).then(function (sink) {
          resolve(sink);
        })["catch"](function (e) {
          reject(e);
        });
      } else {
        isPrebuffering = true;

        _initializeSinkForPrebuffering().then(function (sink) {
          resolve(sink);
        })["catch"](function (e) {
          reject(e);
        });
      }
    });
  }

  function _initializeSinkForPrebuffering() {
    var _this = this;

    return new Promise(function (resolve, reject) {
      var requiredQuality = abrController.getQualityFor(type, streamInfo.id);
      sourceBufferSink = (0,_PreBufferSink__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create(_onAppended.bind(_this));
      updateBufferTimestampOffset(_getRepresentationInfo(requiredQuality)).then(function () {
        resolve(sourceBufferSink);
      })["catch"](function () {
        reject();
      });
    });
  }

  function _initializeSinkForMseBuffering(mediaInfo, oldBufferSinks) {
    return new Promise(function (resolve, reject) {
      var requiredQuality = abrController.getQualityFor(type, streamInfo.id);
      sourceBufferSink = (0,_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_10__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_11__["default"].MEDIASOURCE_TYPE_UNSUPPORTED_CODE, _core_errors_Errors__WEBPACK_IMPORTED_MODULE_11__["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);
    }
  }

  function dischargePreBuffer() {
    if (sourceBufferSink && dischargeBuffer && typeof dischargeBuffer.discharge === 'function') {
      var ranges = dischargeBuffer.getAllBufferRanges();

      if (ranges.length > 0) {
        var rangeStr = 'Beginning ' + type + 'PreBuffer discharge, adding buffer for:';

        for (var i = 0; i < ranges.length; i++) {
          rangeStr += ' start: ' + ranges.start(i) + ', end: ' + ranges.end(i) + ';';
        }

        logger.debug(rangeStr);
      } else {
        logger.debug('PreBuffer discharge requested, but there were no media segments in the PreBuffer.');
      } //A list of fragments to supress bytesAppended events for. This makes transferring from a prebuffer to a sourcebuffer silent.


      dischargeFragments = [];
      var chunks = dischargeBuffer.discharge();
      var lastInit = null;

      for (var j = 0; j < chunks.length; j++) {
        var chunk = chunks[j];

        if (chunk.segmentType !== _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_12__.HTTPRequest.INIT_SEGMENT_TYPE) {
          var initChunk = initCache.extract(chunk.streamId, chunk.representationId);

          if (initChunk) {
            if (lastInit !== initChunk) {
              dischargeFragments.push(initChunk);
              sourceBufferSink.append(initChunk);
              lastInit = initChunk;
            }
          }
        }

        dischargeFragments.push(chunk);
        sourceBufferSink.append(chunk);
      }

      dischargeBuffer.reset();
      dischargeBuffer = null;
    }
  }
  /**
   * 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
   * @param {object} request
   * @private
   */


  function _appendToBuffer(chunk) {
    var request = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;

    if (!sourceBufferSink) {
      return;
    }

    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_6__["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_6__["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_12__.HTTPRequest.MEDIA_SEGMENT_TYPE) {
      _showBufferRanges(ranges);

      _onPlaybackProgression();

      _adjustSeekTarget();
    }

    var suppressAppendedEvent = false;

    if (dischargeFragments) {
      if (dischargeFragments.indexOf(appendedBytesInfo) > 0) {
        suppressAppendedEvent = true;
      }

      dischargeFragments = null;
    }

    if (appendedBytesInfo && !suppressAppendedEvent) {
      _triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["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) || isPrebuffering) 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 rangeAtCurrenTime = getRangeAt(currentTime, 0);
    var rangeAtSeekTarget = getRangeAt(seekTarget, 0);

    if (rangeAtCurrenTime && rangeAtSeekTarget && rangeAtCurrenTime.start === rangeAtSeekTarget.start) {
      seekTarget = NaN;
      return;
    } // Get buffered range corresponding to the seek target


    var segmentDuration = representationController.getCurrentRepresentation().segmentDuration;
    var 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);
      }
    } 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);
    }
  }

  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 () {
        if (settings.get().streaming.buffer.useChangeTypeForTrackSwitch) {
          return sourceBufferSink.changeType(codec);
        }

        return Promise.resolve();
      }).then(function () {
        return pruneAllSafely();
      }).then(function () {
        setIsBufferingCompleted(false);
        resolve();
      })["catch"](function (e) {
        reject(e);
      });
    });
  }

  function prepareForForceReplacementQualitySwitch(representationInfo) {
    return new Promise(function (resolve, reject) {
      sourceBufferSink.abort().then(function () {
        return updateAppendWindow();
      }).then(function () {
        return pruneAllSafely();
      }).then(function () {
        // In any case we need to update the MSE.timeOffset
        return updateBufferTimestampOffset(representationInfo);
      }).then(function () {
        setIsBufferingCompleted(false);
        resolve();
      })["catch"](function (e) {
        reject(e);
      });
    });
  }

  function prepareForNonReplacementTrackSwitch(codec) {
    return new Promise(function (resolve, reject) {
      updateAppendWindow().then(function () {
        if (settings.get().streaming.buffer.useChangeTypeForTrackSwitch) {
          return sourceBufferSink.changeType(codec);
        }

        return Promise.resolve();
      }).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
    // we keep everything that is within bufferToKeepAhead but only if the buffer is continuous.
    // Otherwise we have gaps once the seek is done which might trigger an unintentional gap jump
    var endOfBuffer = ranges.end(ranges.length - 1) + BUFFER_END_THRESHOLD;
    var continuousBufferTime = getContinuousBufferTimeForTargetTime(targetTime); // This is the maximum range we keep ahead

    var isLongFormContent = streamInfo.manifestInfo.duration >= settings.get().streaming.buffer.longFormContentDurationThreshold;
    var bufferToKeepAhead = isLongFormContent ? settings.get().streaming.buffer.bufferTimeAtTopQualityLongForm : settings.get().streaming.buffer.bufferTimeAtTopQuality; // Define the start time from which we will prune. If there is no continuous range from the targettime we start immediately at the target time
    // Otherwise we set the start point to the end of the continuous range taking the maximum buffer to keep ahead into account

    var rangeStart = !isNaN(continuousBufferTime) ? Math.min(continuousBufferTime, targetTime + bufferToKeepAhead) : targetTime; // Check if we are done buffering, no need to prune then

    if (rangeStart >= ranges.end(ranges.length - 1)) {
      return null;
    } // 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);
    } // Never remove the contiguous range of targetTime in order to avoid flushes & reenqueues when the user doesn't want it


    var avoidCurrentTimeRangePruning = settings.get().streaming.buffer.avoidCurrentTimeRangePruning;

    if (avoidCurrentTimeRangePruning) {
      for (var i = 0; i < ranges.length; i++) {
        if (ranges.start(i) <= targetTime && targetTime <= ranges.end(i) && ranges.start(i) <= rangeStart && rangeStart <= ranges.end(i)) {
          var oldRangeStart = rangeStart;

          if (i + 1 < ranges.length) {
            rangeStart = ranges.start(i + 1);
          } else {
            rangeStart = ranges.end(i) + 1;
          }

          logger.debug('Buffered range [' + ranges.start(i) + ', ' + ranges.end(i) + '] overlaps with targetTime ' + targetTime + ' and range to be pruned [' + oldRangeStart + ', ' + endOfBuffer + '], using [' + rangeStart + ', ' + endOfBuffer + '] instead' + (rangeStart < endOfBuffer ? '' : ' (no actual pruning)'));
          break;
        }
      }
    }

    if (rangeStart < ranges.end(ranges.length - 1)) {
      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 hasBufferAtTime(time) {
    try {
      var ranges = sourceBufferSink.getAllBufferRanges();

      if (!ranges || ranges.length === 0) {
        return false;
      }

      var i = 0;

      while (i < ranges.length) {
        var start = ranges.start(i);
        var end = ranges.end(i);

        if (time >= start && time <= end) {
          return true;
        }

        i += 1;
      }

      return false;
    } catch (e) {
      logger.error(e);
      return false;
    }
  }

  function getRangeAt(time, tolerance) {
    if (!sourceBufferSink) {
      return null;
    }

    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 referenceTime = playbackController.getTime() || 0; // In case we are prebuffering we dont have a current time yet

      if (isPrebuffering) {
        referenceTime = !isNaN(seekTarget) ? seekTarget : 0;
      }

      var tolerance = settings.get().streaming.gaps.jumpGaps && !isNaN(settings.get().streaming.gaps.smallGapLimit) ? settings.get().streaming.gaps.smallGapLimit : NaN;
      bufferLevel = Math.max(getBufferLength(referenceTime, tolerance), 0);

      _triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_LEVEL_UPDATED, {
        mediaType: type,
        bufferLevel: bufferLevel
      });

      checkIfSufficientBuffer();
    }
  }

  function _checkIfBufferingCompleted() {
    var isLastIdxAppended = maxAppendedIndex >= maximumIndex - 1; // Handles 0 and non 0 based request index
    // To avoid rounding error when comparing, the stream time and buffer level only must be within 5 decimal places

    var periodBuffered = playbackController.getTimeToStreamEnd(streamInfo) - bufferLevel < 0.00001;

    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 ((!playbackController.getLowLatencyModeEnabled() && 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 || playbackController.getLowLatencyModeEnabled() && 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_6__["default"].BUFFER_LEVEL_STATE_CHANGED, {
      state: state
    });

    _triggerEvent(state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_1__["default"].BUFFER_LOADED ? _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_LOADED : _core_events_Events__WEBPACK_IMPORTED_MODULE_6__["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);

    if (!sourceBufferSink) {
      return;
    }

    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_6__["default"].SEEK_TARGET, {
        time: e.from
      });
    }

    if (isPruningInProgress) {
      clearNextRange();
    } else {
      if (!replacingBuffer) {
        _updateBufferLevel();
      } else {
        replacingBuffer = false;
      }

      _triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["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) {
    isBufferingCompleted = value;

    if (isBufferingCompleted) {
      _triggerEvent(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["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 NaN;
      }

      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 === targetTime ? NaN : 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;
    isPrebuffering = false;

    if (sourceBufferSink) {
      var tmpSourceBufferSinkToReset = sourceBufferSink;
      sourceBufferSink = null;

      if (!errored && !keepBuffers) {
        tmpSourceBufferSinkToReset.abort().then(function () {
          tmpSourceBufferSinkToReset.reset(keepBuffers);
          tmpSourceBufferSinkToReset = null;
        });
      }
    }

    replacingBuffer = false;
  }

  function reset(errored, keepBuffers) {
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].INIT_FRAGMENT_LOADED, _onInitFragmentLoaded, this);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].MEDIA_FRAGMENT_LOADED, _onMediaFragmentLoaded, this);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_6__["default"].WALLCLOCK_TIME_UPDATED, _onWallclockTimeUpdated, this);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_PLAYING, _onPlaybackPlaying, this);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, this);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, this);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_RATE_CHANGED, _onPlaybackRateChanged, this);
    eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_13__["default"].PLAYBACK_STALLED, _onPlaybackStalled, this);
    resetInitialSettings(errored, keepBuffers);
  }

  instance = {
    initialize: initialize,
    getStreamId: getStreamId,
    getType: getType,
    getBufferControllerType: getBufferControllerType,
    createBufferSink: createBufferSink,
    dischargePreBuffer: dischargePreBuffer,
    getBuffer: getBuffer,
    getBufferLevel: getBufferLevel,
    getRangeAt: getRangeAt,
    hasBufferAtTime: hasBufferAtTime,
    pruneBuffer: pruneBuffer,
    setMediaSource: setMediaSource,
    getMediaSource: getMediaSource,
    appendInitSegmentFromCache: appendInitSegmentFromCache,
    getIsBufferingCompleted: getIsBufferingCompleted,
    setIsBufferingCompleted: setIsBufferingCompleted,
    getIsPruningInProgress: getIsPruningInProgress,
    reset: reset,
    prepareForPlaybackSeek: prepareForPlaybackSeek,
    prepareForReplacementTrackSwitch: prepareForReplacementTrackSwitch,
    prepareForNonReplacementTrackSwitch: prepareForNonReplacementTrackSwitch,
    prepareForForceReplacementQualitySwitch: prepareForForceReplacementQualitySwitch,
    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_7__["default"].getClassFactory(BufferController));

/***/ }),

/***/ "./src/streaming/controllers/CatchupController.js":
/*!********************************************************!*\
  !*** ./src/streaming/controllers/CatchupController.js ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _constants_Constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../constants/MetricsConstants */ "./src/streaming/constants/MetricsConstants.js");
/* harmony import */ var _core_Utils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/Utils */ "./src/core/Utils.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 CatchupController() {
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
  var instance, isCatchupSeekInProgress, isSafari, videoModel, settings, streamController, playbackController, mediaPlayerModel, playbackStalled, logger;

  function initialize() {
    _registerEvents();

    _checkPlaybackRates();
  }

  function setConfig(config) {
    if (!config) {
      return;
    }

    if (config.settings) {
      settings = config.settings;
    }

    if (config.videoModel) {
      videoModel = config.videoModel;
    }

    if (config.streamController) {
      streamController = config.streamController;
    }

    if (config.playbackController) {
      playbackController = config.playbackController;
    }

    if (config.mediaPlayerModel) {
      mediaPlayerModel = config.mediaPlayerModel;
    }
  }

  function _registerEvents() {
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].BUFFER_LEVEL_UPDATED, _onBufferLevelUpdated, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].PLAYBACK_SEEKED, _onPlaybackSeeked, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_CATCHUP_ENABLED, _onCatchupSettingUpdated, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_PLAYBACK_RATE_MIN, _checkPlaybackRates, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_PLAYBACK_RATE_MAX, _checkPlaybackRates, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].STREAM_INITIALIZED, _checkPlaybackRates, instance);
  }

  function _unregisterEvents() {
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].BUFFER_LEVEL_UPDATED, _onBufferLevelUpdated, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].PLAYBACK_PROGRESS, _onPlaybackProgression, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackProgression, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].PLAYBACK_SEEKED, _onPlaybackSeeked, instance);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_CATCHUP_ENABLED, _onCatchupSettingUpdated, instance);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_PLAYBACK_RATE_MIN, _checkPlaybackRates, instance);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_PLAYBACK_RATE_MAX, _checkPlaybackRates, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_4__["default"].STREAM_INITIALIZED, _checkPlaybackRates, instance);
  }

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance().getLogger(instance);

    _resetInitialSettings();
  }

  function reset() {
    _unregisterEvents();

    _resetInitialSettings();

    videoModel.setPlaybackRate(1.0, true);
  }

  function _resetInitialSettings() {
    isCatchupSeekInProgress = false;
    var ua = _core_Utils__WEBPACK_IMPORTED_MODULE_7__["default"].parseUserAgent();
    isSafari = ua && ua.browser && ua.browser.name && ua.browser.name.toLowerCase() === 'safari';
  }

  function _onPlaybackSeeked() {
    isCatchupSeekInProgress = false;
  }
  /**
   * When the buffer level updated we check if we can remove the stalled state
   * @param {object} e
   * @private
   */


  function _onBufferLevelUpdated(e) {
    // do not stop when getting an event from Stream that is not active
    if (e.streamId !== streamController.getActiveStreamInfo().id || !playbackStalled) {
      return;
    } // we remove the stalled state once we reach a certain buffer level


    var liveDelay = playbackController.getLiveDelay();
    var bufferLevel = playbackController.getBufferLevel();

    if (bufferLevel > liveDelay / 2) {
      playbackStalled = false;
    }
  }
  /**
   * When the buffer state changed to BUFFER_EMPTY we update the stalled state
   * @param {object} e
   * @private
   */


  function _onBufferLevelStateChanged(e) {
    // do not stop when getting an event from Stream that is not active
    if (e.streamId !== streamController.getActiveStreamInfo().id) {
      return;
    }

    playbackStalled = e.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_EMPTY;
  }
  /**
   * If the catchup mode is disabled in the settings we reset playback rate to 1.0
   * @private
   */


  function _onCatchupSettingUpdated() {
    if (!mediaPlayerModel.getCatchupModeEnabled()) {
      videoModel.setPlaybackRate(1.0);
    }
  }
  /**
   * While playback is progressing we check if we need to start or stop the catchup mechanism to reach the target latency
   * @private
   */


  function _onPlaybackProgression() {
    if (playbackController.getIsDynamic() && mediaPlayerModel.getCatchupModeEnabled() && (mediaPlayerModel.getCatchupPlaybackRates().max > 0 || mediaPlayerModel.getCatchupPlaybackRates().min < 0) && !playbackController.isPaused() && !playbackController.isSeeking() && _shouldStartCatchUp()) {
      _startPlaybackCatchUp();
    }
  }
  /**
   * Apply catchup mode. We either seek back to the target live edge or increase the playback rate.
   */


  function _startPlaybackCatchUp() {
    // we are seeking dont do anything for now
    if (isCatchupSeekInProgress) {
      return;
    }

    if (videoModel) {
      var newRate;
      var currentPlaybackRate = videoModel.getPlaybackRate();
      var liveCatchupPlaybackRates = mediaPlayerModel.getCatchupPlaybackRates();
      var bufferLevel = playbackController.getBufferLevel();

      var deltaLatency = _getLatencyDrift(); // we reached the maxDrift. Do a seek


      var maxDrift = mediaPlayerModel.getCatchupMaxDrift();

      if (!isNaN(maxDrift) && maxDrift > 0 && deltaLatency > maxDrift) {
        logger.info('[CatchupController]: Low Latency catchup mechanism. Latency too high, doing a seek to live point');
        isCatchupSeekInProgress = true;
        playbackController.seekToCurrentLive(true, false);
      } // try to reach the target latency by adjusting the playback rate
      else {
        var currentLiveLatency = playbackController.getCurrentLiveLatency();
        var targetLiveDelay = playbackController.getLiveDelay();

        if (_getCatchupMode() === _constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].LIVE_CATCHUP_MODE_LOLP) {
          // Custom playback control: Based on buffer level
          var playbackBufferMin = settings.get().streaming.liveCatchup.playbackBufferMin;
          newRate = _calculateNewPlaybackRateLolP(liveCatchupPlaybackRates, currentLiveLatency, targetLiveDelay, playbackBufferMin, bufferLevel);
        } else {
          // Default playback control: Based on target and current latency
          newRate = _calculateNewPlaybackRateDefault(liveCatchupPlaybackRates, currentLiveLatency, targetLiveDelay, bufferLevel);
        } // We adjust the min change linear, depending on the maximum catchup rate. Default is 0.02 for rate 0.5.
        // For Safari we stick to a fixed value because of  https://bugs.webkit.org/show_bug.cgi?id=208142


        var minPlaybackRateChange = isSafari ? 0.25 : 0.02 / (0.5 / liveCatchupPlaybackRates.max); // Obtain newRate and apply to video model.  Don't change playbackrate for small variations (don't overload element with playbackrate changes)

        if (newRate && Math.abs(currentPlaybackRate - newRate) >= minPlaybackRateChange) {
          // non-null
          logger.debug("[CatchupController]: Setting playback rate to ".concat(newRate));
          videoModel.setPlaybackRate(newRate);
        }
      }
    }
  }
  /**
   * Calculates the drift between the current latency and the target latency
   * @return {number}
   * @private
   */


  function _getLatencyDrift() {
    var currentLiveLatency = playbackController.getCurrentLiveLatency();
    var targetLiveDelay = playbackController.getLiveDelay();
    return currentLiveLatency - targetLiveDelay;
  }
  /**
   * Checks whether the catchup mechanism should be enabled. We use different subfunctions here depending on the catchup mode.
   * @return {boolean}
   */


  function _shouldStartCatchUp() {
    try {
      if (!playbackController.getTime() > 0 || isCatchupSeekInProgress) {
        return false;
      }

      var catchupMode = _getCatchupMode();

      if (catchupMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].LIVE_CATCHUP_MODE_LOLP) {
        var currentBuffer = playbackController.getBufferLevel();
        var playbackBufferMin = settings.get().streaming.liveCatchup.playbackBufferMin;
        return _lolpNeedToCatchUpCustom(currentBuffer, playbackBufferMin);
      } else {
        return _defaultNeedToCatchUp();
      }
    } catch (e) {
      return false;
    }
  }
  /**
   * 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_3__["default"].LIVE_CATCHUP_MODE_LOLP && playbackBufferMin !== null && !isNaN(playbackBufferMin) ? _constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].LIVE_CATCHUP_MODE_LOLP : _constants_Constants__WEBPACK_IMPORTED_MODULE_3__["default"].LIVE_CATCHUP_MODE_DEFAULT;
  }
  /**
   * Default algorithm to determine if catchup mode should be enabled
   * @return {boolean}
   * @private
   */


  function _defaultNeedToCatchUp() {
    try {
      var latencyDrift = Math.abs(_getLatencyDrift());
      return latencyDrift > 0;
    } catch (e) {
      return false;
    }
  }
  /**
   * LoL+ logic to determine if catchup mode should be enabled
   * @param {number} currentBuffer
   * @param {number} playbackBufferMin
   * @return {boolean}
   * @private
   */


  function _lolpNeedToCatchUpCustom(currentBuffer, playbackBufferMin) {
    try {
      var latencyDrift = Math.abs(_getLatencyDrift());
      return latencyDrift > 0 || currentBuffer < playbackBufferMin;
    } catch (e) {
      return false;
    }
  }
  /**
   * Default algorithm to calculate the new playback rate
   * @param {object} liveCatchUpPlaybackRates
   * @param {number} liveCatchUpPlaybackRates.min - minimum playback rate decrease limit
   * @param {number} liveCatchUpPlaybackRates.max - maximum playback rate increase limit
   * @param {number} currentLiveLatency
   * @param {number} liveDelay
   * @param {number} bufferLevel
   * @param {number} currentPlaybackRate
   * @return {number}
   * @private
   */


  function _calculateNewPlaybackRateDefault(liveCatchUpPlaybackRates, currentLiveLatency, liveDelay, bufferLevel) {
    // if we recently ran into an empty buffer we wait for the buffer to recover before applying a new rate
    if (playbackStalled) {
      return 1.0;
    }

    var deltaLatency = currentLiveLatency - liveDelay;
    var cpr = deltaLatency < 0 ? Math.abs(liveCatchUpPlaybackRates.min) : liveCatchUpPlaybackRates.max;
    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 (playbackController.getPlaybackStalled()) {
      if (bufferLevel <= liveDelay / 2 && deltaLatency > 0) {
        newRate = 1.0;
      }
    }

    return newRate;
  }
  /**
   * Lol+ algorithm to calculate the new playback rate
   * @param {object} liveCatchUpPlaybackRates
   * @param {number} liveCatchUpPlaybackRates.min - minimum playback rate decrease limit
   * @param {number} liveCatchUpPlaybackRates.max - maximum playback rate increase limit
   * @param {number} currentLiveLatency
   * @param {number} liveDelay
   * @param {number} playbackBufferMin
   * @param {number} bufferLevel
   * @param {number} currentPlaybackRate
   * @return {number}
   * @private
   */


  function _calculateNewPlaybackRateLolP(liveCatchUpPlaybackRates, currentLiveLatency, liveDelay, playbackBufferMin, bufferLevel) {
    var newRate; // Hybrid: Buffer-based

    if (bufferLevel < playbackBufferMin) {
      // Buffer in danger, slow down
      var cpr = Math.abs(liveCatchUpPlaybackRates.min); // Absolute value as negative delta value will be used.

      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
      var _cpr = liveCatchUpPlaybackRates.max; // 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);
    }

    return newRate;
  }

  function _checkPlaybackRates() {
    mediaPlayerModel.getCatchupPlaybackRates(true);
  }

  instance = {
    reset: reset,
    setConfig: setConfig,
    initialize: initialize
  };
  setup();
  return instance;
}

CatchupController.__dashjs_factory_name = 'CatchupController';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(CatchupController));

/***/ }),

/***/ "./src/streaming/controllers/EventController.js":
/*!******************************************************!*\
  !*** ./src/streaming/controllers/EventController.js ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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[periodID][schemeIdUri]

    inbandEvents = {}; // Format inbandEvents[periodID][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;
    }
  }
  /**
   * 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);

        _removeOutdatedEventObjects(inbandEvents);

        _removeOutdatedEventObjects(inlineEvents);

        lastEventTimerCall = currentVideoTime;
        eventHandlingInProgress = false;
      }
    } catch (e) {
      eventHandlingInProgress = false;
      logger.error(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, _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_START);
          } else if (_eventHasExpired(currentVideoTime, duration + presentationTimeThreshold, event.calculatedPresentationTime) || _eventIsInvalid(event)) {
            logger.debug("Removing event ".concat(event.id, " from period ").concat(event.eventStream.period.id, " as it is expired or invalid"));

            _removeEvent(events, event);
          }
        }
      };

      _iterateAndTriggerCallback(events, callback);
    } catch (e) {
      logger.error(e);
    }
  }
  /**
   * Iterates over the entries of the events object and deletes the entries for which no events are present
   * @param {object} events
   * @private
   */


  function _removeOutdatedEventObjects(events) {
    try {
      for (var key in events) {
        if (events.hasOwnProperty(key)) {
          if (Object.keys(events[key]).length === 0) delete events[key];
        }
      }
    } catch (e) {
      logger.error(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
   * @param {string} periodId
   */


  function addInlineEvents(values, periodId) {
    try {
      checkConfig();

      if (!inlineEvents[periodId]) {
        inlineEvents[periodId] = {};
      }

      if (values) {
        for (var i = 0; i < values.length; i++) {
          var event = values[i];
          var currentTime = playbackController.getTime();
          var duration = !isNaN(event.duration) ? event.duration : 0;

          if (!_eventHasExpired(currentTime, duration, event.calculatedPresentationTime)) {
            var result = _addOrUpdateEvent(event, inlineEvents[periodId], true);

            if (result === EVENT_HANDLED_STATES.ADDED) {
              logger.debug("Added inline event with id ".concat(event.id, " from period ").concat(periodId)); // If we see the event for the first time we trigger it in onReceive mode

              _startEvent(event, _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, " from period ").concat(periodId));
            }
          }
        }
      }
    } 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
   * @param {string} periodId
   */


  function addInbandEvents(values, periodId) {
    try {
      checkConfig();

      if (!inbandEvents[periodId]) {
        inbandEvents[periodId] = {};
      }

      for (var i = 0; i < values.length; i++) {
        var event = values[i];
        var currentTime = playbackController.getTime();
        var duration = !isNaN(event.duration) ? event.duration : 0;

        if (!_eventHasExpired(currentTime, duration, event.calculatedPresentationTime)) {
          var result = _addOrUpdateEvent(event, inbandEvents[periodId], false);

          if (result === EVENT_HANDLED_STATES.ADDED) {
            if (event.eventStream.schemeIdUri === MPD_RELOAD_SCHEME) {
              _handleManifestReloadEvent(event);
            }

            logger.debug("Added inband event with id ".concat(event.id, " from period ").concat(periodId));

            _startEvent(event, _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, ", period id ").concat(periodId, " and event 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;
    }); // New event, we add it to our list of events

    if (indexOfExistingEvent === -1) {
      events[schemeIdUri].push(event);
      event.triggeredReceivedEvent = false;
      event.triggeredStartEvent = false;
      eventState = EVENT_HANDLED_STATES.ADDED;
    } // We have a similar event for this period with the same schemeIdUri, value and id. Overwrite it or ignore it
    else if (shouldOverwriteExistingEvents) {
      var oldEvent = events[schemeIdUri][indexOfExistingEvent];
      event.triggeredReceivedEvent = oldEvent.triggeredReceivedEvent;
      event.triggeredStartEvent = oldEvent.triggeredStartEvent;
      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) {
      logger.error(e);
    }
  }
  /**
   * 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) {
      logger.error(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, _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_START);
        }
      };

      _iterateAndTriggerCallback(events, callback);
    } catch (e) {
      logger.error(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 periodIds = Object.keys(events);

        for (var i = 0; i < periodIds.length; i++) {
          var currentPeriod = events[periodIds[i]];
          var schemeIdUris = Object.keys(currentPeriod);

          for (var j = 0; j < schemeIdUris.length; j++) {
            var schemeIdEvents = currentPeriod[schemeIdUris[j]];
            schemeIdEvents.forEach(function (event) {
              if (event !== undefined) {
                callback(event);
              }
            });
          }
        }
      }
    } catch (e) {
      logger.error(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) {
      logger.error(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) {
      logger.error(e);
      return false;
    }
  }
  /**
   * Starts an event. Depending on the schemeIdUri we distinguish between
   * - MPD Reload events
   * - MPD Callback events
   * - Events to be dispatched to the application
   * @param {object} event
   * @param {String} mode
   * @private
   */


  function _startEvent(event, mode) {
    try {
      var currentVideoTime = playbackController.getTime();
      var eventId = event.id;

      if (mode === _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].EVENT_MODE_ON_RECEIVE && !event.triggeredReceivedEvent) {
        logger.debug("Received event ".concat(eventId));
        event.triggeredReceivedEvent = true;
        eventBus.trigger(event.eventStream.schemeIdUri, {
          event: event
        }, {
          mode: mode
        });
        return;
      }

      if (!event.triggeredStartEvent) {
        if (event.eventStream.schemeIdUri === MPD_RELOAD_SCHEME && event.eventStream.value == MPD_RELOAD_VALUE) {
          //If both are set to zero, it indicates the media is over at this point. Don't reload the manifest.
          if (event.duration !== 0 || event.presentationTimeDelta !== 0) {
            logger.debug("Starting manifest refresh event ".concat(eventId, " at ").concat(currentVideoTime));

            _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));

          _sendCallbackRequest(event.messageData);
        } else {
          logger.debug("Starting event ".concat(eventId, " from period ").concat(event.eventStream.period.id, " at ").concat(currentVideoTime));
          eventBus.trigger(event.eventStream.schemeIdUri, {
            event: event
          }, {
            mode: mode
          });
        }

        event.triggeredStartEvent = true;
      }
    } catch (e) {
      logger.error(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) {
    try {
      var schemeIdUri = event.eventStream.schemeIdUri;
      var periodId = event.eventStream.period.id;
      var value = event.eventStream.value;
      var id = event.id;
      events[periodId][schemeIdUri] = events[periodId][schemeIdUri].filter(function (e) {
        return value && e.eventStream.value && e.eventStream.value !== value || e.id !== id;
      });

      if (events[periodId][schemeIdUri].length === 0) {
        delete events[periodId][schemeIdUri];
      }
    } catch (e) {
      logger.error(e);
    }
  }
  /**
   * Refresh the manifest
   * @private
   */


  function _refreshManifest() {
    try {
      checkConfig();
      manifestUpdater.refreshManifest();
    } catch (e) {
      logger.error(e);
    }
  }
  /**
   * Send a callback request
   * @param {String} url
   * @private
   */


  function _sendCallbackRequest(url) {
    try {
      var loader = (0,_net_XHRLoader__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({});
      loader.load({
        method: 'get',
        url: url,
        request: {
          responseType: 'arraybuffer'
        }
      });
    } catch (e) {
      logger.error(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 ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _utils_SegmentResponseModifier__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../utils/SegmentResponseModifier */ "./src/streaming/utils/SegmentResponseModifier.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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
  var errHandler = config.errHandler;
  var mediaPlayerModel = config.mediaPlayerModel;
  var dashMetrics = config.dashMetrics;
  var debug = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
  var segmentResponseModifier = (0,_utils_SegmentResponseModifier__WEBPACK_IMPORTED_MODULE_11__["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 = (0,_models_FragmentModel__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
        streamInfo: streamInfo,
        type: type,
        dashMetrics: dashMetrics,
        fragmentLoader: (0,_FragmentLoader__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
          dashMetrics: dashMetrics,
          mediaPlayerModel: mediaPlayerModel,
          errHandler: errHandler,
          requestModifier: (0,_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_BASE_URL_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);
    segmentResponseModifier.modifyResponseAsync(chunk).then(function (modifiedChunk) {
      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: modifiedChunk,
        request: request
      }, {
        streamId: strInfo.id,
        mediaType: request.mediaType
      });
    })["catch"](function (e) {
      logger.error(e);
      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 ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* 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 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 = (0,_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 = (0,_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 !== _constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO && e.mediaType !== _constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].AUDIO) {
        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() {
    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;

    if (!streamController.getActiveStream()) {
      return 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;
    }
  }
  /**
   * Check if the currentTime exist within the buffered range
   * @param {object} ranges
   * @param {number} currentTime
   * @private
   * @return {boolean}
   */


  function _isTimeBuffered(ranges, currentTime) {
    for (var i = 0, len = ranges.length; i < len; i++) {
      if (currentTime >= ranges.start(i) && currentTime <= ranges.end(i)) {
        return true;
      }
    }

    return false;
  }
  /**
   * 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 enableStallFix = settings.get().streaming.gaps.enableStallFix;
    var stallSeek = settings.get().streaming.gaps.stallSeek;
    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 (enableStallFix && isNaN(seekToPosition) && playbackStalled && isNaN(nextRangeIndex) && _isTimeBuffered(ranges, currentTime)) {
      if (stallSeek === 0) {
        logger.warn("Toggle play pause to break stall");
        videoModel.pause();
        videoModel.play();
      } else {
        logger.warn("Jumping ".concat(stallSeek, "s to break stall"));
        seekToPosition = currentTime + stallSeek;
      }
    }

    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(seekToPosition - _start));
          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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var bcp_47_normalize__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! bcp-47-normalize */ "./node_modules/bcp-47-normalize/index.js");
/* harmony import */ var bcp_47_normalize__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(bcp_47_normalize__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var bcp_47_match__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! bcp-47-match */ "./node_modules/bcp-47-match/index.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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
  var instance, logger, tracks, settings, initialSettings, lastSelectedTracks, customParametersModel, domStorage;

  function setup() {
    logger = (0,_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);

      if (settings) {
        // If the settings are defined locally, do not take codec into account or it'll be too strict.
        // eg: An audio track should not be selected by codec but merely by lang.
        delete settings.codec;
      }

      setInitialSettings(type, settings);
    }

    if (!tracksForType || tracksForType.length === 0) return;

    if (settings) {
      tracks = Array.from(tracksForType);
      tracks = filterTracksBySettings(tracks, matchSettingsLang, settings);
      tracks = filterTracksBySettings(tracks, matchSettingsIndex, settings);
      tracks = filterTracksBySettings(tracks, matchSettingsViewPoint, settings);

      if (!(type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && !!lastSelectedTracks[type])) {
        tracks = filterTracksBySettings(tracks, matchSettingsRole, settings);
      }

      tracks = filterTracksBySettings(tracks, matchSettingsAccessibility, settings);
      tracks = filterTracksBySettings(tracks, matchSettingsAudioChannelConfig, settings);
      tracks = filterTracksBySettings(tracks, matchSettingsCodec, settings);
    }

    if (tracks.length === 0) {
      setTrack(selectInitialTrack(type, tracksForType), true);
    } else {
      if (tracks.length > 1) {
        setTrack(selectInitialTrack(type, tracks));
      } 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]) return;
    tracks[id][type].current = track;

    if (tracks[id][type].current && (type !== _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT && !isTracksEqual(track, current) || 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 sameViewpointDescriptors = JSON.stringify(t1.viewpointsWithSchemeIdUri) === JSON.stringify(t2.viewpointsWithSchemeIdUri);
    var sameLang = t1.lang === t2.lang;
    var sameCodec = t1.codec === t2.codec;
    var sameRoles = t1.roles.toString() === t2.roles.toString();
    var sameRoleDescriptors = JSON.stringify(t1.rolesWithSchemeIdUri) === JSON.stringify(t2.rolesWithSchemeIdUri);
    var sameAccessibility = t1.accessibility.toString() === t2.accessibility.toString();
    var sameAccessibilityDescriptors = JSON.stringify(t1.accessibilitiesWithSchemeIdUri) === JSON.stringify(t2.accessibilitiesWithSchemeIdUri);
    var sameAudioChannelConfiguration = t1.audioChannelConfiguration.toString() === t2.audioChannelConfiguration.toString();
    var sameAudioChannelConfigurationDescriptors = JSON.stringify(t1.audioChannelConfigurationsWithSchemeIdUri) === JSON.stringify(t2.audioChannelConfigurationsWithSchemeIdUri);
    return sameId && sameCodec && sameViewpoint && sameViewpointDescriptors && sameLang && sameRoles && sameRoleDescriptors && sameAccessibility && sameAccessibilityDescriptors && sameAudioChannelConfiguration && sameAudioChannelConfigurationDescriptors;
  }

  function setConfig(config) {
    if (!config) return;

    if (config.domStorage) {
      domStorage = config.domStorage;
    }

    if (config.settings) {
      settings = config.settings;
    }

    if (config.customParametersModel) {
      customParametersModel = config.customParametersModel;
    }
  }
  /**
   * @memberof MediaController#
   */


  function reset() {
    tracks = {};
    lastSelectedTracks = {};
    resetInitialSettings();
  }

  function extractSettings(mediaInfo) {
    var settings = {
      lang: mediaInfo.lang,
      viewpoint: mediaInfo.viewpoint,
      roles: mediaInfo.roles,
      accessibility: mediaInfo.accessibility,
      audioChannelConfiguration: mediaInfo.audioChannelConfiguration,
      codec: mediaInfo.codec
    };
    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 filterTracksBySettings(tracks, filterFn, settings) {
    var tracksAfterMatcher = [];
    tracks.forEach(function (track) {
      if (filterFn(settings, track)) {
        tracksAfterMatcher.push(track);
      }
    });

    if (tracksAfterMatcher.length !== 0) {
      return tracksAfterMatcher;
    }

    return tracks;
  }

  function matchSettingsLang(settings, track) {
    return !settings.lang || settings.lang instanceof RegExp ? track.lang.match(settings.lang) : track.lang !== '' ? (0,bcp_47_match__WEBPACK_IMPORTED_MODULE_6__.extendedFilter)(track.lang, bcp_47_normalize__WEBPACK_IMPORTED_MODULE_5___default()(settings.lang)).length > 0 : false;
  }

  function matchSettingsIndex(settings, track) {
    return settings.index === undefined || settings.index === null || track.index === settings.index;
  }

  function matchSettingsViewPoint(settings, track) {
    return !settings.viewpoint || settings.viewpoint === track.viewpoint;
  }

  function matchSettingsRole(settings, track) {
    var isTrackActive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var matchRole = !settings.role || !!track.roles.filter(function (item) {
      return item === settings.role;
    })[0];
    return matchRole || track.type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO && isTrackActive;
  }

  function matchSettingsAccessibility(settings, track) {
    var matchAccessibility;

    if (!settings.accessibility) {
      // if no accessibility is requested (or request is empty string),
      // match only those tracks having no accessibility element present
      matchAccessibility = !track.accessibility.length;
    } else {
      matchAccessibility = !!track.accessibility.filter(function (item) {
        return item === settings.accessibility;
      })[0];
    }

    return matchAccessibility;
  }

  function matchSettingsAudioChannelConfig(settings, track) {
    var matchAudioChannelConfiguration = !settings.audioChannelConfiguration || !!track.audioChannelConfiguration.filter(function (item) {
      return item === settings.audioChannelConfiguration;
    })[0];
    return matchAudioChannelConfiguration;
  }

  function matchSettingsCodec(settings, track) {
    return !settings.codec || settings.codec === track.codec;
  }

  function matchSettings(settings, track) {
    var isTrackActive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

    try {
      var matchLang = false; // If there is no language defined in the target settings we got a match

      if (!settings.lang) {
        matchLang = true;
      } // If the target language is provided as a RegExp apply match function
      else if (settings.lang instanceof RegExp) {
        matchLang = track.lang.match(settings.lang);
      } // If the track has a language and we can normalize the target language check if we got a match
      else if (track.lang !== '') {
        var normalizedSettingsLang = bcp_47_normalize__WEBPACK_IMPORTED_MODULE_5___default()(settings.lang);

        if (normalizedSettingsLang) {
          matchLang = (0,bcp_47_match__WEBPACK_IMPORTED_MODULE_6__.extendedFilter)(track.lang, normalizedSettingsLang).length > 0;
        }
      }

      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;
    } catch (e) {
      return false;
      logger.error(e);
    }
  }

  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 selectInitialTrack(type, tracks) {
    if (type === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT) return tracks[0];
    var mode = settings.get().streaming.selectionModeForInitialTrack;
    var tmpArr;
    var customInitialTrackSelectionFunction = customParametersModel.getCustomInitialTrackSelectionFunction();

    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() {
    var storeLastSettings = settings.get().streaming.saveLastMediaSettingsForCurrentStreamingSession;
    return {
      audio: {
        list: [],
        storeLastSettings: storeLastSettings,
        current: null
      },
      video: {
        list: [],
        storeLastSettings: storeLastSettings,
        current: null
      },
      text: {
        list: [],
        storeLastSettings: storeLastSettings,
        current: null
      },
      image: {
        list: [],
        storeLastSettings: storeLastSettings,
        current: null
      }
    };
  }

  instance = {
    setInitialMediaSettingsForType: setInitialMediaSettingsForType,
    addTrack: addTrack,
    getTracksFor: getTracksFor,
    getCurrentTrackFor: getCurrentTrackFor,
    isCurrentTrack: isCurrentTrack,
    setTrack: setTrack,
    selectInitialTrack: selectInitialTrack,
    setInitialSettings: setInitialSettings,
    getInitialSettings: getInitialSettings,
    getTracksWithHighestBitrate: getTracksWithHighestBitrate,
    getTracksWithHighestEfficiency: getTracksWithHighestEfficiency,
    getTracksWithWidestRange: getTracksWithWidestRange,
    isTracksEqual: isTracksEqual,
    matchSettings: matchSettings,
    matchSettingsLang: matchSettingsLang,
    matchSettingsIndex: matchSettingsIndex,
    matchSettingsViewPoint: matchSettingsViewPoint,
    matchSettingsRole: matchSettingsRole,
    matchSettingsAccessibility: matchSettingsAccessibility,
    matchSettingsAudioChannelConfig: matchSettingsAudioChannelConfig,
    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 ***!
  \************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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, settings, logger;
  var context = this.context;

  function setup() {
    logger = (0,_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 (value === Infinity && !settings.get().streaming.buffer.mediaSourceDurationInfinity) {
      value = Math.pow(2, 32);
    }

    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;
  }
  /**
   * Set the config of the MediaSourceController
   * @param {object} config
   */


  function setConfig(config) {
    if (!config) {
      return;
    }

    if (config.settings) {
      settings = config.settings;
    }
  }

  instance = {
    createMediaSource: createMediaSource,
    attachMediaSource: attachMediaSource,
    detachMediaSource: detachMediaSource,
    setDuration: setDuration,
    setSeekable: setSeekable,
    signalEndOfStream: signalEndOfStream,
    setConfig: setConfig
  };
  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 ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _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 _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__ = __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.
 */







var LIVE_UPDATE_PLAYBACK_TIME_INTERVAL_MS = 500;

function PlaybackController() {
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  var instance, logger, streamController, serviceDescriptionController, dashMetrics, adapter, videoModel, timelineConverter, wallclockTimeIntervalId, liveDelay, originalLiveDelay, streamInfo, isDynamic, playOnceInitialized, lastLivePlaybackTime, availabilityStartTime, availabilityTimeComplete, lowLatencyModeEnabled, seekTarget, internalSeek, playbackStalled, manifestUpdateInProgress, initialCatchupModeActivated, settings;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance().getLogger(instance);
    reset();
  }
  /**
   * Reset all settings
   */


  function reset() {
    pause();
    playOnceInitialized = false;
    liveDelay = 0;
    originalLiveDelay = 0;
    availabilityStartTime = 0;
    manifestUpdateInProgress = false;
    availabilityTimeComplete = true;
    lowLatencyModeEnabled = false;
    initialCatchupModeActivated = false;
    seekTarget = NaN;

    if (videoModel) {
      eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].DATA_UPDATE_COMPLETED, _onDataUpdateCompleted, instance);
      eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].LOADING_PROGRESS, _onFragmentLoadProgress, instance);
      eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].MANIFEST_UPDATED, _onManifestUpdated, instance);
      eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].STREAMS_COMPOSED, _onStreamsComposed, instance);
      eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance);
      eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].STREAM_INITIALIZING, _onStreamInitializing, instance);
      eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].REPRESENTATION_SWITCH, _onRepresentationSwitch, instance);
      eventBus.off(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);
      stopUpdatingWallclockTime();
      removeAllListeners();
    }

    wallclockTimeIntervalId = null;
    videoModel = null;
    streamInfo = null;
    isDynamic = null;
  }
  /**
   * 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;
    playbackStalled = false;
    internalSeek = false;
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].DATA_UPDATE_COMPLETED, _onDataUpdateCompleted, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].LOADING_PROGRESS, _onFragmentLoadProgress, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].MANIFEST_UPDATED, _onManifestUpdated, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].STREAMS_COMPOSED, _onStreamsComposed, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance, {
      priority: _core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"].EVENT_PRIORITY_HIGH
    });
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].STREAM_INITIALIZING, _onStreamInitializing, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].REPRESENTATION_SWITCH, _onRepresentationSwitch, instance);
    eventBus.on(_streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_5__["default"].BUFFER_LEVEL_STATE_CHANGED, _onBufferLevelStateChanged, instance);

    if (playOnceInitialized) {
      playOnceInitialized = false;
      play();
    }
  }
  /**
   * Returns stalled state
   * @return {boolean}
   */


  function getPlaybackStalled() {
    return playbackStalled;
  }
  /**
   * Returns remaining duration of a period
   * @param {object} sInfo
   * @return {number}
   */


  function getTimeToStreamEnd() {
    var sInfo = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
    return parseFloat((getStreamEndTime(sInfo) - getTime()).toFixed(5));
  }
  /**
   * Returns end time of a period
   * @param {object} sInfo
   * @return {number}
   */


  function getStreamEndTime(sInfo) {
    var refInfo = sInfo ? sInfo : streamInfo;
    return refInfo.start + refInfo.duration;
  }
  /**
   * Triggers play() on the video element
   */


  function play() {
    var adjustLiveDelay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

    if (streamInfo && videoModel && videoModel.getElement()) {
      if (adjustLiveDelay && isDynamic) {
        _adjustLiveDelayAfterUserInteraction(getTime());
      }

      videoModel.play();
    } else {
      playOnceInitialized = true;
    }
  }
  /**
   * Triggers pause() on the video element
   */


  function pause() {
    if (streamInfo && videoModel) {
      videoModel.pause();
    }
  }
  /**
   * Triggers a seek to the specified media time. If internal is enabled there will be now "seeked" event dispatched
   * @param {number} time
   * @param {boolean} stickToBuffered
   * @param {boolean} internal
   * @param {boolean} adjustLiveDelay
   */


  function seek(time) {
    var stickToBuffered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    var internal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var adjustLiveDelay = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
    if (!streamInfo || !videoModel || !videoModel.getElement()) return;
    var currentTime = !isNaN(seekTarget) ? seekTarget : videoModel.getTime();
    if (time === currentTime) return;
    internalSeek = internal === true;

    if (!internalSeek) {
      seekTarget = time;
    }

    logger.info('Requesting seek to time: ' + time + (internalSeek ? ' (internal)' : '')); // We adjust the current latency. If catchup is enabled we will maintain this new latency

    if (isDynamic && adjustLiveDelay) {
      _adjustLiveDelayAfterUserInteraction(time);
    }

    videoModel.setCurrentTime(time, stickToBuffered);
  }
  /**
   * Seeks back to the live edge as defined by the originally calculated live delay
   * @param {boolean} stickToBuffered
   * @param {boolean} internal
   * @param {boolean} adjustLiveDelay
   */


  function seekToOriginalLive() {
    var stickToBuffered = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    var internal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    var adjustLiveDelay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

    var dvrWindowEnd = _getDvrWindowEnd();

    if (dvrWindowEnd === 0) {
      return;
    }

    liveDelay = originalLiveDelay;
    var seektime = dvrWindowEnd - liveDelay;
    seek(seektime, stickToBuffered, internal, adjustLiveDelay);
  }
  /**
   * Seeks to the live edge as currently defined by liveDelay
   * @param {boolean} stickToBuffered
   * @param {boolean} internal
   * @param {boolean} adjustLiveDelay
   */


  function seekToCurrentLive() {
    var stickToBuffered = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    var internal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    var adjustLiveDelay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

    var dvrWindowEnd = _getDvrWindowEnd();

    if (dvrWindowEnd === 0) {
      return;
    }

    var seektime = dvrWindowEnd - liveDelay;
    seek(seektime, stickToBuffered, internal, adjustLiveDelay);
  }

  function _getDvrWindowEnd() {
    if (!streamInfo || !videoModel || !isDynamic) {
      return;
    }

    var type = streamController && streamController.hasVideoTrack() ? _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].VIDEO : _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].AUDIO;
    var dvrInfo = dashMetrics.getCurrentDVRInfo(type);
    return dvrInfo && dvrInfo.range ? dvrInfo.range.end : 0;
  }

  function _adjustLiveDelayAfterUserInteraction(time) {
    var now = new Date(timelineConverter.getClientReferenceTime());
    var period = adapter.getRegularPeriods()[0];
    var nowAsPresentationTime = timelineConverter.calcPresentationTimeFromWallTime(now, period);
    liveDelay = nowAsPresentationTime - time;
  }
  /**
   * Returns current time of video element
   * @return {number|null}
   */


  function getTime() {
    return streamInfo && videoModel ? videoModel.getTime() : null;
  }
  /**
   * Returns paused state of the video element
   * @return {boolean|null}
   */


  function isPaused() {
    return streamInfo && videoModel ? videoModel.isPaused() : null;
  }
  /**
   * Returns seeking state of the video element
   * @return {boolean|null}
   */


  function isSeeking() {
    return streamInfo && videoModel ? videoModel.isSeeking() : null;
  }
  /**
   * Returns stalled state of the video element
   * @return {boolean|null}
   */


  function isStalled() {
    return streamInfo && videoModel ? videoModel.isStalled() : null;
  }
  /**
   * Returns current playback rate of the video element
   * @return {number|null}
   */


  function getPlaybackRate() {
    return streamInfo && videoModel ? videoModel.getPlaybackRate() : null;
  }
  /**
   * Returns the played ranges of the video element
   * @return {array}
   */


  function getPlayedRanges() {
    return streamInfo && videoModel ? videoModel.getPlayedRanges() : null;
  }
  /**
   * Returns ended attribute of the video element
   * @return {boolean|null}
   */


  function getEnded() {
    return streamInfo && videoModel ? videoModel.getEnded() : null;
  }
  /**
   * Returns whether a stream is type dynamic or not
   * @return {boolean}
   */


  function getIsDynamic() {
    return isDynamic;
  }
  /**
   * Returns the StreamController
   * @return {object}
   */


  function getStreamController() {
    return streamController;
  }
  /**
   * Returns whether a manifest update is in progress
   * @return {boolean}
   */


  function getIsManifestUpdateInProgress() {
    return manifestUpdateInProgress;
  }
  /**
   * Returns the availabilityStartTime
   * @return {number}
   */


  function getAvailabilityStartTime() {
    return availabilityStartTime;
  }
  /**
   * Returns the current live delay. A seek triggered by the user adjusts this value.
   * @return {number}
   */


  function getLiveDelay() {
    return liveDelay;
  }
  /**
   * Returns the original live delay as calculated at playback start
   */


  function getOriginalLiveDelay() {
    return originalLiveDelay;
  }
  /**
   * Returns the current live latency
   * @return {number}
   */


  function getCurrentLiveLatency() {
    if (!isDynamic || isNaN(availabilityStartTime)) {
      return NaN;
    }

    var currentTime = getTime();

    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);
  }
  /**
   * 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 MIN_BUFFER_TIME_FACTOR = 4;
    var FRAGMENT_DURATION_FACTOR = 4;
    var adjustedFragmentDuration = !isNaN(fragmentDuration) && isFinite(fragmentDuration) ? fragmentDuration : NaN;
    var suggestedPresentationDelay = adapter.getSuggestedPresentationDelay();
    var serviceDescriptionSettings = serviceDescriptionController.getServiceDescriptionSettings(); // Live delay specified by the user

    if (!isNaN(settings.get().streaming.delay.liveDelay)) {
      delay = settings.get().streaming.delay.liveDelay;
    } // Live delay fragment count specified by the user
    else if (settings.get().streaming.delay.liveDelayFragmentCount !== null && !isNaN(settings.get().streaming.delay.liveDelayFragmentCount) && !isNaN(adjustedFragmentDuration)) {
      delay = adjustedFragmentDuration * settings.get().streaming.delay.liveDelayFragmentCount;
    } // Live delay set via ServiceDescription element
    else if (serviceDescriptionSettings && !isNaN(serviceDescriptionSettings.liveDelay) && serviceDescriptionSettings.liveDelay > 0) {
      delay = serviceDescriptionSettings.liveDelay;
    } // Live delay set in the manifest using @suggestedPresentation Delay
    else if (settings.get().streaming.delay.useSuggestedPresentationDelay === true && suggestedPresentationDelay !== null && !isNaN(suggestedPresentationDelay) && suggestedPresentationDelay > 0) {
      delay = suggestedPresentationDelay;
    } // We found a fragment duration, use that to calculcate live delay
    else if (!isNaN(adjustedFragmentDuration)) {
      delay = adjustedFragmentDuration * FRAGMENT_DURATION_FACTOR;
    } // Fall back to @minBufferTime to calculate the live delay
    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) {
      // Latency can not be higher than DVR window size
      ret = Math.min(delay, manifestInfo.dvrWindowSize);
    } else {
      ret = delay;
    }

    liveDelay = ret;
    originalLiveDelay = ret;
    return ret;
  }

  function setConfig(config) {
    if (!config) return;

    if (config.streamController) {
      streamController = config.streamController;
    }

    if (config.serviceDescriptionController) {
      serviceDescriptionController = config.serviceDescriptionController;
    }

    if (config.dashMetrics) {
      dashMetrics = config.dashMetrics;
    }

    if (config.adapter) {
      adapter = config.adapter;
    }

    if (config.videoModel) {
      videoModel = config.videoModel;
    }

    if (config.timelineConverter) {
      timelineConverter = config.timelineConverter;
    }

    if (config.settings) {
      settings = config.settings;
    }
  }
  /**
   * 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 = getTime();

    var actualTime = _getAdjustedPresentationTime(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, false, false);
    }
  }
  /**
   * Adjust the presentation time based on the DVR window. If we are out of the DVR window we return a corrected time
   * @param {number} currentTime
   * @param {string} mediatype
   * @return {number}
   * @private
   */


  function _getAdjustedPresentationTime(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 (lowLatencyModeEnabled) {
        actualTime = Math.max(DVRWindow.end - liveDelay, DVRWindow.start);
      } else {
        actualTime = DVRWindow.start;
      }
    } else {
      actualTime = currentTime;
    }

    return actualTime;
  }
  /**
   * Start interval handler for wallclock time update
   */


  function startUpdatingWallclockTime() {
    if (wallclockTimeIntervalId !== null) return;
    wallclockTimeIntervalId = setInterval(function () {
      _onWallclockTime();
    }, settings.get().streaming.wallclockTimeUpdateInterval);
  }
  /**
   * Stop the interval handler for the wallclock time update
   */


  function stopUpdatingWallclockTime() {
    clearInterval(wallclockTimeIntervalId);
    wallclockTimeIntervalId = null;
  }

  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_2__["default"].CAN_PLAY);
  }

  function _onCanPlayThrough() {
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].CAN_PLAY_THROUGH);
  }

  function _onBufferLevelStateChanged(e) {
    // do not stall playback when get an event from Stream that is not active
    if (e.streamId !== streamController.getActiveStreamInfo().id) {
      return;
    }

    playbackStalled = e.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_EMPTY;

    if (settings.get().streaming.buffer.setStallState) {
      videoModel.setStallState(e.mediaType, e.state === _constants_MetricsConstants__WEBPACK_IMPORTED_MODULE_6__["default"].BUFFER_EMPTY);
    }
  }

  function _onPlaybackStart() {
    logger.info('Native video element event: play');
    updateCurrentTime();
    startUpdatingWallclockTime();
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_STARTED, {
      startTime: getTime()
    });
  }

  function _onPlaybackWaiting() {
    logger.info('Native video element event: waiting');
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_WAITING, {
      playingTime: getTime()
    });
  }

  function _onPlaybackPlaying() {
    logger.info('Native video element event: playing');
    internalSeek = false;
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PLAYING, {
      playingTime: getTime()
    });
  }

  function _onPlaybackPaused() {
    logger.info('Native video element event: pause');
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PAUSED, {
      ended: getEnded()
    });
  }

  function _onPlaybackSeeking() {
    // Check if internal seeking to be ignored
    if (internalSeek) {
      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_2__["default"].PLAYBACK_SEEKING, {
      seekTime: seekTime,
      streamId: streamInfo.id
    });
  }

  function _onPlaybackSeeked() {
    logger.info('Native video element event: seeked');
    internalSeek = false;
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_SEEKED);
  }

  function _onPlaybackTimeUpdated() {
    if (streamInfo) {
      eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_TIME_UPDATED, {
        timeToEnd: getTimeToStreamEnd(),
        time: getTime(),
        streamId: streamInfo.id
      });
    }
  }

  function _onPlaybackProgress() {
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["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_2__["default"].PLAYBACK_RATE_CHANGED, {
      playbackRate: rate
    });
  }

  function _onPlaybackMetaDataLoaded() {
    logger.info('Native video element event: loadedmetadata');
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_METADATA_LOADED);
    startUpdatingWallclockTime();
  }

  function _onPlaybackLoadedData() {
    logger.info('Native video element event: loadeddata');
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["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_2__["default"].PLAYBACK_ENDED, {
      'isLast': streamInfo.isLast
    });
  }

  function _onVolumeChanged() {
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_VOLUME_CHANGED);
  } // 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_2__["default"].PLAYBACK_ERROR, {
      error: target.error
    });
  }

  function _onWallclockTime() {
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["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();
    }
  }
  /**
   * Returns the combined minimum buffer level of all StreamProcessors. If a filter list is provided the types specified in the filter list are excluded.
   * @param {array} filterList StreamProcessor types to exclude
   * @return {null}
   */


  function getBufferLevel() {
    var filterList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
    var bufferLevel = null;
    streamController.getActiveStreamProcessors().forEach(function (p) {
      if (!filterList || filterList.length === 0 || filterList.indexOf(p.getType()) === -1) {
        var bl = p.getBufferLevel();

        if (bufferLevel === null) {
          bufferLevel = bl;
        } else {
          bufferLevel = Math.min(bufferLevel, bl);
        }
      }
    });
    return bufferLevel;
  }
  /**
   * Returns the value of lowLatencyModeEnabled
   * @return {boolean} lowLatencyModeEnabled
   */


  function getLowLatencyModeEnabled() {
    return lowLatencyModeEnabled;
  }

  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 && lowLatencyModeEnabled && !isNaN(e.request.duration)) {
      var minDelay = 1.2 * e.request.duration;

      if (minDelay > liveDelay) {
        logger.warn('Browser does not support fetch API with StreamReader. Increasing live delay to be 20% higher than segment duration:', minDelay.toFixed(2));
        liveDelay = minDelay;
        originalLiveDelay = minDelay;
      }
    }
  }

  function onPlaybackStalled(e) {
    eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["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 (!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;
    }

    availabilityTimeComplete = e.currentRepresentation.availabilityTimeComplete;
    lowLatencyModeEnabled = !availabilityTimeComplete; // If we enable low latency mode for the first time we also enable the catchup mechanism. This can be deactivated again for instance if the user seeks within the DVR window. We leave deactivation up to the application but also do not activate automatically again.

    if (lowLatencyModeEnabled && !initialCatchupModeActivated) {
      initialCatchupModeActivated = true;
    }
  }

  function getInitialCatchupModeActivated() {
    return initialCatchupModeActivated;
  }
  /**
   * 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_DVB_LL_SCHEME] === 'true') {
      logger.debug('Low Latency critical SupplementalProperty set: Enabling low Latency');
      lowLatencyModeEnabled = 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);
    videoModel.addEventListener('volumechange', _onVolumeChanged);
  }

  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);
    videoModel.removeEventListener('volumechange', _onVolumeChanged);
  }

  instance = {
    initialize: initialize,
    setConfig: setConfig,
    getTimeToStreamEnd: getTimeToStreamEnd,
    getBufferLevel: getBufferLevel,
    getPlaybackStalled: getPlaybackStalled,
    getTime: getTime,
    getLowLatencyModeEnabled: getLowLatencyModeEnabled,
    getInitialCatchupModeActivated: getInitialCatchupModeActivated,
    getIsManifestUpdateInProgress: getIsManifestUpdateInProgress,
    getPlaybackRate: getPlaybackRate,
    getPlayedRanges: getPlayedRanges,
    getEnded: getEnded,
    getIsDynamic: getIsDynamic,
    getStreamController: getStreamController,
    computeAndSetLiveDelay: computeAndSetLiveDelay,
    getLiveDelay: getLiveDelay,
    getOriginalLiveDelay: getOriginalLiveDelay,
    getCurrentLiveLatency: getCurrentLiveLatency,
    play: play,
    isPaused: isPaused,
    isStalled: isStalled,
    pause: pause,
    isSeeking: isSeeking,
    getStreamEndTime: getStreamEndTime,
    seek: seek,
    seekToOriginalLive: seekToOriginalLive,
    seekToCurrentLive: seekToCurrentLive,
    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_3__["default"].getSingletonFactory(PlaybackController));

/***/ }),

/***/ "./src/streaming/controllers/ScheduleController.js":
/*!*********************************************************!*\
  !*** ./src/streaming/controllers/ScheduleController.js ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 representationController = config.representationController;
  var settings = config.settings;
  var instance, streamInfo, logger, timeToLoadDelay, scheduleTimeout, hasVideoTrack, lastFragmentRequest, topQualityIndex, lastInitializedQuality, switchTrack, initSegmentRequired, checkPlaybackQuality;

  function setup() {
    logger = (0,_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"].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 startScheduleTimer(value) {
    //return if both buffering and playback have ended
    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(playbackController.getLowLatencyModeEnabled() ? settings.get().streaming.scheduling.lowLatencyTimeout : settings.get().streaming.scheduling.defaultTimeout);
      }
    } catch (e) {
      startScheduleTimer(playbackController.getLowLatencyModeEnabled() ? 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() {
    var currentRepresentationInfo = representationController.getCurrentRepresentationInfo(); // 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 {
      var currentRepresentationInfo = representationController.getCurrentRepresentationInfo();
      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() {
    var currentRepresentationInfo = representationController.getCurrentRepresentationInfo();

    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;
    var currentRepresentationInfo = representationController.getCurrentRepresentationInfo();

    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()) {
        var currentRepresentationInfo = representationController.getCurrentRepresentationInfo();

        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);
      var currentRepresentationInfo = representationController.getCurrentRepresentationInfo(); // 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 currentRepresentationInfo = representationController.getCurrentRepresentationInfo();
      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 getSwitchTrack() {
    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.index !== lastFragmentRequest.mediaInfo.index) && 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 _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 setLastInitializedQuality(value) {
    lastInitializedQuality = 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"].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,
    setTimeToLoadDelay: setTimeToLoadDelay,
    getTimeToLoadDelay: getTimeToLoadDelay,
    setSwitchTrack: setSwitchTrack,
    getSwitchTrack: getSwitchTrack,
    startScheduleTimer: startScheduleTimer,
    clearScheduleTimer: clearScheduleTimer,
    reset: reset,
    getBufferTarget: getBufferTarget,
    getPlaybackController: getPlaybackController,
    setCheckPlaybackQuality: setCheckPlaybackQuality,
    setInitSegmentRequired: setInitSegmentRequired,
    setLastInitializedQuality: setLastInitializedQuality
  };
  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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _TimeSyncController__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./TimeSyncController */ "./src/streaming/controllers/TimeSyncController.js");
/* harmony import */ var _MediaSourceController__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./MediaSourceController */ "./src/streaming/controllers/MediaSourceController.js");
/* harmony import */ var _vo_DashJSError__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../vo/DashJSError */ "./src/streaming/vo/DashJSError.js");
/* harmony import */ var _core_errors_Errors__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../core/errors/Errors */ "./src/core/errors/Errors.js");
/* harmony import */ var _EventController__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./EventController */ "./src/streaming/controllers/EventController.js");
/* harmony import */ var _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_16__ = __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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
  var instance, logger, capabilities, capabilitiesFilter, manifestUpdater, manifestLoader, manifestModel, adapter, dashMetrics, mediaSourceController, timeSyncController, contentSteeringController, baseURLController, segmentBaseController, uriFragmentModel, abrController, mediaController, eventController, initCache, errHandler, timelineConverter, streams, activeStream, protectionController, textController, protectionData, autoPlay, isStreamSwitchingInProgress, hasMediaError, hasInitialisationError, mediaSource, videoModel, playbackController, serviceDescriptionController, mediaPlayerModel, customParametersModel, isPaused, initialPlayback, initialSteeringRequest, playbackEndedTimerInterval, bufferSinks, preloadingStreams, supportsChangeType, settings, firstLicenseIsFetched, waitForPlaybackStartTimeout, providedStartTime, errorInformation;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance().getLogger(instance);
    timeSyncController = (0,_TimeSyncController__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
    mediaSourceController = (0,_MediaSourceController__WEBPACK_IMPORTED_MODULE_12__["default"])(context).getInstance();
    initCache = (0,_utils_InitCache__WEBPACK_IMPORTED_MODULE_9__["default"])(context).getInstance();
    resetInitialSettings();
  }

  function initialize(autoPl, protData) {
    _checkConfig();

    autoPlay = autoPl;
    protectionData = protData;
    timelineConverter.initialize();
    manifestUpdater = (0,_ManifestUpdater__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create();
    manifestUpdater.setConfig({
      manifestModel: manifestModel,
      adapter: adapter,
      manifestLoader: manifestLoader,
      errHandler: errHandler,
      settings: settings,
      contentSteeringController: contentSteeringController
    });
    manifestUpdater.initialize();
    eventController = (0,_EventController__WEBPACK_IMPORTED_MODULE_15__["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();
    mediaSourceController.setConfig({
      settings: settings
    });

    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_10__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_ERROR, _onPlaybackError, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_STARTED, _onPlaybackStarted, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_PAUSED, _onPlaybackPaused, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].METRIC_ADDED, _onMetricAdded, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_VALIDITY_CHANGED, _onManifestValidityChanged, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].BUFFER_LEVEL_UPDATED, _onBufferLevelUpdated, instance);
    eventBus.on(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["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);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_LIVE_DELAY, _onLiveDelaySettingUpdated, instance);
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_LIVE_DELAY_FRAGMENT_COUNT, _onLiveDelaySettingUpdated, instance);
  }

  function unRegisterEvents() {
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_ERROR, _onPlaybackError, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_STARTED, _onPlaybackStarted, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_PAUSED, _onPlaybackPaused, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].PLAYBACK_ENDED, _onPlaybackEnded, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].METRIC_ADDED, _onMetricAdded, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_VALIDITY_CHANGED, _onManifestValidityChanged, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["default"].BUFFER_LEVEL_UPDATED, _onBufferLevelUpdated, instance);
    eventBus.off(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_10__["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);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_LIVE_DELAY, _onLiveDelaySettingUpdated, instance);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_5__["default"].SETTING_UPDATED_LIVE_DELAY_FRAGMENT_COUNT, _onLiveDelaySettingUpdated, instance);
  }

  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');
    }
  }
  /**
   * Start the streaming session by loading the target manifest
   * @param {string} url
   * @param {number} startTime
   */


  function load(url) {
    var startTime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NaN;

    _checkConfig();

    providedStartTime = startTime;
    manifestLoader.load(url);
  }
  /**
   * Start the streaming session by using the provided manifest object
   * @param {object} manifest
   * @param {number} startTime
   */


  function loadWithManifest(manifest) {
    var startTime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NaN;

    _checkInitialize();

    providedStartTime = startTime;
    manifestUpdater.setManifest(manifest);
  }
  /**
   * When the UTC snychronization is completed we can compose the streams
   * @private
   */


  function _onTimeSyncCompleted() {
    _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 periods in the MPD');
      }

      if (activeStream && streamsInfo.length > 0) {
        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 () {
        return new Promise(function (resolve, reject) {
          if (!activeStream) {
            _initializeForFirstStream(streamsInfo, resolve, reject);
          } else {
            resolve();
          }
        });
      }).then(function () {
        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_13__["default"](_core_errors_Errors__WEBPACK_IMPORTED_MODULE_14__["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 = (0,_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 {array} streamsInfo
   * @private
   */


  function _initializeForFirstStream(streamsInfo, resolve, reject) {
    try {
      // 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, resolve, reject);
        }, waitingTime);
        return;
      } // Calculate the producer reference time offsets if given


      if (settings.get().streaming.applyProducerReferenceTime) {
        serviceDescriptionController.calculateProducerReferenceTimeOffsets(streamsInfo);
      } // Apply Service description parameters.


      var manifestInfo = streamsInfo[0].manifestInfo;

      if (settings.get().streaming.applyServiceDescription) {
        serviceDescriptionController.applyServiceDescription(manifestInfo);
      } // Compute and set the live delay


      if (adapter.getIsDynamic()) {
        var fragmentDuration = _getFragmentDurationForLiveDelayCalculation(streamsInfo, manifestInfo);

        playbackController.computeAndSetLiveDelay(fragmentDuration, manifestInfo);
      } // Apply content steering


      _applyContentSteeringBeforeStart().then(function () {
        var manifest = manifestModel.getValue();

        if (manifest) {
          baseURLController.update(manifest);
        }

        _calculateStartTimeAndSwitchStream();

        resolve();
      })["catch"](function (e) {
        logger.error(e);

        _calculateStartTimeAndSwitchStream();

        resolve();
      });
    } catch (e) {
      reject(e);
    }
  }

  function _applyContentSteeringBeforeStart() {
    if (settings.get().streaming.applyContentSteering && contentSteeringController.shouldQueryBeforeStart()) {
      return contentSteeringController.loadSteeringData();
    }

    return Promise.resolve();
  }

  function _calculateStartTimeAndSwitchStream() {
    // 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 we have a video element we are not preloading into a virtual buffer

      if (videoModel.getElement()) {
        _openMediaSource(seekTime, keepBuffers, false);
      } else {
        _activateStream(seekTime, keepBuffers);
      }
    } catch (e) {
      isStreamSwitchingInProgress = false;
    }
  }
  /**
   * Setup the Media Source. Open MSE and attach event listeners
   * @param {number} seekTime
   * @param {boolean} keepBuffers
   * @param {boolean} streamActivated
   * @private
   */


  function _openMediaSource(seekTime, keepBuffers) {
    var streamActivated = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    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);

      if (streamActivated) {
        if (!isNaN(seekTime)) {
          playbackController.seek(seekTime, true, true);
        } // Set the media source for all StreamProcessors


        activeStream.setMediaSource(mediaSource).then(function () {
          // Start text processing now that we have a video element
          activeStream.initializeForTextWithMediaSource(mediaSource);
        });
      } else {
        _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 newTime = e.seekTime;
    var seekToStream = getStreamForTime(newTime);

    if (!seekToStream || seekToStream === activeStream) {
      _cancelPreloading();

      _handleInnerPeriodSeek(e);
    } else if (seekToStream && seekToStream !== activeStream) {
      _cancelPreloading(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 {object} seekToStream
   * @private
   */


  function _cancelPreloading() {
    var seekToStream = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

    // Inner period seek
    if (!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
   * @param {number} oldTime
   * @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();

    if (settings.get().streaming.buffer.resetSourceBuffersForTrackSwitch && e.oldMediaInfo && e.oldMediaInfo.codec !== e.newMediaInfo.codec) {
      var time = playbackController.getTime();
      activeStream.deactivate(false);

      _openMediaSource(time, false, false);

      return;
    }

    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 && settings.get().streaming.buffer.useChangeTypeForTrackSwitch || 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();
      var excludedStreamProcessors = [_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT];

      if (isNaN(initialBufferLevel) || initialBufferLevel <= playbackController.getBufferLevel(excludedStreamProcessors) || 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);
  }
  /**
   * A setting related to the live delay was updated. Check if one of the latency values changed. If so, recalculate the live delay.
   * @private
   */


  function _onLiveDelaySettingUpdated() {
    if (adapter.getIsDynamic() && playbackController.getOriginalLiveDelay() !== 0 && activeStream) {
      var streamsInfo = adapter.getStreamsInfo();

      if (streamsInfo.length > 0) {
        var manifestInfo = streamsInfo[0].manifestInfo;

        var fragmentDuration = _getFragmentDurationForLiveDelayCalculation(streamsInfo, manifestInfo);

        playbackController.computeAndSetLiveDelay(fragmentDuration, manifestInfo);
      }
    }
  }
  /**
   * When the playback time is updated we add the droppedFrames metric to the dash metric object
   * @private
   */


  function _onPlaybackTimeUpdated() {
    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() {
    logger.debug('[onPlaybackStarted]');

    if (!initialPlayback && isPaused) {
      _createPlaylistMetrics(_vo_metrics_PlayList__WEBPACK_IMPORTED_MODULE_7__.PlayList.RESUME_FROM_PAUSE_START_REASON);
    }

    if (initialPlayback) {
      initialPlayback = false;
    }

    if (initialSteeringRequest) {
      initialSteeringRequest = false; // If this is the initial playback attempt and we have not yet triggered content steering now is the time

      if (settings.get().streaming.applyContentSteering && !contentSteeringController.shouldQueryBeforeStart()) {
        contentSteeringController.loadSteeringData();
      }
    }

    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();

      contentSteeringController.stopSteeringRequestTimer();
    }
  }
  /**
   * 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 via the application
    // - at start time provided in URI parameters
    // - at stream/period start time (for static streams) or live start time (for dynamic streams)
    var startTime;
    var isDynamic = adapter.getIsDynamic();

    if (isDynamic) {
      // 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.getOriginalLiveDelay(); // 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) {
        // If start time was provided by the application as part of the call to initialize() or attachSource() use this value
        if (!isNaN(providedStartTime) || providedStartTime.toString().indexOf('posix:') !== -1) {
          logger.info("Start time provided by the app: ".concat(providedStartTime));

          var providedStartTimeAsPresentationTime = _getStartTimeFromProvidedData(true, providedStartTime);

          if (!isNaN(providedStartTimeAsPresentationTime)) {
            // Do not move closer to the live edge as defined by live delay
            startTime = Math.min(startTime, providedStartTimeAsPresentationTime);
          }
        } else {
          // #t shall be relative to period start
          var startTimeFromUri = _getStartTimeFromUriParameters(true);

          if (!isNaN(startTimeFromUri)) {
            logger.info("Start time from URI parameters: ".concat(startTimeFromUri)); // Do not move closer to the live edge as defined by live delay

            startTime = Math.min(startTime, startTimeFromUri);
          }
        } // If calcFromSegmentTimeline is enabled we saw problems caused by the MSE.seekableRange when starting at dvrWindow.start. Apply a small offset to avoid this problem.


        var offset = settings.get().streaming.timeShiftBuffer.calcFromSegmentTimeline ? 0.1 : 0;
        startTime = Math.max(startTime, dvrWindow.start + offset);
      }
    } else {
      // For static stream, start by default at period start
      var _streams = getStreams();

      var streamInfo = _streams[0].getStreamInfo();

      startTime = streamInfo.start; // If start time was provided by the application as part of the call to initialize() or attachSource() use this value

      if (!isNaN(providedStartTime)) {
        logger.info("Start time provided by the app: ".concat(providedStartTime));

        var _providedStartTimeAsPresentationTime = _getStartTimeFromProvidedData(false, providedStartTime);

        if (!isNaN(_providedStartTimeAsPresentationTime)) {
          // Do not play earlier than the start of the first period
          startTime = Math.max(startTime, _providedStartTimeAsPresentationTime);
        }
      } else {
        // 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: ".concat(_startTimeFromUri)); // Do not play earlier than the start of the first period

          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 referenceTime = refStream.getStreamInfo().start;
    fragData.t = fragData.t.split(',')[0];
    return _getStartTimeFromString(isDynamic, fragData.t, referenceTime);
  }
  /**
   * Calculate start time using the value that was provided via the application as part of attachSource() or initialize()
   * @param {boolean} isDynamic
   * @param {number | string} providedStartTime
   * @return {number}
   * @private
   */


  function _getStartTimeFromProvidedData(isDynamic, providedStartTime) {
    var referenceTime = 0;

    if (!isDynamic) {
      var refStream = getStreams()[0];
      referenceTime = refStream.getStreamInfo().start;
    }

    return _getStartTimeFromString(isDynamic, providedStartTime, referenceTime);
  }

  function _getStartTimeFromString(isDynamic, targetValue, referenceTime) {
    // Consider only start time of MediaRange
    // TODO: consider end time of MediaRange to stop playback at provided end time
    // "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 period = adapter.getRegularPeriods()[0];
    var targetString = targetValue.toString();
    var posix = targetString.indexOf('posix:') !== -1 ? targetString.substring(6) === 'now' ? Date.now() / 1000 : parseFloat(targetString.substring(6)) : NaN;
    var startTime = isDynamic && !isNaN(posix) ? timelineConverter.calcPresentationTimeFromWallTime(new Date(posix * 1000), period) : parseFloat(targetString) + referenceTime;
    return startTime;
  }
  /**
   * Streams that are no longer in the manifest can be filtered
   * @param {object} streamsInfo
   * @private
   */


  function _filterOutdatedStreams(streamsInfo) {
    if (streamsInfo.length === 0) {
      logger.warn("No periods included in the current manifest. Skipping the filtering of outdated stream objects.");
      return;
    }

    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_10__["default"].CONFORMANCE_VIOLATION, {
          level: _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_16__["default"].LEVELS.WARNING,
          event: _constants_ConformanceViolationConstants__WEBPACK_IMPORTED_MODULE_16__["default"].EVENTS.NO_UTC_TIMING_ELEMENT
        });
      }

      var allUTCTimingSources = !adapter.getIsDynamic() ? manifestUTCTimingSources : manifestUTCTimingSources.concat(customParametersModel.getUTCTimingSources()); // 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, true);
    }
  }

  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_13__["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, 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 _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.customParametersModel) {
      customParametersModel = config.customParametersModel;
    }

    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.serviceDescriptionController) {
      serviceDescriptionController = config.serviceDescriptionController;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }

    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 = [];
    providedStartTime = NaN;
    protectionController = null;
    isStreamSwitchingInProgress = false;
    activeStream = null;
    hasMediaError = false;
    hasInitialisationError = false;
    initialPlayback = true;
    initialSteeringRequest = 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 ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
  var urlUtils = (0,_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 = (0,_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 || 0;
    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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  var urlUtils = (0,_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 = (0,_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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_utils_DVBErrorsTranslator__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance({
      eventBus: config.eventBus,
      dashMetrics: config.dashMetrics,
      metricsConstants: config.metricsConstants,
      events: config.events
    });
    dvbErrorsTranslator.initialize();
    return (0,_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 (0,_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 (0,_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 ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**************************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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 ***!
  \****************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_RangeController__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
        mediaElement: config.mediaElement
      });
      rangeController.initialize(metricsEntry.Range);
      reportingController = (0,_ReportingController__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
        debug: config.debug,
        metricsConstants: config.metricsConstants,
        mediaPlayerModel: config.mediaPlayerModel
      });
      reportingController.initialize(metricsEntry.Reporting, rangeController);
      metricsHandlersController = (0,_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 ***!
  \************************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \**************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \******************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \****************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**********************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \********************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*******************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \*************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;
  var mediaPlayerModel = config.mediaPlayerModel || {};

  function create(entry, rangeController) {
    var reporting;

    try {
      reporting = knownReportingSchemeIdUris[entry.schemeIdUri](context).create({
        metricsConstants: metricsConstants,
        mediaPlayerModel: mediaPlayerModel
      });
      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 ***!
  \*******************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _models_CustomParametersModel__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../models/CustomParametersModel */ "./src/streaming/models/CustomParametersModel.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, customParametersModel, randomNumberGenerator, reportingPlayerStatusDecided, isReportingPlayer, reportingUrl, rangeController;
  var USE_DRAFT_DVB_SPEC = true;
  var allowPendingRequestsToCompleteOnReset = true;
  var pendingRequests = [];
  var metricsConstants = config.metricsConstants;

  function setup() {
    metricSerialiser = (0,_utils_MetricSerialiser__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
    randomNumberGenerator = (0,_utils_RNG__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
    customParametersModel = (0,_models_CustomParametersModel__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
    resetInitialSettings();
  }

  function doGetRequest(url, successCB, failureCB) {
    var req = new XMLHttpRequest();
    req.withCredentials = customParametersModel.getXHRWithCredentialsForType(metricsConstants.HTTP_REQUEST_DVB_REPORTING_TYPE);

    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 (USE_DRAFT_DVB_SPEC && 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() {
    if (!allowPendingRequestsToCompleteOnReset) {
      pendingRequests.forEach(function (req) {
        return req.abort();
      });
      pendingRequests = [];
    }

    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 ***!
  \************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 uninitialized
    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 initialize() {
    eventBus.on(Events.MANIFEST_UPDATED, onManifestUpdate, instance);
    eventBus.on(Events.SERVICE_LOCATION_BASE_URL_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_BASE_URL_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 = {
    initialize: initialize,
    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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 initialize() {
    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) {
        initialize();
      }

      r = randomNumbers[index] / MAX_VALUE;
      index += 1;
    } else {
      r = Math.random();
    }

    return r * (max - min) + min;
  }

  instance = {
    random: rand
  };
  initialize();
  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 ***!
  \***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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, contentSteeringController;
  var context = this.context;
  var objectUtils = (0,_utils_ObjectUtils__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();

  function setup() {
    reset();
  }

  function setConfig(config) {
    if (config.adapter) {
      adapter = config.adapter;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }
  }

  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 = _getAvailableBaseUrls(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 = _getAvailableBaseUrls(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 _getAvailableBaseUrls(root) {
    var targetBaseUrls = adapter.getBaseURLsFromElement(root);
    var synthesizedBaseUrls = contentSteeringController.getSynthesizedBaseUrlElements(targetBaseUrls);

    if (synthesizedBaseUrls && synthesizedBaseUrls.length > 0) {
      targetBaseUrls = targetBaseUrls.concat(synthesizedBaseUrls);
    }

    return targetBaseUrls;
  }

  function getBaseUrls(manifest) {
    return _getAvailableBaseUrls(manifest);
  }

  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,
    getBaseUrls: getBaseUrls
  };
  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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();

  function setup() {
    dashManifestModel = (0,_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 filteredCmcdData = _applyWhitelist(cmcdData);

        var finalPayloadString = _buildFinalString(filteredCmcdData);

        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 _applyWhitelist(cmcdData) {
    try {
      var enabledCMCDKeys = settings.get().streaming.cmcd.enabledKeys;
      return Object.keys(cmcdData).filter(function (key) {
        return enabledCMCDKeys.includes(key);
      }).reduce(function (obj, key) {
        obj[key] = cmcdData[key];
        return obj;
      }, {});
    } catch (e) {
      return cmcdData;
    }
  }

  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, _applyWhitelistByKeys(['br', 'd', 'ot', 'tb']));

        var cmcdRequestHeader = _copyParameters(cmcdData, _applyWhitelistByKeys(['bl', 'dl', 'mtp', 'nor', 'nrr', 'su']));

        var cmcdStatusHeader = _copyParameters(cmcdData, _applyWhitelistByKeys(['bs', 'rtp']));

        var cmcdSessionHeader = _copyParameters(cmcdData, _applyWhitelistByKeys(['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 _applyWhitelistByKeys(keys) {
    var enabledCMCDKeys = settings.get().streaming.cmcd.enabledKeys;
    return keys.filter(function (key) {
      return enabledCMCDKeys.includes(key);
    });
  }

  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);
    }

    if (!isNaN(rtp)) {
      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) : NaN;
    } 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') {
          acc += "".concat(key, "=").concat(JSON.stringify(cmcdData[key]));
        } 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) {
    try {
      // 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;

      if (!mediaInfo) {
        return NaN;
      }

      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
      // Round to the next multiple of 100

      return (parseInt(maxBandwidth / 100) + 1) * 100;
    } catch (e) {
      return NaN;
    }
  }

  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/CmsdModel.js":
/*!*******************************************!*\
  !*** ./src/streaming/models/CmsdModel.js ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
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 _wrapRegExp(re, groups) { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _RegExp = _wrapNativeSuper(RegExp); var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = _RegExp.call(this, re, flags); _groups.set(_this, groups || _groups.get(re)); return _this; } _inherits(BabelRegExp, _RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = []; args.push.apply(args, arguments); if (_typeof(args[args.length - 1]) !== "object") { args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }

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 _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 _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }

function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }

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 _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

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) 2022, 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.
 */



 // Note: in modern browsers, the header names are returned in all lower case

var CMSD_STATIC = 'static';
var CMSD_DYNAMIC = 'dynamic';
var CMSD_RESPONSE_FIELD_BASENAME = 'cmsd-';
var CMSD_STATIC_RESPONSE_FIELD_NAME = CMSD_RESPONSE_FIELD_BASENAME + CMSD_STATIC;
var CMSD_DYNAMIC_RESPONSE_FIELD_NAME = CMSD_RESPONSE_FIELD_BASENAME + CMSD_DYNAMIC;
var CMSD_KEYS = {
  AVAILABILITY_TIME: 'at',
  DURESS: 'du',
  ENCODED_BITRATE: 'br',
  ESTIMATED_THROUGHPUT: 'etp',
  HELD_TIME: 'ht',
  INTERMEDIARY_IDENTIFIER: 'n',
  MAX_SUGGESTED_BITRATE: 'mb',
  NEXT_OBJECT_RESPONSE: 'nor',
  NEXT_RANGE_RESPONSE: 'nrr',
  OBJECT_DURATION: 'd',
  OBJECT_TYPE: 'ot',
  RESPONSE_DELAY: 'rd',
  ROUND_TRIP_TIME: 'rtt',
  STARTUP: 'su',
  STREAM_TYPE: 'st',
  STREAMING_FORMAT: 'sf',
  VERSION: 'v'
};
var OBJECT_TYPES = {
  MANIFEST: 'm',
  AUDIO: 'a',
  VIDEO: 'v',
  INIT: 'i',
  CAPTION: 'c',
  ISOBMFF_TEXT_TRACK: 'tt',
  ENCRYPTION_KEY: 'k',
  OTHER: 'o',
  STREAM: 'stream' // Specific value for parameters without object type, which apply for all media/objects

};
var PERSISTENT_PARAMS = [CMSD_KEYS.MAX_SUGGESTED_BITRATE, CMSD_KEYS.STREAM_TYPE, CMSD_KEYS.STREAMING_FORMAT, CMSD_KEYS.VERSION];
var MEDIATYPE_TO_OBJECTTYPE = {
  'video': OBJECT_TYPES.VIDEO,
  'audio': OBJECT_TYPES.AUDIO,
  'text': OBJECT_TYPES.ISOBMFF_TEXT_TRACK,
  'stream': OBJECT_TYPES.STREAM
};
var integerRegex = /^[-0-9]/;

function CmsdModel() {
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();

  var instance, logger, _staticParamsDict, _dynamicParamsDict;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance().getLogger(instance);

    _resetInitialSettings();
  }

  function initialize() {}

  function setConfig() {}

  function _resetInitialSettings() {
    _staticParamsDict = {};
    _dynamicParamsDict = {};
  }

  function _clearParams(params) {
    if (!params) {
      return;
    }

    Object.keys(params).forEach(function (key) {
      if (!PERSISTENT_PARAMS.includes(key)) {
        delete params[key];
      }
    });
  }

  function _parseParameterValue(value) {
    // If the value type is BOOLEAN and the value is TRUE, then the equals sign and the value are omitted
    if (!value) {
      return true;
    } // Check if boolean 'false'


    if (value.toLowerCase() === 'false') {
      return false;
    } // Check if a number


    if (integerRegex.test(value)) {
      return parseInt(value, 10);
    } // Value is a string, remove double quotes from string value


    return value.replace(/["]+/g, '');
  }

  function _parseCMSDStatic(value) {
    try {
      var params = {};
      var items = value.split(',');

      for (var i = 0; i < items.length; i++) {
        // <key>=<value>
        var substrs = items[i].split('=');
        var key = substrs[0];

        var v = _parseParameterValue(substrs[1]);

        params[key] = v;
      }

      return params;
    } catch (e) {
      logger.error('Failed to parse CMSD-Static response header value:', e);
    }
  }

  function _parseCMSDDynamic(value) {
    try {
      var params = {};
      var entries = value.split(','); // Consider only last CMSD-Dynamic entry

      var entry = entries[entries.length - 1];
      var items = entry.split(';'); // Server identifier as 1st item

      for (var i = 1; i < items.length; i++) {
        // <key>=<value>
        var substrs = items[i].split('=');
        var key = substrs[0];

        var v = _parseParameterValue(substrs[1]);

        params[key] = v;
      }

      return params;
    } catch (e) {
      logger.error('Failed to parse CMSD-Dynamic response header value:', e);
      return [];
    }
  }

  function _mediaTypetoObjectType(mediaType) {
    return MEDIATYPE_TO_OBJECTTYPE[mediaType] || OBJECT_TYPES.OTHER;
  }

  function _getParamValueForObjectType(paramsType, ot, key) {
    var params = paramsType === CMSD_STATIC ? _staticParamsDict : _dynamicParamsDict;
    var otParams = params[ot] || {};
    var streamParams = params[OBJECT_TYPES.STREAM] || {};
    var value = otParams[key] || streamParams[key];
    return value;
  }

  function parseResponseHeaders(responseHeaders, mediaType) {
    var staticParams = null;
    var dynamicParams = null;
    var headers = responseHeaders.split('\r\n'); // Ge in reverse order in order to consider only last CMSD-Dynamic header

    for (var i = headers.length - 1; i >= 0; i--) {
      var header = headers[i];
      var m = header.match( /*#__PURE__*/_wrapRegExp(/^((?:(?!:)[\s\S])*):[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*(.*)$/, {
        key: 1,
        value: 2
      }));

      if (m && m.groups) {
        // Note: in modern browsers, the header names are returned in all lower case
        var key = m.groups.key.toLowerCase(),
            value = m.groups.value;

        switch (key) {
          case CMSD_STATIC_RESPONSE_FIELD_NAME:
            staticParams = _parseCMSDStatic(value);
            eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].CMSD_STATIC_HEADER, staticParams);
            break;

          case CMSD_DYNAMIC_RESPONSE_FIELD_NAME:
            if (!dynamicParams) {
              dynamicParams = _parseCMSDDynamic(value);
            }

            break;

          default:
            break;
        }
      }
    } // Get object type


    var ot = OBJECT_TYPES.STREAM;

    if (staticParams && staticParams[CMSD_KEYS.OBJECT_TYPE]) {
      ot = staticParams[CMSD_KEYS.OBJECT_TYPE];
    } else if (mediaType) {
      ot = _mediaTypetoObjectType(mediaType);
    } // Clear previously received params except persistent ones 


    _clearParams(_staticParamsDict[ot]);

    _clearParams(_dynamicParamsDict[ot]); // Merge params with previously received params 


    if (staticParams) {
      _staticParamsDict[ot] = Object.assign(_staticParamsDict[ot] || {}, staticParams);
    }

    if (dynamicParams) {
      _dynamicParamsDict[ot] = Object.assign(_dynamicParamsDict[ot] || {}, dynamicParams);
    }

    return {
      "static": staticParams,
      dynamic: dynamicParams
    };
  }

  function getMaxBitrate(type) {
    var ot = _mediaTypetoObjectType(type);

    var mb = _getParamValueForObjectType(CMSD_DYNAMIC, ot, CMSD_KEYS.MAX_SUGGESTED_BITRATE);

    return mb ? mb : -1;
  }

  function getEstimatedThroughput(type) {
    var ot = _mediaTypetoObjectType(type);

    var etp = _getParamValueForObjectType(CMSD_DYNAMIC, ot, CMSD_KEYS.ESTIMATED_THROUGHPUT);

    return etp ? etp : null;
  }

  function getResponseDelay(type) {
    var ot = _mediaTypetoObjectType(type);

    var rd = _getParamValueForObjectType(CMSD_DYNAMIC, ot, CMSD_KEYS.RESPONSE_DELAY);

    return rd ? rd : null;
  }

  function getRoundTripTime(type) {
    var ot = _mediaTypetoObjectType(type);

    var rd = _getParamValueForObjectType(CMSD_DYNAMIC, ot, CMSD_KEYS.ROUND_TRIP_TIME);

    return rd ? rd : null;
  }

  function reset() {
    _resetInitialSettings();
  }

  instance = {
    setConfig: setConfig,
    initialize: initialize,
    reset: reset,
    parseResponseHeaders: parseResponseHeaders,
    getMaxBitrate: getMaxBitrate,
    getEstimatedThroughput: getEstimatedThroughput,
    getResponseDelay: getResponseDelay,
    getRoundTripTime: getRoundTripTime
  };
  setup();
  return instance;
}

CmsdModel.__dashjs_factory_name = 'CmsdModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(CmsdModel));

/***/ }),

/***/ "./src/streaming/models/CustomParametersModel.js":
/*!*******************************************************!*\
  !*** ./src/streaming/models/CustomParametersModel.js ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _core_Settings__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/SupervisorTools */ "./src/streaming/utils/SupervisorTools.js");
/* harmony import */ var _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../rules/abr/ABRRulesCollection */ "./src/streaming/rules/abr/ABRRulesCollection.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_5__ = __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 DEFAULT_XHR_WITH_CREDENTIALS = false;

function CustomParametersModel() {
  var instance, utcTimingSources, xhrWithCredentials, licenseRequestFilters, licenseResponseFilters, customCapabilitiesFilters, customInitialTrackSelectionFunction, customAbrRules;
  var context = this.context;
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();

  function setup() {
    xhrWithCredentials = {
      "default": DEFAULT_XHR_WITH_CREDENTIALS
    };

    _resetInitialSettings();
  }

  function _resetInitialSettings() {
    licenseRequestFilters = [];
    licenseResponseFilters = [];
    customCapabilitiesFilters = [];
    customAbrRules = [];
    customInitialTrackSelectionFunction = null;
    utcTimingSources = [];
  }

  function reset() {
    _resetInitialSettings();
  }

  function setConfig() {}
  /**
   * 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) {
    customInitialTrackSelectionFunction = customFunc;
  }
  /**
   * Resets the custom initial track selection
   */


  function resetCustomInitialTrackSelectionFunction() {
    customInitialTrackSelectionFunction = null;
  }
  /**
   * Returns the initial track selection function
   * @return {function}
   */


  function getCustomInitialTrackSelectionFunction() {
    return customInitialTrackSelectionFunction;
  }
  /**
   * Returns all license request filters
   * @return {array}
   */


  function getLicenseRequestFilters() {
    return licenseRequestFilters;
  }
  /**
   * Returns all license response filters
   * @return {array}
   */


  function getLicenseResponseFilters() {
    return licenseResponseFilters;
  }
  /**
   * 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
   */


  function registerLicenseRequestFilter(filter) {
    licenseRequestFilters.push(filter);
  }
  /**
   * 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
   */


  function registerLicenseResponseFilter(filter) {
    licenseResponseFilters.push(filter);
  }
  /**
   * Unregisters a license request filter.
   * @param {function} filter - the license request filter callback
   */


  function unregisterLicenseRequestFilter(filter) {
    _unregisterFilter(licenseRequestFilters, filter);
  }
  /**
   * Unregisters a license response filter.
   * @param {function} filter - the license response filter callback
   */


  function unregisterLicenseResponseFilter(filter) {
    _unregisterFilter(licenseResponseFilters, filter);
  }
  /**
   * Returns all custom capabilities filter
   * @return {array}
   */


  function getCustomCapabilitiesFilters() {
    return customCapabilitiesFilters;
  }
  /**
   * 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
   */


  function registerCustomCapabilitiesFilter(filter) {
    customCapabilitiesFilters.push(filter);
  }
  /**
   * Unregisters a custom capabilities filter.
   * @param {function} filter - the custom capabilities filter callback
   */


  function unregisterCustomCapabilitiesFilter(filter) {
    _unregisterFilter(customCapabilitiesFilters, filter);
  }
  /**
   * Unregister a filter from the list of existing filers.
   * @param {array} filters
   * @param {function} filter
   * @private
   */


  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);
  }
  /**
   * Iterate through the list of custom ABR rules and find the right rule by name
   * @param {string} rulename
   * @return {number} rule number
   */


  function _findAbrCustomRuleIndex(rulename) {
    var i;

    for (i = 0; i < customAbrRules.length; i++) {
      if (customAbrRules[i].rulename === rulename) {
        return i;
      }
    }

    return -1;
  }
  /**
   * 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
   * @throws {@link Constants#BAD_ARGUMENT_ERROR BAD_ARGUMENT_ERROR} if called with invalid arguments.
   */


  function addAbrCustomRule(type, rulename, rule) {
    if (typeof type !== 'string' || type !== _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_4__["default"].ABANDON_FRAGMENT_RULES && type !== _rules_abr_ABRRulesCollection__WEBPACK_IMPORTED_MODULE_4__["default"].QUALITY_SWITCH_RULES || typeof rulename !== 'string') {
      throw _constants_Constants__WEBPACK_IMPORTED_MODULE_5__["default"].BAD_ARGUMENT_ERROR;
    }

    var index = _findAbrCustomRuleIndex(rulename);

    if (index === -1) {
      // add rule
      customAbrRules.push({
        type: type,
        rulename: rulename,
        rule: rule
      });
    } else {
      // update rule
      customAbrRules[index].type = type;
      customAbrRules[index].rule = rule;
    }
  }
  /**
   * Remove a custom ABR Rule
   *
   * @param {string} rulename - name of the rule to be removed
   */


  function removeAbrCustomRule(rulename) {
    if (rulename) {
      var index = _findAbrCustomRuleIndex(rulename); //if no rulename custom rule has been found, do nothing


      if (index !== -1) {
        // remove rule
        customAbrRules.splice(index, 1);
      }
    } else {
      //if no rulename is defined, remove all ABR custome rules
      customAbrRules = [];
    }
  }
  /**
   * Remove all custom rules
   */


  function removeAllAbrCustomRule() {
    customAbrRules = [];
  }
  /**
   * Return all ABR custom rules
   * @return {array}
   */


  function getAbrCustomRules() {
    return customAbrRules;
  }
  /**
   * Add a UTC timing source at the top of the list
   * @param {string} schemeIdUri
   * @param {string} value
   */


  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);
  }
  /**
   * Return all UTC timing sources
   * @return {array}
   */


  function getUTCTimingSources() {
    return utcTimingSources;
  }
  /**
   * Remove a specific timing source from the array
   * @param {string} schemeIdUri
   * @param {string} value
   */


  function removeUTCTimingSource(schemeIdUri, value) {
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_3__.checkParameterType)(schemeIdUri, 'string');
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_3__.checkParameterType)(value, 'string');
    utcTimingSources.forEach(function (obj, idx) {
      if (obj.schemeIdUri === schemeIdUri && obj.value === value) {
        utcTimingSources.splice(idx, 1);
      }
    });
  }
  /**
   * Remove all timing sources
   */


  function clearDefaultUTCTimingSources() {
    utcTimingSources = [];
  }
  /**
   * Add the default timing source to the list
   */


  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;
  }

  instance = {
    getCustomInitialTrackSelectionFunction: getCustomInitialTrackSelectionFunction,
    setCustomInitialTrackSelectionFunction: setCustomInitialTrackSelectionFunction,
    resetCustomInitialTrackSelectionFunction: resetCustomInitialTrackSelectionFunction,
    getLicenseResponseFilters: getLicenseResponseFilters,
    getLicenseRequestFilters: getLicenseRequestFilters,
    getCustomCapabilitiesFilters: getCustomCapabilitiesFilters,
    registerCustomCapabilitiesFilter: registerCustomCapabilitiesFilter,
    registerLicenseResponseFilter: registerLicenseResponseFilter,
    registerLicenseRequestFilter: registerLicenseRequestFilter,
    unregisterCustomCapabilitiesFilter: unregisterCustomCapabilitiesFilter,
    unregisterLicenseResponseFilter: unregisterLicenseResponseFilter,
    unregisterLicenseRequestFilter: unregisterLicenseRequestFilter,
    addAbrCustomRule: addAbrCustomRule,
    removeAllAbrCustomRule: removeAllAbrCustomRule,
    removeAbrCustomRule: removeAbrCustomRule,
    getAbrCustomRules: getAbrCustomRules,
    addUTCTimingSource: addUTCTimingSource,
    removeUTCTimingSource: removeUTCTimingSource,
    getUTCTimingSources: getUTCTimingSources,
    clearDefaultUTCTimingSources: clearDefaultUTCTimingSources,
    restoreDefaultUTCTimingSources: restoreDefaultUTCTimingSources,
    setXHRWithCredentialsForType: setXHRWithCredentialsForType,
    getXHRWithCredentialsForType: getXHRWithCredentialsForType,
    setConfig: setConfig,
    reset: reset
  };
  setup();
  return instance;
}

CustomParametersModel.__dashjs_factory_name = 'CustomParametersModel';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_1__["default"].getSingletonFactory(CustomParametersModel));

/***/ }),

/***/ "./src/streaming/models/FragmentModel.js":
/*!***********************************************!*\
  !*** ./src/streaming/models/FragmentModel.js ***!
  \***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \***********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _core_Settings__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.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 LOW_LATENCY_REDUCTION_FACTOR = 10;
var LOW_LATENCY_MULTIPLY_FACTOR = 5;
var DEFAULT_CATCHUP_MAX_DRIFT = 12;
var DEFAULT_CATCHUP_PLAYBACK_RATE_MIN = -0.5;
var DEFAULT_CATCHUP_PLAYBACK_RATE_MAX = 0.5;
var CATCHUP_PLAYBACK_RATE_MIN_LIMIT = -0.5;
var CATCHUP_PLAYBACK_RATE_MAX_LIMIT = 1;
/**
 * We use this model as a wrapper/proxy between Settings.js and classes that are using parameters from Settings.js.
 * In some cases we require additional logic to be applied and the settings might need to be adjusted before being used.
 * @class
 * @constructor
 */

function MediaPlayerModel() {
  var instance, logger, playbackController, serviceDescriptionController;
  var context = this.context;
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
  }

  function setConfig(config) {
    if (config.playbackController) {
      playbackController = config.playbackController;
    }

    if (config.serviceDescriptionController) {
      serviceDescriptionController = config.serviceDescriptionController;
    }
  }
  /**
   * Checks the supplied min playback rate is a valid vlaue and within supported limits
   * @param {number} rate - Supplied min playback rate 
   * @param {boolean} log - wether to shown warning or not 
   * @returns {number} corrected min playback rate
   */


  function _checkMinPlaybackRate(rate, log) {
    if (isNaN(rate)) return 0;

    if (rate > 0) {
      if (log) {
        logger.warn("Supplied minimum playback rate is a positive value when it should be negative or 0. The supplied rate will not be applied and set to 0: 100% playback speed.");
      }

      return 0;
    }

    if (rate < CATCHUP_PLAYBACK_RATE_MIN_LIMIT) {
      if (log) {
        logger.warn("Supplied minimum playback rate is out of range and will be limited to ".concat(CATCHUP_PLAYBACK_RATE_MIN_LIMIT, ": ").concat(CATCHUP_PLAYBACK_RATE_MIN_LIMIT * 100, "% playback speed."));
      }

      return CATCHUP_PLAYBACK_RATE_MIN_LIMIT;
    }

    return rate;
  }

  ;
  /**
   * Checks the supplied max playback rate is a valid vlaue and within supported limits
   * @param {number} rate - Supplied max playback rate 
   * @param {boolean} log - wether to shown warning or not 
   * @returns {number} corrected max playback rate
   */

  function _checkMaxPlaybackRate(rate, log) {
    if (isNaN(rate)) return 0;

    if (rate < 0) {
      if (log) {
        logger.warn("Supplied maximum playback rate is a negative value when it should be negative or 0. The supplied rate will not be applied and set to 0: 100% playback speed.");
      }

      return 0;
    }

    if (rate > CATCHUP_PLAYBACK_RATE_MAX_LIMIT) {
      if (log) {
        logger.warn("Supplied maximum playback rate is out of range and will be limited to ".concat(CATCHUP_PLAYBACK_RATE_MAX_LIMIT, ": ").concat((1 + CATCHUP_PLAYBACK_RATE_MAX_LIMIT) * 100, "% playback speed."));
      }

      return CATCHUP_PLAYBACK_RATE_MAX_LIMIT;
    }

    return rate;
  }

  ;
  /**
   * Returns the maximum drift allowed before applying a seek back to the live edge when the catchup mode is enabled
   * @return {number}
   */

  function getCatchupMaxDrift() {
    if (!isNaN(settings.get().streaming.liveCatchup.maxDrift) && settings.get().streaming.liveCatchup.maxDrift > 0) {
      return settings.get().streaming.liveCatchup.maxDrift;
    }

    var serviceDescriptionSettings = serviceDescriptionController.getServiceDescriptionSettings();

    if (serviceDescriptionSettings && serviceDescriptionSettings.liveCatchup && !isNaN(serviceDescriptionSettings.liveCatchup.maxDrift) && serviceDescriptionSettings.liveCatchup.maxDrift > 0) {
      return serviceDescriptionSettings.liveCatchup.maxDrift;
    }

    return DEFAULT_CATCHUP_MAX_DRIFT;
  }
  /**
   * Returns the minimum and maximum playback rates to be used when applying the catchup mechanism
   * If only one of the min/max values has been set then the other will default to 0 (no playback rate change).
   * @return {number}
   */


  function getCatchupPlaybackRates(log) {
    var settingsPlaybackRate = settings.get().streaming.liveCatchup.playbackRate;

    if (!isNaN(settingsPlaybackRate.min) || !isNaN(settingsPlaybackRate.max)) {
      return {
        min: _checkMinPlaybackRate(settingsPlaybackRate.min, log),
        max: _checkMaxPlaybackRate(settingsPlaybackRate.max, log)
      };
    }

    var serviceDescriptionSettings = serviceDescriptionController.getServiceDescriptionSettings();

    if (serviceDescriptionSettings && serviceDescriptionSettings.liveCatchup && (!isNaN(serviceDescriptionSettings.liveCatchup.playbackRate.min) || !isNaN(serviceDescriptionSettings.liveCatchup.playbackRate.max))) {
      var sdPlaybackRate = serviceDescriptionSettings.liveCatchup.playbackRate;
      return {
        min: _checkMinPlaybackRate(sdPlaybackRate.min, log),
        max: _checkMaxPlaybackRate(sdPlaybackRate.max, log)
      };
    }

    return {
      min: DEFAULT_CATCHUP_PLAYBACK_RATE_MIN,
      max: DEFAULT_CATCHUP_PLAYBACK_RATE_MAX
    };
  }
  /**
   * Returns whether the catchup mode is activated via the settings or internally in the PlaybackController
   * @return {boolean}
   */


  function getCatchupModeEnabled() {
    if (settings.get().streaming.liveCatchup.enabled !== null) {
      return settings.get().streaming.liveCatchup.enabled;
    }

    return playbackController.getInitialCatchupModeActivated();
  }
  /**
   * Returns the min,max or initial bitrate for a specific media type.
   * @param {string} field
   * @param {string} mediaType
   */


  function getAbrBitrateParameter(field, mediaType) {
    try {
      var setting = settings.get().streaming.abr[field][mediaType];

      if (!isNaN(setting) && setting !== -1) {
        return setting;
      }

      var serviceDescriptionSettings = serviceDescriptionController.getServiceDescriptionSettings();

      if (serviceDescriptionSettings && serviceDescriptionSettings[field] && !isNaN(serviceDescriptionSettings[field][mediaType])) {
        return serviceDescriptionSettings[field][mediaType];
      }

      return -1;
    } catch (e) {
      return -1;
    }
  }
  /**
   * Returns the initial buffer level taking the stable buffer time into account
   * @return {number}
   */


  function getInitialBufferLevel() {
    var initialBufferLevel = settings.get().streaming.buffer.initialBufferLevel;

    if (isNaN(initialBufferLevel) || initialBufferLevel < 0) {
      return 0;
    }

    return Math.min(getStableBufferTime(), initialBufferLevel);
  }
  /**
   * Returns the stable buffer time taking the live delay into account
   * @return {number}
   */


  function getStableBufferTime() {
    var stableBufferTime = settings.get().streaming.buffer.stableBufferTime > 0 ? settings.get().streaming.buffer.stableBufferTime : settings.get().streaming.buffer.fastSwitchEnabled ? DEFAULT_MIN_BUFFER_TIME_FAST_SWITCH : DEFAULT_MIN_BUFFER_TIME;
    var liveDelay = playbackController.getLiveDelay();
    return !isNaN(liveDelay) && liveDelay > 0 ? Math.min(stableBufferTime, liveDelay) : stableBufferTime;
  }
  /**
   * Returns the number of retry attempts for a specific media type
   * @param type
   * @return {number}
   */


  function getRetryAttemptsForType(type) {
    var lowLatencyMultiplyFactor = !isNaN(settings.get().streaming.retryAttempts.lowLatencyMultiplyFactor) ? settings.get().streaming.retryAttempts.lowLatencyMultiplyFactor : LOW_LATENCY_MULTIPLY_FACTOR;
    return playbackController.getLowLatencyModeEnabled() ? settings.get().streaming.retryAttempts[type] * lowLatencyMultiplyFactor : settings.get().streaming.retryAttempts[type];
  }
  /**
   * Returns the retry interval for a specific media type
   * @param type
   * @return {number}
   */


  function getRetryIntervalsForType(type) {
    var lowLatencyReductionFactor = !isNaN(settings.get().streaming.retryIntervals.lowLatencyReductionFactor) ? settings.get().streaming.retryIntervals.lowLatencyReductionFactor : LOW_LATENCY_REDUCTION_FACTOR;
    return playbackController.getLowLatencyModeEnabled() ? settings.get().streaming.retryIntervals[type] / lowLatencyReductionFactor : settings.get().streaming.retryIntervals[type];
  }

  function reset() {}

  instance = {
    getCatchupMaxDrift: getCatchupMaxDrift,
    getCatchupModeEnabled: getCatchupModeEnabled,
    getStableBufferTime: getStableBufferTime,
    getInitialBufferLevel: getInitialBufferLevel,
    getRetryAttemptsForType: getRetryAttemptsForType,
    getRetryIntervalsForType: getRetryIntervalsForType,
    getCatchupPlaybackRates: getCatchupPlaybackRates,
    getAbrBitrateParameter: getAbrBitrateParameter,
    setConfig: setConfig,
    reset: reset
  };
  setup();
  return instance;
}

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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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) {
    var vo = new _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__.HTTPRequestTrace();
    vo.s = s;
    vo.d = d;
    vo.b = b;
    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, fileLoaderType, cmsd) {
    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, fileLoaderType, cmsd);
      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.cmsd = cmsd;
    vo._tfinish = tfinish;
    vo._stream = mediaType;
    vo._mediaduration = mediaduration;
    vo._quality = quality;
    vo._responseHeaders = responseHeaders;
    vo._serviceLocation = serviceLocation;
    vo._fileLoaderType = fileLoaderType;

    if (traces) {
      traces.forEach(function (trace) {
        appendHttpTrace(vo, trace.s, trace.d, trace.b);
      });
    } 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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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, _currentTime, setCurrentTimeReadyStateFunction, TTMLRenderingDiv, vttRenderingDiv, previousPlaybackRate, timeout;

  var VIDEO_MODEL_WRONG_ELEMENT_TYPE = 'element is not video or audio DOM type!';
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  var stalledStreams = [];

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance().getLogger(instance);
    _currentTime = NaN;
  }

  function initialize() {
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PLAYING, onPlaying, this);
  }

  function reset() {
    clearTimeout(timeout);
    eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].PLAYBACK_PLAYING, onPlaying, this);
  }

  function onPlaybackCanPlay() {
    if (element) {
      element.playbackRate = previousPlaybackRate || 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) {
    if (element) {
      if (setCurrentTimeReadyStateFunction && setCurrentTimeReadyStateFunction.func && setCurrentTimeReadyStateFunction.event) {
        removeEventListener(setCurrentTimeReadyStateFunction.event, setCurrentTimeReadyStateFunction.func);
      }

      _currentTime = currentTime;
      setCurrentTimeReadyStateFunction = waitForReadyState(_constants_Constants__WEBPACK_IMPORTED_MODULE_4__["default"].VIDEO_ELEMENT_READY_STATES.HAVE_METADATA, function () {
        if (!element) {
          return;
        } // 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) {
          _currentTime = NaN;
          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;

          if (!isNaN(_currentTime)) {
            element.currentTime = _currentTime;
          }

          _currentTime = NaN;
        } catch (e) {
          if (element.readyState === 0 && e.code === e.INVALID_STATE_ERR) {
            timeout = setTimeout(function () {
              element.currentTime = _currentTime;
              _currentTime = NaN;
            }, 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 getVttRenderingDiv() {
    return vttRenderingDiv;
  }

  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 setVttRenderingDiv(div) {
    vttRenderingDiv = div;
  }

  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 || !isNaN(_currentTime) : null;
  }

  function getTime() {
    return element ? !isNaN(_currentTime) ? _currentTime : 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() {
    if (element) {
      var parentElement = element.parentNode.host || element.parentNode;
      return parentElement ? element.getBoundingClientRect().top - parentElement.getBoundingClientRect().top : NaN;
    }

    return NaN;
  }

  function getVideoRelativeOffsetLeft() {
    if (element) {
      var parentElement = element.parentNode.host || element.parentNode;
      return parentElement ? element.getBoundingClientRect().left - parentElement.getBoundingClientRect().left : NaN;
    }

    return 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();
      return null;
    } else {
      // wait for the appropriate callback before checking again
      var event = READY_STATES_TO_EVENT_NAMES.get(targetReadyState);
      return _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);
    return {
      func: func,
      event: event
    };
  }

  instance = {
    addEventListener: addEventListener,
    addTextTrack: addTextTrack,
    appendChild: appendChild,
    getBufferRange: getBufferRange,
    getClientHeight: getClientHeight,
    getClientWidth: getClientWidth,
    getElement: getElement,
    getEnded: getEnded,
    getPlaybackQuality: getPlaybackQuality,
    getPlaybackRate: getPlaybackRate,
    getPlayedRanges: getPlayedRanges,
    getReadyState: getReadyState,
    getSource: getSource,
    getTTMLRenderingDiv: getTTMLRenderingDiv,
    getTextTrack: getTextTrack,
    getTextTracks: getTextTracks,
    getTime: getTime,
    getVideoHeight: getVideoHeight,
    getVideoRelativeOffsetLeft: getVideoRelativeOffsetLeft,
    getVideoRelativeOffsetTop: getVideoRelativeOffsetTop,
    getVideoWidth: getVideoWidth,
    getVttRenderingDiv: getVttRenderingDiv,
    initialize: initialize,
    isPaused: isPaused,
    isSeeking: isSeeking,
    isStalled: isStalled,
    pause: pause,
    play: play,
    removeChild: removeChild,
    removeEventListener: removeEventListener,
    reset: reset,
    setCurrentTime: setCurrentTime,
    setElement: setElement,
    setPlaybackRate: setPlaybackRate,
    setSource: setSource,
    setStallState: setStallState,
    setTTMLRenderingDiv: setTTMLRenderingDiv,
    setVttRenderingDiv: setVttRenderingDiv,
    waitForReadyState: waitForReadyState
  };
  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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _utils_RequestModifier__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/RequestModifier */ "./src/streaming/utils/RequestModifier.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 = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  var instance, dashMetrics;

  function setup(cfg) {
    dashMetrics = cfg.dashMetrics;
  }

  function load(httpRequest) {
    if (requestModifier && requestModifier.modifyRequest) {
      (0,_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_3__.modifyRequest)(httpRequest, requestModifier).then(function () {
        return request(httpRequest);
      });
    } else {
      request(httpRequest);
    }
  }

  function request(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 && requestModifier.modifyRequestHeader) {
      // 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);
        }
      }, {
        url: httpRequest.url
      });
    }

    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;
                var calculatedTime = null;

                if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING) {
                  calculatedThroughput = calculateThroughputByChunkData(startTimeData, endTimeData);

                  if (calculatedThroughput) {
                    calculatedTime = bytesReceived * 8 / calculatedThroughput;
                  }
                } else if (calculationMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_2__["default"].ABR_FETCH_THROUGHPUT_CALCULATION_DOWNLOADED_DATA) {
                  calculatedTime = calculateDownloadedTime(downloadedData, bytesReceived);
                }

                httpRequest.progress({
                  loaded: bytesReceived,
                  total: isNaN(totalBytes) ? bytesReceived : totalBytes,
                  lengthComputable: true,
                  time: calculatedTime,
                  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);
              shortDurationStartTime = 0;
            } else {
              if (shortDurationStartTime === 0) {
                shortDurationStartTime = datum[i].ts;
                shortDurationBytesReceived = 0;
              }

              var cumulatedChunkDownloadTime = datumE[i].ts - shortDurationStartTime;

              if (cumulatedChunkDownloadTime > 1) {
                shortDurationBytesReceived += datumE[i].bytes;
                chunkThroughputs.push(8 * shortDurationBytesReceived / cumulatedChunkDownloadTime);
                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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _models_CmsdModel__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../models/CmsdModel */ "./src/streaming/models/CmsdModel.js");
/* harmony import */ var _core_Utils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/Utils */ "./src/core/Utils.js");
/* harmony import */ var _core_Debug__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../core/Debug */ "./src/core/Debug.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../constants/Constants */ "./src/streaming/constants/Constants.js");
/* harmony import */ var _models_LowLatencyThroughputModel__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../models/LowLatencyThroughputModel */ "./src/streaming/models/LowLatencyThroughputModel.js");
/* harmony import */ var _models_CustomParametersModel__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../models/CustomParametersModel */ "./src/streaming/models/CustomParametersModel.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 - dependencies 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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_9__["default"])(context).getInstance();
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_11__["default"])(context).getInstance();
  var instance, requests, delayedRequests, retryRequests, downloadErrorToRequestTypeMap, cmcdModel, cmsdModel, customParametersModel, lowLatencyThroughputModel, logger;

  function setup() {
    var _downloadErrorToReque;

    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_8__["default"])(context).getInstance().getLogger(instance);
    requests = [];
    delayedRequests = [];
    retryRequests = [];
    cmcdModel = (0,_models_CmcdModel__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
    cmsdModel = (0,_models_CmsdModel__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
    lowLatencyThroughputModel = (0,_models_LowLatencyThroughputModel__WEBPACK_IMPORTED_MODULE_13__["default"])(context).getInstance();
    customParametersModel = (0,_models_CustomParametersModel__WEBPACK_IMPORTED_MODULE_14__["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 progressTimeout = null;
    var fileLoaderType = null;
    var httpRequest;

    if (!requestModifier || !dashMetrics || !errHandler) {
      throw new Error('config object is not correct or missing');
    }

    var addHttpRequestMetric = function addHttpRequestMetric(success) {
      request.requestStartDate = requestStartTime;
      request.requestEndDate = new Date();
      request.firstByteDate = request.firstByteDate || requestStartTime;
      request.fileLoaderType = fileLoaderType;
      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 : null;
      var cmsd = responseHeaders && settings.get().streaming.cmsd && settings.get().streaming.cmsd.enabled ? cmsdModel.parseResponseHeaders(responseHeaders, request.mediaType) : null;
      dashMetrics.addHttpRequest(request, responseUrl, responseStatus, responseHeaders, success ? traces : null, cmsd);
    };

    var handleLoaded = function handleLoaded(success) {
      needFailureReport = false;
      addHttpRequestMetric(success);

      if (request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__.HTTPRequest.MPD_TYPE) {
        dashMetrics.addManifestUpdate(request);
        eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_10__["default"].MANIFEST_LOADING_FINISHED, {
          request: request
        });
      }
    };

    var onloadend = function onloadend() {
      if (progressTimeout) {
        clearTimeout(progressTimeout);
        progressTimeout = null;
      }

      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_10__["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, httpRequest.response);
          }

          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]
        });
        lastTraceTime = currentTime;
        lastTraceReceivedCount = event.loaded;
      }

      if (progressTimeout) {
        clearTimeout(progressTimeout);
        progressTimeout = null;
      }

      if (settings.get().streaming.fragmentRequestProgressTimeout > 0) {
        progressTimeout = setTimeout(function () {
          // No more progress => abort request and treat as an error
          logger.warn('Abort request ' + httpRequest.url + ' due to progress timeout');
          httpRequest.response.onabort = null;
          httpRequest.loader.abort(httpRequest);
          onloadend();
        }, settings.get().streaming.fragmentRequestProgressTimeout);
      }

      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() {
      addHttpRequestMetric(true);

      if (progressTimeout) {
        clearTimeout(progressTimeout);
        progressTimeout = null;
      }

      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 (request.hasOwnProperty('availabilityTimeComplete') && request.availabilityTimeComplete === false && window.fetch && request.responseType === 'arraybuffer' && request.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__.HTTPRequest.MEDIA_SEGMENT_TYPE) {
      loader = (0,_FetchLoader__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
        requestModifier: requestModifier,
        lowLatencyThroughputModel: lowLatencyThroughputModel,
        boxParser: boxParser
      });
      loader.setup({
        dashMetrics: dashMetrics
      });
      fileLoaderType = _constants_Constants__WEBPACK_IMPORTED_MODULE_12__["default"].FILE_LOADER_TYPES.FETCH;
    } else {
      loader = (0,_XHRLoader__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
        requestModifier: requestModifier
      });
      fileLoaderType = _constants_Constants__WEBPACK_IMPORTED_MODULE_12__["default"].FILE_LOADER_TYPES.XHR;
    }

    var headers = null;
    var modifiedUrl = requestModifier.modifyRequestURL ? requestModifier.modifyRequestURL(request.url) : 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_12__["default"].CMCD_MODE_QUERY) {
        var additionalQueryParameter = _getAdditionalQueryParameter(request);

        modifiedUrl = _core_Utils__WEBPACK_IMPORTED_MODULE_7__["default"].addAditionalQueryParameterToUrl(modifiedUrl, additionalQueryParameter);
      } else if (cmcdMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_12__["default"].CMCD_MODE_HEADER) {
        headers = cmcdModel.getHeaderParameters(request);
      }
    }

    var withCredentials = customParametersModel.getXHRWithCredentialsForType(request.type); // Add queryParams that came from pathway cloning

    if (request.queryParams) {
      var queryParams = Object.keys(request.queryParams).map(function (key) {
        return {
          key: key,
          value: request.queryParams[key]
        };
      });
      modifiedUrl = _core_Utils__WEBPACK_IMPORTED_MODULE_7__["default"].addAditionalQueryParameterToUrl(modifiedUrl, queryParams);
    }

    request.url = modifiedUrl;
    httpRequest = {
      url: modifiedUrl,
      method: _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_2__.HTTPRequest.GET,
      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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 depending on URL
 * @param {Object} cfg - dependencies
 * @ignore
*/

function URLLoader(cfg) {
  cfg = cfg || {};
  var context = this.context;
  var instance, schemeLoaderFactory, loader;
  schemeLoaderFactory = (0,_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 ***!
  \****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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_RequestModifier__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/RequestModifier */ "./src/streaming/utils/RequestModifier.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) {
    if (requestModifier && requestModifier.modifyRequest) {
      (0,_utils_RequestModifier__WEBPACK_IMPORTED_MODULE_1__.modifyRequest)(httpRequest, requestModifier).then(function () {
        return request(httpRequest);
      });
    } else {
      request(httpRequest);
    }
  }

  function request(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 && requestModifier.modifyRequestHeader) {
      xhr = requestModifier.modifyRequestHeader(xhr, {
        url: httpRequest.url
      });
    }

    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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_controllers_ProtectionKeyController__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
    protectionKeyController.setConfig({
      debug: config.debug,
      BASE64: config.BASE64,
      settings: config.settings
    });
    protectionKeyController.initialize();

    var protectionModel = _getProtectionModel(config);

    if (!controller && protectionModel) {
      //TODO add ability to set external controller if still needed at all?
      controller = (0,_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,
        customParametersModel: config.customParametersModel,
        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 (0,_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 (0,_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 (0,_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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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
     * @event ProtectionEvents#KEY_SYSTEM_ACCESS_COMPLETE
     */

    _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 ***!
  \**********************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 customParametersModel = config.customParametersModel;
  var instance, logger, pendingKeySessionsToHandle, mediaInfoArr, protDataSet, sessionType, robustnessLevel, selectedKeySystem, keySystemSelectionInProgress, licenseXhrRequest, licenseRequestRetryTimeout;

  function setup() {
    logger = debug.getLogger(instance);
    pendingKeySessionsToHandle = [];
    mediaInfoArr = [];
    sessionType = 'temporary';
    robustnessLevel = '';
    licenseXhrRequest = null;
    licenseRequestRetryTimeout = null;
    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);
  }
  /**
   * Once all mediaInfo objects have been added to our mediaInfoArray we can select a key system or check if the kid has changed and we need to trigger a new license request
   * @memberof module:ProtectionController
   * @instance
   */


  function handleKeySystemFromManifest() {
    if (!mediaInfoArr || mediaInfoArr.length === 0) {
      return;
    }

    var supportedKeySystems = [];
    mediaInfoArr.forEach(function (mInfo) {
      var currentKs = protectionKeyController.getSupportedKeySystemsFromContentProtection(mInfo.contentProtection, protDataSet, sessionType); // We assume that the same key systems are signaled for each AS. We can use the first entry we found

      if (currentKs.length > 0) {
        if (supportedKeySystems.length === 0) {
          supportedKeySystems = currentKs;
        } // Save config for creating key session once we selected a key system


        pendingKeySessionsToHandle.push(currentKs);
      }
    });

    if (supportedKeySystems && supportedKeySystems.length > 0) {
      _selectKeySystemOrUpdateKeySessions(supportedKeySystems, 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
   * @private
   */


  function _handleKeySystemFromPssh(supportedKs) {
    pendingKeySessionsToHandle.push(supportedKs);

    _selectKeySystemOrUpdateKeySessions(supportedKs, false);
  }
  /**
   * Select the key system or update one of our existing key sessions
   * @param {array} supportedKs
   * @param {boolean} fromManifest
   * @private
   */


  function _selectKeySystemOrUpdateKeySessions(supportedKs, fromManifest) {
    // First time, so we need to select a key system
    if (!selectedKeySystem && !keySystemSelectionInProgress) {
      _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) {
      _handleKeySessions();
    }
  }
  /**
   * We do not have a key system yet. Select one
   * @param {array} supportedKs
   * @param {boolean} fromManifest
   * @private
   */


  function _selectInitialKeySystem(supportedKs, fromManifest) {
    if (!keySystemSelectionInProgress) {
      keySystemSelectionInProgress = true;
      var requestedKeySystems = []; // 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;
      }); // 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],
          protData: supportedKs[i].protData
        });
      }

      var keySystemAccess;
      protectionModel.requestKeySystemAccess(requestedKeySystems).then(function (event) {
        keySystemAccess = event.data;
        var selectedSystemString = keySystemAccess.mksa && keySystemAccess.mksa.selectedSystemString ? keySystemAccess.mksa.selectedSystemString : keySystemAccess.keySystem.systemString;
        logger.info('DRM: KeySystem Access Granted for system string (' + selectedSystemString + ')!  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);
        }

        _handleKeySessions();
      })["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 key system we only need to create a new key session and issue a new license request if the init data has changed.
   * @private
   */


  function _handleKeySessions() {
    // Create key sessions for the different AdaptationSets
    var ksIdx;

    for (var i = 0; i < pendingKeySessionsToHandle.length; i++) {
      for (ksIdx = 0; ksIdx < pendingKeySessionsToHandle[i].length; ksIdx++) {
        if (selectedKeySystem === pendingKeySessionsToHandle[i][ksIdx].ks) {
          var current = pendingKeySessionsToHandle[i][ksIdx];

          _loadOrCreateKeySession(current);

          break;
        }
      }
    }

    pendingKeySessionsToHandle = [];
  }
  /**
   * 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') && Object.keys(keySystemInfo.protData.clearkeys).length !== 0) {
        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() {
    _abortLicenseRequest();

    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();

    _abortLicenseRequest();

    setMediaElement(null);
    selectedKeySystem = null;
    keySystemSelectionInProgress = false;

    if (protectionModel) {
      protectionModel.reset();
      protectionModel = null;
    }

    needkeyRetries.forEach(function (retryTimeout) {
      return clearTimeout(retryTimeout);
    });
    needkeyRetries = [];
    mediaInfoArr = [];
    pendingKeySessionsToHandle = [];
  }
  /**
   * 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 && clearkeys.keyPairs && clearkeys.keyPairs.length > 0) {
        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);
        var licenseResponseFilters = customParametersModel.getLicenseResponseFilters();

        _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;
    var licenseRequestFilters = customParametersModel.getLicenseRequestFilters();

    _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;
      licenseRequestRetryTimeout = setTimeout(function () {
        _doLicenseRequest(request, retriesCount, timeout, onLoad, onAbort, onError);
      }, retryInterval);
    };

    xhr.onload = function () {
      licenseXhrRequest = null;

      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 () {
      licenseXhrRequest = null;

      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
    });
    licenseXhrRequest = xhr;
    xhr.send(request.data);
  }
  /**
   * Aborts license request
   * @private
   */


  function _abortLicenseRequest() {
    if (licenseXhrRequest) {
      licenseXhrRequest.onloadend = licenseXhrRequest.onerror = licenseXhrRequest.onprogress = undefined; //Ignore events from aborted requests.

      licenseXhrRequest.abort();
      licenseXhrRequest = null;
    }

    if (licenseRequestRetryTimeout) {
      clearTimeout(licenseRequestRetryTimeout);
      licenseRequestRetryTimeout = null;
    }
  }
  /**
   * 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 = 'NONE';
    var data = null;

    if (xhr.response) {
      errorMsg = licenseServerData.getErrorResponse(xhr.response, keySystemString, messageType);
      data = {
        serverResponse: xhr.response || null,
        responseCode: xhr.status || null,
        responseText: xhr.statusText || null
      };
    }

    _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, data));
  }
  /**
   * 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
   * @private
   */


  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;
      }

      _handleKeySystemFromPssh(supportedKs);
    }
  }
  /**
   * 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);
    }
  }

  instance = {
    initializeForMedia: initializeForMedia,
    clearMediaInfoArray: clearMediaInfoArray,
    handleKeySystemFromManifest: handleKeySystemFromManifest,
    createKeySession: createKeySession,
    loadKeySession: loadKeySession,
    removeKeySession: removeKeySession,
    closeKeySession: closeKeySession,
    setServerCertificate: setServerCertificate,
    setMediaElement: setMediaElement,
    setSessionType: setSessionType,
    setRobustnessLevel: setRobustnessLevel,
    setProtectionData: setProtectionData,
    getSupportedKeySystemsFromContentProtection: getSupportedKeySystemsFromContentProtection,
    getKeySystems: getKeySystems,
    setKeySystems: setKeySystems,
    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 ***!
  \*************************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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, settings, clearkeyKeySystem, clearkeyW3CKeySystem;

  function setConfig(config) {
    if (!config) return;

    if (config.debug) {
      debug = config.debug;
      logger = debug.getLogger(instance);
    }

    if (config.BASE64) {
      BASE64 = config.BASE64;
    }

    if (config.settings) {
      settings = config.settings;
    }
  }

  function initialize() {
    keySystems = [];
    var keySystem; // PlayReady

    keySystem = (0,_drm_KeySystemPlayReady__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance({
      BASE64: BASE64,
      settings: settings
    });
    keySystems.push(keySystem); // Widevine

    keySystem = (0,_drm_KeySystemWidevine__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance({
      BASE64: BASE64
    });
    keySystems.push(keySystem); // ClearKey

    keySystem = (0,_drm_KeySystemClearKey__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance({
      BASE64: BASE64
    });
    keySystems.push(keySystem);
    clearkeyKeySystem = keySystem; // W3C ClearKey

    keySystem = (0,_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 = (0,_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 = (0,_servers_Widevine__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
    } else if (keySystem.systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_9__["default"].PLAYREADY_KEYSTEM_STRING) {
      licenseServerData = (0,_servers_PlayReady__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
    } else if (keySystem.systemString === _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_9__["default"].CLEARKEY_KEYSTEM_STRING) {
      licenseServerData = (0,_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 ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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, '').replace(/\//g, '_').replace(/\+/g, '-');
    } catch (e) {
      return null;
    }
  }

  function getRequestHeadersFromMessage() {
    // Set content type to application/json by default
    return {
      'Content-Type': 'application/json'
    };
  }

  function getLicenseRequestFromMessage(message) {
    return JSON.stringify(JSON.parse(String.fromCharCode.apply(null, new Uint8Array(message))));
  }

  function getLicenseServerURLFromInitData() {
    return null;
  }

  function getCDMData() {
    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 ***!
  \************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;
  var settings = config.settings;

  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();

    if (settings && settings.get().streaming.protection.detectPlayreadyMessageFormat) {
      // If message format configured/defaulted to utf-16 AND number of bytes is odd, assume 'unwrapped' raw CDM message.
      if (messageFormat === 'utf-16' && message && message.byteLength % 2 === 1) {
        headers['Content-Type'] = 'text/xml; charset=utf-8';
        return headers;
      }
    }

    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();

    if (settings && settings.get().streaming.protection.detectPlayreadyMessageFormat) {
      // If message format configured/defaulted to utf-16 AND number of bytes is odd, assume 'unwrapped' raw CDM message.
      if (messageFormat === 'utf-16' && message && message.byteLength % 2 === 1) {
        return message;
      }
    }

    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 ***!
  \**************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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() {
    return null;
  }

  function getLicenseRequestFromMessage(message) {
    return new Uint8Array(message);
  }

  function getLicenseServerURLFromInitData() {
    return null;
  }

  function getCDMData() {
    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 ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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() {
    return null;
  }

  function getLicenseRequestFromMessage(message) {
    return new Uint8Array(message);
  }

  function getLicenseServerURLFromInitData() {
    return null;
  }

  function getCDMData() {
    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 ***!
  \*************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \****************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 (!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_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() {
    /* Not supported */
  }

  function loadKeySession() {
    /* Not supported */
  }

  function removeKeySession() {
    /* 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 ***!
  \**********************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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
 */







var SYSTEM_STRING_PRIORITY = {};
SYSTEM_STRING_PRIORITY[_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYREADY_KEYSTEM_STRING] = [_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYREADY_KEYSTEM_STRING, _constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].PLAYREADY_RECOMMENDATION_KEYSTEM_STRING];
SYSTEM_STRING_PRIORITY[_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].WIDEVINE_KEYSTEM_STRING] = [_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].WIDEVINE_KEYSTEM_STRING];
SYSTEM_STRING_PRIORITY[_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CLEARKEY_KEYSTEM_STRING] = [_constants_ProtectionConstants__WEBPACK_IMPORTED_MODULE_6__["default"].CLEARKEY_KEYSTEM_STRING];

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 = (0,_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) {
            _closeKeySessionInternal(session);

            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);

        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) {
    // In case requestMediaKeySystemAccess is not available we can not proceed and dispatch an error
    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;
    } // If a systemStringPriority is defined by the application we use these values. Otherwise we use the default system string
    // This is useful for DRM systems such as Playready for which multiple system strings are possible for instance com.microsoft.playready and com.microsoft.playready.recommendation


    var protDataSystemStringPriority = ksConfigurations[idx].protData && ksConfigurations[idx].protData.systemStringPriority ? ksConfigurations[idx].protData.systemStringPriority : null;
    var configs = ksConfigurations[idx].configs;
    var currentKeySystem = ksConfigurations[idx].ks;
    var systemString = currentKeySystem.systemString; // Use the default values in case no values are provided by the application

    var systemStringsToApply = protDataSystemStringPriority ? protDataSystemStringPriority : SYSTEM_STRING_PRIORITY[systemString] ? SYSTEM_STRING_PRIORITY[systemString] : [systemString]; // Check all the available system strings and the available configurations for support

    _checkAccessForKeySystem(systemStringsToApply, configs).then(function (mediaKeySystemAccess) {
      var configuration = typeof mediaKeySystemAccess.getConfiguration === 'function' ? mediaKeySystemAccess.getConfiguration() : null;
      var keySystemAccess = new _vo_KeySystemAccess__WEBPACK_IMPORTED_MODULE_5__["default"](currentKeySystem, configuration);
      keySystemAccess.mksa = mediaKeySystemAccess;
      eventBus.trigger(events.KEY_SYSTEM_ACCESS_COMPLETE, {
        data: keySystemAccess
      });
      resolve({
        data: keySystemAccess
      });
    })["catch"](function (e) {
      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 + e.message
        });
        reject({
          error: errorMessage + e.message
        });
      }
    });
  }
  /**
   * For a specific key system: Iterate over the possible system strings and resolve once a valid configuration was found
   * @param {array} systemStringsToApply
   * @param {object} configs
   * @return {Promise}
   * @private
   */


  function _checkAccessForKeySystem(systemStringsToApply, configs) {
    return new Promise(function (resolve, reject) {
      _checkAccessForSystemStrings(systemStringsToApply, configs, 0, resolve, reject);
    });
  }
  /**
   * Recursively iterate over the possible system strings until a supported configuration is found or we ran out of options
   * @param {array} systemStringsToApply
   * @param {object} configs
   * @param {number} idx
   * @param {function} resolve
   * @param {function} reject
   * @private
   */


  function _checkAccessForSystemStrings(systemStringsToApply, configs, idx, resolve, reject) {
    var systemString = systemStringsToApply[idx];
    logger.debug("Requesting key system access for system string ".concat(systemString));
    navigator.requestMediaKeySystemAccess(systemString, configs).then(function (mediaKeySystemAccess) {
      mediaKeySystemAccess.selectedSystemString = systemString;
      resolve(mediaKeySystemAccess);
    })["catch"](function (e) {
      if (idx + 1 < systemStringsToApply.length) {
        _checkAccessForSystemStrings(systemStringsToApply, configs, idx + 1, resolve, reject);
      } else {
        reject(e);
      }
    });
  }
  /**
   * 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) {
    if (!sessionToken || !sessionToken.session) {
      return Promise.resolve;
    }

    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 ***!
  \*********************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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() {
    /* Not supported */
  }

  function loadKeySession() {
    /* Not supported */
  }

  function removeKeySession() {
    /* 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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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() {
    return 'POST';
  }

  function getResponseType() {
    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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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() {
    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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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.
 */

/* 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() {
    return 'POST';
  }

  function getResponseType() {
    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"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(PlayReady));
/* jshint ignore:line */

/***/ }),

/***/ "./src/streaming/protection/servers/Widevine.js":
/*!******************************************************!*\
  !*** ./src/streaming/protection/servers/Widevine.js ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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() {
    return 'POST';
  }

  function getResponseType() {
    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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 response
 *
 * @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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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[streamId];
    lastDroppedFrames[streamId] = droppedVideoFrames;
    var intervalTotalFrames = totalVideoFrames - lastTotalFrames[streamId];
    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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _core_EventBus__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__ = __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) 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) {
  var context = this.context;
  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 eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance();
  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 (httpRequest._fileLoaderType && httpRequest._fileLoaderType === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].FILE_LOADER_TYPES.FETCH) {
      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
    } // Get estimated throughput (etp, in kbits/s) from CMSD response headers


    if (httpRequest.cmsd) {
      var etp = httpRequest.cmsd.dynamic && httpRequest.cmsd.dynamic.etp ? httpRequest.cmsd.dynamic.etp : null;

      if (etp) {
        // Apply weight ratio on etp
        var etpWeightRatio = settings.get().streaming.cmsd.abr.etpWeightRatio;

        if (etpWeightRatio > 0 && etpWeightRatio <= 1) {
          throughput = throughput * (1 - etpWeightRatio) + etp * etpWeightRatio;
        }
      }
    }

    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);
    eventBus.trigger(_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_3__["default"].THROUGHPUT_MEASUREMENT_STORED, {
      throughput: throughput,
      mediaType: mediaType,
      httpRequest: httpRequest
    });

    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 ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 customParametersModel = config.customParametersModel;
  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((0,_L2ARule_js__WEBPACK_IMPORTED_MODULE_6__["default"])(context).create({
          dashMetrics: dashMetrics,
          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((0,_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((0,_BolaRule__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
          dashMetrics: dashMetrics,
          mediaPlayerModel: mediaPlayerModel,
          settings: settings
        }));
        qualitySwitchRules.push((0,_ThroughputRule__WEBPACK_IMPORTED_MODULE_0__["default"])(context).create({
          dashMetrics: dashMetrics
        }));

        if (settings.get().streaming.abr.additionalAbrRules.insufficientBufferRule) {
          qualitySwitchRules.push((0,_InsufficientBufferRule__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
            dashMetrics: dashMetrics,
            settings: settings
          }));
        }

        if (settings.get().streaming.abr.additionalAbrRules.switchHistoryRule) {
          qualitySwitchRules.push((0,_SwitchHistoryRule__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create());
        }

        if (settings.get().streaming.abr.additionalAbrRules.droppedFramesRule) {
          qualitySwitchRules.push((0,_DroppedFramesRule__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create());
        }

        if (settings.get().streaming.abr.additionalAbrRules.abandonRequestsRule) {
          abandonFragmentRules.push((0,_AbandonRequestsRule__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
            dashMetrics: dashMetrics,
            mediaPlayerModel: mediaPlayerModel,
            settings: settings
          }));
        }
      }
    } // add custom ABR rules if any


    var customRules = customParametersModel.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 (0,_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 || (0,_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 || (0,_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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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;
            switchRequest.reason.rule = this.getClassName();
            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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _constants_Constants__WEBPACK_IMPORTED_MODULE_8__ = __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) 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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
  var instance, logger, bolaStateDict;

  function setup() {
    logger = (0,_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(e) {
    // if we rebuffer, we don't want the placeholder buffer to artificially raise BOLA quality
    var mediaType = e.mediaType; // if audio buffer runs empty (due to track switch for example) then reset placeholder buffer only for audio (to avoid decrease video BOLA quality)

    var stateDict = mediaType === _constants_Constants__WEBPACK_IMPORTED_MODULE_8__["default"].AUDIO ? [_constants_Constants__WEBPACK_IMPORTED_MODULE_8__["default"].AUDIO] : bolaStateDict;

    for (var _mediaType in stateDict) {
      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 = (0,_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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_2__["default"])(context).getInstance().getLogger(instance);
  }

  function getMaxIndex(rulesContext) {
    var switchRequest = (0,_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 (0,_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 ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance();
  var dashMetrics = config.dashMetrics;
  var instance, logger, bufferStateDict;

  function setup() {
    logger = (0,_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 = (0,_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 scheduleController = rulesContext.getScheduleController();
    var isDynamic = streamInfo && streamInfo.manifestInfo && streamInfo.manifestInfo.isDynamic;
    var playbackController = scheduleController.getPlaybackController(); // Don't ask for a bitrate change if there is not info about buffer state or if fragmentDuration is not defined

    var lowLatencyEnabled = playbackController.getLowLatencyModeEnabled();

    if (shouldIgnore(lowLatencyEnabled, 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(lowLatencyEnabled, mediaType) {
    return !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 ***!
  \********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
  var instance, l2AStateDict, l2AParameterDict, logger;
  /**
   * Setup function to initialize L2ARule
   */

  function setup() {
    logger = (0,_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;
    l2AState.lastSegmentUrl = '';
  }
  /**
   * 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 = (0,_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

        var currentHttpRequest = dashMetrics.getCurrentHttpRequest(mediaType);

        if (lastthroughput < 1) {
          lastthroughput = 1;
        } //To avoid division with 0 (avoid infinity) in case of an absolute network outage
        // Note that for SegmentBase addressing the request url does not change.
        // As this is not relevant for low latency streaming at this point the check below is sufficient


        if (currentHttpRequest.url === l2AState.lastSegmentUrl || currentHttpRequest.type === _vo_metrics_HTTPRequest__WEBPACK_IMPORTED_MODULE_3__.HTTPRequest.INIT_SEGMENT_TYPE) {
          // No change to inputs or init segment so use previously calculated quality
          quality = l2AState.lastQuality;
        } else {
          // Recalculate Q
          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);
          }

          l2AState.lastSegmentUrl = currentHttpRequest.url;
        }

        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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 setup() {}

  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 = (0,_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
  };
  setup();
  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 ***!
  \***************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \**********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \**************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_0__["default"])(context).getInstance().getLogger(instance);
    learningController = (0,_LearningAbrController__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create();
    qoeEvaluator = (0,_LoLpQoEEvaluator__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create();
  }

  function getMaxIndex(rulesContext) {
    try {
      var switchRequest = (0,_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 = (0,_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) {
        logger.debug('[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 ***!
  \************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 {number|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 ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \******************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_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 = (0,_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 dischargePreBuffer() {}

  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 hasBufferAtTime() {
    return true;
  }

  function getAllRangesWithSafetyFactor() {
    return [];
  }

  function getContinuousBufferTimeForTargetTime() {
    return Number.POSITIVE_INFINITY;
  }

  function clearBuffers() {
    return Promise.resolve();
  }

  function pruneBuffer() {
    return;
  }

  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,
    dischargePreBuffer: dischargePreBuffer,
    getBuffer: getBuffer,
    getBufferLevel: getBufferLevel,
    getRangeAt: getRangeAt,
    pruneBuffer: pruneBuffer,
    hasBufferAtTime: hasBufferAtTime,
    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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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_VttCustomRenderingParser__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/VttCustomRenderingParser */ "./src/streaming/utils/VttCustomRenderingParser.js");
/* harmony import */ var _utils_TTMLParser__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/TTMLParser */ "./src/streaming/utils/TTMLParser.js");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _streaming_MediaPlayerEvents__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../streaming/MediaPlayerEvents */ "./src/streaming/MediaPlayerEvents.js");
/* harmony import */ var _utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_10__ = __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, vttCustomRenderingParser, ttmlParser, eventBus, allTracksAreDisabled, forceTextStreaming, textTracksAdded, disableTextBeforeTextTracksAdded;

  function setup() {
    forceTextStreaming = false;
    textTracksAdded = false;
    disableTextBeforeTextTracksAdded = false;
    vttParser = (0,_utils_VTTParser__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
    vttCustomRenderingParser = (0,_utils_VttCustomRenderingParser__WEBPACK_IMPORTED_MODULE_5__["default"])(context).getInstance();
    ttmlParser = (0,_utils_TTMLParser__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
    eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_7__["default"])(context).getInstance();
    resetInitialSettings();
  }

  function initialize() {
    eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_8__["default"].TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);

    if (settings.get().streaming.text.webvtt.customRenderingEnabled) {
      eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_8__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
      eventBus.on(_core_events_Events__WEBPACK_IMPORTED_MODULE_8__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, instance);
    }
  }

  function initializeForStream(streamInfo) {
    var streamId = streamInfo.id;
    var tracks = (0,_TextTracks__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
      videoModel: videoModel,
      settings: settings,
      streamInfo: streamInfo
    });
    tracks.initialize();
    textTracks[streamId] = tracks;
    var textSourceBuffer = (0,_TextSourceBuffer__WEBPACK_IMPORTED_MODULE_2__["default"])(context).create({
      errHandler: errHandler,
      adapter: adapter,
      manifestModel: manifestModel,
      mediaController: mediaController,
      videoModel: videoModel,
      textTracks: tracks,
      vttParser: vttParser,
      vttCustomRenderingParser: vttCustomRenderingParser,
      ttmlParser: ttmlParser,
      streamInfo: streamInfo,
      settings: settings
    });
    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 _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 {
      var currentTrack = mediaController.getCurrentTrackFor(_constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT, streamId);

      if (currentTrack) {
        var defaultSettings = {
          lang: currentTrack.lang,
          role: currentTrack.roles[0],
          index: currentTrack.index,
          codec: currentTrack.codec,
          accessibility: currentTrack.accessibility[0]
        };
        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_9__["default"].TEXT_TRACKS_ADDED, {
      enabled: isTextEnabled(),
      index: index,
      tracks: tracks,
      streamId: streamId
    });
    textTracksAdded = true;
  }

  function _onPlaybackTimeUpdated(e) {
    try {
      var streamId = e.streamId;

      if (!textTracks[streamId] || isNaN(e.time)) {
        return;
      }

      textTracks[streamId].manualCueProcessing(e.time);
    } catch (err) {}
  }

  function _onPlaybackSeeking(e) {
    try {
      var streamId = e.streamId;

      if (!textTracks[streamId]) {
        return;
      }

      textTracks[streamId].disableManualTracks();
    } catch (e) {}
  }

  function enableText(streamId, enable) {
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_10__.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);
        }
      }
    }

    return true;
  }

  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) {
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_10__.checkParameterType)(enable, 'boolean');
    forceTextStreaming = enable;
    return true;
  }

  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].disableManualTracks();
    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_8__["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_8__["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_8__["default"].TEXT_TRACKS_QUEUE_INITIALIZED, _onTextTracksAdded, instance);

    if (settings.get().streaming.text.webvtt.customRenderingEnabled) {
      eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_8__["default"].PLAYBACK_TIME_UPDATED, _onPlaybackTimeUpdated, instance);
      eventBus.off(_core_events_Events__WEBPACK_IMPORTED_MODULE_8__["default"].PLAYBACK_SEEKING, _onPlaybackSeeking, 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,
    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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _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 vttCustomRenderingParser = config.vttCustomRenderingParser;
  var ttmlParser = config.ttmlParser;
  var streamInfo = config.streamInfo;
  var settings = config.settings;
  var context = this.context;
  var eventBus = (0,_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, lastChunkEnd, embeddedCea608FieldParsers, embeddedTextHtmlRender;

  function setup() {
    logger = (0,_core_Debug__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance().getLogger(instance);
    boxParser = (0,_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 = (0,_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;
    lastChunkEnd = null;
    embeddedInitialized = true;
    embeddedTextHtmlRender = (0,_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;
    lastChunkEnd = 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__.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__.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);
          var entry = {
            styles: {}
          };

          for (k = 0; k < box1.boxes.length; k++) {
            var box2 = box1.boxes[k];
            logger.debug('VTT box2: ' + box2.type); // Mandatory cue payload lines

            if (box2.type === 'payl') {
              entry.start = sample.cts / timescale;
              entry.end = (sample.cts + sample.duration) / timescale;
              entry.data = box2.cue_text;
            } // The styling information
            else if (box2.type === 'sttg' && box2.settings && box2.settings !== '') {
              try {
                var stylings = box2.settings.split(' ');
                entry.styles = vttParser.getCaptionStyles(stylings);
              } catch (e) {}
            }
          }

          if (entry && entry.data) {
            captionArray.push(entry);
            logger.debug("VTT  ".concat(entry.start, " - ").concat(entry.end, " :  ").concat(entry.data));
          }
        }
      }
    }

    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__.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 _isDiscontinuityOfChunks(embeddedLastSequenceNumber, sequenceNumber, numSequences, lastChunkEnd, chunkStart) {
    if (embeddedLastSequenceNumber === null || sequenceNumber === null || lastChunkEnd === null || chunkStart === null) {
      return false;
    } // Sequence number is always 1 for low latency streams


    if (sequenceNumber === embeddedLastSequenceNumber) {
      // time-based continuity check
      return lastChunkEnd !== chunkStart;
    }

    return sequenceNumber !== embeddedLastSequenceNumber + numSequences;
  }

  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;
      var chunkStart = Math.trunc(chunk.start);
      var chunkEnd = Math.trunc(chunk.end);

      if (!embeddedCea608FieldParsers[0] && !embeddedCea608FieldParsers[1]) {
        _setupCeaParser();
      }

      if (embeddedTimescale) {
        if (_isDiscontinuityOfChunks(embeddedLastSequenceNumber, sequenceNumber, samplesInfo.numSequences, lastChunkEnd, chunkStart)) {
          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;
        lastChunkEnd = chunkEnd;
      }
    }
  }

  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().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().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().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 = settings.get().streaming.text.webvtt.customRenderingEnabled && vttCustomRenderingParser ? vttCustomRenderingParser : 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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
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 CUE_PROPS_TO_COMPARE = ['text', 'align', 'fontSize', 'id', 'isd', 'line', 'lineAlign', 'lineHeight', 'linePadding', 'position', 'positionAlign', 'region', 'size', 'snapToLines', 'vertical'];

function TextTracks(config) {
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  var videoModel = config.videoModel;
  var streamInfo = config.streamInfo;
  var settings = config.settings;
  var instance, logger, Cue, textTrackQueue, nativeTrackElementArr, currentTrackIdx, actualVideoLeft, actualVideoTop, actualVideoWidth, actualVideoHeight, captionContainer, vttCaptionContainer, videoSizeCheckInterval, fullscreenAttribute, displayCCOnTop, previousISDState, topZIndex, resizeObserver;

  function setup() {
    logger = (0,_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;
    vttCaptionContainer = 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();
    vttCaptionContainer = videoModel.getVttRenderingDiv();
    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;
          videoTextTrack.manualMode = 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 _resolveImageSrc(cue, src) {
    var imsc1ImgUrnTester = /^(urn:)(mpeg:[a-z0-9][a-z0-9-]{0,31}:)(subs:)([0-9]+)$/;
    var smpteImgUrnTester = /^#(.*)$/;

    if (imsc1ImgUrnTester.test(src)) {
      var match = imsc1ImgUrnTester.exec(src);
      var imageId = parseInt(match[4], 10) - 1;
      var imageData = btoa(cue.images[imageId]);
      var imageSrc = 'data:image/png;base64,' + imageData;
      return imageSrc;
    } else if (smpteImgUrnTester.test(src)) {
      var _match = smpteImgUrnTester.exec(src);

      var _imageId = _match[1];

      var _imageSrc = 'data:image/png;base64,' + cue.embeddedImages[_imageId];

      return _imageSrc;
    } else {
      return src;
    }
  }

  function _renderCaption(cue) {
    if (captionContainer) {
      var finalCue = document.createElement('div');
      captionContainer.appendChild(finalCue);
      previousISDState = (0,imsc__WEBPACK_IMPORTED_MODULE_6__.renderHTML)(cue.isd, finalCue, function (src) {
        return _resolveImageSrc(cue, src);
      }, 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
      });
    }
  }

  function _extendLastCue(cue, track) {
    if (!settings.get().streaming.text.extendSegmentedCues) {
      return false;
    }

    if (!track.cues || track.cues.length === 0) {
      return false;
    }

    var prevCue = track.cues[track.cues.length - 1]; // Check previous cue endTime with current cue startTime
    // (should we consider an epsilon margin? for example to get around rounding issues)

    if (prevCue.endTime < cue.startTime) {
      return false;
    } // Compare cues content


    if (!_cuesContentAreEqual(prevCue, cue, CUE_PROPS_TO_COMPARE)) {
      return false;
    }

    prevCue.endTime = Math.max(prevCue.endTime, cue.endTime);
    return true;
  }

  function _cuesContentAreEqual(cue1, cue2, props) {
    for (var i = 0; i < props.length; i++) {
      var key = props[i];

      if (JSON.stringify(cue1[key]) !== JSON.stringify(cue2[key])) {
        return false;
      }
    }

    return true;
  }

  function _resolveImagesInContents(cue, contents) {
    if (!contents) {
      return;
    }

    contents.forEach(function (c) {
      if (c.kind && c.kind === 'image') {
        c.src = _resolveImageSrc(cue, c.src);
      }

      _resolveImagesInContents(cue, c.contents);
    });
  }
  /*
   * Add captions to track, store for later adding, or add captions added before
   */


  function addCaptions(trackIdx, timeOffset, captionData) {
    var track = getTrackByIdx(trackIdx);

    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 (!isNaN(currentItem.start) && !isNaN(currentItem.end)) {
        cue = currentItem.type === 'html' && captionContainer ? _handleHtmlCaption(currentItem, timeOffset, track) : currentItem.data ? _handleNonHtmlCaption(currentItem, timeOffset, track) : null;
      }

      try {
        if (cue) {
          if (!cueInTrack(track, cue)) {
            if (settings.get().streaming.text.webvtt.customRenderingEnabled) {
              if (!track.manualCueList) {
                track.manualCueList = [];
              }

              track.manualCueList.push(cue);
            } else {
              if (!_extendLastCue(cue, track)) {
                track.addCue(cue);
              }
            }
          }
        } else {
          logger.error('Impossible to display subtitles. You might have missed setting a TTML rendering div via player.attachTTMLRenderingDiv(TTMLRenderingDiv)');
        }
      } 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 _handleHtmlCaption(currentItem, timeOffset, track) {
    var self = this;
    var 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'; // Resolve images sources

    if (cue.isd) {
      _resolveImagesInContents(cue, cue.isd.contents);
    }

    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;
          }
        }
      }
    };

    return cue;
  }

  function _handleNonHtmlCaption(currentItem, timeOffset, track) {
    var cue = new Cue(currentItem.start - timeOffset, currentItem.end - timeOffset, currentItem.data);
    cue.cueID = "".concat(cue.startTime, "_").concat(cue.endTime);
    cue.isActive = false;

    if (currentItem.styles) {
      try {
        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.snapToLines !== undefined && 'snapToLines' in cue) {
          cue.snapToLines = currentItem.styles.snapToLines;
        }

        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;
        }
      } catch (e) {
        logger.error(e);
      }
    }

    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
        });
      }
    };

    return cue;
  }

  function manualCueProcessing(time) {
    var activeTracks = _getManualActiveTracks();

    if (activeTracks && activeTracks.length > 0) {
      var targetTrack = activeTracks[0];
      var cues = targetTrack.manualCueList;

      if (cues && cues.length > 0) {
        cues.forEach(function (cue) {
          // Render cue if target time is reached and not in active state
          if (cue.startTime <= time && cue.endTime >= time && !cue.isActive) {
            cue.isActive = true; // eslint-disable-next-line no-undef

            WebVTT.processCues(window, [cue], vttCaptionContainer, cue.cueID);
          } else if (cue.isActive && (cue.startTime > time || cue.endTime < time)) {
            cue.isActive = false;

            _removeManualCue(cue);
          }
        });
      }
    }
  }

  function _removeManualCue(cue) {
    if (vttCaptionContainer) {
      var divs = vttCaptionContainer.childNodes;

      for (var i = 0; i < divs.length; ++i) {
        if (divs[i].id === cue.cueID) {
          vttCaptionContainer.removeChild(divs[i]);
          --i;
        }
      }
    }
  }

  function disableManualTracks() {
    var activeTracks = _getManualActiveTracks();

    if (activeTracks && activeTracks.length > 0) {
      var targetTrack = activeTracks[0];
      var cues = targetTrack.manualCueList;

      if (cues && cues.length > 0) {
        cues.forEach(function (cue) {
          if (cue.isActive) {
            cue.isActive = false;

            if (vttCaptionContainer) {
              var divs = vttCaptionContainer.childNodes;

              for (var i = 0; i < divs.length; ++i) {
                if (divs[i].id === cue.cueID) {
                  vttCaptionContainer.removeChild(divs[i]);
                  --i;
                }
              }
            }
          }
        });
      }
    }
  }

  function _getManualActiveTracks() {
    var tracks = videoModel.getTextTracks();
    var activeTracks = [];

    var _iterator = _createForOfIteratorHelper(tracks),
        _step;

    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var track = _step.value;

        if (track.manualMode === _constants_Constants__WEBPACK_IMPORTED_MODULE_0__["default"].TEXT_SHOWING) {
          activeTracks.push(track);
        }
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }

    return activeTracks;
  }

  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) {
    var strict = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;

    if (!cue) {
      return false;
    }

    return (isNaN(start) || (strict ? cue.startTime : cue.endTime) >= start) && (isNaN(end) || (strict ? cue.endTime : cue.startTime) <= end);
  }

  function deleteTrackCues(track, start, end) {
    var strict = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;

    if (track && (track.cues || track.manualCueList)) {
      var mode = track.cues && track.cues.length > 0 ? 'native' : 'custom';
      var cues = mode === 'native' ? track.cues : track.manualCueList;

      if (!cues || cues.length === 0) {
        return;
      }

      var lastIdx = cues.length - 1;

      for (var r = lastIdx; r >= 0; r--) {
        if (cueInRange(cues[r], start, end, strict)) {
          if (mode === 'native') {
            if (cues[r].onexit) {
              cues[r].onexit();
            }

            track.removeCue(cues[r]);
          } else {
            _removeManualCue(cues[r]);

            delete track.manualCueList[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, false);
      }
    }

    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;
    }

    if (track && track.manualMode !== mode) {
      track.manualMode = 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,
    manualCueProcessing: manualCueProcessing,
    disableManualTracks: disableManualTracks
  };
  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 ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 = (0,_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__.replaceTokenForTemplate)(track.templateUrl, 'Number', seqIdx);
    url = (0,_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__.replaceTokenForTemplate)(url, 'Time', (seqIdx - 1) * track.segmentDuration * track.timescale);
    url = (0,_dash_utils_SegmentsUtils__WEBPACK_IMPORTED_MODULE_5__.replaceTokenForTemplate)(url, 'Bandwidth', track.bandwidth);
    return (0,_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 ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "THUMBNAILS_SCHEME_ID_URIS": function() { return /* binding */ THUMBNAILS_SCHEME_ID_URIS; }
/* harmony export */ });
/* 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 = (0,_streaming_utils_URLUtils__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
  var instance, tracks, dashHandler, currentTrackIndex, mediaInfo, segmentsController, loader, boxParser;

  function setup() {
    reset();
    loader = (0,_streaming_net_XHRLoader__WEBPACK_IMPORTED_MODULE_7__["default"])(context).create({});
    boxParser = (0,_streaming_utils_BoxParser__WEBPACK_IMPORTED_MODULE_6__["default"])(context).getInstance();
    segmentsController = (0,_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 = (0,_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 = (0,_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 (0,_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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _baseUrlResolution_ContentSteeringSelector__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./baseUrlResolution/ContentSteeringSelector */ "./src/streaming/utils/baseUrlResolution/ContentSteeringSelector.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.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 = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_10__["default"])(context).getInstance();
  var instance, serviceLocationBlacklistController, basicSelector, dvbSelector, contentSteeringSelector, selector;

  function setup() {
    serviceLocationBlacklistController = (0,_controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_3__["default"])(context).create({
      updateEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].SERVICE_LOCATION_BASE_URL_BLACKLIST_CHANGED,
      addBlacklistEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_2__["default"].SERVICE_LOCATION_BASE_URL_BLACKLIST_ADD
    });
    basicSelector = (0,_baseUrlResolution_BasicSelector__WEBPACK_IMPORTED_MODULE_5__["default"])(context).create({
      blacklistController: serviceLocationBlacklistController
    });
    dvbSelector = (0,_baseUrlResolution_DVBSelector__WEBPACK_IMPORTED_MODULE_4__["default"])(context).create({
      blacklistController: serviceLocationBlacklistController
    });
    contentSteeringSelector = (0,_baseUrlResolution_ContentSteeringSelector__WEBPACK_IMPORTED_MODULE_9__["default"])(context).create();
    contentSteeringSelector.setConfig({
      blacklistController: serviceLocationBlacklistController
    });
    selector = basicSelector;
  }

  function setConfig(config) {
    if (config.selector) {
      selector = config.selector;
    }

    if (config.contentSteeringSelector) {
      contentSteeringSelector = config.contentSteeringSelector;
    }
  }

  function chooseSelector(isDVB) {
    (0,_utils_SupervisorTools__WEBPACK_IMPORTED_MODULE_8__.checkParameterType)(isDVB, 'boolean');
    selector = isDVB ? dvbSelector : basicSelector;
  }

  function select(data) {
    if (!data) {
      return;
    } // Check if we got any instructions from the content steering element in the MPD or from the content steering server


    if (settings.get().streaming.applyContentSteering) {
      var steeringIndex = contentSteeringSelector.selectBaseUrlIndex(data);

      if (!isNaN(steeringIndex) && steeringIndex !== -1) {
        data.selectedIdx = steeringIndex;
      }
    } // 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(data.selectedIdx)) {
      return data.baseUrls[data.selectedIdx];
    }

    var selectedBaseUrl = selector.select(data.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 = data.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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _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() {
  var logger, instance;
  var context = this.context;

  function setup() {
    logger = (0,_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__.parseBuffer(data);
    var dashIsoFile = (0,_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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "supportsMediaSource": function() { return /* binding */ supportsMediaSource; }
/* harmony export */ });
/* 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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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");
/* harmony import */ var _core_EventBus__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/EventBus */ "./src/core/EventBus.js");
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");






function CapabilitiesFilter() {
  var context = this.context;
  var eventBus = (0,_core_EventBus__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance();
  var instance, adapter, capabilities, settings, customParametersModel, logger;

  function setup() {
    logger = (0,_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;
    }

    if (config.customParametersModel) {
      customParametersModel = config.customParametersModel;
    }
  }

  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) {
            eventBus.trigger(_core_events_Events__WEBPACK_IMPORTED_MODULE_4__["default"].ADAPTATION_SET_REMOVED_NO_CAPABILITIES, {
              adaptationSet: as
            });
            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) {
    var customCapabilitiesFilters = customParametersModel.getCustomCapabilitiesFilters();

    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;
      });
    });
  }

  instance = {
    setConfig: setConfig,
    filterUnsupportedFeatures: filterUnsupportedFeatures
  };
  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 ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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() {
  var customTimeRangeArray = [];
  var length = 0;

  function add(start, end) {
    var i;

    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) {
    (0,_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) {
    (0,_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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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) {
    checkConfig();

    if (!settings.get().streaming.lastMediaSettingsCachingInfo.enabled) {
      return null;
    }

    var mediaSettings = null; //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) {
    checkConfig();

    if (!settings.get().streaming.lastBitrateCachingInfo.enabled) {
      return NaN;
    }

    var savedBitrate = NaN; //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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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, there is
   * not enough data, or if the value exceeds the maximum safe integer value
   * @memberof EBMLParser
   */


  function getMatroskaUint(size) {
    if (size > 4) {
      return getMatroskaUintLarge(size);
    }

    var val = 0;

    for (var i = 0; i < size; i += 1) {
      val <<= 8;
      val |= data.getUint8(pos + i) & 0xff;
    }

    pos += size;
    return val >>> 0;
  }
  /**
   * 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, there is
   * not enough data, or if the value exceeds the maximum safe integer value
   */


  function getMatroskaUintLarge(size) {
    var limit = Math.floor(Number.MAX_SAFE_INTEGER / 256);
    var val = 0;

    for (var i = 0; i < size; i += 1) {
      if (val > limit) {
        throw new Error('Value exceeds safe integer limit');
      }

      val *= 256;
      var n = data.getUint8(pos + i);

      if (val > Number.MAX_SAFE_INTEGER - n) {
        throw new Error('Value exceeds safe integer limit');
      }

      val += n;
    }

    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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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/LocationSelector.js":
/*!*************************************************!*\
  !*** ./src/streaming/utils/LocationSelector.js ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _core_events_Events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/events/Events */ "./src/core/events/Events.js");
/* harmony import */ var _controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../controllers/BlacklistController */ "./src/streaming/controllers/BlacklistController.js");
/* harmony import */ var _core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/FactoryMaker */ "./src/core/FactoryMaker.js");
/* harmony import */ var _core_Settings__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../core/Settings */ "./src/core/Settings.js");
/* harmony import */ var _dash_controllers_ContentSteeringController__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../dash/controllers/ContentSteeringController */ "./src/dash/controllers/ContentSteeringController.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) 2023, 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 LocationSelector() {
  var context = this.context;
  var settings = (0,_core_Settings__WEBPACK_IMPORTED_MODULE_3__["default"])(context).getInstance();
  var instance, blacklistController, contentSteeringController;

  function setup() {
    blacklistController = (0,_controllers_BlacklistController__WEBPACK_IMPORTED_MODULE_1__["default"])(context).create({
      updateEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_0__["default"].SERVICE_LOCATION_LOCATION_BLACKLIST_CHANGED,
      addBlacklistEventName: _core_events_Events__WEBPACK_IMPORTED_MODULE_0__["default"].SERVICE_LOCATION_LOCATION_BLACKLIST_ADD
    });
    contentSteeringController = (0,_dash_controllers_ContentSteeringController__WEBPACK_IMPORTED_MODULE_4__["default"])(context).getInstance();
  }

  function setConfig(config) {
    if (config.blacklistController) {
      blacklistController = config.blacklistController;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }
  }
  /**
   *
   * @param {MpdLocation[]} mpdLocations
   * @returns {*}
   */


  function select(mpdLocations) {
    if (!mpdLocations || mpdLocations.length === 0) {
      return null;
    }

    var mpdLocation = null;

    if (settings.get().streaming.applyContentSteering) {
      mpdLocation = _selectByContentSteering(mpdLocations);
    }

    if (!mpdLocation) {
      mpdLocation = _selectByDefault(mpdLocations);
    }

    return mpdLocation;
  }

  function _selectByContentSteering(mpdLocations) {
    // Search in the response data of the steering server
    var currentSteeringResponseData = contentSteeringController.getCurrentSteeringResponseData();

    if (currentSteeringResponseData && currentSteeringResponseData.pathwayPriority && currentSteeringResponseData.pathwayPriority.length > 0) {
      return _findMpdLocation(currentSteeringResponseData.pathwayPriority, mpdLocations);
    }

    return null;
  }

  function _findMpdLocation() {
    var pathwayPriority = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var mpdLocations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    var i = 0;
    var target = null;

    var _loop = function _loop() {
      var curr = pathwayPriority[i];
      var idx = mpdLocations.findIndex(function (elem) {
        return elem.serviceLocation && elem.serviceLocation === curr;
      });

      if (idx !== -1 && !blacklistController.contains(mpdLocations[idx].serviceLocation)) {
        target = mpdLocations[idx];
        return "break";
      }

      i += 1;
    };

    while (i < pathwayPriority.length) {
      var _ret = _loop();

      if (_ret === "break") break;
    }

    return target;
  }

  function _selectByDefault(mpdLocations) {
    return mpdLocations[0];
  }

  function reset() {
    blacklistController.reset();
  }

  instance = {
    select: select,
    setConfig: setConfig,
    reset: reset
  };
  setup();
  return instance;
}

LocationSelector.__dashjs_factory_name = 'LocationSelector';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_2__["default"].getClassFactory(LocationSelector));

/***/ }),

/***/ "./src/streaming/utils/ObjectUtils.js":
/*!********************************************!*\
  !*** ./src/streaming/utils/ObjectUtils.js ***!
  \********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "modifyRequest": function() { return /* binding */ modifyRequest; }
/* harmony export */ });
/* 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 modifyRequest(httpRequest, requestModifier) {
  var request = {
    url: httpRequest.url,
    method: httpRequest.method,
    headers: Object.assign({}, httpRequest.headers),
    credentials: httpRequest.withCredentials ? 'include' : undefined
  };
  return Promise.resolve(requestModifier.modifyRequest(request)).then(function () {
    return Object.assign(httpRequest, request, {
      withCredentials: request.credentials === 'include'
    });
  });
}

function RequestModifier() {
  var instance;

  function modifyRequestURL(url) {
    return url;
  } // eslint-disable-next-line no-unused-vars


  function modifyRequestHeader(request, _ref) {
    var url = _ref.url;
    return request;
  }

  instance = {
    modifyRequest: null,
    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/SegmentResponseModifier.js":
/*!********************************************************!*\
  !*** ./src/streaming/utils/SegmentResponseModifier.js ***!
  \********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 SegmentResponseModifier() {
  var instance;

  function modifyResponseAsync(chunk) {
    return Promise.resolve(chunk);
  }

  instance = {
    modifyResponseAsync: modifyResponseAsync
  };
  return instance;
}

SegmentResponseModifier.__dashjs_factory_name = 'SegmentResponseModifier';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(SegmentResponseModifier));

/***/ }),

/***/ "./src/streaming/utils/SupervisorTools.js":
/*!************************************************!*\
  !*** ./src/streaming/utils/SupervisorTools.js ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "checkInteger": function() { return /* binding */ checkInteger; },
/* harmony export */   "checkIsVideoOrAudioType": function() { return /* binding */ checkIsVideoOrAudioType; },
/* harmony export */   "checkParameterType": function() { return /* binding */ checkParameterType; },
/* harmony export */   "checkRange": function() { return /* binding */ checkRange; }
/* harmony export */ });
/* 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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _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 = (0,_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 = (0,_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 = (0,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 = (0,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;
        endTime = 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/TimeUtils.js":
/*!******************************************!*\
  !*** ./src/streaming/utils/TimeUtils.js ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 TimeUtils
 * @ignore
 * @description Provides utility functions for time manipulation/conversion
 */

function TimeUtils() {
  var instance;
  /**
   * Convert NTP timestamp into an UTC timestamp
   * @return {number}
   * @param {number} ntpTimestamp
   * @memberof module:TimeUtils
   * @instance
   */

  function ntpToUTC(ntpTimeStamp) {
    var start = new Date(Date.UTC(1900, 0, 1, 0, 0, 0));
    return new Date(start.getTime() + ntpTimeStamp).getTime();
  }

  instance = {
    ntpToUTC: ntpToUTC
  };
  return instance;
}

TimeUtils.__dashjs_factory_name = 'TimeUtils';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(TimeUtils));

/***/ }),

/***/ "./src/streaming/utils/URLUtils.js":
/*!*****************************************!*\
  !*** ./src/streaming/utils/URLUtils.js ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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 ***!
  \******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 = (0,_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];
        var isPercentage = false;

        if (val && val.search(/%/) != -1) {
          isPercentage = true;
          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 === 'auto' ? val : parseInt(val, 10);

          if (isPercentage) {
            styleObject.snapToLines = false;
          }
        }

        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,
    getCaptionStyles: getCaptionStyles
  };
  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/VttCustomRenderingParser.js":
/*!*********************************************************!*\
  !*** ./src/streaming/utils/VttCustomRenderingParser.js ***!
  \*********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 VttCustomRenderingParser() {
  var instance, vttjs;

  function setup() {
    try {
      if (window && window.WebVTT && window.WebVTT.Parser) {
        vttjs = new window.WebVTT.Parser(window, window.vttjs, window.WebVTT.StringDecoder());
      }
    } catch (e) {}
  }

  function parse(data) {
    var cues = [];

    vttjs.oncue = function (cue) {
      cue.start = cue.startTime;
      cue.end = cue.endTime;
      cue.data = cue.text;
      cue.styles = {
        align: cue.align,
        line: cue.line,
        position: cue.position,
        size: cue.size
      };
      cues.push(cue);
    };

    vttjs.parse(data);
    return cues;
  }

  instance = {
    parse: parse
  };
  setup();
  return instance;
}

VttCustomRenderingParser.__dashjs_factory_name = 'VttCustomRenderingParser';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getSingletonFactory(VttCustomRenderingParser));

/***/ }),

/***/ "./src/streaming/utils/baseUrlResolution/BasicSelector.js":
/*!****************************************************************!*\
  !*** ./src/streaming/utils/baseUrlResolution/BasicSelector.js ***!
  \****************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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/ContentSteeringSelector.js":
/*!**************************************************************************!*\
  !*** ./src/streaming/utils/baseUrlResolution/ContentSteeringSelector.js ***!
  \**************************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 _dash_controllers_ContentSteeringController__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../dash/controllers/ContentSteeringController */ "./src/dash/controllers/ContentSteeringController.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 ContentSteeringSelector() {
  var context = this.context;
  var instance, contentSteeringController, blacklistController;

  function setup() {
    contentSteeringController = (0,_dash_controllers_ContentSteeringController__WEBPACK_IMPORTED_MODULE_1__["default"])(context).getInstance();
  }

  function setConfig(config) {
    if (config.blacklistController) {
      blacklistController = config.blacklistController;
    }

    if (config.contentSteeringController) {
      contentSteeringController = config.contentSteeringController;
    }
  }

  function selectBaseUrlIndex(data) {
    var steeringIndex = NaN; // In case we dont have a selected idx yet we consider the defaultServiceLocation

    if (isNaN(data.selectedIdx)) {
      var steeringDataFromMpd = contentSteeringController.getSteeringDataFromManifest();

      if (steeringDataFromMpd && steeringDataFromMpd.defaultServiceLocationArray.length > 0) {
        steeringIndex = _findexIndexOfServiceLocation(steeringDataFromMpd.defaultServiceLocationArray, data.baseUrls);
      }
    } // Search in the response data of the steering server


    var currentSteeringResponseData = contentSteeringController.getCurrentSteeringResponseData();

    if (data.baseUrls && data.baseUrls.length && currentSteeringResponseData && currentSteeringResponseData.pathwayPriority && currentSteeringResponseData.pathwayPriority.length) {
      steeringIndex = _findexIndexOfServiceLocation(currentSteeringResponseData.pathwayPriority, data.baseUrls);
    }

    return steeringIndex;
  }

  function _findexIndexOfServiceLocation() {
    var pathwayPriority = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var baseUrls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    var i = 0;
    var steeringIndex = NaN;

    var _loop = function _loop() {
      var curr = pathwayPriority[i];
      var idx = baseUrls.findIndex(function (elem) {
        return elem.serviceLocation && elem.serviceLocation === curr;
      });

      if (idx !== -1 && !blacklistController.contains(baseUrls[idx].serviceLocation)) {
        steeringIndex = idx;
        return "break";
      }

      i += 1;
    };

    while (i < pathwayPriority.length) {
      var _ret = _loop();

      if (_ret === "break") break;
    }

    return steeringIndex;
  }

  instance = {
    selectBaseUrlIndex: selectBaseUrlIndex,
    setConfig: setConfig
  };
  setup();
  return instance;
}

ContentSteeringSelector.__dashjs_factory_name = 'ContentSteeringSelector';
/* harmony default export */ __webpack_exports__["default"] = (_core_FactoryMaker__WEBPACK_IMPORTED_MODULE_0__["default"].getClassFactory(ContentSteeringSelector));

/***/ }),

/***/ "./src/streaming/utils/baseUrlResolution/DVBSelector.js":
/*!**************************************************************!*\
  !*** ./src/streaming/utils/baseUrlResolution/DVBSelector.js ***!
  \**************************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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;

      case 'prft':
        this.version = boxData.version;
        this.reference_track_ID = boxData.reference_track_ID;
        this.ntp_timestamp_sec = boxData.ntp_timestamp_sec;
        this.ntp_timestamp_frac = boxData.ntp_timestamp_frac;
        this.media_time = boxData.media_time;
        this.flags = boxData.flags;
        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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*****************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*******************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \*************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "HTTPRequest": function() { return /* binding */ HTTPRequest; },
/* harmony export */   "HTTPRequestTrace": function() { return /* binding */ HTTPRequestTrace; }
/* harmony export */ });
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 = [];
  /**
   * The CMSD static and dynamic values retrieved from CMSD response headers.
   * @public
   */

  this.cmsd = null;
  /**
   * 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;
  /**
   * The type of the loader that was used. Distinguish between fetch loader and xhr loader
   */

  this._fileLoaderType = 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 = [];
};

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.DVB_REPORTING_TYPE = 'DVBReporting';
HTTPRequest.LICENSE = 'license';
HTTPRequest.CONTENT_STEERING_TYPE = 'ContentSteering';
HTTPRequest.OTHER_TYPE = 'other';


/***/ }),

/***/ "./src/streaming/vo/metrics/ManifestUpdate.js":
/*!****************************************************!*\
  !*** ./src/streaming/vo/metrics/ManifestUpdate.js ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "ManifestUpdate": function() { return /* binding */ ManifestUpdate; },
/* harmony export */   "ManifestUpdateRepresentationInfo": function() { return /* binding */ ManifestUpdateRepresentationInfo; },
/* harmony export */   "ManifestUpdateStreamInfo": function() { return /* binding */ ManifestUpdateStreamInfo; }
/* harmony export */ });
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 ***!
  \**********************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "PlayList": function() { return /* binding */ PlayList; },
/* harmony export */   "PlayListTrace": function() { return /* binding */ PlayListTrace; }
/* harmony export */ });
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 ***!
  \**********************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \***************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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 ***!
  \****************************************************/
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {

"use strict";
__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);

/***/ }),

/***/ "./node_modules/bcp-47-match/index.js":
/*!********************************************!*\
  !*** ./node_modules/bcp-47-match/index.js ***!
  \********************************************/
/***/ (function(__unused_webpack_module, exports) {

"use strict";


// See https://tools.ietf.org/html/rfc4647#section-3.1
// for more information on the algorithms.

exports.basicFilter = factory(basic, true)
exports.extendedFilter = factory(extended, true)
exports.lookup = factory(lookup)

// Basic Filtering (Section 3.3.1) matches a language priority list consisting
// of basic language ranges (Section 2.1) to sets of language tags.
function basic(tag, range) {
  return range === '*' || tag === range || tag.indexOf(range + '-') > -1
}

// Extended Filtering (Section 3.3.2) matches a language priority list
// consisting of extended language ranges (Section 2.2) to sets of language
// tags.
function extended(tag, range) {
  // 3.3.2.1
  var left = tag.split('-')
  var right = range.split('-')
  var leftIndex = 0
  var rightIndex = 0

  // 3.3.2.2
  if (right[rightIndex] !== '*' && left[leftIndex] !== right[rightIndex]) {
    return false
  }

  leftIndex++
  rightIndex++

  // 3.3.2.3
  while (rightIndex < right.length) {
    // 3.3.2.3.A
    if (right[rightIndex] === '*') {
      rightIndex++
      continue
    }

    // 3.3.2.3.B
    if (!left[leftIndex]) return false

    // 3.3.2.3.C
    if (left[leftIndex] === right[rightIndex]) {
      leftIndex++
      rightIndex++
      continue
    }

    // 3.3.2.3.D
    if (left[leftIndex].length === 1) return false

    // 3.3.2.3.E
    leftIndex++
  }

  // 3.3.2.4
  return true
}

// Lookup (Section 3.4) matches a language priority list consisting of basic
// language ranges to sets of language tags to find the one exact language tag
// that best matches the range.
function lookup(tag, range) {
  var right = range
  var index

  /* eslint-disable-next-line no-constant-condition */
  while (true) {
    if (right === '*' || tag === right) return true

    index = right.lastIndexOf('-')

    if (index < 0) return false

    if (right.charAt(index - 2) === '-') index -= 2

    right = right.slice(0, index)
  }
}

// Factory to perform a filter or a lookup.
// This factory creates a function that accepts a list of tags and a list of
// ranges, and contains logic to exit early for lookups.
// `check` just has to deal with one tag and one range.
// This match function iterates over ranges, and for each range,
// iterates over tags.  That way, earlier ranges matching any tag have
// precedence over later ranges.
function factory(check, filter) {
  return match

  function match(tags, ranges) {
    var left = cast(tags, 'tag')
    var right = cast(ranges == null ? '*' : ranges, 'range')
    var matches = []
    var rightIndex = -1
    var range
    var leftIndex
    var next

    while (++rightIndex < right.length) {
      range = right[rightIndex].toLowerCase()

      // Ignore wildcards in lookup mode.
      if (!filter && range === '*') continue

      leftIndex = -1
      next = []

      while (++leftIndex < left.length) {
        if (check(left[leftIndex].toLowerCase(), range)) {
          // Exit if this is a lookup and we have a match.
          if (!filter) return left[leftIndex]
          matches.push(left[leftIndex])
        } else {
          next.push(left[leftIndex])
        }
      }

      left = next
    }

    // If this is a filter, return the list.  If it’s a lookup, we didn’t find
    // a match, so return `undefined`.
    return filter ? matches : undefined
  }
}

// Validate tags or ranges, and cast them to arrays.
function cast(values, name) {
  var value = values && typeof values === 'string' ? [values] : values

  if (!value || typeof value !== 'object' || !('length' in value)) {
    throw new Error(
      'Invalid ' + name + ' `' + value + '`, expected non-empty string'
    )
  }

  return value
}


/***/ }),

/***/ "./node_modules/bcp-47-normalize/index.js":
/*!************************************************!*\
  !*** ./node_modules/bcp-47-normalize/index.js ***!
  \************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


module.exports = __webpack_require__(/*! ./lib */ "./node_modules/bcp-47-normalize/lib/index.js")


/***/ }),

/***/ "./node_modules/bcp-47-normalize/lib/index.js":
/*!****************************************************!*\
  !*** ./node_modules/bcp-47-normalize/lib/index.js ***!
  \****************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


var bcp47 = __webpack_require__(/*! bcp-47 */ "./node_modules/bcp-47/index.js")
var match = __webpack_require__(/*! bcp-47-match */ "./node_modules/bcp-47-match/index.js")
var matches = __webpack_require__(/*! ./matches.json */ "./node_modules/bcp-47-normalize/lib/matches.json")
var fields = __webpack_require__(/*! ./fields.json */ "./node_modules/bcp-47-normalize/lib/fields.json")
var defaults = __webpack_require__(/*! ./defaults.json */ "./node_modules/bcp-47-normalize/lib/defaults.json")
var many = __webpack_require__(/*! ./many.json */ "./node_modules/bcp-47-normalize/lib/many.json")

module.exports = normalize

var own = {}.hasOwnProperty

var collator = new Intl.Collator()

var emptyExtraFields = {
  variants: [],
  extensions: [],
  privateuse: [],
  irregular: null,
  regular: null
}

function normalize(value, options) {
  var settings = options || {}
  // 1. normalize and lowercase the tag (`sgn-be-fr` -> `sfb`).
  var schema = bcp47.parse(String(value || '').toLowerCase(), settings)
  var tag = bcp47.stringify(schema)
  var index = -1
  var key

  if (!tag) {
    return tag
  }

  // 2. Do fancy, expensive replaces (`ha-latn-gh` -> `ha-gh`).
  while (++index < matches.length) {
    if (match.extendedFilter(tag, matches[index].from).length) {
      replace(schema, matches[index].from, matches[index].to)
      tag = bcp47.stringify(schema)
    }
  }

  // 3. Do basic field replaces (`en-840` -> `en-us`).
  index = -1

  while (++index < fields.length) {
    if (remove(schema, fields[index].from.field, fields[index].from.value)) {
      add(schema, fields[index].to.field, fields[index].to.value)
    }
  }

  // 4. Remove defaults (`nl-nl` -> `nl`).
  tag = bcp47.stringify(Object.assign({}, schema, emptyExtraFields))
  index = -1

  while (++index < defaults.length) {
    if (tag === defaults[index]) {
      replace(
        schema,
        defaults[index],
        defaults[index].split('-').slice(0, -1).join('-')
      )
      tag = bcp47.stringify(Object.assign({}, schema, emptyExtraFields))
    }
  }

  // 5. Sort extensions on singleton.
  schema.extensions.sort(compareSingleton)

  // 6. Warn if fields (currently only regions) should be updated but have
  // multiple choices.
  if (settings.warning) {
    for (key in many) {
      if (own.call(many[key], schema[key])) {
        settings.warning(
          'Deprecated ' +
            key +
            ' `' +
            schema[key] +
            '`, expected one of `' +
            many[key][schema[key]].join('`, `') +
            '`',
          null,
          7
        )
      }
    }
  }

  // 7. Add proper casing back.
  // Format script (ISO 15924) as titlecase (example: `Latn`):
  if (schema.script) {
    schema.script =
      schema.script.charAt(0).toUpperCase() + schema.script.slice(1)
  }

  // Format region (ISO 3166) as uppercase (note: this doesn’t affect numeric
  // codes, which is fine):
  if (schema.region) {
    schema.region = schema.region.toUpperCase()
  }

  return bcp47.stringify(schema)
}

function replace(schema, from, to) {
  var left = bcp47.parse(from)
  var right = bcp47.parse(to)
  var removed = []
  var key

  // Remove values from `from`:
  for (key in left) {
    if (left[key] && left[key].length && remove(schema, key, left[key])) {
      removed.push(key)
    }
  }

  // Add values from `to`:
  for (key in right) {
    // Only add values that are defined on `to`, and that were either removed by
    // `from` or are currently empty.
    if (
      right[key] &&
      right[key].length &&
      (removed.indexOf(key) > -1 || !schema[key] || !schema[key].length)
    ) {
      add(schema, key, right[key])
    }
  }
}

function remove(object, key, value) {
  var removed = false
  var current
  var result
  var index
  var item

  /* istanbul ignore else - this is currently done by wrapping code, so else is
   * never reached.
   * However, that could change in the future, so leave this guard here. */
  if (value) {
    current = object[key]
    result = current

    if (current && typeof current === 'object') {
      result = []
      index = -1

      while (++index < current.length) {
        item = current[index]

        if (value.indexOf(item) < 0) {
          result.push(item)
        } else {
          removed = true
        }
      }
    } else if (current === value) {
      result = null
      removed = true
    }

    object[key] = result
  }

  return removed
}

function add(object, key, value) {
  var current = object[key]
  var list
  var index
  var item

  if (current && typeof current === 'object') {
    list = [].concat(value)
    index = -1

    while (++index < list.length) {
      item = list[index]

      /* istanbul ignore else - this currently can’t happen, but guard for the
       * future. */
      if (current.indexOf(item) < 0) {
        current.push(item)
      }
    }
  } else {
    object[key] = value
  }
}

function compareSingleton(left, right) {
  return collator.compare(left.singleton, right.singleton)
}


/***/ }),

/***/ "./node_modules/bcp-47/index.js":
/*!**************************************!*\
  !*** ./node_modules/bcp-47/index.js ***!
  \**************************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

"use strict";


exports.parse = __webpack_require__(/*! ./lib/parse */ "./node_modules/bcp-47/lib/parse.js")
exports.stringify = __webpack_require__(/*! ./lib/stringify */ "./node_modules/bcp-47/lib/stringify.js")


/***/ }),

/***/ "./node_modules/bcp-47/lib/parse.js":
/*!******************************************!*\
  !*** ./node_modules/bcp-47/lib/parse.js ***!
  \******************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


var alphanumeric = __webpack_require__(/*! is-alphanumerical */ "./node_modules/is-alphanumerical/index.js")
var alphabetical = __webpack_require__(/*! is-alphabetical */ "./node_modules/is-alphabetical/index.js")
var decimal = __webpack_require__(/*! is-decimal */ "./node_modules/is-decimal/index.js")
var regular = __webpack_require__(/*! ./regular.json */ "./node_modules/bcp-47/lib/regular.json")
var normal = __webpack_require__(/*! ./normalize.json */ "./node_modules/bcp-47/lib/normalize.json")

module.exports = parse

var own = {}.hasOwnProperty

// Parse a BCP 47 language tag.
/* eslint-disable-next-line complexity */
function parse(tag, options) {
  var settings = options || {}
  var result = empty()
  var source = String(tag)
  var value = source.toLowerCase()
  var index = 0
  var start
  var groups
  var offset

  // Check input.
  if (tag == null) {
    throw new Error('Expected string, got `' + tag + '`')
  }

  // Let’s start.
  // First: the edge cases.
  if (own.call(normal, value)) {
    if ((settings.normalize == null || settings.normalize) && normal[value]) {
      return parse(normal[value])
    }

    result[regular.indexOf(value) === -1 ? 'irregular' : 'regular'] = source

    return result
  }

  // Now, to actually parse, eat what could be a language.
  while (alphabetical(value.charCodeAt(index)) && index < 9) index++

  // A language.
  if (index > 1 /* Min 639. */ && index < 9 /* Max subtag. */) {
    // 5 and up is a subtag.
    // 4 is the size of reserved languages.
    // 3 an ISO 639-2 or ISO 639-3.
    // 2 is an ISO 639-1.
    // <https://github.com/wooorm/iso-639-2>
    // <https://github.com/wooorm/iso-639-3>
    result.language = source.slice(0, index)

    if (index < 4 /* Max 639. */) {
      groups = 0

      while (
        value.charCodeAt(index) === 45 /* `-` */ &&
        alphabetical(value.charCodeAt(index + 1)) &&
        alphabetical(value.charCodeAt(index + 2)) &&
        alphabetical(value.charCodeAt(index + 3)) &&
        !alphabetical(value.charCodeAt(index + 4))
      ) {
        if (groups > 2 /* Max extended language subtag count. */) {
          return fail(
            index,
            3,
            'Too many extended language subtags, expected at most 3 subtags'
          )
        }

        // Extended language subtag.
        result.extendedLanguageSubtags.push(source.slice(index + 1, index + 4))
        index += 4
        groups++
      }
    }

    // ISO 15924 script.
    // <https://github.com/wooorm/iso-15924>
    if (
      value.charCodeAt(index) === 45 /* `-` */ &&
      alphabetical(value.charCodeAt(index + 1)) &&
      alphabetical(value.charCodeAt(index + 2)) &&
      alphabetical(value.charCodeAt(index + 3)) &&
      alphabetical(value.charCodeAt(index + 4)) &&
      !alphabetical(value.charCodeAt(index + 5))
    ) {
      result.script = source.slice(index + 1, index + 5)
      index += 5
    }

    if (value.charCodeAt(index) === 45 /* `-` */) {
      // ISO 3166-1 region.
      // <https://github.com/wooorm/iso-3166>
      if (
        alphabetical(value.charCodeAt(index + 1)) &&
        alphabetical(value.charCodeAt(index + 2)) &&
        !alphabetical(value.charCodeAt(index + 3))
      ) {
        result.region = source.slice(index + 1, index + 3)
        index += 3
      }
      // UN M49 region.
      // <https://github.com/wooorm/un-m49>
      else if (
        decimal(value.charCodeAt(index + 1)) &&
        decimal(value.charCodeAt(index + 2)) &&
        decimal(value.charCodeAt(index + 3)) &&
        !decimal(value.charCodeAt(index + 4))
      ) {
        result.region = source.slice(index + 1, index + 4)
        index += 4
      }
    }

    while (value.charCodeAt(index) === 45 /* `-` */) {
      offset = start = index + 1

      while (alphanumeric(value.charCodeAt(offset))) {
        if (offset - start > 7 /* Max variant. */) {
          return fail(
            offset,
            1,
            'Too long variant, expected at most 8 characters'
          )
        }

        offset++
      }

      if (
        // Long variant.
        offset - start > 4 /* Min alpha numeric variant. */ ||
        // Short variant.
        (offset - start > 3 /* Min variant. */ &&
          decimal(value.charCodeAt(start)))
      ) {
        result.variants.push(source.slice(start, offset))
        index = offset
      }
      // Something else.
      else {
        break
      }
    }

    // Extensions.
    while (value.charCodeAt(index) === 45 /* `-` */) {
      // Exit if this isn’t an extension.
      if (
        value.charCodeAt(index + 1) === 120 /* `x` */ ||
        !alphanumeric(value.charCodeAt(index + 1)) ||
        value.charCodeAt(index + 2) !== 45 /* `-` */ ||
        !alphanumeric(value.charCodeAt(index + 3))
      ) {
        break
      }

      offset = index + 2
      groups = 0

      while (
        value.charCodeAt(offset) === 45 /* `-` */ &&
        alphanumeric(value.charCodeAt(offset + 1)) &&
        alphanumeric(value.charCodeAt(offset + 2))
      ) {
        start = offset + 1
        offset = start + 2
        groups++

        while (alphanumeric(value.charCodeAt(offset))) {
          if (offset - start > 7 /* Max extension. */) {
            return fail(
              offset,
              2,
              'Too long extension, expected at most 8 characters'
            )
          }

          offset++
        }
      }

      if (!groups) {
        return fail(
          offset,
          4,
          'Empty extension, extensions must have at least 2 characters of content'
        )
      }

      result.extensions.push({
        singleton: source.charAt(index + 1),
        extensions: source.slice(index + 3, offset).split('-')
      })

      index = offset
    }
  }
  // Not a language.
  else {
    index = 0
  }

  // Private use.
  if (
    (index === 0 && value.charCodeAt(index) === 120) /* `x` */ ||
    (value.charCodeAt(index) === 45 /* `-` */ &&
      value.charCodeAt(index + 1) === 120) /* `x` */
  ) {
    offset = index = index ? index + 2 : 1

    while (
      value.charCodeAt(offset) === 45 /* `-` */ &&
      alphanumeric(value.charCodeAt(offset + 1))
    ) {
      offset = start = index + 1

      while (alphanumeric(value.charCodeAt(offset))) {
        if (offset - start > 7 /* Max private use. */) {
          return fail(
            offset,
            5,
            'Too long private-use area, expected at most 8 characters'
          )
        }

        offset++
      }

      result.privateuse.push(source.slice(index + 1, offset))
      index = offset
    }
  }

  if (index !== source.length) {
    return fail(index, 6, 'Found superfluous content after tag')
  }

  return result

  function fail(offset, code, reason) {
    if (settings.warning) settings.warning(reason, code, offset)
    return settings.forgiving ? result : empty()
  }
}

// Create an empty results object.
function empty() {
  return {
    language: null,
    extendedLanguageSubtags: [],
    script: null,
    region: null,
    variants: [],
    extensions: [],
    privateuse: [],
    irregular: null,
    regular: null
  }
}


/***/ }),

/***/ "./node_modules/bcp-47/lib/stringify.js":
/*!**********************************************!*\
  !*** ./node_modules/bcp-47/lib/stringify.js ***!
  \**********************************************/
/***/ (function(module) {

"use strict";


module.exports = stringify

// Compile a language schema to a BCP 47 language tag.
function stringify(schema) {
  var fields = schema || {}
  var result = []
  var values
  var index
  var value

  if (fields.irregular || fields.regular) {
    return fields.irregular || fields.regular
  }

  if (fields.language) {
    result = result.concat(
      fields.language,
      fields.extendedLanguageSubtags || [],
      fields.script || [],
      fields.region || [],
      fields.variants || []
    )

    values = fields.extensions || []
    index = -1

    while (++index < values.length) {
      value = values[index]

      if (value.singleton && value.extensions && value.extensions.length) {
        result = result.concat(value.singleton, value.extensions)
      }
    }
  }

  if (fields.privateuse && fields.privateuse.length) {
    result = result.concat('x', fields.privateuse)
  }

  return result.join('-')
}


/***/ }),

/***/ "./node_modules/buffer/index.js":
/*!**************************************!*\
  !*** ./node_modules/buffer/index.js ***!
  \**************************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

"use strict";
/*!
 * The buffer module from node.js, for the browser.
 *
 * @author   Feross Aboukhadijeh <https://feross.org>
 * @license  MIT
 */
/* eslint-disable no-proto */



var base64 = __webpack_require__(/*! base64-js */ "./node_modules/buffer/node_modules/base64-js/index.js")
var ieee754 = __webpack_require__(/*! ieee754 */ "./node_modules/buffer/node_modules/ieee754/index.js")
var customInspectSymbol =
  (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
    ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
    : null

exports.Buffer = Buffer
exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50

var K_MAX_LENGTH = 0x7fffffff
exports.kMaxLength = K_MAX_LENGTH

/**
 * If `Buffer.TYPED_ARRAY_SUPPORT`:
 *   === true    Use Uint8Array implementation (fastest)
 *   === false   Print warning and recommend using `buffer` v4.x which has an 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+.
 *
 * We report that the browser does not support typed arrays if the are not subclassable
 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
 * for __proto__ and has a buggy typed array implementation.
 */
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()

if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
    typeof console.error === 'function') {
  console.error(
    'This browser lacks typed array (Uint8Array) support which is required by ' +
    '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  )
}

function typedArraySupport () {
  // Can typed array instances can be augmented?
  try {
    var arr = new Uint8Array(1)
    var proto = { foo: function () { return 42 } }
    Object.setPrototypeOf(proto, Uint8Array.prototype)
    Object.setPrototypeOf(arr, proto)
    return arr.foo() === 42
  } catch (e) {
    return false
  }
}

Object.defineProperty(Buffer.prototype, 'parent', {
  enumerable: true,
  get: function () {
    if (!Buffer.isBuffer(this)) return undefined
    return this.buffer
  }
})

Object.defineProperty(Buffer.prototype, 'offset', {
  enumerable: true,
  get: function () {
    if (!Buffer.isBuffer(this)) return undefined
    return this.byteOffset
  }
})

function createBuffer (length) {
  if (length > K_MAX_LENGTH) {
    throw new RangeError('The value "' + length + '" is invalid for option "size"')
  }
  // Return an augmented `Uint8Array` instance
  var buf = new Uint8Array(length)
  Object.setPrototypeOf(buf, Buffer.prototype)
  return buf
}

/**
 * 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) {
  // Common case.
  if (typeof arg === 'number') {
    if (typeof encodingOrOffset === 'string') {
      throw new TypeError(
        'The "string" argument must be of type string. Received type number'
      )
    }
    return allocUnsafe(arg)
  }
  return from(arg, encodingOrOffset, length)
}

Buffer.poolSize = 8192 // not used by this implementation

function from (value, encodingOrOffset, length) {
  if (typeof value === 'string') {
    return fromString(value, encodingOrOffset)
  }

  if (ArrayBuffer.isView(value)) {
    return fromArrayView(value)
  }

  if (value == null) {
    throw new TypeError(
      'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
      'or Array-like Object. Received type ' + (typeof value)
    )
  }

  if (isInstance(value, ArrayBuffer) ||
      (value && isInstance(value.buffer, ArrayBuffer))) {
    return fromArrayBuffer(value, encodingOrOffset, length)
  }

  if (typeof SharedArrayBuffer !== 'undefined' &&
      (isInstance(value, SharedArrayBuffer) ||
      (value && isInstance(value.buffer, SharedArrayBuffer)))) {
    return fromArrayBuffer(value, encodingOrOffset, length)
  }

  if (typeof value === 'number') {
    throw new TypeError(
      'The "value" argument must not be of type number. Received type number'
    )
  }

  var valueOf = value.valueOf && value.valueOf()
  if (valueOf != null && valueOf !== value) {
    return Buffer.from(valueOf, encodingOrOffset, length)
  }

  var b = fromObject(value)
  if (b) return b

  if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
      typeof value[Symbol.toPrimitive] === 'function') {
    return Buffer.from(
      value[Symbol.toPrimitive]('string'), encodingOrOffset, length
    )
  }

  throw new TypeError(
    'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
    'or Array-like Object. Received type ' + (typeof 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(value, encodingOrOffset, length)
}

// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
// https://github.com/feross/buffer/pull/148
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
Object.setPrototypeOf(Buffer, Uint8Array)

function assertSize (size) {
  if (typeof size !== 'number') {
    throw new TypeError('"size" argument must be of type number')
  } else if (size < 0) {
    throw new RangeError('The value "' + size + '" is invalid for option "size"')
  }
}

function alloc (size, fill, encoding) {
  assertSize(size)
  if (size <= 0) {
    return createBuffer(size)
  }
  if (fill !== undefined) {
    // Only pay attention to encoding if it's a string. This
    // prevents accidentally sending in a number that would
    // be interpreted as a start offset.
    return typeof encoding === 'string'
      ? createBuffer(size).fill(fill, encoding)
      : createBuffer(size).fill(fill)
  }
  return createBuffer(size)
}

/**
 * Creates a new filled Buffer instance.
 * alloc(size[, fill[, encoding]])
 **/
Buffer.alloc = function (size, fill, encoding) {
  return alloc(size, fill, encoding)
}

function allocUnsafe (size) {
  assertSize(size)
  return createBuffer(size < 0 ? 0 : checked(size) | 0)
}

/**
 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
 * */
Buffer.allocUnsafe = function (size) {
  return allocUnsafe(size)
}
/**
 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
 */
Buffer.allocUnsafeSlow = function (size) {
  return allocUnsafe(size)
}

function fromString (string, encoding) {
  if (typeof encoding !== 'string' || encoding === '') {
    encoding = 'utf8'
  }

  if (!Buffer.isEncoding(encoding)) {
    throw new TypeError('Unknown encoding: ' + encoding)
  }

  var length = byteLength(string, encoding) | 0
  var buf = createBuffer(length)

  var actual = buf.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')
    buf = buf.slice(0, actual)
  }

  return buf
}

function fromArrayLike (array) {
  var length = array.length < 0 ? 0 : checked(array.length) | 0
  var buf = createBuffer(length)
  for (var i = 0; i < length; i += 1) {
    buf[i] = array[i] & 255
  }
  return buf
}

function fromArrayView (arrayView) {
  if (isInstance(arrayView, Uint8Array)) {
    var copy = new Uint8Array(arrayView)
    return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
  }
  return fromArrayLike(arrayView)
}

function fromArrayBuffer (array, byteOffset, length) {
  if (byteOffset < 0 || array.byteLength < byteOffset) {
    throw new RangeError('"offset" is outside of buffer bounds')
  }

  if (array.byteLength < byteOffset + (length || 0)) {
    throw new RangeError('"length" is outside of buffer bounds')
  }

  var buf
  if (byteOffset === undefined && length === undefined) {
    buf = new Uint8Array(array)
  } else if (length === undefined) {
    buf = new Uint8Array(array, byteOffset)
  } else {
    buf = new Uint8Array(array, byteOffset, length)
  }

  // Return an augmented `Uint8Array` instance
  Object.setPrototypeOf(buf, Buffer.prototype)

  return buf
}

function fromObject (obj) {
  if (Buffer.isBuffer(obj)) {
    var len = checked(obj.length) | 0
    var buf = createBuffer(len)

    if (buf.length === 0) {
      return buf
    }

    obj.copy(buf, 0, 0, len)
    return buf
  }

  if (obj.length !== undefined) {
    if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
      return createBuffer(0)
    }
    return fromArrayLike(obj)
  }

  if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
    return fromArrayLike(obj.data)
  }
}

function checked (length) {
  // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  // length is NaN (which is otherwise coerced to zero.)
  if (length >= K_MAX_LENGTH) {
    throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
                         'size: 0x' + K_MAX_LENGTH.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 === true &&
    b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
}

Buffer.compare = function compare (a, b) {
  if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
    throw new TypeError(
      'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
    )
  }

  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 (!Array.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 (isInstance(buf, Uint8Array)) {
      if (pos + buf.length > buffer.length) {
        Buffer.from(buf).copy(buffer, pos)
      } else {
        Uint8Array.prototype.set.call(
          buffer,
          buf,
          pos
        )
      }
    } else if (!Buffer.isBuffer(buf)) {
      throw new TypeError('"list" argument must be an Array of Buffers')
    } else {
      buf.copy(buffer, pos)
    }
    pos += buf.length
  }
  return buffer
}

function byteLength (string, encoding) {
  if (Buffer.isBuffer(string)) {
    return string.length
  }
  if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
    return string.byteLength
  }
  if (typeof string !== 'string') {
    throw new TypeError(
      'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
      'Received type ' + typeof string
    )
  }

  var len = string.length
  var mustMatch = (arguments.length > 2 && arguments[2] === true)
  if (!mustMatch && 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':
        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 mustMatch ? -1 : 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 coercion 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
    }
  }
}

// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
// reliably in a browserify context because there could be multiple different
// copies of the 'buffer' package in use. This method works even for Buffer
// instances that were created from another copy of the `buffer` package.
// See: https://github.com/feross/buffer/issues/154
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
  if (length === 0) return ''
  if (arguments.length === 0) return utf8Slice(this, 0, length)
  return slowToString.apply(this, arguments)
}

Buffer.prototype.toLocaleString = Buffer.prototype.toString

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
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  if (this.length > max) str += ' ... '
  return '<Buffer ' + str + '>'
}
if (customInspectSymbol) {
  Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
}

Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  if (isInstance(target, Uint8Array)) {
    target = Buffer.from(target, target.offset, target.byteLength)
  }
  if (!Buffer.isBuffer(target)) {
    throw new TypeError(
      'The "target" argument must be one of type Buffer or Uint8Array. ' +
      'Received type ' + (typeof target)
    )
  }

  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 (numberIsNaN(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 (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
    }
  }

  var strLen = string.length

  if (length > strLen / 2) {
    length = strLen / 2
  }
  for (var i = 0; i < length; ++i) {
    var parsed = parseInt(string.substr(i * 2, 2), 16)
    if (numberIsNaN(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 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
    }
  } 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':
      case 'latin1':
      case 'binary':
        return asciiWrite(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 += hexSliceLookupTable[buf[i]]
  }
  return out
}

function utf16leSlice (buf, start, end) {
  var bytes = buf.slice(start, end)
  var res = ''
  // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
  for (var i = 0; i < bytes.length - 1; 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 = this.subarray(start, end)
  // Return an augmented `Uint8Array` instance
  Object.setPrototypeOf(newBuf, Buffer.prototype)

  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 =
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 =
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 =
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  offset = offset >>> 0
  if (!noAssert) checkOffset(offset, 1, this.length)
  return this[offset]
}

Buffer.prototype.readUint16LE =
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  offset = offset >>> 0
  if (!noAssert) checkOffset(offset, 2, this.length)
  return this[offset] | (this[offset + 1] << 8)
}

Buffer.prototype.readUint16BE =
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  offset = offset >>> 0
  if (!noAssert) checkOffset(offset, 2, this.length)
  return (this[offset] << 8) | this[offset + 1]
}

Buffer.prototype.readUint32LE =
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  offset = offset >>> 0
  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 =
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  offset = offset >>> 0
  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) {
  offset = offset >>> 0
  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) {
  offset = offset >>> 0
  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) {
  offset = offset >>> 0
  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) {
  offset = offset >>> 0
  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) {
  offset = offset >>> 0
  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) {
  offset = offset >>> 0
  if (!noAssert) checkOffset(offset, 4, this.length)
  return ieee754.read(this, offset, true, 23, 4)
}

Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  offset = offset >>> 0
  if (!noAssert) checkOffset(offset, 4, this.length)
  return ieee754.read(this, offset, false, 23, 4)
}

Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  offset = offset >>> 0
  if (!noAssert) checkOffset(offset, 8, this.length)
  return ieee754.read(this, offset, true, 52, 8)
}

Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  offset = offset >>> 0
  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 =
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 =
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 =
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  value = +value
  offset = offset >>> 0
  if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  this[offset] = (value & 0xff)
  return offset + 1
}

Buffer.prototype.writeUint16LE =
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  value = +value
  offset = offset >>> 0
  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  this[offset] = (value & 0xff)
  this[offset + 1] = (value >>> 8)
  return offset + 2
}

Buffer.prototype.writeUint16BE =
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  value = +value
  offset = offset >>> 0
  if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  this[offset] = (value >>> 8)
  this[offset + 1] = (value & 0xff)
  return offset + 2
}

Buffer.prototype.writeUint32LE =
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  value = +value
  offset = offset >>> 0
  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  this[offset + 3] = (value >>> 24)
  this[offset + 2] = (value >>> 16)
  this[offset + 1] = (value >>> 8)
  this[offset] = (value & 0xff)
  return offset + 4
}

Buffer.prototype.writeUint32BE =
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  value = +value
  offset = offset >>> 0
  if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  this[offset] = (value >>> 24)
  this[offset + 1] = (value >>> 16)
  this[offset + 2] = (value >>> 8)
  this[offset + 3] = (value & 0xff)
  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 (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)
  this[offset] = (value & 0xff)
  this[offset + 1] = (value >>> 8)
  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)
  this[offset] = (value >>> 8)
  this[offset + 1] = (value & 0xff)
  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)
  this[offset] = (value & 0xff)
  this[offset + 1] = (value >>> 8)
  this[offset + 2] = (value >>> 16)
  this[offset + 3] = (value >>> 24)
  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
  this[offset] = (value >>> 24)
  this[offset + 1] = (value >>> 16)
  this[offset + 2] = (value >>> 8)
  this[offset + 3] = (value & 0xff)
  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) {
  value = +value
  offset = offset >>> 0
  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) {
  value = +value
  offset = offset >>> 0
  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 (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  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('Index out of range')
  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

  if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
    // Use built-in when available, missing from IE11
    this.copyWithin(targetStart, start, end)
  } else {
    Uint8Array.prototype.set.call(
      target,
      this.subarray(start, end),
      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 (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)
    }
    if (val.length === 1) {
      var code = val.charCodeAt(0)
      if ((encoding === 'utf8' && code < 128) ||
          encoding === 'latin1') {
        // Fast path: If `val` fits into a single byte, use that numeric value.
        val = code
      }
    }
  } else if (typeof val === 'number') {
    val = val & 255
  } else if (typeof val === 'boolean') {
    val = Number(val)
  }

  // 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
      : Buffer.from(val, encoding)
    var len = bytes.length
    if (len === 0) {
      throw new TypeError('The value "' + val +
        '" is invalid for argument "value"')
    }
    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 takes equal signs as end of the Base64 encoding
  str = str.split('=')[0]
  // Node strips out invalid characters like \n and \t from the string, base64-js does not
  str = str.trim().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 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
}

// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
// the `instanceof` check but they should be treated as of that type.
// See: https://github.com/feross/buffer/issues/166
function isInstance (obj, type) {
  return obj instanceof type ||
    (obj != null && obj.constructor != null && obj.constructor.name != null &&
      obj.constructor.name === type.name)
}
function numberIsNaN (obj) {
  // For IE11 support
  return obj !== obj // eslint-disable-line no-self-compare
}

// Create lookup table for `toString('hex')`
// See: https://github.com/feross/buffer/issues/219
var hexSliceLookupTable = (function () {
  var alphabet = '0123456789abcdef'
  var table = new Array(256)
  for (var i = 0; i < 16; ++i) {
    var i16 = i * 16
    for (var j = 0; j < 16; ++j) {
      table[i16 + j] = alphabet[i] + alphabet[j]
    }
  }
  return table
})()


/***/ }),

/***/ "./node_modules/buffer/node_modules/base64-js/index.js":
/*!*************************************************************!*\
  !*** ./node_modules/buffer/node_modules/base64-js/index.js ***!
  \*************************************************************/
/***/ (function(__unused_webpack_module, exports) {

"use strict";


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

  var i
  for (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/buffer/node_modules/ieee754/index.js":
/*!***********************************************************!*\
  !*** ./node_modules/buffer/node_modules/ieee754/index.js ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, exports) {

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
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/codem-isoboxer/dist/iso_boxer.js":
/*!*******************************************************!*\
  !*** ./node_modules/codem-isoboxer/dist/iso_boxer.js ***!
  \*******************************************************/
/***/ (function(__unused_webpack_module, exports) {

/*! codem-isoboxer v0.3.9 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) {
        // 1-byte character (7 bits)
      } 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);
};

if (true) {
  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:
    // Size zero indicates last box in the file. Consume remaining buffer.
    this._raw = new DataView(this._raw.buffer, this._offset);
    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/2/3/4, hev1, hvc1, encv
ISOBox.prototype._boxProcessors['avc1'] =
ISOBox.prototype._boxProcessors['avc2'] =
ISOBox.prototype._boxProcessors['avc3'] =
ISOBox.prototype._boxProcessors['avc4'] =
ISOBox.prototype._boxProcessors['hvc1'] =
ISOBox.prototype._boxProcessors['hev1'] =
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);
  // Codec-specific fields
  this._procField('config', 'data', -1);
};

// ISO/IEC 14496-12:2012 - 8.6.1.3 Composition Time To Sample Box
ISOBox.prototype._boxProcessors['ctts'] = function() {
  this._procFullBox();
  this._procField('entry_count', 'uint', 32);
  this._procEntries('entries', this.entry_count, function(entry) {
    this._procEntryField(entry, 'sample_count', 'uint', 32);
    this._procEntryField(entry, 'sample_offset', (this.version === 1) ? 'int' : 'uint', 32);
  });
};

// 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 14496-12:2012 - 8.16.5 Producer Reference Time
ISOBox.prototype._boxProcessors['prft'] = function() {
  this._procFullBox();
  this._procField('reference_track_ID', 'uint', 32);
  this._procField('ntp_timestamp_sec', 'uint', 32);
  this._procField('ntp_timestamp_frac', 'uint', 32);
  this._procField('media_time', 'uint', (this.version == 1) ? 64 : 32);
};

//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-30:2014 - WebVTT Cue Settings Box.
ISOBox.prototype._boxProcessors['sttg'] = function() {
    this._procField('settings', 'utf8');
};

// ISO/IEC 14496-12:2012 - 8.6.1.2 Decoding Time To Sample Box
ISOBox.prototype._boxProcessors['stts'] = function() {
  this._procFullBox();
  this._procField('entry_count', 'uint', 32);
  this._procEntries('entries', this.entry_count, function(entry) {
    this._procEntryField(entry, 'sample_count', 'uint', 32);
    this._procEntryField(entry, 'sample_delta', 'uint', 32);
  });
};

// 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/es6-promise/auto.js":
/*!******************************************!*\
  !*** ./node_modules/es6-promise/auto.js ***!
  \******************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// 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 ***!
  \******************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

/*!
 * @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) {
	 true ? module.exports = factory() :
	0;
}(this, (function () { 'use strict';

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) {
    // noop
  } 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 __webpack_require__.g !== 'undefined') {
    local = __webpack_require__.g;
  } 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;

})));



//# sourceMappingURL=es6-promise.map


/***/ }),

/***/ "./node_modules/events/events.js":
/*!***************************************!*\
  !*** ./node_modules/events/events.js ***!
  \***************************************/
/***/ (function(module) {

"use strict";
// 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/fast-deep-equal/index.js":
/*!***********************************************!*\
  !*** ./node_modules/fast-deep-equal/index.js ***!
  \***********************************************/
/***/ (function(module) {

"use strict";


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/imsc/src/main/js/doc.js":
/*!**********************************************!*\
  !*** ./node_modules/imsc/src/main/js/doc.js ***!
  \**********************************************/
/***/ (function(__unused_webpack_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.
 */

/**
 * @module imscDoc
 */

;
(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 Region) {

                /* merge referenced styles */

                if (doc.head !== null && doc.head.styling !== null) {
                    mergeReferencedStyles(doc.head.styling, estack[0].styleRefs, estack[0].styleAttrs, errorHandler);
                }

                delete estack[0].styleRefs;

            } else if (estack[0] instanceof Styling) {

                /* flatten chained referential styling */

                for (var sid in estack[0].styles) {

                    if (! estack[0].styles.hasOwnProperty(sid)) continue;

                    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) {

                /* ignoring text outside of elements */

            } else if (estack[0] instanceof Span || estack[0] instanceof P) {

                /* ignore children text nodes in ruby container spans */

                if (estack[0] instanceof Span) {

                    var ruby = estack[0].styleAttrs[imscStyles.byName.ruby.qname];

                    if (ruby === 'container' || ruby === 'textContainer' || ruby === 'baseContainer') {

                        return;

                    }

                }

                /* create an anonymous span */

                var s = new AnonymousSpan();

                s.initFromText(doc, estack[0], str, xmllangstack[0], 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, xmllangstack[0], 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 + ")");
                    }

                    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 + ")");
                    }

                    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 === 'initial') {

                    var ini;

                    if (estack[0] instanceof Styling) {

                        ini = new Initial();

                        ini.initFromNode(node, errorHandler);
                        
                        for (var qn in ini.styleAttrs) {

                            if (! ini.styleAttrs.hasOwnProperty(qn)) continue;
                            
                            doc.head.styling.initials[qn] = ini.styleAttrs[qn];
                            
                        }
                        
                        estack.unshift(ini);

                    } else {

                        reportFatal(errorHandler, "Parent of <initial> element is not <styling> 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 + ")");

                    }

                    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, xmllangstack[0], 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, xmllangstack[0], 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, xmllangstack[0], errorHandler);
                    
                    /* transform smpte:backgroundImage to TTML2 image element */
                    
                    var bi = d.styleAttrs[imscStyles.byName.backgroundImage.qname];
                    
                    if (bi) {
                        d.contents.push(new Image(bi));
                        delete d.styleAttrs[imscStyles.byName.backgroundImage.qname];                  
                    }

                    estack[0].contents.push(d);

                    estack.unshift(d);

                } else if (node.local === 'image') {

                    if (!(estack[0] instanceof Div)) {

                        reportFatal(errorHandler, "Parent of <image> element is not <div> at " + this.line + "," + this.column + ")");

                    }

                    var img = new Image();
                    
                    img.initFromNode(doc, estack[0], node, xmllangstack[0], errorHandler);
                    
                    estack[0].contents.push(img);

                    estack.unshift(img);

                } 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, xmllangstack[0], 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, xmllangstack[0], 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, xmllangstack[0], 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 styles

        delete doc.head.styling.styles;
       
        // create default region if no regions specified

        var hasRegions = false;

        /* AFAIK the only way to determine whether an object has members */

        for (var i in doc.head.layout.regions) {

            if (doc.head.layout.regions.hasOwnProperty(i)) {
                hasRegions = true;
                break;
            }

        }

        if (!hasRegions) {

            /* create default region */

            var dr = Region.prototype.createDefaultRegion(doc.lang);

            doc.head.layout.regions[dr.id] = dr;

        }

        /* resolve desired timing for regions */

        for (var region_i in doc.head.layout.regions) {

            if (! doc.head.layout.regions.hasOwnProperty(region_i)) continue;

            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);
        }

        /* remove undefined spans in ruby containers */

        if (doc.body) {
            cleanRubyContainers(doc.body);
        }

        return doc;
    };

    function cleanRubyContainers(element) {
        
        if (! ('contents' in element)) return;

        var rubyval = 'styleAttrs' in element ? element.styleAttrs[imscStyles.byName.ruby.qname] : null;

        var isrubycontainer = (element.kind === 'span' && (rubyval === "container" || rubyval === "textContainer" || rubyval === "baseContainer"));

        for (var i = element.contents.length - 1; i >= 0; i--) {

            if (isrubycontainer && !('styleAttrs' in element.contents[i] && imscStyles.byName.ruby.qname in element.contents[i].styleAttrs)) {

                /* prune undefined <span> in ruby containers */

                delete element.contents[i];

            } else {

                cleanRubyContainers(element.contents[i]);

            }

        }

    }

    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;

        if ("sets" in element) {

            for (var set_i = 0; set_i < element.sets.length; set_i++) {

                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 if ("contents" in element) {
 
            for (var content_i = 0; content_i < element.contents.length; content_i++) {

                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 = new Head();
        this.body = null;
    }

    TT.prototype.initFromNode = function (node, xmllang, errorHandler) {

        /* compute cell resolution */

        var cr = extractCellResolution(node, errorHandler);
        
        this.cellLength = {
                'h': new imscUtils.ComputedLength(0, 1/cr.h),
                'w': new imscUtils.ComputedLength(1/cr.w, 0)
            };

        /* 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) {

            this.pxLength = {
                'h': null,
                'w': null
            };

        } else {

            if (e.h.unit !== "px" || e.w.unit !== "px") {
                reportFatal(errorHandler, "Extent on TT must be in px or absent");
            }

            this.pxLength = {
                'h': new imscUtils.ComputedLength(0, 1 / e.h.value),
                'w': new imscUtils.ComputedLength(1 / e.w.value, 0)
            };
        }
        
        /** set root container dimensions to (1, 1) arbitrarily
          * the root container is mapped to actual dimensions at rendering
        **/
        
        this.dimensions = {
                'h': new imscUtils.ComputedLength(0, 1),
                'w': new imscUtils.ComputedLength(1, 0)

        };

        /* xml:lang */

        this.lang = xmllang;

    };

    /* 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 = new Styling();
        this.layout = new Layout();
    }

    /*
     * Represents a TTML Styling element
     */

    function Styling() {
        this.styles = {};
        this.initials = {};
    }

    /*
     * 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 initial element
     */

    function Initial() {
        this.styleAttrs = null;
    }

    Initial.prototype.initFromNode = function (node, errorHandler) {
        
        this.styleAttrs = {};
        
        for (var i in node.attributes) {

            if (node.attributes[i].uri === imscNames.ns_itts ||
                node.attributes[i].uri === imscNames.ns_ebutts ||
                node.attributes[i].uri === imscNames.ns_tts) {
                
                var qname = node.attributes[i].uri + " " + node.attributes[i].local;
                
                this.styleAttrs[qname] = node.attributes[i].value;

            }
        }
        
    };

    /*
     * Represents a TTML Layout element
     * 
     */

    function Layout() {
        this.regions = {};
    }
    
    /*
     * Represents a TTML image element
     */

    function Image(src, type) {
        ContentElement.call(this, 'image');
        this.src = src;
        this.type = type;
    }

    Image.prototype.initFromNode = function (doc, parent, node, xmllang, errorHandler) {
        this.src = 'src' in node.attributes ? node.attributes.src.value : null;
        
        if (! this.src) {
            reportError(errorHandler, "Invalid image@src attribute");
        }
        
        this.type = 'type' in node.attributes ? node.attributes.type.value : null;
        
        if (! this.type) {
            reportError(errorHandler, "Invalid image@type attribute");
        }
        
        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);

        this.lang = xmllang;
    };

    /*
     * 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, xmllang, 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);

        this.lang = xmllang;
    };

    /*
     * Represents a TTML div element
     */

    function Div() {
        ContentElement.call(this, 'div');
    }

    Div.prototype.initFromNode = function (doc, parent, node, xmllang, 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.lang = xmllang;
    };

    /*
     * Represents a TTML p element
     */

    function P() {
        ContentElement.call(this, 'p');
    }

    P.prototype.initFromNode = function (doc, parent, node, xmllang, 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.lang = xmllang;
    };

    /*
     * Represents a TTML span element
     */

    function Span() {
        ContentElement.call(this, 'span');
    }

    Span.prototype.initFromNode = function (doc, parent, node, xmllang, 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;
        this.lang = xmllang;
    };

    /*
     * Represents a TTML anonymous span element
     */

    function AnonymousSpan() {
        ContentElement.call(this, 'span');
    }

    AnonymousSpan.prototype.initFromText = function (doc, parent, text, xmllang, xmlspace, errorHandler) {
        TimedElement.prototype.initFromNode.call(this, doc, parent, null, errorHandler);

        this.text = text;
        this.space = xmlspace;
        this.lang = xmllang;
    };

    /*
     * Represents a TTML br element
     */

    function Br() {
        ContentElement.call(this, 'br');
    }

    Br.prototype.initFromNode = function (doc, parent, node, xmllang, errorHandler) {
        LayoutElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);
        TimedElement.prototype.initFromNode.call(this, doc, parent, node, errorHandler);

        this.lang = xmllang;
    };

    /*
     * Represents a TTML Region element
     * 
     */

    function Region() {
    }

    Region.prototype.createDefaultRegion = function (xmllang) {
        var r = new Region();

        IdentifiedElement.call(r, '');
        StyledElement.call(r, {});
        AnimatedElement.call(r, []);
        TimedElement.call(r, 0, Number.POSITIVE_INFINITY, null);

        this.lang = xmllang;

        return r;
    };

    Region.prototype.initFromNode = function (doc, node, xmllang, errorHandler) {
        IdentifiedElement.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);

        /* add specified styles */

        this.styleAttrs = elementGetStyles(node, errorHandler);

        /* remember referential styles for merging after nested styling is processed*/

        this.styleRefs = elementGetStyleRefs(node);

        /* xml:lang */

        this.lang = xmllang;
    };

    /*
     * 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 (! styles.hasOwnProperty(qname)) continue;

            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");

        if (ar === null) {
            
            ar = findAttribute(node, imscNames.ns_ttp, "displayAspectRatio");
            
        }

        var rslt = null;

        if (ar !== null) {

            var ASPECT_RATIO_RE = /(\d+)\s+(\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 (! from_styles.hasOwnProperty(sname)) continue;

            if (sname in into_styles)
                continue;

            into_styles[sname] = from_styles[sname];

        }

    }

    /* TODO: validate style format at parsing */


    /*
     * ERROR HANDLING UTILITY FUNCTIONS
     * 
     */

    function reportInfo(errorHandler, msg) {

        if (errorHandler && errorHandler.info && errorHandler.info(msg))
            throw msg;

    }

    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};
    }


})( false ? 0 : 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 ***!
  \***********************************************/
/***/ (function(__unused_webpack_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.
 */

/**
 * @module imscHTML
 */

;
(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) */
            ruby: null, /* is ruby present in a <p> */
            textEmphasis: null, /* is textEmphasis present in a <p> */
            rubyReserve: null /* is rubyReserve applicable to a <p> */
        };

        element.appendChild(rootcontainer);

        if ("contents" in isd) {

            for (var i = 0; i < isd.contents.length; i++) {

                processElement(context, rootcontainer, isd.contents[i], isd);

            }

        }

        return context.currentISDState;

    };

    function processElement(context, dom_parent, isd_element, isd_parent) {

        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 === 'image') {

            e = document.createElement("img");

            if (context.imgResolver !== null && isd_element.src !== null) {

                var uri = context.imgResolver(isd_element.src, e);

                if (uri)
                    e.src = uri;

                e.height = context.regionH;
                e.width = context.regionW;

            }

        } else if (isd_element.kind === 'p') {

            e = document.createElement("p");

        } else if (isd_element.kind === 'span') {

            if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "container") {

                e = document.createElement("ruby");

                context.ruby = true;

            } else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "base") {

                e = document.createElement("rb");

            } else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "text") {

                e = document.createElement("rt");


            } else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "baseContainer") {

                e = document.createElement("rbc");


            } else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "textContainer") {

                e = document.createElement("rtc");


            } else if (isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "delimiter") {

                /* ignore rp */

                return;

            } else {

                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;

        }

        /* set language */

        if (isd_element.lang) {

            if (isd_element.kind === 'region' || isd_element.lang !== isd_parent.lang) {
                e.lang = isd_element.lang;
            }

        }

        /* add to parent */

        dom_parent.appendChild(e);

        /* override UA default margin */
        /* TODO: should apply to <p> only */

        e.style.margin = "0";

        /* determine ipd and bpd */

        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";

            }
 
        } else if (isd_element.kind === "p" && context.bpd === "tb") {

            var pdir = isd_element.styleAttrs[imscStyles.byName.direction.qname];

            context.ipd = pdir === "ltr" ? "lr" : "rl"; 
 
        }

        /* tranform TTML styles to CSS styles */

        for (var i = 0; i < STYLING_MAP_DEFS.length; i++) {

            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;

        /* do we have linePadding ? */

        var lp = isd_element.styleAttrs[imscStyles.byName.linePadding.qname];

        if (lp && (! lp.isZero())) {

            var plength = lp.toUsedLength(context.w, context.h);


            if (plength > 0) {
                
                /* apply padding to the <p> so that line padding does not cause line wraps */

                var padmeasure = Math.ceil(plength) + "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;

        }

        /* do we have rubyReserve? */

        var rr = isd_element.styleAttrs[imscStyles.byName.rubyReserve.qname];

        if (rr && rr[0] !== "none") {
            context.rubyReserve = rr;
        }


        /* 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) {

            var te = isd_element.styleAttrs[imscStyles.byName.textEmphasis.qname];

            if (te && te.style !== "none") {

                context.textEmphasis = true;

            }

            if (imscStyles.byName.textCombine.qname in isd_element.styleAttrs &&
                    isd_element.styleAttrs[imscStyles.byName.textCombine.qname] === "all") {

                /* ignore tate-chu-yoku since line break cannot happen within */
                e.textContent = isd_element.text;

                if (te) {

                    applyTextEmphasis(context, e, isd_element, te);

                };

            } else {

                // 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 - 1) {

                        /* wrap the character(s) in a span unless it is a high surrogate */

                        var span = document.createElement("span");

                        span.textContent = cbuf;

                        /* apply textEmphasis */
                        
                        if (te) {

                            applyTextEmphasis(context, span, isd_element, te);

                        };
    
                        e.appendChild(span);

                        cbuf = '';

                        //For the sake of merging these back together, record what isd element generated it.
                        span._isd_element = isd_element;
                    }

                }

            }
        }

        /* process the children of the ISD element */

        if ("contents" in isd_element) {

            for (var k = 0; k < isd_element.contents.length; k++) {

                processElement(context, proc_e, isd_element.contents[k], isd_element);

            }

        }

        /* list of lines */

        var linelist = [];


        /* paragraph processing */
        /* TODO: linePadding only supported for horizontal scripts */

        if (isd_element.kind === "p") {

            constructLineList(context, proc_e, linelist, null);

            /* apply rubyReserve */

            if (context.rubyReserve) {

                applyRubyReserve(linelist, context);

                context.rubyReserve = null;

            }

            /* apply tts:rubyPosition="outside" */

            if (context.ruby || context.rubyReserve) {

                applyRubyPosition(linelist, context);

                context.ruby = null;

            }

            /* apply text emphasis "outside" position */

            if (context.textEmphasis) {

                applyTextEmphasisOutside(linelist, context);

                context.textEmphasis = null;

            }

            /* insert line breaks for multirowalign */

            if (context.mra) {

                applyMultiRowAlign(linelist);

                context.mra = null;

            }

            /* add linepadding */

            if (context.lp) {

                applyLinePadding(linelist, context.lp.toUsedLength(context.w, context.h), context);

                context.lp = null;

            }

            mergeSpans(linelist); // The earlier we can do this the less processing there will be.

            /* fill line gaps linepadding */

            if (context.flg) {

                var par_edges = rect2edges(proc_e.getBoundingClientRect(), context);

                applyFillLineGap(linelist, par_edges.before, par_edges.after, context, proc_e);

                context.flg = null;

            }

        }


        /* region processing */

        if (isd_element.kind === "region") {

            /* perform roll up if needed */
            if ((context.bpd === "tb") &&
                    context.enableRollUp &&
                    isd_element.contents.length > 0 &&
                    isd_element.styleAttrs[imscStyles.byName.displayAlign.qname] === 'after') {

                /* build line list */
                constructLineList(context, proc_e, linelist, null);

                /* 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)";

                }

            }
        }
    }

    function mergeSpans(lineList) {

        for (var i = 0; i < lineList.length; i++) {

            var line = lineList[i];

            for (var j = 1; j < line.elements.length;) {

                var previous = line.elements[j - 1];
                var span = line.elements[j];

                if (spanMerge(previous.node, span.node)) {

                    //removed from DOM by spanMerge(), remove from the list too.
                    line.elements.splice(j, 1);
                    continue;

                } else {

                    j++;

                }

            }
        }

        // Copy backgroundColor to each span so that fillLineGap will apply padding to elements with the right background
        var thisNode, ancestorBackgroundColor;
        var clearTheseBackgrounds = [];

        for (var l = 0; l < lineList.length; l++) {

            for (var el = 0; el < lineList[l].elements.length; el++) {

                thisNode = lineList[l].elements[el].node;
                ancestorBackgroundColor = getSpanAncestorColor(thisNode, clearTheseBackgrounds, false);

                if (ancestorBackgroundColor) {

                    thisNode.style.backgroundColor = ancestorBackgroundColor;

                }
            }
        }

        for (var bi = 0; bi < clearTheseBackgrounds.length; bi++) {

            clearTheseBackgrounds[bi].style.backgroundColor = "";

        }
    }

    function getSpanAncestorColor(element, ancestorList, isAncestor) {

        if (element.style.backgroundColor) {

            if (isAncestor && !ancestorList.includes(element)) {

                ancestorList.push(element);

            }
            return element.style.backgroundColor;

        } else {

            if (element.parentElement.nodeName === "SPAN") {

                return getSpanAncestorColor(element.parentElement, ancestorList, true);

            }

        }

        return undefined;
    }

    function spanMerge(first, second) {

        if (first.tagName === "SPAN" &&
            second.tagName === "SPAN" &&
            first._isd_element === second._isd_element) {

                first.textContent += second.textContent;

                for (var i = 0; i < second.style.length; i++) {

                    var styleName = second.style[i];
                    if (styleName.indexOf("border") >= 0 || 
                        styleName.indexOf("padding") >= 0 ||
                        styleName.indexOf("margin") >= 0) {

                        first.style[styleName] = second.style[styleName];

                    }
                }

                second.parentElement.removeChild(second);

                return true;
            }

        return false;
    }

    function applyLinePadding(lineList, lp, context) {

        if (lineList === null) return;

        for (var i = 0; i < lineList.length; i++) {

            var l = lineList[i].elements.length;

            var pospadpxlen = Math.ceil(lp) + "px";

            var negpadpxlen = "-" + Math.ceil(lp) + "px";

            if (l !== 0) {

                var se = lineList[i].elements[lineList[i].start_elem];

                var ee = lineList[i].elements[lineList[i].end_elem];

                if (se === ee) {

                    // Check to see if there's any background at all
                    elementBoundingRect = se.node.getBoundingClientRect();
                    
                    if (elementBoundingRect.width == 0 || elementBoundingRect.height == 0) {

                        // There's no background on this line, move on.
                        continue;

                    }

                }

                // Start element
                if (context.ipd === "lr") {

                    se.node.style.marginLeft = negpadpxlen;
                    se.node.style.paddingLeft = pospadpxlen;

                } else if (context.ipd === "rl") {

                    se.node.style.paddingRight = pospadpxlen;
                    se.node.style.marginRight = negpadpxlen;

                } else if (context.ipd === "tb") {

                    se.node.style.paddingTop = pospadpxlen;
                    se.node.style.marginTop = negpadpxlen;

                }

                // End element
                if (context.ipd === "lr") {

                    ee.node.style.marginRight = negpadpxlen;
                    ee.node.style.paddingRight = pospadpxlen;

                } else if (context.ipd === "rl") {

                    ee.node.style.paddingLeft = pospadpxlen;
                    ee.node.style.marginLeft = negpadpxlen;

                } else if (context.ipd === "tb") {

                    ee.node.style.paddingBottom = 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 applyTextEmphasisOutside(lineList, context) {

        /* supports "outside" only */

        for (var i = 0; i < lineList.length; i++) {

            for (var j = 0; j < lineList[i].te.length; j++) {

                /* skip if position already set */

                if (lineList[i].te[j].style[TEXTEMPHASISPOSITION_PROP] &&
                    lineList[i].te[j].style[TEXTEMPHASISPOSITION_PROP] !== "none")
                    continue;

                var pos;

                if (context.bpd === "tb") {

                    pos = (i === 0) ? "left over" : "left under";


                } else {

                    if (context.bpd === "rl") {

                        pos = (i === 0) ? "right under" : "left under";

                    } else {

                        pos = (i === 0) ? "left under" : "right under";

                    }

                }

                lineList[i].te[j].style[TEXTEMPHASISPOSITION_PROP] = pos;

            }

        }

    }

    function applyRubyPosition(lineList, context) {

        for (var i = 0; i < lineList.length; i++) {

            for (var j = 0; j < lineList[i].rbc.length; j++) {

                /* skip if ruby-position already set */

                if (lineList[i].rbc[j].style[RUBYPOSITION_PROP])
                    continue;

                var pos;

                if (RUBYPOSITION_ISWK) {

                    /* WebKit exception */

                    pos = (i === 0) ? "before" : "after";

                } else if (context.bpd === "tb") {

                    pos = (i === 0) ? "over" : "under";


                } else {

                    if (context.bpd === "rl") {

                        pos = (i === 0) ? "over" : "under";

                    } else {

                        pos = (i === 0) ? "under" : "over";

                    }

                }

                lineList[i].rbc[j].style[RUBYPOSITION_PROP] = pos;

            }

        }

    }

    function applyRubyReserve(lineList, context) {

        for (var i = 0; i < lineList.length; i++) {

            var ruby = document.createElement("ruby");

            var rb = document.createElement("rb");
            rb.textContent = "\u200B";

            ruby.appendChild(rb);

            var rt1;
            var rt2;

            var fs = context.rubyReserve[1].toUsedLength(context.w, context.h) + "px";

            if (context.rubyReserve[0] === "both" || (context.rubyReserve[0] === "outside" && lineList.length == 1)) {

                rt1 = document.createElement("rtc");
                rt1.style[RUBYPOSITION_PROP] = RUBYPOSITION_ISWK ? "after" : "under";
                rt1.textContent = "\u200B";
                rt1.style.fontSize = fs;

                rt2 = document.createElement("rtc");
                rt2.style[RUBYPOSITION_PROP] = RUBYPOSITION_ISWK ? "before" : "over";
                rt2.textContent = "\u200B";
                rt2.style.fontSize = fs;

                ruby.appendChild(rt1);
                ruby.appendChild(rt2);

            } else {

                rt1 = document.createElement("rtc");
                rt1.textContent = "\u200B";
                rt1.style.fontSize = fs;

                var pos;

                if (context.rubyReserve[0] === "after" || (context.rubyReserve[0] === "outside" && i > 0)) {

                    pos = RUBYPOSITION_ISWK ? "after" : ((context.bpd === "tb" || context.bpd === "rl") ? "under" : "over");

                } else {

                    pos = RUBYPOSITION_ISWK ? "before" : ((context.bpd === "tb" || context.bpd === "rl") ? "over" : "under");

                }

                rt1.style[RUBYPOSITION_PROP] = pos;

                ruby.appendChild(rt1);

            }

            /* add in front of the first ruby element of the line, if it exists */

            var sib = null;

            for (var j = 0; j < lineList[i].rbc.length; j++) {

                if (lineList[i].rbc[j].localName === 'ruby') {

                    sib = lineList[i].rbc[j];

                    /* copy specified style properties from the sibling ruby container */
                    
                    for (var k = 0; k < sib.style.length; k++) {

                        ruby.style.setProperty(sib.style.item(k), sib.style.getPropertyValue(sib.style.item(k)));

                    }

                    break;
                }

            }

            /* otherwise add before first span */

            sib = sib || lineList[i].elements[0].node;

            sib.parentElement.insertBefore(ruby, sib);

        }

    }

    function applyFillLineGap(lineList, par_before, par_after, context, element) {

        /* 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 = Math.round(par_before);

            } else if (i === lineList.length) {

                frontier = Math.round(par_after);

            } else {

                frontier = Math.round((lineList[i - 1].after + lineList[i].before) / 2);

            }

            var padding;
            var l,thisNode;

            /* before line */
            if (i > 0) {

                if (lineList[i-1]) {

                    for (l = 0; l < lineList[i - 1].elements.length; l++) {

                        thisNode=lineList[i - 1].elements[l];
                        padding = s*(frontier-thisNode.after) + "px";

                        if (context.bpd === "lr") {

                            thisNode.node.style.paddingRight = padding;

                        } else if (context.bpd === "rl") {

                            thisNode.node.style.paddingLeft = padding;

                        } else if (context.bpd === "tb") {

                            thisNode.node.style.paddingBottom = padding;

                        }

                    }

                }

            }

            /* after line */
            if (i < lineList.length) {

                for (l = 0; l < lineList[i].elements.length; l++) {

                    thisNode = lineList[i].elements[l];
                    padding = s * (thisNode.before - frontier) + "px";

                    if (context.bpd === "lr") {

                        thisNode.node.style.paddingLeft = padding;

                    } else if (context.bpd === "rl") {

                        thisNode.node.style.paddingRight = padding;

                    } else if (context.bpd === "tb") {

                        thisNode.node.style.paddingTop = padding;

                    }
                }

            }

        }

    }

    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) {

        if (element.localName === "rt" || element.localName === "rtc") {

            /* skip ruby annotations */

            return;

        }

        var curbgcolor = element.style.backgroundColor || bgcolor;

        if (element.childElementCount === 0) {

            if (element.localName === 'span' || element.localName === 'rb') {

                var r = element.getBoundingClientRect();

                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: [],
                        rbc: [],
                        te: [],
                        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);

                    if (child.localName === 'ruby' || child.localName === 'rtc') {

                        /* remember non-empty ruby and rtc elements so that tts:rubyPosition can be applied */

                        if (llist.length > 0) {

                            llist[llist.length - 1].rbc.push(child);

                        }

                    } else if (child.localName === 'span' &&
                            child.style[TEXTEMPHASISSTYLE_PROP] &&
                            child.style[TEXTEMPHASISSTYLE_PROP] !== "none") {

                        /* remember non-empty span elements with textEmphasis */

                        if (llist.length > 0) {

                            llist[llist.length - 1].te.push(child);

                        }

                    }
                    

                }

                child = child.nextSibling;
            }
        }

    }

    function isSameLine(before1, after1, before2, after2) {

        return ((after1 < after2) && (before1 > before2)) || ((after2 <= after1) && (before2 >= before1));

    }

    function applyTextEmphasis(context, dom_element, isd_element, attr) {

        /* ignore color (not used in IMSC 1.1) */

        if (attr.style === "none") {

            /* text-emphasis is not inherited and the default is none, so nothing to do */
            
            return;
        
        } else if (attr.style === "auto") {

            dom_element.style[TEXTEMPHASISSTYLE_PROP] = "filled";
        
        } else {

            dom_element.style[TEXTEMPHASISSTYLE_PROP] =  attr.style + " " + attr.symbol;
        }

        /* ignore "outside" position (set in postprocessing) */

        if (attr.position === "before" || attr.position === "after") {

            var pos;

            if (context.bpd === "tb") {

                pos = (attr.position === "before") ? "left over" : "left under";


            } else {

                if (context.bpd === "rl") {

                    pos = (attr.position === "before") ? "right under" : "left under";

                } else {

                    pos = (attr.position === "before") ? "left under" : "right under";

                }

            }

            dom_element.style[TEXTEMPHASISPOSITION_PROP] = pos;
        }
    }

    function HTMLStylingMapDefinition(qName, mapFunc) {
        this.qname = qName;
        this.map = mapFunc;
    }

    var STYLING_MAP_DEFS = [

        new HTMLStylingMapDefinition(
                "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 HTMLStylingMapDefinition(
                "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 HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling direction",
                function (context, dom_element, isd_element, attr) {

                    dom_element.style.direction = attr;

                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling display",
                function (context, dom_element, isd_element, attr) {}
        ),
        new HTMLStylingMapDefinition(
                "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 HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling extent",
                function (context, dom_element, isd_element, attr) {
                    /* TODO: this is super ugly */

                    context.regionH = attr.h.toUsedLength(context.w, context.h);
                    context.regionW = attr.w.toUsedLength(context.w, context.h);

                    /* 
                     * 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) {

                        /* error */

                    } else {

                        hdelta = p[0].toUsedLength(context.w, context.h) + p[2].toUsedLength(context.w, context.h);
                        wdelta = p[1].toUsedLength(context.w, context.h) + p[3].toUsedLength(context.w, context.h);

                    }

                    dom_element.style.height = (context.regionH - hdelta) + "px";
                    dom_element.style.width = (context.regionW - wdelta) + "px";

                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling fontFamily",
                function (context, dom_element, isd_element, attr) {

                    var rslt = [];

                    /* per IMSC1 */

                    for (var i = 0; i < attr.length; i++) {

                        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]);

                        }

                    }

                    // prune later duplicates we may have inserted 
                    if (rslt.length > 0) {

                        var unique=[rslt[0]];

                        for (var fi = 1; fi < rslt.length; fi++) {

                            if (unique.indexOf(rslt[fi]) == -1) {

                                unique.push(rslt[fi]);

                            }
                        }

                        rslt = unique;
                    }

                    dom_element.style.fontFamily = rslt.join(",");
                }
        ),

        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling shear",
                function (context, dom_element, isd_element, attr) {

                    /* return immediately if tts:shear is 0% since CSS transforms are not inherited*/

                    if (attr === 0)
                        return;

                    var angle = attr * -0.9;

                    /* context.bpd is needed since writing mode is not inherited and sets the inline progression */

                    if (context.bpd === "tb") {

                        dom_element.style.transform = "skewX(" + angle + "deg)";

                    } else {

                        dom_element.style.transform = "skewY(" + angle + "deg)";

                    }

                }
        ),

        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling fontSize",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.fontSize = attr.toUsedLength(context.w, context.h) + "px";
                }
        ),

        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling fontStyle",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.fontStyle = attr;
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling fontWeight",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.fontWeight = attr;
                }
        ),
        new HTMLStylingMapDefinition(
                "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.toUsedLength(context.w, context.h) + "px";
                    }
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling opacity",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.opacity = attr;
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling origin",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.top = attr.h.toUsedLength(context.w, context.h) + "px";
                    dom_element.style.left = attr.w.toUsedLength(context.w, context.h) + "px";
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling overflow",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.overflow = attr;
                }
        ),
        new HTMLStylingMapDefinition(
                "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].toUsedLength(context.w, context.h) + "px";
                    rslt[1] = attr[3].toUsedLength(context.w, context.h) + "px";
                    rslt[2] = attr[2].toUsedLength(context.w, context.h) + "px";
                    rslt[3] = attr[1].toUsedLength(context.w, context.h) + "px";

                    dom_element.style.padding = rslt.join(" ");
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling position",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.top = attr.h.toUsedLength(context.w, context.h) + "px";
                    dom_element.style.left = attr.w.toUsedLength(context.w, context.h) + "px";
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling rubyAlign",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.rubyAlign = attr === "spaceAround" ? "space-around" : "center";
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling rubyPosition",
                function (context, dom_element, isd_element, attr) {

                    /* skip if "outside", which is handled by applyRubyPosition() */

                    if (attr === "before" || attr === "after") {

                        var pos;

                        if (RUBYPOSITION_ISWK) {

                            /* WebKit exception */
        
                            pos = attr;
        
                        } else if (context.bpd === "tb") {

                            pos = (attr === "before") ? "over" : "under";


                        } else {

                            if (context.bpd === "rl") {

                                pos = (attr === "before") ? "over" : "under";

                            } else {

                                pos = (attr === "before") ? "under" : "over";

                            }

                        }

                        /* apply position to the parent dom_element, i.e. ruby or rtc */

                        dom_element.parentElement.style[RUBYPOSITION_PROP] = pos;
                    }
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling showBackground",
                null
                ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling textAlign",
                function (context, dom_element, isd_element, attr) {

                    var ta;

                    /* handle UAs that do not understand start or end */

                    if (attr === "start") {

                        ta = (context.ipd === "rl") ? "right" : "left";

                    } else if (attr === "end") {

                        ta = (context.ipd === "rl") ? "left" : "right";

                    } else {

                        ta = attr;

                    }

                    dom_element.style.textAlign = ta;

                }
        ),
        new HTMLStylingMapDefinition(
                "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 HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling textOutline",
                function (context, dom_element, isd_element, attr) {

                    /* defer to tts:textShadow */
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling textShadow",
                function (context, dom_element, isd_element, attr) {

                    var txto = isd_element.styleAttrs[imscStyles.byName.textOutline.qname];

                    if (attr === "none" && txto === "none") {

                        dom_element.style.textShadow = "";

                    } else {

                        var s = [];

                        if (txto !== "none") {

                            /* emulate text outline */

                            var to_color = "rgba(" +
                                                txto.color[0].toString() + "," +
                                                txto.color[1].toString() + "," +
                                                txto.color[2].toString() + "," +
                                                (txto.color[3] / 255).toString() +
                                                ")";

                            s.push(  "1px 1px 1px " + to_color);
                            s.push(  "-1px 1px 1px " + to_color);
                            s.push(  "1px -1px 1px " + to_color);
                            s.push(  "-1px -1px 1px " + to_color);

                        }

                        /* add text shadow */

                        if (attr !== "none") {

                            for (var i = 0; i < attr.length; i++) {


                                s.push(attr[i].x_off.toUsedLength(context.w, context.h) + "px " +
                                        attr[i].y_off.toUsedLength(context.w, context.h) + "px " +
                                        attr[i].b_radius.toUsedLength(context.w, context.h) + "px " +
                                        "rgba(" +
                                        attr[i].color[0].toString() + "," +
                                        attr[i].color[1].toString() + "," +
                                        attr[i].color[2].toString() + "," +
                                        (attr[i].color[3] / 255).toString() +
                                        ")"
                                        );

                            }

                        }

                        dom_element.style.textShadow = s.join(",");

                    }
                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling textCombine",
                function (context, dom_element, isd_element, attr) {

                    dom_element.style.textCombineUpright = attr;

                }
        ),
        new HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling textEmphasis",
                function (context, dom_element, isd_element, attr) {

                    /* applied as part of HTML document construction */

                }
        ),
        new HTMLStylingMapDefinition(
                "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 HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling visibility",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.visibility = attr;
                }
        ),
        new HTMLStylingMapDefinition(
                "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 HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling writingMode",
                function (context, dom_element, isd_element, attr) {

                    var wm;

                    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 HTMLStylingMapDefinition(
                "http://www.w3.org/ns/ttml#styling zIndex",
                function (context, dom_element, isd_element, attr) {
                    dom_element.style.zIndex = attr;
                }
        ),
        new HTMLStylingMapDefinition(
                "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 = 0; i < STYLING_MAP_DEFS.length; i++) {

        STYLMAP_BY_QNAME[STYLING_MAP_DEFS[i].qname] = STYLING_MAP_DEFS[i];
    }

    /* CSS property names */

    var RUBYPOSITION_ISWK = "webkitRubyPosition" in window.getComputedStyle(document.documentElement);

    var RUBYPOSITION_PROP = RUBYPOSITION_ISWK ? "webkitRubyPosition" : "rubyPosition";

    var TEXTEMPHASISSTYLE_PROP = "webkitTextEmphasisStyle" in window.getComputedStyle(document.documentElement) ? "webkitTextEmphasisStyle" : "textEmphasisStyle";

    var TEXTEMPHASISPOSITION_PROP = "webkitTextEmphasisPosition" in window.getComputedStyle(document.documentElement) ? "webkitTextEmphasisPosition" : "textEmphasisPosition";

    /* error utilities */

    function reportError(errorHandler, msg) {

        if (errorHandler && errorHandler.error && errorHandler.error(msg))
            throw msg;

    }

})( false ? 0 : 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,
        typeof imscUtils === 'undefined' ? __webpack_require__(/*! ./utils */ "./node_modules/imsc/src/main/js/utils.js") : imscUtils);


/***/ }),

/***/ "./node_modules/imsc/src/main/js/isd.js":
/*!**********************************************!*\
  !*** ./node_modules/imsc/src/main/js/isd.js ***!
  \**********************************************/
/***/ (function(__unused_webpack_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.
 */

/**
 * @module imscISD
 */


;
(function (imscISD, imscNames, imscStyles, imscUtils) { // 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 = {

            /*rubyfs: []*/ /* font size of the nearest textContainer or container */

        };

        /* Filter body contents - Only process what we need within the offset and discard regions not applicable to the content */
        var body = {};
        var activeRegions = {};

        /* gather any regions that might have showBackground="always" and show a background */
        var initialShowBackground = tt.head.styling.initials[imscStyles.byName.showBackground.qname];
        var initialbackgroundColor = tt.head.styling.initials[imscStyles.byName.backgroundColor.qname];
        for (var layout_child in tt.head.layout.regions)
        {
            if (tt.head.layout.regions.hasOwnProperty(layout_child)) {
                var region = tt.head.layout.regions[layout_child];
                var showBackground = region.styleAttrs[imscStyles.byName.showBackground.qname] || initialShowBackground;
                var backgroundColor = region.styleAttrs[imscStyles.byName.backgroundColor.qname] || initialbackgroundColor;
                activeRegions[region.id] = (
                    (showBackground === 'always' || showBackground === undefined) &&
                    backgroundColor !== undefined &&
                    !(offset < region.begin || offset >= region.end)
                    );
            }
        }

        /* If the body specifies a region, catch it, since no filtered content will */
        /* likely specify the region. */
        if (tt.body && tt.body.regionID) {
            activeRegions[tt.body.regionID] = true;
        }

        function filter(offset, element) {
            function offsetFilter(element) {
                return !(offset < element.begin || offset >= element.end);    
            }    
        
            if (element.contents) {
                var clone = {};
                for (var prop in element) {
                    if (element.hasOwnProperty(prop)) {
                        clone[prop] = element[prop];
                    }
                }
                clone.contents = [];

                element.contents.filter(offsetFilter).forEach(function (el) {
                    var filteredElement = filter(offset, el);
                    if (filteredElement.regionID) {
                        activeRegions[filteredElement.regionID] = true;
                    }
        
                    if (filteredElement !== null) {
                        clone.contents.push(filteredElement);
                    }
                });
                return clone;
            } else {
                return element;
            }
        }

        if (tt.body !== null) {
            body = filter(offset, tt.body);
        } else {
            body = null;
        }

        /* rewritten TTML will always have a default - this covers it. because the region is defaulted to "" */
        if (activeRegions[""] !== undefined) {
            activeRegions[""] = true;
        }

        /* process regions */      
        for (var regionID in activeRegions) {
            if (activeRegions[regionID]) {
                /* post-order traversal of the body tree per [construct intermediate document] */

                var c = isdProcessContentElement(tt, offset, tt.head.layout.regions[regionID], body, null, '', tt.head.layout.regions[regionID], errorHandler, context);

                if (c !== null) {

                    /* add the region to the ISD */

                    isd.contents.push(c.element);
                }
            }
        }

        return isd;
    };

    /* set of styles not applicable to ruby container spans */

    var _rcs_na_styles = [
        imscStyles.byName.color.qname,
        imscStyles.byName.textCombine.qname,
        imscStyles.byName.textDecoration.qname,
        imscStyles.byName.textEmphasis.qname,
        imscStyles.byName.textOutline.qname,
        imscStyles.byName.textShadow.qname
    ];

    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 */

        if ("sets" in elem) {
            for (var i = 0; i < elem.sets.length; i++) {

                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) {

            if (! isd_element.styleAttrs.hasOwnProperty(qname)) continue;

            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 (isd_element.kind === 'region' &&
                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 = 0; j < imscStyles.all.length; j++) {

                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.qname === imscStyles.byName.fontSize.qname &&
                    !(sa.qname in isd_element.styleAttrs) &&
                    isd_element.kind === 'span' &&
                    isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "textContainer") {
                    
                    /* special inheritance rule for ruby text container font size */
                    
                    var ruby_fs = parent.styleAttrs[imscStyles.byName.fontSize.qname];

                    isd_element.styleAttrs[sa.qname] = new imscUtils.ComputedLength(
                        0.5 * ruby_fs.rw,
                        0.5 * ruby_fs.rh);

                } else if (sa.qname === imscStyles.byName.fontSize.qname &&
                    !(sa.qname in isd_element.styleAttrs) &&
                    isd_element.kind === 'span' &&
                    isd_element.styleAttrs[imscStyles.byName.ruby.qname] === "text") {
                    
                    /* special inheritance rule for ruby text font size */
                    
                    var parent_fs = parent.styleAttrs[imscStyles.byName.fontSize.qname];
                    
                    if (parent.styleAttrs[imscStyles.byName.ruby.qname] === "textContainer") {
                        
                        isd_element.styleAttrs[sa.qname] = parent_fs;
                        
                    } else {
                        
                        isd_element.styleAttrs[sa.qname] = new imscUtils.ComputedLength(
                            0.5 * parent_fs.rw,
                            0.5 * parent_fs.rh);
                    }
                    
                } 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 = 0; k < imscStyles.all.length; k++) {
            
            var ivs = imscStyles.all[k];

            /* skip if value is already specified */

            if (ivs.qname in isd_element.styleAttrs) continue;

            /* skip tts:position if tts:origin is specified */

            if (ivs.qname === imscStyles.byName.position.qname &&
                imscStyles.byName.origin.qname in isd_element.styleAttrs)
                continue;

            /* skip tts:origin if tts:position is specified */

            if (ivs.qname === imscStyles.byName.origin.qname &&
                imscStyles.byName.position.qname in isd_element.styleAttrs)
                continue;
            
            /* determine initial value */
            
            var iv = doc.head.styling.initials[ivs.qname] || ivs.initial;

            if (iv === null) {
                /* skip processing if no initial value defined */

                continue;
            }

            /* apply initial value to elements other than region only if non-inherited */

            if (isd_element.kind === 'region' || (ivs.inherit === false && iv !== null)) {

                var piv = ivs.parse(iv);

                if (piv !== null) {

                    isd_element.styleAttrs[ivs.qname] = piv;

                    /* keep track of the style as specified */

                    spec_attr[ivs.qname] = true;

                } else {

                    reportError(errorHandler, "Invalid initial value for '" + ivs.qname + "' on element '" + isd_element.kind);

                }

            }

        }

        /* compute styles (only for non-inherited styles) */
        /* TODO: get rid of spec_attr */

        for (var z = 0; z < imscStyles.all.length; z++) {
            
            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 {
                    /* if the style cannot be computed, replace it by its initial value */

                    isd_element.styleAttrs[cs.qname] = cs.compute(
                        /*doc, parent, element, attr, context*/
                        doc,
                        parent,
                        isd_element,
                        cs.parse(cs.initial),
                        context
                    );

                    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 = null;

        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 = 0; contents !== null && x < contents.length; x++) {

            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);

            }

        }

        /* remove styles that are not applicable */

        for (var qnameb in isd_element.styleAttrs) {
            if (!isd_element.styleAttrs.hasOwnProperty(qnameb)) continue;

            /* true if not applicable */

            var na = false;

            /* special applicability of certain style properties to ruby container spans */
            /* TODO: in the future ruby elements should be translated to elements instead of kept as spans */

            if (isd_element.kind === 'span') {

                var rsp = isd_element.styleAttrs[imscStyles.byName.ruby.qname];

                na = ( rsp === 'container' || rsp === 'textContainer' || rsp === 'baseContainer' ) && 
                    _rcs_na_styles.indexOf(qnameb) !== -1;

                if (! na) {

                    na = rsp !== 'container' &&
                        qnameb === imscStyles.byName.rubyAlign.qname;

                }

                if (! na) {

                    na =  (! (rsp === 'textContainer' || rsp === 'text')) &&
                        qnameb === imscStyles.byName.rubyPosition.qname;

                }

            }

            /* normal applicability */
            
            if (! na) {

                var da = imscStyles.byQName[qnameb];

                if ("applies" in da){

                    na = da.applies.indexOf(isd_element.kind) === -1;

                }

            }


            if (na) {
                delete isd_element.styleAttrs[qnameb];
            }

        }

        /* trim whitespace around explicit line breaks */

        var ruby = isd_element.styleAttrs[imscStyles.byName.ruby.qname];

        if (isd_element.kind === 'p' ||
            (isd_element.kind === 'span' && (ruby === "textContainer" || ruby === "text"))
            ) {

            var elist = [];

            constructSpanList(isd_element, elist);

            collapseLWSP(elist);

            pruneEmptySpans(isd_element);

        }

        /* keep element if:
         * * contains a background image
         * * <br/>
         * * if there are children
         * * if it is an image
         * * 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' ||
            isd_element.kind === 'image' ||
            ('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 collapseLWSP(elist) {

        function isPrevCharLWSP(prev_element) {
            return prev_element.kind === 'br' || /[\r\n\t ]$/.test(prev_element.text);
        }

        function isNextCharLWSP(next_element) {
            return next_element.kind === 'br' || (next_element.space === "preserve" && /^[\r\n]/.test(next_element.text));
        }

        /* collapse spaces and remove leading LWSPs */

        var element;

        for (var i = 0; i < elist.length;) {

            element = elist[i];

            if (element.kind === "br" || element.space === "preserve") {
                i++;
                continue;
            }

            var trimmed_text = element.text.replace(/[\t\r\n ]+/g, ' ');

            if (/^[ ]/.test(trimmed_text)) {

                if (i === 0 || isPrevCharLWSP(elist[i - 1])) {
                    trimmed_text = trimmed_text.substring(1);
                }

            }

            element.text = trimmed_text;

            if (trimmed_text.length === 0) {
                elist.splice(i, 1);
            } else {
                i++;
            }

        }

        /* remove trailing LWSPs */

        for (i = 0; i < elist.length; i++) {

            element = elist[i];

            if (element.kind === "br" || element.space === "preserve") {
                i++;
                continue;
            }

            if (/[ ]$/.test(element.text)) {

                if (i === (elist.length - 1) || isNextCharLWSP(elist[i + 1])) {
                    element.text = element.text.slice(0, -1);
                }

            }

        }

    }

    function constructSpanList(element, elist) {

        if (! ("contents" in element)) {
            return;
        }

        for (var i = 0; i < element.contents.length; i++) {

            var child = element.contents[i];
            var ruby = child.styleAttrs[imscStyles.byName.ruby.qname];

            if (child.kind === 'span' && (ruby === "textContainer" || ruby === "text")) {

                /* skip ruby text and text containers, which are handled on their own */
            
                continue;

            } else if ('contents' in child) {
    
                constructSpanList(child, elist);
    
            } else if ((child.kind === 'span' && child.text.length !== 0) || child.kind === 'br') {

                /* skip empty spans */

                elist.push(child);

            }

        }

    }

    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;
        this.lang = tt.lang;
    }

    function ISDContentElement(ttelem) {

        /* assume the element is a region if it does not have a kind */

        this.kind = ttelem.kind || 'region';

        /* copy lang */

        this.lang = ttelem.lang;

        /* copy id */

        if (ttelem.id) {
            this.id = ttelem.id;
        }

        /* deep copy of style attributes */
        this.styleAttrs = {};

        for (var sname in ttelem.styleAttrs) {

            if (! ttelem.styleAttrs.hasOwnProperty(sname)) continue;

            this.styleAttrs[sname] =
                ttelem.styleAttrs[sname];
        }
        
        /* copy src and type if image */
        
        if ('src' in ttelem) {
            
            this.src = ttelem.src;
            
        }
        
         if ('type' in ttelem) {
            
            this.type = ttelem.type;
            
        }

        /* TODO: clean this! 
         * TODO: ISDElement and document element should be better tied together */

        if ('text' in ttelem) {

            this.text = ttelem.text;

        } else if (this.kind === 'region' || 'contents' in ttelem) {

            this.contents = [];
        }

        if ('space' in ttelem) {

            this.space = ttelem.space;
        }
    }


    /*
     * ERROR HANDLING UTILITY FUNCTIONS
     * 
     */

    function reportInfo(errorHandler, msg) {

        if (errorHandler && errorHandler.info && errorHandler.info(msg))
            throw msg;

    }

    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;

    }


})( false ? 0 : 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,
    typeof imscUtils === 'undefined' ? __webpack_require__(/*! ./utils */ "./node_modules/imsc/src/main/js/utils.js") : imscUtils
    );


/***/ }),

/***/ "./node_modules/imsc/src/main/js/main.js":
/*!***********************************************!*\
  !*** ./node_modules/imsc/src/main/js/main.js ***!
  \***********************************************/
/***/ (function(__unused_webpack_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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, exports) {

/* 
 * 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.
 */

/**
 * @module imscNames
 */

;
(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";
    
})( false ? 0 : exports);






/***/ }),

/***/ "./node_modules/imsc/src/main/js/styles.js":
/*!*************************************************!*\
  !*** ./node_modules/imsc/src/main/js/styles.js ***!
  \*************************************************/
/***/ (function(__unused_webpack_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.
 */

/**
 * @module imscStyles
 */

;
(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 = new imscUtils.ComputedLength(0, 1);

                } else {

                    h = imscUtils.toComputedLength(
                        attr.h.value,
                        attr.h.unit,
                        null,
                        doc.dimensions.h,
                        null,
                        doc.pxLength.h
                        );


                    if (h === null) {

                        return null;

                    }
                }

                if (attr === "auto") {

                    w = new imscUtils.ComputedLength(1, 0);

                } else {

                    w = imscUtils.toComputedLength(
                        attr.w.value,
                        attr.w.unit,
                        null,
                        doc.dimensions.w,
                        null,
                        doc.pxLength.w
                        );

                    if (w === null) {

                        return null;

                    }

                }

                return {'h': h, 'w': w};
            }
        ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "fontFamily",
            "default",
            ['span', 'p'],
            true,
            true,
            function (str) {
                var ffs = str.split(",");
                var rslt = [];

                for (var i = 0; i < ffs.length; i++) {

                    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,
            "shear",
            "0%",
            ['p'],
            true,
            true,
            imscUtils.parseLength,
            function (doc, parent, element, attr) {

                var fs;

                if (attr.unit === "%") {

                    fs = Math.abs(attr.value) > 100 ? Math.sign(attr.value) * 100 : attr.value;

                } else {

                    return null;

                }

                return fs;
            }
        ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "fontSize",
            "1c",
            ['span', 'p'],
            true,
            true,
            imscUtils.parseLength,
            function (doc, parent, element, attr, context) {

                var fs;

                fs = imscUtils.toComputedLength(
                    attr.value,
                    attr.unit,
                    parent !== null ? parent.styleAttrs[imscStyles.byName.fontSize.qname] : doc.cellLength.h,
                    parent !== null ? parent.styleAttrs[imscStyles.byName.fontSize.qname] : doc.cellLength.h,
                    doc.cellLength.h,
                    doc.pxLength.h
                    );

                return fs;
            }
        ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "fontStyle",
            "normal",
            ['span', 'p'],
            true,
            true,
            function (str) {
                /* TODO: handle font style */

                return str;
            },
            null
            ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "fontWeight",
            "normal",
            ['span', 'p'],
            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 {

                    lh = imscUtils.toComputedLength(
                        attr.value,
                        attr.unit,
                        element.styleAttrs[imscStyles.byName.fontSize.qname],
                        element.styleAttrs[imscStyles.byName.fontSize.qname],
                        doc.cellLength.h,
                        doc.pxLength.h
                        );

                    if (lh === null) {

                        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 = new imscUtils.ComputedLength(0,0);

                } else {

                    h = imscUtils.toComputedLength(
                        attr.h.value,
                        attr.h.unit,
                        null,
                        doc.dimensions.h,
                        null,
                        doc.pxLength.h
                        );

                    if (h === null) {

                        return null;

                    }

                }

                if (attr === "auto") {

                    w = new imscUtils.ComputedLength(0,0);

                } else {

                    w = imscUtils.toComputedLength(
                        attr.w.value,
                        attr.w.unit,
                        null,
                        doc.dimensions.w,
                        null,
                        doc.pxLength.w
                        );

                    if (w === null) {

                        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 = 0; i < s.length; i++) {

                    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 = 0 ; i < padding.length; i++) {

                    if (padding[i].value === 0) {

                        out[i] = new imscUtils.ComputedLength(0,0);

                    } else {

                        out[i] = imscUtils.toComputedLength(
                            padding[i].value,
                            padding[i].unit,
                            element.styleAttrs[imscStyles.byName.fontSize.qname],
                            i === 0 || i === 2 ? element.styleAttrs[imscStyles.byName.extent.qname].h : element.styleAttrs[imscStyles.byName.extent.qname].w,
                            i === 0 || i === 2 ? doc.cellLength.h : doc.cellLength.w,
                            i === 0 || i === 2 ? doc.pxLength.h: doc.pxLength.w
                            );

                        if (out[i] === null) return null;

                    }
                }


                return out;
            }
        ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "position",
            "top left",
            ['region'],
            false,
            true,
            function (str) {

                return imscUtils.parsePosition(str);

            },
            function (doc, parent, element, attr) {
                var h;
                var w;
                
                h = imscUtils.toComputedLength(
                    attr.v.offset.value,
                    attr.v.offset.unit,
                    null,
                    new imscUtils.ComputedLength(
                        - element.styleAttrs[imscStyles.byName.extent.qname].h.rw,
                        doc.dimensions.h.rh - element.styleAttrs[imscStyles.byName.extent.qname].h.rh 
                    ),
                    null,
                    doc.pxLength.h
                    );

                if (h === null) return null;


                if (attr.v.edge === "bottom") {

                    h = new imscUtils.ComputedLength(
                        - h.rw - element.styleAttrs[imscStyles.byName.extent.qname].h.rw,
                        doc.dimensions.h.rh - h.rh - element.styleAttrs[imscStyles.byName.extent.qname].h.rh
                    );
            
                }

                w = imscUtils.toComputedLength(
                    attr.h.offset.value,
                    attr.h.offset.unit,
                    null,
                    new imscUtils.ComputedLength(
                        doc.dimensions.w.rw - element.styleAttrs[imscStyles.byName.extent.qname].w.rw,
                        - element.styleAttrs[imscStyles.byName.extent.qname].w.rh
                    ),
                    null,
                    doc.pxLength.w
                    );

                if (h === null) return null;

                if (attr.h.edge === "right") {
                    
                    w = new imscUtils.ComputedLength(
                        doc.dimensions.w.rw - w.rw - element.styleAttrs[imscStyles.byName.extent.qname].w.rw,
                        - w.rh - element.styleAttrs[imscStyles.byName.extent.qname].w.rh
                    );

                }

                return {'h': h, 'w': w};
            }
        ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "ruby",
            "none",
            ['span'],
            false,
            true,
            function (str) {
                return str;
            },
            null
            ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "rubyAlign",
            "center",
            ['span'],
            true,
            true,
            function (str) {
                
                if (! (str === "center" || str === "spaceAround")) {
                    return null;
                }
                
                return str;
            },
            null
            ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "rubyPosition",
            "outside",
            ['span'],
            true,
            true,
            function (str) {
                return str;
            },
            null
            ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "rubyReserve",
            "none",
            ['p'],
            true,
            true,
            function (str) {
                var s = str.split(" ");

                var r = [null, null];

                if (s.length === 0 || s.length > 2)
                    return null;

                if (s[0] === "none" ||
                    s[0] === "both" ||
                    s[0] === "after" ||
                    s[0] === "before" ||
                    s[0] === "outside") {

                    r[0] = s[0];

                } else {

                    return null;

                }

                if (s.length === 2 && s[0] !== "none") {

                    var l = imscUtils.parseLength(s[1]);

                    if (l) {

                        r[1] = l;

                    } else {

                        return null;

                    }

                }


                return r;
            },
            function (doc, parent, element, attr, context) {

                if (attr[0] === "none") {

                    return attr;

                }

                var fs = null;

                if (attr[1] === null) {

                    fs = new imscUtils.ComputedLength(
                            element.styleAttrs[imscStyles.byName.fontSize.qname].rw * 0.5,
                            element.styleAttrs[imscStyles.byName.fontSize.qname].rh * 0.5
                    );

                } else {

                    fs = imscUtils.toComputedLength(attr[1].value,
                        attr[1].unit,
                        element.styleAttrs[imscStyles.byName.fontSize.qname],
                        element.styleAttrs[imscStyles.byName.fontSize.qname],
                        doc.cellLength.h,
                        doc.pxLength.h
                        );
                
                }

                if (fs === null) return null;

                return [attr[0], fs];
            }
        ),
        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,
            "textCombine",
            "none",
            ['span'],
            true,
            true,
            function (str) {
                if (str === "none" || str === "all") {

                    return str;
                }

                return null;
            },
            null
            ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "textDecoration",
            "none",
            ['span'],
            true,
            true,
            function (str) {
                return str.split(" ");
            },
            null
            ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "textEmphasis",
            "none",
            ['span'],
            true,
            true,
            function (str) {
                var e = str.split(" ");

                var rslt = {style: null, symbol: null, color: null, position: null};

                for (var i = 0; i < e.length; i++) {

                    if (e[i] === "none" || e[i] === "auto") {

                        rslt.style = e[i];

                    } else if (e[i] === "filled" ||
                        e[i] === "open") {

                        rslt.style = e[i];

                    } else if (e[i] === "circle" ||
                        e[i] === "dot" ||
                        e[i] === "sesame") {

                        rslt.symbol = e[i];

                    } else if (e[i] === "current") {

                        rslt.color = e[i];

                    } else if (e[i] === "outside" || e[i] === "before" || e[i] === "after") {

                        rslt.position = e[i];

                    } else {

                        rslt.color = imscUtils.parseColor(e[i]);

                        if (rslt.color === null)
                            return null;

                    }
                }

                if (rslt.style == null && rslt.symbol == null) {

                    rslt.style = "auto";

                } else {

                    rslt.symbol = rslt.symbol || "circle";
                    rslt.style = rslt.style || "filled";

                }

                rslt.position = rslt.position || "outside";
                rslt.color = rslt.color || "current";

                return rslt;
            },
            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;

                }

                rslt.thickness = imscUtils.toComputedLength(
                    attr.thickness.value,
                    attr.thickness.unit,
                    element.styleAttrs[imscStyles.byName.fontSize.qname],
                    element.styleAttrs[imscStyles.byName.fontSize.qname],
                    doc.cellLength.h,
                    doc.pxLength.h
                    );

                if (rslt.thickness === null)
                    return null;

                return rslt;
            }
        ),
        new StylingAttributeDefinition(
            imscNames.ns_tts,
            "textShadow",
            "none",
            ['span'],
            true,
            true,
            imscUtils.parseTextShadow,
            function (doc, parent, element, attr) {

                /*
                 * returns [{x_off: <length>, y_off: <length>, b_radius: <length>, color: <color>}*] or "none"
                 * 
                 */

                if (attr === "none")
                    return attr;

                var r = [];

                for (var i = 0; i < attr.length; i++) {

                    var shadow = {};

                    shadow.x_off = imscUtils.toComputedLength(
                        attr[i][0].value,
                        attr[i][0].unit,
                        null,
                        element.styleAttrs[imscStyles.byName.fontSize.qname],
                        null,
                        doc.pxLength.w
                        );

                    if (shadow.x_off === null)
                        return null;

                    shadow.y_off = imscUtils.toComputedLength(
                        attr[i][1].value,
                        attr[i][1].unit,
                        null,
                        element.styleAttrs[imscStyles.byName.fontSize.qname],
                        null,
                        doc.pxLength.h
                        );

                    if (shadow.y_off === null)
                        return null;

                    if (attr[i][2] === null) {

                        shadow.b_radius = 0;

                    } else {

                        shadow.b_radius = imscUtils.toComputedLength(
                            attr[i][2].value,
                            attr[i][2].unit,
                            null,
                            element.styleAttrs[imscStyles.byName.fontSize.qname],
                            null,
                            doc.pxLength.h
                            );

                        if (shadow.b_radius === null)
                            return null;

                    }

                    if (attr[i][3] === null) {

                        shadow.color = element.styleAttrs[imscStyles.byName.color.qname];

                    } else {

                        shadow.color = attr[i][3];

                    }

                    r.push(shadow);

                }

                return r;
            }
        ),
        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) {

                return imscUtils.toComputedLength(attr.value, attr.unit, null, null, doc.cellLength.w, 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];
    }


})( false ? 0 : 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 ***!
  \************************************************/
/***/ (function(__unused_webpack_module, exports) {

/* 
 * 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.
 */

/**
 * @module imscUtils
 */

;
(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|%|rh|rw)$/;

    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;
    };

    imscUtils.parseTextShadow = function (str) {

        var shadows = str.match(/([^\(,\)]|\([^\)]+\))+/g);
        
        var r = [];

        for (var i = 0; i < shadows.length; i++) {

            var shadow = shadows[i].split(" ");

            if (shadow.length === 1 && shadow[0] === "none") {

                return "none";

            } else if (shadow.length > 1 && shadow.length < 5) {

                var out_shadow = [null, null, null, null];

                /* x offset */

                var l = imscUtils.parseLength(shadow.shift());

                if (l === null)
                    return null;

                out_shadow[0] = l;

                /* y offset */

                l = imscUtils.parseLength(shadow.shift());

                if (l === null)
                    return null;

                out_shadow[1] = l;

                /* is there a third component */

                if (shadow.length === 0) {
                    r.push(out_shadow);
                    continue;
                }

                l = imscUtils.parseLength(shadow[0]);

                if (l !== null) {

                    out_shadow[2] = l;

                    shadow.shift();

                }

                if (shadow.length === 0) {
                    r.push(out_shadow);
                    continue;
                }

                var c = imscUtils.parseColor(shadow[0]);

                if (c === null)
                    return null;

                out_shadow[3] = c;

                r.push(out_shadow);
            }

        }

        return r;
    };


    imscUtils.parsePosition = function (str) {

        /* see https://www.w3.org/TR/ttml2/#style-value-position */

        var s = str.split(" ");

        var isKeyword = function (str) {

            return str === "center" ||
                    str === "left" ||
                    str === "top" ||
                    str === "bottom" ||
                    str === "right";

        };

        if (s.length > 4) {

            return null;

        }

        /* initial clean-up pass */

        for (var j = 0 ; j < s.length; j++) {

            if (!isKeyword(s[j])) {

                var l = imscUtils.parseLength(s[j]);

                if (l === null)
                    return null;

                s[j] = l;
            }

        }

        /* position default */

        var pos = {
            h: {edge: "left", offset: {value: 50, unit: "%"}},
            v: {edge: "top", offset: {value: 50, unit: "%"}}
        };

        /* update position */

        for (var i = 0; i < s.length; ) {

            /* extract the current component */

            var comp = s[i++];

            if (isKeyword(comp)) {

                /* we have a keyword */

                var offset = {value: 0, unit: "%"};

                /* peek at the next component */

                if (s.length !== 2 && i < s.length && (!isKeyword(s[i]))) {

                    /* followed by an offset */

                    offset = s[i++];

                }

                /* skip if center */

                if (comp === "right") {

                    pos.h.edge = comp;

                    pos.h.offset = offset;

                } else if (comp === "bottom") {

                    pos.v.edge = comp;


                    pos.v.offset = offset;


                } else if (comp === "left") {

                    pos.h.offset = offset;


                } else if (comp === "top") {

                    pos.v.offset = offset;


                }

            } else if (s.length === 1 || s.length === 2) {

                /* we have a bare value */

                if (i === 1) {

                    /* assign it to left edge if first bare value */

                    pos.h.offset = comp;

                } else {

                    /* assign it to top edge if second bare value */

                    pos.v.offset = comp;

                }

            } else {

                /* error condition */

                return null;

            }

        }

        return pos;
    };


    imscUtils.ComputedLength = function (rw, rh) {
        this.rw = rw;
        this.rh = rh;
    };

    imscUtils.ComputedLength.prototype.toUsedLength = function (width, height) {
        return width * this.rw + height * this.rh;
    };

    imscUtils.ComputedLength.prototype.isZero = function () {
        return this.rw === 0 && this.rh === 0;
    };

    /**
     * Computes a specified length to a root container relative length
     * 
     * @param {number} lengthVal Length value to be computed
     * @param {string} lengthUnit Units of the length value
     * @param {number} emScale length of 1em, or null if em is not allowed
     * @param {number} percentScale length to which , or null if perecentage is not allowed
     * @param {number} cellScale length of 1c, or null if c is not allowed
     * @param {number} pxScale length of 1px, or null if px is not allowed
     * @param {number} direction 0 if the length is computed in the horizontal direction, 1 if the length is computed in the vertical direction
     * @return {number} Computed length
     */
    imscUtils.toComputedLength = function(lengthVal, lengthUnit, emLength, percentLength, cellLength, pxLength) {

        if (lengthUnit === "%" && percentLength) {

            return new imscUtils.ComputedLength(
                    percentLength.rw * lengthVal / 100,
                    percentLength.rh * lengthVal / 100
                    );

        } else if (lengthUnit === "em" && emLength) {

            return new imscUtils.ComputedLength(
                    emLength.rw * lengthVal,
                    emLength.rh * lengthVal
                    );

        } else if (lengthUnit === "c" && cellLength) {

            return new imscUtils.ComputedLength(
                    lengthVal * cellLength.rw,
                    lengthVal * cellLength.rh
                    );

        } else if (lengthUnit === "px" && pxLength) {

            return new imscUtils.ComputedLength(
                    lengthVal * pxLength.rw,
                    lengthVal * pxLength.rh
                    );

        } else if (lengthUnit === "rh") {

            return new imscUtils.ComputedLength(
                    0,
                    lengthVal / 100
                    );

        } else if (lengthUnit === "rw") {

            return new imscUtils.ComputedLength(
                    lengthVal / 100,
                    0                    
                    );

        } else {

            return null;

        }

    };



})( false ? 0 : exports);


/***/ }),

/***/ "./node_modules/is-alphabetical/index.js":
/*!***********************************************!*\
  !*** ./node_modules/is-alphabetical/index.js ***!
  \***********************************************/
/***/ (function(module) {

"use strict";


module.exports = alphabetical

// Check if the given character code, or the character code at the first
// character, is alphabetical.
function alphabetical(character) {
  var code = typeof character === 'string' ? character.charCodeAt(0) : character

  return (
    (code >= 97 && code <= 122) /* a-z */ ||
    (code >= 65 && code <= 90) /* A-Z */
  )
}


/***/ }),

/***/ "./node_modules/is-alphanumerical/index.js":
/*!*************************************************!*\
  !*** ./node_modules/is-alphanumerical/index.js ***!
  \*************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


var alphabetical = __webpack_require__(/*! is-alphabetical */ "./node_modules/is-alphabetical/index.js")
var decimal = __webpack_require__(/*! is-decimal */ "./node_modules/is-decimal/index.js")

module.exports = alphanumerical

// Check if the given character code, or the character code at the first
// character, is alphanumerical.
function alphanumerical(character) {
  return alphabetical(character) || decimal(character)
}


/***/ }),

/***/ "./node_modules/is-decimal/index.js":
/*!******************************************!*\
  !*** ./node_modules/is-decimal/index.js ***!
  \******************************************/
/***/ (function(module) {

"use strict";


module.exports = decimal

// Check if the given character code, or the character code at the first
// character, is decimal.
function decimal(character) {
  var code = typeof character === 'string' ? character.charCodeAt(0) : character

  return code >= 48 && code <= 57 /* 0-9 */
}


/***/ }),

/***/ "./node_modules/path-browserify/index.js":
/*!***********************************************!*\
  !*** ./node_modules/path-browserify/index.js ***!
  \***********************************************/
/***/ (function(module) {

"use strict";
// 'path' module extracted from Node.js v8.11.1 (only the posix part)
// transplited with Babel

// 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.



function assertPath(path) {
  if (typeof path !== 'string') {
    throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
  }
}

// Resolves . and .. elements in a path with directory names
function normalizeStringPosix(path, allowAboveRoot) {
  var res = '';
  var lastSegmentLength = 0;
  var lastSlash = -1;
  var dots = 0;
  var code;
  for (var i = 0; i <= path.length; ++i) {
    if (i < path.length)
      code = path.charCodeAt(i);
    else if (code === 47 /*/*/)
      break;
    else
      code = 47 /*/*/;
    if (code === 47 /*/*/) {
      if (lastSlash === i - 1 || dots === 1) {
        // NOOP
      } else if (lastSlash !== i - 1 && dots === 2) {
        if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
          if (res.length > 2) {
            var lastSlashIndex = res.lastIndexOf('/');
            if (lastSlashIndex !== res.length - 1) {
              if (lastSlashIndex === -1) {
                res = '';
                lastSegmentLength = 0;
              } else {
                res = res.slice(0, lastSlashIndex);
                lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
              }
              lastSlash = i;
              dots = 0;
              continue;
            }
          } else if (res.length === 2 || res.length === 1) {
            res = '';
            lastSegmentLength = 0;
            lastSlash = i;
            dots = 0;
            continue;
          }
        }
        if (allowAboveRoot) {
          if (res.length > 0)
            res += '/..';
          else
            res = '..';
          lastSegmentLength = 2;
        }
      } else {
        if (res.length > 0)
          res += '/' + path.slice(lastSlash + 1, i);
        else
          res = path.slice(lastSlash + 1, i);
        lastSegmentLength = i - lastSlash - 1;
      }
      lastSlash = i;
      dots = 0;
    } else if (code === 46 /*.*/ && dots !== -1) {
      ++dots;
    } else {
      dots = -1;
    }
  }
  return res;
}

function _format(sep, pathObject) {
  var dir = pathObject.dir || pathObject.root;
  var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
  if (!dir) {
    return base;
  }
  if (dir === pathObject.root) {
    return dir + base;
  }
  return dir + sep + base;
}

var posix = {
  // path.resolve([from ...], to)
  resolve: function resolve() {
    var resolvedPath = '';
    var resolvedAbsolute = false;
    var cwd;

    for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
      var path;
      if (i >= 0)
        path = arguments[i];
      else {
        if (cwd === undefined)
          cwd = process.cwd();
        path = cwd;
      }

      assertPath(path);

      // Skip empty entries
      if (path.length === 0) {
        continue;
      }

      resolvedPath = path + '/' + resolvedPath;
      resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
    }

    // 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 = normalizeStringPosix(resolvedPath, !resolvedAbsolute);

    if (resolvedAbsolute) {
      if (resolvedPath.length > 0)
        return '/' + resolvedPath;
      else
        return '/';
    } else if (resolvedPath.length > 0) {
      return resolvedPath;
    } else {
      return '.';
    }
  },

  normalize: function normalize(path) {
    assertPath(path);

    if (path.length === 0) return '.';

    var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
    var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;

    // Normalize the path
    path = normalizeStringPosix(path, !isAbsolute);

    if (path.length === 0 && !isAbsolute) path = '.';
    if (path.length > 0 && trailingSeparator) path += '/';

    if (isAbsolute) return '/' + path;
    return path;
  },

  isAbsolute: function isAbsolute(path) {
    assertPath(path);
    return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
  },

  join: function join() {
    if (arguments.length === 0)
      return '.';
    var joined;
    for (var i = 0; i < arguments.length; ++i) {
      var arg = arguments[i];
      assertPath(arg);
      if (arg.length > 0) {
        if (joined === undefined)
          joined = arg;
        else
          joined += '/' + arg;
      }
    }
    if (joined === undefined)
      return '.';
    return posix.normalize(joined);
  },

  relative: function relative(from, to) {
    assertPath(from);
    assertPath(to);

    if (from === to) return '';

    from = posix.resolve(from);
    to = posix.resolve(to);

    if (from === to) return '';

    // Trim any leading backslashes
    var fromStart = 1;
    for (; fromStart < from.length; ++fromStart) {
      if (from.charCodeAt(fromStart) !== 47 /*/*/)
        break;
    }
    var fromEnd = from.length;
    var fromLen = fromEnd - fromStart;

    // Trim any leading backslashes
    var toStart = 1;
    for (; toStart < to.length; ++toStart) {
      if (to.charCodeAt(toStart) !== 47 /*/*/)
        break;
    }
    var toEnd = to.length;
    var toLen = toEnd - toStart;

    // Compare paths to find the longest common path from root
    var length = fromLen < toLen ? fromLen : toLen;
    var lastCommonSep = -1;
    var i = 0;
    for (; i <= length; ++i) {
      if (i === length) {
        if (toLen > length) {
          if (to.charCodeAt(toStart + i) === 47 /*/*/) {
            // We get here if `from` is the exact base path for `to`.
            // For example: from='/foo/bar'; to='/foo/bar/baz'
            return to.slice(toStart + i + 1);
          } else if (i === 0) {
            // We get here if `from` is the root
            // For example: from='/'; to='/foo'
            return to.slice(toStart + i);
          }
        } else if (fromLen > length) {
          if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
            // We get here if `to` is the exact base path for `from`.
            // For example: from='/foo/bar/baz'; to='/foo/bar'
            lastCommonSep = i;
          } else if (i === 0) {
            // We get here if `to` is the root.
            // For example: from='/foo'; to='/'
            lastCommonSep = 0;
          }
        }
        break;
      }
      var fromCode = from.charCodeAt(fromStart + i);
      var toCode = to.charCodeAt(toStart + i);
      if (fromCode !== toCode)
        break;
      else if (fromCode === 47 /*/*/)
        lastCommonSep = i;
    }

    var out = '';
    // Generate the relative path based on the path difference between `to`
    // and `from`
    for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
      if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
        if (out.length === 0)
          out += '..';
        else
          out += '/..';
      }
    }

    // Lastly, append the rest of the destination (`to`) path that comes after
    // the common path parts
    if (out.length > 0)
      return out + to.slice(toStart + lastCommonSep);
    else {
      toStart += lastCommonSep;
      if (to.charCodeAt(toStart) === 47 /*/*/)
        ++toStart;
      return to.slice(toStart);
    }
  },

  _makeLong: function _makeLong(path) {
    return path;
  },

  dirname: function dirname(path) {
    assertPath(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 '//';
    return path.slice(0, end);
  },

  basename: function basename(path, ext) {
    if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
    assertPath(path);

    var start = 0;
    var end = -1;
    var matchedSlash = true;
    var i;

    if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
      if (ext.length === path.length && ext === path) return '';
      var extIdx = ext.length - 1;
      var firstNonSlashEnd = -1;
      for (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) {
              start = i + 1;
              break;
            }
          } else {
          if (firstNonSlashEnd === -1) {
            // We saw the first non-path separator, remember this index in case
            // we need it if the extension ends up not matching
            matchedSlash = false;
            firstNonSlashEnd = i + 1;
          }
          if (extIdx >= 0) {
            // Try to match the explicit extension
            if (code === ext.charCodeAt(extIdx)) {
              if (--extIdx === -1) {
                // We matched the extension, so mark this as the end of our path
                // component
                end = i;
              }
            } else {
              // Extension does not match, so our result is the entire path
              // component
              extIdx = -1;
              end = firstNonSlashEnd;
            }
          }
        }
      }

      if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
      return path.slice(start, end);
    } else {
      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);
    }
  },

  extname: function extname(path) {
    assertPath(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);
  },

  format: function format(pathObject) {
    if (pathObject === null || typeof pathObject !== 'object') {
      throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
    }
    return _format('/', pathObject);
  },

  parse: function parse(path) {
    assertPath(path);

    var ret = { root: '', dir: '', base: '', ext: '', name: '' };
    if (path.length === 0) return ret;
    var code = path.charCodeAt(0);
    var isAbsolute = code === 47 /*/*/;
    var start;
    if (isAbsolute) {
      ret.root = '/';
      start = 1;
    } else {
      start = 0;
    }
    var startDot = -1;
    var startPart = 0;
    var end = -1;
    var matchedSlash = true;
    var i = path.length - 1;

    // Track the state of characters (if any) we see before our first dot and
    // after any path separator we find
    var preDotState = 0;

    // Get non-dir info
    for (; i >= start; --i) {
      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) {
      if (end !== -1) {
        if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
      }
    } else {
      if (startPart === 0 && isAbsolute) {
        ret.name = path.slice(1, startDot);
        ret.base = path.slice(1, end);
      } else {
        ret.name = path.slice(startPart, startDot);
        ret.base = path.slice(startPart, end);
      }
      ret.ext = path.slice(startDot, end);
    }

    if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';

    return ret;
  },

  sep: '/',
  delimiter: ':',
  win32: null,
  posix: null
};

posix.posix = posix;

module.exports = posix;


/***/ }),

/***/ "./node_modules/safe-buffer/index.js":
/*!*******************************************!*\
  !*** ./node_modules/safe-buffer/index.js ***!
  \*******************************************/
/***/ (function(module, exports, __webpack_require__) {

/* eslint-disable node/no-deprecated-api */
var buffer = __webpack_require__(/*! buffer */ "./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 ***!
  \*************************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

;(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)) {
            // wait for it...
          } 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
      }
    }())
  }
})( false ? 0 : exports)


/***/ }),

/***/ "./node_modules/stream-browserify/index.js":
/*!*************************************************!*\
  !*** ./node_modules/stream-browserify/index.js ***!
  \*************************************************/
/***/ (function(module, __unused_webpack_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/events/events.js").EventEmitter);
var inherits = __webpack_require__(/*! inherits */ "./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js");

inherits(Stream, EE);
Stream.Readable = __webpack_require__(/*! readable-stream/lib/_stream_readable.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_readable.js");
Stream.Writable = __webpack_require__(/*! readable-stream/lib/_stream_writable.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_writable.js");
Stream.Duplex = __webpack_require__(/*! readable-stream/lib/_stream_duplex.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js");
Stream.Transform = __webpack_require__(/*! readable-stream/lib/_stream_transform.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_transform.js");
Stream.PassThrough = __webpack_require__(/*! readable-stream/lib/_stream_passthrough.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_passthrough.js");
Stream.finished = __webpack_require__(/*! readable-stream/lib/internal/streams/end-of-stream.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js")
Stream.pipeline = __webpack_require__(/*! readable-stream/lib/internal/streams/pipeline.js */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/pipeline.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/stream-browserify/node_modules/inherits/inherits_browser.js":
/*!**********************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js ***!
  \**********************************************************************************/
/***/ (function(module) {

if (typeof Object.create === 'function') {
  // implementation from standard node.js 'util' module
  module.exports = function inherits(ctor, superCtor) {
    if (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) {
    if (superCtor) {
      ctor.super_ = superCtor
      var TempCtor = function () {}
      TempCtor.prototype = superCtor.prototype
      ctor.prototype = new TempCtor()
      ctor.prototype.constructor = ctor
    }
  }
}


/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js":
/*!***************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js ***!
  \***************************************************************************************/
/***/ (function(module) {

"use strict";


function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

var codes = {};

function createErrorType(code, message, Base) {
  if (!Base) {
    Base = Error;
  }

  function getMessage(arg1, arg2, arg3) {
    if (typeof message === 'string') {
      return message;
    } else {
      return message(arg1, arg2, arg3);
    }
  }

  var NodeError =
  /*#__PURE__*/
  function (_Base) {
    _inheritsLoose(NodeError, _Base);

    function NodeError(arg1, arg2, arg3) {
      return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
    }

    return NodeError;
  }(Base);

  NodeError.prototype.name = Base.name;
  NodeError.prototype.code = code;
  codes[code] = NodeError;
} // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js


function oneOf(expected, thing) {
  if (Array.isArray(expected)) {
    var len = expected.length;
    expected = expected.map(function (i) {
      return String(i);
    });

    if (len > 2) {
      return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
    } else if (len === 2) {
      return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
    } else {
      return "of ".concat(thing, " ").concat(expected[0]);
    }
  } else {
    return "of ".concat(thing, " ").concat(String(expected));
  }
} // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith


function startsWith(str, search, pos) {
  return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
} // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith


function endsWith(str, search, this_len) {
  if (this_len === undefined || this_len > str.length) {
    this_len = str.length;
  }

  return str.substring(this_len - search.length, this_len) === search;
} // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes


function includes(str, search, start) {
  if (typeof start !== 'number') {
    start = 0;
  }

  if (start + search.length > str.length) {
    return false;
  } else {
    return str.indexOf(search, start) !== -1;
  }
}

createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
  return 'The value "' + value + '" is invalid for option "' + name + '"';
}, TypeError);
createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  // determiner: 'must be' or 'must not be'
  var determiner;

  if (typeof expected === 'string' && startsWith(expected, 'not ')) {
    determiner = 'must not be';
    expected = expected.replace(/^not /, '');
  } else {
    determiner = 'must be';
  }

  var msg;

  if (endsWith(name, ' argument')) {
    // For cases like 'first argument'
    msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  } else {
    var type = includes(name, '.') ? 'property' : 'argument';
    msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  }

  msg += ". Received type ".concat(typeof actual);
  return msg;
}, TypeError);
createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
  return 'The ' + name + ' method is not implemented';
});
createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
createErrorType('ERR_STREAM_DESTROYED', function (name) {
  return 'Cannot call ' + name + ' after a stream was destroyed';
});
createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
  return 'Unknown encoding: ' + arg;
}, TypeError);
createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
module.exports.codes = codes;


/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js":
/*!*******************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js ***!
  \*******************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// 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 objectKeys = Object.keys || function (obj) {
  var keys = [];

  for (var key in obj) {
    keys.push(key);
  }

  return keys;
};
/*</replacement>*/


module.exports = Duplex;

var Readable = __webpack_require__(/*! ./_stream_readable */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_readable.js");

var Writable = __webpack_require__(/*! ./_stream_writable */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_writable.js");

__webpack_require__(/*! inherits */ "./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js")(Duplex, Readable);

{
  // Allow the keys array to be GC'ed.
  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);
  this.allowHalfOpen = true;

  if (options) {
    if (options.readable === false) this.readable = false;
    if (options.writable === false) this.writable = false;

    if (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 get() {
    return this._writableState.highWaterMark;
  }
});
Object.defineProperty(Duplex.prototype, 'writableBuffer', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._writableState && this._writableState.getBuffer();
  }
});
Object.defineProperty(Duplex.prototype, 'writableLength', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._writableState.length;
  }
}); // the no-half-open enforcer

function onend() {
  // If the writable side ended, then we're ok.
  if (this._writableState.ended) return; // no more data can be written.
  // But allow more writes to happen in this tick.

  process.nextTick(onEndNT, this);
}

function onEndNT(self) {
  self.end();
}

Object.defineProperty(Duplex.prototype, 'destroyed', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    if (this._readableState === undefined || this._writableState === undefined) {
      return false;
    }

    return this._readableState.destroyed && this._writableState.destroyed;
  },
  set: function set(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;
  }
});

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_passthrough.js":
/*!************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_passthrough.js ***!
  \************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// 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/stream-browserify/node_modules/readable-stream/lib/_stream_transform.js");

__webpack_require__(/*! inherits */ "./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js")(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/stream-browserify/node_modules/readable-stream/lib/_stream_readable.js":
/*!*********************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_readable.js ***!
  \*********************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// 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 = Readable;
/*<replacement>*/

var Duplex;
/*</replacement>*/

Readable.ReadableState = ReadableState;
/*<replacement>*/

var EE = (__webpack_require__(/*! events */ "./node_modules/events/events.js").EventEmitter);

var EElistenerCount = function EElistenerCount(emitter, type) {
  return emitter.listeners(type).length;
};
/*</replacement>*/

/*<replacement>*/


var Stream = __webpack_require__(/*! ./internal/streams/stream */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream-browser.js");
/*</replacement>*/


var Buffer = (__webpack_require__(/*! buffer */ "./node_modules/buffer/index.js").Buffer);

var OurUint8Array = __webpack_require__.g.Uint8Array || function () {};

function _uint8ArrayToBuffer(chunk) {
  return Buffer.from(chunk);
}

function _isUint8Array(obj) {
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
}
/*<replacement>*/


var debugUtil = __webpack_require__(/*! util */ "?19e6");

var debug;

if (debugUtil && debugUtil.debuglog) {
  debug = debugUtil.debuglog('stream');
} else {
  debug = function debug() {};
}
/*</replacement>*/


var BufferList = __webpack_require__(/*! ./internal/streams/buffer_list */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/buffer_list.js");

var destroyImpl = __webpack_require__(/*! ./internal/streams/destroy */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/destroy.js");

var _require = __webpack_require__(/*! ./internal/streams/state */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/state.js"),
    getHighWaterMark = _require.getHighWaterMark;

var _require$codes = (__webpack_require__(/*! ../errors */ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js").codes),
    ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
    ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
    ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
    ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.


var StringDecoder;
var createReadableStreamAsyncIterator;
var from;

__webpack_require__(/*! inherits */ "./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js")(Readable, Stream);

var errorOrDestroy = destroyImpl.errorOrDestroy;
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 (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
}

function ReadableState(options, stream, isDuplex) {
  Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/stream-browserify/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.

  if (typeof isDuplex !== 'boolean') 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"

  this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // 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;
  this.paused = true; // Should close be emitted on destroy. Defaults to true.

  this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')

  this.autoDestroy = !!options.autoDestroy; // 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/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js");
  if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
  // the ReadableState constructor, at least with V8 6.5

  var isDuplex = this instanceof Duplex;
  this._readableState = new ReadableState(options, this, isDuplex); // 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', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    if (this._readableState === undefined) {
      return false;
    }

    return this._readableState.destroyed;
  },
  set: function set(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) {
  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) {
  debug('readableAddChunk', chunk);
  var state = stream._readableState;

  if (chunk === null) {
    state.reading = false;
    onEofChunk(stream, state);
  } else {
    var er;
    if (!skipChunkCheck) er = chunkInvalid(state, chunk);

    if (er) {
      errorOrDestroy(stream, 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) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
      } else if (state.ended) {
        errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
      } else if (state.destroyed) {
        return false;
      } 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;
      maybeReadMore(stream, state);
    }
  } // We can push more data if we are below the highWaterMark.
  // 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.


  return !state.ended && (state.length < state.highWaterMark || state.length === 0);
}

function addChunk(stream, state, chunk, addToFront) {
  if (state.flowing && state.length === 0 && !state.sync) {
    state.awaitDrain = 0;
    stream.emit('data', chunk);
  } 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 ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
  }

  return er;
}

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);
  var decoder = new StringDecoder(enc);
  this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8

  this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:

  var p = this._readableState.buffer.head;
  var content = '';

  while (p !== null) {
    content += decoder.write(p.data);
    p = p.next;
  }

  this._readableState.buffer.clear();

  if (content !== '') this._readableState.buffer.push(content);
  this._readableState.length = content.length;
  return this;
}; // Don't raise the hwm > 1GB


var MAX_HWM = 0x40000000;

function computeNewHighWaterMark(n) {
  if (n >= MAX_HWM) {
    // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
    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.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || 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 = state.length <= state.highWaterMark;
    n = 0;
  } else {
    state.length -= n;
    state.awaitDrain = 0;
  }

  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) {
  debug('onEofChunk');
  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;

  if (state.sync) {
    // if we are sync, wait until next tick to emit the data.
    // Otherwise we risk emitting data in the flow()
    // the readable code triggers during a read() call
    emitReadable(stream);
  } else {
    // emit 'readable' now to make sure it gets picked up.
    state.needReadable = false;

    if (!state.emittedReadable) {
      state.emittedReadable = true;
      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;
  debug('emitReadable', state.needReadable, state.emittedReadable);
  state.needReadable = false;

  if (!state.emittedReadable) {
    debug('emitReadable', state.flowing);
    state.emittedReadable = true;
    process.nextTick(emitReadable_, stream);
  }
}

function emitReadable_(stream) {
  var state = stream._readableState;
  debug('emitReadable_', state.destroyed, state.length, state.ended);

  if (!state.destroyed && (state.length || state.ended)) {
    stream.emit('readable');
    state.emittedReadable = false;
  } // The stream needs another readable event if
  // 1. It is not flowing, as the flow mechanism will take
  //    care of it.
  // 2. It is not ended.
  // 3. It is below the highWaterMark, so we can schedule
  //    another readable later.


  state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
  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;
    process.nextTick(maybeReadMore_, stream, state);
  }
}

function maybeReadMore_(stream, state) {
  // Attempt to read more data if we should.
  //
  // The conditions for reading more data are (one of):
  // - Not enough data buffered (state.length < state.highWaterMark). The loop
  //   is responsible for filling the buffer with enough data if such data
  //   is available. If highWaterMark is 0 and we are not in the flowing mode
  //   we should _not_ attempt to buffer any extra data. We'll get more data
  //   when the stream consumer calls read() instead.
  // - No data in the buffer, and the stream is in flowing mode. In this mode
  //   the loop below is responsible for ensuring read() is called. Failing to
  //   call read here would abort the flow and there's no other mechanism for
  //   continuing the flow if the stream consumer has just subscribed to the
  //   'data' event.
  //
  // In addition to the above conditions to keep reading data, the following
  // conditions prevent the data from being read:
  // - The stream has ended (state.ended).
  // - There is already a pending 'read' operation (state.reading). This is a
  //   case where the the stream has called the implementation defined _read()
  //   method, but they are processing the call asynchronously and have _not_
  //   called push() with new data. In this case we skip performing more
  //   read()s. The execution ends in this method again after the _read() ends
  //   up calling push() with more data.
  while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
    var len = state.length;
    debug('maybeReadMore read 0');
    stream.read(0);
    if (len === state.length) // didn't get any data, stop spinning.
      break;
  }

  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) {
  errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
};

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) process.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();
  }

  src.on('data', ondata);

  function ondata(chunk) {
    debug('ondata');
    var ret = dest.write(chunk);
    debug('dest.write', ret);

    if (ret === false) {
      // 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', state.awaitDrain);
        state.awaitDrain++;
      }

      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) errorOrDestroy(dest, 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 pipeOnDrainFunctionResult() {
    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, {
        hasUnpiped: false
      });
    }

    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);
  var state = this._readableState;

  if (ev === 'data') {
    // update readableListening so that resume() may be a no-op
    // a few lines down. This is needed to support once('readable').
    state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused

    if (state.flowing !== false) this.resume();
  } else if (ev === 'readable') {
    if (!state.endEmitted && !state.readableListening) {
      state.readableListening = state.needReadable = true;
      state.flowing = false;
      state.emittedReadable = false;
      debug('on readable', state.length, state.reading);

      if (state.length) {
        emitReadable(this);
      } else if (!state.reading) {
        process.nextTick(nReadingNextTick, this);
      }
    }
  }

  return res;
};

Readable.prototype.addListener = Readable.prototype.on;

Readable.prototype.removeListener = function (ev, fn) {
  var res = Stream.prototype.removeListener.call(this, ev, fn);

  if (ev === 'readable') {
    // We need to check if there is someone still listening to
    // readable and reset the state. However this needs to happen
    // after readable has been emitted but before I/O (nextTick) to
    // support once('readable', fn) cycles. This means that calling
    // resume within the same tick will have no
    // effect.
    process.nextTick(updateReadableListening, this);
  }

  return res;
};

Readable.prototype.removeAllListeners = function (ev) {
  var res = Stream.prototype.removeAllListeners.apply(this, arguments);

  if (ev === 'readable' || ev === undefined) {
    // We need to check if there is someone still listening to
    // readable and reset the state. However this needs to happen
    // after readable has been emitted but before I/O (nextTick) to
    // support once('readable', fn) cycles. This means that calling
    // resume within the same tick will have no
    // effect.
    process.nextTick(updateReadableListening, this);
  }

  return res;
};

function updateReadableListening(self) {
  var state = self._readableState;
  state.readableListening = self.listenerCount('readable') > 0;

  if (state.resumeScheduled && !state.paused) {
    // flowing needs to be set to true now, otherwise
    // the upcoming resume will not flow.
    state.flowing = true; // crude way to check if we should resume
  } else if (self.listenerCount('data') > 0) {
    self.resume();
  }
}

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'); // we flow only if there is no one listening
    // for readable, but we still have to call
    // resume()

    state.flowing = !state.readableListening;
    resume(this, state);
  }

  state.paused = false;
  return this;
};

function resume(stream, state) {
  if (!state.resumeScheduled) {
    state.resumeScheduled = true;
    process.nextTick(resume_, stream, state);
  }
}

function resume_(stream, state) {
  debug('resume', state.reading);

  if (!state.reading) {
    stream.read(0);
  }

  state.resumeScheduled = false;
  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 (this._readableState.flowing !== false) {
    debug('pause');
    this._readableState.flowing = false;
    this.emit('pause');
  }

  this._readableState.paused = true;
  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 methodWrap(method) {
        return function methodWrapReturnFunction() {
          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;
};

if (typeof Symbol === 'function') {
  Readable.prototype[Symbol.asyncIterator] = function () {
    if (createReadableStreamAsyncIterator === undefined) {
      createReadableStreamAsyncIterator = __webpack_require__(/*! ./internal/streams/async_iterator */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/async_iterator.js");
    }

    return createReadableStreamAsyncIterator(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 get() {
    return this._readableState.highWaterMark;
  }
});
Object.defineProperty(Readable.prototype, 'readableBuffer', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._readableState && this._readableState.buffer;
  }
});
Object.defineProperty(Readable.prototype, 'readableFlowing', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._readableState.flowing;
  },
  set: function set(state) {
    if (this._readableState) {
      this._readableState.flowing = state;
    }
  }
}); // exposed for testing purposes only.

Readable._fromList = fromList;
Object.defineProperty(Readable.prototype, 'readableLength', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._readableState.length;
  }
}); // 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.first();else ret = state.buffer.concat(state.length);
    state.buffer.clear();
  } else {
    // read part of list
    ret = state.buffer.consume(n, state.decoder);
  }
  return ret;
}

function endReadable(stream) {
  var state = stream._readableState;
  debug('endReadable', state.endEmitted);

  if (!state.endEmitted) {
    state.ended = true;
    process.nextTick(endReadableNT, state, stream);
  }
}

function endReadableNT(state, stream) {
  debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.

  if (!state.endEmitted && state.length === 0) {
    state.endEmitted = true;
    stream.readable = false;
    stream.emit('end');

    if (state.autoDestroy) {
      // In case of duplex streams we need a way to detect
      // if the writable side is ready for autoDestroy as well
      var wState = stream._writableState;

      if (!wState || wState.autoDestroy && wState.finished) {
        stream.destroy();
      }
    }
  }
}

if (typeof Symbol === 'function') {
  Readable.from = function (iterable, opts) {
    if (from === undefined) {
      from = __webpack_require__(/*! ./internal/streams/from */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from-browser.js");
    }

    return from(Readable, iterable, opts);
  };
}

function indexOf(xs, x) {
  for (var i = 0, l = xs.length; i < l; i++) {
    if (xs[i] === x) return i;
  }

  return -1;
}

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_transform.js":
/*!**********************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_transform.js ***!
  \**********************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// 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 _require$codes = (__webpack_require__(/*! ../errors */ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js").codes),
    ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
    ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
    ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
    ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;

var Duplex = __webpack_require__(/*! ./_stream_duplex */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js");

__webpack_require__(/*! inherits */ "./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js")(Transform, Duplex);

function afterTransform(er, data) {
  var ts = this._transformState;
  ts.transforming = false;
  var cb = ts.writecb;

  if (cb === null) {
    return this.emit('error', new ERR_MULTIPLE_CALLBACK());
  }

  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._readableState.destroyed) {
    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) {
  cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
};

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.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) {
  Duplex.prototype._destroy.call(this, err, function (err2) {
    cb(err2);
  });
};

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); // TODO(BridgeAR): Write a test for these two error cases
  // if there's nothing in the write buffer, then that means
  // that nothing more will ever be provided

  if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
  if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
  return stream.push(null);
}

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_writable.js":
/*!*********************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_writable.js ***!
  \*********************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// 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.


module.exports = Writable;
/* <replacement> */

function WriteReq(chunk, encoding, cb) {
  this.chunk = chunk;
  this.encoding = encoding;
  this.callback = cb;
  this.next = null;
} // 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 Duplex;
/*</replacement>*/

Writable.WritableState = WritableState;
/*<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/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream-browser.js");
/*</replacement>*/


var Buffer = (__webpack_require__(/*! buffer */ "./node_modules/buffer/index.js").Buffer);

var OurUint8Array = __webpack_require__.g.Uint8Array || function () {};

function _uint8ArrayToBuffer(chunk) {
  return Buffer.from(chunk);
}

function _isUint8Array(obj) {
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
}

var destroyImpl = __webpack_require__(/*! ./internal/streams/destroy */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/destroy.js");

var _require = __webpack_require__(/*! ./internal/streams/state */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/state.js"),
    getHighWaterMark = _require.getHighWaterMark;

var _require$codes = (__webpack_require__(/*! ../errors */ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js").codes),
    ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
    ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
    ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
    ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
    ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
    ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
    ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
    ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;

var errorOrDestroy = destroyImpl.errorOrDestroy;

__webpack_require__(/*! inherits */ "./node_modules/stream-browserify/node_modules/inherits/inherits_browser.js")(Writable, Stream);

function nop() {}

function WritableState(options, stream, isDuplex) {
  Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/stream-browserify/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,
  // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.

  if (typeof isDuplex !== 'boolean') 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()

  this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // 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; // Should close be emitted on destroy. Defaults to true.

  this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')

  this.autoDestroy = !!options.autoDestroy; // 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 writableStateBufferGetter() {
        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 value(object) {
      if (realHasInstance.call(this, object)) return true;
      if (this !== Writable) return false;
      return object && object._writableState instanceof WritableState;
    }
  });
} else {
  realHasInstance = function realHasInstance(object) {
    return object instanceof this;
  };
}

function Writable(options) {
  Duplex = Duplex || __webpack_require__(/*! ./_stream_duplex */ "./node_modules/stream-browserify/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.
  // Checking for a Stream.Duplex instance is faster here instead of inside
  // the WritableState constructor, at least with V8 6.5

  var isDuplex = this instanceof Duplex;
  if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
  this._writableState = new WritableState(options, this, isDuplex); // 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 () {
  errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
};

function writeAfterEnd(stream, cb) {
  var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb

  errorOrDestroy(stream, er);
  process.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 er;

  if (chunk === null) {
    er = new ERR_STREAM_NULL_VALUES();
  } else if (typeof chunk !== 'string' && !state.objectMode) {
    er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
  }

  if (er) {
    errorOrDestroy(stream, er);
    process.nextTick(cb, er);
    return false;
  }

  return true;
}

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.ending) 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 () {
  this._writableState.corked++;
};

Writable.prototype.uncork = function () {
  var state = this._writableState;

  if (state.corked) {
    state.corked--;
    if (!state.writing && !state.corked && !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 ERR_UNKNOWN_ENCODING(encoding);
  this._writableState.defaultEncoding = encoding;
  return this;
};

Object.defineProperty(Writable.prototype, 'writableBuffer', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._writableState && this._writableState.getBuffer();
  }
});

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 get() {
    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 (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else 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
    process.nextTick(cb, er); // this can emit finish, and it will always happen
    // after error

    process.nextTick(finishMaybe, stream, state);
    stream._writableState.errorEmitted = true;
    errorOrDestroy(stream, er);
  } else {
    // the caller expect this to happen before if
    // it is async
    cb(er);
    stream._writableState.errorEmitted = true;
    errorOrDestroy(stream, 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;
  if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
  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) || stream.destroyed;

    if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
      clearBuffer(stream, state);
    }

    if (sync) {
      process.nextTick(afterWrite, stream, state, finished, cb);
    } 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 ERR_METHOD_NOT_IMPLEMENTED('_write()'));
};

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) endWritable(this, state, cb);
  return this;
};

Object.defineProperty(Writable.prototype, 'writableLength', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    return this._writableState.length;
  }
});

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) {
      errorOrDestroy(stream, 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.destroyed) {
      state.pendingcb++;
      state.finalCalled = true;
      process.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');

      if (state.autoDestroy) {
        // In case of duplex streams we need a way to detect
        // if the readable side is ready for autoDestroy as well
        var rState = stream._readableState;

        if (!rState || rState.autoDestroy && rState.endEmitted) {
          stream.destroy();
        }
      }
    }
  }

  return need;
}

function endWritable(stream, state, cb) {
  state.ending = true;
  finishMaybe(stream, state);

  if (cb) {
    if (state.finished) process.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;
  } // reuse the free corkReq.


  state.corkedRequestsFree.next = corkReq;
}

Object.defineProperty(Writable.prototype, 'destroyed', {
  // making it explicit this property is not enumerable
  // because otherwise some prototype manipulation in
  // userland will fail
  enumerable: false,
  get: function get() {
    if (this._writableState === undefined) {
      return false;
    }

    return this._writableState.destroyed;
  },
  set: function set(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) {
  cb(err);
};

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/async_iterator.js":
/*!************************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/async_iterator.js ***!
  \************************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


var _Object$setPrototypeO;

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; }

var finished = __webpack_require__(/*! ./end-of-stream */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js");

var kLastResolve = Symbol('lastResolve');
var kLastReject = Symbol('lastReject');
var kError = Symbol('error');
var kEnded = Symbol('ended');
var kLastPromise = Symbol('lastPromise');
var kHandlePromise = Symbol('handlePromise');
var kStream = Symbol('stream');

function createIterResult(value, done) {
  return {
    value: value,
    done: done
  };
}

function readAndResolve(iter) {
  var resolve = iter[kLastResolve];

  if (resolve !== null) {
    var data = iter[kStream].read(); // we defer if data is null
    // we can be expecting either 'end' or
    // 'error'

    if (data !== null) {
      iter[kLastPromise] = null;
      iter[kLastResolve] = null;
      iter[kLastReject] = null;
      resolve(createIterResult(data, false));
    }
  }
}

function onReadable(iter) {
  // we wait for the next tick, because it might
  // emit an error with process.nextTick
  process.nextTick(readAndResolve, iter);
}

function wrapForNext(lastPromise, iter) {
  return function (resolve, reject) {
    lastPromise.then(function () {
      if (iter[kEnded]) {
        resolve(createIterResult(undefined, true));
        return;
      }

      iter[kHandlePromise](resolve, reject);
    }, reject);
  };
}

var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
  get stream() {
    return this[kStream];
  },

  next: function next() {
    var _this = this;

    // if we have detected an error in the meanwhile
    // reject straight away
    var error = this[kError];

    if (error !== null) {
      return Promise.reject(error);
    }

    if (this[kEnded]) {
      return Promise.resolve(createIterResult(undefined, true));
    }

    if (this[kStream].destroyed) {
      // We need to defer via nextTick because if .destroy(err) is
      // called, the error will be emitted via nextTick, and
      // we cannot guarantee that there is no error lingering around
      // waiting to be emitted.
      return new Promise(function (resolve, reject) {
        process.nextTick(function () {
          if (_this[kError]) {
            reject(_this[kError]);
          } else {
            resolve(createIterResult(undefined, true));
          }
        });
      });
    } // if we have multiple next() calls
    // we will wait for the previous Promise to finish
    // this logic is optimized to support for await loops,
    // where next() is only called once at a time


    var lastPromise = this[kLastPromise];
    var promise;

    if (lastPromise) {
      promise = new Promise(wrapForNext(lastPromise, this));
    } else {
      // fast path needed to support multiple this.push()
      // without triggering the next() queue
      var data = this[kStream].read();

      if (data !== null) {
        return Promise.resolve(createIterResult(data, false));
      }

      promise = new Promise(this[kHandlePromise]);
    }

    this[kLastPromise] = promise;
    return promise;
  }
}, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
  return this;
}), _defineProperty(_Object$setPrototypeO, "return", function _return() {
  var _this2 = this;

  // destroy(err, cb) is a private API
  // we can guarantee we have that here, because we control the
  // Readable class this is attached to
  return new Promise(function (resolve, reject) {
    _this2[kStream].destroy(null, function (err) {
      if (err) {
        reject(err);
        return;
      }

      resolve(createIterResult(undefined, true));
    });
  });
}), _Object$setPrototypeO), AsyncIteratorPrototype);

var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
  var _Object$create;

  var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
    value: stream,
    writable: true
  }), _defineProperty(_Object$create, kLastResolve, {
    value: null,
    writable: true
  }), _defineProperty(_Object$create, kLastReject, {
    value: null,
    writable: true
  }), _defineProperty(_Object$create, kError, {
    value: null,
    writable: true
  }), _defineProperty(_Object$create, kEnded, {
    value: stream._readableState.endEmitted,
    writable: true
  }), _defineProperty(_Object$create, kHandlePromise, {
    value: function value(resolve, reject) {
      var data = iterator[kStream].read();

      if (data) {
        iterator[kLastPromise] = null;
        iterator[kLastResolve] = null;
        iterator[kLastReject] = null;
        resolve(createIterResult(data, false));
      } else {
        iterator[kLastResolve] = resolve;
        iterator[kLastReject] = reject;
      }
    },
    writable: true
  }), _Object$create));
  iterator[kLastPromise] = null;
  finished(stream, function (err) {
    if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
      var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
      // returned by next() and store the error

      if (reject !== null) {
        iterator[kLastPromise] = null;
        iterator[kLastResolve] = null;
        iterator[kLastReject] = null;
        reject(err);
      }

      iterator[kError] = err;
      return;
    }

    var resolve = iterator[kLastResolve];

    if (resolve !== null) {
      iterator[kLastPromise] = null;
      iterator[kLastResolve] = null;
      iterator[kLastReject] = null;
      resolve(createIterResult(undefined, true));
    }

    iterator[kEnded] = true;
  });
  stream.on('readable', onReadable.bind(null, iterator));
  return iterator;
};

module.exports = createReadableStreamAsyncIterator;

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/buffer_list.js":
/*!*********************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/buffer_list.js ***!
  \*********************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

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 _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; }

var _require = __webpack_require__(/*! buffer */ "./node_modules/buffer/index.js"),
    Buffer = _require.Buffer;

var _require2 = __webpack_require__(/*! util */ "?3e83"),
    inspect = _require2.inspect;

var custom = inspect && inspect.custom || 'inspect';

function copyBuffer(src, target, offset) {
  Buffer.prototype.copy.call(src, target, offset);
}

module.exports =
/*#__PURE__*/
function () {
  function BufferList() {
    _classCallCheck(this, BufferList);

    this.head = null;
    this.tail = null;
    this.length = 0;
  }

  _createClass(BufferList, [{
    key: "push",
    value: 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;
    }
  }, {
    key: "unshift",
    value: function unshift(v) {
      var entry = {
        data: v,
        next: this.head
      };
      if (this.length === 0) this.tail = entry;
      this.head = entry;
      ++this.length;
    }
  }, {
    key: "shift",
    value: 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;
    }
  }, {
    key: "clear",
    value: function clear() {
      this.head = this.tail = null;
      this.length = 0;
    }
  }, {
    key: "join",
    value: 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;
    }
  }, {
    key: "concat",
    value: function concat(n) {
      if (this.length === 0) return Buffer.alloc(0);
      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;
    } // Consumes a specified amount of bytes or characters from the buffered data.

  }, {
    key: "consume",
    value: function consume(n, hasStrings) {
      var ret;

      if (n < this.head.data.length) {
        // `slice` is the same for buffers and strings.
        ret = this.head.data.slice(0, n);
        this.head.data = this.head.data.slice(n);
      } else if (n === this.head.data.length) {
        // First chunk is a perfect match.
        ret = this.shift();
      } else {
        // Result spans more than one buffer.
        ret = hasStrings ? this._getString(n) : this._getBuffer(n);
      }

      return ret;
    }
  }, {
    key: "first",
    value: function first() {
      return this.head.data;
    } // Consumes a specified amount of characters from the buffered data.

  }, {
    key: "_getString",
    value: function _getString(n) {
      var p = this.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) this.head = p.next;else this.head = this.tail = null;
          } else {
            this.head = p;
            p.data = str.slice(nb);
          }

          break;
        }

        ++c;
      }

      this.length -= c;
      return ret;
    } // Consumes a specified amount of bytes from the buffered data.

  }, {
    key: "_getBuffer",
    value: function _getBuffer(n) {
      var ret = Buffer.allocUnsafe(n);
      var p = this.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) this.head = p.next;else this.head = this.tail = null;
          } else {
            this.head = p;
            p.data = buf.slice(nb);
          }

          break;
        }

        ++c;
      }

      this.length -= c;
      return ret;
    } // Make sure the linked list only shows the minimal necessary information.

  }, {
    key: custom,
    value: function value(_, options) {
      return inspect(this, _objectSpread({}, options, {
        // Only inspect one level.
        depth: 0,
        // It should not recurse.
        customInspect: false
      }));
    }
  }]);

  return BufferList;
}();

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/destroy.js":
/*!*****************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/destroy.js ***!
  \*****************************************************************************************************/
/***/ (function(module) {

"use strict";
 // 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) {
      if (!this._writableState) {
        process.nextTick(emitErrorNT, this, err);
      } else if (!this._writableState.errorEmitted) {
        this._writableState.errorEmitted = true;
        process.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) {
      if (!_this._writableState) {
        process.nextTick(emitErrorAndCloseNT, _this, err);
      } else if (!_this._writableState.errorEmitted) {
        _this._writableState.errorEmitted = true;
        process.nextTick(emitErrorAndCloseNT, _this, err);
      } else {
        process.nextTick(emitCloseNT, _this);
      }
    } else if (cb) {
      process.nextTick(emitCloseNT, _this);
      cb(err);
    } else {
      process.nextTick(emitCloseNT, _this);
    }
  });

  return this;
}

function emitErrorAndCloseNT(self, err) {
  emitErrorNT(self, err);
  emitCloseNT(self);
}

function emitCloseNT(self) {
  if (self._writableState && !self._writableState.emitClose) return;
  if (self._readableState && !self._readableState.emitClose) return;
  self.emit('close');
}

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.finalCalled = false;
    this._writableState.prefinished = false;
    this._writableState.finished = false;
    this._writableState.errorEmitted = false;
  }
}

function emitErrorNT(self, err) {
  self.emit('error', err);
}

function errorOrDestroy(stream, err) {
  // We have tests that rely on errors being emitted
  // in the same tick, so changing this is semver major.
  // For now when you opt-in to autoDestroy we allow
  // the error to be emitted nextTick. In a future
  // semver major update we should change the default to this.
  var rState = stream._readableState;
  var wState = stream._writableState;
  if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
}

module.exports = {
  destroy: destroy,
  undestroy: undestroy,
  errorOrDestroy: errorOrDestroy
};

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js":
/*!***********************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js ***!
  \***********************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// Ported from https://github.com/mafintosh/end-of-stream with
// permission from the author, Mathias Buus (@mafintosh).


var ERR_STREAM_PREMATURE_CLOSE = (__webpack_require__(/*! ../../../errors */ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js").codes.ERR_STREAM_PREMATURE_CLOSE);

function once(callback) {
  var called = false;
  return function () {
    if (called) return;
    called = true;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    callback.apply(this, args);
  };
}

function noop() {}

function isRequest(stream) {
  return stream.setHeader && typeof stream.abort === 'function';
}

function eos(stream, opts, callback) {
  if (typeof opts === 'function') return eos(stream, null, opts);
  if (!opts) opts = {};
  callback = once(callback || noop);
  var readable = opts.readable || opts.readable !== false && stream.readable;
  var writable = opts.writable || opts.writable !== false && stream.writable;

  var onlegacyfinish = function onlegacyfinish() {
    if (!stream.writable) onfinish();
  };

  var writableEnded = stream._writableState && stream._writableState.finished;

  var onfinish = function onfinish() {
    writable = false;
    writableEnded = true;
    if (!readable) callback.call(stream);
  };

  var readableEnded = stream._readableState && stream._readableState.endEmitted;

  var onend = function onend() {
    readable = false;
    readableEnded = true;
    if (!writable) callback.call(stream);
  };

  var onerror = function onerror(err) {
    callback.call(stream, err);
  };

  var onclose = function onclose() {
    var err;

    if (readable && !readableEnded) {
      if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
      return callback.call(stream, err);
    }

    if (writable && !writableEnded) {
      if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
      return callback.call(stream, err);
    }
  };

  var onrequest = function onrequest() {
    stream.req.on('finish', onfinish);
  };

  if (isRequest(stream)) {
    stream.on('complete', onfinish);
    stream.on('abort', onclose);
    if (stream.req) onrequest();else stream.on('request', onrequest);
  } else if (writable && !stream._writableState) {
    // legacy streams
    stream.on('end', onlegacyfinish);
    stream.on('close', onlegacyfinish);
  }

  stream.on('end', onend);
  stream.on('finish', onfinish);
  if (opts.error !== false) stream.on('error', onerror);
  stream.on('close', onclose);
  return function () {
    stream.removeListener('complete', onfinish);
    stream.removeListener('abort', onclose);
    stream.removeListener('request', onrequest);
    if (stream.req) stream.req.removeListener('finish', onfinish);
    stream.removeListener('end', onlegacyfinish);
    stream.removeListener('close', onlegacyfinish);
    stream.removeListener('finish', onfinish);
    stream.removeListener('end', onend);
    stream.removeListener('error', onerror);
    stream.removeListener('close', onclose);
  };
}

module.exports = eos;

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from-browser.js":
/*!**********************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from-browser.js ***!
  \**********************************************************************************************************/
/***/ (function(module) {

module.exports = function () {
  throw new Error('Readable.from is not available in the browser')
};


/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/pipeline.js":
/*!******************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/pipeline.js ***!
  \******************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";
// Ported from https://github.com/mafintosh/pump with
// permission from the author, Mathias Buus (@mafintosh).


var eos;

function once(callback) {
  var called = false;
  return function () {
    if (called) return;
    called = true;
    callback.apply(void 0, arguments);
  };
}

var _require$codes = (__webpack_require__(/*! ../../../errors */ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js").codes),
    ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
    ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;

function noop(err) {
  // Rethrow the error if it exists to avoid swallowing it
  if (err) throw err;
}

function isRequest(stream) {
  return stream.setHeader && typeof stream.abort === 'function';
}

function destroyer(stream, reading, writing, callback) {
  callback = once(callback);
  var closed = false;
  stream.on('close', function () {
    closed = true;
  });
  if (eos === undefined) eos = __webpack_require__(/*! ./end-of-stream */ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js");
  eos(stream, {
    readable: reading,
    writable: writing
  }, function (err) {
    if (err) return callback(err);
    closed = true;
    callback();
  });
  var destroyed = false;
  return function (err) {
    if (closed) return;
    if (destroyed) return;
    destroyed = true; // request.destroy just do .end - .abort is what we want

    if (isRequest(stream)) return stream.abort();
    if (typeof stream.destroy === 'function') return stream.destroy();
    callback(err || new ERR_STREAM_DESTROYED('pipe'));
  };
}

function call(fn) {
  fn();
}

function pipe(from, to) {
  return from.pipe(to);
}

function popCallback(streams) {
  if (!streams.length) return noop;
  if (typeof streams[streams.length - 1] !== 'function') return noop;
  return streams.pop();
}

function pipeline() {
  for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
    streams[_key] = arguments[_key];
  }

  var callback = popCallback(streams);
  if (Array.isArray(streams[0])) streams = streams[0];

  if (streams.length < 2) {
    throw new ERR_MISSING_ARGS('streams');
  }

  var error;
  var destroys = streams.map(function (stream, i) {
    var reading = i < streams.length - 1;
    var writing = i > 0;
    return destroyer(stream, reading, writing, function (err) {
      if (!error) error = err;
      if (err) destroys.forEach(call);
      if (reading) return;
      destroys.forEach(call);
      callback(error);
    });
  });
  return streams.reduce(pipe);
}

module.exports = pipeline;

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/state.js":
/*!***************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/state.js ***!
  \***************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

"use strict";


var ERR_INVALID_OPT_VALUE = (__webpack_require__(/*! ../../../errors */ "./node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js").codes.ERR_INVALID_OPT_VALUE);

function highWaterMarkFrom(options, isDuplex, duplexKey) {
  return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
}

function getHighWaterMark(state, options, duplexKey, isDuplex) {
  var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);

  if (hwm != null) {
    if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
      var name = isDuplex ? duplexKey : 'highWaterMark';
      throw new ERR_INVALID_OPT_VALUE(name, hwm);
    }

    return Math.floor(hwm);
  } // Default value


  return state.objectMode ? 16 : 16 * 1024;
}

module.exports = {
  getHighWaterMark: getHighWaterMark
};

/***/ }),

/***/ "./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream-browser.js":
/*!************************************************************************************************************!*\
  !*** ./node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream-browser.js ***!
  \************************************************************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

module.exports = __webpack_require__(/*! events */ "./node_modules/events/events.js").EventEmitter;


/***/ }),

/***/ "./node_modules/string_decoder/lib/string_decoder.js":
/*!***********************************************************!*\
  !*** ./node_modules/string_decoder/lib/string_decoder.js ***!
  \***********************************************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

"use strict";
// 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/ua-parser-js/src/ua-parser.js":
/*!****************************************************!*\
  !*** ./node_modules/ua-parser-js/src/ua-parser.js ***!
  \****************************************************/
/***/ (function(module, exports, __webpack_require__) {

var __WEBPACK_AMD_DEFINE_RESULT__;/////////////////////////////////////////////////////////////////////////////////
/* UAParser.js v1.0.2
   Copyright © 2012-2021 Faisal Salman <f@faisalman.com>
   MIT License *//*
   Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
   Supports browser & node.js environment. 
   Demo   : https://faisalman.github.io/ua-parser-js
   Source : https://github.com/faisalman/ua-parser-js */
/////////////////////////////////////////////////////////////////////////////////

(function (window, undefined) {

    'use strict';

    //////////////
    // Constants
    /////////////


    var LIBVERSION  = '1.0.2',
        EMPTY       = '',
        UNKNOWN     = '?',
        FUNC_TYPE   = 'function',
        UNDEF_TYPE  = 'undefined',
        OBJ_TYPE    = 'object',
        STR_TYPE    = 'string',
        MAJOR       = 'major',
        MODEL       = 'model',
        NAME        = 'name',
        TYPE        = 'type',
        VENDOR      = 'vendor',
        VERSION     = 'version',
        ARCHITECTURE= 'architecture',
        CONSOLE     = 'console',
        MOBILE      = 'mobile',
        TABLET      = 'tablet',
        SMARTTV     = 'smarttv',
        WEARABLE    = 'wearable',
        EMBEDDED    = 'embedded',
        UA_MAX_LENGTH = 255;

    var AMAZON  = 'Amazon',
        APPLE   = 'Apple',
        ASUS    = 'ASUS',
        BLACKBERRY = 'BlackBerry',
        BROWSER = 'Browser',
        CHROME  = 'Chrome',
        EDGE    = 'Edge',
        FIREFOX = 'Firefox',
        GOOGLE  = 'Google',
        HUAWEI  = 'Huawei',
        LG      = 'LG',
        MICROSOFT = 'Microsoft',
        MOTOROLA  = 'Motorola',
        OPERA   = 'Opera',
        SAMSUNG = 'Samsung',
        SONY    = 'Sony',
        XIAOMI  = 'Xiaomi',
        ZEBRA   = 'Zebra',
        FACEBOOK   = 'Facebook';

    ///////////
    // Helper
    //////////

    var extend = function (regexes, extensions) {
            var mergedRegexes = {};
            for (var i in regexes) {
                if (extensions[i] && extensions[i].length % 2 === 0) {
                    mergedRegexes[i] = extensions[i].concat(regexes[i]);
                } else {
                    mergedRegexes[i] = regexes[i];
                }
            }
            return mergedRegexes;
        },
        enumerize = function (arr) {
            var enums = {};
            for (var i=0; i<arr.length; i++) {
                enums[arr[i].toUpperCase()] = arr[i];
            }
            return enums;
        },
        has = function (str1, str2) {
            return typeof str1 === STR_TYPE ? lowerize(str2).indexOf(lowerize(str1)) !== -1 : false;
        },
        lowerize = function (str) {
            return str.toLowerCase();
        },
        majorize = function (version) {
            return typeof(version) === STR_TYPE ? version.replace(/[^\d\.]/g, EMPTY).split('.')[0] : undefined;
        },
        trim = function (str, len) {
            if (typeof(str) === STR_TYPE) {
                str = str.replace(/^\s\s*/, EMPTY).replace(/\s\s*$/, EMPTY);
                return typeof(len) === UNDEF_TYPE ? str : str.substring(0, UA_MAX_LENGTH);
            }
    };

    ///////////////
    // Map helper
    //////////////

    var rgxMapper = function (ua, arrays) {

            var i = 0, j, k, p, q, matches, match;

            // loop through all regexes maps
            while (i < arrays.length && !matches) {

                var regex = arrays[i],       // even sequence (0,2,4,..)
                    props = arrays[i + 1];   // odd sequence (1,3,5,..)
                j = k = 0;

                // try matching uastring with regexes
                while (j < regex.length && !matches) {

                    matches = regex[j++].exec(ua);

                    if (!!matches) {
                        for (p = 0; p < props.length; p++) {
                            match = matches[++k];
                            q = props[p];
                            // check if given property is actually array
                            if (typeof q === OBJ_TYPE && q.length > 0) {
                                if (q.length === 2) {
                                    if (typeof q[1] == FUNC_TYPE) {
                                        // assign modified match
                                        this[q[0]] = q[1].call(this, match);
                                    } else {
                                        // assign given value, ignore regex match
                                        this[q[0]] = q[1];
                                    }
                                } else if (q.length === 3) {
                                    // check whether function or regex
                                    if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
                                        // call function (usually string mapper)
                                        this[q[0]] = match ? q[1].call(this, match, q[2]) : undefined;
                                    } else {
                                        // sanitize match using given regex
                                        this[q[0]] = match ? match.replace(q[1], q[2]) : undefined;
                                    }
                                } else if (q.length === 4) {
                                        this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined;
                                }
                            } else {
                                this[q] = match ? match : undefined;
                            }
                        }
                    }
                }
                i += 2;
            }
        },

        strMapper = function (str, map) {

            for (var i in map) {
                // check if current value is array
                if (typeof map[i] === OBJ_TYPE && map[i].length > 0) {
                    for (var j = 0; j < map[i].length; j++) {
                        if (has(map[i][j], str)) {
                            return (i === UNKNOWN) ? undefined : i;
                        }
                    }
                } else if (has(map[i], str)) {
                    return (i === UNKNOWN) ? undefined : i;
                }
            }
            return str;
    };

    ///////////////
    // String map
    //////////////

    // Safari < 3.0
    var oldSafariMap = {
            '1.0'   : '/8',
            '1.2'   : '/1',
            '1.3'   : '/3',
            '2.0'   : '/412',
            '2.0.2' : '/416',
            '2.0.3' : '/417',
            '2.0.4' : '/419',
            '?'     : '/'
        },
        windowsVersionMap = {
            'ME'        : '4.90',
            'NT 3.11'   : 'NT3.51',
            'NT 4.0'    : 'NT4.0',
            '2000'      : 'NT 5.0',
            'XP'        : ['NT 5.1', 'NT 5.2'],
            'Vista'     : 'NT 6.0',
            '7'         : 'NT 6.1',
            '8'         : 'NT 6.2',
            '8.1'       : 'NT 6.3',
            '10'        : ['NT 6.4', 'NT 10.0'],
            'RT'        : 'ARM'
    };

    //////////////
    // Regex map
    /////////////

    var regexes = {

        browser : [[

            /\b(?:crmo|crios)\/([\w\.]+)/i                                      // Chrome for Android/iOS
            ], [VERSION, [NAME, 'Chrome']], [
            /edg(?:e|ios|a)?\/([\w\.]+)/i                                       // Microsoft Edge
            ], [VERSION, [NAME, 'Edge']], [

            // Presto based
            /(opera mini)\/([-\w\.]+)/i,                                        // Opera Mini
            /(opera [mobiletab]{3,6})\b.+version\/([-\w\.]+)/i,                 // Opera Mobi/Tablet
            /(opera)(?:.+version\/|[\/ ]+)([\w\.]+)/i                           // Opera
            ], [NAME, VERSION], [
            /opios[\/ ]+([\w\.]+)/i                                             // Opera mini on iphone >= 8.0
            ], [VERSION, [NAME, OPERA+' Mini']], [
            /\bopr\/([\w\.]+)/i                                                 // Opera Webkit
            ], [VERSION, [NAME, OPERA]], [

            // Mixed
            /(kindle)\/([\w\.]+)/i,                                             // Kindle
            /(lunascape|maxthon|netfront|jasmine|blazer)[\/ ]?([\w\.]*)/i,      // Lunascape/Maxthon/Netfront/Jasmine/Blazer
            // Trident based
            /(avant |iemobile|slim)(?:browser)?[\/ ]?([\w\.]*)/i,               // Avant/IEMobile/SlimBrowser
            /(ba?idubrowser)[\/ ]?([\w\.]+)/i,                                  // Baidu Browser
            /(?:ms|\()(ie) ([\w\.]+)/i,                                         // Internet Explorer

            // Webkit/KHTML based                                               // Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium/PhantomJS/Bowser/QupZilla/Falkon
            /(flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs|bowser|quark|qupzilla|falkon|rekonq|puffin|brave|whale|qqbrowserlite|qq)\/([-\w\.]+)/i,
                                                                                // Rekonq/Puffin/Brave/Whale/QQBrowserLite/QQ, aka ShouQ
            /(weibo)__([\d\.]+)/i                                               // Weibo
            ], [NAME, VERSION], [
            /(?:\buc? ?browser|(?:juc.+)ucweb)[\/ ]?([\w\.]+)/i                 // UCBrowser
            ], [VERSION, [NAME, 'UC'+BROWSER]], [
            /\bqbcore\/([\w\.]+)/i                                              // WeChat Desktop for Windows Built-in Browser
            ], [VERSION, [NAME, 'WeChat(Win) Desktop']], [
            /micromessenger\/([\w\.]+)/i                                        // WeChat
            ], [VERSION, [NAME, 'WeChat']], [
            /konqueror\/([\w\.]+)/i                                             // Konqueror
            ], [VERSION, [NAME, 'Konqueror']], [
            /trident.+rv[: ]([\w\.]{1,9})\b.+like gecko/i                       // IE11
            ], [VERSION, [NAME, 'IE']], [
            /yabrowser\/([\w\.]+)/i                                             // Yandex
            ], [VERSION, [NAME, 'Yandex']], [
            /(avast|avg)\/([\w\.]+)/i                                           // Avast/AVG Secure Browser
            ], [[NAME, /(.+)/, '$1 Secure '+BROWSER], VERSION], [
            /\bfocus\/([\w\.]+)/i                                               // Firefox Focus
            ], [VERSION, [NAME, FIREFOX+' Focus']], [
            /\bopt\/([\w\.]+)/i                                                 // Opera Touch
            ], [VERSION, [NAME, OPERA+' Touch']], [
            /coc_coc\w+\/([\w\.]+)/i                                            // Coc Coc Browser
            ], [VERSION, [NAME, 'Coc Coc']], [
            /dolfin\/([\w\.]+)/i                                                // Dolphin
            ], [VERSION, [NAME, 'Dolphin']], [
            /coast\/([\w\.]+)/i                                                 // Opera Coast
            ], [VERSION, [NAME, OPERA+' Coast']], [
            /miuibrowser\/([\w\.]+)/i                                           // MIUI Browser
            ], [VERSION, [NAME, 'MIUI '+BROWSER]], [
            /fxios\/([-\w\.]+)/i                                                // Firefox for iOS
            ], [VERSION, [NAME, FIREFOX]], [
            /\bqihu|(qi?ho?o?|360)browser/i                                     // 360
            ], [[NAME, '360 '+BROWSER]], [
            /(oculus|samsung|sailfish)browser\/([\w\.]+)/i
            ], [[NAME, /(.+)/, '$1 '+BROWSER], VERSION], [                      // Oculus/Samsung/Sailfish Browser
            /(comodo_dragon)\/([\w\.]+)/i                                       // Comodo Dragon
            ], [[NAME, /_/g, ' '], VERSION], [
            /(electron)\/([\w\.]+) safari/i,                                    // Electron-based App
            /(tesla)(?: qtcarbrowser|\/(20\d\d\.[-\w\.]+))/i,                   // Tesla
            /m?(qqbrowser|baiduboxapp|2345Explorer)[\/ ]?([\w\.]+)/i            // QQBrowser/Baidu App/2345 Browser
            ], [NAME, VERSION], [
            /(metasr)[\/ ]?([\w\.]+)/i,                                         // SouGouBrowser
            /(lbbrowser)/i                                                      // LieBao Browser
            ], [NAME], [

            // WebView
            /((?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/([\w\.]+);)/i       // Facebook App for iOS & Android
            ], [[NAME, FACEBOOK], VERSION], [
            /safari (line)\/([\w\.]+)/i,                                        // Line App for iOS
            /\b(line)\/([\w\.]+)\/iab/i,                                        // Line App for Android
            /(chromium|instagram)[\/ ]([-\w\.]+)/i                              // Chromium/Instagram
            ], [NAME, VERSION], [
            /\bgsa\/([\w\.]+) .*safari\//i                                      // Google Search Appliance on iOS
            ], [VERSION, [NAME, 'GSA']], [

            /headlesschrome(?:\/([\w\.]+)| )/i                                  // Chrome Headless
            ], [VERSION, [NAME, CHROME+' Headless']], [

            / wv\).+(chrome)\/([\w\.]+)/i                                       // Chrome WebView
            ], [[NAME, CHROME+' WebView'], VERSION], [

            /droid.+ version\/([\w\.]+)\b.+(?:mobile safari|safari)/i           // Android Browser
            ], [VERSION, [NAME, 'Android '+BROWSER]], [

            /(chrome|omniweb|arora|[tizenoka]{5} ?browser)\/v?([\w\.]+)/i       // Chrome/OmniWeb/Arora/Tizen/Nokia
            ], [NAME, VERSION], [

            /version\/([\w\.]+) .*mobile\/\w+ (safari)/i                        // Mobile Safari
            ], [VERSION, [NAME, 'Mobile Safari']], [
            /version\/([\w\.]+) .*(mobile ?safari|safari)/i                     // Safari & Safari Mobile
            ], [VERSION, NAME], [
            /webkit.+?(mobile ?safari|safari)(\/[\w\.]+)/i                      // Safari < 3.0
            ], [NAME, [VERSION, strMapper, oldSafariMap]], [

            /(webkit|khtml)\/([\w\.]+)/i
            ], [NAME, VERSION], [

            // Gecko based
            /(navigator|netscape\d?)\/([-\w\.]+)/i                              // Netscape
            ], [[NAME, 'Netscape'], VERSION], [
            /mobile vr; rv:([\w\.]+)\).+firefox/i                               // Firefox Reality
            ], [VERSION, [NAME, FIREFOX+' Reality']], [
            /ekiohf.+(flow)\/([\w\.]+)/i,                                       // Flow
            /(swiftfox)/i,                                                      // Swiftfox
            /(icedragon|iceweasel|camino|chimera|fennec|maemo browser|minimo|conkeror|klar)[\/ ]?([\w\.\+]+)/i,
                                                                                // IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror/Klar
            /(seamonkey|k-meleon|icecat|iceape|firebird|phoenix|palemoon|basilisk|waterfox)\/([-\w\.]+)$/i,
                                                                                // Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
            /(firefox)\/([\w\.]+)/i,                                            // Other Firefox-based
            /(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i,                         // Mozilla

            // Other
            /(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,
                                                                                // Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Sleipnir/Obigo/Mosaic/Go/ICE/UP.Browser
            /(links) \(([\w\.]+)/i                                              // Links
            ], [NAME, VERSION]
        ],

        cpu : [[

            /(?:(amd|x(?:(?:86|64)[-_])?|wow|win)64)[;\)]/i                     // AMD64 (x64)
            ], [[ARCHITECTURE, 'amd64']], [

            /(ia32(?=;))/i                                                      // IA32 (quicktime)
            ], [[ARCHITECTURE, lowerize]], [

            /((?:i[346]|x)86)[;\)]/i                                            // IA32 (x86)
            ], [[ARCHITECTURE, 'ia32']], [

            /\b(aarch64|arm(v?8e?l?|_?64))\b/i                                 // ARM64
            ], [[ARCHITECTURE, 'arm64']], [

            /\b(arm(?:v[67])?ht?n?[fl]p?)\b/i                                   // ARMHF
            ], [[ARCHITECTURE, 'armhf']], [

            // PocketPC mistakenly identified as PowerPC
            /windows (ce|mobile); ppc;/i
            ], [[ARCHITECTURE, 'arm']], [

            /((?:ppc|powerpc)(?:64)?)(?: mac|;|\))/i                            // PowerPC
            ], [[ARCHITECTURE, /ower/, EMPTY, lowerize]], [

            /(sun4\w)[;\)]/i                                                    // SPARC
            ], [[ARCHITECTURE, 'sparc']], [

            /((?:avr32|ia64(?=;))|68k(?=\))|\barm(?=v(?:[1-7]|[5-7]1)l?|;|eabi)|(?=atmel )avr|(?:irix|mips|sparc)(?:64)?\b|pa-risc)/i
                                                                                // IA64, 68K, ARM/64, AVR/32, IRIX/64, MIPS/64, SPARC/64, PA-RISC
            ], [[ARCHITECTURE, lowerize]]
        ],

        device : [[

            //////////////////////////
            // MOBILES & TABLETS
            // Ordered by popularity
            /////////////////////////

            // Samsung
            /\b(sch-i[89]0\d|shw-m380s|sm-[pt]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i
            ], [MODEL, [VENDOR, SAMSUNG], [TYPE, TABLET]], [
            /\b((?:s[cgp]h|gt|sm)-\w+|galaxy nexus)/i,
            /samsung[- ]([-\w]+)/i,
            /sec-(sgh\w+)/i
            ], [MODEL, [VENDOR, SAMSUNG], [TYPE, MOBILE]], [

            // Apple
            /\((ip(?:hone|od)[\w ]*);/i                                         // iPod/iPhone
            ], [MODEL, [VENDOR, APPLE], [TYPE, MOBILE]], [
            /\((ipad);[-\w\),; ]+apple/i,                                       // iPad
            /applecoremedia\/[\w\.]+ \((ipad)/i,
            /\b(ipad)\d\d?,\d\d?[;\]].+ios/i
            ], [MODEL, [VENDOR, APPLE], [TYPE, TABLET]], [

            // Huawei
            /\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i
            ], [MODEL, [VENDOR, HUAWEI], [TYPE, TABLET]], [
            /(?:huawei|honor)([-\w ]+)[;\)]/i,
            /\b(nexus 6p|\w{2,4}-[atu]?[ln][01259x][012359][an]?)\b(?!.+d\/s)/i
            ], [MODEL, [VENDOR, HUAWEI], [TYPE, MOBILE]], [

            // Xiaomi
            /\b(poco[\w ]+)(?: bui|\))/i,                                       // Xiaomi POCO
            /\b; (\w+) build\/hm\1/i,                                           // Xiaomi Hongmi 'numeric' models
            /\b(hm[-_ ]?note?[_ ]?(?:\d\w)?) bui/i,                             // Xiaomi Hongmi
            /\b(redmi[\-_ ]?(?:note|k)?[\w_ ]+)(?: bui|\))/i,                   // Xiaomi Redmi
            /\b(mi[-_ ]?(?:a\d|one|one[_ ]plus|note lte|max)?[_ ]?(?:\d?\w?)[_ ]?(?:plus|se|lite)?)(?: bui|\))/i // Xiaomi Mi
            ], [[MODEL, /_/g, ' '], [VENDOR, XIAOMI], [TYPE, MOBILE]], [
            /\b(mi[-_ ]?(?:pad)(?:[\w_ ]+))(?: bui|\))/i                        // Mi Pad tablets
            ],[[MODEL, /_/g, ' '], [VENDOR, XIAOMI], [TYPE, TABLET]], [

            // OPPO
            /; (\w+) bui.+ oppo/i,
            /\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i
            ], [MODEL, [VENDOR, 'OPPO'], [TYPE, MOBILE]], [

            // Vivo
            /vivo (\w+)(?: bui|\))/i,
            /\b(v[12]\d{3}\w?[at])(?: bui|;)/i
            ], [MODEL, [VENDOR, 'Vivo'], [TYPE, MOBILE]], [

            // Realme
            /\b(rmx[12]\d{3})(?: bui|;|\))/i
            ], [MODEL, [VENDOR, 'Realme'], [TYPE, MOBILE]], [

            // Motorola
            /\b(milestone|droid(?:[2-4x]| (?:bionic|x2|pro|razr))?:?( 4g)?)\b[\w ]+build\//i,
            /\bmot(?:orola)?[- ](\w*)/i,
            /((?:moto[\w\(\) ]+|xt\d{3,4}|nexus 6)(?= bui|\)))/i
            ], [MODEL, [VENDOR, MOTOROLA], [TYPE, MOBILE]], [
            /\b(mz60\d|xoom[2 ]{0,2}) build\//i
            ], [MODEL, [VENDOR, MOTOROLA], [TYPE, TABLET]], [

            // LG
            /((?=lg)?[vl]k\-?\d{3}) bui| 3\.[-\w; ]{10}lg?-([06cv9]{3,4})/i
            ], [MODEL, [VENDOR, LG], [TYPE, TABLET]], [
            /(lm(?:-?f100[nv]?|-[\w\.]+)(?= bui|\))|nexus [45])/i,
            /\blg[-e;\/ ]+((?!browser|netcast|android tv)\w+)/i,
            /\blg-?([\d\w]+) bui/i
            ], [MODEL, [VENDOR, LG], [TYPE, MOBILE]], [

            // Lenovo
            /(ideatab[-\w ]+)/i,
            /lenovo ?(s[56]000[-\w]+|tab(?:[\w ]+)|yt[-\d\w]{6}|tb[-\d\w]{6})/i
            ], [MODEL, [VENDOR, 'Lenovo'], [TYPE, TABLET]], [

            // Nokia
            /(?:maemo|nokia).*(n900|lumia \d+)/i,
            /nokia[-_ ]?([-\w\.]*)/i
            ], [[MODEL, /_/g, ' '], [VENDOR, 'Nokia'], [TYPE, MOBILE]], [

            // Google
            /(pixel c)\b/i                                                      // Google Pixel C
            ], [MODEL, [VENDOR, GOOGLE], [TYPE, TABLET]], [
            /droid.+; (pixel[\daxl ]{0,6})(?: bui|\))/i                         // Google Pixel
            ], [MODEL, [VENDOR, GOOGLE], [TYPE, MOBILE]], [

            // Sony
            /droid.+ ([c-g]\d{4}|so[-gl]\w+|xq-a\w[4-7][12])(?= bui|\).+chrome\/(?![1-6]{0,1}\d\.))/i
            ], [MODEL, [VENDOR, SONY], [TYPE, MOBILE]], [
            /sony tablet [ps]/i,
            /\b(?:sony)?sgp\w+(?: bui|\))/i
            ], [[MODEL, 'Xperia Tablet'], [VENDOR, SONY], [TYPE, TABLET]], [

            // OnePlus
            / (kb2005|in20[12]5|be20[12][59])\b/i,
            /(?:one)?(?:plus)? (a\d0\d\d)(?: b|\))/i
            ], [MODEL, [VENDOR, 'OnePlus'], [TYPE, MOBILE]], [

            // Amazon
            /(alexa)webm/i,
            /(kf[a-z]{2}wi)( bui|\))/i,                                         // Kindle Fire without Silk
            /(kf[a-z]+)( bui|\)).+silk\//i                                      // Kindle Fire HD
            ], [MODEL, [VENDOR, AMAZON], [TYPE, TABLET]], [
            /((?:sd|kf)[0349hijorstuw]+)( bui|\)).+silk\//i                     // Fire Phone
            ], [[MODEL, /(.+)/g, 'Fire Phone $1'], [VENDOR, AMAZON], [TYPE, MOBILE]], [

            // BlackBerry
            /(playbook);[-\w\),; ]+(rim)/i                                      // BlackBerry PlayBook
            ], [MODEL, VENDOR, [TYPE, TABLET]], [
            /\b((?:bb[a-f]|st[hv])100-\d)/i,
            /\(bb10; (\w+)/i                                                    // BlackBerry 10
            ], [MODEL, [VENDOR, BLACKBERRY], [TYPE, MOBILE]], [

            // Asus
            /(?:\b|asus_)(transfo[prime ]{4,10} \w+|eeepc|slider \w+|nexus 7|padfone|p00[cj])/i
            ], [MODEL, [VENDOR, ASUS], [TYPE, TABLET]], [
            / (z[bes]6[027][012][km][ls]|zenfone \d\w?)\b/i
            ], [MODEL, [VENDOR, ASUS], [TYPE, MOBILE]], [

            // HTC
            /(nexus 9)/i                                                        // HTC Nexus 9
            ], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
            /(htc)[-;_ ]{1,2}([\w ]+(?=\)| bui)|\w+)/i,                         // HTC

            // ZTE
            /(zte)[- ]([\w ]+?)(?: bui|\/|\))/i,
            /(alcatel|geeksphone|nexian|panasonic|sony)[-_ ]?([-\w]*)/i         // Alcatel/GeeksPhone/Nexian/Panasonic/Sony
            ], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [

            // Acer
            /droid.+; ([ab][1-7]-?[0178a]\d\d?)/i
            ], [MODEL, [VENDOR, 'Acer'], [TYPE, TABLET]], [

            // Meizu
            /droid.+; (m[1-5] note) bui/i,
            /\bmz-([-\w]{2,})/i
            ], [MODEL, [VENDOR, 'Meizu'], [TYPE, MOBILE]], [

            // Sharp
            /\b(sh-?[altvz]?\d\d[a-ekm]?)/i
            ], [MODEL, [VENDOR, 'Sharp'], [TYPE, MOBILE]], [

            // MIXED
            /(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|meizu|motorola|polytron)[-_ ]?([-\w]*)/i,
                                                                                // BlackBerry/BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Meizu/Motorola/Polytron
            /(hp) ([\w ]+\w)/i,                                                 // HP iPAQ
            /(asus)-?(\w+)/i,                                                   // Asus
            /(microsoft); (lumia[\w ]+)/i,                                      // Microsoft Lumia
            /(lenovo)[-_ ]?([-\w]+)/i,                                          // Lenovo
            /(jolla)/i,                                                         // Jolla
            /(oppo) ?([\w ]+) bui/i                                             // OPPO
            ], [VENDOR, MODEL, [TYPE, MOBILE]], [

            /(archos) (gamepad2?)/i,                                            // Archos
            /(hp).+(touchpad(?!.+tablet)|tablet)/i,                             // HP TouchPad
            /(kindle)\/([\w\.]+)/i,                                             // Kindle
            /(nook)[\w ]+build\/(\w+)/i,                                        // Nook
            /(dell) (strea[kpr\d ]*[\dko])/i,                                   // Dell Streak
            /(le[- ]+pan)[- ]+(\w{1,9}) bui/i,                                  // Le Pan Tablets
            /(trinity)[- ]*(t\d{3}) bui/i,                                      // Trinity Tablets
            /(gigaset)[- ]+(q\w{1,9}) bui/i,                                    // Gigaset Tablets
            /(vodafone) ([\w ]+)(?:\)| bui)/i                                   // Vodafone
            ], [VENDOR, MODEL, [TYPE, TABLET]], [

            /(surface duo)/i                                                    // Surface Duo
            ], [MODEL, [VENDOR, MICROSOFT], [TYPE, TABLET]], [
            /droid [\d\.]+; (fp\du?)(?: b|\))/i                                 // Fairphone
            ], [MODEL, [VENDOR, 'Fairphone'], [TYPE, MOBILE]], [
            /(u304aa)/i                                                         // AT&T
            ], [MODEL, [VENDOR, 'AT&T'], [TYPE, MOBILE]], [
            /\bsie-(\w*)/i                                                      // Siemens
            ], [MODEL, [VENDOR, 'Siemens'], [TYPE, MOBILE]], [
            /\b(rct\w+) b/i                                                     // RCA Tablets
            ], [MODEL, [VENDOR, 'RCA'], [TYPE, TABLET]], [
            /\b(venue[\d ]{2,7}) b/i                                            // Dell Venue Tablets
            ], [MODEL, [VENDOR, 'Dell'], [TYPE, TABLET]], [
            /\b(q(?:mv|ta)\w+) b/i                                              // Verizon Tablet
            ], [MODEL, [VENDOR, 'Verizon'], [TYPE, TABLET]], [
            /\b(?:barnes[& ]+noble |bn[rt])([\w\+ ]*) b/i                       // Barnes & Noble Tablet
            ], [MODEL, [VENDOR, 'Barnes & Noble'], [TYPE, TABLET]], [
            /\b(tm\d{3}\w+) b/i
            ], [MODEL, [VENDOR, 'NuVision'], [TYPE, TABLET]], [
            /\b(k88) b/i                                                        // ZTE K Series Tablet
            ], [MODEL, [VENDOR, 'ZTE'], [TYPE, TABLET]], [
            /\b(nx\d{3}j) b/i                                                   // ZTE Nubia
            ], [MODEL, [VENDOR, 'ZTE'], [TYPE, MOBILE]], [
            /\b(gen\d{3}) b.+49h/i                                              // Swiss GEN Mobile
            ], [MODEL, [VENDOR, 'Swiss'], [TYPE, MOBILE]], [
            /\b(zur\d{3}) b/i                                                   // Swiss ZUR Tablet
            ], [MODEL, [VENDOR, 'Swiss'], [TYPE, TABLET]], [
            /\b((zeki)?tb.*\b) b/i                                              // Zeki Tablets
            ], [MODEL, [VENDOR, 'Zeki'], [TYPE, TABLET]], [
            /\b([yr]\d{2}) b/i,
            /\b(dragon[- ]+touch |dt)(\w{5}) b/i                                // Dragon Touch Tablet
            ], [[VENDOR, 'Dragon Touch'], MODEL, [TYPE, TABLET]], [
            /\b(ns-?\w{0,9}) b/i                                                // Insignia Tablets
            ], [MODEL, [VENDOR, 'Insignia'], [TYPE, TABLET]], [
            /\b((nxa|next)-?\w{0,9}) b/i                                        // NextBook Tablets
            ], [MODEL, [VENDOR, 'NextBook'], [TYPE, TABLET]], [
            /\b(xtreme\_)?(v(1[045]|2[015]|[3469]0|7[05])) b/i                  // Voice Xtreme Phones
            ], [[VENDOR, 'Voice'], MODEL, [TYPE, MOBILE]], [
            /\b(lvtel\-)?(v1[12]) b/i                                           // LvTel Phones
            ], [[VENDOR, 'LvTel'], MODEL, [TYPE, MOBILE]], [
            /\b(ph-1) /i                                                        // Essential PH-1
            ], [MODEL, [VENDOR, 'Essential'], [TYPE, MOBILE]], [
            /\b(v(100md|700na|7011|917g).*\b) b/i                               // Envizen Tablets
            ], [MODEL, [VENDOR, 'Envizen'], [TYPE, TABLET]], [
            /\b(trio[-\w\. ]+) b/i                                              // MachSpeed Tablets
            ], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
            /\btu_(1491) b/i                                                    // Rotor Tablets
            ], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]], [
            /(shield[\w ]+) b/i                                                 // Nvidia Shield Tablets
            ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, TABLET]], [
            /(sprint) (\w+)/i                                                   // Sprint Phones
            ], [VENDOR, MODEL, [TYPE, MOBILE]], [
            /(kin\.[onetw]{3})/i                                                // Microsoft Kin
            ], [[MODEL, /\./g, ' '], [VENDOR, MICROSOFT], [TYPE, MOBILE]], [
            /droid.+; (cc6666?|et5[16]|mc[239][23]x?|vc8[03]x?)\)/i             // Zebra
            ], [MODEL, [VENDOR, ZEBRA], [TYPE, TABLET]], [
            /droid.+; (ec30|ps20|tc[2-8]\d[kx])\)/i
            ], [MODEL, [VENDOR, ZEBRA], [TYPE, MOBILE]], [

            ///////////////////
            // CONSOLES
            ///////////////////

            /(ouya)/i,                                                          // Ouya
            /(nintendo) ([wids3utch]+)/i                                        // Nintendo
            ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
            /droid.+; (shield) bui/i                                            // Nvidia
            ], [MODEL, [VENDOR, 'Nvidia'], [TYPE, CONSOLE]], [
            /(playstation [345portablevi]+)/i                                   // Playstation
            ], [MODEL, [VENDOR, SONY], [TYPE, CONSOLE]], [
            /\b(xbox(?: one)?(?!; xbox))[\); ]/i                                // Microsoft Xbox
            ], [MODEL, [VENDOR, MICROSOFT], [TYPE, CONSOLE]], [

            ///////////////////
            // SMARTTVS
            ///////////////////

            /smart-tv.+(samsung)/i                                              // Samsung
            ], [VENDOR, [TYPE, SMARTTV]], [
            /hbbtv.+maple;(\d+)/i
            ], [[MODEL, /^/, 'SmartTV'], [VENDOR, SAMSUNG], [TYPE, SMARTTV]], [
            /(nux; netcast.+smarttv|lg (netcast\.tv-201\d|android tv))/i        // LG SmartTV
            ], [[VENDOR, LG], [TYPE, SMARTTV]], [
            /(apple) ?tv/i                                                      // Apple TV
            ], [VENDOR, [MODEL, APPLE+' TV'], [TYPE, SMARTTV]], [
            /crkey/i                                                            // Google Chromecast
            ], [[MODEL, CHROME+'cast'], [VENDOR, GOOGLE], [TYPE, SMARTTV]], [
            /droid.+aft(\w)( bui|\))/i                                          // Fire TV
            ], [MODEL, [VENDOR, AMAZON], [TYPE, SMARTTV]], [
            /\(dtv[\);].+(aquos)/i                                              // Sharp
            ], [MODEL, [VENDOR, 'Sharp'], [TYPE, SMARTTV]], [
            /\b(roku)[\dx]*[\)\/]((?:dvp-)?[\d\.]*)/i,                          // Roku
            /hbbtv\/\d+\.\d+\.\d+ +\([\w ]*; *(\w[^;]*);([^;]*)/i               // HbbTV devices
            ], [[VENDOR, trim], [MODEL, trim], [TYPE, SMARTTV]], [
            /\b(android tv|smart[- ]?tv|opera tv|tv; rv:)\b/i                   // SmartTV from Unidentified Vendors
            ], [[TYPE, SMARTTV]], [

            ///////////////////
            // WEARABLES
            ///////////////////

            /((pebble))app/i                                                    // Pebble
            ], [VENDOR, MODEL, [TYPE, WEARABLE]], [
            /droid.+; (glass) \d/i                                              // Google Glass
            ], [MODEL, [VENDOR, GOOGLE], [TYPE, WEARABLE]], [
            /droid.+; (wt63?0{2,3})\)/i
            ], [MODEL, [VENDOR, ZEBRA], [TYPE, WEARABLE]], [
            /(quest( 2)?)/i                                                     // Oculus Quest
            ], [MODEL, [VENDOR, FACEBOOK], [TYPE, WEARABLE]], [

            ///////////////////
            // EMBEDDED
            ///////////////////

            /(tesla)(?: qtcarbrowser|\/[-\w\.]+)/i                              // Tesla
            ], [VENDOR, [TYPE, EMBEDDED]], [

            ////////////////////
            // MIXED (GENERIC)
            ///////////////////

            /droid .+?; ([^;]+?)(?: bui|\) applew).+? mobile safari/i           // Android Phones from Unidentified Vendors
            ], [MODEL, [TYPE, MOBILE]], [
            /droid .+?; ([^;]+?)(?: bui|\) applew).+?(?! mobile) safari/i       // Android Tablets from Unidentified Vendors
            ], [MODEL, [TYPE, TABLET]], [
            /\b((tablet|tab)[;\/]|focus\/\d(?!.+mobile))/i                      // Unidentifiable Tablet
            ], [[TYPE, TABLET]], [
            /(phone|mobile(?:[;\/]| safari)|pda(?=.+windows ce))/i              // Unidentifiable Mobile
            ], [[TYPE, MOBILE]], [
            /(android[-\w\. ]{0,9});.+buil/i                                    // Generic Android Device
            ], [MODEL, [VENDOR, 'Generic']]
        ],

        engine : [[

            /windows.+ edge\/([\w\.]+)/i                                       // EdgeHTML
            ], [VERSION, [NAME, EDGE+'HTML']], [

            /webkit\/537\.36.+chrome\/(?!27)([\w\.]+)/i                         // Blink
            ], [VERSION, [NAME, 'Blink']], [

            /(presto)\/([\w\.]+)/i,                                             // Presto
            /(webkit|trident|netfront|netsurf|amaya|lynx|w3m|goanna)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m/Goanna
            /ekioh(flow)\/([\w\.]+)/i,                                          // Flow
            /(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i,                           // KHTML/Tasman/Links
            /(icab)[\/ ]([23]\.[\d\.]+)/i                                       // iCab
            ], [NAME, VERSION], [

            /rv\:([\w\.]{1,9})\b.+(gecko)/i                                     // Gecko
            ], [VERSION, NAME]
        ],

        os : [[

            // Windows
            /microsoft (windows) (vista|xp)/i                                   // Windows (iTunes)
            ], [NAME, VERSION], [
            /(windows) nt 6\.2; (arm)/i,                                        // Windows RT
            /(windows (?:phone(?: os)?|mobile))[\/ ]?([\d\.\w ]*)/i,            // Windows Phone
            /(windows)[\/ ]?([ntce\d\. ]+\w)(?!.+xbox)/i
            ], [NAME, [VERSION, strMapper, windowsVersionMap]], [
            /(win(?=3|9|n)|win 9x )([nt\d\.]+)/i
            ], [[NAME, 'Windows'], [VERSION, strMapper, windowsVersionMap]], [

            // iOS/macOS
            /ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i,              // iOS
            /cfnetwork\/.+darwin/i
            ], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
            /(mac os x) ?([\w\. ]*)/i,
            /(macintosh|mac_powerpc\b)(?!.+haiku)/i                             // Mac OS
            ], [[NAME, 'Mac OS'], [VERSION, /_/g, '.']], [

            // Mobile OSes
            /droid ([\w\.]+)\b.+(android[- ]x86)/i                              // Android-x86
            ], [VERSION, NAME], [                                               // Android/WebOS/QNX/Bada/RIM/Maemo/MeeGo/Sailfish OS
            /(android|webos|qnx|bada|rim tablet os|maemo|meego|sailfish)[-\/ ]?([\w\.]*)/i,
            /(blackberry)\w*\/([\w\.]*)/i,                                      // Blackberry
            /(tizen|kaios)[\/ ]([\w\.]+)/i,                                     // Tizen/KaiOS
            /\((series40);/i                                                    // Series 40
            ], [NAME, VERSION], [
            /\(bb(10);/i                                                        // BlackBerry 10
            ], [VERSION, [NAME, BLACKBERRY]], [
            /(?:symbian ?os|symbos|s60(?=;)|series60)[-\/ ]?([\w\.]*)/i         // Symbian
            ], [VERSION, [NAME, 'Symbian']], [
            /mozilla\/[\d\.]+ \((?:mobile|tablet|tv|mobile; [\w ]+); rv:.+ gecko\/([\w\.]+)/i // Firefox OS
            ], [VERSION, [NAME, FIREFOX+' OS']], [
            /web0s;.+rt(tv)/i,
            /\b(?:hp)?wos(?:browser)?\/([\w\.]+)/i                              // WebOS
            ], [VERSION, [NAME, 'webOS']], [

            // Google Chromecast
            /crkey\/([\d\.]+)/i                                                 // Google Chromecast
            ], [VERSION, [NAME, CHROME+'cast']], [
            /(cros) [\w]+ ([\w\.]+\w)/i                                         // Chromium OS
            ], [[NAME, 'Chromium OS'], VERSION],[

            // Console
            /(nintendo|playstation) ([wids345portablevuch]+)/i,                 // Nintendo/Playstation
            /(xbox); +xbox ([^\);]+)/i,                                         // Microsoft Xbox (360, One, X, S, Series X, Series S)

            // Other
            /\b(joli|palm)\b ?(?:os)?\/?([\w\.]*)/i,                            // Joli/Palm
            /(mint)[\/\(\) ]?(\w*)/i,                                           // Mint
            /(mageia|vectorlinux)[; ]/i,                                        // Mageia/VectorLinux
            /([kxln]?ubuntu|debian|suse|opensuse|gentoo|arch(?= linux)|slackware|fedora|mandriva|centos|pclinuxos|red ?hat|zenwalk|linpus|raspbian|plan 9|minix|risc os|contiki|deepin|manjaro|elementary os|sabayon|linspire)(?: gnu\/linux)?(?: enterprise)?(?:[- ]linux)?(?:-gnu)?[-\/ ]?(?!chrom|package)([-\w\.]*)/i,
                                                                                // Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware/Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk/Linpus/Raspbian/Plan9/Minix/RISCOS/Contiki/Deepin/Manjaro/elementary/Sabayon/Linspire
            /(hurd|linux) ?([\w\.]*)/i,                                         // Hurd/Linux
            /(gnu) ?([\w\.]*)/i,                                                // GNU
            /\b([-frentopcghs]{0,5}bsd|dragonfly)[\/ ]?(?!amd|[ix346]{1,2}86)([\w\.]*)/i, // FreeBSD/NetBSD/OpenBSD/PC-BSD/GhostBSD/DragonFly
            /(haiku) (\w+)/i                                                    // Haiku
            ], [NAME, VERSION], [
            /(sunos) ?([\w\.\d]*)/i                                             // Solaris
            ], [[NAME, 'Solaris'], VERSION], [
            /((?:open)?solaris)[-\/ ]?([\w\.]*)/i,                              // Solaris
            /(aix) ((\d)(?=\.|\)| )[\w\.])*/i,                                  // AIX
            /\b(beos|os\/2|amigaos|morphos|openvms|fuchsia|hp-ux)/i,            // BeOS/OS2/AmigaOS/MorphOS/OpenVMS/Fuchsia/HP-UX
            /(unix) ?([\w\.]*)/i                                                // UNIX
            ], [NAME, VERSION]
        ]
    };

    /////////////////
    // Constructor
    ////////////////

    var UAParser = function (ua, extensions) {

        if (typeof ua === OBJ_TYPE) {
            extensions = ua;
            ua = undefined;
        }

        if (!(this instanceof UAParser)) {
            return new UAParser(ua, extensions).getResult();
        }

        var _ua = ua || ((typeof window !== UNDEF_TYPE && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : EMPTY);
        var _rgxmap = extensions ? extend(regexes, extensions) : regexes;

        this.getBrowser = function () {
            var _browser = {};
            _browser[NAME] = undefined;
            _browser[VERSION] = undefined;
            rgxMapper.call(_browser, _ua, _rgxmap.browser);
            _browser.major = majorize(_browser.version);
            return _browser;
        };
        this.getCPU = function () {
            var _cpu = {};
            _cpu[ARCHITECTURE] = undefined;
            rgxMapper.call(_cpu, _ua, _rgxmap.cpu);
            return _cpu;
        };
        this.getDevice = function () {
            var _device = {};
            _device[VENDOR] = undefined;
            _device[MODEL] = undefined;
            _device[TYPE] = undefined;
            rgxMapper.call(_device, _ua, _rgxmap.device);
            return _device;
        };
        this.getEngine = function () {
            var _engine = {};
            _engine[NAME] = undefined;
            _engine[VERSION] = undefined;
            rgxMapper.call(_engine, _ua, _rgxmap.engine);
            return _engine;
        };
        this.getOS = function () {
            var _os = {};
            _os[NAME] = undefined;
            _os[VERSION] = undefined;
            rgxMapper.call(_os, _ua, _rgxmap.os);
            return _os;
        };
        this.getResult = function () {
            return {
                ua      : this.getUA(),
                browser : this.getBrowser(),
                engine  : this.getEngine(),
                os      : this.getOS(),
                device  : this.getDevice(),
                cpu     : this.getCPU()
            };
        };
        this.getUA = function () {
            return _ua;
        };
        this.setUA = function (ua) {
            _ua = (typeof ua === STR_TYPE && ua.length > UA_MAX_LENGTH) ? trim(ua, UA_MAX_LENGTH) : ua;
            return this;
        };
        this.setUA(_ua);
        return this;
    };

    UAParser.VERSION = LIBVERSION;
    UAParser.BROWSER =  enumerize([NAME, VERSION, MAJOR]);
    UAParser.CPU = enumerize([ARCHITECTURE]);
    UAParser.DEVICE = enumerize([MODEL, VENDOR, TYPE, CONSOLE, MOBILE, SMARTTV, TABLET, WEARABLE, EMBEDDED]);
    UAParser.ENGINE = UAParser.OS = enumerize([NAME, VERSION]);

    ///////////
    // Export
    //////////

    // check js environment
    if (typeof(exports) !== UNDEF_TYPE) {
        // nodejs env
        if ("object" !== UNDEF_TYPE && module.exports) {
            exports = module.exports = UAParser;
        }
        exports.UAParser = UAParser;
    } else {
        // requirejs env (optional)
        if ("function" === FUNC_TYPE && __webpack_require__.amdO) {
            !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
                return UAParser;
            }).call(exports, __webpack_require__, exports, module),
		__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
        } else if (typeof window !== UNDEF_TYPE) {
            // browser env
            window.UAParser = UAParser;
        }
    }

    // jQuery/Zepto specific (optional)
    // Note:
    //   In AMD env the global scope should be kept clean, but jQuery is an exception.
    //   jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
    //   and we should catch that.
    var $ = typeof window !== UNDEF_TYPE && (window.jQuery || window.Zepto);
    if ($ && !$.ua) {
        var parser = new UAParser();
        $.ua = parser.getResult();
        $.ua.get = function () {
            return parser.getUA();
        };
        $.ua.set = function (ua) {
            parser.setUA(ua);
            var result = parser.getResult();
            for (var prop in result) {
                $.ua[prop] = result[prop];
            }
        };
    }

})(typeof window === 'object' ? window : this);


/***/ }),

/***/ "./node_modules/util-deprecate/browser.js":
/*!************************************************!*\
  !*** ./node_modules/util-deprecate/browser.js ***!
  \************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {


/**
 * 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 (!__webpack_require__.g.localStorage) return false;
  } catch (_) {
    return false;
  }
  var val = __webpack_require__.g.localStorage[name];
  if (null == val) return false;
  return String(val).toLowerCase() === 'true';
}


/***/ }),

/***/ "?3e83":
/*!**********************!*\
  !*** util (ignored) ***!
  \**********************/
/***/ (function() {

/* (ignored) */

/***/ }),

/***/ "?19e6":
/*!**********************!*\
  !*** util (ignored) ***!
  \**********************/
/***/ (function() {

/* (ignored) */

/***/ }),

/***/ "./node_modules/bcp-47-normalize/lib/defaults.json":
/*!*********************************************************!*\
  !*** ./node_modules/bcp-47-normalize/lib/defaults.json ***!
  \*********************************************************/
/***/ (function(module) {

"use strict";
module.exports = JSON.parse('["mni-beng-in","mni-mtei-in","sat-deva-in","sat-olck-in","shi-latn-ma","shi-tfng-ma","vai-latn-lr","vai-vaii-lr","yue-hans-cn","yue-hant-hk","az-arab-ir","az-cyrl-az","az-latn-az","bm-nkoo-ml","bs-cyrl-ba","bs-latn-ba","en-dsrt-us","ff-adlm-gn","ff-latn-sn","ha-arab-ng","hi-latn-in","iu-latn-ca","ks-arab-in","ks-deva-in","mn-mong-cn","ms-arab-my","pa-arab-pk","pa-guru-in","sd-arab-pk","sd-deva-in","sr-cyrl-rs","sr-latn-rs","su-latn-id","uz-arab-af","uz-cyrl-uz","uz-latn-uz","zh-hans-cn","zh-hant-tw","mni-beng","sat-olck","shi-tfng","vai-vaii","yue-hant","az-latn","bs-latn","ff-latn","jbo-001","ks-arab","pa-guru","prg-001","sd-arab","sr-cyrl","su-latn","uz-latn","zh-hans","agq-cm","ar-001","arn-cl","asa-tz","ast-es","bas-cm","bem-zm","bez-tz","bgn-pk","blt-vn","brx-in","bss-cm","byn-er","cad-us","cch-ng","ccp-bd","ceb-ph","cgg-ug","chr-us","cic-us","ckb-iq","dav-ke","dje-ne","doi-in","dsb-de","dua-cm","dyo-sn","ebu-ke","eo-001","ewo-cm","fil-ph","fur-it","gaa-gh","gez-et","gsw-ch","guz-ke","haw-us","hsb-de","ia-001","ife-tg","io-001","jgo-cm","jmc-tz","kab-dz","kaj-ng","kam-ke","kcg-ng","kde-tz","kea-cv","ken-cm","khq-ml","kkj-cm","kln-ke","kok-in","kpe-lr","ksb-tz","ksf-cm","ksh-de","lag-tz","lkt-us","lrc-ir","luo-ke","luy-ke","mai-in","mas-ke","mer-ke","mfe-mu","mgh-mz","mgo-cm","moh-ca","mua-cm","mus-us","myv-ru","mzn-ir","naq-na","nds-de","nmg-cm","nnh-cm","nqo-gn","nso-za","nus-ss","nyn-ug","osa-us","pcm-ng","quc-gt","rof-tz","rwk-tz","sah-ru","saq-ke","sbp-tz","scn-it","sdh-ir","seh-mz","ses-ml","sid-et","sma-se","smj-se","smn-fi","sms-fi","ssy-er","syr-iq","szl-pl","teo-ug","tig-er","trv-tw","trw-pk","twq-ne","tzm-ma","vo-001","vun-tz","wae-ch","wal-et","wbp-au","xog-ug","yav-cm","yi-001","zgh-ma","aa-et","af-za","ak-gh","am-et","an-es","as-in","ba-ru","be-by","bg-bg","bm-ml","bn-bd","bo-cn","br-fr","ca-es","ce-ru","co-fr","cs-cz","cu-ru","cv-ru","cy-gb","da-dk","de-de","dv-mv","dz-bt","ee-gh","el-gr","en-us","es-es","et-ee","eu-es","fa-ir","fi-fi","fo-fo","fr-fr","fy-nl","ga-ie","gd-gb","gl-es","gn-py","gu-in","gv-im","ha-ng","he-il","hi-in","hr-hr","hu-hu","hy-am","id-id","ig-ng","ii-cn","is-is","it-it","iu-ca","ja-jp","jv-id","ka-ge","ki-ke","kk-kz","kl-gl","km-kh","kn-in","ko-kr","ku-tr","kw-gb","ky-kg","lb-lu","lg-ug","ln-cd","lo-la","lt-lt","lu-cd","lv-lv","mg-mg","mi-nz","mk-mk","ml-in","mn-mn","mr-in","ms-my","mt-mt","my-mm","nb-no","nd-zw","ne-np","nl-nl","nn-no","nr-za","nv-us","ny-mw","oc-fr","om-et","or-in","os-ge","pl-pl","ps-af","pt-br","qu-pe","rm-ch","rn-bi","ro-ro","ru-ru","rw-rw","sa-in","sc-it","se-no","sg-cf","si-lk","sk-sk","sl-si","sn-zw","so-so","sq-al","ss-za","st-za","sv-se","sw-tz","ta-in","te-in","tg-tj","th-th","ti-et","tk-tm","tn-za","to-to","tr-tr","ts-za","tt-ru","ug-cn","uk-ua","ur-pk","ve-za","vi-vn","wa-be","wo-sn","xh-za","yo-ng","zu-za"]');

/***/ }),

/***/ "./node_modules/bcp-47-normalize/lib/fields.json":
/*!*******************************************************!*\
  !*** ./node_modules/bcp-47-normalize/lib/fields.json ***!
  \*******************************************************/
/***/ (function(module) {

"use strict";
module.exports = JSON.parse('[{"from":{"field":"script","value":"qaai"},"to":{"field":"script","value":"zinh"}},{"from":{"field":"region","value":"bu"},"to":{"field":"region","value":"mm"}},{"from":{"field":"region","value":"ct"},"to":{"field":"region","value":"ki"}},{"from":{"field":"region","value":"dd"},"to":{"field":"region","value":"de"}},{"from":{"field":"region","value":"dy"},"to":{"field":"region","value":"bj"}},{"from":{"field":"region","value":"fx"},"to":{"field":"region","value":"fr"}},{"from":{"field":"region","value":"hv"},"to":{"field":"region","value":"bf"}},{"from":{"field":"region","value":"jt"},"to":{"field":"region","value":"um"}},{"from":{"field":"region","value":"mi"},"to":{"field":"region","value":"um"}},{"from":{"field":"region","value":"nh"},"to":{"field":"region","value":"vu"}},{"from":{"field":"region","value":"nq"},"to":{"field":"region","value":"aq"}},{"from":{"field":"region","value":"pu"},"to":{"field":"region","value":"um"}},{"from":{"field":"region","value":"pz"},"to":{"field":"region","value":"pa"}},{"from":{"field":"region","value":"qu"},"to":{"field":"region","value":"eu"}},{"from":{"field":"region","value":"rh"},"to":{"field":"region","value":"zw"}},{"from":{"field":"region","value":"tp"},"to":{"field":"region","value":"tl"}},{"from":{"field":"region","value":"uk"},"to":{"field":"region","value":"gb"}},{"from":{"field":"region","value":"vd"},"to":{"field":"region","value":"vn"}},{"from":{"field":"region","value":"wk"},"to":{"field":"region","value":"um"}},{"from":{"field":"region","value":"yd"},"to":{"field":"region","value":"ye"}},{"from":{"field":"region","value":"zr"},"to":{"field":"region","value":"cd"}},{"from":{"field":"region","value":"230"},"to":{"field":"region","value":"et"}},{"from":{"field":"region","value":"280"},"to":{"field":"region","value":"de"}},{"from":{"field":"region","value":"736"},"to":{"field":"region","value":"sd"}},{"from":{"field":"region","value":"886"},"to":{"field":"region","value":"ye"}},{"from":{"field":"region","value":"958"},"to":{"field":"region","value":"aa"}},{"from":{"field":"region","value":"020"},"to":{"field":"region","value":"ad"}},{"from":{"field":"region","value":"784"},"to":{"field":"region","value":"ae"}},{"from":{"field":"region","value":"004"},"to":{"field":"region","value":"af"}},{"from":{"field":"region","value":"028"},"to":{"field":"region","value":"ag"}},{"from":{"field":"region","value":"660"},"to":{"field":"region","value":"ai"}},{"from":{"field":"region","value":"008"},"to":{"field":"region","value":"al"}},{"from":{"field":"region","value":"051"},"to":{"field":"region","value":"am"}},{"from":{"field":"region","value":"024"},"to":{"field":"region","value":"ao"}},{"from":{"field":"region","value":"010"},"to":{"field":"region","value":"aq"}},{"from":{"field":"region","value":"032"},"to":{"field":"region","value":"ar"}},{"from":{"field":"region","value":"016"},"to":{"field":"region","value":"as"}},{"from":{"field":"region","value":"040"},"to":{"field":"region","value":"at"}},{"from":{"field":"region","value":"036"},"to":{"field":"region","value":"au"}},{"from":{"field":"region","value":"533"},"to":{"field":"region","value":"aw"}},{"from":{"field":"region","value":"248"},"to":{"field":"region","value":"ax"}},{"from":{"field":"region","value":"031"},"to":{"field":"region","value":"az"}},{"from":{"field":"region","value":"070"},"to":{"field":"region","value":"ba"}},{"from":{"field":"region","value":"052"},"to":{"field":"region","value":"bb"}},{"from":{"field":"region","value":"050"},"to":{"field":"region","value":"bd"}},{"from":{"field":"region","value":"056"},"to":{"field":"region","value":"be"}},{"from":{"field":"region","value":"854"},"to":{"field":"region","value":"bf"}},{"from":{"field":"region","value":"100"},"to":{"field":"region","value":"bg"}},{"from":{"field":"region","value":"048"},"to":{"field":"region","value":"bh"}},{"from":{"field":"region","value":"108"},"to":{"field":"region","value":"bi"}},{"from":{"field":"region","value":"204"},"to":{"field":"region","value":"bj"}},{"from":{"field":"region","value":"652"},"to":{"field":"region","value":"bl"}},{"from":{"field":"region","value":"060"},"to":{"field":"region","value":"bm"}},{"from":{"field":"region","value":"096"},"to":{"field":"region","value":"bn"}},{"from":{"field":"region","value":"068"},"to":{"field":"region","value":"bo"}},{"from":{"field":"region","value":"535"},"to":{"field":"region","value":"bq"}},{"from":{"field":"region","value":"076"},"to":{"field":"region","value":"br"}},{"from":{"field":"region","value":"044"},"to":{"field":"region","value":"bs"}},{"from":{"field":"region","value":"064"},"to":{"field":"region","value":"bt"}},{"from":{"field":"region","value":"104"},"to":{"field":"region","value":"mm"}},{"from":{"field":"region","value":"074"},"to":{"field":"region","value":"bv"}},{"from":{"field":"region","value":"072"},"to":{"field":"region","value":"bw"}},{"from":{"field":"region","value":"112"},"to":{"field":"region","value":"by"}},{"from":{"field":"region","value":"084"},"to":{"field":"region","value":"bz"}},{"from":{"field":"region","value":"124"},"to":{"field":"region","value":"ca"}},{"from":{"field":"region","value":"166"},"to":{"field":"region","value":"cc"}},{"from":{"field":"region","value":"180"},"to":{"field":"region","value":"cd"}},{"from":{"field":"region","value":"140"},"to":{"field":"region","value":"cf"}},{"from":{"field":"region","value":"178"},"to":{"field":"region","value":"cg"}},{"from":{"field":"region","value":"756"},"to":{"field":"region","value":"ch"}},{"from":{"field":"region","value":"384"},"to":{"field":"region","value":"ci"}},{"from":{"field":"region","value":"184"},"to":{"field":"region","value":"ck"}},{"from":{"field":"region","value":"152"},"to":{"field":"region","value":"cl"}},{"from":{"field":"region","value":"120"},"to":{"field":"region","value":"cm"}},{"from":{"field":"region","value":"156"},"to":{"field":"region","value":"cn"}},{"from":{"field":"region","value":"170"},"to":{"field":"region","value":"co"}},{"from":{"field":"region","value":"188"},"to":{"field":"region","value":"cr"}},{"from":{"field":"region","value":"192"},"to":{"field":"region","value":"cu"}},{"from":{"field":"region","value":"132"},"to":{"field":"region","value":"cv"}},{"from":{"field":"region","value":"531"},"to":{"field":"region","value":"cw"}},{"from":{"field":"region","value":"162"},"to":{"field":"region","value":"cx"}},{"from":{"field":"region","value":"196"},"to":{"field":"region","value":"cy"}},{"from":{"field":"region","value":"203"},"to":{"field":"region","value":"cz"}},{"from":{"field":"region","value":"278"},"to":{"field":"region","value":"de"}},{"from":{"field":"region","value":"276"},"to":{"field":"region","value":"de"}},{"from":{"field":"region","value":"262"},"to":{"field":"region","value":"dj"}},{"from":{"field":"region","value":"208"},"to":{"field":"region","value":"dk"}},{"from":{"field":"region","value":"212"},"to":{"field":"region","value":"dm"}},{"from":{"field":"region","value":"214"},"to":{"field":"region","value":"do"}},{"from":{"field":"region","value":"012"},"to":{"field":"region","value":"dz"}},{"from":{"field":"region","value":"218"},"to":{"field":"region","value":"ec"}},{"from":{"field":"region","value":"233"},"to":{"field":"region","value":"ee"}},{"from":{"field":"region","value":"818"},"to":{"field":"region","value":"eg"}},{"from":{"field":"region","value":"732"},"to":{"field":"region","value":"eh"}},{"from":{"field":"region","value":"232"},"to":{"field":"region","value":"er"}},{"from":{"field":"region","value":"724"},"to":{"field":"region","value":"es"}},{"from":{"field":"region","value":"231"},"to":{"field":"region","value":"et"}},{"from":{"field":"region","value":"246"},"to":{"field":"region","value":"fi"}},{"from":{"field":"region","value":"242"},"to":{"field":"region","value":"fj"}},{"from":{"field":"region","value":"238"},"to":{"field":"region","value":"fk"}},{"from":{"field":"region","value":"583"},"to":{"field":"region","value":"fm"}},{"from":{"field":"region","value":"234"},"to":{"field":"region","value":"fo"}},{"from":{"field":"region","value":"250"},"to":{"field":"region","value":"fr"}},{"from":{"field":"region","value":"249"},"to":{"field":"region","value":"fr"}},{"from":{"field":"region","value":"266"},"to":{"field":"region","value":"ga"}},{"from":{"field":"region","value":"826"},"to":{"field":"region","value":"gb"}},{"from":{"field":"region","value":"308"},"to":{"field":"region","value":"gd"}},{"from":{"field":"region","value":"268"},"to":{"field":"region","value":"ge"}},{"from":{"field":"region","value":"254"},"to":{"field":"region","value":"gf"}},{"from":{"field":"region","value":"831"},"to":{"field":"region","value":"gg"}},{"from":{"field":"region","value":"288"},"to":{"field":"region","value":"gh"}},{"from":{"field":"region","value":"292"},"to":{"field":"region","value":"gi"}},{"from":{"field":"region","value":"304"},"to":{"field":"region","value":"gl"}},{"from":{"field":"region","value":"270"},"to":{"field":"region","value":"gm"}},{"from":{"field":"region","value":"324"},"to":{"field":"region","value":"gn"}},{"from":{"field":"region","value":"312"},"to":{"field":"region","value":"gp"}},{"from":{"field":"region","value":"226"},"to":{"field":"region","value":"gq"}},{"from":{"field":"region","value":"300"},"to":{"field":"region","value":"gr"}},{"from":{"field":"region","value":"239"},"to":{"field":"region","value":"gs"}},{"from":{"field":"region","value":"320"},"to":{"field":"region","value":"gt"}},{"from":{"field":"region","value":"316"},"to":{"field":"region","value":"gu"}},{"from":{"field":"region","value":"624"},"to":{"field":"region","value":"gw"}},{"from":{"field":"region","value":"328"},"to":{"field":"region","value":"gy"}},{"from":{"field":"region","value":"344"},"to":{"field":"region","value":"hk"}},{"from":{"field":"region","value":"334"},"to":{"field":"region","value":"hm"}},{"from":{"field":"region","value":"340"},"to":{"field":"region","value":"hn"}},{"from":{"field":"region","value":"191"},"to":{"field":"region","value":"hr"}},{"from":{"field":"region","value":"332"},"to":{"field":"region","value":"ht"}},{"from":{"field":"region","value":"348"},"to":{"field":"region","value":"hu"}},{"from":{"field":"region","value":"360"},"to":{"field":"region","value":"id"}},{"from":{"field":"region","value":"372"},"to":{"field":"region","value":"ie"}},{"from":{"field":"region","value":"376"},"to":{"field":"region","value":"il"}},{"from":{"field":"region","value":"833"},"to":{"field":"region","value":"im"}},{"from":{"field":"region","value":"356"},"to":{"field":"region","value":"in"}},{"from":{"field":"region","value":"086"},"to":{"field":"region","value":"io"}},{"from":{"field":"region","value":"368"},"to":{"field":"region","value":"iq"}},{"from":{"field":"region","value":"364"},"to":{"field":"region","value":"ir"}},{"from":{"field":"region","value":"352"},"to":{"field":"region","value":"is"}},{"from":{"field":"region","value":"380"},"to":{"field":"region","value":"it"}},{"from":{"field":"region","value":"832"},"to":{"field":"region","value":"je"}},{"from":{"field":"region","value":"388"},"to":{"field":"region","value":"jm"}},{"from":{"field":"region","value":"400"},"to":{"field":"region","value":"jo"}},{"from":{"field":"region","value":"392"},"to":{"field":"region","value":"jp"}},{"from":{"field":"region","value":"404"},"to":{"field":"region","value":"ke"}},{"from":{"field":"region","value":"417"},"to":{"field":"region","value":"kg"}},{"from":{"field":"region","value":"116"},"to":{"field":"region","value":"kh"}},{"from":{"field":"region","value":"296"},"to":{"field":"region","value":"ki"}},{"from":{"field":"region","value":"174"},"to":{"field":"region","value":"km"}},{"from":{"field":"region","value":"659"},"to":{"field":"region","value":"kn"}},{"from":{"field":"region","value":"408"},"to":{"field":"region","value":"kp"}},{"from":{"field":"region","value":"410"},"to":{"field":"region","value":"kr"}},{"from":{"field":"region","value":"414"},"to":{"field":"region","value":"kw"}},{"from":{"field":"region","value":"136"},"to":{"field":"region","value":"ky"}},{"from":{"field":"region","value":"398"},"to":{"field":"region","value":"kz"}},{"from":{"field":"region","value":"418"},"to":{"field":"region","value":"la"}},{"from":{"field":"region","value":"422"},"to":{"field":"region","value":"lb"}},{"from":{"field":"region","value":"662"},"to":{"field":"region","value":"lc"}},{"from":{"field":"region","value":"438"},"to":{"field":"region","value":"li"}},{"from":{"field":"region","value":"144"},"to":{"field":"region","value":"lk"}},{"from":{"field":"region","value":"430"},"to":{"field":"region","value":"lr"}},{"from":{"field":"region","value":"426"},"to":{"field":"region","value":"ls"}},{"from":{"field":"region","value":"440"},"to":{"field":"region","value":"lt"}},{"from":{"field":"region","value":"442"},"to":{"field":"region","value":"lu"}},{"from":{"field":"region","value":"428"},"to":{"field":"region","value":"lv"}},{"from":{"field":"region","value":"434"},"to":{"field":"region","value":"ly"}},{"from":{"field":"region","value":"504"},"to":{"field":"region","value":"ma"}},{"from":{"field":"region","value":"492"},"to":{"field":"region","value":"mc"}},{"from":{"field":"region","value":"498"},"to":{"field":"region","value":"md"}},{"from":{"field":"region","value":"499"},"to":{"field":"region","value":"me"}},{"from":{"field":"region","value":"663"},"to":{"field":"region","value":"mf"}},{"from":{"field":"region","value":"450"},"to":{"field":"region","value":"mg"}},{"from":{"field":"region","value":"584"},"to":{"field":"region","value":"mh"}},{"from":{"field":"region","value":"807"},"to":{"field":"region","value":"mk"}},{"from":{"field":"region","value":"466"},"to":{"field":"region","value":"ml"}},{"from":{"field":"region","value":"496"},"to":{"field":"region","value":"mn"}},{"from":{"field":"region","value":"446"},"to":{"field":"region","value":"mo"}},{"from":{"field":"region","value":"580"},"to":{"field":"region","value":"mp"}},{"from":{"field":"region","value":"474"},"to":{"field":"region","value":"mq"}},{"from":{"field":"region","value":"478"},"to":{"field":"region","value":"mr"}},{"from":{"field":"region","value":"500"},"to":{"field":"region","value":"ms"}},{"from":{"field":"region","value":"470"},"to":{"field":"region","value":"mt"}},{"from":{"field":"region","value":"480"},"to":{"field":"region","value":"mu"}},{"from":{"field":"region","value":"462"},"to":{"field":"region","value":"mv"}},{"from":{"field":"region","value":"454"},"to":{"field":"region","value":"mw"}},{"from":{"field":"region","value":"484"},"to":{"field":"region","value":"mx"}},{"from":{"field":"region","value":"458"},"to":{"field":"region","value":"my"}},{"from":{"field":"region","value":"508"},"to":{"field":"region","value":"mz"}},{"from":{"field":"region","value":"516"},"to":{"field":"region","value":"na"}},{"from":{"field":"region","value":"540"},"to":{"field":"region","value":"nc"}},{"from":{"field":"region","value":"562"},"to":{"field":"region","value":"ne"}},{"from":{"field":"region","value":"574"},"to":{"field":"region","value":"nf"}},{"from":{"field":"region","value":"566"},"to":{"field":"region","value":"ng"}},{"from":{"field":"region","value":"558"},"to":{"field":"region","value":"ni"}},{"from":{"field":"region","value":"528"},"to":{"field":"region","value":"nl"}},{"from":{"field":"region","value":"578"},"to":{"field":"region","value":"no"}},{"from":{"field":"region","value":"524"},"to":{"field":"region","value":"np"}},{"from":{"field":"region","value":"520"},"to":{"field":"region","value":"nr"}},{"from":{"field":"region","value":"570"},"to":{"field":"region","value":"nu"}},{"from":{"field":"region","value":"554"},"to":{"field":"region","value":"nz"}},{"from":{"field":"region","value":"512"},"to":{"field":"region","value":"om"}},{"from":{"field":"region","value":"591"},"to":{"field":"region","value":"pa"}},{"from":{"field":"region","value":"604"},"to":{"field":"region","value":"pe"}},{"from":{"field":"region","value":"258"},"to":{"field":"region","value":"pf"}},{"from":{"field":"region","value":"598"},"to":{"field":"region","value":"pg"}},{"from":{"field":"region","value":"608"},"to":{"field":"region","value":"ph"}},{"from":{"field":"region","value":"586"},"to":{"field":"region","value":"pk"}},{"from":{"field":"region","value":"616"},"to":{"field":"region","value":"pl"}},{"from":{"field":"region","value":"666"},"to":{"field":"region","value":"pm"}},{"from":{"field":"region","value":"612"},"to":{"field":"region","value":"pn"}},{"from":{"field":"region","value":"630"},"to":{"field":"region","value":"pr"}},{"from":{"field":"region","value":"275"},"to":{"field":"region","value":"ps"}},{"from":{"field":"region","value":"620"},"to":{"field":"region","value":"pt"}},{"from":{"field":"region","value":"585"},"to":{"field":"region","value":"pw"}},{"from":{"field":"region","value":"600"},"to":{"field":"region","value":"py"}},{"from":{"field":"region","value":"634"},"to":{"field":"region","value":"qa"}},{"from":{"field":"region","value":"959"},"to":{"field":"region","value":"qm"}},{"from":{"field":"region","value":"960"},"to":{"field":"region","value":"qn"}},{"from":{"field":"region","value":"962"},"to":{"field":"region","value":"qp"}},{"from":{"field":"region","value":"963"},"to":{"field":"region","value":"qq"}},{"from":{"field":"region","value":"964"},"to":{"field":"region","value":"qr"}},{"from":{"field":"region","value":"965"},"to":{"field":"region","value":"qs"}},{"from":{"field":"region","value":"966"},"to":{"field":"region","value":"qt"}},{"from":{"field":"region","value":"967"},"to":{"field":"region","value":"eu"}},{"from":{"field":"region","value":"968"},"to":{"field":"region","value":"qv"}},{"from":{"field":"region","value":"969"},"to":{"field":"region","value":"qw"}},{"from":{"field":"region","value":"970"},"to":{"field":"region","value":"qx"}},{"from":{"field":"region","value":"971"},"to":{"field":"region","value":"qy"}},{"from":{"field":"region","value":"972"},"to":{"field":"region","value":"qz"}},{"from":{"field":"region","value":"638"},"to":{"field":"region","value":"re"}},{"from":{"field":"region","value":"642"},"to":{"field":"region","value":"ro"}},{"from":{"field":"region","value":"688"},"to":{"field":"region","value":"rs"}},{"from":{"field":"region","value":"643"},"to":{"field":"region","value":"ru"}},{"from":{"field":"region","value":"646"},"to":{"field":"region","value":"rw"}},{"from":{"field":"region","value":"682"},"to":{"field":"region","value":"sa"}},{"from":{"field":"region","value":"090"},"to":{"field":"region","value":"sb"}},{"from":{"field":"region","value":"690"},"to":{"field":"region","value":"sc"}},{"from":{"field":"region","value":"729"},"to":{"field":"region","value":"sd"}},{"from":{"field":"region","value":"752"},"to":{"field":"region","value":"se"}},{"from":{"field":"region","value":"702"},"to":{"field":"region","value":"sg"}},{"from":{"field":"region","value":"654"},"to":{"field":"region","value":"sh"}},{"from":{"field":"region","value":"705"},"to":{"field":"region","value":"si"}},{"from":{"field":"region","value":"744"},"to":{"field":"region","value":"sj"}},{"from":{"field":"region","value":"703"},"to":{"field":"region","value":"sk"}},{"from":{"field":"region","value":"694"},"to":{"field":"region","value":"sl"}},{"from":{"field":"region","value":"674"},"to":{"field":"region","value":"sm"}},{"from":{"field":"region","value":"686"},"to":{"field":"region","value":"sn"}},{"from":{"field":"region","value":"706"},"to":{"field":"region","value":"so"}},{"from":{"field":"region","value":"740"},"to":{"field":"region","value":"sr"}},{"from":{"field":"region","value":"728"},"to":{"field":"region","value":"ss"}},{"from":{"field":"region","value":"678"},"to":{"field":"region","value":"st"}},{"from":{"field":"region","value":"222"},"to":{"field":"region","value":"sv"}},{"from":{"field":"region","value":"534"},"to":{"field":"region","value":"sx"}},{"from":{"field":"region","value":"760"},"to":{"field":"region","value":"sy"}},{"from":{"field":"region","value":"748"},"to":{"field":"region","value":"sz"}},{"from":{"field":"region","value":"796"},"to":{"field":"region","value":"tc"}},{"from":{"field":"region","value":"148"},"to":{"field":"region","value":"td"}},{"from":{"field":"region","value":"260"},"to":{"field":"region","value":"tf"}},{"from":{"field":"region","value":"768"},"to":{"field":"region","value":"tg"}},{"from":{"field":"region","value":"764"},"to":{"field":"region","value":"th"}},{"from":{"field":"region","value":"762"},"to":{"field":"region","value":"tj"}},{"from":{"field":"region","value":"772"},"to":{"field":"region","value":"tk"}},{"from":{"field":"region","value":"626"},"to":{"field":"region","value":"tl"}},{"from":{"field":"region","value":"795"},"to":{"field":"region","value":"tm"}},{"from":{"field":"region","value":"788"},"to":{"field":"region","value":"tn"}},{"from":{"field":"region","value":"776"},"to":{"field":"region","value":"to"}},{"from":{"field":"region","value":"792"},"to":{"field":"region","value":"tr"}},{"from":{"field":"region","value":"780"},"to":{"field":"region","value":"tt"}},{"from":{"field":"region","value":"798"},"to":{"field":"region","value":"tv"}},{"from":{"field":"region","value":"158"},"to":{"field":"region","value":"tw"}},{"from":{"field":"region","value":"834"},"to":{"field":"region","value":"tz"}},{"from":{"field":"region","value":"804"},"to":{"field":"region","value":"ua"}},{"from":{"field":"region","value":"800"},"to":{"field":"region","value":"ug"}},{"from":{"field":"region","value":"581"},"to":{"field":"region","value":"um"}},{"from":{"field":"region","value":"840"},"to":{"field":"region","value":"us"}},{"from":{"field":"region","value":"858"},"to":{"field":"region","value":"uy"}},{"from":{"field":"region","value":"860"},"to":{"field":"region","value":"uz"}},{"from":{"field":"region","value":"336"},"to":{"field":"region","value":"va"}},{"from":{"field":"region","value":"670"},"to":{"field":"region","value":"vc"}},{"from":{"field":"region","value":"862"},"to":{"field":"region","value":"ve"}},{"from":{"field":"region","value":"092"},"to":{"field":"region","value":"vg"}},{"from":{"field":"region","value":"850"},"to":{"field":"region","value":"vi"}},{"from":{"field":"region","value":"704"},"to":{"field":"region","value":"vn"}},{"from":{"field":"region","value":"548"},"to":{"field":"region","value":"vu"}},{"from":{"field":"region","value":"876"},"to":{"field":"region","value":"wf"}},{"from":{"field":"region","value":"882"},"to":{"field":"region","value":"ws"}},{"from":{"field":"region","value":"973"},"to":{"field":"region","value":"xa"}},{"from":{"field":"region","value":"974"},"to":{"field":"region","value":"xb"}},{"from":{"field":"region","value":"975"},"to":{"field":"region","value":"xc"}},{"from":{"field":"region","value":"976"},"to":{"field":"region","value":"xd"}},{"from":{"field":"region","value":"977"},"to":{"field":"region","value":"xe"}},{"from":{"field":"region","value":"978"},"to":{"field":"region","value":"xf"}},{"from":{"field":"region","value":"979"},"to":{"field":"region","value":"xg"}},{"from":{"field":"region","value":"980"},"to":{"field":"region","value":"xh"}},{"from":{"field":"region","value":"981"},"to":{"field":"region","value":"xi"}},{"from":{"field":"region","value":"982"},"to":{"field":"region","value":"xj"}},{"from":{"field":"region","value":"983"},"to":{"field":"region","value":"xk"}},{"from":{"field":"region","value":"984"},"to":{"field":"region","value":"xl"}},{"from":{"field":"region","value":"985"},"to":{"field":"region","value":"xm"}},{"from":{"field":"region","value":"986"},"to":{"field":"region","value":"xn"}},{"from":{"field":"region","value":"987"},"to":{"field":"region","value":"xo"}},{"from":{"field":"region","value":"988"},"to":{"field":"region","value":"xp"}},{"from":{"field":"region","value":"989"},"to":{"field":"region","value":"xq"}},{"from":{"field":"region","value":"990"},"to":{"field":"region","value":"xr"}},{"from":{"field":"region","value":"991"},"to":{"field":"region","value":"xs"}},{"from":{"field":"region","value":"992"},"to":{"field":"region","value":"xt"}},{"from":{"field":"region","value":"993"},"to":{"field":"region","value":"xu"}},{"from":{"field":"region","value":"994"},"to":{"field":"region","value":"xv"}},{"from":{"field":"region","value":"995"},"to":{"field":"region","value":"xw"}},{"from":{"field":"region","value":"996"},"to":{"field":"region","value":"xx"}},{"from":{"field":"region","value":"997"},"to":{"field":"region","value":"xy"}},{"from":{"field":"region","value":"998"},"to":{"field":"region","value":"xz"}},{"from":{"field":"region","value":"720"},"to":{"field":"region","value":"ye"}},{"from":{"field":"region","value":"887"},"to":{"field":"region","value":"ye"}},{"from":{"field":"region","value":"175"},"to":{"field":"region","value":"yt"}},{"from":{"field":"region","value":"710"},"to":{"field":"region","value":"za"}},{"from":{"field":"region","value":"894"},"to":{"field":"region","value":"zm"}},{"from":{"field":"region","value":"716"},"to":{"field":"region","value":"zw"}},{"from":{"field":"region","value":"999"},"to":{"field":"region","value":"zz"}},{"from":{"field":"variants","value":"aaland"},"to":{"field":"region","value":"ax"}},{"from":{"field":"variants","value":"polytoni"},"to":{"field":"variants","value":"polyton"}},{"from":{"field":"variants","value":"heploc"},"to":{"field":"variants","value":"alalc97"}},{"from":{"field":"variants","value":"arevela"},"to":{"field":"language","value":"hy"}},{"from":{"field":"variants","value":"arevmda"},"to":{"field":"language","value":"hyw"}}]');

/***/ }),

/***/ "./node_modules/bcp-47-normalize/lib/many.json":
/*!*****************************************************!*\
  !*** ./node_modules/bcp-47-normalize/lib/many.json ***!
  \*****************************************************/
/***/ (function(module) {

"use strict";
module.exports = JSON.parse('{"region":{"172":["ru","am","az","by","ge","kg","kz","md","tj","tm","ua","uz"],"200":["cz","sk"],"530":["cw","sx","bq"],"532":["cw","sx","bq"],"536":["sa","iq"],"582":["fm","mh","mp","pw"],"810":["ru","am","az","by","ee","ge","kz","kg","lv","lt","md","tj","tm","ua","uz"],"830":["je","gg"],"890":["rs","me","si","hr","mk","ba"],"891":["rs","me"],"an":["cw","sx","bq"],"cs":["rs","me"],"fq":["aq","tf"],"nt":["sa","iq"],"pc":["fm","mh","mp","pw"],"su":["ru","am","az","by","ee","ge","kz","kg","lv","lt","md","tj","tm","ua","uz"],"yu":["rs","me"],"062":["034","143"],"ant":["cw","sx","bq"],"scg":["rs","me"],"ntz":["sa","iq"],"sun":["ru","am","az","by","ee","ge","kz","kg","lv","lt","md","tj","tm","ua","uz"],"yug":["rs","me"]}}');

/***/ }),

/***/ "./node_modules/bcp-47-normalize/lib/matches.json":
/*!********************************************************!*\
  !*** ./node_modules/bcp-47-normalize/lib/matches.json ***!
  \********************************************************/
/***/ (function(module) {

"use strict";
module.exports = JSON.parse('[{"from":"in","to":"id"},{"from":"iw","to":"he"},{"from":"ji","to":"yi"},{"from":"jw","to":"jv"},{"from":"mo","to":"ro"},{"from":"scc","to":"sr"},{"from":"scr","to":"hr"},{"from":"aam","to":"aas"},{"from":"adp","to":"dz"},{"from":"aue","to":"ktz"},{"from":"ayx","to":"nun"},{"from":"bgm","to":"bcg"},{"from":"bjd","to":"drl"},{"from":"ccq","to":"rki"},{"from":"cjr","to":"mom"},{"from":"cka","to":"cmr"},{"from":"cmk","to":"xch"},{"from":"coy","to":"pij"},{"from":"cqu","to":"quh"},{"from":"drh","to":"mn"},{"from":"drw","to":"fa-af"},{"from":"gav","to":"dev"},{"from":"gfx","to":"vaj"},{"from":"ggn","to":"gvr"},{"from":"gti","to":"nyc"},{"from":"guv","to":"duz"},{"from":"hrr","to":"jal"},{"from":"ibi","to":"opa"},{"from":"ilw","to":"gal"},{"from":"jeg","to":"oyb"},{"from":"kgc","to":"tdf"},{"from":"kgh","to":"kml"},{"from":"koj","to":"kwv"},{"from":"krm","to":"bmf"},{"from":"ktr","to":"dtp"},{"from":"kvs","to":"gdj"},{"from":"kwq","to":"yam"},{"from":"kxe","to":"tvd"},{"from":"kzj","to":"dtp"},{"from":"kzt","to":"dtp"},{"from":"lii","to":"raq"},{"from":"lmm","to":"rmx"},{"from":"meg","to":"cir"},{"from":"mst","to":"mry"},{"from":"mwj","to":"vaj"},{"from":"myt","to":"mry"},{"from":"nad","to":"xny"},{"from":"ncp","to":"kdz"},{"from":"nnx","to":"ngv"},{"from":"nts","to":"pij"},{"from":"oun","to":"vaj"},{"from":"pcr","to":"adx"},{"from":"pmc","to":"huw"},{"from":"pmu","to":"phr"},{"from":"ppa","to":"bfy"},{"from":"ppr","to":"lcq"},{"from":"pry","to":"prt"},{"from":"puz","to":"pub"},{"from":"sca","to":"hle"},{"from":"skk","to":"oyb"},{"from":"tdu","to":"dtp"},{"from":"thc","to":"tpo"},{"from":"thx","to":"oyb"},{"from":"tie","to":"ras"},{"from":"tkk","to":"twm"},{"from":"tlw","to":"weo"},{"from":"tmp","to":"tyj"},{"from":"tne","to":"kak"},{"from":"tnf","to":"fa-af"},{"from":"tsf","to":"taj"},{"from":"uok","to":"ema"},{"from":"xba","to":"cax"},{"from":"xia","to":"acn"},{"from":"xkh","to":"waw"},{"from":"xsj","to":"suj"},{"from":"ybd","to":"rki"},{"from":"yma","to":"lrr"},{"from":"ymt","to":"mtm"},{"from":"yos","to":"zom"},{"from":"yuu","to":"yug"},{"from":"asd","to":"snz"},{"from":"dit","to":"dif"},{"from":"llo","to":"ngt"},{"from":"myd","to":"aog"},{"from":"nns","to":"nbr"},{"from":"sgn-br","to":"bzs"},{"from":"sgn-co","to":"csn"},{"from":"sgn-de","to":"gsg"},{"from":"sgn-dk","to":"dsl"},{"from":"sgn-fr","to":"fsl"},{"from":"sgn-gb","to":"bfi"},{"from":"sgn-gr","to":"gss"},{"from":"sgn-ie","to":"isg"},{"from":"sgn-it","to":"ise"},{"from":"sgn-jp","to":"jsl"},{"from":"sgn-mx","to":"mfs"},{"from":"sgn-ni","to":"ncs"},{"from":"sgn-nl","to":"dse"},{"from":"sgn-no","to":"nsi"},{"from":"sgn-pt","to":"psr"},{"from":"sgn-se","to":"swl"},{"from":"sgn-us","to":"ase"},{"from":"sgn-za","to":"sfs"},{"from":"no-bokmal","to":"nb"},{"from":"no-nynorsk","to":"nn"},{"from":"aa-saaho","to":"ssy"},{"from":"sh","to":"sr-latn"},{"from":"cnr","to":"sr-me"},{"from":"no","to":"nb"},{"from":"tl","to":"fil"},{"from":"az-az","to":"az-latn-az"},{"from":"bs-ba","to":"bs-latn-ba"},{"from":"ha-latn-gh","to":"ha-gh"},{"from":"ha-latn-ne","to":"ha-ne"},{"from":"ha-latn-ng","to":"ha-ng"},{"from":"kk-cyrl-kz","to":"kk-kz"},{"from":"ky-cyrl-kg","to":"ky-kg"},{"from":"ks-arab-in","to":"ks-in"},{"from":"mn-cyrl-mn","to":"mn-mn"},{"from":"ms-latn-bn","to":"ms-bn"},{"from":"ms-latn-my","to":"ms-my"},{"from":"ms-latn-sg","to":"ms-sg"},{"from":"pa-in","to":"pa-guru-in"},{"from":"pa-pk","to":"pa-arab-pk"},{"from":"shi-ma","to":"shi-tfng-ma"},{"from":"sr-ba","to":"sr-cyrl-ba"},{"from":"sr-me","to":"sr-latn-me"},{"from":"sr-rs","to":"sr-cyrl-rs"},{"from":"sr-xk","to":"sr-cyrl-xk"},{"from":"tzm-latn-ma","to":"tzm-ma"},{"from":"ug-arab-cn","to":"ug-cn"},{"from":"uz-af","to":"uz-arab-af"},{"from":"uz-uz","to":"uz-latn-uz"},{"from":"vai-lr","to":"vai-vaii-lr"},{"from":"yue-cn","to":"yue-hans-cn"},{"from":"yue-hk","to":"yue-hant-hk"},{"from":"zh-cn","to":"zh-hans-cn"},{"from":"zh-hk","to":"zh-hant-hk"},{"from":"zh-mo","to":"zh-hant-mo"},{"from":"zh-sg","to":"zh-hans-sg"},{"from":"zh-tw","to":"zh-hant-tw"},{"from":"aju","to":"jrb"},{"from":"als","to":"sq"},{"from":"arb","to":"ar"},{"from":"ayr","to":"ay"},{"from":"azj","to":"az"},{"from":"bcc","to":"bal"},{"from":"bcl","to":"bik"},{"from":"bxk","to":"luy"},{"from":"bxr","to":"bua"},{"from":"cld","to":"syr"},{"from":"cmn","to":"zh"},{"from":"cwd","to":"cr"},{"from":"dgo","to":"doi"},{"from":"dhd","to":"mwr"},{"from":"dik","to":"din"},{"from":"diq","to":"zza"},{"from":"lbk","to":"bnc"},{"from":"ekk","to":"et"},{"from":"emk","to":"man"},{"from":"esk","to":"ik"},{"from":"fat","to":"ak"},{"from":"fuc","to":"ff"},{"from":"gaz","to":"om"},{"from":"gbo","to":"grb"},{"from":"gno","to":"gon"},{"from":"gug","to":"gn"},{"from":"gya","to":"gba"},{"from":"hdn","to":"hai"},{"from":"hea","to":"hmn"},{"from":"ike","to":"iu"},{"from":"kmr","to":"ku"},{"from":"knc","to":"kr"},{"from":"kng","to":"kg"},{"from":"knn","to":"kok"},{"from":"kpv","to":"kv"},{"from":"lvs","to":"lv"},{"from":"mhr","to":"chm"},{"from":"mup","to":"raj"},{"from":"khk","to":"mn"},{"from":"npi","to":"ne"},{"from":"ojg","to":"oj"},{"from":"ory","to":"or"},{"from":"pbu","to":"ps"},{"from":"pes","to":"fa"},{"from":"plt","to":"mg"},{"from":"pnb","to":"lah"},{"from":"quz","to":"qu"},{"from":"rmy","to":"rom"},{"from":"spy","to":"kln"},{"from":"src","to":"sc"},{"from":"swh","to":"sw"},{"from":"ttq","to":"tmh"},{"from":"tw","to":"ak"},{"from":"umu","to":"del"},{"from":"uzn","to":"uz"},{"from":"xpe","to":"kpe"},{"from":"xsl","to":"den"},{"from":"ydd","to":"yi"},{"from":"zai","to":"zap"},{"from":"zsm","to":"ms"},{"from":"zyb","to":"za"},{"from":"him","to":"srx"},{"from":"mnk","to":"man"},{"from":"bh","to":"bho"},{"from":"prs","to":"fa-af"},{"from":"swc","to":"sw-cd"},{"from":"aar","to":"aa"},{"from":"abk","to":"ab"},{"from":"ave","to":"ae"},{"from":"afr","to":"af"},{"from":"aka","to":"ak"},{"from":"amh","to":"am"},{"from":"arg","to":"an"},{"from":"ara","to":"ar"},{"from":"asm","to":"as"},{"from":"ava","to":"av"},{"from":"aym","to":"ay"},{"from":"aze","to":"az"},{"from":"bak","to":"ba"},{"from":"bel","to":"be"},{"from":"bul","to":"bg"},{"from":"bih","to":"bho"},{"from":"bis","to":"bi"},{"from":"bam","to":"bm"},{"from":"ben","to":"bn"},{"from":"bod","to":"bo"},{"from":"bre","to":"br"},{"from":"bos","to":"bs"},{"from":"cat","to":"ca"},{"from":"che","to":"ce"},{"from":"cha","to":"ch"},{"from":"cos","to":"co"},{"from":"cre","to":"cr"},{"from":"ces","to":"cs"},{"from":"chu","to":"cu"},{"from":"chv","to":"cv"},{"from":"cym","to":"cy"},{"from":"dan","to":"da"},{"from":"deu","to":"de"},{"from":"div","to":"dv"},{"from":"dzo","to":"dz"},{"from":"ewe","to":"ee"},{"from":"ell","to":"el"},{"from":"eng","to":"en"},{"from":"epo","to":"eo"},{"from":"spa","to":"es"},{"from":"est","to":"et"},{"from":"eus","to":"eu"},{"from":"fas","to":"fa"},{"from":"ful","to":"ff"},{"from":"fin","to":"fi"},{"from":"fij","to":"fj"},{"from":"fao","to":"fo"},{"from":"fra","to":"fr"},{"from":"fry","to":"fy"},{"from":"gle","to":"ga"},{"from":"gla","to":"gd"},{"from":"glg","to":"gl"},{"from":"grn","to":"gn"},{"from":"guj","to":"gu"},{"from":"glv","to":"gv"},{"from":"hau","to":"ha"},{"from":"heb","to":"he"},{"from":"hin","to":"hi"},{"from":"hmo","to":"ho"},{"from":"hrv","to":"hr"},{"from":"hat","to":"ht"},{"from":"hun","to":"hu"},{"from":"hye","to":"hy"},{"from":"her","to":"hz"},{"from":"ina","to":"ia"},{"from":"ind","to":"id"},{"from":"ile","to":"ie"},{"from":"ibo","to":"ig"},{"from":"iii","to":"ii"},{"from":"ipk","to":"ik"},{"from":"ido","to":"io"},{"from":"isl","to":"is"},{"from":"ita","to":"it"},{"from":"iku","to":"iu"},{"from":"jpn","to":"ja"},{"from":"jav","to":"jv"},{"from":"kat","to":"ka"},{"from":"kon","to":"kg"},{"from":"kik","to":"ki"},{"from":"kua","to":"kj"},{"from":"kaz","to":"kk"},{"from":"kal","to":"kl"},{"from":"khm","to":"km"},{"from":"kan","to":"kn"},{"from":"kor","to":"ko"},{"from":"kau","to":"kr"},{"from":"kas","to":"ks"},{"from":"kur","to":"ku"},{"from":"kom","to":"kv"},{"from":"cor","to":"kw"},{"from":"kir","to":"ky"},{"from":"lat","to":"la"},{"from":"ltz","to":"lb"},{"from":"lug","to":"lg"},{"from":"lim","to":"li"},{"from":"lin","to":"ln"},{"from":"lao","to":"lo"},{"from":"lit","to":"lt"},{"from":"lub","to":"lu"},{"from":"lav","to":"lv"},{"from":"mlg","to":"mg"},{"from":"mah","to":"mh"},{"from":"mri","to":"mi"},{"from":"mkd","to":"mk"},{"from":"mal","to":"ml"},{"from":"mon","to":"mn"},{"from":"mol","to":"ro"},{"from":"mar","to":"mr"},{"from":"msa","to":"ms"},{"from":"mlt","to":"mt"},{"from":"mya","to":"my"},{"from":"nau","to":"na"},{"from":"nob","to":"nb"},{"from":"nde","to":"nd"},{"from":"nep","to":"ne"},{"from":"ndo","to":"ng"},{"from":"nld","to":"nl"},{"from":"nno","to":"nn"},{"from":"nor","to":"nb"},{"from":"nbl","to":"nr"},{"from":"nav","to":"nv"},{"from":"nya","to":"ny"},{"from":"oci","to":"oc"},{"from":"oji","to":"oj"},{"from":"orm","to":"om"},{"from":"ori","to":"or"},{"from":"oss","to":"os"},{"from":"pan","to":"pa"},{"from":"pli","to":"pi"},{"from":"pol","to":"pl"},{"from":"pus","to":"ps"},{"from":"por","to":"pt"},{"from":"que","to":"qu"},{"from":"roh","to":"rm"},{"from":"run","to":"rn"},{"from":"ron","to":"ro"},{"from":"rus","to":"ru"},{"from":"kin","to":"rw"},{"from":"san","to":"sa"},{"from":"srd","to":"sc"},{"from":"snd","to":"sd"},{"from":"sme","to":"se"},{"from":"sag","to":"sg"},{"from":"hbs","to":"sr-latn"},{"from":"sin","to":"si"},{"from":"slk","to":"sk"},{"from":"slv","to":"sl"},{"from":"smo","to":"sm"},{"from":"sna","to":"sn"},{"from":"som","to":"so"},{"from":"sqi","to":"sq"},{"from":"srp","to":"sr"},{"from":"ssw","to":"ss"},{"from":"sot","to":"st"},{"from":"sun","to":"su"},{"from":"swe","to":"sv"},{"from":"swa","to":"sw"},{"from":"tam","to":"ta"},{"from":"tel","to":"te"},{"from":"tgk","to":"tg"},{"from":"tha","to":"th"},{"from":"tir","to":"ti"},{"from":"tuk","to":"tk"},{"from":"tgl","to":"fil"},{"from":"tsn","to":"tn"},{"from":"ton","to":"to"},{"from":"tur","to":"tr"},{"from":"tso","to":"ts"},{"from":"tat","to":"tt"},{"from":"twi","to":"ak"},{"from":"tah","to":"ty"},{"from":"uig","to":"ug"},{"from":"ukr","to":"uk"},{"from":"urd","to":"ur"},{"from":"uzb","to":"uz"},{"from":"ven","to":"ve"},{"from":"vie","to":"vi"},{"from":"vol","to":"vo"},{"from":"wln","to":"wa"},{"from":"wol","to":"wo"},{"from":"xho","to":"xh"},{"from":"yid","to":"yi"},{"from":"yor","to":"yo"},{"from":"zha","to":"za"},{"from":"zho","to":"zh"},{"from":"zul","to":"zu"},{"from":"alb","to":"sq"},{"from":"arm","to":"hy"},{"from":"baq","to":"eu"},{"from":"bur","to":"my"},{"from":"chi","to":"zh"},{"from":"cze","to":"cs"},{"from":"dut","to":"nl"},{"from":"fre","to":"fr"},{"from":"geo","to":"ka"},{"from":"ger","to":"de"},{"from":"gre","to":"el"},{"from":"ice","to":"is"},{"from":"mac","to":"mk"},{"from":"mao","to":"mi"},{"from":"may","to":"ms"},{"from":"per","to":"fa"},{"from":"rum","to":"ro"},{"from":"slo","to":"sk"},{"from":"tib","to":"bo"},{"from":"wel","to":"cy"}]');

/***/ }),

/***/ "./node_modules/bcp-47/lib/normalize.json":
/*!************************************************!*\
  !*** ./node_modules/bcp-47/lib/normalize.json ***!
  \************************************************/
/***/ (function(module) {

"use strict";
module.exports = JSON.parse('{"en-gb-oed":"en-GB-oxendict","i-ami":"ami","i-bnn":"bnn","i-default":null,"i-enochian":null,"i-hak":"hak","i-klingon":"tlh","i-lux":"lb","i-mingo":null,"i-navajo":"nv","i-pwn":"pwn","i-tao":"tao","i-tay":"tay","i-tsu":"tsu","sgn-be-fr":"sfb","sgn-be-nl":"vgt","sgn-ch-de":"sgg","art-lojban":"jbo","cel-gaulish":null,"no-bok":"nb","no-nyn":"nn","zh-guoyu":"cmn","zh-hakka":"hak","zh-min":null,"zh-min-nan":"nan","zh-xiang":"hsn"}');

/***/ }),

/***/ "./node_modules/bcp-47/lib/regular.json":
/*!**********************************************!*\
  !*** ./node_modules/bcp-47/lib/regular.json ***!
  \**********************************************/
/***/ (function(module) {

"use strict";
module.exports = JSON.parse('["art-lojban","cel-gaulish","no-bok","no-nyn","zh-guoyu","zh-hakka","zh-min","zh-min-nan","zh-xiang"]');

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/amd options */
/******/ 	!function() {
/******/ 		__webpack_require__.amdO = {};
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	!function() {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = function(module) {
/******/ 			var getter = module && module.__esModule ?
/******/ 				function() { return module['default']; } :
/******/ 				function() { return module; };
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/define property getters */
/******/ 	!function() {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = function(exports, definition) {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/global */
/******/ 	!function() {
/******/ 		__webpack_require__.g = (function() {
/******/ 			if (typeof globalThis === 'object') return globalThis;
/******/ 			try {
/******/ 				return this || new Function('return this')();
/******/ 			} catch (e) {
/******/ 				if (typeof window === 'object') return window;
/******/ 			}
/******/ 		})();
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	!function() {
/******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ 	}();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	!function() {
/******/ 		// 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 });
/******/ 		};
/******/ 	}();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
!function() {
"use strict";
/*!******************!*\
  !*** ./index.js ***!
  \******************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Debug": function() { return /* reexport safe */ _src_core_Debug__WEBPACK_IMPORTED_MODULE_5__["default"]; },
/* harmony export */   "MediaPlayer": function() { return /* reexport safe */ _index_mediaplayerOnly__WEBPACK_IMPORTED_MODULE_0__.MediaPlayer; },
/* harmony export */   "MediaPlayerFactory": function() { return /* reexport safe */ _src_streaming_MediaPlayerFactory__WEBPACK_IMPORTED_MODULE_4__["default"]; },
/* harmony export */   "MetricsReporting": function() { return /* reexport safe */ _src_streaming_metrics_MetricsReporting__WEBPACK_IMPORTED_MODULE_2__["default"]; },
/* harmony export */   "Protection": function() { return /* reexport safe */ _src_streaming_protection_Protection__WEBPACK_IMPORTED_MODULE_3__["default"]; },
/* harmony export */   "supportsMediaSource": function() { return /* reexport safe */ _src_streaming_utils_Capabilities__WEBPACK_IMPORTED_MODULE_1__.supportsMediaSource; }
/* harmony export */ });
/* harmony import */ var _index_mediaplayerOnly__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index_mediaplayerOnly */ "./index_mediaplayerOnly.js");
/* harmony import */ var _src_streaming_utils_Capabilities__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./src/streaming/utils/Capabilities */ "./src/streaming/utils/Capabilities.js");
/* harmony import */ var _src_streaming_metrics_MetricsReporting__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./src/streaming/metrics/MetricsReporting */ "./src/streaming/metrics/MetricsReporting.js");
/* harmony import */ var _src_streaming_protection_Protection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./src/streaming/protection/Protection */ "./src/streaming/protection/Protection.js");
/* harmony import */ var _src_streaming_MediaPlayerFactory__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./src/streaming/MediaPlayerFactory */ "./src/streaming/MediaPlayerFactory.js");
/* harmony import */ var _src_core_Debug__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./src/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.
 */






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);

}();
__webpack_exports__ = __webpack_exports__["default"];
/******/ 	return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=dash.all.debug.js.map