import C from "./index-resolve-url.js";
import K from "./index-window.js";
import X from "./index-decode-b64-to-uint8-array.js";
import { l as q } from "./index-_virtual34.js";
var w = function(e) {
  return !!e && typeof e == "object";
}, S = function o() {
  for (var e = arguments.length, n = new Array(e), t = 0; t < e; t++)
    n[t] = arguments[t];
  return n.reduce(function(r, a) {
    return typeof a != "object" || Object.keys(a).forEach(function(i) {
      Array.isArray(r[i]) && Array.isArray(a[i]) ? r[i] = r[i].concat(a[i]) : w(r[i]) && w(a[i]) ? r[i] = o(r[i], a[i]) : r[i] = a[i];
    }), r;
  }, {});
}, Z = function(e) {
  return Object.keys(e).map(function(n) {
    return e[n];
  });
}, J = function(e, n) {
  for (var t = [], r = e; r < n; r++)
    t.push(r);
  return t;
}, O = function(e) {
  return e.reduce(function(n, t) {
    return n.concat(t);
  }, []);
}, H = function(e) {
  if (!e.length)
    return [];
  for (var n = [], t = 0; t < e.length; t++)
    n.push(e[t]);
  return n;
}, Q = function(e, n) {
  return e.reduce(function(t, r, a) {
    return r[n] && t.push(a), t;
  }, []);
}, E = {
  INVALID_NUMBER_OF_PERIOD: "INVALID_NUMBER_OF_PERIOD",
  DASH_EMPTY_MANIFEST: "DASH_EMPTY_MANIFEST",
  DASH_INVALID_XML: "DASH_INVALID_XML",
  NO_BASE_URL: "NO_BASE_URL",
  SEGMENT_TIME_UNSPECIFIED: "SEGMENT_TIME_UNSPECIFIED",
  UNSUPPORTED_UTC_TIMING_SCHEME: "UNSUPPORTED_UTC_TIMING_SCHEME"
}, N = function(e) {
  var n = e.baseUrl, t = n === void 0 ? "" : n, r = e.source, a = r === void 0 ? "" : r, i = e.range, u = i === void 0 ? "" : i, s = e.indexRange, d = s === void 0 ? "" : s, m = {
    uri: a,
    resolvedUri: C(t || "", a)
  };
  if (u || d) {
    var c = u || d, f = c.split("-"), l = parseInt(f[0], 10), v = parseInt(f[1], 10);
    m.byterange = {
      length: v - l + 1,
      offset: l
    };
  }
  return m;
}, k = function(e) {
  var n = e.offset + e.length - 1;
  return e.offset + "-" + n;
}, $ = function(e) {
  return e && typeof e != "number" && (e = parseInt(e, 10)), isNaN(e) ? null : e;
}, ee = {
  /**
   * Returns the entire range of available segments for a static MPD
   *
   * @param {Object} attributes
   *        Inheritied MPD attributes
   * @return {{ start: number, end: number }}
   *         The start and end numbers for available segments
   */
  static: function(e) {
    var n = e.duration, t = e.timescale, r = t === void 0 ? 1 : t, a = e.sourceDuration, i = e.periodDuration, u = $(e.endNumber), s = n / r;
    return typeof u == "number" ? {
      start: 0,
      end: u
    } : typeof i == "number" ? {
      start: 0,
      end: i / s
    } : {
      start: 0,
      end: a / s
    };
  },
  /**
   * Returns the current live window range of available segments for a dynamic MPD
   *
   * @param {Object} attributes
   *        Inheritied MPD attributes
   * @return {{ start: number, end: number }}
   *         The start and end numbers for available segments
   */
  dynamic: function(e) {
    var n = e.NOW, t = e.clientOffset, r = e.availabilityStartTime, a = e.timescale, i = a === void 0 ? 1 : a, u = e.duration, s = e.start, d = s === void 0 ? 0 : s, m = e.minimumUpdatePeriod, c = m === void 0 ? 0 : m, f = e.timeShiftBufferDepth, l = f === void 0 ? 1 / 0 : f, v = $(e.endNumber), p = (n + t) / 1e3, h = r + d, I = p + c, U = I - h, T = Math.ceil(U * i / u), y = Math.floor((p - h - l) * i / u), D = Math.floor((p - h) * i / u);
    return {
      start: Math.max(0, y),
      end: typeof v == "number" ? v : Math.min(T, D)
    };
  }
}, te = function(e) {
  return function(n, t) {
    var r = e.duration, a = e.timescale, i = a === void 0 ? 1 : a, u = e.periodIndex, s = e.startNumber, d = s === void 0 ? 1 : s;
    return {
      number: d + n,
      duration: r / i,
      timeline: u,
      time: t * r
    };
  };
}, L = function(e) {
  var n = e.type, t = e.duration, r = e.timescale, a = r === void 0 ? 1 : r, i = e.periodDuration, u = e.sourceDuration, s = ee[n](e), d = s.start, m = s.end, c = J(d, m).map(te(e));
  if (n === "static") {
    var f = c.length - 1, l = typeof i == "number" ? i : u;
    c[f].duration = l - t / a * f;
  }
  return c;
}, G = function(e) {
  var n = e.baseUrl, t = e.initialization, r = t === void 0 ? {} : t, a = e.sourceDuration, i = e.indexRange, u = i === void 0 ? "" : i, s = e.duration;
  if (!n)
    throw new Error(E.NO_BASE_URL);
  var d = N({
    baseUrl: n,
    source: r.sourceURL,
    range: r.range
  }), m = N({
    baseUrl: n,
    source: n,
    indexRange: u
  });
  if (m.map = d, s) {
    var c = L(e);
    c.length && (m.duration = c[0].duration, m.timeline = c[0].timeline);
  } else a && (m.duration = a, m.timeline = 0);
  return m.number = 0, [m];
}, re = function(e, n, t) {
  for (var r = e.sidx.map ? e.sidx.map : null, a = e.sidx.duration, i = e.timeline || 0, u = e.sidx.byterange, s = u.offset + u.length, d = n.timescale, m = n.references.filter(function(R) {
    return R.referenceType !== 1;
  }), c = [], f = e.endList ? "static" : "dynamic", l = s + n.firstOffset, v = 0; v < m.length; v++) {
    var p = n.references[v], h = p.referencedSize, I = p.subsegmentDuration, U = l + h - 1, T = l + "-" + U, y = {
      baseUrl: t,
      timescale: d,
      timeline: i,
      // this is used in parseByDuration
      periodIndex: i,
      duration: I,
      sourceDuration: a,
      indexRange: T,
      type: f
    }, D = G(y)[0];
    r && (D.map = r), c.push(D), l += h;
  }
  return e.segments = c, e;
}, ne = function(e) {
  return e && e.uri + "-" + k(e.byterange);
}, F = function(e) {
  var n = Z(e.reduce(function(t, r) {
    var a = r.attributes.id + (r.attributes.lang || "");
    if (t[a]) {
      var i;
      r.segments[0] && (r.segments[0].discontinuity = !0), (i = t[a].segments).push.apply(i, r.segments), r.attributes.contentProtection && (t[a].attributes.contentProtection = r.attributes.contentProtection);
    } else
      t[a] = r;
    return t;
  }, {}));
  return n.map(function(t) {
    return t.discontinuityStarts = Q(t.segments, "discontinuity"), t;
  });
}, x = function(e, n) {
  var t = ne(e.sidx), r = t && n[t] && n[t].sidx;
  return r && re(e, r, e.sidx.resolvedUri), e;
}, ae = function(e, n) {
  if (n === void 0 && (n = {}), !Object.keys(n).length)
    return e;
  for (var t in e)
    e[t] = x(e[t], n);
  return e;
}, ie = function(e, n) {
  var t, r = e.attributes, a = e.segments, i = e.sidx, u = {
    attributes: (t = {
      NAME: r.id,
      BANDWIDTH: r.bandwidth,
      CODECS: r.codecs
    }, t["PROGRAM-ID"] = 1, t),
    uri: "",
    endList: r.type === "static",
    timeline: r.periodIndex,
    resolvedUri: "",
    targetDuration: r.duration,
    segments: a,
    mediaSequence: a.length ? a[0].number : 1
  };
  return r.contentProtection && (u.contentProtection = r.contentProtection), i && (u.sidx = i), n && (u.attributes.AUDIO = "audio", u.attributes.SUBTITLES = "subs"), u;
}, oe = function(e) {
  var n, t = e.attributes, r = e.segments;
  typeof r > "u" && (r = [{
    uri: t.baseUrl,
    timeline: t.periodIndex,
    resolvedUri: t.baseUrl || "",
    duration: t.sourceDuration,
    number: 0
  }], t.duration = t.sourceDuration);
  var a = (n = {
    NAME: t.id,
    BANDWIDTH: t.bandwidth
  }, n["PROGRAM-ID"] = 1, n);
  return t.codecs && (a.CODECS = t.codecs), {
    attributes: a,
    uri: "",
    endList: t.type === "static",
    timeline: t.periodIndex,
    resolvedUri: t.baseUrl || "",
    targetDuration: t.duration,
    segments: r,
    mediaSequence: r.length ? r[0].number : 1
  };
}, ue = function(e, n, t) {
  n === void 0 && (n = {}), t === void 0 && (t = !1);
  var r, a = e.reduce(function(u, s) {
    var d = s.attributes.role && s.attributes.role.value || "", m = s.attributes.lang || "", c = s.attributes.label || "main";
    if (m && !s.attributes.label) {
      var f = d ? " (" + d + ")" : "";
      c = "" + s.attributes.lang + f;
    }
    u[c] || (u[c] = {
      language: m,
      autoselect: !0,
      default: d === "main",
      playlists: [],
      uri: ""
    });
    var l = x(ie(s, t), n);
    return u[c].playlists.push(l), typeof r > "u" && d === "main" && (r = s, r.default = !0), u;
  }, {});
  if (!r) {
    var i = Object.keys(a)[0];
    a[i].default = !0;
  }
  return a;
}, se = function(e, n) {
  return n === void 0 && (n = {}), e.reduce(function(t, r) {
    var a = r.attributes.lang || "text";
    return t[a] || (t[a] = {
      language: a,
      default: !1,
      autoselect: !1,
      playlists: [],
      uri: ""
    }), t[a].playlists.push(x(oe(r), n)), t;
  }, {});
}, de = function(e) {
  return e.reduce(function(n, t) {
    return t && t.forEach(function(r) {
      var a = r.channel, i = r.language;
      n[i] = {
        autoselect: !1,
        default: !1,
        instreamId: a,
        language: i
      }, r.hasOwnProperty("aspectRatio") && (n[i].aspectRatio = r.aspectRatio), r.hasOwnProperty("easyReader") && (n[i].easyReader = r.easyReader), r.hasOwnProperty("3D") && (n[i]["3D"] = r["3D"]);
    }), n;
  }, {});
}, me = function(e) {
  var n, t = e.attributes, r = e.segments, a = e.sidx, i = {
    attributes: (n = {
      NAME: t.id,
      AUDIO: "audio",
      SUBTITLES: "subs",
      RESOLUTION: {
        width: t.width,
        height: t.height
      },
      CODECS: t.codecs,
      BANDWIDTH: t.bandwidth
    }, n["PROGRAM-ID"] = 1, n),
    uri: "",
    endList: t.type === "static",
    timeline: t.periodIndex,
    resolvedUri: "",
    targetDuration: t.duration,
    segments: r,
    mediaSequence: r.length ? r[0].number : 1
  };
  return t.contentProtection && (i.contentProtection = t.contentProtection), a && (i.sidx = a), i;
}, fe = function(e) {
  var n = e.attributes;
  return n.mimeType === "video/mp4" || n.mimeType === "video/webm" || n.contentType === "video";
}, ce = function(e) {
  var n = e.attributes;
  return n.mimeType === "audio/mp4" || n.mimeType === "audio/webm" || n.contentType === "audio";
}, le = function(e) {
  var n = e.attributes;
  return n.mimeType === "text/vtt" || n.contentType === "text";
}, ve = function(e, n, t) {
  var r;
  if (t === void 0 && (t = {}), !e.length)
    return {};
  var a = e[0].attributes, i = a.sourceDuration, u = a.type, s = a.suggestedPresentationDelay, d = a.minimumUpdatePeriod, m = F(e.filter(fe)).map(me), c = F(e.filter(ce)), f = e.filter(le), l = e.map(function(h) {
    return h.attributes.captionServices;
  }).filter(Boolean), v = {
    allowCache: !0,
    discontinuityStarts: [],
    segments: [],
    endList: !0,
    mediaGroups: (r = {
      AUDIO: {},
      VIDEO: {}
    }, r["CLOSED-CAPTIONS"] = {}, r.SUBTITLES = {}, r),
    uri: "",
    duration: i,
    playlists: ae(m, t)
  };
  d >= 0 && (v.minimumUpdatePeriod = d * 1e3), n && (v.locations = n), u === "dynamic" && (v.suggestedPresentationDelay = s);
  var p = v.playlists.length === 0;
  return c.length && (v.mediaGroups.AUDIO.audio = ue(c, t, p)), f.length && (v.mediaGroups.SUBTITLES.subs = se(f, t)), l.length && (v.mediaGroups["CLOSED-CAPTIONS"].cc = de(l)), v;
}, pe = function(e, n, t) {
  var r = e.NOW, a = e.clientOffset, i = e.availabilityStartTime, u = e.timescale, s = u === void 0 ? 1 : u, d = e.start, m = d === void 0 ? 0 : d, c = e.minimumUpdatePeriod, f = c === void 0 ? 0 : c, l = (r + a) / 1e3, v = i + m, p = l + f, h = p - v;
  return Math.ceil((h * s - n) / t);
}, W = function(e, n) {
  for (var t = e.type, r = e.minimumUpdatePeriod, a = r === void 0 ? 0 : r, i = e.media, u = i === void 0 ? "" : i, s = e.sourceDuration, d = e.timescale, m = d === void 0 ? 1 : d, c = e.startNumber, f = c === void 0 ? 1 : c, l = e.periodIndex, v = [], p = -1, h = 0; h < n.length; h++) {
    var I = n[h], U = I.d, T = I.r || 0, y = I.t || 0;
    p < 0 && (p = y), y && y > p && (p = y);
    var D = void 0;
    if (T < 0) {
      var R = h + 1;
      R === n.length ? t === "dynamic" && a > 0 && u.indexOf("$Number$") > 0 ? D = pe(e, p, U) : D = (s * m - p) / U : D = (n[R].t - p) / U;
    } else
      D = T + 1;
    for (var Y = f + v.length + D, A = f + v.length; A < Y; )
      v.push({
        number: A,
        duration: U / m,
        time: p,
        timeline: l
      }), p += U, A++;
  }
  return v;
}, ge = /\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g, he = function(e) {
  return function(n, t, r, a) {
    if (n === "$$")
      return "$";
    if (typeof e[t] > "u")
      return n;
    var i = "" + e[t];
    return t === "RepresentationID" || (r ? a = parseInt(a, 10) : a = 1, i.length >= a) ? i : "" + new Array(a - i.length + 1).join("0") + i;
  };
}, z = function(e, n) {
  return e.replace(ge, he(n));
}, be = function(e, n) {
  return !e.duration && !n ? [{
    number: e.startNumber || 1,
    duration: e.sourceDuration,
    time: 0,
    timeline: e.periodIndex
  }] : e.duration ? L(e) : W(e, n);
}, Se = function(e, n) {
  var t = {
    RepresentationID: e.id,
    Bandwidth: e.bandwidth || 0
  }, r = e.initialization, a = r === void 0 ? {
    sourceURL: "",
    range: ""
  } : r, i = N({
    baseUrl: e.baseUrl,
    source: z(a.sourceURL, t),
    range: a.range
  }), u = be(e, n);
  return u.map(function(s) {
    t.Number = s.number, t.Time = s.time;
    var d = z(e.media || "", t), m = e.timescale || 1, c = e.presentationTimeOffset || 0, f = (
      // Even if the @t attribute is not specified for the segment, segment.time is
      // calculated in mpd-parser prior to this, so it's assumed to be available.
      e.periodStart + (s.time - c) / m
    ), l = {
      uri: d,
      timeline: s.timeline,
      duration: s.duration,
      resolvedUri: C(e.baseUrl || "", d),
      map: i,
      number: s.number,
      presentationTime: f
    };
    return l;
  });
}, Ie = function(e, n) {
  var t = e.baseUrl, r = e.initialization, a = r === void 0 ? {} : r, i = N({
    baseUrl: t,
    source: a.sourceURL,
    range: a.range
  }), u = N({
    baseUrl: t,
    source: n.media,
    range: n.mediaRange
  });
  return u.map = i, u;
}, Ue = function(e, n) {
  var t = e.duration, r = e.segmentUrls, a = r === void 0 ? [] : r, i = e.periodStart;
  if (!t && !n || t && n)
    throw new Error(E.SEGMENT_TIME_UNSPECIFIED);
  var u = a.map(function(m) {
    return Ie(e, m);
  }), s;
  t && (s = L(e)), n && (s = W(e, n));
  var d = s.map(function(m, c) {
    if (u[c]) {
      var f = u[c], l = e.timescale || 1, v = e.presentationTimeOffset || 0;
      return f.timeline = m.timeline, f.duration = m.duration, f.number = m.number, f.presentationTime = i + (m.time - v) / l, f;
    }
  }).filter(function(m) {
    return m;
  });
  return d;
}, De = function(e) {
  var n = e.attributes, t = e.segmentInfo, r, a;
  t.template ? (a = Se, r = S(n, t.template)) : t.base ? (a = G, r = S(n, t.base)) : t.list && (a = Ue, r = S(n, t.list));
  var i = {
    attributes: n
  };
  if (!a)
    return i;
  var u = a(r, t.segmentTimeline);
  if (r.duration) {
    var s = r, d = s.duration, m = s.timescale, c = m === void 0 ? 1 : m;
    r.duration = d / c;
  } else u.length ? r.duration = u.reduce(function(f, l) {
    return Math.max(f, Math.ceil(l.duration));
  }, 0) : r.duration = 0;
  return i.attributes = r, i.segments = u, t.base && r.indexRange && (i.sidx = u[0], i.segments = []), i;
}, ye = function(e) {
  return e.map(De);
}, g = function(e, n) {
  return H(e.childNodes).filter(function(t) {
    var r = t.tagName;
    return r === n;
  });
}, B = function(e) {
  return e.textContent.trim();
}, P = function(e) {
  var n = 31536e3, t = 720 * 60 * 60, r = 1440 * 60, a = 3600, i = 60, u = /P(?:(\d*)Y)?(?:(\d*)M)?(?:(\d*)D)?(?:T(?:(\d*)H)?(?:(\d*)M)?(?:([\d.]*)S)?)?/, s = u.exec(e);
  if (!s)
    return 0;
  var d = s.slice(1), m = d[0], c = d[1], f = d[2], l = d[3], v = d[4], p = d[5];
  return parseFloat(m || 0) * n + parseFloat(c || 0) * t + parseFloat(f || 0) * r + parseFloat(l || 0) * a + parseFloat(v || 0) * i + parseFloat(p || 0);
}, Te = function(e) {
  var n = /^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?$/;
  return n.test(e) && (e += "Z"), Date.parse(e);
}, V = {
  /**
   * Specifies the duration of the entire Media Presentation. Format is a duration string
   * as specified in ISO 8601
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The duration in seconds
   */
  mediaPresentationDuration: function(e) {
    return P(e);
  },
  /**
   * Specifies the Segment availability start time for all Segments referred to in this
   * MPD. For a dynamic manifest, it specifies the anchor for the earliest availability
   * time. Format is a date string as specified in ISO 8601
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The date as seconds from unix epoch
   */
  availabilityStartTime: function(e) {
    return Te(e) / 1e3;
  },
  /**
   * Specifies the smallest period between potential changes to the MPD. Format is a
   * duration string as specified in ISO 8601
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The duration in seconds
   */
  minimumUpdatePeriod: function(e) {
    return P(e);
  },
  /**
   * Specifies the suggested presentation delay. Format is a
   * duration string as specified in ISO 8601
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The duration in seconds
   */
  suggestedPresentationDelay: function(e) {
    return P(e);
  },
  /**
   * specifices the type of mpd. Can be either "static" or "dynamic"
   *
   * @param {string} value
   *        value of attribute as a string
   *
   * @return {string}
   *         The type as a string
   */
  type: function(e) {
    return e;
  },
  /**
   * Specifies the duration of the smallest time shifting buffer for any Representation
   * in the MPD. Format is a duration string as specified in ISO 8601
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The duration in seconds
   */
  timeShiftBufferDepth: function(e) {
    return P(e);
  },
  /**
   * Specifies the PeriodStart time of the Period relative to the availabilityStarttime.
   * Format is a duration string as specified in ISO 8601
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The duration in seconds
   */
  start: function(e) {
    return P(e);
  },
  /**
   * Specifies the width of the visual presentation
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed width
   */
  width: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the height of the visual presentation
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed height
   */
  height: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the bitrate of the representation
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed bandwidth
   */
  bandwidth: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the number of the first Media Segment in this Representation in the Period
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed number
   */
  startNumber: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the timescale in units per seconds
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed timescale
   */
  timescale: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the presentationTimeOffset.
   *
   * @param {string} value
   *        value of the attribute as a string
   *
   * @return {number}
   *         The parsed presentationTimeOffset
   */
  presentationTimeOffset: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the constant approximate Segment duration
   * NOTE: The <Period> element also contains an @duration attribute. This duration
   *       specifies the duration of the Period. This attribute is currently not
   *       supported by the rest of the parser, however we still check for it to prevent
   *       errors.
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed duration
   */
  duration: function(e) {
    var n = parseInt(e, 10);
    return isNaN(n) ? P(e) : n;
  },
  /**
   * Specifies the Segment duration, in units of the value of the @timescale.
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed duration
   */
  d: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the MPD start time, in @timescale units, the first Segment in the series
   * starts relative to the beginning of the Period
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed time
   */
  t: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Specifies the repeat count of the number of following contiguous Segments with the
   * same duration expressed by the value of @d
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {number}
   *         The parsed number
   */
  r: function(e) {
    return parseInt(e, 10);
  },
  /**
   * Default parser for all other attributes. Acts as a no-op and just returns the value
   * as a string
   *
   * @param {string} value
   *        value of attribute as a string
   * @return {string}
   *         Unparsed value
   */
  DEFAULT: function(e) {
    return e;
  }
}, b = function(e) {
  return e && e.attributes ? H(e.attributes).reduce(function(n, t) {
    var r = V[t.name] || V.DEFAULT;
    return n[t.name] = r(t.value), n;
  }, {}) : {};
}, Pe = {
  "urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b": "org.w3.clearkey",
  "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed": "com.widevine.alpha",
  "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95": "com.microsoft.playready",
  "urn:uuid:f239e769-efa3-4850-9c16-a903c6932efb": "com.adobe.primetime"
}, _ = function(e, n) {
  return n.length ? O(e.map(function(t) {
    return n.map(function(r) {
      return C(t, B(r));
    });
  })) : e;
}, M = function(e) {
  var n = g(e, "SegmentTemplate")[0], t = g(e, "SegmentList")[0], r = t && g(t, "SegmentURL").map(function(f) {
    return S({
      tag: "SegmentURL"
    }, b(f));
  }), a = g(e, "SegmentBase")[0], i = t || n, u = i && g(i, "SegmentTimeline")[0], s = t || a || n, d = s && g(s, "Initialization")[0], m = n && b(n);
  m && d ? m.initialization = d && b(d) : m && m.initialization && (m.initialization = {
    sourceURL: m.initialization
  });
  var c = {
    template: m,
    segmentTimeline: u && g(u, "S").map(function(f) {
      return b(f);
    }),
    list: t && S(b(t), {
      segmentUrls: r,
      initialization: b(d)
    }),
    base: a && S(b(a), {
      initialization: b(d)
    })
  };
  return Object.keys(c).forEach(function(f) {
    c[f] || delete c[f];
  }), c;
}, Ee = function(e, n, t) {
  return function(r) {
    var a = g(r, "BaseURL"), i = _(n, a), u = S(e, b(r)), s = M(r);
    return i.map(function(d) {
      return {
        segmentInfo: S(t, s),
        attributes: S(u, {
          baseUrl: d
        })
      };
    });
  };
}, Ne = function(e) {
  return e.reduce(function(n, t) {
    var r = b(t), a = Pe[r.schemeIdUri];
    if (a) {
      n[a] = {
        attributes: r
      };
      var i = g(t, "cenc:pssh")[0];
      if (i) {
        var u = B(i), s = u && X(u);
        n[a].pssh = s;
      }
    }
    return n;
  }, {});
}, Re = function(e) {
  if (e.schemeIdUri === "urn:scte:dash:cc:cea-608:2015") {
    var n = typeof e.value != "string" ? [] : e.value.split(";");
    return n.map(function(r) {
      var a, i;
      if (i = r, /^CC\d=/.test(r)) {
        var u = r.split("=");
        a = u[0], i = u[1];
      } else /^CC\d$/.test(r) && (a = r);
      return {
        channel: a,
        language: i
      };
    });
  } else if (e.schemeIdUri === "urn:scte:dash:cc:cea-708:2015") {
    var t = typeof e.value != "string" ? [] : e.value.split(";");
    return t.map(function(r) {
      var a = {
        // service or channel number 1-63
        channel: void 0,
        // language is a 3ALPHA per ISO 639.2/B
        // field is required
        language: void 0,
        // BIT 1/0 or ?
        // default value is 1, meaning 16:9 aspect ratio, 0 is 4:3, ? is unknown
        aspectRatio: 1,
        // BIT 1/0
        // easy reader flag indicated the text is tailed to the needs of beginning readers
        // default 0, or off
        easyReader: 0,
        // BIT 1/0
        // If 3d metadata is present (CEA-708.1) then 1
        // default 0
        "3D": 0
      };
      if (/=/.test(r)) {
        var i = r.split("="), u = i[0], s = i[1], d = s === void 0 ? "" : s;
        a.channel = u, a.language = r, d.split(",").forEach(function(m) {
          var c = m.split(":"), f = c[0], l = c[1];
          f === "lang" ? a.language = l : f === "er" ? a.easyReader = Number(l) : f === "war" ? a.aspectRatio = Number(l) : f === "3D" && (a["3D"] = Number(l));
        });
      } else
        a.language = r;
      return a.channel && (a.channel = "SERVICE" + a.channel), a;
    });
  }
}, Oe = function(e, n, t) {
  return function(r) {
    var a = b(r), i = _(n, g(r, "BaseURL")), u = g(r, "Role")[0], s = {
      role: b(u)
    }, d = S(e, a, s), m = g(r, "Accessibility")[0], c = Re(b(m));
    c && (d = S(d, {
      captionServices: c
    }));
    var f = g(r, "Label")[0];
    if (f && f.childNodes.length) {
      var l = f.childNodes[0].nodeValue.trim();
      d = S(d, {
        label: l
      });
    }
    var v = Ne(g(r, "ContentProtection"));
    Object.keys(v).length && (d = S(d, {
      contentProtection: v
    }));
    var p = M(r), h = g(r, "Representation"), I = S(t, p);
    return O(h.map(Ee(d, i, I)));
  };
}, _e = function(e, n) {
  return function(t, r) {
    var a = _(n, g(t.node, "BaseURL")), i = parseInt(t.attributes.id, 10), u = K.isNaN(i) ? r : i, s = S(e, {
      periodIndex: u,
      periodStart: t.attributes.start
    });
    typeof t.attributes.duration == "number" && (s.periodDuration = t.attributes.duration);
    var d = g(t.node, "AdaptationSet"), m = M(t.node);
    return O(d.map(Oe(s, a, m)));
  };
}, Ae = function(e) {
  var n = e.attributes, t = e.priorPeriodAttributes, r = e.mpdType;
  return typeof n.start == "number" ? n.start : t && typeof t.start == "number" && typeof t.duration == "number" ? t.start + t.duration : !t && r === "static" ? 0 : null;
}, Ce = function(e, n) {
  n === void 0 && (n = {});
  var t = n, r = t.manifestUri, a = r === void 0 ? "" : r, i = t.NOW, u = i === void 0 ? Date.now() : i, s = t.clientOffset, d = s === void 0 ? 0 : s, m = g(e, "Period");
  if (!m.length)
    throw new Error(E.INVALID_NUMBER_OF_PERIOD);
  var c = g(e, "Location"), f = b(e), l = _([a], g(e, "BaseURL"));
  f.type = f.type || "static", f.sourceDuration = f.mediaPresentationDuration || 0, f.NOW = u, f.clientOffset = d, c.length && (f.locations = c.map(B));
  var v = [];
  return m.forEach(function(p, h) {
    var I = b(p), U = v[h - 1];
    I.start = Ae({
      attributes: I,
      priorPeriodAttributes: U ? U.attributes : null,
      mpdType: f.type
    }), v.push({
      node: p,
      attributes: I
    });
  }), {
    locations: f.locations,
    representationInfo: O(v.map(_e(f, l)))
  };
}, j = function(e) {
  if (e === "")
    throw new Error(E.DASH_EMPTY_MANIFEST);
  var n = new q.DOMParser(), t, r;
  try {
    t = n.parseFromString(e, "application/xml"), r = t && t.documentElement.tagName === "MPD" ? t.documentElement : null;
  } catch {
  }
  if (!r || r && r.getElementsByTagName("parsererror").length > 0)
    throw new Error(E.DASH_INVALID_XML);
  return r;
}, Le = function(e) {
  var n = g(e, "UTCTiming")[0];
  if (!n)
    return null;
  var t = b(n);
  switch (t.schemeIdUri) {
    case "urn:mpeg:dash:utc:http-head:2014":
    case "urn:mpeg:dash:utc:http-head:2012":
      t.method = "HEAD";
      break;
    case "urn:mpeg:dash:utc:http-xsdate:2014":
    case "urn:mpeg:dash:utc:http-iso:2014":
    case "urn:mpeg:dash:utc:http-xsdate:2012":
    case "urn:mpeg:dash:utc:http-iso:2012":
      t.method = "GET";
      break;
    case "urn:mpeg:dash:utc:direct:2014":
    case "urn:mpeg:dash:utc:direct:2012":
      t.method = "DIRECT", t.value = Date.parse(t.value);
      break;
    case "urn:mpeg:dash:utc:http-ntp:2014":
    case "urn:mpeg:dash:utc:ntp:2014":
    case "urn:mpeg:dash:utc:sntp:2014":
    default:
      throw new Error(E.UNSUPPORTED_UTC_TIMING_SCHEME);
  }
  return t;
}, $e = function(e, n) {
  n === void 0 && (n = {});
  var t = Ce(j(e), n), r = ye(t.representationInfo);
  return ve(r, t.locations, n.sidxMapping);
}, Fe = function(e) {
  return Le(j(e));
};
export {
  re as addSidxSegmentsToPlaylist,
  ne as generateSidxKey,
  Ce as inheritAttributes,
  $e as parse,
  Fe as parseUTCTiming,
  j as stringToMpdXml,
  ve as toM3u8,
  ye as toPlaylists
};
