import s from "../../../../../../../../_virtual/window.js";
var u = {
  // to determine mime types
  mp4: /^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,
  webm: /^(vp0?[89]|av0?1|opus|vorbis)/,
  ogg: /^(vp0?[89]|theora|flac|opus|vorbis)/,
  // to determine if a codec is audio or video
  video: /^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,
  audio: /^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,
  text: /^(stpp.ttml.im1t)/,
  // mux.js support regex
  muxerVideo: /^(avc0?1)/,
  muxerAudio: /^(mp4a)/,
  // match nothing as muxer does not support text right now.
  // there cannot never be a character before the start of a string
  // so this matches nothing.
  muxerText: /a^/
}, d = ["video", "audio", "text"], f = ["Video", "Audio", "Text"], c = function(e) {
  return e && e.replace(/avc1\.(\d+)\.(\d+)/i, function(r, t, a) {
    var i = ("00" + Number(t).toString(16)).slice(-2), p = ("00" + Number(a).toString(16)).slice(-2);
    return "avc1." + i + "00" + p;
  });
}, C = function(e) {
  e === void 0 && (e = "");
  var r = e.split(","), t = [];
  return r.forEach(function(a) {
    a = a.trim();
    var i;
    d.forEach(function(p) {
      var n = u[p].exec(a.toLowerCase());
      if (!(!n || n.length <= 1)) {
        i = p;
        var v = a.substring(0, n[1].length), m = a.replace(v, "");
        t.push({
          type: v,
          details: m,
          mediaType: p
        });
      }
    }), i || t.push({
      type: a,
      details: "",
      mediaType: "unknown"
    });
  }), t;
}, T = function(e, r) {
  if (!e.mediaGroups.AUDIO || !r)
    return null;
  var t = e.mediaGroups.AUDIO[r];
  if (!t)
    return null;
  for (var a in t) {
    var i = t[a];
    if (i.default && i.playlists)
      return C(i.playlists[0].attributes.CODECS);
  }
  return null;
}, y = function(e) {
  return e === void 0 && (e = ""), u.audio.test(e.trim().toLowerCase());
}, x = function(e) {
  return e === void 0 && (e = ""), u.text.test(e.trim().toLowerCase());
}, l = function(e) {
  if (!(!e || typeof e != "string")) {
    var r = e.toLowerCase().split(",").map(function(i) {
      return c(i.trim());
    }), t = "video";
    r.length === 1 && y(r[0]) ? t = "audio" : r.length === 1 && x(r[0]) && (t = "application");
    var a = "mp4";
    return r.every(function(i) {
      return u.mp4.test(i);
    }) ? a = "mp4" : r.every(function(i) {
      return u.webm.test(i);
    }) ? a = "webm" : r.every(function(i) {
      return u.ogg.test(i);
    }) && (a = "ogg"), t + "/" + a + ';codecs="' + e + '"';
  }
}, b = function(e, r) {
  return e === void 0 && (e = ""), r === void 0 && (r = !1), s.MediaSource && s.MediaSource.isTypeSupported && s.MediaSource.isTypeSupported(l(e)) || r && s.ManagedMediaSource && s.ManagedMediaSource.isTypeSupported && s.ManagedMediaSource.isTypeSupported(l(e)) || !1;
}, h = function(e) {
  return e === void 0 && (e = ""), e.toLowerCase().split(",").every(function(r) {
    r = r.trim();
    for (var t = 0; t < f.length; t++) {
      var a = f[t];
      if (u["muxer" + a].test(r))
        return !0;
    }
    return !1;
  });
}, w = "mp4a.40.2", D = "avc1.4d400d";
export {
  w as DEFAULT_AUDIO_CODEC,
  D as DEFAULT_VIDEO_CODEC,
  b as browserSupportsCodec,
  T as codecsFromDefault,
  l as getMimeForCodec,
  y as isAudioCodec,
  x as isTextCodec,
  h as muxerSupportsCodec,
  C as parseCodecs,
  c as translateLegacyCodec
};
//# sourceMappingURL=codecs.js.map
