@eluvio/elv-player-js 1.0.136 → 1.0.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -12
- package/package.json +4 -3
- package/src/Analytics.js +114 -0
- package/src/PlayerControls.js +195 -24
- package/src/index.js +295 -72
- package/src/static/icons/Icons.js +11 -8
- package/src/static/icons/media/list.svg +1 -0
- package/src/static/icons/media/next.svg +1 -0
- package/src/static/icons/media/previous.svg +1 -0
- package/src/static/stylesheets/player.scss +68 -6
- package/webpack.config.js +16 -7
- package/dist/5897e28fa3e8ac0a2fae.png +0 -0
- package/dist/bundle.333.7815f5ebcb1488f0e077.js +0 -2
- package/dist/bundle.333.7815f5ebcb1488f0e077.js.LICENSE.txt +0 -1
- package/dist/bundle.542.13fbfeeb92e41067e9da.js +0 -2
- package/dist/bundle.542.13fbfeeb92e41067e9da.js.LICENSE.txt +0 -13
- package/dist/bundle.543.f78d7c10787a91d4b582.js +0 -2
- package/dist/bundle.543.f78d7c10787a91d4b582.js.LICENSE.txt +0 -1
- package/dist/bundle.552.fbfc2e2fc68f6287f12c.js +0 -1
- package/dist/bundle.688.ef6032af9f304acb167f.js +0 -1
- package/dist/bundle.978.40fe2f1d0a843e187793.js +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.LICENSE.txt +0 -64
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkEluvioPlayer=self.webpackChunkEluvioPlayer||[]).push([[688],{8688:(e,t,r)=>{function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||n(e)||function(){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 a(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=n(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0,a=function(){};return{s:a,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:a}}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 s,o=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){l=!0,s=e},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw s}}}}function n(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}function o(e){var t="function"==typeof Map?new Map:void 0;return o=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return l(e,arguments,g(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),h(i,e)},o(e)}function l(e,t,r){return l=v()?Reflect.construct.bind():function(e,t,r){var i=[null];i.push.apply(i,t);var a=new(Function.bind.apply(e,i));return r&&h(a,r.prototype),a},l.apply(null,arguments)}function u(){return u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=g(e)););return e}(e,t);if(i){var a=Object.getOwnPropertyDescriptor(i,t);return a.get?a.get.call(arguments.length<3?e:r):a.value}},u.apply(this,arguments)}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function d(e){var t=v();return function(){var r,i=g(e);if(t){var a=g(this).constructor;r=Reflect.construct(i,arguments,a)}else r=i.apply(this,arguments);return function(e,t){if(t&&("object"===E(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return f(e)}(this,r)}}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function m(e,t,r){return(t=T(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function y(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,T(i.key),i)}}function k(e,t,r){return t&&p(e.prototype,t),r&&p(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function T(e){var t=function(e,t){if("object"!==E(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,"string");if("object"!==E(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===E(t)?t:String(t)}function E(e){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},E(e)}function S(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}r.r(t),r.d(t,{default:()=>On});var L,A,R,b,D,I={exports:{}};L=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,A=/^(?=([^\/?#]*))\1([^]*)$/,R=/(?:\/|^)\.(?=\/)/g,b=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,I.exports=D={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var i=D.parseURL(e);if(!i)throw new Error("Error trying to parse base URL.");return i.path=D.normalizePath(i.path),D.buildURLFromParts(i)}var a=D.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=D.normalizePath(a.path),D.buildURLFromParts(a)):t;var n=D.parseURL(e);if(!n)throw new Error("Error trying to parse base URL.");if(!n.netLoc&&n.path&&"/"!==n.path[0]){var s=A.exec(n.path);n.netLoc=s[1],n.path=s[2]}n.netLoc&&!n.path&&(n.path="/");var o={scheme:n.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(o.netLoc=n.netLoc,"/"!==a.path[0]))if(a.path){var l=n.path,u=l.substring(0,l.lastIndexOf("/")+1)+a.path;o.path=D.normalizePath(u)}else o.path=n.path,a.params||(o.params=n.params,a.query||(o.query=n.query));return null===o.path&&(o.path=r.alwaysNormalize?D.normalizePath(a.path):a.path),D.buildURLFromParts(o)},parseURL:function(e){var t=L.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(R,"");e.length!==(e=e.replace(b,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}};var w=I.exports;function C(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function _(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?C(Object(r),!0).forEach((function(t){P(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):C(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function P(e,t,r){return(t=function(e){var t=function(e,t){if("object"!==E(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,"string");if("object"!==E(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===E(t)?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function x(){return x=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},x.apply(this,arguments)}var F=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},O=function(e){return e.MEDIA_ATTACHING="hlsMediaAttaching",e.MEDIA_ATTACHED="hlsMediaAttached",e.MEDIA_DETACHING="hlsMediaDetaching",e.MEDIA_DETACHED="hlsMediaDetached",e.BUFFER_RESET="hlsBufferReset",e.BUFFER_CODECS="hlsBufferCodecs",e.BUFFER_CREATED="hlsBufferCreated",e.BUFFER_APPENDING="hlsBufferAppending",e.BUFFER_APPENDED="hlsBufferAppended",e.BUFFER_EOS="hlsBufferEos",e.BUFFER_FLUSHING="hlsBufferFlushing",e.BUFFER_FLUSHED="hlsBufferFlushed",e.MANIFEST_LOADING="hlsManifestLoading",e.MANIFEST_LOADED="hlsManifestLoaded",e.MANIFEST_PARSED="hlsManifestParsed",e.LEVEL_SWITCHING="hlsLevelSwitching",e.LEVEL_SWITCHED="hlsLevelSwitched",e.LEVEL_LOADING="hlsLevelLoading",e.LEVEL_LOADED="hlsLevelLoaded",e.LEVEL_UPDATED="hlsLevelUpdated",e.LEVEL_PTS_UPDATED="hlsLevelPtsUpdated",e.LEVELS_UPDATED="hlsLevelsUpdated",e.AUDIO_TRACKS_UPDATED="hlsAudioTracksUpdated",e.AUDIO_TRACK_SWITCHING="hlsAudioTrackSwitching",e.AUDIO_TRACK_SWITCHED="hlsAudioTrackSwitched",e.AUDIO_TRACK_LOADING="hlsAudioTrackLoading",e.AUDIO_TRACK_LOADED="hlsAudioTrackLoaded",e.SUBTITLE_TRACKS_UPDATED="hlsSubtitleTracksUpdated",e.SUBTITLE_TRACKS_CLEARED="hlsSubtitleTracksCleared",e.SUBTITLE_TRACK_SWITCH="hlsSubtitleTrackSwitch",e.SUBTITLE_TRACK_LOADING="hlsSubtitleTrackLoading",e.SUBTITLE_TRACK_LOADED="hlsSubtitleTrackLoaded",e.SUBTITLE_FRAG_PROCESSED="hlsSubtitleFragProcessed",e.CUES_PARSED="hlsCuesParsed",e.NON_NATIVE_TEXT_TRACKS_FOUND="hlsNonNativeTextTracksFound",e.INIT_PTS_FOUND="hlsInitPtsFound",e.FRAG_LOADING="hlsFragLoading",e.FRAG_LOAD_EMERGENCY_ABORTED="hlsFragLoadEmergencyAborted",e.FRAG_LOADED="hlsFragLoaded",e.FRAG_DECRYPTED="hlsFragDecrypted",e.FRAG_PARSING_INIT_SEGMENT="hlsFragParsingInitSegment",e.FRAG_PARSING_USERDATA="hlsFragParsingUserdata",e.FRAG_PARSING_METADATA="hlsFragParsingMetadata",e.FRAG_PARSED="hlsFragParsed",e.FRAG_BUFFERED="hlsFragBuffered",e.FRAG_CHANGED="hlsFragChanged",e.FPS_DROP="hlsFpsDrop",e.FPS_DROP_LEVEL_CAPPING="hlsFpsDropLevelCapping",e.ERROR="hlsError",e.DESTROYING="hlsDestroying",e.KEY_LOADING="hlsKeyLoading",e.KEY_LOADED="hlsKeyLoaded",e.LIVE_BACK_BUFFER_REACHED="hlsLiveBackBufferReached",e.BACK_BUFFER_REACHED="hlsBackBufferReached",e}({}),M=function(e){return e.NETWORK_ERROR="networkError",e.MEDIA_ERROR="mediaError",e.KEY_SYSTEM_ERROR="keySystemError",e.MUX_ERROR="muxError",e.OTHER_ERROR="otherError",e}({}),N=function(e){return e.KEY_SYSTEM_NO_KEYS="keySystemNoKeys",e.KEY_SYSTEM_NO_ACCESS="keySystemNoAccess",e.KEY_SYSTEM_NO_SESSION="keySystemNoSession",e.KEY_SYSTEM_NO_CONFIGURED_LICENSE="keySystemNoConfiguredLicense",e.KEY_SYSTEM_LICENSE_REQUEST_FAILED="keySystemLicenseRequestFailed",e.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED="keySystemServerCertificateRequestFailed",e.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED="keySystemServerCertificateUpdateFailed",e.KEY_SYSTEM_SESSION_UPDATE_FAILED="keySystemSessionUpdateFailed",e.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED="keySystemStatusOutputRestricted",e.KEY_SYSTEM_STATUS_INTERNAL_ERROR="keySystemStatusInternalError",e.MANIFEST_LOAD_ERROR="manifestLoadError",e.MANIFEST_LOAD_TIMEOUT="manifestLoadTimeOut",e.MANIFEST_PARSING_ERROR="manifestParsingError",e.MANIFEST_INCOMPATIBLE_CODECS_ERROR="manifestIncompatibleCodecsError",e.LEVEL_EMPTY_ERROR="levelEmptyError",e.LEVEL_LOAD_ERROR="levelLoadError",e.LEVEL_LOAD_TIMEOUT="levelLoadTimeOut",e.LEVEL_PARSING_ERROR="levelParsingError",e.LEVEL_SWITCH_ERROR="levelSwitchError",e.AUDIO_TRACK_LOAD_ERROR="audioTrackLoadError",e.AUDIO_TRACK_LOAD_TIMEOUT="audioTrackLoadTimeOut",e.SUBTITLE_LOAD_ERROR="subtitleTrackLoadError",e.SUBTITLE_TRACK_LOAD_TIMEOUT="subtitleTrackLoadTimeOut",e.FRAG_LOAD_ERROR="fragLoadError",e.FRAG_LOAD_TIMEOUT="fragLoadTimeOut",e.FRAG_DECRYPT_ERROR="fragDecryptError",e.FRAG_PARSING_ERROR="fragParsingError",e.FRAG_GAP="fragGap",e.REMUX_ALLOC_ERROR="remuxAllocError",e.KEY_LOAD_ERROR="keyLoadError",e.KEY_LOAD_TIMEOUT="keyLoadTimeOut",e.BUFFER_ADD_CODEC_ERROR="bufferAddCodecError",e.BUFFER_INCOMPATIBLE_CODECS_ERROR="bufferIncompatibleCodecsError",e.BUFFER_APPEND_ERROR="bufferAppendError",e.BUFFER_APPENDING_ERROR="bufferAppendingError",e.BUFFER_STALLED_ERROR="bufferStalledError",e.BUFFER_FULL_ERROR="bufferFullError",e.BUFFER_SEEK_OVER_HOLE="bufferSeekOverHole",e.BUFFER_NUDGE_ON_STALL="bufferNudgeOnStall",e.INTERNAL_EXCEPTION="internalException",e.INTERNAL_ABORTED="aborted",e.UNKNOWN="unknown",e}({}),U=function(){},B={trace:U,debug:U,log:U,warn:U,info:U,error:U},G=B;var K=G,H=/^(\d+)x(\d+)$/,V=/(.+?)=(".*?"|.*?)(?:,|$)/g,Y=function(){function e(t){for(var r in y(this,e),"string"==typeof t&&(t=e.parseAttrList(t)),t)t.hasOwnProperty(r)&&("X-"===r.substring(0,2)&&(this.clientAttrs=this.clientAttrs||[],this.clientAttrs.push(r)),this[r]=t[r])}return k(e,[{key:"decimalInteger",value:function(e){var t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t}},{key:"hexadecimalInteger",value:function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),i=0;i<t.length/2;i++)r[i]=parseInt(t.slice(2*i,2*i+2),16);return r}return null}},{key:"hexadecimalIntegerAsNumber",value:function(e){var t=parseInt(this[e],16);return t>Number.MAX_SAFE_INTEGER?1/0:t}},{key:"decimalFloatingPoint",value:function(e){return parseFloat(this[e])}},{key:"optionalFloat",value:function(e,t){var r=this[e];return r?parseFloat(r):t}},{key:"enumeratedString",value:function(e){return this[e]}},{key:"bool",value:function(e){return"YES"===this[e]}},{key:"decimalResolution",value:function(e){var t=H.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}}}],[{key:"parseAttrList",value:function(e){var t,r={};for(V.lastIndex=0;null!==(t=V.exec(e));){var i=t[2];0===i.indexOf('"')&&i.lastIndexOf('"')===i.length-1&&(i=i.slice(1,-1)),r[t[1].trim()]=i}return r}}]),e}();function W(e){return"SCTE35-OUT"===e||"SCTE35-IN"===e}var j=function(){function e(t,r){if(y(this,e),this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,r){var i=r.attr;for(var a in i)if(Object.prototype.hasOwnProperty.call(t,a)&&t[a]!==i[a]){K.warn('DATERANGE tag attribute: "'.concat(a,'" does not match for tags with ID: "').concat(t.ID,'"')),this._badValueForSameId=a;break}t=x(new Y({}),i,t)}if(this.attr=t,this._startDate=new Date(t["START-DATE"]),"END-DATE"in this.attr){var n=new Date(this.attr["END-DATE"]);F(n.getTime())&&(this._endDate=n)}}return k(e,[{key:"id",get:function(){return this.attr.ID}},{key:"class",get:function(){return this.attr.CLASS}},{key:"startDate",get:function(){return this._startDate}},{key:"endDate",get:function(){if(this._endDate)return this._endDate;var e=this.duration;return null!==e?new Date(this._startDate.getTime()+1e3*e):null}},{key:"duration",get:function(){if("DURATION"in this.attr){var e=this.attr.decimalFloatingPoint("DURATION");if(F(e))return e}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}},{key:"plannedDuration",get:function(){return"PLANNED-DURATION"in this.attr?this.attr.decimalFloatingPoint("PLANNED-DURATION"):null}},{key:"endOnNext",get:function(){return this.attr.bool("END-ON-NEXT")}},{key:"isValid",get:function(){return!!this.id&&!this._badValueForSameId&&F(this.startDate.getTime())&&(null===this.duration||this.duration>=0)&&(!this.endOnNext||!!this.class)}}]),e}(),q=k((function e(){y(this,e),this.aborted=!1,this.loaded=0,this.retry=0,this.total=0,this.chunkCount=0,this.bwEstimate=0,this.loading={start:0,first:0,end:0},this.parsing={start:0,end:0},this.buffering={start:0,first:0,end:0}})),X="audio",z="video",Q="audiovideo",$=function(){function e(t){var r;y(this,e),this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams=(m(r={},X,null),m(r,z,null),m(r,Q,null),r),this.baseurl=t}return k(e,[{key:"setByteRange",value:function(e,t){var r=e.split("@",2),i=[];1===r.length?i[0]=t?t.byteRangeEndOffset:0:i[0]=parseInt(r[1]),i[1]=parseInt(r[0])+i[0],this._byteRange=i}},{key:"byteRange",get:function(){return this._byteRange?this._byteRange:[]}},{key:"byteRangeStartOffset",get:function(){return this.byteRange[0]}},{key:"byteRangeEndOffset",get:function(){return this.byteRange[1]}},{key:"url",get:function(){return!this._url&&this.baseurl&&this.relurl&&(this._url=w.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""},set:function(e){this._url=e}}]),e}(),J=function(e){c(r,e);var t=d(r);function r(e,i){var a;return y(this,r),(a=t.call(this,i))._decryptdata=null,a.rawProgramDateTime=null,a.programDateTime=null,a.tagList=[],a.duration=0,a.sn=0,a.levelkeys=void 0,a.type=void 0,a.loader=null,a.keyLoader=null,a.level=-1,a.cc=0,a.startPTS=void 0,a.endPTS=void 0,a.startDTS=void 0,a.endDTS=void 0,a.start=0,a.deltaPTS=void 0,a.maxStartPTS=void 0,a.minEndPTS=void 0,a.stats=new q,a.urlId=0,a.data=void 0,a.bitrateTest=!1,a.title=null,a.initSegment=null,a.endList=void 0,a.gap=void 0,a.type=e,a}return k(r,[{key:"decryptdata",get:function(){if(!this.levelkeys&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){var e=this.levelkeys.identity;if(e)this._decryptdata=e.getDecryptData(this.sn);else{var t=Object.keys(this.levelkeys);if(1===t.length)return this._decryptdata=this.levelkeys[t[0]].getDecryptData(this.sn)}}return this._decryptdata}},{key:"end",get:function(){return this.start+this.duration}},{key:"endProgramDateTime",get:function(){if(null===this.programDateTime)return null;if(!F(this.programDateTime))return null;var e=F(this.duration)?this.duration:0;return this.programDateTime+1e3*e}},{key:"encrypted",get:function(){var e;if(null!=(e=this._decryptdata)&&e.encrypted)return!0;if(this.levelkeys){var t=Object.keys(this.levelkeys),r=t.length;if(r>1||1===r&&this.levelkeys[t[0]].encrypted)return!0}return!1}},{key:"setKeyFormat",value:function(e){if(this.levelkeys){var t=this.levelkeys[e];t&&!this._decryptdata&&(this._decryptdata=t.getDecryptData(this.sn))}}},{key:"abortRequests",value:function(){var e,t;null==(e=this.loader)||e.abort(),null==(t=this.keyLoader)||t.abort()}},{key:"setElementaryStreamInfo",value:function(e,t,r,i,a){var n=arguments.length>5&&void 0!==arguments[5]&&arguments[5],s=this.elementaryStreams,o=s[e];o?(o.startPTS=Math.min(o.startPTS,t),o.endPTS=Math.max(o.endPTS,r),o.startDTS=Math.min(o.startDTS,i),o.endDTS=Math.max(o.endDTS,a)):s[e]={startPTS:t,endPTS:r,startDTS:i,endDTS:a,partial:n}}},{key:"clearElementaryStreamInfo",value:function(){var e=this.elementaryStreams;e[X]=null,e[z]=null,e[Q]=null}}]),r}($),Z=function(e){c(r,e);var t=d(r);function r(e,i,a,n,s){var o;y(this,r),(o=t.call(this,a)).fragOffset=0,o.duration=0,o.gap=!1,o.independent=!1,o.relurl=void 0,o.fragment=void 0,o.index=void 0,o.stats=new q,o.duration=e.decimalFloatingPoint("DURATION"),o.gap=e.bool("GAP"),o.independent=e.bool("INDEPENDENT"),o.relurl=e.enumeratedString("URI"),o.fragment=i,o.index=n;var l=e.enumeratedString("BYTERANGE");return l&&o.setByteRange(l,s),s&&(o.fragOffset=s.fragOffset+s.duration),o}return k(r,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var e=this.elementaryStreams;return!!(e.audio||e.video||e.audiovideo)}}]),r}($),ee=function(){function e(t){y(this,e),this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.live=!0,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.availabilityDelay=void 0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.playlistParsingError=null,this.variableList=null,this.hasVariableRefs=!1,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=t}return k(e,[{key:"reloaded",value:function(e){if(!e)return this.advanced=!0,void(this.updated=!0);var t=this.lastPartSn-e.lastPartSn,r=this.lastPartIndex-e.lastPartIndex;this.updated=this.endSN!==e.endSN||!!r||!!t||!this.live,this.advanced=this.endSN>e.endSN||t>0||0===t&&r>0,this.updated||this.advanced?this.misses=Math.floor(.6*e.misses):this.misses=e.misses+1,this.availabilityDelay=e.availabilityDelay}},{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&F(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||10}},{key:"drift",get:function(){var e=this.driftEndTime-this.driftStartTime;return e>0?1e3*(this.driftEnd-this.driftStart)/e:1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var e;return null!=(e=this.fragments)&&e.length?this.fragments[this.fragments.length-1].end:0}},{key:"age",get:function(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}},{key:"lastPartIndex",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].index:-1}},{key:"lastPartSn",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}]),e}();function te(e){return Uint8Array.from(atob(e),(function(e){return e.charCodeAt(0)}))}function re(e){return Uint8Array.from(unescape(encodeURIComponent(e)),(function(e){return e.charCodeAt(0)}))}var ie={CLEARKEY:"org.w3.clearkey",FAIRPLAY:"com.apple.fps",PLAYREADY:"com.microsoft.playready",WIDEVINE:"com.widevine.alpha"},ae="org.w3.clearkey",ne="com.apple.streamingkeydelivery",se="com.microsoft.playready",oe="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";function le(e){switch(e){case ne:return ie.FAIRPLAY;case se:return ie.PLAYREADY;case oe:return ie.WIDEVINE;case ae:return ie.CLEARKEY}}var ue="edef8ba979d64acea3c827dcd51d21ed";function ce(e){switch(e){case ie.FAIRPLAY:return ne;case ie.PLAYREADY:return se;case ie.WIDEVINE:return oe;case ie.CLEARKEY:return ae}}function he(e){var t=e.drmSystems,r=e.widevineLicenseUrl,i=t?[ie.FAIRPLAY,ie.WIDEVINE,ie.PLAYREADY,ie.CLEARKEY].filter((function(e){return!!t[e]})):[];return!i[ie.WIDEVINE]&&r&&i.push(ie.WIDEVINE),i}var de="undefined"!=typeof self&&self.navigator&&self.navigator.requestMediaKeySystemAccess?self.navigator.requestMediaKeySystemAccess.bind(self.navigator):null;function fe(e,t,r){return Uint8Array.prototype.slice?e.slice(t,r):new Uint8Array(Array.prototype.slice.call(e,t,r))}var ve,ge=function(e,t){return t+10<=e.length&&73===e[t]&&68===e[t+1]&&51===e[t+2]&&e[t+3]<255&&e[t+4]<255&&e[t+6]<128&&e[t+7]<128&&e[t+8]<128&&e[t+9]<128},me=function(e,t){return t+10<=e.length&&51===e[t]&&68===e[t+1]&&73===e[t+2]&&e[t+3]<255&&e[t+4]<255&&e[t+6]<128&&e[t+7]<128&&e[t+8]<128&&e[t+9]<128},ye=function(e,t){for(var r=t,i=0;ge(e,t);)i+=10,i+=pe(e,t+6),me(e,t+10)&&(i+=10),t+=i;if(i>0)return e.subarray(r,r+i)},pe=function(e,t){var r=0;return r=(127&e[t])<<21,r|=(127&e[t+1])<<14,(r|=(127&e[t+2])<<7)|127&e[t+3]},ke=function(e,t){return ge(e,t)&&pe(e,t+6)+10<=e.length-t},Te=function(e){return e&&"PRIV"===e.key&&"com.apple.streaming.transportStreamTimestamp"===e.info},Ee=function(e){var t=String.fromCharCode(e[0],e[1],e[2],e[3]),r=pe(e,4);return{type:t,size:r,data:e.subarray(10,10+r)}},Se=function(e){for(var t=0,r=[];ge(e,t);){for(var i=pe(e,t+6),a=(t+=10)+i;t+8<a;){var n=Ee(e.subarray(t)),s=Le(n);s&&r.push(s),t+=n.size+10}me(e,t)&&(t+=10)}return r},Le=function(e){return"PRIV"===e.type?Ae(e):"W"===e.type[0]?be(e):Re(e)},Ae=function(e){if(!(e.size<2)){var t=Ie(e.data,!0),r=new Uint8Array(e.data.subarray(t.length+1));return{key:e.type,info:t,data:r.buffer}}},Re=function(e){if(!(e.size<2)){if("TXXX"===e.type){var t=1,r=Ie(e.data.subarray(t),!0);t+=r.length+1;var i=Ie(e.data.subarray(t));return{key:e.type,info:r,data:i}}var a=Ie(e.data.subarray(1));return{key:e.type,data:a}}},be=function(e){if("WXXX"===e.type){if(e.size<2)return;var t=1,r=Ie(e.data.subarray(t),!0);t+=r.length+1;var i=Ie(e.data.subarray(t));return{key:e.type,info:r,data:i}}var a=Ie(e.data);return{key:e.type,data:a}},De=function(e){if(8===e.data.byteLength){var t=new Uint8Array(e.data),r=1&t[3],i=(t[4]<<23)+(t[5]<<15)+(t[6]<<7)+t[7];return i/=45,r&&(i+=47721858.84),Math.round(i)}},Ie=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=we();if(r){var i=r.decode(e);if(t){var a=i.indexOf("\0");return-1!==a?i.substring(0,a):i}return i.replace(/\0/g,"")}for(var n,s,o,l=e.length,u="",c=0;c<l;){if(0===(n=e[c++])&&t)return u;if(0!==n&&3!==n)switch(n>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=String.fromCharCode(n);break;case 12:case 13:s=e[c++],u+=String.fromCharCode((31&n)<<6|63&s);break;case 14:s=e[c++],o=e[c++],u+=String.fromCharCode((15&n)<<12|(63&s)<<6|(63&o)<<0)}}return u};function we(){return ve||void 0===self.TextDecoder||(ve=new self.TextDecoder("utf-8")),ve}var Ce=function(e){for(var t="",r=0;r<e.length;r++){var i=e[r].toString(16);i.length<2&&(i="0"+i),t+=i}return t},_e=Math.pow(2,32)-1,Pe=[].push,xe={video:1,audio:2,id3:3,text:4};function Fe(e){return String.fromCharCode.apply(null,e)}function Oe(e,t){var r=e[t]<<8|e[t+1];return r<0?65536+r:r}function Me(e,t){var r=Ne(e,t);return r<0?4294967296+r:r}function Ne(e,t){return e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function Ue(e,t,r){e[t]=r>>24,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r}function Be(e,t){var r=[];if(!t.length)return r;for(var i=e.byteLength,a=0;a<i;){var n=Me(e,a),s=n>1?a+n:i;if(Fe(e.subarray(a+4,a+8))===t[0])if(1===t.length)r.push(e.subarray(a+8,s));else{var o=Be(e.subarray(a+8,s),t.slice(1));o.length&&Pe.apply(r,o)}a=s}return r}function Ge(e){var t=[],r=e[0],i=8,a=Me(e,i);i+=4,i+=0===r?8:16,i+=2;var n=e.length+0,s=Oe(e,i);i+=2;for(var o=0;o<s;o++){var l=i,u=Me(e,l);l+=4;var c=2147483647&u;if(1==(2147483648&u)>>>31)return K.warn("SIDX has hierarchical references (not supported)"),null;var h=Me(e,l);l+=4,t.push({referenceSize:c,subsegmentDuration:h,info:{duration:h/a,start:n,end:n+c-1}}),n+=c,i=l+=4}return{earliestPresentationTime:0,timescale:a,version:r,referencesCount:s,references:t}}function Ke(e){for(var t=[],r=Be(e,["moov","trak"]),i=0;i<r.length;i++){var a=r[i],n=Be(a,["tkhd"])[0];if(n){var s=n[0],o=0===s?12:20,l=Me(n,o),u=Be(a,["mdia","mdhd"])[0];if(u){var c=Me(u,o=0===(s=u[0])?12:20),h=Be(a,["mdia","hdlr"])[0];if(h){var d=Fe(h.subarray(8,12)),f={soun:X,vide:z}[d];if(f){var v=Be(a,["mdia","minf","stbl","stsd"])[0],g=void 0;v&&(g=Fe(v.subarray(12,16))),t[l]={timescale:c,type:f},t[f]={timescale:c,id:l,codec:g}}}}}}return Be(e,["moov","mvex","trex"]).forEach((function(e){var r=Me(e,4),i=t[r];i&&(i.default={duration:Me(e,12),flags:Me(e,20)})})),t}function He(e){var t=Be(e,["schm"])[0];if(t){var r=Fe(t.subarray(4,8));if("cbcs"===r||"cenc"===r)return Be(e,["schi","tenc"])[0]}return K.error("[eme] missing 'schm' box"),null}function Ve(e){var t=Me(e,0),r=8;1&t&&(r+=4),4&t&&(r+=4);for(var i=0,a=Me(e,4),n=0;n<a;n++)256&t&&(i+=Me(e,r),r+=4),512&t&&(r+=4),1024&t&&(r+=4),2048&t&&(r+=4);return i}function Ye(e,t){var r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}function We(e,t){var r=[],i=t.samples,a=t.timescale,n=t.id,s=!1;return Be(i,["moof"]).map((function(o){var l=o.byteOffset-8;Be(o,["traf"]).map((function(o){var u=Be(o,["tfdt"]).map((function(e){var t=e[0],r=Me(e,4);return 1===t&&(r*=Math.pow(2,32),r+=Me(e,8)),r/a}))[0];return void 0!==u&&(e=u),Be(o,["tfhd"]).map((function(u){var c=Me(u,4),h=16777215&Me(u,0),d=0,f=0!=(16&h),v=0,g=0!=(32&h),m=8;c===n&&(0!=(1&h)&&(m+=8),0!=(2&h)&&(m+=4),0!=(8&h)&&(d=Me(u,m),m+=4),f&&(v=Me(u,m),m+=4),g&&(m+=4),"video"===t.type&&(s=function(e){if(!e)return!1;var t=e.indexOf("."),r=t<0?e:e.substring(0,t);return"hvc1"===r||"hev1"===r||"dvh1"===r||"dvhe"===r}(t.codec)),Be(o,["trun"]).map((function(n){var o=n[0],u=16777215&Me(n,0),c=0!=(1&u),h=0,f=0!=(4&u),g=0!=(256&u),m=0,y=0!=(512&u),p=0,k=0!=(1024&u),T=0!=(2048&u),E=0,S=Me(n,4),L=8;c&&(h=Me(n,L),L+=4),f&&(L+=4);for(var A=h+l,R=0;R<S;R++){if(g?(m=Me(n,L),L+=4):m=d,y?(p=Me(n,L),L+=4):p=v,k&&(L+=4),T&&(E=0===o?Me(n,L):Ne(n,L),L+=4),t.type===z)for(var b=0;b<p;){var D=Me(i,A);je(s,i[A+=4])&&qe(i.subarray(A,A+D),s?2:1,e+E/a,r),A+=D,b+=D+4}e+=m/a}})))}))}))})),r}function je(e,t){if(e){var r=t>>1&63;return 39===r||40===r}return 6==(31&t)}function qe(e,t,r,i){var a=Xe(e),n=0;n+=t;for(var s=0,o=0,l=!1,u=0;n<a.length;){s=0;do{if(n>=a.length)break;s+=u=a[n++]}while(255===u);o=0;do{if(n>=a.length)break;o+=u=a[n++]}while(255===u);var c=a.length-n;if(!l&&4===s&&n<a.length){if(l=!0,181===a[n++]){var h=Oe(a,n);if(n+=2,49===h){var d=Me(a,n);if(n+=4,1195456820===d){var f=a[n++];if(3===f){var v=a[n++],g=64&v,m=g?2+3*(31&v):0,y=new Uint8Array(m);if(g){y[0]=v;for(var p=1;p<m;p++)y[p]=a[n++]}i.push({type:f,payloadType:s,pts:r,bytes:y})}}}}}else if(5===s&&o<c){if(l=!0,o>16){for(var k=[],T=0;T<16;T++){var E=a[n++].toString(16);k.push(1==E.length?"0"+E:E),3!==T&&5!==T&&7!==T&&9!==T||k.push("-")}for(var S=o-16,L=new Uint8Array(S),A=0;A<S;A++)L[A]=a[n++];i.push({payloadType:s,pts:r,uuid:k.join(""),userData:Ie(L),userDataBytes:L})}}else if(o<c)n+=o;else if(o>c)break}}function Xe(e){for(var t=e.byteLength,r=[],i=1;i<t-2;)0===e[i]&&0===e[i+1]&&3===e[i+2]?(r.push(i+2),i+=2):i++;if(0===r.length)return e;var a=t-r.length,n=new Uint8Array(a),s=0;for(i=0;i<a;s++,i++)s===r[0]&&(s++,r.shift()),n[i]=e[s];return n}var ze={},Qe=function(){function e(t,r,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[1],n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;y(this,e),this.uri=void 0,this.method=void 0,this.keyFormat=void 0,this.keyFormatVersions=void 0,this.encrypted=void 0,this.isCommonEncryption=void 0,this.iv=null,this.key=null,this.keyId=null,this.pssh=null,this.method=t,this.uri=r,this.keyFormat=i,this.keyFormatVersions=a,this.iv=n,this.encrypted=!!t&&"NONE"!==t,this.isCommonEncryption=this.encrypted&&"AES-128"!==t}return k(e,[{key:"isSupported",value:function(){if(this.method){if("AES-128"===this.method||"NONE"===this.method)return!0;if("identity"===this.keyFormat)return"SAMPLE-AES"===this.method;switch(this.keyFormat){case ne:case oe:case se:case ae:return-1!==["ISO-23001-7","SAMPLE-AES","SAMPLE-AES-CENC","SAMPLE-AES-CTR"].indexOf(this.method)}}return!1}},{key:"getDecryptData",value:function(t){if(!this.encrypted||!this.uri)return null;if("AES-128"===this.method&&this.uri&&!this.iv){"number"!=typeof t&&("AES-128"!==this.method||this.iv||K.warn('missing IV for initialization segment with method="'.concat(this.method,'" - compliance issue')),t=0);var r=function(e){for(var t=new Uint8Array(16),r=12;r<16;r++)t[r]=e>>8*(15-r)&255;return t}(t);return new e(this.method,this.uri,"identity",this.keyFormatVersions,r)}var i=function(e){var t,r,i=e.split(":"),a=null;if("data"===i[0]&&2===i.length){var n=i[1].split(";"),s=n[n.length-1].split(",");if(2===s.length){var o="base64"===s[0],l=s[1];o?(n.splice(-1,1),a=te(l)):(t=re(l).subarray(0,16),(r=new Uint8Array(16)).set(t,16-t.length),a=r)}}return a}(this.uri);if(i)switch(this.keyFormat){case oe:this.pssh=i,i.length>=22&&(this.keyId=i.subarray(i.length-22,i.length-6));break;case se:var a=new Uint8Array([154,4,240,121,152,64,66,134,171,146,230,91,224,136,95,149]);this.pssh=function(e,t,r){if(16!==e.byteLength)throw new RangeError("Invalid system id");var i,a,n;if(t){i=1,a=new Uint8Array(16*t.length);for(var s=0;s<t.length;s++){var o=t[s];if(16!==o.byteLength)throw new RangeError("Invalid key");a.set(o,16*s)}}else i=0,a=new Uint8Array;i>0?(n=new Uint8Array(4),t.length>0&&new DataView(n.buffer).setUint32(0,t.length,!1)):n=new Uint8Array;var l=new Uint8Array(4);return r&&r.byteLength>0&&new DataView(l.buffer).setUint32(0,r.byteLength,!1),function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];for(var a=r.length,n=8,s=a;s--;)n+=r[s].byteLength;var o=new Uint8Array(n);for(o[0]=n>>24&255,o[1]=n>>16&255,o[2]=n>>8&255,o[3]=255&n,o.set(e,4),s=0,n=8;s<a;s++)o.set(r[s],n),n+=r[s].byteLength;return o}([112,115,115,104],new Uint8Array([i,0,0,0]),e,n,a,l,r||new Uint8Array)}(a,null,i);var n=new Uint16Array(i.buffer,i.byteOffset,i.byteLength/2),s=String.fromCharCode.apply(null,Array.from(n)),o=s.substring(s.indexOf("<"),s.length),l=(new DOMParser).parseFromString(o,"text/xml").getElementsByTagName("KID")[0];if(l){var u=l.childNodes[0]?l.childNodes[0].nodeValue:l.getAttribute("VALUE");if(u){var c=te(u).subarray(0,16);!function(e){var t=function(e,t,r){var i=e[t];e[t]=e[r],e[r]=i};t(e,0,3),t(e,1,2),t(e,4,5),t(e,6,7)}(c),this.keyId=c}}break;default:var h=i.subarray(0,16);if(16!==h.length){var d=new Uint8Array(16);d.set(h,16-h.length),h=d}this.keyId=h}if(!this.keyId||16!==this.keyId.byteLength){var f=ze[this.uri];if(!f){var v=Object.keys(ze).length%Number.MAX_SAFE_INTEGER;f=new Uint8Array(16),new DataView(f.buffer,12,4).setUint32(0,v),ze[this.uri]=f}this.keyId=f}return this}}],[{key:"clearKeyUriToKeyIdMap",value:function(){ze={}}}]),e}(),$e=/\{\$([a-zA-Z0-9-_]+)\}/g;function Je(e){return $e.test(e)}function Ze(e,t,r){if(null!==e.variableList||e.hasVariableRefs)for(var i=r.length;i--;){var a=r[i],n=t[a];n&&(t[a]=et(e,n))}}function et(e,t){if(null!==e.variableList||e.hasVariableRefs){var r=e.variableList;return t.replace($e,(function(t){var i=t.substring(2,t.length-1),a=null==r?void 0:r[i];return void 0===a?(e.playlistParsingError||(e.playlistParsingError=new Error('Missing preceding EXT-X-DEFINE tag for Variable Reference: "'.concat(i,'"'))),t):a}))}return t}function tt(e,t,r){var i,a,n=e.variableList;if(n||(e.variableList=n={}),"QUERYPARAM"in t){i=t.QUERYPARAM;try{var s=new self.URL(r).searchParams;if(!s.has(i))throw new Error('"'.concat(i,'" does not match any query parameter in URI: "').concat(r,'"'));a=s.get(i)}catch(t){e.playlistParsingError||(e.playlistParsingError=new Error("EXT-X-DEFINE QUERYPARAM: ".concat(t.message)))}}else i=t.NAME,a=t.VALUE;i in n?e.playlistParsingError||(e.playlistParsingError=new Error('EXT-X-DEFINE duplicate Variable Name declarations: "'.concat(i,'"'))):n[i]=a||""}function rt(e,t,r){var i=t.IMPORT;if(r&&i in r){var a=e.variableList;a||(e.variableList=a={}),a[i]=r[i]}else e.playlistParsingError||(e.playlistParsingError=new Error('EXT-X-DEFINE IMPORT attribute not found in Multivariant Playlist: "'.concat(i,'"')))}function it(){if("undefined"!=typeof self)return self.MediaSource||self.WebKitMediaSource}var at={audio:{a3ds:!0,"ac-3":!0,"ac-4":!0,alac:!0,alaw:!0,dra1:!0,"dts+":!0,"dts-":!0,dtsc:!0,dtse:!0,dtsh:!0,"ec-3":!0,enca:!0,g719:!0,g726:!0,m4ae:!0,mha1:!0,mha2:!0,mhm1:!0,mhm2:!0,mlpa:!0,mp4a:!0,"raw ":!0,Opus:!0,opus:!0,samr:!0,sawb:!0,sawp:!0,sevc:!0,sqcp:!0,ssmv:!0,twos:!0,ulaw:!0},video:{avc1:!0,avc2:!0,avc3:!0,avc4:!0,avcp:!0,av01:!0,drac:!0,dva1:!0,dvav:!0,dvh1:!0,dvhe:!0,encv:!0,hev1:!0,hvc1:!0,mjp2:!0,mp4v:!0,mvc1:!0,mvc2:!0,mvc3:!0,mvc4:!0,resv:!0,rv60:!0,s263:!0,svc1:!0,svc2:!0,"vc-1":!0,vp08:!0,vp09:!0},text:{stpp:!0,wvtt:!0}},nt=it();function st(e,t){var r;return null!=(r=null==nt?void 0:nt.isTypeSupported("".concat(t||"video",'/mp4;codecs="').concat(e,'"')))&&r}var ot=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g,lt=/#EXT-X-MEDIA:(.*)/g,ut=/^#EXT(?:INF|-X-TARGETDURATION):/m,ct=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[\S ]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),ht=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),dt=function(){function e(){y(this,e)}return k(e,null,[{key:"findGroup",value:function(e,t){for(var r=0;r<e.length;r++){var i=e[r];if(i.id===t)return i}}},{key:"convertAVC1ToAVCOTI",value:function(e){var t=e.split(".");if(t.length>2){var r=t.shift()+".";return(r+=parseInt(t.shift()).toString(16))+("000"+parseInt(t.shift()).toString(16)).slice(-4)}return e}},{key:"resolve",value:function(e,t){return w.buildAbsoluteURL(t,e,{alwaysNormalize:!0})}},{key:"isMediaPlaylist",value:function(e){return ut.test(e)}},{key:"parseMasterPlaylist",value:function(t,r){var i,a={contentSteering:null,levels:[],playlistParsingError:null,sessionData:null,sessionKeys:null,startTimeOffset:null,variableList:null,hasVariableRefs:Je(t)},n=[];for(ot.lastIndex=0;null!=(i=ot.exec(t));)if(i[1]){var s,o=new Y(i[1]);Ze(a,o,["CODECS","SUPPLEMENTAL-CODECS","ALLOWED-CPC","PATHWAY-ID","STABLE-VARIANT-ID","AUDIO","VIDEO","SUBTITLES","CLOSED-CAPTIONS","NAME"]);var l=et(a,i[2]),u={attrs:o,bitrate:o.decimalInteger("AVERAGE-BANDWIDTH")||o.decimalInteger("BANDWIDTH"),name:o.NAME,url:e.resolve(l,r)},c=o.decimalResolution("RESOLUTION");c&&(u.width=c.width,u.height=c.height),gt((o.CODECS||"").split(/[ ,]+/).filter((function(e){return e})),u),u.videoCodec&&-1!==u.videoCodec.indexOf("avc1")&&(u.videoCodec=e.convertAVC1ToAVCOTI(u.videoCodec)),null!=(s=u.unknownCodecs)&&s.length||n.push(u),a.levels.push(u)}else if(i[3]){var h=i[3],d=i[4];switch(h){case"SESSION-DATA":var f=new Y(d);Ze(a,f,["DATA-ID","LANGUAGE","VALUE","URI"]);var v=f["DATA-ID"];v&&(null===a.sessionData&&(a.sessionData={}),a.sessionData[v]=f);break;case"SESSION-KEY":var g=ft(d,r,a);g.encrypted&&g.isSupported()?(null===a.sessionKeys&&(a.sessionKeys=[]),a.sessionKeys.push(g)):K.warn('[Keys] Ignoring invalid EXT-X-SESSION-KEY tag: "'.concat(d,'"'));break;case"DEFINE":var m=new Y(d);Ze(a,m,["NAME","VALUE","QUERYPARAM"]),tt(a,m,r);break;case"CONTENT-STEERING":var y=new Y(d);Ze(a,y,["SERVER-URI","PATHWAY-ID"]),a.contentSteering={uri:e.resolve(y["SERVER-URI"],r),pathwayId:y["PATHWAY-ID"]||"."};break;case"START":a.startTimeOffset=vt(d)}}var p=n.length>0&&n.length<a.levels.length;return a.levels=p?n:a.levels,0===a.levels.length&&(a.playlistParsingError=new Error("no levels found in manifest")),a}},{key:"parseMasterPlaylistMedia",value:function(t,r,i){var a,n={},s=i.levels,o={AUDIO:s.map((function(e){return{id:e.attrs.AUDIO,audioCodec:e.audioCodec}})),SUBTITLES:s.map((function(e){return{id:e.attrs.SUBTITLES,textCodec:e.textCodec}})),"CLOSED-CAPTIONS":[]},l=0;for(lt.lastIndex=0;null!==(a=lt.exec(t));){var u=new Y(a[1]),c=u.TYPE;if(c){var h=o[c],d=n[c]||[];n[c]=d,Ze(i,u,["URI","GROUP-ID","LANGUAGE","ASSOC-LANGUAGE","STABLE-RENDITION-ID","NAME","INSTREAM-ID","CHARACTERISTICS","CHANNELS"]);var f={attrs:u,bitrate:0,id:l++,groupId:u["GROUP-ID"]||"",instreamId:u["INSTREAM-ID"],name:u.NAME||u.LANGUAGE||"",type:c,default:u.bool("DEFAULT"),autoselect:u.bool("AUTOSELECT"),forced:u.bool("FORCED"),lang:u.LANGUAGE,url:u.URI?e.resolve(u.URI,r):""};if(null!=h&&h.length){var v=e.findGroup(h,f.groupId)||h[0];mt(f,v,"audioCodec"),mt(f,v,"textCodec")}d.push(f)}}return n}},{key:"parseLevelPlaylist",value:function(e,t,r,i,a,n){var s,o,l,u=new ee(t),c=u.fragments,h=null,d=0,f=0,v=0,g=0,m=null,y=new J(i,t),p=-1,k=!1;for(ct.lastIndex=0,u.m3u8=e,u.hasVariableRefs=Je(e);null!==(s=ct.exec(e));){k&&(k=!1,(y=new J(i,t)).start=v,y.sn=d,y.cc=g,y.level=r,h&&(y.initSegment=h,y.rawProgramDateTime=h.rawProgramDateTime,h.rawProgramDateTime=null));var T=s[1];if(T){y.duration=parseFloat(T);var E=(" "+s[2]).slice(1);y.title=E||null,y.tagList.push(E?["INF",T,E]:["INF",T])}else if(s[3]){if(F(y.duration)){y.start=v,l&&kt(y,l,u),y.sn=d,y.level=r,y.cc=g,y.urlId=a,c.push(y);var S=(" "+s[3]).slice(1);y.relurl=et(u,S),yt(y,m),m=y,v+=y.duration,d++,f=0,k=!0}}else if(s[4]){var L=(" "+s[4]).slice(1);m?y.setByteRange(L,m):y.setByteRange(L)}else if(s[5])y.rawProgramDateTime=(" "+s[5]).slice(1),y.tagList.push(["PROGRAM-DATE-TIME",y.rawProgramDateTime]),-1===p&&(p=c.length);else{if(!(s=s[0].match(ht))){K.warn("No matches on slow regex match for level playlist!");continue}for(o=1;o<s.length&&void 0===s[o];o++);var A=(" "+s[o]).slice(1),R=(" "+s[o+1]).slice(1),b=s[o+2]?(" "+s[o+2]).slice(1):"";switch(A){case"PLAYLIST-TYPE":u.type=R.toUpperCase();break;case"MEDIA-SEQUENCE":d=u.startSN=parseInt(R);break;case"SKIP":var D=new Y(R);Ze(u,D,["RECENTLY-REMOVED-DATERANGES"]);var I=D.decimalInteger("SKIPPED-SEGMENTS");if(F(I)){u.skippedSegments=I;for(var w=I;w--;)c.unshift(null);d+=I}var C=D.enumeratedString("RECENTLY-REMOVED-DATERANGES");C&&(u.recentlyRemovedDateranges=C.split("\t"));break;case"TARGETDURATION":u.targetduration=Math.max(parseInt(R),1);break;case"VERSION":u.version=parseInt(R);break;case"EXTM3U":break;case"ENDLIST":u.live=!1;break;case"#":(R||b)&&y.tagList.push(b?[R,b]:[R]);break;case"DISCONTINUITY":g++,y.tagList.push(["DIS"]);break;case"GAP":y.gap=!0,y.tagList.push([A]);break;case"BITRATE":y.tagList.push([A,R]);break;case"DATERANGE":var _=new Y(R);Ze(u,_,["ID","CLASS","START-DATE","END-DATE","SCTE35-CMD","SCTE35-OUT","SCTE35-IN"]),Ze(u,_,_.clientAttrs);var P=new j(_,u.dateRanges[_.ID]);P.isValid||u.skippedSegments?u.dateRanges[P.id]=P:K.warn('Ignoring invalid DATERANGE tag: "'.concat(R,'"')),y.tagList.push(["EXT-X-DATERANGE",R]);break;case"DEFINE":var O=new Y(R);Ze(u,O,["NAME","VALUE","IMPORT","QUERYPARAM"]),"IMPORT"in O?rt(u,O,n):tt(u,O,t);break;case"DISCONTINUITY-SEQUENCE":g=parseInt(R);break;case"KEY":var M=ft(R,t,u);if(M.isSupported()){if("NONE"===M.method){l=void 0;break}l||(l={}),l[M.keyFormat]&&(l=x({},l)),l[M.keyFormat]=M}else K.warn('[Keys] Ignoring invalid EXT-X-KEY tag: "'.concat(R,'"'));break;case"START":u.startTimeOffset=vt(R);break;case"MAP":var N=new Y(R);if(Ze(u,N,["BYTERANGE","URI"]),y.duration){var U=new J(i,t);pt(U,N,r,l),h=U,y.initSegment=h,h.rawProgramDateTime&&!y.rawProgramDateTime&&(y.rawProgramDateTime=h.rawProgramDateTime)}else pt(y,N,r,l),h=y,k=!0;break;case"SERVER-CONTROL":var B=new Y(R);u.canBlockReload=B.bool("CAN-BLOCK-RELOAD"),u.canSkipUntil=B.optionalFloat("CAN-SKIP-UNTIL",0),u.canSkipDateRanges=u.canSkipUntil>0&&B.bool("CAN-SKIP-DATERANGES"),u.partHoldBack=B.optionalFloat("PART-HOLD-BACK",0),u.holdBack=B.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var G=new Y(R);u.partTarget=G.decimalFloatingPoint("PART-TARGET");break;case"PART":var H=u.partList;H||(H=u.partList=[]);var V=f>0?H[H.length-1]:void 0,W=f++,q=new Y(R);Ze(u,q,["BYTERANGE","URI"]);var X=new Z(q,y,t,W,V);H.push(X),y.duration+=X.duration;break;case"PRELOAD-HINT":var z=new Y(R);Ze(u,z,["URI"]),u.preloadHint=z;break;case"RENDITION-REPORT":var Q=new Y(R);Ze(u,Q,["URI"]),u.renditionReports=u.renditionReports||[],u.renditionReports.push(Q);break;default:K.warn("line parsed but not handled: ".concat(s))}}}m&&!m.relurl?(c.pop(),v-=m.duration,u.partList&&(u.fragmentHint=m)):u.partList&&(yt(y,m),y.cc=g,u.fragmentHint=y,l&&kt(y,l,u));var $=c.length,te=c[0],re=c[$-1];if((v+=u.skippedSegments*u.targetduration)>0&&$&&re){u.averagetargetduration=v/$;var ie=re.sn;u.endSN="initSegment"!==ie?ie:0,u.live||(re.endList=!0),te&&(u.startCC=te.cc)}else u.endSN=0,u.startCC=0;return u.fragmentHint&&(v+=u.fragmentHint.duration),u.totalduration=v,u.endCC=g,p>0&&function(e,t){for(var r=e[t],i=t;i--;){var a=e[i];if(!a)return;a.programDateTime=r.programDateTime-1e3*a.duration,r=a}}(c,p),u}}]),e}();function ft(e,t,r){var i,a,n=new Y(e);Ze(r,n,["KEYFORMAT","KEYFORMATVERSIONS","URI","IV","URI"]);var s=null!=(i=n.METHOD)?i:"",o=n.URI,l=n.hexadecimalInteger("IV"),u=n.KEYFORMATVERSIONS,c=null!=(a=n.KEYFORMAT)?a:"identity";o&&n.IV&&!l&&K.error("Invalid IV: ".concat(n.IV));var h=o?dt.resolve(o,t):"",d=(u||"1").split("/").map(Number).filter(Number.isFinite);return new Qe(s,h,c,d,l)}function vt(e){var t=new Y(e).decimalFloatingPoint("TIME-OFFSET");return F(t)?t:null}function gt(e,t){["video","audio","text"].forEach((function(r){var i=e.filter((function(e){return function(e,t){var r=at[t];return!!r&&!0===r[e.slice(0,4)]}(e,r)}));if(i.length){var a=i.filter((function(e){return 0===e.lastIndexOf("avc1",0)||0===e.lastIndexOf("mp4a",0)}));t["".concat(r,"Codec")]=a.length>0?a[0]:i[0],e=e.filter((function(e){return-1===i.indexOf(e)}))}})),t.unknownCodecs=e}function mt(e,t,r){var i=t[r];i&&(e[r]=i)}function yt(e,t){e.rawProgramDateTime?e.programDateTime=Date.parse(e.rawProgramDateTime):null!=t&&t.programDateTime&&(e.programDateTime=t.endProgramDateTime),F(e.programDateTime)||(e.programDateTime=null,e.rawProgramDateTime=null)}function pt(e,t,r,i){e.relurl=t.URI,t.BYTERANGE&&e.setByteRange(t.BYTERANGE),e.level=r,e.sn="initSegment",i&&(e.levelkeys=i),e.initSegment=null}function kt(e,t,r){e.levelkeys=t;var i=r.encryptedFragments;i.length&&i[i.length-1].levelkeys===t||!Object.keys(t).some((function(e){return t[e].isCommonEncryption}))||i.push(e)}var Tt="manifest",Et="level",St="audioTrack",Lt="subtitleTrack",At="main",Rt="audio",bt="subtitle";function Dt(e){switch(e.type){case St:return Rt;case Lt:return bt;default:return At}}function It(e,t){var r=e.url;return void 0!==r&&0!==r.indexOf("data:")||(r=t.url),r}var wt=function(){function e(t){y(this,e),this.hls=void 0,this.loaders=Object.create(null),this.variableList=null,this.hls=t,this.registerListeners()}return k(e,[{key:"startLoad",value:function(e){}},{key:"stopLoad",value:function(){this.destroyInternalLoaders()}},{key:"registerListeners",value:function(){var e=this.hls;e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.LEVEL_LOADING,this.onLevelLoading,this),e.on(O.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.on(O.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.LEVEL_LOADING,this.onLevelLoading,this),e.off(O.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.off(O.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)}},{key:"createInternalLoader",value:function(e){var t=this.hls.config,r=t.pLoader,i=t.loader,a=new(r||i)(t);return this.loaders[e.type]=a,a}},{key:"getInternalLoader",value:function(e){return this.loaders[e.type]}},{key:"resetInternalLoader",value:function(e){this.loaders[e]&&delete this.loaders[e]}},{key:"destroyInternalLoaders",value:function(){for(var e in this.loaders){var t=this.loaders[e];t&&t.destroy(),this.resetInternalLoader(e)}}},{key:"destroy",value:function(){this.variableList=null,this.unregisterListeners(),this.destroyInternalLoaders()}},{key:"onManifestLoading",value:function(e,t){var r=t.url;this.variableList=null,this.load({id:null,level:0,responseType:"text",type:Tt,url:r,deliveryDirectives:null})}},{key:"onLevelLoading",value:function(e,t){var r=t.id,i=t.level,a=t.url,n=t.deliveryDirectives;this.load({id:r,level:i,responseType:"text",type:Et,url:a,deliveryDirectives:n})}},{key:"onAudioTrackLoading",value:function(e,t){var r=t.id,i=t.groupId,a=t.url,n=t.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:St,url:a,deliveryDirectives:n})}},{key:"onSubtitleTrackLoading",value:function(e,t){var r=t.id,i=t.groupId,a=t.url,n=t.deliveryDirectives;this.load({id:r,groupId:i,level:null,responseType:"text",type:Lt,url:a,deliveryDirectives:n})}},{key:"load",value:function(e){var t,r,i,a=this,n=this.hls.config,s=this.getInternalLoader(e);if(s){var o=s.context;if(o&&o.url===e.url)return void K.trace("[playlist-loader]: playlist request ongoing");K.log("[playlist-loader]: aborting previous loader for type: ".concat(e.type)),s.abort()}if(r=e.type===Tt?n.manifestLoadPolicy.default:x({},n.playlistLoadPolicy.default,{timeoutRetry:null,errorRetry:null}),s=this.createInternalLoader(e),null!=(t=e.deliveryDirectives)&&t.part&&(e.type===Et&&null!==e.level?i=this.hls.levels[e.level].details:e.type===St&&null!==e.id?i=this.hls.audioTracks[e.id].details:e.type===Lt&&null!==e.id&&(i=this.hls.subtitleTracks[e.id].details),i)){var l=i.partTarget,u=i.targetduration;if(l&&u){var c=1e3*Math.max(3*l,.8*u);r=x({},r,{maxTimeToFirstByteMs:Math.min(c,r.maxTimeToFirstByteMs),maxLoadTimeMs:Math.min(c,r.maxTimeToFirstByteMs)})}}var h=r.errorRetry||r.timeoutRetry||{},d={loadPolicy:r,timeout:r.maxLoadTimeMs,maxRetry:h.maxNumRetry||0,retryDelay:h.retryDelayMs||0,maxRetryDelay:h.maxRetryDelayMs||0},f={onSuccess:function(e,t,r,i){var n=a.getInternalLoader(r);a.resetInternalLoader(r.type);var s=e.data;0===s.indexOf("#EXTM3U")?(t.parsing.start=performance.now(),dt.isMediaPlaylist(s)?a.handleTrackOrLevelPlaylist(e,t,r,i||null,n):a.handleMasterPlaylist(e,t,r,i)):a.handleManifestParsingError(e,r,new Error("no EXTM3U delimiter"),i||null,t)},onError:function(e,t,r,i){a.handleNetworkError(t,r,!1,e,i)},onTimeout:function(e,t,r){a.handleNetworkError(t,r,!0,void 0,e)}};s.load(e,d,f)}},{key:"handleMasterPlaylist",value:function(e,t,r,i){var a=this.hls,n=e.data,s=It(e,r),o=dt.parseMasterPlaylist(n,s);if(o.playlistParsingError)this.handleManifestParsingError(e,r,o.playlistParsingError,i,t);else{var l=o.contentSteering,u=o.levels,c=o.sessionData,h=o.sessionKeys,d=o.startTimeOffset,f=o.variableList;this.variableList=f;var v=dt.parseMasterPlaylistMedia(n,s,o),g=v.AUDIO,m=void 0===g?[]:g,y=v.SUBTITLES,p=v["CLOSED-CAPTIONS"];m.length&&(m.some((function(e){return!e.url}))||!u[0].audioCodec||u[0].attrs.AUDIO||(K.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),m.unshift({type:"main",name:"main",groupId:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new Y({}),bitrate:0,url:""}))),a.trigger(O.MANIFEST_LOADED,{levels:u,audioTracks:m,subtitles:y,captions:p,contentSteering:l,url:s,stats:t,networkDetails:i,sessionData:c,sessionKeys:h,startTimeOffset:d,variableList:f})}}},{key:"handleTrackOrLevelPlaylist",value:function(e,t,r,i,a){var n=this.hls,s=r.id,o=r.level,l=r.type,u=It(e,r),c=F(s)?s:0,h=F(o)?o:c,d=Dt(r),f=dt.parseLevelPlaylist(e.data,u,h,d,c,this.variableList);if(l===Tt){var v={attrs:new Y({}),bitrate:0,details:f,name:"",url:u};n.trigger(O.MANIFEST_LOADED,{levels:[v],audioTracks:[],url:u,stats:t,networkDetails:i,sessionData:null,sessionKeys:null,contentSteering:null,startTimeOffset:null,variableList:null})}t.parsing.end=performance.now(),r.levelDetails=f,this.handlePlaylistLoaded(f,e,t,r,i,a)}},{key:"handleManifestParsingError",value:function(e,t,r,i,a){this.hls.trigger(O.ERROR,{type:M.NETWORK_ERROR,details:N.MANIFEST_PARSING_ERROR,fatal:t.type===Tt,url:e.url,err:r,error:r,reason:r.message,response:e,context:t,networkDetails:i,stats:a})}},{key:"handleNetworkError",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0,n="A network ".concat(r?"timeout":"error"+(i?" (status "+i.code+")":"")," occurred while loading ").concat(e.type);e.type===Et?n+=": ".concat(e.level," id: ").concat(e.id):e.type!==St&&e.type!==Lt||(n+=" id: ".concat(e.id,' group-id: "').concat(e.groupId,'"'));var s=new Error(n);K.warn("[playlist-loader]: ".concat(n));var o=N.UNKNOWN,l=!1,u=this.getInternalLoader(e);switch(e.type){case Tt:o=r?N.MANIFEST_LOAD_TIMEOUT:N.MANIFEST_LOAD_ERROR,l=!0;break;case Et:o=r?N.LEVEL_LOAD_TIMEOUT:N.LEVEL_LOAD_ERROR,l=!1;break;case St:o=r?N.AUDIO_TRACK_LOAD_TIMEOUT:N.AUDIO_TRACK_LOAD_ERROR,l=!1;break;case Lt:o=r?N.SUBTITLE_TRACK_LOAD_TIMEOUT:N.SUBTITLE_LOAD_ERROR,l=!1}u&&this.resetInternalLoader(e.type);var c={type:M.NETWORK_ERROR,details:o,fatal:l,url:e.url,loader:u,context:e,error:s,networkDetails:t,stats:a};if(i){var h=(null==t?void 0:t.url)||e.url;c.response=_({url:h,data:void 0},i)}this.hls.trigger(O.ERROR,c)}},{key:"handlePlaylistLoaded",value:function(e,t,r,i,a,n){var s=this.hls,o=i.type,l=i.level,u=i.id,c=i.groupId,h=i.deliveryDirectives,d=It(t,i),f=Dt(i),v="number"==typeof i.level&&f===At?l:void 0;if(e.fragments.length){e.targetduration||(e.playlistParsingError=new Error("Missing Target Duration"));var g=e.playlistParsingError;if(g)s.trigger(O.ERROR,{type:M.NETWORK_ERROR,details:N.LEVEL_PARSING_ERROR,fatal:!1,url:d,error:g,reason:g.message,response:t,context:i,level:v,parent:f,networkDetails:a,stats:r});else switch(e.live&&n&&(n.getCacheAge&&(e.ageHeader=n.getCacheAge()||0),n.getCacheAge&&!isNaN(e.ageHeader)||(e.ageHeader=0)),o){case Tt:case Et:s.trigger(O.LEVEL_LOADED,{details:e,level:v||0,id:u||0,stats:r,networkDetails:a,deliveryDirectives:h});break;case St:s.trigger(O.AUDIO_TRACK_LOADED,{details:e,id:u||0,groupId:c||"",stats:r,networkDetails:a,deliveryDirectives:h});break;case Lt:s.trigger(O.SUBTITLE_TRACK_LOADED,{details:e,id:u||0,groupId:c||"",stats:r,networkDetails:a,deliveryDirectives:h})}}else{var m=new Error("No Segments found in Playlist");s.trigger(O.ERROR,{type:M.NETWORK_ERROR,details:N.LEVEL_EMPTY_ERROR,fatal:!1,url:d,error:m,reason:m.message,response:t,context:i,level:v,parent:f,networkDetails:a,stats:r})}}}]),e}();function Ct(e,t){var r;try{r=new Event("addtrack")}catch(e){(r=document.createEvent("Event")).initEvent("addtrack",!1,!1)}r.track=e,t.dispatchEvent(r)}function _t(e,t){var r=e.mode;if("disabled"===r&&(e.mode="hidden"),e.cues&&!e.cues.getCueById(t.id))try{if(e.addCue(t),!e.cues.getCueById(t.id))throw new Error("addCue is failed for: ".concat(t))}catch(r){K.debug("[texttrack-utils]: ".concat(r));try{var i=new self.TextTrackCue(t.startTime,t.endTime,t.text);i.id=t.id,e.addCue(i)}catch(e){K.debug("[texttrack-utils]: Legacy TextTrackCue fallback failed: ".concat(e))}}"disabled"===r&&(e.mode=r)}function Pt(e){var t=e.mode;if("disabled"===t&&(e.mode="hidden"),e.cues)for(var r=e.cues.length;r--;)e.removeCue(e.cues[r]);"disabled"===t&&(e.mode=t)}function xt(e,t,r,i){var a=e.mode;if("disabled"===a&&(e.mode="hidden"),e.cues&&e.cues.length>0)for(var n=function(e,t,r){var i=[],a=function(e,t){if(t<e[0].startTime)return 0;var r=e.length-1;if(t>e[r].endTime)return-1;for(var i=0,a=r;i<=a;){var n=Math.floor((a+i)/2);if(t<e[n].startTime)a=n-1;else{if(!(t>e[n].startTime&&i<r))return n;i=n+1}}return e[i].startTime-t<t-e[a].startTime?i:a}(e,t);if(a>-1)for(var n=a,s=e.length;n<s;n++){var o=e[n];if(o.startTime>=t&&o.endTime<=r)i.push(o);else if(o.startTime>r)return i}return i}(e.cues,t,r),s=0;s<n.length;s++)i&&!i(n[s])||e.removeCue(n[s]);"disabled"===a&&(e.mode=a)}var Ft="org.id3",Ot="https://aomedia.org/emsg/ID3";function Mt(){if("undefined"!=typeof self)return self.WebKitDataCue||self.VTTCue||self.TextTrackCue}var Nt=function(){var e=Mt();try{new e(0,Number.POSITIVE_INFINITY,"")}catch(e){return Number.MAX_VALUE}return Number.POSITIVE_INFINITY}();function Ut(e,t){return e.getTime()/1e3-t}var Bt=function(){function e(t){y(this,e),this.hls=void 0,this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=t,this._registerListeners()}return k(e,[{key:"destroy",value:function(){this._unregisterListeners(),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=null}},{key:"_registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.on(O.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(O.LEVEL_UPDATED,this.onLevelUpdated,this)}},{key:"_unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.off(O.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(O.LEVEL_UPDATED,this.onLevelUpdated,this)}},{key:"onMediaAttached",value:function(e,t){this.media=t.media}},{key:"onMediaDetaching",value:function(){this.id3Track&&(Pt(this.id3Track),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={})}},{key:"onManifestLoading",value:function(){this.dateRangeCuesAppended={}}},{key:"createTrack",value:function(e){var t=this.getID3Track(e.textTracks);return t.mode="hidden",t}},{key:"getID3Track",value:function(e){if(this.media){for(var t=0;t<e.length;t++){var r=e[t];if("metadata"===r.kind&&"id3"===r.label)return Ct(r,this.media),r}return this.media.addTextTrack("metadata","id3")}}},{key:"onFragParsingMetadata",value:function(e,t){if(this.media){var r=this.hls.config,i=r.enableEmsgMetadataCues,a=r.enableID3MetadataCues;if(i||a){var n=t.samples;this.id3Track||(this.id3Track=this.createTrack(this.media));for(var s=Mt(),o=0;o<n.length;o++){var l=n[o].type;if((l!==Ot||i)&&a){var u=Se(n[o].data);if(u){var c=n[o].pts,h=c+n[o].duration;h>Nt&&(h=Nt),h-c<=0&&(h=c+.25);for(var d=0;d<u.length;d++){var f=u[d];if(!Te(f)){this.updateId3CueEnds(c,l);var v=new s(c,h,"");v.value=f,l&&(v.type=l),this.id3Track.addCue(v)}}}}}}}}},{key:"updateId3CueEnds",value:function(e,t){var r,i=null==(r=this.id3Track)?void 0:r.cues;if(i)for(var a=i.length;a--;){var n=i[a];n.type===t&&n.startTime<e&&n.endTime===Nt&&(n.endTime=e)}}},{key:"onBufferFlushing",value:function(e,t){var r=t.startOffset,i=t.endOffset,a=t.type,n=this.id3Track,s=this.hls;if(s){var o=s.config,l=o.enableEmsgMetadataCues,u=o.enableID3MetadataCues;n&&(l||u)&&xt(n,r,i,"audio"===a?function(e){return e.type===Ft&&u}:"video"===a?function(e){return e.type===Ot&&l}:function(e){return e.type===Ft&&u||e.type===Ot&&l})}}},{key:"onLevelUpdated",value:function(e,t){var r=this,i=t.details;if(this.media&&i.hasProgramDateTime&&this.hls.config.enableDateRangeMetadataCues){var a=this.dateRangeCuesAppended,n=this.id3Track,s=i.dateRanges,o=Object.keys(s);if(n)for(var l=Object.keys(a).filter((function(e){return!o.includes(e)})),u=function(){var e=l[c];Object.keys(a[e].cues).forEach((function(t){n.removeCue(a[e].cues[t])})),delete a[e]},c=l.length;c--;)u();var h=i.fragments[i.fragments.length-1];if(0!==o.length&&F(null==h?void 0:h.programDateTime)){this.id3Track||(this.id3Track=this.createTrack(this.media));for(var d=h.programDateTime/1e3-h.start,f=Mt(),v=function(){var e=o[g],t=s[e],i=a[e],n=(null==i?void 0:i.cues)||{},l=(null==i?void 0:i.durationKnown)||!1,u=Ut(t.startDate,d),c=Nt,h=t.endDate;if(h)c=Ut(h,d),l=!0;else if(t.endOnNext&&!l){var v=o.reduce((function(e,r){var i=s[r];return i.class===t.class&&i.id!==r&&i.startDate>t.startDate&&e.push(i),e}),[]).sort((function(e,t){return e.startDate.getTime()-t.startDate.getTime()}))[0];v&&(c=Ut(v.startDate,d),l=!0)}for(var m,y,p=Object.keys(t.attr),k=0;k<p.length;k++){var T=p[k];if("ID"!==(y=T)&&"CLASS"!==y&&"START-DATE"!==y&&"DURATION"!==y&&"END-DATE"!==y&&"END-ON-NEXT"!==y){var E=n[T];if(E)l&&!i.durationKnown&&(E.endTime=c);else{var S=t.attr[T];E=new f(u,c,""),W(T)&&(m=S,S=Uint8Array.from(m.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer),E.value={key:T,data:S},E.type="com.apple.quicktime.HLS",E.id=e,r.id3Track.addCue(E),n[T]=E}}}a[e]={cues:n,dateRange:t,durationKnown:l}},g=0;g<o.length;g++)v()}}}}]),e}(),Gt=function(){function e(t){var r=this;y(this,e),this.hls=void 0,this.config=void 0,this.media=null,this.levelDetails=null,this.currentTime=0,this.stallCount=0,this._latency=null,this.timeupdateHandler=function(){return r.timeupdate()},this.hls=t,this.config=t.config,this.registerListeners()}return k(e,[{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var e=this.config,t=this.levelDetails;return void 0!==e.liveMaxLatencyDuration?e.liveMaxLatencyDuration:t?e.liveMaxLatencyDurationCount*t.targetduration:0}},{key:"targetLatency",get:function(){var e=this.levelDetails;if(null===e)return null;var t=e.holdBack,r=e.partHoldBack,i=e.targetduration,a=this.config,n=a.liveSyncDuration,s=a.liveSyncDurationCount,o=a.lowLatencyMode,l=this.hls.userConfig,u=o&&r||t;(l.liveSyncDuration||l.liveSyncDurationCount||0===u)&&(u=void 0!==n?n:s*i);var c=i;return u+Math.min(1*this.stallCount,c)}},{key:"liveSyncPosition",get:function(){var e=this.estimateLiveEdge(),t=this.targetLatency,r=this.levelDetails;if(null===e||null===t||null===r)return null;var i=r.edge,a=e-t-this.edgeStalled,n=i-r.totalduration,s=i-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(n,a),s)}},{key:"drift",get:function(){var e=this.levelDetails;return null===e?1:e.drift}},{key:"edgeStalled",get:function(){var e=this.levelDetails;if(null===e)return 0;var t=3*(this.config.lowLatencyMode&&e.partTarget||e.targetduration);return Math.max(e.age-t,0)}},{key:"forwardBufferLength",get:function(){var e=this.media,t=this.levelDetails;if(!e||!t)return 0;var r=e.buffered.length;return(r?e.buffered.end(r-1):t.edge)-this.currentTime}},{key:"destroy",value:function(){this.unregisterListeners(),this.onMediaDetaching(),this.levelDetails=null,this.hls=this.timeupdateHandler=null}},{key:"registerListeners",value:function(){this.hls.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.on(O.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(O.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.on(O.ERROR,this.onError,this)}},{key:"unregisterListeners",value:function(){this.hls.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.off(O.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(O.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.off(O.ERROR,this.onError,this)}},{key:"onMediaAttached",value:function(e,t){this.media=t.media,this.media.addEventListener("timeupdate",this.timeupdateHandler)}},{key:"onMediaDetaching",value:function(){this.media&&(this.media.removeEventListener("timeupdate",this.timeupdateHandler),this.media=null)}},{key:"onManifestLoading",value:function(){this.levelDetails=null,this._latency=null,this.stallCount=0}},{key:"onLevelUpdated",value:function(e,t){var r=t.details;this.levelDetails=r,r.advanced&&this.timeupdate(),!r.live&&this.media&&this.media.removeEventListener("timeupdate",this.timeupdateHandler)}},{key:"onError",value:function(e,t){var r;t.details===N.BUFFER_STALLED_ERROR&&(this.stallCount++,null!=(r=this.levelDetails)&&r.live&&K.warn("[playback-rate-controller]: Stall detected, adjusting target latency"))}},{key:"timeupdate",value:function(){var e=this.media,t=this.levelDetails;if(e&&t){this.currentTime=e.currentTime;var r=this.computeLatency();if(null!==r){this._latency=r;var i=this.config,a=i.lowLatencyMode,n=i.maxLiveSyncPlaybackRate;if(a&&1!==n){var s=this.targetLatency;if(null!==s){var o=r-s,l=o<Math.min(this.maxLatency,s+t.targetduration);if(t.live&&l&&o>.05&&this.forwardBufferLength>1){var u=Math.min(2,Math.max(1,n)),c=Math.round(2/(1+Math.exp(-.75*o-this.edgeStalled))*20)/20;e.playbackRate=Math.min(u,Math.max(1,c))}else 1!==e.playbackRate&&0!==e.playbackRate&&(e.playbackRate=1)}}}}}},{key:"estimateLiveEdge",value:function(){var e=this.levelDetails;return null===e?null:e.edge+e.age}},{key:"computeLatency",value:function(){var e=this.estimateLiveEdge();return null===e?null:e-this.currentTime}}]),e}(),Kt=["NONE","TYPE-0","TYPE-1",null],Ht=function(){function e(t,r,i){y(this,e),this.msn=void 0,this.part=void 0,this.skip=void 0,this.msn=t,this.part=r,this.skip=i}return k(e,[{key:"addDirectives",value:function(e){var t=new self.URL(e);return void 0!==this.msn&&t.searchParams.set("_HLS_msn",this.msn.toString()),void 0!==this.part&&t.searchParams.set("_HLS_part",this.part.toString()),this.skip&&t.searchParams.set("_HLS_skip",this.skip),t.href}}]),e}(),Vt=function(){function e(t){y(this,e),this._attrs=void 0,this.audioCodec=void 0,this.bitrate=void 0,this.codecSet=void 0,this.height=void 0,this.id=void 0,this.name=void 0,this.videoCodec=void 0,this.width=void 0,this.unknownCodecs=void 0,this.audioGroupIds=void 0,this.details=void 0,this.fragmentError=0,this.loadError=0,this.loaded=void 0,this.realBitrate=0,this.textGroupIds=void 0,this.url=void 0,this._urlId=0,this.url=[t.url],this._attrs=[t.attrs],this.bitrate=t.bitrate,t.details&&(this.details=t.details),this.id=t.id||0,this.name=t.name,this.width=t.width||0,this.height=t.height||0,this.audioCodec=t.audioCodec,this.videoCodec=t.videoCodec,this.unknownCodecs=t.unknownCodecs,this.codecSet=[t.videoCodec,t.audioCodec].filter((function(e){return e})).join(",").replace(/\.[^.,]+/g,"")}return k(e,[{key:"maxBitrate",get:function(){return Math.max(this.realBitrate,this.bitrate)}},{key:"attrs",get:function(){return this._attrs[this._urlId]}},{key:"pathwayId",get:function(){return this.attrs["PATHWAY-ID"]||"."}},{key:"uri",get:function(){return this.url[this._urlId]||""}},{key:"urlId",get:function(){return this._urlId},set:function(e){var t=e%this.url.length;this._urlId!==t&&(this.fragmentError=0,this.loadError=0,this.details=void 0,this._urlId=t)}},{key:"audioGroupId",get:function(){var e;return null==(e=this.audioGroupIds)?void 0:e[this.urlId]}},{key:"textGroupId",get:function(){var e;return null==(e=this.textGroupIds)?void 0:e[this.urlId]}},{key:"addFallback",value:function(e){this.url.push(e.url),this._attrs.push(e.attrs)}}]),e}();function Yt(e,t){var r=t.startPTS;if(F(r)){var i,a=0;t.sn>e.sn?(a=r-e.start,i=e):(a=e.start-r,i=t),i.duration!==a&&(i.duration=a)}else t.sn>e.sn?e.cc===t.cc&&e.minEndPTS?t.start=e.start+(e.minEndPTS-e.start):t.start=e.start+e.duration:t.start=Math.max(e.start-t.duration,0)}function Wt(e,t,r,i,a,n){i-r<=0&&(K.warn("Fragment should have a positive duration",t),i=r+t.duration,n=a+t.duration);var s=r,o=i,l=t.startPTS,u=t.endPTS;if(F(l)){var c=Math.abs(l-r);F(t.deltaPTS)?t.deltaPTS=Math.max(c,t.deltaPTS):t.deltaPTS=c,s=Math.max(r,l),r=Math.min(r,l),a=Math.min(a,t.startDTS),o=Math.min(i,u),i=Math.max(i,u),n=Math.max(n,t.endDTS)}var h=r-t.start;0!==t.start&&(t.start=r),t.duration=i-t.start,t.startPTS=r,t.maxStartPTS=s,t.startDTS=a,t.endPTS=i,t.minEndPTS=o,t.endDTS=n;var d,f=t.sn;if(!e||f<e.startSN||f>e.endSN)return 0;var v=f-e.startSN,g=e.fragments;for(g[v]=t,d=v;d>0;d--)Yt(g[d],g[d-1]);for(d=v;d<g.length-1;d++)Yt(g[d],g[d+1]);return e.fragmentHint&&Yt(g[g.length-1],e.fragmentHint),e.PTSKnown=e.alignedSliding=!0,h}function jt(e,t){var r=t.startSN+t.skippedSegments-e.startSN,i=e.fragments;r<0||r>=i.length||qt(t,i[r].start)}function qt(e,t){if(t){for(var r=e.fragments,i=e.skippedSegments;i<r.length;i++)r[i].start+=t;e.fragmentHint&&(e.fragmentHint.start+=t)}}function Xt(e,t,r){var i;return null!=e&&e.details?zt(null==(i=e.details)?void 0:i.partList,t,r):null}function zt(e,t,r){if(e)for(var i=e.length;i--;){var a=e[i];if(a.index===r&&a.fragment.sn===t)return a}return null}function Qt(e){switch(e.details){case N.FRAG_LOAD_TIMEOUT:case N.KEY_LOAD_TIMEOUT:case N.LEVEL_LOAD_TIMEOUT:case N.MANIFEST_LOAD_TIMEOUT:return!0}return!1}function $t(e,t){var r=Qt(t);return e.default["".concat(r?"timeout":"error","Retry")]}function Jt(e,t){var r="linear"===e.backoff?1:Math.pow(2,t);return Math.min(r*e.retryDelayMs,e.maxRetryDelayMs)}function Zt(e){return _(_({},e),{errorRetry:null,timeoutRetry:null})}function er(e,t,r,i){return!!e&&t<e.maxNumRetry&&(function(e){return 0===e&&!1===navigator.onLine||!!e&&(e<400||e>499)}(i)||!!r)}var tr=function(e,t){for(var r=0,i=e.length-1,a=null,n=null;r<=i;){var s=t(n=e[a=(r+i)/2|0]);if(s>0)r=a+1;else{if(!(s<0))return n;i=a-1}}return null};function rr(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=null;if(e?a=t[e.sn-t[0].sn+1]||null:0===r&&0===t[0].start&&(a=t[0]),a&&0===ir(r,i,a))return a;var n=tr(t,ir.bind(null,r,i));return!n||n===e&&a?a:n}function ir(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2?arguments[2]:void 0;if(r.start<=e&&r.start+r.duration>e)return 0;var i=Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return r.start+r.duration-i<=e?1:r.start-i>e&&r.start?-1:0}function ar(e,t,r){var i=1e3*Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return(r.endProgramDateTime||0)-i>e}var nr,sr=function(){function e(t){y(this,e),this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=t,this.log=K.log.bind(K,"[info]:"),this.warn=K.warn.bind(K,"[warning]:"),this.error=K.error.bind(K,"[error]:"),this.registerListeners()}return k(e,[{key:"registerListeners",value:function(){var e=this.hls;e.on(O.ERROR,this.onError,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.LEVEL_UPDATED,this.onLevelUpdated,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e&&(e.off(O.ERROR,this.onError,this),e.off(O.ERROR,this.onErrorOut,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.LEVEL_UPDATED,this.onLevelUpdated,this))}},{key:"destroy",value:function(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}}},{key:"startLoad",value:function(e){this.playlistError=0}},{key:"stopLoad",value:function(){}},{key:"getVariantLevelIndex",value:function(e){return(null==e?void 0:e.type)===At?e.level:this.hls.loadLevel}},{key:"onManifestLoading",value:function(){this.playlistError=0,this.penalizedRenditions={}}},{key:"onLevelUpdated",value:function(){this.playlistError=0}},{key:"onError",value:function(e,t){var r,i;if(!t.fatal){var a=this.hls,n=t.context;switch(t.details){case N.FRAG_LOAD_ERROR:case N.FRAG_LOAD_TIMEOUT:case N.KEY_LOAD_ERROR:case N.KEY_LOAD_TIMEOUT:return void(t.errorAction=this.getFragRetryOrSwitchAction(t));case N.FRAG_PARSING_ERROR:if(null!=(r=t.frag)&&r.gap)return void(t.errorAction={action:0,flags:0});case N.FRAG_GAP:case N.FRAG_DECRYPT_ERROR:return t.errorAction=this.getFragRetryOrSwitchAction(t),void(t.errorAction.action=2);case N.LEVEL_EMPTY_ERROR:case N.LEVEL_PARSING_ERROR:var s,o,l=t.parent===At?t.level:a.loadLevel;return void(t.details===N.LEVEL_EMPTY_ERROR&&null!=(s=t.context)&&null!=(o=s.levelDetails)&&o.live?t.errorAction=this.getPlaylistRetryOrSwitchAction(t,l):(t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,l)));case N.LEVEL_LOAD_ERROR:case N.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==n?void 0:n.level)&&(t.errorAction=this.getPlaylistRetryOrSwitchAction(t,n.level)));case N.AUDIO_TRACK_LOAD_ERROR:case N.AUDIO_TRACK_LOAD_TIMEOUT:case N.SUBTITLE_LOAD_ERROR:case N.SUBTITLE_TRACK_LOAD_TIMEOUT:if(n){var u=a.levels[a.loadLevel];if(u&&(n.type===St&&n.groupId===u.audioGroupId||n.type===Lt&&n.groupId===u.textGroupId))return t.errorAction=this.getPlaylistRetryOrSwitchAction(t,a.loadLevel),t.errorAction.action=2,void(t.errorAction.flags=1)}return;case N.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:var c=a.levels[a.loadLevel],h=null==c?void 0:c.attrs["HDCP-LEVEL"];return void(h&&(t.errorAction={action:2,flags:2,hdcpLevel:h}));case N.BUFFER_ADD_CODEC_ERROR:case N.REMUX_ALLOC_ERROR:return void(t.errorAction=this.getLevelSwitchAction(t,null!=(i=t.level)?i:a.loadLevel));case N.INTERNAL_EXCEPTION:case N.BUFFER_APPENDING_ERROR:case N.BUFFER_APPEND_ERROR:case N.BUFFER_FULL_ERROR:case N.LEVEL_SWITCH_ERROR:case N.BUFFER_STALLED_ERROR:case N.BUFFER_SEEK_OVER_HOLE:case N.BUFFER_NUDGE_ON_STALL:return void(t.errorAction={action:0,flags:0})}if(t.type===M.KEY_SYSTEM_ERROR){var d=this.getVariantLevelIndex(t.frag);return t.levelRetry=!1,void(t.errorAction=this.getLevelSwitchAction(t,d))}}}},{key:"getPlaylistRetryOrSwitchAction",value:function(e,t){var r,i=$t(this.hls.config.playlistLoadPolicy,e),a=this.playlistError++,n=null==(r=e.response)?void 0:r.code;if(er(i,a,Qt(e),n))return{action:5,flags:0,retryConfig:i,retryCount:a};var s=this.getLevelSwitchAction(e,t);return i&&(s.retryConfig=i,s.retryCount=a),s}},{key:"getFragRetryOrSwitchAction",value:function(e){var t=this.hls,r=this.getVariantLevelIndex(e.frag),i=t.levels[r],a=t.config,n=a.fragLoadPolicy,s=a.keyLoadPolicy,o=$t(e.details.startsWith("key")?s:n,e),l=t.levels.reduce((function(e,t){return e+t.fragmentError}),0);if(i){var u;e.details!==N.FRAG_GAP&&i.fragmentError++;var c=null==(u=e.response)?void 0:u.code;if(er(o,l,Qt(e),c))return{action:5,flags:0,retryConfig:o,retryCount:l}}var h=this.getLevelSwitchAction(e,r);return o&&(h.retryConfig=o,h.retryCount=l),h}},{key:"getLevelSwitchAction",value:function(e,t){var r=this.hls;null==t&&(t=r.loadLevel);var i=this.hls.levels[t];if(i&&(i.loadError++,r.autoLevelEnabled)){for(var a,n,s=-1,o=r.levels,l=r.loadLevel,u=r.minAutoLevel,c=r.maxAutoLevel,h=null==(a=e.frag)?void 0:a.type,d=null!=(n=e.context)?n:{},f=d.type,v=d.groupId,g=o.length;g--;){var m=(g+l)%o.length;if(m!==l&&m>=u&&m<=c&&0===o[m].loadError){var y=o[m];if(e.details===N.FRAG_GAP&&e.frag){var p=o[m].details;if(p){var k=rr(e.frag,p.fragments,e.frag.start);if(null!=k&&k.gap)continue}}else{if(f===St&&v===y.audioGroupId||f===Lt&&v===y.textGroupId)continue;if(h===Rt&&i.audioGroupId===y.audioGroupId||h===bt&&i.textGroupId===y.textGroupId)continue}s=m;break}}if(s>-1&&r.loadLevel!==s)return e.levelRetry=!0,this.playlistError=0,{action:2,flags:0,nextAutoLevel:s}}return{action:2,flags:1}}},{key:"onErrorOut",value:function(e,t){var r;switch(null==(r=t.errorAction)?void 0:r.action){case 0:break;case 2:this.sendAlternateToPenaltyBox(t),t.errorAction.resolved||t.details===N.FRAG_GAP||(t.fatal=!0)}t.fatal&&this.hls.stopLoad()}},{key:"sendAlternateToPenaltyBox",value:function(e){var t=this.hls,r=e.errorAction;if(r){var i=r.flags,a=r.hdcpLevel,n=r.nextAutoLevel;switch(i){case 0:this.switchLevel(e,n);break;case 1:r.resolved||(r.resolved=this.redundantFailover(e));break;case 2:a&&(t.maxHdcpLevel=Kt[Kt.indexOf(a)-1],r.resolved=!0),this.warn('Restricting playback to HDCP-LEVEL of "'.concat(t.maxHdcpLevel,'" or lower'))}r.resolved||this.switchLevel(e,n)}}},{key:"switchLevel",value:function(e,t){void 0!==t&&e.errorAction&&(this.warn("switching to level ".concat(t," after ").concat(e.details)),this.hls.nextAutoLevel=t,e.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)}},{key:"redundantFailover",value:function(e){var t=this,r=this.hls,i=this.penalizedRenditions,a=e.parent===At?e.level:r.loadLevel,n=r.levels[a],s=n.url.length,o=e.frag?e.frag.urlId:n.urlId;n.urlId!==o||e.frag&&!n.details||this.penalizeRendition(n,e);for(var l,u=function(){var l=(o+c)%s,u=i[l];if(!u||function(e,t,r){if(performance.now()-e.lastErrorPerfMs>3e5)return!0;var i=e.details;if(t.details===N.FRAG_GAP&&i&&t.frag){var a=t.frag.start,n=rr(null,i.fragments,a);if(n&&!n.gap)return!0}if(r&&e.errors.length<r.errors.length){var s=e.errors[e.errors.length-1];if(i&&s.frag&&t.frag&&Math.abs(s.frag.start-t.frag.start)>3*i.targetduration)return!0}return!1}(u,e,i[o]))return t.warn("Switching to Redundant Stream ".concat(l+1,"/").concat(s,': "').concat(n.url[l],'" after ').concat(e.details)),t.playlistError=0,r.levels.forEach((function(e){e.urlId=l})),r.nextLoadLevel=a,{v:!0}},c=1;c<s;c++)if(l=u())return l.v;return!1}},{key:"penalizeRendition",value:function(e,t){var r=this.penalizedRenditions,i=r[e.urlId]||{lastErrorPerfMs:0,errors:[],details:void 0};i.lastErrorPerfMs=performance.now(),i.errors.push(t),i.details=e.details,r[e.urlId]=i}}]),e}(),or=function(){function e(t,r){y(this,e),this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.log=void 0,this.warn=void 0,this.log=K.log.bind(K,"".concat(r,":")),this.warn=K.warn.bind(K,"".concat(r,":")),this.hls=t}return k(e,[{key:"destroy",value:function(){this.clearTimer(),this.hls=this.log=this.warn=null}},{key:"clearTimer",value:function(){clearTimeout(this.timer),this.timer=-1}},{key:"startLoad",value:function(){this.canLoad=!0,this.requestScheduled=-1,this.loadPlaylist()}},{key:"stopLoad",value:function(){this.canLoad=!1,this.clearTimer()}},{key:"switchParams",value:function(e,t){var r=null==t?void 0:t.renditionReports;if(r){for(var i=-1,a=0;a<r.length;a++){var n=r[a],s=void 0;try{s=new self.URL(n.URI,t.url).href}catch(e){K.warn("Could not construct new URL for Rendition Report: ".concat(e)),s=n.URI||""}if(s===e){i=a;break}s===e.substring(0,s.length)&&(i=a)}if(-1!==i){var o=r[i],l=parseInt(o["LAST-MSN"])||(null==t?void 0:t.lastPartSn),u=parseInt(o["LAST-PART"])||(null==t?void 0:t.lastPartIndex);if(this.hls.config.lowLatencyMode){var c=Math.min(t.age-t.partTarget,t.targetduration);u>=0&&c>t.partTarget&&(u+=1)}return new Ht(l,u>=0?u:void 0,"")}}}},{key:"loadPlaylist",value:function(e){-1===this.requestScheduled&&(this.requestScheduled=self.performance.now())}},{key:"shouldLoadPlaylist",value:function(e){return this.canLoad&&!!e&&!!e.url&&(!e.details||e.details.live)}},{key:"shouldReloadPlaylist",value:function(e){return-1===this.timer&&-1===this.requestScheduled&&this.shouldLoadPlaylist(e)}},{key:"playlistLoaded",value:function(e,t,r){var i=this,a=t.details,n=t.stats,s=self.performance.now(),o=n.loading.first?Math.max(0,s-n.loading.first):0;if(a.advancedDateTime=Date.now()-o,a.live||null!=r&&r.live){if(a.reloaded(r),r&&this.log("live playlist ".concat(e," ").concat(a.advanced?"REFRESHED "+a.lastPartSn+"-"+a.lastPartIndex:a.updated?"UPDATED":"MISSED")),r&&a.fragments.length>0&&function(e,t){for(var r=null,i=e.fragments,a=i.length-1;a>=0;a--){var n=i[a].initSegment;if(n){r=n;break}}e.fragmentHint&&delete e.fragmentHint.endPTS;var s,o,l,u,c,h=0;if(function(e,t,r){for(var i=t.skippedSegments,a=Math.max(e.startSN,t.startSN)-t.startSN,n=(e.fragmentHint?1:0)+(i?t.endSN:Math.min(e.endSN,t.endSN))-t.startSN,s=t.startSN-e.startSN,o=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments,l=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments,u=a;u<=n;u++){var c=l[s+u],h=o[u];i&&!h&&u<i&&(h=t.fragments[u]=c),c&&h&&r(c,h)}}(e,t,(function(e,i){e.relurl&&(h=e.cc-i.cc),F(e.startPTS)&&F(e.endPTS)&&(i.start=i.startPTS=e.startPTS,i.startDTS=e.startDTS,i.maxStartPTS=e.maxStartPTS,i.endPTS=e.endPTS,i.endDTS=e.endDTS,i.minEndPTS=e.minEndPTS,i.duration=e.endPTS-e.startPTS,i.duration&&(s=i),t.PTSKnown=t.alignedSliding=!0),i.elementaryStreams=e.elementaryStreams,i.loader=e.loader,i.stats=e.stats,i.urlId=e.urlId,e.initSegment&&(i.initSegment=e.initSegment,r=e.initSegment)})),r&&(t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments).forEach((function(e){var t;e.initSegment&&e.initSegment.relurl!==(null==(t=r)?void 0:t.relurl)||(e.initSegment=r)})),t.skippedSegments)if(t.deltaUpdateFailed=t.fragments.some((function(e){return!e})),t.deltaUpdateFailed){K.warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(var d=t.skippedSegments;d--;)t.fragments.shift();t.startSN=t.fragments[0].sn,t.startCC=t.fragments[0].cc}else t.canSkipDateRanges&&(t.dateRanges=(o=e.dateRanges,l=t.dateRanges,u=t.recentlyRemovedDateranges,c=x({},o),u&&u.forEach((function(e){delete c[e]})),Object.keys(l).forEach((function(e){var t=new j(l[e].attr,c[e]);t.isValid?c[e]=t:K.warn('Ignoring invalid Playlist Delta Update DATERANGE tag: "'.concat(JSON.stringify(l[e].attr),'"'))})),c));var f=t.fragments;if(h){K.warn("discontinuity sliding from playlist, take drift into account");for(var v=0;v<f.length;v++)f[v].cc+=h}t.skippedSegments&&(t.startCC=t.fragments[0].cc),function(e,t,r){if(e&&t)for(var i=0,a=0,n=e.length;a<=n;a++){var s=e[a],o=t[a+i];s&&o&&s.index===o.index&&s.fragment.sn===o.fragment.sn?r(s,o):i--}}(e.partList,t.partList,(function(e,t){t.elementaryStreams=e.elementaryStreams,t.stats=e.stats})),s?Wt(t,s,s.startPTS,s.endPTS,s.startDTS,s.endDTS):jt(e,t),f.length&&(t.totalduration=t.edge-f[0].start),t.driftStartTime=e.driftStartTime,t.driftStart=e.driftStart;var g=t.advancedDateTime;if(t.advanced&&g){var m=t.edge;t.driftStart||(t.driftStartTime=g,t.driftStart=m),t.driftEndTime=g,t.driftEnd=m}else t.driftEndTime=e.driftEndTime,t.driftEnd=e.driftEnd,t.advancedDateTime=e.advancedDateTime}(r,a),!this.canLoad||!a.live)return;var l,u=void 0,c=void 0;if(a.canBlockReload&&a.endSN&&a.advanced){var h=this.hls.config.lowLatencyMode,d=a.lastPartSn,f=a.endSN,v=a.lastPartIndex,g=d===f;-1!==v?(u=g?f+1:d,c=g?h?0:v:v+1):u=f+1;var m=a.age,y=m+a.ageHeader,p=Math.min(y-a.partTarget,1.5*a.targetduration);if(p>0){if(r&&p>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: ".concat(r.tuneInGoal," to: ").concat(p," with playlist age: ").concat(a.age)),p=0;else{var k=Math.floor(p/a.targetduration);u+=k,void 0!==c&&(c+=Math.round(p%a.targetduration/a.partTarget)),this.log("CDN Tune-in age: ".concat(a.ageHeader,"s last advanced ").concat(m.toFixed(2),"s goal: ").concat(p," skip sn ").concat(k," to part ").concat(c))}a.tuneInGoal=p}if(l=this.getDeliveryDirectives(a,t.deliveryDirectives,u,c),h||!g)return void this.loadPlaylist(l)}else(a.canBlockReload||a.canSkipUntil)&&(l=this.getDeliveryDirectives(a,t.deliveryDirectives,u,c));var T=this.hls.mainForwardBufferInfo,E=T?T.end-T.len:0,S=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1/0,r=1e3*e.targetduration;if(e.updated){var i=e.fragments;if(i.length&&4*r>t){var a=1e3*i[i.length-1].duration;a<r&&(r=a)}}else r/=2;return Math.round(r)}(a,1e3*(a.edge-E));a.updated&&s>this.requestScheduled+S&&(this.requestScheduled=n.loading.start),void 0!==u&&a.canBlockReload?this.requestScheduled=n.loading.first+S-(1e3*a.partTarget||1e3):-1===this.requestScheduled||this.requestScheduled+S<s?this.requestScheduled=s:this.requestScheduled-s<=0&&(this.requestScheduled+=S);var L=this.requestScheduled-s;L=Math.max(0,L),this.log("reload live playlist ".concat(e," in ").concat(Math.round(L)," ms")),this.timer=self.setTimeout((function(){return i.loadPlaylist(l)}),L)}else this.clearTimer()}},{key:"getDeliveryDirectives",value:function(e,t,r,i){var a=function(e,t){var r=e.canSkipUntil,i=e.canSkipDateRanges,a=e.endSN;return r&&(void 0!==t?t-a:0)<r?i?"v2":"YES":""}(e,r);return null!=t&&t.skip&&e.deltaUpdateFailed&&(r=t.msn,i=t.part,a=""),new Ht(r,i,a)}},{key:"checkRetry",value:function(e){var t=this,r=e.details,i=Qt(e),a=e.errorAction,n=a||{},s=n.action,o=n.retryCount,l=void 0===o?0:o,u=n.retryConfig,c=!!a&&!!u&&(5===s||!a.resolved&&2===s);if(c){var h;if(this.requestScheduled=-1,l>=u.maxNumRetry)return!1;if(i&&null!=(h=e.context)&&h.deliveryDirectives)this.warn("Retrying playlist loading ".concat(l+1,"/").concat(u.maxNumRetry,' after "').concat(r,'" without delivery-directives')),this.loadPlaylist();else{var d=Jt(u,l);this.timer=self.setTimeout((function(){return t.loadPlaylist()}),d),this.warn("Retrying playlist loading ".concat(l+1,"/").concat(u.maxNumRetry,' after "').concat(r,'" in ').concat(d,"ms"))}e.levelRetry=!0,a.resolved=!0}return c}}]),e}(),lr=function(e){c(r,e);var t=d(r);function r(e,i){var a;return y(this,r),(a=t.call(this,e,"[level-controller]"))._levels=[],a._firstLevel=-1,a._startLevel=void 0,a.currentLevel=null,a.currentLevelIndex=-1,a.manualLevelIndex=-1,a.steering=void 0,a.onParsedComplete=void 0,a.steering=i,a._registerListeners(),a}return k(r,[{key:"_registerListeners",value:function(){var e=this.hls;e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(O.LEVEL_LOADED,this.onLevelLoaded,this),e.on(O.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(O.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.on(O.FRAG_LOADED,this.onFragLoaded,this),e.on(O.ERROR,this.onError,this)}},{key:"_unregisterListeners",value:function(){var e=this.hls;e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(O.LEVEL_LOADED,this.onLevelLoaded,this),e.off(O.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(O.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.off(O.FRAG_LOADED,this.onFragLoaded,this),e.off(O.ERROR,this.onError,this)}},{key:"destroy",value:function(){this._unregisterListeners(),this.steering=null,this.resetLevels(),u(g(r.prototype),"destroy",this).call(this)}},{key:"startLoad",value:function(){this._levels.forEach((function(e){e.loadError=0,e.fragmentError=0})),u(g(r.prototype),"startLoad",this).call(this)}},{key:"resetLevels",value:function(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[]}},{key:"onManifestLoading",value:function(e,t){this.resetLevels()}},{key:"onManifestLoaded",value:function(e,t){var r,i=[],a={};t.levels.forEach((function(e){var t,n=e.attrs;-1!==(null==(t=e.audioCodec)?void 0:t.indexOf("mp4a.40.34"))&&(nr||(nr=/chrome|firefox/i.test(navigator.userAgent)),nr&&(e.audioCodec=void 0));var s=n.AUDIO,o=n.CODECS,l=n["FRAME-RATE"],u=n["PATHWAY-ID"],c=n.RESOLUTION,h=n.SUBTITLES,d="".concat(u||".","-"),f="".concat(d).concat(e.bitrate,"-").concat(c,"-").concat(l,"-").concat(o);(r=a[f])?r.addFallback(e):(r=new Vt(e),a[f]=r,i.push(r)),ur(r,"audio",s),ur(r,"text",h)})),this.filterAndSortMediaOptions(i,t)}},{key:"filterAndSortMediaOptions",value:function(e,t){var r=this,i=[],a=[],n=!1,s=!1,o=!1,l=e.filter((function(e){var t=e.audioCodec,r=e.videoCodec,i=e.width,a=e.height,l=e.unknownCodecs;return n||(n=!(!i||!a)),s||(s=!!r),o||(o=!!t),!(null!=l&&l.length)&&(!t||st(t,"audio"))&&(!r||st(r,"video"))}));if((n||s)&&o&&(l=l.filter((function(e){var t=e.videoCodec,r=e.width,i=e.height;return!!t||!(!r||!i)}))),0!==l.length){t.audioTracks&&cr(i=t.audioTracks.filter((function(e){return!e.audioCodec||st(e.audioCodec,"audio")}))),t.subtitles&&cr(a=t.subtitles);var u=l.slice(0);l.sort((function(e,t){return e.attrs["HDCP-LEVEL"]!==t.attrs["HDCP-LEVEL"]?(e.attrs["HDCP-LEVEL"]||"")>(t.attrs["HDCP-LEVEL"]||"")?1:-1:e.bitrate!==t.bitrate?e.bitrate-t.bitrate:e.attrs["FRAME-RATE"]!==t.attrs["FRAME-RATE"]?e.attrs.decimalFloatingPoint("FRAME-RATE")-t.attrs.decimalFloatingPoint("FRAME-RATE"):e.attrs.SCORE!==t.attrs.SCORE?e.attrs.decimalFloatingPoint("SCORE")-t.attrs.decimalFloatingPoint("SCORE"):n&&e.height!==t.height?e.height-t.height:0}));var c=u[0];if(this.steering&&(l=this.steering.filterParsedLevels(l)).length!==u.length)for(var h=0;h<u.length;h++)if(u[h].pathwayId===l[0].pathwayId){c=u[h];break}this._levels=l;for(var d=0;d<l.length;d++)if(l[d]===c){this._firstLevel=d,this.log("manifest loaded, ".concat(l.length," level(s) found, first bitrate: ").concat(c.bitrate));break}var f=o&&!s,v={levels:l,audioTracks:i,subtitleTracks:a,sessionData:t.sessionData,sessionKeys:t.sessionKeys,firstLevel:this._firstLevel,stats:t.stats,audio:o,video:s,altAudio:!f&&i.some((function(e){return!!e.url}))};this.hls.trigger(O.MANIFEST_PARSED,v),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else Promise.resolve().then((function(){if(r.hls){var e=new Error("no level with compatible codecs found in manifest");r.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:t.url,error:e,reason:e.message})}}))}},{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(e){var t=this._levels;if(0!==t.length){if(e<0||e>=t.length){var r=new Error("invalid level idx"),i=e<0;if(this.hls.trigger(O.ERROR,{type:M.OTHER_ERROR,details:N.LEVEL_SWITCH_ERROR,level:e,fatal:i,error:r,reason:r.message}),i)return;e=Math.min(e,t.length-1)}var a=this.currentLevelIndex,n=this.currentLevel,s=n?n.attrs["PATHWAY-ID"]:void 0,o=t[e],l=o.attrs["PATHWAY-ID"];if(this.currentLevelIndex=e,this.currentLevel=o,a!==e||!o.details||!n||s!==l){this.log("Switching to level ".concat(e).concat(l?" with Pathway "+l:""," from level ").concat(a).concat(s?" with Pathway "+s:""));var u=x({},o,{level:e,maxBitrate:o.maxBitrate,attrs:o.attrs,uri:o.uri,urlId:o.urlId});delete u._attrs,delete u._urlId,this.hls.trigger(O.LEVEL_SWITCHING,u);var c=o.details;if(!c||c.live){var h=this.switchParams(o.uri,null==n?void 0:n.details);this.loadPlaylist(h)}}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(e){this.manualLevelIndex=e,void 0===this._startLevel&&(this._startLevel=e),-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var e=this.hls.config.startLevel;return void 0!==e?e:this._firstLevel}return this._startLevel},set:function(e){this._startLevel=e}},{key:"onError",value:function(e,t){!t.fatal&&t.context&&t.context.type===Et&&t.context.level===this.level&&this.checkRetry(t)}},{key:"onFragLoaded",value:function(e,t){var r=t.frag;if(void 0!==r&&r.type===At){var i=this._levels[r.level];void 0!==i&&(i.loadError=0)}}},{key:"onLevelLoaded",value:function(e,t){var r,i,a=t.level,n=t.details,s=this._levels[a];if(!s)return this.warn("Invalid level index ".concat(a)),void(null!=(i=t.deliveryDirectives)&&i.skip&&(n.deltaUpdateFailed=!0));a===this.currentLevelIndex?(0===s.fragmentError&&(s.loadError=0),this.playlistLoaded(a,t,s.details)):null!=(r=t.deliveryDirectives)&&r.skip&&(n.deltaUpdateFailed=!0)}},{key:"onAudioTrackSwitched",value:function(e,t){var r=this.currentLevel;if(r){var i=this.hls.audioTracks[t.id].groupId;if(r.audioGroupIds&&r.audioGroupId!==i){for(var a=-1,n=0;n<r.audioGroupIds.length;n++)if(r.audioGroupIds[n]===i){a=n;break}-1!==a&&a!==r.urlId&&(r.urlId=a,this.canLoad&&this.startLoad())}}}},{key:"loadPlaylist",value:function(e){u(g(r.prototype),"loadPlaylist",this).call(this);var t=this.currentLevelIndex,i=this.currentLevel;if(i&&this.shouldLoadPlaylist(i)){var a=i.urlId,n=i.uri;if(e)try{n=e.addDirectives(n)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: ".concat(e))}var s=i.attrs["PATHWAY-ID"];this.log("Loading level index ".concat(t).concat(void 0!==(null==e?void 0:e.msn)?" at sn "+e.msn+" part "+e.part:""," with").concat(s?" Pathway "+s:""," URI ").concat(a+1,"/").concat(i.url.length," ").concat(n)),this.clearTimer(),this.hls.trigger(O.LEVEL_LOADING,{url:n,level:t,id:a,deliveryDirectives:e||null})}}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(e){this.level=e,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=e)}},{key:"removeLevel",value:function(e,t){var r=this,i=function(e,r){return r!==t},a=this._levels.filter((function(a,n){return n!==e||(a.url.length>1&&void 0!==t?(a.url=a.url.filter(i),a.audioGroupIds&&(a.audioGroupIds=a.audioGroupIds.filter(i)),a.textGroupIds&&(a.textGroupIds=a.textGroupIds.filter(i)),a.urlId=0,!0):(r.steering&&r.steering.removeLevel(a),!1))}));this.hls.trigger(O.LEVELS_UPDATED,{levels:a})}},{key:"onLevelsUpdated",value:function(e,t){var r=t.levels;r.forEach((function(e,t){var r=e.details;null!=r&&r.fragments&&r.fragments.forEach((function(e){e.level=t}))})),this._levels=r}}]),r}(or);function ur(e,t,r){r&&("audio"===t?(e.audioGroupIds||(e.audioGroupIds=[]),e.audioGroupIds[e.url.length-1]=r):"text"===t&&(e.textGroupIds||(e.textGroupIds=[]),e.textGroupIds[e.url.length-1]=r))}function cr(e){var t={};e.forEach((function(e){var r=e.groupId||"";e.id=t[r]=t[r]||0,t[r]++}))}var hr="NOT_LOADED",dr="APPENDING",fr="PARTIAL",vr="OK",gr=function(){function e(t){y(this,e),this.activePartLists=Object.create(null),this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hasGaps=!1,this.hls=t,this._registerListeners()}return k(e,[{key:"_registerListeners",value:function(){var e=this.hls;e.on(O.BUFFER_APPENDED,this.onBufferAppended,this),e.on(O.FRAG_BUFFERED,this.onFragBuffered,this),e.on(O.FRAG_LOADED,this.onFragLoaded,this)}},{key:"_unregisterListeners",value:function(){var e=this.hls;e.off(O.BUFFER_APPENDED,this.onBufferAppended,this),e.off(O.FRAG_BUFFERED,this.onFragBuffered,this),e.off(O.FRAG_LOADED,this.onFragLoaded,this)}},{key:"destroy",value:function(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null}},{key:"getAppendedFrag",value:function(e,t){var r=this.activePartLists[t];if(r)for(var i=r.length;i--;){var a=r[i];if(!a)break;var n=a.end;if(a.start<=e&&null!==n&&e<=n)return a}return this.getBufferedFrag(e,t)}},{key:"getBufferedFrag",value:function(e,t){for(var r=this.fragments,i=Object.keys(r),a=i.length;a--;){var n=r[i[a]];if((null==n?void 0:n.body.type)===t&&n.buffered){var s=n.body;if(s.start<=e&&e<=s.end)return s}}return null}},{key:"detectEvictedFragments",value:function(e,t,r,i){var a=this;this.timeRanges&&(this.timeRanges[e]=t);var n=(null==i?void 0:i.fragment.sn)||-1;Object.keys(this.fragments).forEach((function(i){var s=a.fragments[i];if(s&&!(n>=s.body.sn))if(s.buffered||s.loaded){var o=s.range[e];o&&o.time.some((function(e){var r=!a.isTimeBuffered(e.startPTS,e.endPTS,t);return r&&a.removeFragment(s.body),r}))}else s.body.type===r&&a.removeFragment(s.body)}))}},{key:"detectPartialFragments",value:function(e){var t=this,r=this.timeRanges,i=e.frag,a=e.part;if(r&&"initSegment"!==i.sn){var n=yr(i),s=this.fragments[n];if(!(!s||s.buffered&&i.gap)){var o=!i.relurl;Object.keys(r).forEach((function(e){var n=i.elementaryStreams[e];if(n){var l=r[e],u=o||!0===n.partial;s.range[e]=t.getBufferedTimes(i,a,u,l)}})),s.loaded=null,Object.keys(s.range).length?(s.buffered=!0,(s.body.endList=i.endList||s.body.endList)&&(this.endListFragments[s.body.type]=s),mr(s)||this.removeParts(i.sn-1,i.type)):this.removeFragment(s.body)}}}},{key:"removeParts",value:function(e,t){var r=this.activePartLists[t];r&&(this.activePartLists[t]=r.filter((function(t){return t.fragment.sn>=e})))}},{key:"fragBuffered",value:function(e,t){var r=yr(e),i=this.fragments[r];!i&&t&&(i=this.fragments[r]={body:e,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},e.gap&&(this.hasGaps=!0)),i&&(i.loaded=null,i.buffered=!0)}},{key:"getBufferedTimes",value:function(e,t,r,i){for(var a={time:[],partial:r},n=e.start,s=e.end,o=e.minEndPTS||s,l=e.maxStartPTS||n,u=0;u<i.length;u++){var c=i.start(u)-this.bufferPadding,h=i.end(u)+this.bufferPadding;if(l>=c&&o<=h){a.time.push({startPTS:Math.max(n,i.start(u)),endPTS:Math.min(s,i.end(u))});break}if(n<h&&s>c)a.partial=!0,a.time.push({startPTS:Math.max(n,i.start(u)),endPTS:Math.min(s,i.end(u))});else if(s<=c)break}return a}},{key:"getPartialFragment",value:function(e){var t,r,i,a=null,n=0,s=this.bufferPadding,o=this.fragments;return Object.keys(o).forEach((function(l){var u=o[l];u&&mr(u)&&(r=u.body.start-s,i=u.body.end+s,e>=r&&e<=i&&(t=Math.min(e-r,i-e),n<=t&&(a=u.body,n=t)))})),a}},{key:"isEndListAppended",value:function(e){var t=this.endListFragments[e];return void 0!==t&&(t.buffered||mr(t))}},{key:"getState",value:function(e){var t=yr(e),r=this.fragments[t];return r?r.buffered?mr(r)?fr:vr:dr:hr}},{key:"isTimeBuffered",value:function(e,t,r){for(var i,a,n=0;n<r.length;n++){if(i=r.start(n)-this.bufferPadding,a=r.end(n)+this.bufferPadding,e>=i&&t<=a)return!0;if(t<=i)return!1}return!1}},{key:"onFragLoaded",value:function(e,t){var r=t.frag,i=t.part;if("initSegment"!==r.sn&&!r.bitrateTest){var a=i?null:t,n=yr(r);this.fragments[n]={body:r,appendedPTS:null,loaded:a,buffered:!1,range:Object.create(null)}}}},{key:"onBufferAppended",value:function(e,t){var r=this,i=t.frag,a=t.part,n=t.timeRanges;if("initSegment"!==i.sn){var s=i.type;if(a){var o=this.activePartLists[s];o||(this.activePartLists[s]=o=[]),o.push(a)}this.timeRanges=n,Object.keys(n).forEach((function(e){var t=n[e];r.detectEvictedFragments(e,t,s,a)}))}}},{key:"onFragBuffered",value:function(e,t){this.detectPartialFragments(t)}},{key:"hasFragment",value:function(e){var t=yr(e);return!!this.fragments[t]}},{key:"hasParts",value:function(e){var t;return!(null==(t=this.activePartLists[e])||!t.length)}},{key:"removeFragmentsInRange",value:function(e,t,r,i,a){var n=this;i&&!this.hasGaps||Object.keys(this.fragments).forEach((function(s){var o=n.fragments[s];if(o){var l=o.body;l.type!==r||i&&!l.gap||l.start<t&&l.end>e&&(o.buffered||a)&&n.removeFragment(l)}}))}},{key:"removeFragment",value:function(e){var t=yr(e);e.stats.loaded=0,e.clearElementaryStreamInfo();var r=this.activePartLists[e.type];if(r){var i=e.sn;this.activePartLists[e.type]=r.filter((function(e){return e.fragment.sn!==i}))}delete this.fragments[t],e.endList&&delete this.endListFragments[e.type]}},{key:"removeAllFragments",value:function(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1}}]),e}();function mr(e){var t,r,i;return e.buffered&&(e.body.gap||(null==(t=e.range.video)?void 0:t.partial)||(null==(r=e.range.audio)?void 0:r.partial)||(null==(i=e.range.audiovideo)?void 0:i.partial))}function yr(e){return"".concat(e.type,"_").concat(e.level,"_").concat(e.urlId,"_").concat(e.sn)}var pr=Math.pow(2,17),kr=function(){function e(t){y(this,e),this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=t}return k(e,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null)}},{key:"abort",value:function(){this.loader&&this.loader.abort()}},{key:"load",value:function(e,t){var r=this,i=e.url;if(!i)return Promise.reject(new Sr({type:M.NETWORK_ERROR,details:N.FRAG_LOAD_ERROR,fatal:!1,frag:e,error:new Error("Fragment does not have a ".concat(i?"part list":"url")),networkDetails:null}));this.abort();var a=this.config,n=a.fLoader,s=a.loader;return new Promise((function(o,l){if(r.loader&&r.loader.destroy(),e.gap){if(e.tagList.some((function(e){return"GAP"===e[0]})))return void l(Er(e));e.gap=!1}var u=r.loader=e.loader=n?new n(a):new s(a),c=Tr(e),h=Zt(a.fragLoadPolicy.default),d={loadPolicy:h,timeout:h.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:"initSegment"===e.sn?1/0:pr};e.stats=u.stats,u.load(c,d,{onSuccess:function(t,i,a,n){r.resetLoader(e,u);var s=t.data;a.resetIV&&e.decryptdata&&(e.decryptdata.iv=new Uint8Array(s.slice(0,16)),s=s.slice(16)),o({frag:e,part:null,payload:s,networkDetails:n})},onError:function(t,a,n,s){r.resetLoader(e,u),l(new Sr({type:M.NETWORK_ERROR,details:N.FRAG_LOAD_ERROR,fatal:!1,frag:e,response:_({url:i,data:void 0},t),error:new Error("HTTP Error ".concat(t.code," ").concat(t.text)),networkDetails:n,stats:s}))},onAbort:function(t,i,a){r.resetLoader(e,u),l(new Sr({type:M.NETWORK_ERROR,details:N.INTERNAL_ABORTED,fatal:!1,frag:e,error:new Error("Aborted"),networkDetails:a,stats:t}))},onTimeout:function(t,i,a){r.resetLoader(e,u),l(new Sr({type:M.NETWORK_ERROR,details:N.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,error:new Error("Timeout after ".concat(d.timeout,"ms")),networkDetails:a,stats:t}))},onProgress:function(r,i,a,n){t&&t({frag:e,part:null,payload:a,networkDetails:n})}})}))}},{key:"loadPart",value:function(e,t,r){var i=this;this.abort();var a=this.config,n=a.fLoader,s=a.loader;return new Promise((function(o,l){if(i.loader&&i.loader.destroy(),e.gap||t.gap)l(Er(e,t));else{var u=i.loader=e.loader=n?new n(a):new s(a),c=Tr(e,t),h=Zt(a.fragLoadPolicy.default),d={loadPolicy:h,timeout:h.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:pr};t.stats=u.stats,u.load(c,d,{onSuccess:function(a,n,s,l){i.resetLoader(e,u),i.updateStatsFromPart(e,t);var c={frag:e,part:t,payload:a.data,networkDetails:l};r(c),o(c)},onError:function(r,a,n,s){i.resetLoader(e,u),l(new Sr({type:M.NETWORK_ERROR,details:N.FRAG_LOAD_ERROR,fatal:!1,frag:e,part:t,response:_({url:c.url,data:void 0},r),error:new Error("HTTP Error ".concat(r.code," ").concat(r.text)),networkDetails:n,stats:s}))},onAbort:function(r,a,n){e.stats.aborted=t.stats.aborted,i.resetLoader(e,u),l(new Sr({type:M.NETWORK_ERROR,details:N.INTERNAL_ABORTED,fatal:!1,frag:e,part:t,error:new Error("Aborted"),networkDetails:n,stats:r}))},onTimeout:function(r,a,n){i.resetLoader(e,u),l(new Sr({type:M.NETWORK_ERROR,details:N.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,part:t,error:new Error("Timeout after ".concat(d.timeout,"ms")),networkDetails:n,stats:r}))}})}}))}},{key:"updateStatsFromPart",value:function(e,t){var r=e.stats,i=t.stats,a=i.total;if(r.loaded+=i.loaded,a){var n=Math.round(e.duration/t.duration),s=Math.min(Math.round(r.loaded/a),n),o=(n-s)*Math.round(r.loaded/s);r.total=r.loaded+o}else r.total=Math.max(r.loaded,r.total);var l=r.loading,u=i.loading;l.start?l.first+=u.first-u.start:(l.start=u.start,l.first=u.first),l.end=u.end}},{key:"resetLoader",value:function(e,t){e.loader=null,this.loader===t&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),t.destroy()}}]),e}();function Tr(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=t||e,i={frag:e,part:t,responseType:"arraybuffer",url:r.url,headers:{},rangeStart:0,rangeEnd:0},a=r.byteRangeStartOffset,n=r.byteRangeEndOffset;if(F(a)&&F(n)){var s,o=a,l=n;if("initSegment"===e.sn&&"AES-128"===(null==(s=e.decryptdata)?void 0:s.method)){var u=n-a;u%16&&(l=n+(16-u%16)),0!==a&&(i.resetIV=!0,o=a-16)}i.rangeStart=o,i.rangeEnd=l}return i}function Er(e,t){var r=new Error("GAP ".concat(e.gap?"tag":"attribute"," found")),i={type:M.MEDIA_ERROR,details:N.FRAG_GAP,fatal:!1,frag:e,error:r,networkDetails:null};return t&&(i.part=t),(t||e).stats.aborted=!0,new Sr(i)}var Sr=function(e){c(r,e);var t=d(r);function r(e){var i;return y(this,r),(i=t.call(this,e.error.message)).data=void 0,i.data=e,i}return k(r)}(o(Error)),Lr=function(){function e(t){y(this,e),this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=t}return k(e,[{key:"abort",value:function(e){for(var t in this.keyUriToKeyInfo){var r=this.keyUriToKeyInfo[t].loader;if(r){if(e&&e!==r.context.frag.type)return;r.abort()}}}},{key:"detach",value:function(){for(var e in this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e];(t.mediaKeySessionContext||t.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[e]}}},{key:"destroy",value:function(){for(var e in this.detach(),this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e].loader;t&&t.destroy()}this.keyUriToKeyInfo={}}},{key:"createKeyLoadError",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:N.KEY_LOAD_ERROR,r=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0;return new Sr({type:M.NETWORK_ERROR,details:t,fatal:!1,frag:e,response:a,error:r,networkDetails:i})}},{key:"loadClear",value:function(e,t){var r=this;if(this.emeController&&this.config.emeEnabled)for(var i=e.sn,a=e.cc,n=function(){var e=t[s];if(a<=e.cc&&("initSegment"===i||"initSegment"===e.sn||i<e.sn))return r.emeController.selectKeySystemFormat(e).then((function(t){e.setKeyFormat(t)})),1},s=0;s<t.length&&!n();s++);}},{key:"load",value:function(e){var t=this;return!e.decryptdata&&e.encrypted&&this.emeController?this.emeController.selectKeySystemFormat(e).then((function(r){return t.loadInternal(e,r)})):this.loadInternal(e)}},{key:"loadInternal",value:function(e,t){var r,i;t&&e.setKeyFormat(t);var a=e.decryptdata;if(!a){var n=new Error(t?"Expected frag.decryptdata to be defined after setting format ".concat(t):"Missing decryption data on fragment in onKeyLoading");return Promise.reject(this.createKeyLoadError(e,N.KEY_LOAD_ERROR,n))}var s=a.uri;if(!s)return Promise.reject(this.createKeyLoadError(e,N.KEY_LOAD_ERROR,new Error('Invalid key URI: "'.concat(s,'"'))));var o,l=this.keyUriToKeyInfo[s];if(null!=(r=l)&&r.decryptdata.key)return a.key=l.decryptdata.key,Promise.resolve({frag:e,keyInfo:l});if(null!=(i=l)&&i.keyLoadPromise)switch(null==(o=l.mediaKeySessionContext)?void 0:o.keyStatus){case void 0:case"status-pending":case"usable":case"usable-in-future":return l.keyLoadPromise.then((function(t){return a.key=t.keyInfo.decryptdata.key,{frag:e,keyInfo:l}}))}switch(l=this.keyUriToKeyInfo[s]={decryptdata:a,keyLoadPromise:null,loader:null,mediaKeySessionContext:null},a.method){case"ISO-23001-7":case"SAMPLE-AES":case"SAMPLE-AES-CENC":case"SAMPLE-AES-CTR":return"identity"===a.keyFormat?this.loadKeyHTTP(l,e):this.loadKeyEME(l,e);case"AES-128":return this.loadKeyHTTP(l,e);default:return Promise.reject(this.createKeyLoadError(e,N.KEY_LOAD_ERROR,new Error('Key supplied with unsupported METHOD: "'.concat(a.method,'"'))))}}},{key:"loadKeyEME",value:function(e,t){var r={frag:t,keyInfo:e};if(this.emeController&&this.config.emeEnabled){var i=this.emeController.loadKey(r);if(i)return(e.keyLoadPromise=i.then((function(t){return e.mediaKeySessionContext=t,r}))).catch((function(t){throw e.keyLoadPromise=null,t}))}return Promise.resolve(r)}},{key:"loadKeyHTTP",value:function(e,t){var r=this,i=this.config,a=new(0,i.loader)(i);return t.keyLoader=e.loader=a,e.keyLoadPromise=new Promise((function(n,s){var o={keyInfo:e,frag:t,responseType:"arraybuffer",url:e.decryptdata.uri},l=i.keyLoadPolicy.default,u={loadPolicy:l,timeout:l.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},c={onSuccess:function(e,t,i,a){var o=i.frag,l=i.keyInfo,u=i.url;if(!o.decryptdata||l!==r.keyUriToKeyInfo[u])return s(r.createKeyLoadError(o,N.KEY_LOAD_ERROR,new Error("after key load, decryptdata unset or changed"),a));l.decryptdata.key=o.decryptdata.key=new Uint8Array(e.data),o.keyLoader=null,l.loader=null,n({frag:o,keyInfo:l})},onError:function(e,i,a,n){r.resetLoader(i),s(r.createKeyLoadError(t,N.KEY_LOAD_ERROR,new Error("HTTP Error ".concat(e.code," loading key ").concat(e.text)),a,_({url:o.url,data:void 0},e)))},onTimeout:function(e,i,a){r.resetLoader(i),s(r.createKeyLoadError(t,N.KEY_LOAD_TIMEOUT,new Error("key loading timed out"),a))},onAbort:function(e,i,a){r.resetLoader(i),s(r.createKeyLoadError(t,N.INTERNAL_ABORTED,new Error("key loading aborted"),a))}};a.load(o,u,c)}))}},{key:"resetLoader",value:function(e){var t=e.frag,r=e.keyInfo,i=e.url,a=r.loader;t.keyLoader===a&&(t.keyLoader=null,r.loader=null),delete this.keyUriToKeyInfo[i],a&&a.destroy()}}]),e}(),Ar=function(){function e(){y(this,e),this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}return k(e,[{key:"destroy",value:function(){this.onHandlerDestroying(),this.onHandlerDestroyed()}},{key:"onHandlerDestroying",value:function(){this.clearNextTick(),this.clearInterval()}},{key:"onHandlerDestroyed",value:function(){}},{key:"hasInterval",value:function(){return!!this._tickInterval}},{key:"hasNextTick",value:function(){return!!this._tickTimer}},{key:"setInterval",value:function(e){return!this._tickInterval&&(this._tickCallCount=0,this._tickInterval=self.setInterval(this._boundTick,e),!0)}},{key:"clearInterval",value:function(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)}},{key:"clearNextTick",value:function(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)}},{key:"tick",value:function(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)}},{key:"tickImmediate",value:function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)}},{key:"doTick",value:function(){}}]),e}(),Rr={length:0,start:function(){return 0},end:function(){return 0}},br=function(){function e(){y(this,e)}return k(e,null,[{key:"isBuffered",value:function(t,r){try{if(t)for(var i=e.getBuffered(t),a=0;a<i.length;a++)if(r>=i.start(a)&&r<=i.end(a))return!0}catch(e){}return!1}},{key:"bufferInfo",value:function(t,r,i){try{if(t){var a,n=e.getBuffered(t),s=[];for(a=0;a<n.length;a++)s.push({start:n.start(a),end:n.end(a)});return this.bufferedInfo(s,r,i)}}catch(e){}return{len:0,start:r,end:r,nextStart:void 0}}},{key:"bufferedInfo",value:function(e,t,r){t=Math.max(0,t),e.sort((function(e,t){return e.start-t.start||t.end-e.end}));var i=[];if(r)for(var a=0;a<e.length;a++){var n=i.length;if(n){var s=i[n-1].end;e[a].start-s<r?e[a].end>s&&(i[n-1].end=e[a].end):i.push(e[a])}else i.push(e[a])}else i=e;for(var o,l=0,u=t,c=t,h=0;h<i.length;h++){var d=i[h].start,f=i[h].end;if(t+r>=d&&t<f)u=d,l=(c=f)-t;else if(t+r<d){o=d;break}}return{len:l,start:u||0,end:c||0,nextStart:o}}},{key:"getBuffered",value:function(e){try{return e.buffered}catch(e){return K.log("failed to get media.buffered",e),Rr}}}]),e}(),Dr=k((function e(t,r,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:-1,s=arguments.length>5&&void 0!==arguments[5]&&arguments[5];y(this,e),this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing={start:0,executeStart:0,executeEnd:0,end:0},this.buffering={audio:{start:0,executeStart:0,executeEnd:0,end:0},video:{start:0,executeStart:0,executeEnd:0,end:0},audiovideo:{start:0,executeStart:0,executeEnd:0,end:0}},this.level=t,this.sn=r,this.id=i,this.size=a,this.part=n,this.partial=s}));function Ir(e,t){for(var r=null,i=0,a=e.length;i<a;i++){var n=e[i];if(n&&n.cc===t){r=n;break}}return r}function wr(e,t){if(e){var r=e.start+t;e.start=e.startPTS=r,e.endPTS=r+e.duration}}function Cr(e,t){for(var r=t.fragments,i=0,a=r.length;i<a;i++)wr(r[i],e);t.fragmentHint&&wr(t.fragmentHint,e),t.alignedSliding=!0}function _r(e,t){if(e.hasProgramDateTime&&t.hasProgramDateTime){var r=e.fragments,i=t.fragments;if(r.length&&i.length){var a=i[Math.round(i.length/2)-1],n=Ir(r,a.cc)||r[Math.round(r.length/2)-1],s=a.programDateTime,o=n.programDateTime;null!==s&&null!==o&&Cr((o-s)/1e3-(n.start-a.start),e)}}}var Pr=function(){function e(t,r){y(this,e),this.subtle=void 0,this.aesIV=void 0,this.subtle=t,this.aesIV=r}return k(e,[{key:"decrypt",value:function(e,t){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},t,e)}}]),e}(),xr=function(){function e(t,r){y(this,e),this.subtle=void 0,this.key=void 0,this.subtle=t,this.key=r}return k(e,[{key:"expandKey",value:function(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])}}]),e}(),Fr=function(){function e(){y(this,e),this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}return k(e,[{key:"uint8ArrayToUint32Array_",value:function(e){for(var t=new DataView(e),r=new Uint32Array(4),i=0;i<4;i++)r[i]=t.getUint32(4*i);return r}},{key:"initTable",value:function(){var e=this.sBox,t=this.invSBox,r=this.subMix,i=r[0],a=r[1],n=r[2],s=r[3],o=this.invSubMix,l=o[0],u=o[1],c=o[2],h=o[3],d=new Uint32Array(256),f=0,v=0,g=0;for(g=0;g<256;g++)d[g]=g<128?g<<1:g<<1^283;for(g=0;g<256;g++){var m=v^v<<1^v<<2^v<<3^v<<4;m=m>>>8^255&m^99,e[f]=m,t[m]=f;var y=d[f],p=d[y],k=d[p],T=257*d[m]^16843008*m;i[f]=T<<24|T>>>8,a[f]=T<<16|T>>>16,n[f]=T<<8|T>>>24,s[f]=T,T=16843009*k^65537*p^257*y^16843008*f,l[m]=T<<24|T>>>8,u[m]=T<<16|T>>>16,c[m]=T<<8|T>>>24,h[m]=T,f?(f=y^d[d[d[k^y]]],v^=d[d[v]]):f=v=1}}},{key:"expandKey",value:function(e){for(var t=this.uint8ArrayToUint32Array_(e),r=!0,i=0;i<t.length&&r;)r=t[i]===this.key[i],i++;if(!r){this.key=t;var a=this.keySize=t.length;if(4!==a&&6!==a&&8!==a)throw new Error("Invalid aes key size="+a);var n,s,o,l,u=this.ksRows=4*(a+6+1),c=this.keySchedule=new Uint32Array(u),h=this.invKeySchedule=new Uint32Array(u),d=this.sBox,f=this.rcon,v=this.invSubMix,g=v[0],m=v[1],y=v[2],p=v[3];for(n=0;n<u;n++)n<a?o=c[n]=t[n]:(l=o,n%a==0?(l=d[(l=l<<8|l>>>24)>>>24]<<24|d[l>>>16&255]<<16|d[l>>>8&255]<<8|d[255&l],l^=f[n/a|0]<<24):a>6&&n%a==4&&(l=d[l>>>24]<<24|d[l>>>16&255]<<16|d[l>>>8&255]<<8|d[255&l]),c[n]=o=(c[n-a]^l)>>>0);for(s=0;s<u;s++)n=u-s,l=3&s?c[n]:c[n-4],h[s]=s<4||n<=4?l:g[d[l>>>24]]^m[d[l>>>16&255]]^y[d[l>>>8&255]]^p[d[255&l]],h[s]=h[s]>>>0}}},{key:"networkToHostOrderSwap",value:function(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24}},{key:"decrypt",value:function(e,t,r){for(var i,a,n,s,o,l,u,c,h,d,f,v,g,m,y=this.keySize+6,p=this.invKeySchedule,k=this.invSBox,T=this.invSubMix,E=T[0],S=T[1],L=T[2],A=T[3],R=this.uint8ArrayToUint32Array_(r),b=R[0],D=R[1],I=R[2],w=R[3],C=new Int32Array(e),_=new Int32Array(C.length),P=this.networkToHostOrderSwap;t<C.length;){for(h=P(C[t]),d=P(C[t+1]),f=P(C[t+2]),v=P(C[t+3]),o=h^p[0],l=v^p[1],u=f^p[2],c=d^p[3],g=4,m=1;m<y;m++)i=E[o>>>24]^S[l>>16&255]^L[u>>8&255]^A[255&c]^p[g],a=E[l>>>24]^S[u>>16&255]^L[c>>8&255]^A[255&o]^p[g+1],n=E[u>>>24]^S[c>>16&255]^L[o>>8&255]^A[255&l]^p[g+2],s=E[c>>>24]^S[o>>16&255]^L[l>>8&255]^A[255&u]^p[g+3],o=i,l=a,u=n,c=s,g+=4;i=k[o>>>24]<<24^k[l>>16&255]<<16^k[u>>8&255]<<8^k[255&c]^p[g],a=k[l>>>24]<<24^k[u>>16&255]<<16^k[c>>8&255]<<8^k[255&o]^p[g+1],n=k[u>>>24]<<24^k[c>>16&255]<<16^k[o>>8&255]<<8^k[255&l]^p[g+2],s=k[c>>>24]<<24^k[o>>16&255]<<16^k[l>>8&255]<<8^k[255&u]^p[g+3],_[t]=P(i^b),_[t+1]=P(s^D),_[t+2]=P(n^I),_[t+3]=P(a^w),b=h,D=d,I=f,w=v,t+=4}return _.buffer}}]),e}(),Or=function(){function e(t){var r=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).removePKCS7Padding,i=void 0===r||r;if(y(this,e),this.logEnabled=!0,this.removePKCS7Padding=void 0,this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null,this.useSoftware=void 0,this.useSoftware=t.enableSoftwareAES,this.removePKCS7Padding=i,i)try{var a=self.crypto;a&&(this.subtle=a.subtle||a.webkitSubtle)}catch(e){}null===this.subtle&&(this.useSoftware=!0)}return k(e,[{key:"destroy",value:function(){this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null}},{key:"isSync",value:function(){return this.useSoftware}},{key:"flush",value:function(){var e=this.currentResult,t=this.remainderData;if(!e||t)return this.reset(),null;var r,i,a,n=new Uint8Array(e);return this.reset(),this.removePKCS7Padding?(a=(i=(r=n).byteLength)&&new DataView(r.buffer).getUint8(i-1))?fe(r,0,i-a):r:n}},{key:"reset",value:function(){this.currentResult=null,this.currentIV=null,this.remainderData=null,this.softwareDecrypter&&(this.softwareDecrypter=null)}},{key:"decrypt",value:function(e,t,r){var i=this;return this.useSoftware?new Promise((function(a,n){i.softwareDecrypt(new Uint8Array(e),t,r);var s=i.flush();s?a(s.buffer):n(new Error("[softwareDecrypt] Failed to decrypt data"))})):this.webCryptoDecrypt(new Uint8Array(e),t,r)}},{key:"softwareDecrypt",value:function(e,t,r){var i=this.currentIV,a=this.currentResult,n=this.remainderData;this.logOnce("JS AES decrypt"),n&&(e=Ye(n,e),this.remainderData=null);var s=this.getValidChunk(e);if(!s.length)return null;i&&(r=i);var o=this.softwareDecrypter;o||(o=this.softwareDecrypter=new Fr),o.expandKey(t);var l=a;return this.currentResult=o.decrypt(s.buffer,0,r),this.currentIV=fe(s,-16).buffer,l||null}},{key:"webCryptoDecrypt",value:function(e,t,r){var i=this,a=this.subtle;return this.key===t&&this.fastAesKey||(this.key=t,this.fastAesKey=new xr(a,t)),this.fastAesKey.expandKey().then((function(t){return a?(i.logOnce("WebCrypto AES decrypt"),new Pr(a,new Uint8Array(r)).decrypt(e.buffer,t)):Promise.reject(new Error("web crypto not initialized"))})).catch((function(a){return K.warn("[decrypter]: WebCrypto Error, disable WebCrypto API, ".concat(a.name,": ").concat(a.message)),i.onWebCryptoError(e,t,r)}))}},{key:"onWebCryptoError",value:function(e,t,r){this.useSoftware=!0,this.logEnabled=!0,this.softwareDecrypt(e,t,r);var i=this.flush();if(i)return i.buffer;throw new Error("WebCrypto and softwareDecrypt: failed to decrypt data")}},{key:"getValidChunk",value:function(e){var t=e,r=e.length-e.length%16;return r!==e.length&&(t=fe(e,0,r),this.remainderData=fe(e,r)),t}},{key:"logOnce",value:function(e){this.logEnabled&&(K.log("[decrypter]: ".concat(e)),this.logEnabled=!1)}}]),e}(),Mr="STOPPED",Nr="IDLE",Ur="KEY_LOADING",Br="FRAG_LOADING",Gr="FRAG_LOADING_WAITING_RETRY",Kr="WAITING_TRACK",Hr="PARSING",Vr="PARSED",Yr="ENDED",Wr="ERROR",jr="WAITING_INIT_PTS",qr="WAITING_LEVEL",Xr=function(e){c(r,e);var t=d(r);function r(e,i,a,n,s){var o;return y(this,r),(o=t.call(this)).hls=void 0,o.fragPrevious=null,o.fragCurrent=null,o.fragmentTracker=void 0,o.transmuxer=null,o._state=Mr,o.playlistType=void 0,o.media=null,o.mediaBuffer=null,o.config=void 0,o.bitrateTest=!1,o.lastCurrentTime=0,o.nextLoadPosition=0,o.startPosition=0,o.startTimeOffset=null,o.loadedmetadata=!1,o.retryDate=0,o.levels=null,o.fragmentLoader=void 0,o.keyLoader=void 0,o.levelLastLoaded=null,o.startFragRequested=!1,o.decrypter=void 0,o.initPTS=[],o.onvseeking=null,o.onvended=null,o.logPrefix="",o.log=void 0,o.warn=void 0,o.playlistType=s,o.logPrefix=n,o.log=K.log.bind(K,"".concat(n,":")),o.warn=K.warn.bind(K,"".concat(n,":")),o.hls=e,o.fragmentLoader=new kr(e.config),o.keyLoader=a,o.fragmentTracker=i,o.config=e.config,o.decrypter=new Or(e.config),e.on(O.MANIFEST_LOADED,o.onManifestLoaded,f(o)),o}return k(r,[{key:"doTick",value:function(){this.onTickEnd()}},{key:"onTickEnd",value:function(){}},{key:"startLoad",value:function(e){}},{key:"stopLoad",value:function(){this.fragmentLoader.abort(),this.keyLoader.abort(this.playlistType);var e=this.fragCurrent;null!=e&&e.loader&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=Mr}},{key:"_streamEnded",value:function(e,t){if(t.live||e.nextStart||!e.end||!this.media)return!1;var r=t.partList;if(null!=r&&r.length){var i=r[r.length-1];return br.isBuffered(this.media,i.start+i.duration/2)}var a=t.fragments[t.fragments.length-1].type;return this.fragmentTracker.isEndListAppended(a)}},{key:"getLevelDetails",value:function(){var e;if(this.levels&&null!==this.levelLastLoaded)return null==(e=this.levels[this.levelLastLoaded])?void 0:e.details}},{key:"onMediaAttached",value:function(e,t){var r=this.media=this.mediaBuffer=t.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),r.addEventListener("seeking",this.onvseeking),r.addEventListener("ended",this.onvended);var i=this.config;this.levels&&i.autoStartLoad&&this.state===Mr&&this.startLoad(i.startPosition)}},{key:"onMediaDetaching",value:function(){var e=this.media;null!=e&&e.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),e&&this.onvseeking&&this.onvended&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.keyLoader&&this.keyLoader.detach(),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()}},{key:"onMediaSeeking",value:function(){var e=this.config,t=this.fragCurrent,r=this.media,i=this.mediaBuffer,a=this.state,n=r?r.currentTime:0,s=br.bufferInfo(i||r,n,e.maxBufferHole);if(this.log("media seeking to ".concat(F(n)?n.toFixed(3):n,", state: ").concat(a)),this.state===Yr)this.resetLoadingState();else if(t){var o=e.maxFragLookUpTolerance,l=t.start-o,u=t.start+t.duration+o;if(!s.len||u<s.start||l>s.end){var c=n>u;(n<l||c)&&(c&&t.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),t.abortRequests(),this.resetLoadingState()),this.fragPrevious=null)}}r&&(this.fragmentTracker.removeFragmentsInRange(n,1/0,this.playlistType,!0),this.lastCurrentTime=n),this.loadedmetadata||s.len||(this.nextLoadPosition=this.startPosition=n),this.tickImmediate()}},{key:"onMediaEnded",value:function(){this.startPosition=this.lastCurrentTime=0}},{key:"onManifestLoaded",value:function(e,t){this.startTimeOffset=t.startTimeOffset,this.initPTS=[]}},{key:"onHandlerDestroying",value:function(){this.stopLoad(),u(g(r.prototype),"onHandlerDestroying",this).call(this)}},{key:"onHandlerDestroyed",value:function(){this.state=Mr,this.fragmentLoader&&this.fragmentLoader.destroy(),this.keyLoader&&this.keyLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.keyLoader=this.fragmentLoader=this.fragmentTracker=null,u(g(r.prototype),"onHandlerDestroyed",this).call(this)}},{key:"loadFragment",value:function(e,t,r){this._loadFragForPlayback(e,t,r)}},{key:"_loadFragForPlayback",value:function(e,t,r){var i=this;this._doFragLoad(e,t,r,(function(t){if(i.fragContextChanged(e))return i.warn("Fragment ".concat(e.sn).concat(t.part?" p: "+t.part.index:""," of level ").concat(e.level," was dropped during download.")),void i.fragmentTracker.removeFragment(e);e.stats.chunkCount++,i._handleFragmentLoadProgress(t)})).then((function(t){if(t){var r=i.state;i.fragContextChanged(e)?(r===Br||!i.fragCurrent&&r===Hr)&&(i.fragmentTracker.removeFragment(e),i.state=Nr):("payload"in t&&(i.log("Loaded fragment ".concat(e.sn," of level ").concat(e.level)),i.hls.trigger(O.FRAG_LOADED,t)),i._handleFragmentLoadComplete(t))}})).catch((function(t){i.state!==Mr&&i.state!==Wr&&(i.warn(t),i.resetFragmentLoading(e))}))}},{key:"clearTrackerIfNeeded",value:function(e){var t,r=this.fragmentTracker;if(r.getState(e)===dr){var i=e.type,a=this.getFwdBufferInfo(this.mediaBuffer,i),n=Math.max(e.duration,a?a.len:this.config.maxBufferLength);this.reduceMaxBufferLength(n)&&r.removeFragment(e)}else 0===(null==(t=this.mediaBuffer)?void 0:t.buffered.length)?r.removeAllFragments():r.hasParts(e.type)&&(r.detectPartialFragments({frag:e,part:null,stats:e.stats,id:e.type}),r.getState(e)===fr&&r.removeFragment(e))}},{key:"checkLiveUpdate",value:function(e){if(e.updated&&!e.live){var t=e.fragments[e.fragments.length-1];this.fragmentTracker.detectPartialFragments({frag:t,part:null,stats:t.stats,id:t.type})}e.fragments[0]||(e.deltaUpdateFailed=!0)}},{key:"flushMainBuffer",value:function(e,t){if(e-t){var r={startOffset:e,endOffset:t,type:arguments.length>2&&void 0!==arguments[2]?arguments[2]:null};this.hls.trigger(O.BUFFER_FLUSHING,r)}}},{key:"_loadInitSegment",value:function(e,t){var r=this;this._doFragLoad(e,t).then((function(t){if(!t||r.fragContextChanged(e)||!r.levels)throw new Error("init load aborted");return t})).then((function(t){var i=r.hls,a=t.payload,n=e.decryptdata;if(a&&a.byteLength>0&&n&&n.key&&n.iv&&"AES-128"===n.method){var s=self.performance.now();return r.decrypter.decrypt(new Uint8Array(a),n.key.buffer,n.iv.buffer).catch((function(t){throw i.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:e}),t})).then((function(r){var a=self.performance.now();return i.trigger(O.FRAG_DECRYPTED,{frag:e,payload:r,stats:{tstart:s,tdecrypt:a}}),t.payload=r,t}))}return t})).then((function(i){var a=r.fragCurrent,n=r.hls;if(!r.levels)throw new Error("init load aborted, missing levels");var s=e.stats;r.state=Nr,t.fragmentError=0,e.data=new Uint8Array(i.payload),s.parsing.start=s.buffering.start=self.performance.now(),s.parsing.end=s.buffering.end=self.performance.now(),i.frag===a&&n.trigger(O.FRAG_BUFFERED,{stats:s,frag:a,part:null,id:e.type}),r.tick()})).catch((function(t){r.state!==Mr&&r.state!==Wr&&(r.warn(t),r.resetFragmentLoading(e))}))}},{key:"fragContextChanged",value:function(e){var t=this.fragCurrent;return!e||!t||e.level!==t.level||e.sn!==t.sn||e.urlId!==t.urlId}},{key:"fragBufferedComplete",value:function(e,t){var r,i,a,n,s=this.mediaBuffer?this.mediaBuffer:this.media;this.log("Buffered ".concat(e.type," sn: ").concat(e.sn).concat(t?" part: "+t.index:""," of ").concat(this.playlistType===At?"level":"track"," ").concat(e.level," (frag:[").concat((null!=(r=e.startPTS)?r:NaN).toFixed(3),"-").concat((null!=(i=e.endPTS)?i:NaN).toFixed(3),"] > buffer:").concat(s?function(e){for(var t="",r=e.length,i=0;i<r;i++)t+="[".concat(e.start(i).toFixed(3),"-").concat(e.end(i).toFixed(3),"]");return t}(br.getBuffered(s)):"(detached)",")")),this.state=Nr,s&&(!this.loadedmetadata&&e.type==At&&s.buffered.length&&(null==(a=this.fragCurrent)?void 0:a.sn)===(null==(n=this.fragPrevious)?void 0:n.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())}},{key:"seekToStartPos",value:function(){}},{key:"_handleFragmentLoadComplete",value:function(e){var t=this.transmuxer;if(t){var r=e.frag,i=e.part,a=e.partsLoaded,n=!a||0===a.length||a.some((function(e){return!e})),s=new Dr(r.level,r.sn,r.stats.chunkCount+1,0,i?i.index:-1,!n);t.flush(s)}}},{key:"_handleFragmentLoadProgress",value:function(e){}},{key:"_doFragLoad",value:function(e,t){var r,i=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,s=arguments.length>3?arguments[3]:void 0,o=null==t?void 0:t.details;if(!this.levels||!o)throw new Error("frag load aborted, missing level".concat(o?"":" detail","s"));var l=null;if(!e.encrypted||null!=(r=e.decryptdata)&&r.key?!e.encrypted&&o.encryptedFragments.length&&this.keyLoader.loadClear(e,o.encryptedFragments):(this.log("Loading key for ".concat(e.sn," of [").concat(o.startSN,"-").concat(o.endSN,"], ").concat("[stream-controller]"===this.logPrefix?"level":"track"," ").concat(e.level)),this.state=Ur,this.fragCurrent=e,l=this.keyLoader.load(e).then((function(e){if(!i.fragContextChanged(e.frag))return i.hls.trigger(O.KEY_LOADED,e),i.state===Ur&&(i.state=Nr),e})),this.hls.trigger(O.KEY_LOADING,{frag:e}),null===this.fragCurrent&&(l=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING")))),a=Math.max(e.start,a||0),this.config.lowLatencyMode&&"initSegment"!==e.sn){var u=o.partList;if(u&&s){a>e.end&&o.fragmentHint&&(e=o.fragmentHint);var c=this.getNextPart(u,e,a);if(c>-1){var h,d=u[c];return this.log("Loading part sn: ".concat(e.sn," p: ").concat(d.index," cc: ").concat(e.cc," of playlist [").concat(o.startSN,"-").concat(o.endSN,"] parts [0-").concat(c,"-").concat(u.length-1,"] ").concat("[stream-controller]"===this.logPrefix?"level":"track",": ").concat(e.level,", target: ").concat(parseFloat(a.toFixed(3)))),this.nextLoadPosition=d.start+d.duration,this.state=Br,h=l?l.then((function(r){return!r||i.fragContextChanged(r.frag)?null:i.doFragPartsLoad(e,d,t,s)})).catch((function(e){return i.handleFragLoadError(e)})):this.doFragPartsLoad(e,d,t,s).catch((function(e){return i.handleFragLoadError(e)})),this.hls.trigger(O.FRAG_LOADING,{frag:e,part:d,targetBufferTime:a}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):h}if(!e.url||this.loadedEndOfParts(u,a))return Promise.resolve(null)}}this.log("Loading fragment ".concat(e.sn," cc: ").concat(e.cc," ").concat(o?"of ["+o.startSN+"-"+o.endSN+"] ":"").concat("[stream-controller]"===this.logPrefix?"level":"track",": ").concat(e.level,", target: ").concat(parseFloat(a.toFixed(3)))),F(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=Br;var f,v=this.config.progressive;return f=v&&l?l.then((function(t){return!t||i.fragContextChanged(null==t?void 0:t.frag)?null:i.fragmentLoader.load(e,s)})).catch((function(e){return i.handleFragLoadError(e)})):Promise.all([this.fragmentLoader.load(e,v?s:void 0),l]).then((function(e){var t,r,i=(t=e,r=1,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var i,a,n,s,o=[],l=!0,u=!1;try{if(n=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(i=n.call(r)).done)&&(o.push(i.value),o.length!==t);l=!0);}catch(e){u=!0,a=e}finally{try{if(!l&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw a}}return o}}(t,r)||n(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())[0];return!v&&i&&s&&s(i),i})).catch((function(e){return i.handleFragLoadError(e)})),this.hls.trigger(O.FRAG_LOADING,{frag:e,targetBufferTime:a}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):f}},{key:"doFragPartsLoad",value:function(e,t,r,i){var a=this;return new Promise((function(n,s){var o,l=[],u=null==(o=r.details)?void 0:o.partList;!function t(o){a.fragmentLoader.loadPart(e,o,i).then((function(i){l[o.index]=i;var s=i.part;a.hls.trigger(O.FRAG_LOADED,i);var c=Xt(r,e.sn,o.index+1)||zt(u,e.sn,o.index+1);if(!c)return n({frag:e,part:s,partsLoaded:l});t(c)})).catch(s)}(t)}))}},{key:"handleFragLoadError",value:function(e){if("data"in e){var t=e.data;e.data&&t.details===N.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(O.ERROR,t)}else this.hls.trigger(O.ERROR,{type:M.OTHER_ERROR,details:N.INTERNAL_EXCEPTION,err:e,error:e,fatal:!0});return null}},{key:"_handleTransmuxerFlush",value:function(e){var t=this.getCurrentContext(e);if(t&&this.state===Hr){var r=t.frag,i=t.part,a=t.level,n=self.performance.now();r.stats.parsing.end=n,i&&(i.stats.parsing.end=n),this.updateLevelTiming(r,i,a,e.partial)}else this.fragCurrent||this.state===Mr||this.state===Wr||(this.state=Nr)}},{key:"getCurrentContext",value:function(e){var t=this.levels,r=this.fragCurrent,i=e.level,a=e.sn,n=e.part;if(null==t||!t[i])return this.warn("Levels object was unset while buffering fragment ".concat(a," of level ").concat(i,". The current chunk will not be buffered.")),null;var s=t[i],o=n>-1?Xt(s,a,n):null,l=o?o.fragment:function(e,t,r){if(null==e||!e.details)return null;var i=e.details,a=i.fragments[t-i.startSN];return a||((a=i.fragmentHint)&&a.sn===t?a:t<i.startSN&&r&&r.sn===t?r:null)}(s,a,r);return l?(r&&r!==l&&(l.stats=r.stats),{frag:l,part:o,level:s}):null}},{key:"bufferFragmentData",value:function(e,t,r,i,a){var n;if(e&&this.state===Hr){var s=e.data1,o=e.data2,l=s;if(s&&o&&(l=Ye(s,o)),null!=(n=l)&&n.length){var u={type:e.type,frag:t,part:r,chunkMeta:i,parent:t.type,data:l};if(this.hls.trigger(O.BUFFER_APPENDING,u),e.dropped&&e.independent&&!r){if(a)return;this.flushBufferGap(t)}}}}},{key:"flushBufferGap",value:function(e){var t=this.media;if(t)if(br.isBuffered(t,t.currentTime)){var r=t.currentTime,i=br.bufferInfo(t,r,0),a=e.duration,n=Math.min(2*this.config.maxFragLookUpTolerance,.25*a),s=Math.max(Math.min(e.start-n,i.end-n),r+n);e.start-s>n&&this.flushMainBuffer(s,e.start)}else this.flushMainBuffer(0,e.start)}},{key:"getFwdBufferInfo",value:function(e,t){var r=this.getLoadPosition();return F(r)?this.getFwdBufferInfoAtPos(e,r,t):null}},{key:"getFwdBufferInfoAtPos",value:function(e,t,r){var i=this.config.maxBufferHole,a=br.bufferInfo(e,t,i);if(0===a.len&&void 0!==a.nextStart){var n=this.fragmentTracker.getBufferedFrag(t,r);if(n&&a.nextStart<n.end)return br.bufferInfo(e,t,Math.max(a.nextStart,i))}return a}},{key:"getMaxBufferLength",value:function(e){var t,r=this.config;return t=e?Math.max(8*r.maxBufferSize/e,r.maxBufferLength):r.maxBufferLength,Math.min(t,r.maxMaxBufferLength)}},{key:"reduceMaxBufferLength",value:function(e){var t=this.config,r=e||t.maxBufferLength;return t.maxMaxBufferLength>=r&&(t.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to ".concat(t.maxMaxBufferLength,"s")),!0)}},{key:"getAppendedFrag",value:function(e){var t=this.fragmentTracker.getAppendedFrag(e,At);return t&&"fragment"in t?t.fragment:t}},{key:"getNextFragment",value:function(e,t){var r=t.fragments,i=r.length;if(!i)return null;var a,n=this.config,s=r[0].start;if(t.live){var o=n.initialLiveManifestSize;if(i<o)return this.warn("Not enough fragments to start playback (have: ".concat(i,", need: ").concat(o,")")),null;t.PTSKnown||this.startFragRequested||-1!==this.startPosition||(a=this.getInitialLiveFragment(t,r),this.startPosition=a?this.hls.liveSyncPosition||a.start:e)}else e<=s&&(a=r[0]);if(!a){var l=n.lowLatencyMode?t.partEnd:t.fragmentEnd;a=this.getFragmentAtPosition(e,l,t)}return this.mapToInitFragWhenRequired(a)}},{key:"isLoopLoading",value:function(e,t){var r=this.fragmentTracker.getState(e);return(r===vr||r===fr&&!!e.gap)&&this.nextLoadPosition>t}},{key:"getNextFragmentLoopLoading",value:function(e,t,r,i,a){var n=e.gap,s=this.getNextFragment(this.nextLoadPosition,t);if(null===s)return s;if(e=s,n&&e&&!e.gap&&r.nextStart){var o=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,r.nextStart,i);if(null!==o&&r.len+o.len>=a)return this.log('buffer full after gaps in "'.concat(i,'" playlist starting at sn: ').concat(e.sn)),null}return e}},{key:"mapToInitFragWhenRequired",value:function(e){return null==e||!e.initSegment||null!=e&&e.initSegment.data||this.bitrateTest?e:e.initSegment}},{key:"getNextPart",value:function(e,t,r){for(var i=-1,a=!1,n=!0,s=0,o=e.length;s<o;s++){var l=e[s];if(n=n&&!l.independent,i>-1&&r<l.start)break;var u=l.loaded;u?i=-1:(a||l.independent||n)&&l.fragment===t&&(i=s),a=u}return i}},{key:"loadedEndOfParts",value:function(e,t){var r=e[e.length-1];return r&&t>r.start&&r.loaded}},{key:"getInitialLiveFragment",value:function(e,t){var r=this.fragPrevious,i=null;if(r){if(e.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: ".concat(r.programDateTime)),i=function(e,t,r){if(null===t||!Array.isArray(e)||!e.length||!F(t))return null;if(t<(e[0].programDateTime||0))return null;if(t>=(e[e.length-1].endProgramDateTime||0))return null;r=r||0;for(var i=0;i<e.length;++i){var a=e[i];if(ar(t,r,a))return a}return null}(t,r.endProgramDateTime,this.config.maxFragLookUpTolerance)),!i){var a=r.sn+1;if(a>=e.startSN&&a<=e.endSN){var n=t[a-e.startSN];r.cc===n.cc&&(i=n,this.log("Live playlist, switching playlist, load frag with next SN: ".concat(i.sn)))}i||(i=function(e,t){return tr(e,(function(e){return e.cc<t?1:e.cc>t?-1:0}))}(t,r.cc),i&&this.log("Live playlist, switching playlist, load frag with same CC: ".concat(i.sn)))}}else{var s=this.hls.liveSyncPosition;null!==s&&(i=this.getFragmentAtPosition(s,this.bitrateTest?e.fragmentEnd:e.edge,e))}return i}},{key:"getFragmentAtPosition",value:function(e,t,r){var i,a=this.config,n=this.fragPrevious,s=r.fragments,o=r.endSN,l=r.fragmentHint,u=a.maxFragLookUpTolerance,c=r.partList,h=!!(a.lowLatencyMode&&null!=c&&c.length&&l);if(h&&l&&!this.bitrateTest&&(s=s.concat(l),o=l.sn),i=e<t?rr(n,s,e,e>t-u?0:u):s[s.length-1]){var d=i.sn-r.startSN,f=this.fragmentTracker.getState(i);if((f===vr||f===fr&&i.gap)&&(n=i),n&&i.sn===n.sn&&(!h||c[0].fragment.sn>i.sn)&&n&&i.level===n.level){var v=s[d+1];i=i.sn<o&&this.fragmentTracker.getState(v)!==vr?v:null}}return i}},{key:"synchronizeToLiveEdge",value:function(e){var t=this.config,r=this.media;if(r){var i=this.hls.liveSyncPosition,a=r.currentTime,n=e.fragments[0].start,s=e.edge,o=a>=n-t.maxFragLookUpTolerance&&a<=s;if(null!==i&&r.duration>i&&(a<i||!o)){var l=void 0!==t.liveMaxLatencyDuration?t.liveMaxLatencyDuration:t.liveMaxLatencyDurationCount*e.targetduration;(!o&&r.readyState<4||a<s-l)&&(this.loadedmetadata||(this.nextLoadPosition=i),r.readyState&&(this.warn("Playback: ".concat(a.toFixed(3)," is located too far from the end of live sliding playlist: ").concat(s,", reset currentTime to : ").concat(i.toFixed(3))),r.currentTime=i))}}}},{key:"alignPlaylists",value:function(e,t){var r=this.levels,i=this.levelLastLoaded,a=this.fragPrevious,n=null!==i?r[i]:null,s=e.fragments.length;if(!s)return this.warn("No fragments in live playlist"),0;var o=e.fragments[0].start,l=!t,u=e.alignedSliding&&F(o);if(l||!u&&!o){!function(e,t,r){t&&(function(e,t,r){if(function(e,t,r){return!(!t.details||!(r.endCC>r.startCC||e&&e.cc<r.startCC))}(e,r,t)){var i=function(e,t){var r=e.fragments,i=t.fragments;if(i.length&&r.length){var a=Ir(r,i[0].cc);if(a&&(!a||a.startPTS))return a;K.log("No frag in previous level to align on")}else K.log("No fragments to align")}(r.details,t);i&&F(i.start)&&(K.log("Adjusting PTS using last level due to CC increase within current level ".concat(t.url)),Cr(i.start,t))}}(e,r,t),!r.alignedSliding&&t.details&&function(e,t){if(t.fragments.length&&e.hasProgramDateTime&&t.hasProgramDateTime){var r=t.fragments[0].programDateTime,i=e.fragments[0].programDateTime,a=(i-r)/1e3+t.fragments[0].start;a&&F(a)&&(K.log("Adjusting PTS using programDateTime delta ".concat(i-r,"ms, sliding:").concat(a.toFixed(3)," ").concat(e.url," ")),Cr(a,e))}}(r,t.details),r.alignedSliding||!t.details||r.skippedSegments||jt(t.details,r))}(a,n,e);var c=e.fragments[0].start;return this.log("Live playlist sliding: ".concat(c.toFixed(2)," start-sn: ").concat(t?t.startSN:"na","->").concat(e.startSN," prev-sn: ").concat(a?a.sn:"na"," fragments: ").concat(s)),c}return o}},{key:"waitForCdnTuneIn",value:function(e){return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,3*e.partTarget)}},{key:"setStartPosition",value:function(e,t){var r=this.startPosition;if(r<t&&(r=-1),-1===r||-1===this.lastCurrentTime){var i=null!==this.startTimeOffset,a=i?this.startTimeOffset:e.startTimeOffset;null!==a&&F(a)?(r=t+a,a<0&&(r+=e.totalduration),r=Math.min(Math.max(t,r),t+e.totalduration),this.log("Start time offset ".concat(a," found in ").concat(i?"multivariant":"media"," playlist, adjust startPosition to ").concat(r)),this.startPosition=r):e.live?r=this.hls.liveSyncPosition||t:this.startPosition=r=0,this.lastCurrentTime=r}this.nextLoadPosition=r}},{key:"getLoadPosition",value:function(){var e=this.media,t=0;return this.loadedmetadata&&e?t=e.currentTime:this.nextLoadPosition&&(t=this.nextLoadPosition),t}},{key:"handleFragLoadAborted",value:function(e,t){this.transmuxer&&"initSegment"!==e.sn&&e.stats.aborted&&(this.warn("Fragment ".concat(e.sn).concat(t?" part "+t.index:""," of level ").concat(e.level," was aborted")),this.resetFragmentLoading(e))}},{key:"resetFragmentLoading",value:function(e){this.fragCurrent&&(this.fragContextChanged(e)||this.state===Gr)||(this.state=Nr)}},{key:"onFragmentOrKeyLoadError",value:function(e,t){if(t.chunkMeta&&!t.frag){var r=this.getCurrentContext(t.chunkMeta);r&&(t.frag=r.frag)}var i=t.frag;if(i&&i.type===e&&this.levels)if(this.fragContextChanged(i)){var a;this.warn("Frag load error must match current frag to retry ".concat(i.url," > ").concat(null==(a=this.fragCurrent)?void 0:a.url))}else{var n=t.details===N.FRAG_GAP;n&&this.fragmentTracker.fragBuffered(i,!0);var s=t.errorAction,o=s||{},l=o.action,u=o.retryCount,c=void 0===u?0:u,h=o.retryConfig;if(s&&5===l&&h){var d;this.resetStartWhenNotLoaded(null!=(d=this.levelLastLoaded)?d:i.level);var f=Jt(h,c);this.warn("Fragment ".concat(i.sn," of ").concat(e," ").concat(i.level," errored with ").concat(t.details,", retrying loading ").concat(c+1,"/").concat(h.maxNumRetry," in ").concat(f,"ms")),s.resolved=!0,this.retryDate=self.performance.now()+f,this.state=Gr}else h&&s?(this.resetFragmentErrors(e),c<h.maxNumRetry?n||(s.resolved=!0):K.warn("".concat(t.details," reached or exceeded max retry (").concat(c,")"))):2===(null==s?void 0:s.action)?this.state=qr:this.state=Wr;this.tickImmediate()}}},{key:"reduceLengthAndFlushBuffer",value:function(e){if(this.state===Hr||this.state===Vr){var t=e.parent,r=this.getFwdBufferInfo(this.mediaBuffer,t),i=r&&r.len>.5;i&&this.reduceMaxBufferLength(r.len);var a=!i;return a&&this.warn("Buffer full error while media.currentTime is not buffered, flush ".concat(t," buffer")),e.frag&&(this.fragmentTracker.removeFragment(e.frag),this.nextLoadPosition=e.frag.start),this.resetLoadingState(),a}return!1}},{key:"resetFragmentErrors",value:function(e){e===Rt&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==Mr&&(this.state=Nr)}},{key:"afterBufferFlushed",value:function(e,t,r){if(e){var i=br.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,i,r),this.state===Yr&&this.resetLoadingState()}}},{key:"resetLoadingState",value:function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=Nr}},{key:"resetStartWhenNotLoaded",value:function(e){if(!this.loadedmetadata){this.startFragRequested=!1;var t=this.levels?this.levels[e].details:null;null!=t&&t.live?(this.startPosition=-1,this.setStartPosition(t,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}}},{key:"resetWhenMissingContext",value:function(e){var t;this.warn("The loading context changed while buffering fragment ".concat(e.sn," of level ").concat(e.level,". This chunk will not be buffered.")),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(null!=(t=this.levelLastLoaded)?t:e.level),this.resetLoadingState()}},{key:"removeUnbufferedFrags",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.fragmentTracker.removeFragmentsInRange(e,1/0,this.playlistType,!1,!0)}},{key:"updateLevelTiming",value:function(e,t,r,i){var a,n=this,s=r.details;if(s){if(Object.keys(e.elementaryStreams).reduce((function(t,a){var o=e.elementaryStreams[a];if(o){var l=o.endPTS-o.startPTS;if(l<=0)return n.warn("Could not parse fragment ".concat(e.sn," ").concat(a," duration reliably (").concat(l,")")),t||!1;var u=i?0:Wt(s,e,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return n.hls.trigger(O.LEVEL_PTS_UPDATED,{details:s,level:r,drift:u,type:a,frag:e,start:o.startPTS,end:o.endPTS}),!0}return t}),!1))r.fragmentError=0;else if(null===(null==(a=this.transmuxer)?void 0:a.error)){var o=new Error("Found no media in fragment ".concat(e.sn," of level ").concat(e.level," resetting transmuxer to fallback to playlist timing"));if(0===r.fragmentError&&(r.fragmentError++,e.gap=!0,this.fragmentTracker.removeFragment(e),this.fragmentTracker.fragBuffered(e,!0)),this.warn(o.message),this.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_PARSING_ERROR,fatal:!1,error:o,frag:e,reason:"Found no media in msn ".concat(e.sn,' of level "').concat(r.url,'"')}),!this.hls)return;this.resetTransmuxer()}this.state=Vr,this.hls.trigger(O.FRAG_PARSED,{frag:e,part:t})}else this.warn("level.details undefined")}},{key:"resetTransmuxer",value:function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)}},{key:"recoverWorkerError",value:function(e){var t,r,i;"demuxerWorker"===e.event&&(this.fragmentTracker.removeAllFragments(),this.resetTransmuxer(),this.resetStartWhenNotLoaded(null!=(t=null!=(r=this.levelLastLoaded)?r:null==(i=this.fragCurrent)?void 0:i.level)?t:0),this.resetLoadingState())}},{key:"state",get:function(){return this._state},set:function(e){var t=this._state;t!==e&&(this._state=e,this.log("".concat(t,"->").concat(e)))}}]),r}(Ar);function zr(){return self.SourceBuffer||self.WebKitSourceBuffer}function Qr(){return{type:arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",id:-1,pid:-1,inputTimeScale:arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4,sequenceNumber:-1,samples:[],dropped:0}}var $r=function(){function e(){y(this,e),this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}return k(e,[{key:"resetInitSegment",value:function(e,t,r,i){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}}},{key:"resetTimeStamp",value:function(e){this.initPTS=e,this.resetContiguity()}},{key:"resetContiguity",value:function(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0}},{key:"canParse",value:function(e,t){return!1}},{key:"appendFrame",value:function(e,t,r){}},{key:"demux",value:function(e,t){this.cachedData&&(e=Ye(this.cachedData,e),this.cachedData=null);var r,i=ye(e,0),a=i?i.length:0,n=this._audioTrack,s=this._id3Track,o=i?function(e){for(var t=Se(e),r=0;r<t.length;r++){var i=t[r];if(Te(i))return De(i)}}(i):void 0,l=e.length;for((null===this.basePTS||0===this.frameIndex&&F(o))&&(this.basePTS=Jr(o,t,this.initPTS),this.lastPTS=this.basePTS),null===this.lastPTS&&(this.lastPTS=this.basePTS),i&&i.length>0&&s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:i,type:Ft,duration:Number.POSITIVE_INFINITY});a<l;){if(this.canParse(e,a)){var u=this.appendFrame(n,e,a);u?(this.frameIndex++,this.lastPTS=u.sample.pts,r=a+=u.length):a=l}else ke(e,a)?(i=ye(e,a),s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:i,type:Ft,duration:Number.POSITIVE_INFINITY}),r=a+=i.length):a++;if(a===l&&r!==l){var c=fe(e,r);this.cachedData?this.cachedData=Ye(this.cachedData,c):this.cachedData=c}}return{audioTrack:n,videoTrack:Qr(),id3Track:s,textTrack:Qr()}}},{key:"demuxSampleAes",value:function(e,t,r){return Promise.reject(new Error("[".concat(this,"] This demuxer does not support Sample-AES decryption")))}},{key:"flush",value:function(e){var t=this.cachedData;return t&&(this.cachedData=null,this.demux(t,0)),{audioTrack:this._audioTrack,videoTrack:Qr(),id3Track:this._id3Track,textTrack:Qr()}}},{key:"destroy",value:function(){}}]),e}(),Jr=function(e,t,r){return F(e)?90*e:9e4*t+(r?9e4*r.baseTime/r.timescale:0)};function Zr(e,t){return 255===e[t]&&240==(246&e[t+1])}function ei(e,t){return 1&e[t+1]?7:9}function ti(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function ri(e,t){return t+1<e.length&&Zr(e,t)}function ii(e,t){if(ri(e,t)){var r=ei(e,t);if(t+r>=e.length)return!1;var i=ti(e,t);if(i<=r)return!1;var a=t+i;return a===e.length||ri(e,a)}return!1}function ai(e,t,r,i,a){if(!e.samplerate){var n=function(e,t,r,i){var a,n,s,o,l=navigator.userAgent.toLowerCase(),u=i,c=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];a=1+((192&t[r+2])>>>6);var h=(60&t[r+2])>>>2;if(!(h>c.length-1))return s=(1&t[r+2])<<2,s|=(192&t[r+3])>>>6,K.log("manifest codec:".concat(i,", ADTS type:").concat(a,", samplingIndex:").concat(h)),/firefox/i.test(l)?h>=6?(a=5,o=new Array(4),n=h-3):(a=2,o=new Array(2),n=h):-1!==l.indexOf("android")?(a=2,o=new Array(2),n=h):(a=5,o=new Array(4),i&&(-1!==i.indexOf("mp4a.40.29")||-1!==i.indexOf("mp4a.40.5"))||!i&&h>=6?n=h-3:((i&&-1!==i.indexOf("mp4a.40.2")&&(h>=6&&1===s||/vivaldi/i.test(l))||!i&&1===s)&&(a=2,o=new Array(2)),n=h)),o[0]=a<<3,o[0]|=(14&h)>>1,o[1]|=(1&h)<<7,o[1]|=s<<3,5===a&&(o[1]|=(14&n)>>1,o[2]=(1&n)<<7,o[2]|=8,o[3]=0),{config:o,samplerate:c[h],channelCount:s,codec:"mp4a.40."+a,manifestCodec:u};e.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:".concat(h)})}(t,r,i,a);if(!n)return;e.config=n.config,e.samplerate=n.samplerate,e.channelCount=n.channelCount,e.codec=n.codec,e.manifestCodec=n.manifestCodec,K.log("parsed codec:".concat(e.codec,", rate:").concat(n.samplerate,", channels:").concat(n.channelCount))}}function ni(e){return 9216e4/e}function si(e,t,r,i,a){var n,s=i+a*ni(e.samplerate),o=function(e,t){var r=ei(e,t);if(t+r<=e.length){var i=ti(e,t)-r;if(i>0)return{headerLength:r,frameLength:i}}}(t,r);if(o){var l=o.frameLength,u=o.headerLength,c=u+l,h=Math.max(0,r+c-t.length);h?(n=new Uint8Array(c-u)).set(t.subarray(r+u,t.length),0):n=t.subarray(r+u,r+c);var d={unit:n,pts:s};return h||e.samples.push(d),{sample:d,length:c,missing:h}}var f=t.length-r;return(n=new Uint8Array(f)).set(t.subarray(r,t.length),0),{sample:{unit:n,pts:s},length:f,missing:-1}}var oi=function(e){c(r,e);var t=d(r);function r(e,i){var a;return y(this,r),(a=t.call(this)).observer=void 0,a.config=void 0,a.observer=e,a.config=i,a}return k(r,[{key:"resetInitSegment",value:function(e,t,i,a){u(g(r.prototype),"resetInitSegment",this).call(this,e,t,i,a),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:t,duration:a,inputTimeScale:9e4,dropped:0}}},{key:"canParse",value:function(e,t){return function(e,t){return function(e,t){return t+5<e.length}(e,t)&&Zr(e,t)&&ti(e,t)<=e.length-t}(e,t)}},{key:"appendFrame",value:function(e,t,r){ai(e,this.observer,t,r,e.manifestCodec);var i=si(e,t,r,this.basePTS,this.frameIndex);if(i&&0===i.missing)return i}}],[{key:"probe",value:function(e){if(!e)return!1;for(var t=(ye(e,0)||[]).length,r=e.length;t<r;t++)if(ii(e,t))return K.log("ADTS sync word found !"),!0;return!1}}]),r}($r),li=/\/emsg[-/]ID3/i,ui=function(){function e(t,r){y(this,e),this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=r}return k(e,[{key:"resetTimeStamp",value:function(){}},{key:"resetInitSegment",value:function(e,t,r,i){var a=this.videoTrack=Qr("video",1),n=this.audioTrack=Qr("audio",1),s=this.txtTrack=Qr("text",1);if(this.id3Track=Qr("id3",1),this.timeOffset=0,null!=e&&e.byteLength){var o=Ke(e);if(o.video){var l=o.video,u=l.id,c=l.timescale,h=l.codec;a.id=u,a.timescale=s.timescale=c,a.codec=h}if(o.audio){var d=o.audio,f=d.id,v=d.timescale,g=d.codec;n.id=f,n.timescale=v,n.codec=g}s.id=xe.text,a.sampleDuration=0,a.duration=n.duration=i}}},{key:"resetContiguity",value:function(){this.remainderData=null}},{key:"demux",value:function(e,t){this.timeOffset=t;var r=e,i=this.videoTrack,a=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=Ye(this.remainderData,e));var n=function(e){var t={valid:null,remainder:null},r=Be(e,["moof"]);if(!r)return t;if(r.length<2)return t.remainder=e,t;var i=r[r.length-1];return t.valid=fe(e,0,i.byteOffset-8),t.remainder=fe(e,i.byteOffset-8),t}(r);this.remainderData=n.remainder,i.samples=n.valid||new Uint8Array}else i.samples=r;var s=this.extractID3Track(i,t);return a.samples=We(t,i),{videoTrack:i,audioTrack:this.audioTrack,id3Track:s,textTrack:this.txtTrack}}},{key:"flush",value:function(){var e=this.timeOffset,t=this.videoTrack,r=this.txtTrack;t.samples=this.remainderData||new Uint8Array,this.remainderData=null;var i=this.extractID3Track(t,this.timeOffset);return r.samples=We(e,t),{videoTrack:t,audioTrack:Qr(),id3Track:i,textTrack:Qr()}}},{key:"extractID3Track",value:function(e,t){var r=this.id3Track;if(e.samples.length){var i=Be(e.samples,["emsg"]);i&&i.forEach((function(e){var i=function(e){var t=e[0],r="",i="",a=0,n=0,s=0,o=0,l=0,u=0;if(0===t){for(;"\0"!==Fe(e.subarray(u,u+1));)r+=Fe(e.subarray(u,u+1)),u+=1;for(r+=Fe(e.subarray(u,u+1)),u+=1;"\0"!==Fe(e.subarray(u,u+1));)i+=Fe(e.subarray(u,u+1)),u+=1;i+=Fe(e.subarray(u,u+1)),u+=1,a=Me(e,12),n=Me(e,16),o=Me(e,20),l=Me(e,24),u=28}else if(1===t){a=Me(e,u+=4);var c=Me(e,u+=4),h=Me(e,u+=4);for(u+=4,s=Math.pow(2,32)*c+h,Number.isSafeInteger(s)||(s=Number.MAX_SAFE_INTEGER,K.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=Me(e,u),l=Me(e,u+=4),u+=4;"\0"!==Fe(e.subarray(u,u+1));)r+=Fe(e.subarray(u,u+1)),u+=1;for(r+=Fe(e.subarray(u,u+1)),u+=1;"\0"!==Fe(e.subarray(u,u+1));)i+=Fe(e.subarray(u,u+1)),u+=1;i+=Fe(e.subarray(u,u+1)),u+=1}return{schemeIdUri:r,value:i,timeScale:a,presentationTime:s,presentationTimeDelta:n,eventDuration:o,id:l,payload:e.subarray(u,e.byteLength)}}(e);if(li.test(i.schemeIdUri)){var a=F(i.presentationTime)?i.presentationTime/i.timeScale:t+i.presentationTimeDelta/i.timeScale,n=4294967295===i.eventDuration?Number.POSITIVE_INFINITY:i.eventDuration/i.timeScale;n<=.001&&(n=Number.POSITIVE_INFINITY);var s=i.payload;r.samples.push({data:s,len:s.byteLength,dts:a,pts:a,type:Ot,duration:n})}}))}return r}},{key:"demuxSampleAes",value:function(e,t,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))}},{key:"destroy",value:function(){}}],[{key:"probe",value:function(e){return Be(e=e.length>16384?e.subarray(0,16384):e,["moof"]).length>0}}]),e}(),ci=null,hi=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],di=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],fi=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],vi=[0,1,1,4];function gi(e,t,r,i,a){if(!(r+24>t.length)){var n=mi(t,r);if(n&&r+n.frameLength<=t.length){var s=i+a*(9e4*n.samplesPerFrame/n.sampleRate),o={unit:t.subarray(r,r+n.frameLength),pts:s,dts:s};return e.config=[],e.channelCount=n.channelCount,e.samplerate=n.sampleRate,e.samples.push(o),{sample:o,length:n.frameLength,missing:0}}}}function mi(e,t){var r=e[t+1]>>3&3,i=e[t+1]>>1&3,a=e[t+2]>>4&15,n=e[t+2]>>2&3;if(1!==r&&0!==a&&15!==a&&3!==n){var s=e[t+2]>>1&1,o=e[t+3]>>6,l=1e3*hi[14*(3===r?3-i:3===i?3:4)+a-1],u=di[3*(3===r?0:2===r?1:2)+n],c=3===o?1:2,h=fi[r][i],d=vi[i],f=8*h*d,v=Math.floor(h*l/u+s)*d;if(null===ci){var g=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);ci=g?parseInt(g[1]):0}return!!ci&&ci<=87&&2===i&&l>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:u,channelCount:c,frameLength:v,samplesPerFrame:f}}}function yi(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}function pi(e,t){return t+1<e.length&&yi(e,t)}function ki(e,t){if(t+1<e.length&&yi(e,t)){var r=mi(e,t),i=4;null!=r&&r.frameLength&&(i=r.frameLength);var a=t+i;return a===e.length||pi(e,a)}return!1}var Ti=function(){function e(t){y(this,e),this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=t,this.bytesAvailable=t.byteLength,this.word=0,this.bitsAvailable=0}return k(e,[{key:"loadWord",value:function(){var e=this.data,t=this.bytesAvailable,r=e.byteLength-t,i=new Uint8Array(4),a=Math.min(4,t);if(0===a)throw new Error("no bytes available");i.set(e.subarray(r,r+a)),this.word=new DataView(i.buffer).getUint32(0),this.bitsAvailable=8*a,this.bytesAvailable-=a}},{key:"skipBits",value:function(e){var t;e=Math.min(e,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,e-=(t=e>>3)<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)}},{key:"readBits",value:function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(e>32&&K.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0)this.word<<=t;else{if(!(this.bytesAvailable>0))throw new Error("no bits available");this.loadWord()}return(t=e-t)>0&&this.bitsAvailable?r<<t|this.readBits(t):r}},{key:"skipLZ",value:function(){var e;for(e=0;e<this.bitsAvailable;++e)if(0!=(this.word&2147483648>>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}},{key:"skipScalingList",value:function(e){for(var t=8,r=8,i=0;i<e;i++)0!==r&&(r=(t+this.readEG()+256)%256),t=0===r?t:r}},{key:"readSPS",value:function(){var e,t,r,i=0,a=0,n=0,s=0,o=this.readUByte.bind(this),l=this.readBits.bind(this),u=this.readUEG.bind(this),c=this.readBoolean.bind(this),h=this.skipBits.bind(this),d=this.skipEG.bind(this),f=this.skipUEG.bind(this),v=this.skipScalingList.bind(this);o();var g=o();if(l(5),h(3),o(),f(),100===g||110===g||122===g||244===g||44===g||83===g||86===g||118===g||128===g){var m=u();if(3===m&&h(1),f(),f(),h(1),c())for(t=3!==m?8:12,r=0;r<t;r++)c()&&v(r<6?16:64)}f();var y=u();if(0===y)u();else if(1===y)for(h(1),d(),d(),e=u(),r=0;r<e;r++)d();f(),h(1);var p=u(),k=u(),T=l(1);0===T&&h(1),h(1),c()&&(i=u(),a=u(),n=u(),s=u());var E=[1,1];if(c()&&c())switch(o()){case 1:E=[1,1];break;case 2:E=[12,11];break;case 3:E=[10,11];break;case 4:E=[16,11];break;case 5:E=[40,33];break;case 6:E=[24,11];break;case 7:E=[20,11];break;case 8:E=[32,11];break;case 9:E=[80,33];break;case 10:E=[18,11];break;case 11:E=[15,11];break;case 12:E=[64,33];break;case 13:E=[160,99];break;case 14:E=[4,3];break;case 15:E=[3,2];break;case 16:E=[2,1];break;case 255:E=[o()<<8|o(),o()<<8|o()]}return{width:Math.ceil(16*(p+1)-2*i-2*a),height:(2-T)*(k+1)*16-(T?2:4)*(n+s),pixelRatio:E}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}(),Ei=function(){function e(t,r,i){y(this,e),this.keyData=void 0,this.decrypter=void 0,this.keyData=i,this.decrypter=new Or(r,{removePKCS7Padding:!1})}return k(e,[{key:"decryptBuffer",value:function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer)}},{key:"decryptAacSample",value:function(e,t,r){var i=this,a=e[t].unit;if(!(a.length<=16)){var n=a.subarray(16,a.length-a.length%16),s=n.buffer.slice(n.byteOffset,n.byteOffset+n.length);this.decryptBuffer(s).then((function(n){var s=new Uint8Array(n);a.set(s,16),i.decrypter.isSync()||i.decryptAacSamples(e,t+1,r)}))}}},{key:"decryptAacSamples",value:function(e,t,r){for(;;t++){if(t>=e.length)return void r();if(!(e[t].unit.length<32||(this.decryptAacSample(e,t,r),this.decrypter.isSync())))return}}},{key:"getAvcEncryptedData",value:function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),i=0,a=32;a<e.length-16;a+=160,i+=16)r.set(e.subarray(a,a+16),i);return r}},{key:"getAvcDecryptedUnit",value:function(e,t){for(var r=new Uint8Array(t),i=0,a=32;a<e.length-16;a+=160,i+=16)e.set(r.subarray(i,i+16),a);return e}},{key:"decryptAvcSample",value:function(e,t,r,i,a){var n=this,s=Xe(a.data),o=this.getAvcEncryptedData(s);this.decryptBuffer(o.buffer).then((function(o){a.data=n.getAvcDecryptedUnit(s,o),n.decrypter.isSync()||n.decryptAvcSamples(e,t,r+1,i)}))}},{key:"decryptAvcSamples",value:function(e,t,r,i){if(e instanceof Uint8Array)throw new Error("Cannot decrypt samples of type Uint8Array");for(;;t++,r=0){if(t>=e.length)return void i();for(var a=e[t].units;!(r>=a.length);r++){var n=a[r];if(!(n.data.length<=48||1!==n.type&&5!==n.type||(this.decryptAvcSample(e,t,r,i,n),this.decrypter.isSync())))return}}}}]),e}(),Si=188,Li=function(){function e(t,r,i){y(this,e),this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._avcTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.observer=t,this.config=r,this.typeSupported=i}return k(e,[{key:"resetInitSegment",value:function(t,r,i,a){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack=e.createTrack("video"),this._audioTrack=e.createTrack("audio",a),this._id3Track=e.createTrack("id3"),this._txtTrack=e.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=i,this._duration=a}},{key:"resetTimeStamp",value:function(){}},{key:"resetContiguity",value:function(){var e=this._audioTrack,t=this._avcTrack,r=this._id3Track;e&&(e.pesData=null),t&&(t.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.avcSample=null,this.remainderData=null}},{key:"demux",value:function(t,r){var i,a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];a||(this.sampleAes=null);var s=this._avcTrack,o=this._audioTrack,l=this._id3Track,u=this._txtTrack,c=s.pid,h=s.pesData,d=o.pid,f=l.pid,v=o.pesData,g=l.pesData,m=null,y=this.pmtParsed,p=this._pmtId,k=t.length;if(this.remainderData&&(k=(t=Ye(this.remainderData,t)).length,this.remainderData=null),k<Si&&!n)return this.remainderData=t,{audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};var T=Math.max(0,e.syncOffset(t));(k-=(k-T)%Si)<t.byteLength&&!n&&(this.remainderData=new Uint8Array(t.buffer,k,t.buffer.byteLength-k));for(var E=0,S=T;S<k;S+=Si)if(71===t[S]){var L=!!(64&t[S+1]),A=Ri(t,S),R=void 0;if((48&t[S+3])>>4>1){if((R=S+5+t[S+4])===S+Si)continue}else R=S+4;switch(A){case c:L&&(h&&(i=Ii(h))&&this.parseAVCPES(s,u,i,!1),h={data:[],size:0}),h&&(h.data.push(t.subarray(R,S+Si)),h.size+=S+Si-R);break;case d:if(L){if(v&&(i=Ii(v)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,i);break;case"mp3":this.parseMPEGPES(o,i)}v={data:[],size:0}}v&&(v.data.push(t.subarray(R,S+Si)),v.size+=S+Si-R);break;case f:L&&(g&&(i=Ii(g))&&this.parseID3PES(l,i),g={data:[],size:0}),g&&(g.data.push(t.subarray(R,S+Si)),g.size+=S+Si-R);break;case 0:L&&(R+=t[R]+1),p=this._pmtId=bi(t,R);break;case p:L&&(R+=t[R]+1);var b=Di(t,R,this.typeSupported,a);(c=b.avc)>0&&(s.pid=c),(d=b.audio)>0&&(o.pid=d,o.segmentCodec=b.segmentCodec),(f=b.id3)>0&&(l.pid=f),null===m||y||(K.warn("MPEG-TS PMT found at ".concat(S," after unknown PID '").concat(m,"'. Backtracking to sync byte @").concat(T," to parse all TS packets.")),m=null,S=T-188),y=this.pmtParsed=!0;break;case 17:case 8191:break;default:m=A}}else E++;if(E>0){var D=new Error("Found ".concat(E," TS packet/s that do not start with 0x47"));this.observer.emit(O.ERROR,O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_PARSING_ERROR,fatal:!1,error:D,reason:D.message})}s.pesData=h,o.pesData=v,l.pesData=g;var I={audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};return n&&this.extractRemainingSamples(I),I}},{key:"flush",value:function(){var e,t=this.remainderData;return this.remainderData=null,e=t?this.demux(t,-1,!1,!0):{videoTrack:this._avcTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(e),this.sampleAes?this.decrypt(e,this.sampleAes):e}},{key:"extractRemainingSamples",value:function(e){var t,r=e.audioTrack,i=e.videoTrack,a=e.id3Track,n=e.textTrack,s=i.pesData,o=r.pesData,l=a.pesData;if(s&&(t=Ii(s))?(this.parseAVCPES(i,n,t,!0),i.pesData=null):i.pesData=s,o&&(t=Ii(o))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,t);break;case"mp3":this.parseMPEGPES(r,t)}r.pesData=null}else null!=o&&o.size&&K.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(t=Ii(l))?(this.parseID3PES(a,t),a.pesData=null):a.pesData=l}},{key:"demuxSampleAes",value:function(e,t,r){var i=this.demux(e,r,!0,!this.config.progressive),a=this.sampleAes=new Ei(this.observer,this.config,t);return this.decrypt(i,a)}},{key:"decrypt",value:function(e,t){return new Promise((function(r){var i=e.audioTrack,a=e.videoTrack;i.samples&&"aac"===i.segmentCodec?t.decryptAacSamples(i.samples,0,(function(){a.samples?t.decryptAvcSamples(a.samples,0,0,(function(){r(e)})):r(e)})):a.samples&&t.decryptAvcSamples(a.samples,0,0,(function(){r(e)}))}))}},{key:"destroy",value:function(){this._duration=0}},{key:"parseAVCPES",value:function(e,t,r,i){var a,n=this,s=this.parseAVCNALu(e,r.data),o=this.avcSample,l=!1;r.data=null,o&&s.length&&!e.audFound&&(wi(o,e),o=this.avcSample=Ai(!1,r.pts,r.dts,"")),s.forEach((function(i){var s;switch(i.type){case 1:var u=!1;a=!0;var c,h=i.data;if(l&&h.length>4){var d=new Ti(h).readSliceType();2!==d&&4!==d&&7!==d&&9!==d||(u=!0)}u&&null!=(c=o)&&c.frame&&!o.key&&(wi(o,e),o=n.avcSample=null),o||(o=n.avcSample=Ai(!0,r.pts,r.dts,"")),o.frame=!0,o.key=u;break;case 5:a=!0,null!=(s=o)&&s.frame&&!o.key&&(wi(o,e),o=n.avcSample=null),o||(o=n.avcSample=Ai(!0,r.pts,r.dts,"")),o.key=!0,o.frame=!0;break;case 6:a=!0,qe(i.data,1,r.pts,t.samples);break;case 7:if(a=!0,l=!0,!e.sps){var f=i.data,v=new Ti(f).readSPS();e.width=v.width,e.height=v.height,e.pixelRatio=v.pixelRatio,e.sps=[f],e.duration=n._duration;for(var g=f.subarray(1,4),m="avc1.",y=0;y<3;y++){var p=g[y].toString(16);p.length<2&&(p="0"+p),m+=p}e.codec=m}break;case 8:a=!0,e.pps||(e.pps=[i.data]);break;case 9:a=!1,e.audFound=!0,o&&wi(o,e),o=n.avcSample=Ai(!1,r.pts,r.dts,"");break;case 12:a=!0;break;default:a=!1,o&&(o.debug+="unknown NAL "+i.type+" ")}o&&a&&o.units.push(i)})),i&&o&&(wi(o,e),this.avcSample=null)}},{key:"getLastNalUnit",value:function(e){var t,r,i=this.avcSample;if(i&&0!==i.units.length||(i=e[e.length-1]),null!=(t=i)&&t.units){var a=i.units;r=a[a.length-1]}return r}},{key:"parseAVCNALu",value:function(e,t){var r,i,a=t.byteLength,n=e.naluState||0,s=n,o=[],l=0,u=-1,c=0;for(-1===n&&(u=0,c=31&t[0],n=0,l=1);l<a;)if(r=t[l++],n)if(1!==n)if(r)if(1===r){if(u>=0){var h={data:t.subarray(u,l-n-1),type:c};o.push(h)}else{var d=this.getLastNalUnit(e.samples);if(d&&(s&&l<=4-s&&d.state&&(d.data=d.data.subarray(0,d.data.byteLength-s)),(i=l-n-1)>0)){var f=new Uint8Array(d.data.byteLength+i);f.set(d.data,0),f.set(t.subarray(0,i),d.data.byteLength),d.data=f,d.state=0}}l<a?(u=l,c=31&t[l],n=0):n=-1}else n=0;else n=3;else n=r?0:2;else n=r?0:1;if(u>=0&&n>=0){var v={data:t.subarray(u,a),type:c,state:n};o.push(v)}if(0===o.length){var g=this.getLastNalUnit(e.samples);if(g){var m=new Uint8Array(g.data.byteLength+t.byteLength);m.set(g.data,0),m.set(t,g.data.byteLength),g.data=m}}return e.naluState=n,o}},{key:"parseAACPES",value:function(e,t){var r,i,a,n=0,s=this.aacOverFlow,o=t.data;if(s){this.aacOverFlow=null;var l=s.missing,u=s.sample.unit.byteLength;if(-1===l){var c=new Uint8Array(u+o.byteLength);c.set(s.sample.unit,0),c.set(o,u),o=c}else{var h=u-l;s.sample.unit.set(o.subarray(0,l),h),e.samples.push(s.sample),n=s.missing}}for(r=n,i=o.length;r<i-1&&!ri(o,r);r++);if(r!==n){var d,f=r<i-1;d=f?"AAC PES did not start with ADTS header,offset:".concat(r):"No ADTS header found in AAC PES";var v=new Error(d);if(K.warn("parsing error: ".concat(d)),this.observer.emit(O.ERROR,O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_PARSING_ERROR,fatal:!1,levelRetry:f,error:v,reason:d}),!f)return}if(ai(e,this.observer,o,r,this.audioCodec),void 0!==t.pts)a=t.pts;else{if(!s)return void K.warn("[tsdemuxer]: AAC PES unknown PTS");var g=ni(e.samplerate);a=s.sample.pts+g}for(var m,y=0;r<i;){if(r+=(m=si(e,o,r,a,y)).length,m.missing){this.aacOverFlow=m;break}for(y++;r<i-1&&!ri(o,r);r++);}}},{key:"parseMPEGPES",value:function(e,t){var r=t.data,i=r.length,a=0,n=0,s=t.pts;if(void 0!==s)for(;n<i;)if(pi(r,n)){var o=gi(e,r,n,s,a);if(!o)break;n+=o.length,a++}else n++;else K.warn("[tsdemuxer]: MPEG PES unknown PTS")}},{key:"parseID3PES",value:function(e,t){if(void 0!==t.pts){var r=x({},t,{type:this._avcTrack?Ot:Ft,duration:Number.POSITIVE_INFINITY});e.samples.push(r)}else K.warn("[tsdemuxer]: ID3 PES unknown PTS")}}],[{key:"probe",value:function(t){var r=e.syncOffset(t);return r>0&&K.warn("MPEG2-TS detected but first sync word found @ offset ".concat(r)),-1!==r}},{key:"syncOffset",value:function(e){for(var t=e.length,r=Math.min(940,e.length-Si)+1,i=0;i<r;){for(var a=!1,n=-1,s=0,o=i;o<t;o+=Si){if(71!==e[o]){if(s)return-1;break}if(s++,-1===n&&0!==(n=o)&&(r=Math.min(n+18612,e.length-Si)+1),a||(a=0===Ri(e,o)),a&&s>1&&(0===n&&s>2||o+Si>r))return n}i++}return-1}},{key:"createTrack",value:function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:xe[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}}}]),e}();function Ai(e,t,r,i){return{key:e,frame:!1,pts:t,dts:r,units:[],debug:i,length:0}}function Ri(e,t){return((31&e[t+1])<<8)+e[t+2]}function bi(e,t){return(31&e[t+10])<<8|e[t+11]}function Di(e,t,r,i){var a={audio:-1,avc:-1,id3:-1,segmentCodec:"aac"},n=t+3+((15&e[t+1])<<8|e[t+2])-4;for(t+=12+((15&e[t+10])<<8|e[t+11]);t<n;){var s=Ri(e,t);switch(e[t]){case 207:if(!i){K.log("ADTS AAC with AES-128-CBC frame encryption found in unencrypted stream");break}case 15:-1===a.audio&&(a.audio=s);break;case 21:-1===a.id3&&(a.id3=s);break;case 219:if(!i){K.log("H.264 with AES-128-CBC slice encryption found in unencrypted stream");break}case 27:-1===a.avc&&(a.avc=s);break;case 3:case 4:!0!==r.mpeg&&!0!==r.mp3?K.log("MPEG audio found, not supported in this browser"):-1===a.audio&&(a.audio=s,a.segmentCodec="mp3");break;case 36:K.warn("Unsupported HEVC stream type found")}t+=5+((15&e[t+3])<<8|e[t+4])}return a}function Ii(e){var t,r,i,a,n,s=0,o=e.data;if(!e||0===e.size)return null;for(;o[0].length<19&&o.length>1;){var l=new Uint8Array(o[0].length+o[1].length);l.set(o[0]),l.set(o[1],o[0].length),o[0]=l,o.splice(1,1)}if(1===((t=o[0])[0]<<16)+(t[1]<<8)+t[2]){if((r=(t[4]<<8)+t[5])&&r>e.size-6)return null;var u=t[7];192&u&&(a=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,64&u?a-(n=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2)>54e5&&(K.warn("".concat(Math.round((a-n)/9e4),"s delta between PTS and DTS, align them")),a=n):n=a);var c=(i=t[8])+9;if(e.size<=c)return null;e.size-=c;for(var h=new Uint8Array(e.size),d=0,f=o.length;d<f;d++){var v=(t=o[d]).byteLength;if(c){if(c>v){c-=v;continue}t=t.subarray(c),v-=c,c=0}h.set(t,s),s+=v}return r&&(r-=i+3),{data:h,pts:a,dts:n,len:r}}return null}function wi(e,t){if(e.units.length&&e.frame){if(void 0===e.pts){var r=t.samples,i=r.length;if(!i)return void t.dropped++;var a=r[i-1];e.pts=a.pts,e.dts=a.dts}t.samples.push(e)}e.debug.length&&K.log(e.pts+"/"+e.dts+":"+e.debug)}var Ci=function(e){c(r,e);var t=d(r);function r(){return y(this,r),t.apply(this,arguments)}return k(r,[{key:"resetInitSegment",value:function(e,t,i,a){u(g(r.prototype),"resetInitSegment",this).call(this,e,t,i,a),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:t,duration:a,inputTimeScale:9e4,dropped:0}}},{key:"canParse",value:function(e,t){return function(e,t){return yi(e,t)&&4<=e.length-t}(e,t)}},{key:"appendFrame",value:function(e,t,r){if(null!==this.basePTS)return gi(e,t,r,this.basePTS,this.frameIndex)}}],[{key:"probe",value:function(e){if(!e)return!1;for(var t=(ye(e,0)||[]).length,r=e.length;t<r;t++)if(ki(e,t))return K.log("MPEG Audio sync word found !"),!0;return!1}}]),r}($r),_i=function(){function e(){y(this,e)}return k(e,null,[{key:"getSilentFrame",value:function(e,t){if("mp4a.40.2"===e){if(1===t)return new Uint8Array([0,200,0,128,35,128]);if(2===t)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224])}else{if(1===t)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}}}]),e}(),Pi=Math.pow(2,32)-1,xi=function(){function e(){y(this,e)}return k(e,null,[{key:"init",value:function(){var t;for(t in e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),i=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);e.HDLR_TYPES={video:r,audio:i};var a=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),n=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=n,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,l,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,a))}},{key:"box",value:function(e){for(var t=8,r=arguments.length,i=new Array(r>1?r-1:0),a=1;a<r;a++)i[a-1]=arguments[a];for(var n=i.length,s=n;n--;)t+=i[n].byteLength;var o=new Uint8Array(t);for(o[0]=t>>24&255,o[1]=t>>16&255,o[2]=t>>8&255,o[3]=255&t,o.set(e,4),n=0,t=8;n<s;n++)o.set(i[n],t),t+=i[n].byteLength;return o}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}},{key:"mdhd",value:function(t,r){r*=t;var i=Math.floor(r/(Pi+1)),a=Math.floor(r%(Pi+1));return e.box(e.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))}},{key:"moof",value:function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))}},{key:"moov",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(e.mvex(t)))}},{key:"mvex",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(i))}},{key:"mvhd",value:function(t,r){r*=t;var i=Math.floor(r/(Pi+1)),a=Math.floor(r%(Pi+1)),n=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,a>>24,a>>16&255,a>>8&255,255&a,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return e.box(e.types.mvhd,n)}},{key:"sdtp",value:function(t){var r,i,a=t.samples||[],n=new Uint8Array(4+a.length);for(r=0;r<a.length;r++)i=a[r].flags,n[r+4]=i.dependsOn<<4|i.isDependedOn<<2|i.hasRedundancy;return e.box(e.types.sdtp,n)}},{key:"stbl",value:function(t){return e.box(e.types.stbl,e.stsd(t),e.box(e.types.stts,e.STTS),e.box(e.types.stsc,e.STSC),e.box(e.types.stsz,e.STSZ),e.box(e.types.stco,e.STCO))}},{key:"avc1",value:function(t){var r,i,a,n=[],s=[];for(r=0;r<t.sps.length;r++)a=(i=t.sps[r]).byteLength,n.push(a>>>8&255),n.push(255&a),n=n.concat(Array.prototype.slice.call(i));for(r=0;r<t.pps.length;r++)a=(i=t.pps[r]).byteLength,s.push(a>>>8&255),s.push(255&a),s=s.concat(Array.prototype.slice.call(i));var o=e.box(e.types.avcC,new Uint8Array([1,n[3],n[4],n[5],255,224|t.sps.length].concat(n).concat([t.pps.length]).concat(s))),l=t.width,u=t.height,c=t.pixelRatio[0],h=t.pixelRatio[1];return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,l>>8&255,255&l,u>>8&255,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),e.box(e.types.pasp,new Uint8Array([c>>24,c>>16&255,c>>8&255,255&c,h>>24,h>>16&255,h>>8&255,255&h])))}},{key:"esds",value:function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))}},{key:"mp4a",value:function(t){var r=t.samplerate;return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"mp3",value:function(t){var r=t.samplerate;return e.box(e.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]))}},{key:"stsd",value:function(t){return"audio"===t.type?"mp3"===t.segmentCodec&&"mp3"===t.codec?e.box(e.types.stsd,e.STSD,e.mp3(t)):e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){var r=t.id,i=t.duration*t.timescale,a=t.width,n=t.height,s=Math.floor(i/(Pi+1)),o=Math.floor(i%(Pi+1));return e.box(e.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,a>>8&255,255&a,0,0,n>>8&255,255&n,0,0]))}},{key:"traf",value:function(t,r){var i=e.sdtp(t),a=t.id,n=Math.floor(r/(Pi+1)),s=Math.floor(r%(Pi+1));return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a])),e.box(e.types.tfdt,new Uint8Array([1,0,0,0,n>>24,n>>16&255,n>>8&255,255&n,s>>24,s>>16&255,s>>8&255,255&s])),e.trun(t,i.length+16+20+8+16+8+8),i)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(t,r){var i,a,n,s,o,l,u=t.samples||[],c=u.length,h=12+16*c,d=new Uint8Array(h);for(r+=8+h,d.set(["video"===t.type?1:0,0,15,1,c>>>24&255,c>>>16&255,c>>>8&255,255&c,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i<c;i++)n=(a=u[i]).duration,s=a.size,o=a.flags,l=a.cts,d.set([n>>>24&255,n>>>16&255,n>>>8&255,255&n,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return e.box(e.types.trun,d)}},{key:"initSegment",value:function(t){e.types||e.init();var r=e.moov(t),i=new Uint8Array(e.FTYP.byteLength+r.byteLength);return i.set(e.FTYP),i.set(r,e.FTYP.byteLength),i}}]),e}();xi.types=void 0,xi.HDLR_TYPES=void 0,xi.STTS=void 0,xi.STSC=void 0,xi.STCO=void 0,xi.STSZ=void 0,xi.VMHD=void 0,xi.SMHD=void 0,xi.STSD=void 0,xi.FTYP=void 0,xi.DINF=void 0;function Fi(e,t){var r=e*t*(arguments.length>2&&void 0!==arguments[2]?arguments[2]:1);return arguments.length>3&&void 0!==arguments[3]&&arguments[3]?Math.round(r):r}function Oi(e){return Fi(e,1e3,1/9e4,arguments.length>1&&void 0!==arguments[1]&&arguments[1])}var Mi=null,Ni=null,Ui=function(){function e(t,r,i){if(y(this,e),this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=null,this._initDTS=null,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.observer=t,this.config=r,this.typeSupported=i,this.ISGenerated=!1,null===Mi){var a=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Mi=a?parseInt(a[1]):0}if(null===Ni){var n=navigator.userAgent.match(/Safari\/(\d+)/i);Ni=n?parseInt(n[1]):0}}return k(e,[{key:"destroy",value:function(){}},{key:"resetTimeStamp",value:function(e){K.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e}},{key:"resetNextTimestamp",value:function(){K.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1}},{key:"resetInitSegment",value:function(){K.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1}},{key:"getVideoStartPts",value:function(e){var t=!1,r=e.reduce((function(e,r){var i=r.pts-e;return i<-4294967296?(t=!0,Bi(e,r.pts)):i>0?e:r.pts}),e[0].pts);return t&&K.debug("PTS rollover detected"),r}},{key:"remux",value:function(e,t,r,i,a,n,s,o){var l,u,c,h,d,f,v=a,g=a,m=e.pid>-1,y=t.pid>-1,p=t.samples.length,k=e.samples.length>0,T=s&&p>0||p>1;if((!m||k)&&(!y||T)||this.ISGenerated||s){this.ISGenerated||(c=this.generateIS(e,t,a,n));var E,S=this.isVideoContiguous,L=-1;if(T&&(L=function(e){for(var t=0;t<e.length;t++)if(e[t].key)return t;return-1}(t.samples),!S&&this.config.forceKeyFrameOnDiscontinuity))if(f=!0,L>0){K.warn("[mp4-remuxer]: Dropped ".concat(L," out of ").concat(p," video samples due to a missing keyframe"));var A=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(L),t.dropped+=L,E=g+=(t.samples[0].pts-A)/t.inputTimeScale}else-1===L&&(K.warn("[mp4-remuxer]: No keyframe found out of ".concat(p," video samples")),f=!1);if(this.ISGenerated){if(k&&T){var R=this.getVideoStartPts(t.samples),b=(Bi(e.samples[0].pts,R)-R)/t.inputTimeScale;v+=Math.max(0,b),g+=Math.max(0,-b)}if(k){if(e.samplerate||(K.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),c=this.generateIS(e,t,a,n)),u=this.remuxAudio(e,v,this.isAudioContiguous,n,y||T||o===Rt?g:void 0),T){var D=u?u.endPTS-u.startPTS:0;t.inputTimeScale||(K.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),c=this.generateIS(e,t,a,n)),l=this.remuxVideo(t,g,S,D)}}else T&&(l=this.remuxVideo(t,g,S,0));l&&(l.firstKeyFrame=L,l.independent=-1!==L,l.firstKeyFramePTS=E)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(d=Gi(r,a,this._initPTS,this._initDTS)),i.samples.length&&(h=Ki(i,a,this._initPTS))),{audio:u,video:l,initSegment:c,independent:f,text:h,id3:d}}},{key:"generateIS",value:function(e,t,r,i){var a,n,s,o=e.samples,l=t.samples,u=this.typeSupported,c={},h=this._initPTS,d=!h||i,f="audio/mp4";if(d&&(a=n=1/0),e.config&&o.length&&(e.timescale=e.samplerate,"mp3"===e.segmentCodec&&(u.mpeg?(f="audio/mpeg",e.codec=""):u.mp3&&(e.codec="mp3")),c.audio={id:"audio",container:f,codec:e.codec,initSegment:"mp3"===e.segmentCodec&&u.mpeg?new Uint8Array(0):xi.initSegment([e]),metadata:{channelCount:e.channelCount}},d&&(s=e.inputTimeScale,h&&s===h.timescale?d=!1:a=n=o[0].pts-Math.round(s*r))),t.sps&&t.pps&&l.length&&(t.timescale=t.inputTimeScale,c.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:xi.initSegment([t]),metadata:{width:t.width,height:t.height}},d))if(s=t.inputTimeScale,h&&s===h.timescale)d=!1;else{var v=this.getVideoStartPts(l),g=Math.round(s*r);n=Math.min(n,Bi(l[0].dts,v)-g),a=Math.min(a,v-g)}if(Object.keys(c).length)return this.ISGenerated=!0,d?(this._initPTS={baseTime:a,timescale:s},this._initDTS={baseTime:n,timescale:s}):a=s=void 0,{tracks:c,initPTS:a,timescale:s}}},{key:"remuxVideo",value:function(e,t,r,i){var a,n,s=e.inputTimeScale,o=e.samples,l=[],u=o.length,c=this._initPTS,h=this.nextAvcDts,d=8,f=this.videoSampleDuration,v=Number.POSITIVE_INFINITY,g=Number.NEGATIVE_INFINITY,m=!1;r&&null!==h||(h=t*s-(o[0].pts-Bi(o[0].dts,o[0].pts)));for(var y=c.baseTime*s/c.timescale,p=0;p<u;p++){var k=o[p];k.pts=Bi(k.pts-y,h),k.dts=Bi(k.dts-y,h),k.dts<o[p>0?p-1:p].dts&&(m=!0)}m&&o.sort((function(e,t){var r=e.dts-t.dts,i=e.pts-t.pts;return r||i})),a=o[0].dts;var T=o[o.length-1].dts-a,E=T?Math.round(T/(u-1)):f||e.inputTimeScale/30;if(r){var S=a-h,L=S>E,A=S<-1;if((L||A)&&(L?K.warn("AVC: ".concat(Oi(S,!0)," ms (").concat(S,"dts) hole between fragments detected, filling it")):K.warn("AVC: ".concat(Oi(-S,!0)," ms (").concat(S,"dts) overlapping between fragments detected")),!A||h>=o[0].pts)){a=h;var R=o[0].pts-S;o[0].dts=a,o[0].pts=R,K.log("Video: First PTS/DTS adjusted: ".concat(Oi(R,!0),"/").concat(Oi(a,!0),", delta: ").concat(Oi(S,!0)," ms"))}}a=Math.max(0,a);for(var b=0,D=0,I=0;I<u;I++){for(var w=o[I],C=w.units,_=C.length,P=0,F=0;F<_;F++)P+=C[F].data.length;D+=P,b+=_,w.length=P,w.dts=Math.max(w.dts,a),v=Math.min(w.pts,v),g=Math.max(w.pts,g)}n=o[u-1].dts;var U,B=D+4*b+8;try{U=new Uint8Array(B)}catch(e){return void this.observer.emit(O.ERROR,O.ERROR,{type:M.MUX_ERROR,details:N.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:B,reason:"fail allocating video mdat ".concat(B)})}var G=new DataView(U.buffer);G.setUint32(0,B),U.set(xi.types.mdat,4);for(var H=!1,V=Number.POSITIVE_INFINITY,Y=Number.POSITIVE_INFINITY,W=Number.NEGATIVE_INFINITY,j=Number.NEGATIVE_INFINITY,q=0;q<u;q++){for(var X=o[q],z=X.units,Q=0,$=0,J=z.length;$<J;$++){var Z=z[$],ee=Z.data,te=Z.data.byteLength;G.setUint32(d,te),d+=4,U.set(ee,d),d+=te,Q+=4+te}var re=void 0;if(q<u-1)f=o[q+1].dts-X.dts,re=o[q+1].pts-X.pts;else{var ie=this.config,ae=q>0?X.dts-o[q-1].dts:E;if(re=q>0?X.pts-o[q-1].pts:E,ie.stretchShortVideoTrack&&null!==this.nextAudioPts){var ne=Math.floor(ie.maxBufferHole*s),se=(i?v+i*s:this.nextAudioPts)-X.pts;se>ne?((f=se-ae)<0?f=ae:H=!0,K.log("[mp4-remuxer]: It is approximately ".concat(se/90," ms to the next segment; using duration ").concat(f/90," ms for the last video frame."))):f=ae}else f=ae}var oe=Math.round(X.pts-X.dts);V=Math.min(V,f),W=Math.max(W,f),Y=Math.min(Y,re),j=Math.max(j,re),l.push(new Vi(X.key,f,Q,oe))}if(l.length)if(Mi){if(Mi<70){var le=l[0].flags;le.dependsOn=2,le.isNonSync=0}}else if(Ni&&j-Y<W-V&&E/W<.025&&0===l[0].cts){K.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");for(var ue=a,ce=0,he=l.length;ce<he;ce++){var de=ue+l[ce].duration,fe=ue+l[ce].cts;if(ce<he-1){var ve=de+l[ce+1].cts;l[ce].duration=ve-fe}else l[ce].duration=ce?l[ce-1].duration:E;l[ce].cts=0,ue=de}}f=H||!f?E:f,this.nextAvcDts=h=n+f,this.videoSampleDuration=f,this.isVideoContiguous=!0;var ge={data1:xi.moof(e.sequenceNumber++,a,x({},e,{samples:l})),data2:U,startPTS:v/s,endPTS:(g+f)/s,startDTS:a/s,endDTS:h/s,type:"video",hasAudio:!1,hasVideo:!0,nb:l.length,dropped:e.dropped};return e.samples=[],e.dropped=0,ge}},{key:"remuxAudio",value:function(e,t,r,i,a){var n=e.inputTimeScale,s=n/(e.samplerate?e.samplerate:n),o="aac"===e.segmentCodec?1024:1152,l=o*s,u=this._initPTS,c="mp3"===e.segmentCodec&&this.typeSupported.mpeg,h=[],d=void 0!==a,f=e.samples,v=c?0:8,g=this.nextAudioPts||-1,m=t*n,y=u.baseTime*n/u.timescale;if(this.isAudioContiguous=r=r||f.length&&g>0&&(i&&Math.abs(m-g)<9e3||Math.abs(Bi(f[0].pts-y,m)-g)<20*l),f.forEach((function(e){e.pts=Bi(e.pts-y,m)})),!r||g<0){if(f=f.filter((function(e){return e.pts>=0})),!f.length)return;g=0===a?0:i&&!d?Math.max(0,m):f[0].pts}if("aac"===e.segmentCodec)for(var p=this.config.maxAudioFramesDrift,k=0,T=g;k<f.length;k++){var E=f[k],S=E.pts,L=S-T,A=Math.abs(1e3*L/n);if(L<=-p*l&&d)0===k&&(K.warn("Audio frame @ ".concat((S/n).toFixed(3),"s overlaps nextAudioPts by ").concat(Math.round(1e3*L/n)," ms.")),this.nextAudioPts=g=T=S);else if(L>=p*l&&A<1e4&&d){var R=Math.round(L/l);(T=S-R*l)<0&&(R--,T+=l),0===k&&(this.nextAudioPts=g=T),K.warn("[mp4-remuxer]: Injecting ".concat(R," audio frame @ ").concat((T/n).toFixed(3),"s due to ").concat(Math.round(1e3*L/n)," ms gap."));for(var b=0;b<R;b++){var D=Math.max(T,0),I=_i.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);I||(K.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),I=E.unit.subarray()),f.splice(k,0,{unit:I,pts:D}),T+=l,k++}}E.pts=T,T+=l}for(var w,C=null,_=null,P=0,F=f.length;F--;)P+=f[F].unit.byteLength;for(var U=0,B=f.length;U<B;U++){var G=f[U],H=G.unit,V=G.pts;if(null!==_)h[U-1].duration=Math.round((V-_)/s);else{if(r&&"aac"===e.segmentCodec&&(V=g),C=V,!(P>0))return;P+=v;try{w=new Uint8Array(P)}catch(e){return void this.observer.emit(O.ERROR,O.ERROR,{type:M.MUX_ERROR,details:N.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:P,reason:"fail allocating audio mdat ".concat(P)})}c||(new DataView(w.buffer).setUint32(0,P),w.set(xi.types.mdat,4))}w.set(H,v);var Y=H.byteLength;v+=Y,h.push(new Vi(!0,o,Y,0)),_=V}var W=h.length;if(W){var j=h[h.length-1];this.nextAudioPts=g=_+s*j.duration;var q=c?new Uint8Array(0):xi.moof(e.sequenceNumber++,C/s,x({},e,{samples:h}));e.samples=[];var X=C/n,z=g/n,Q={data1:q,data2:w,startPTS:X,endPTS:z,startDTS:X,endDTS:z,type:"audio",hasAudio:!0,hasVideo:!1,nb:W};return this.isAudioContiguous=!0,Q}}},{key:"remuxEmptyAudio",value:function(e,t,r,i){var a=e.inputTimeScale,n=a/(e.samplerate?e.samplerate:a),s=this.nextAudioPts,o=this._initDTS,l=9e4*o.baseTime/o.timescale,u=(null!==s?s:i.startDTS*a)+l,c=i.endDTS*a+l,h=1024*n,d=Math.ceil((c-u)/h),f=_i.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(K.warn("[mp4-remuxer]: remux empty Audio"),f){for(var v=[],g=0;g<d;g++){var m=u+g*h;v.push({unit:f,pts:m,dts:m})}return e.samples=v,this.remuxAudio(e,t,r,!1)}K.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec")}}]),e}();function Bi(e,t){var r;if(null===t)return e;for(r=t<e?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=r;return e}function Gi(e,t,r,i){var a=e.samples.length;if(a){for(var n=e.inputTimeScale,s=0;s<a;s++){var o=e.samples[s];o.pts=Bi(o.pts-r.baseTime*n/r.timescale,t*n)/n,o.dts=Bi(o.dts-i.baseTime*n/i.timescale,t*n)/n}var l=e.samples;return e.samples=[],{samples:l}}}function Ki(e,t,r){var i=e.samples.length;if(i){for(var a=e.inputTimeScale,n=0;n<i;n++){var s=e.samples[n];s.pts=Bi(s.pts-r.baseTime*a/r.timescale,t*a)/a}e.samples.sort((function(e,t){return e.pts-t.pts}));var o=e.samples;return e.samples=[],{samples:o}}}var Hi,Vi=k((function e(t,r,i,a){y(this,e),this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=r,this.size=i,this.cts=a,this.flags=new Yi(t)})),Yi=k((function e(t){y(this,e),this.isLeading=0,this.isDependedOn=0,this.hasRedundancy=0,this.degradPrio=0,this.dependsOn=1,this.isNonSync=1,this.dependsOn=t?2:1,this.isNonSync=t?0:1})),Wi=function(){function e(){y(this,e),this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=null,this.initTracks=void 0,this.lastEndTime=null}return k(e,[{key:"destroy",value:function(){}},{key:"resetTimeStamp",value:function(e){this.initPTS=e,this.lastEndTime=null}},{key:"resetNextTimestamp",value:function(){this.lastEndTime=null}},{key:"resetInitSegment",value:function(e,t,r,i){this.audioCodec=t,this.videoCodec=r,this.generateInitSegment(function(e,t){if(!e||!t)return e;var r=t.keyId;return r&&t.isCommonEncryption&&Be(e,["moov","trak"]).forEach((function(e){var t=Be(e,["mdia","minf","stbl","stsd"])[0].subarray(8),i=Be(t,["enca"]),a=i.length>0;a||(i=Be(t,["encv"])),i.forEach((function(e){Be(a?e.subarray(28):e.subarray(78),["sinf"]).forEach((function(e){var t=He(e);if(t){var i=t.subarray(8,24);i.some((function(e){return 0!==e}))||(K.log("[eme] Patching keyId in 'enc".concat(a?"a":"v",">sinf>>tenc' box: ").concat(Ce(i)," -> ").concat(Ce(r))),t.set(r,8))}}))}))})),e}(e,i)),this.emitInitSegment=!0}},{key:"generateInitSegment",value:function(e){var t=this.audioCodec,r=this.videoCodec;if(null==e||!e.byteLength)return this.initTracks=void 0,void(this.initData=void 0);var i=this.initData=Ke(e);t||(t=ji(i.audio,X)),r||(r=ji(i.video,z));var a={};i.audio&&i.video?a.audiovideo={container:"video/mp4",codec:t+","+r,initSegment:e,id:"main"}:i.audio?a.audio={container:"audio/mp4",codec:t,initSegment:e,id:"audio"}:i.video?a.video={container:"video/mp4",codec:r,initSegment:e,id:"main"}:K.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=a}},{key:"remux",value:function(e,t,r,i,a,n){var s,o,l=this.initPTS,u=this.lastEndTime,c={audio:void 0,video:void 0,text:i,id3:r,initSegment:void 0};F(u)||(u=this.lastEndTime=a||0);var h=t.samples;if(null==h||!h.length)return c;var d={initPTS:void 0,timescale:1},f=this.initData;if(null!=(s=f)&&s.length||(this.generateInitSegment(h),f=this.initData),null==(o=f)||!o.length)return K.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),c;this.emitInitSegment&&(d.tracks=this.initTracks,this.emitInitSegment=!1);var v=function(e,t){for(var r=0,i=0,a=0,n=Be(e,["moof","traf"]),s=0;s<n.length;s++){var o=n[s],l=Be(o,["tfhd"])[0],u=t[Me(l,4)];if(u){var c=u.default,h=Me(l,0)|(null==c?void 0:c.flags),d=null==c?void 0:c.duration;8&h&&(d=Me(l,2&h?12:8));for(var f=u.timescale||9e4,v=Be(o,["trun"]),g=0;g<v.length;g++)!(r=Ve(v[g]))&&d&&(r=d*Me(v[g],4)),u.type===z?i+=r/f:u.type===X&&(a+=r/f)}}if(0===i&&0===a){for(var m=0,y=Be(e,["sidx"]),p=0;p<y.length;p++){var k=Ge(y[p]);null!=k&&k.references&&(m+=k.references.reduce((function(e,t){return e+t.info.duration||0}),0))}return m}return i||a}(h,f),g=function(e,t){return Be(t,["moof","traf"]).reduce((function(t,r){var i=Be(r,["tfdt"])[0],a=i[0],n=Be(r,["tfhd"]).reduce((function(t,r){var n=Me(r,4),s=e[n];if(s){var o=Me(i,4);if(1===a){if(o===_e)return K.warn("[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time"),t;o*=_e+1,o+=Me(i,8)}var l=o/(s.timescale||9e4);if(isFinite(l)&&(null===t||l<t))return l}return t}),null);return null!==n&&isFinite(n)&&(null===t||n<t)?n:t}),null)}(f,h),m=null===g?a:g;(function(e,t,r,i){if(null===e)return!0;var a=Math.max(i,1),n=t-e.baseTime/e.timescale;return Math.abs(n-r)>a}(l,m,a,v)||d.timescale!==l.timescale&&n)&&(d.initPTS=m-a,l&&1===l.timescale&&K.warn("Adjusting initPTS by ".concat(d.initPTS-l.baseTime)),this.initPTS=l={baseTime:d.initPTS,timescale:1});var y=e?m-l.baseTime/l.timescale:u,p=y+v;!function(e,t,r){Be(t,["moof","traf"]).forEach((function(t){Be(t,["tfhd"]).forEach((function(i){var a=Me(i,4),n=e[a];if(n){var s=n.timescale||9e4;Be(t,["tfdt"]).forEach((function(e){var t=e[0],i=Me(e,4);if(0===t)i-=r*s,Ue(e,4,i=Math.max(i,0));else{i*=Math.pow(2,32),i+=Me(e,8),i-=r*s,i=Math.max(i,0);var a=Math.floor(i/(_e+1)),n=Math.floor(i%(_e+1));Ue(e,4,a),Ue(e,8,n)}}))}}))}))}(f,h,l.baseTime/l.timescale),v>0?this.lastEndTime=p:(K.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var k=!!f.audio,T=!!f.video,E="";k&&(E+="audio"),T&&(E+="video");var S={data1:h,startPTS:y,startDTS:y,endPTS:p,endDTS:p,type:E,hasAudio:k,hasVideo:T,nb:1,dropped:0};return c.audio="audio"===S.type?S:void 0,c.video="audio"!==S.type?S:void 0,c.initSegment=d,c.id3=Gi(r,a,l,l),i.samples.length&&(c.text=Ki(i,a,l)),c}}]),e}();function ji(e,t){var r=null==e?void 0:e.codec;return r&&r.length>4?r:"hvc1"===r||"hev1"===r?"hvc1.1.6.L120.90":"av01"===r?"av01.0.04M.08":"avc1"===r||t===z?"avc1.42e01e":"mp4a.40.5"}try{Hi=self.performance.now.bind(self.performance)}catch(e){K.debug("Unable to use Performance API on this environment"),Hi="undefined"!=typeof self&&self.Date.now}var qi=[{demux:ui,remux:Wi},{demux:Li,remux:Ui},{demux:oi,remux:Ui},{demux:Ci,remux:Ui}],Xi=function(){function e(t,r,i,a,n){y(this,e),this.async=!1,this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=t,this.typeSupported=r,this.config=i,this.vendor=a,this.id=n}return k(e,[{key:"configure",value:function(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()}},{key:"push",value:function(e,t,r,i){var a=this,n=r.transmuxing;n.executeStart=Hi();var s=new Uint8Array(e),o=this.currentTransmuxState,l=this.transmuxConfig;i&&(this.currentTransmuxState=i);var u=i||o,c=u.contiguous,h=u.discontinuity,d=u.trackSwitch,f=u.accurateTimeOffset,v=u.timeOffset,g=u.initSegmentChange,m=l.audioCodec,y=l.videoCodec,p=l.defaultInitPts,k=l.duration,T=l.initSegmentData,E=function(e,t){var r=null;return e.byteLength>0&&null!=t&&null!=t.key&&null!==t.iv&&null!=t.method&&(r=t),r}(s,t);if(E&&"AES-128"===E.method){var S=this.getDecrypter();if(!S.isSync())return this.decryptionPromise=S.webCryptoDecrypt(s,E.key.buffer,E.iv.buffer).then((function(e){var t=a.push(e,null,r);return a.decryptionPromise=null,t})),this.decryptionPromise;var L=S.softwareDecrypt(s,E.key.buffer,E.iv.buffer);if(r.part>-1&&(L=S.flush()),!L)return n.executeEnd=Hi(),zi(r);s=new Uint8Array(L)}var A=this.needsProbing(h,d);if(A){var R=this.configureTransmuxer(s);if(R)return K.warn("[transmuxer] ".concat(R.message)),this.observer.emit(O.ERROR,O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_PARSING_ERROR,fatal:!1,error:R,reason:R.message}),n.executeEnd=Hi(),zi(r)}(h||d||g||A)&&this.resetInitSegment(T,m,y,k,t),(h||g||A)&&this.resetInitialTimestamp(p),c||this.resetContiguity();var b=this.transmux(s,E,v,f,r),D=this.currentTransmuxState;return D.contiguous=!0,D.discontinuity=!1,D.trackSwitch=!1,n.executeEnd=Hi(),b}},{key:"flush",value:function(e){var t=this,r=e.transmuxing;r.executeStart=Hi();var i=this.decrypter,a=this.currentTransmuxState,n=this.decryptionPromise;if(n)return n.then((function(){return t.flush(e)}));var s=[],o=a.timeOffset;if(i){var l=i.flush();l&&s.push(this.push(l,null,e))}var u=this.demuxer,c=this.remuxer;if(!u||!c)return r.executeEnd=Hi(),[zi(e)];var h=u.flush(o);return Qi(h)?h.then((function(r){return t.flushRemux(s,r,e),s})):(this.flushRemux(s,h,e),s)}},{key:"flushRemux",value:function(e,t,r){var i=t.audioTrack,a=t.videoTrack,n=t.id3Track,s=t.textTrack,o=this.currentTransmuxState,l=o.accurateTimeOffset,u=o.timeOffset;K.log("[transmuxer.ts]: Flushed fragment ".concat(r.sn).concat(r.part>-1?" p: "+r.part:""," of level ").concat(r.level));var c=this.remuxer.remux(i,a,n,s,u,l,!0,this.id);e.push({remuxResult:c,chunkMeta:r}),r.transmuxing.executeEnd=Hi()}},{key:"resetInitialTimestamp",value:function(e){var t=this.demuxer,r=this.remuxer;t&&r&&(t.resetTimeStamp(e),r.resetTimeStamp(e))}},{key:"resetContiguity",value:function(){var e=this.demuxer,t=this.remuxer;e&&t&&(e.resetContiguity(),t.resetNextTimestamp())}},{key:"resetInitSegment",value:function(e,t,r,i,a){var n=this.demuxer,s=this.remuxer;n&&s&&(n.resetInitSegment(e,t,r,i),s.resetInitSegment(e,t,r,a))}},{key:"destroy",value:function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)}},{key:"transmux",value:function(e,t,r,i,a){return t&&"SAMPLE-AES"===t.method?this.transmuxSampleAes(e,t,r,i,a):this.transmuxUnencrypted(e,r,i,a)}},{key:"transmuxUnencrypted",value:function(e,t,r,i){var a=this.demuxer.demux(e,t,!1,!this.config.progressive),n=a.audioTrack,s=a.videoTrack,o=a.id3Track,l=a.textTrack;return{remuxResult:this.remuxer.remux(n,s,o,l,t,r,!1,this.id),chunkMeta:i}}},{key:"transmuxSampleAes",value:function(e,t,r,i,a){var n=this;return this.demuxer.demuxSampleAes(e,t,r).then((function(e){return{remuxResult:n.remuxer.remux(e.audioTrack,e.videoTrack,e.id3Track,e.textTrack,r,i,!1,n.id),chunkMeta:a}}))}},{key:"configureTransmuxer",value:function(e){for(var t,r=this.config,i=this.observer,a=this.typeSupported,n=this.vendor,s=0,o=qi.length;s<o;s++)if(qi[s].demux.probe(e)){t=qi[s];break}if(!t)return new Error("Failed to find demuxer by probing fragment data");var l=this.demuxer,u=this.remuxer,c=t.remux,h=t.demux;u&&u instanceof c||(this.remuxer=new c(i,r,a,n)),l&&l instanceof h||(this.demuxer=new h(i,r,a),this.probe=h.probe)}},{key:"needsProbing",value:function(e,t){return!this.demuxer||!this.remuxer||e||t}},{key:"getDecrypter",value:function(){var e=this.decrypter;return e||(e=this.decrypter=new Or(this.config)),e}}]),e}(),zi=function(e){return{remuxResult:{},chunkMeta:e}};function Qi(e){return"then"in e&&e.then instanceof Function}var $i=k((function e(t,r,i,a,n){y(this,e),this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=t,this.videoCodec=r,this.initSegmentData=i,this.duration=a,this.defaultInitPts=n||null})),Ji=k((function e(t,r,i,a,n,s){y(this,e),this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=t,this.contiguous=r,this.accurateTimeOffset=i,this.trackSwitch=a,this.timeOffset=n,this.initSegmentChange=s})),Zi={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,r="~";function i(){}function a(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function n(e,t,i,n,s){if("function"!=typeof i)throw new TypeError("The listener must be a function");var o=new a(i,n||e,s),l=r?r+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],o]:e._events[l].push(o):(e._events[l]=o,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new i:delete e._events[t]}function o(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(r=!1)),o.prototype.eventNames=function(){var e,i,a=[];if(0===this._eventsCount)return a;for(i in e=this._events)t.call(e,i)&&a.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?a.concat(Object.getOwnPropertySymbols(e)):a},o.prototype.listeners=function(e){var t=r?r+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var a=0,n=i.length,s=new Array(n);a<n;a++)s[a]=i[a].fn;return s},o.prototype.listenerCount=function(e){var t=r?r+e:e,i=this._events[t];return i?i.fn?1:i.length:0},o.prototype.emit=function(e,t,i,a,n,s){var o=r?r+e:e;if(!this._events[o])return!1;var l,u,c=this._events[o],h=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),h){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,i),!0;case 4:return c.fn.call(c.context,t,i,a),!0;case 5:return c.fn.call(c.context,t,i,a,n),!0;case 6:return c.fn.call(c.context,t,i,a,n,s),!0}for(u=1,l=new Array(h-1);u<h;u++)l[u-1]=arguments[u];c.fn.apply(c.context,l)}else{var d,f=c.length;for(u=0;u<f;u++)switch(c[u].once&&this.removeListener(e,c[u].fn,void 0,!0),h){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,t);break;case 3:c[u].fn.call(c[u].context,t,i);break;case 4:c[u].fn.call(c[u].context,t,i,a);break;default:if(!l)for(d=1,l=new Array(h-1);d<h;d++)l[d-1]=arguments[d];c[u].fn.apply(c[u].context,l)}}return!0},o.prototype.on=function(e,t,r){return n(this,e,t,r,!1)},o.prototype.once=function(e,t,r){return n(this,e,t,r,!0)},o.prototype.removeListener=function(e,t,i,a){var n=r?r+e:e;if(!this._events[n])return this;if(!t)return s(this,n),this;var o=this._events[n];if(o.fn)o.fn!==t||a&&!o.once||i&&o.context!==i||s(this,n);else{for(var l=0,u=[],c=o.length;l<c;l++)(o[l].fn!==t||a&&!o[l].once||i&&o[l].context!==i)&&u.push(o[l]);u.length?this._events[n]=1===u.length?u[0]:u:s(this,n)}return this},o.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=r,o.EventEmitter=o,e.exports=o}(Zi);var ea=S(Zi.exports),ta=it()||{isTypeSupported:function(){return!1}},ra=function(){function e(t,r,i,a){var n=this;y(this,e),this.error=null,this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.useWorker=void 0,this.workerContext=null,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0;var s=t.config;this.hls=t,this.id=r,this.useWorker=!!s.enableWorker,this.onTransmuxComplete=i,this.onFlush=a;var o=function(e,t){(t=t||{}).frag=n.frag,t.id=n.id,e===O.ERROR&&(n.error=t.error),n.hls.trigger(e,t)};this.observer=new ea,this.observer.on(O.FRAG_DECRYPTED,o),this.observer.on(O.ERROR,o);var l,u,c,h,d={mp4:ta.isTypeSupported("video/mp4"),mpeg:ta.isTypeSupported("audio/mpeg"),mp3:ta.isTypeSupported('audio/mp4; codecs="mp3"')},f=navigator.vendor;if(!this.useWorker||"undefined"==typeof Worker||!s.workerPath&&"function"!=typeof __HLS_WORKER_BUNDLE__)this.transmuxer=new Xi(this.observer,d,s,f,r);else try{s.workerPath?(K.log("loading Web Worker ".concat(s.workerPath,' for "').concat(r,'"')),this.workerContext=(c=s.workerPath,h=new self.URL(c,self.location.href).href,{worker:new self.Worker(h),scriptURL:h})):(K.log('injecting Web Worker for "'.concat(r,'"')),this.workerContext=(l=new self.Blob(["var exports={};var module={exports:exports};function define(f){f()};define.amd=true;(".concat(__HLS_WORKER_BUNDLE__.toString(),")(true);")],{type:"text/javascript"}),u=self.URL.createObjectURL(l),{worker:new self.Worker(u),objectURL:u})),this.onwmsg=function(e){return n.onWorkerMessage(e)};var v=this.workerContext.worker;v.addEventListener("message",this.onwmsg),v.onerror=function(e){var t=new Error("".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")"));s.enableWorker=!1,K.warn('Error in "'.concat(r,'" Web Worker, fallback to inline')),n.hls.trigger(O.ERROR,{type:M.OTHER_ERROR,details:N.INTERNAL_EXCEPTION,fatal:!1,event:"demuxerWorker",error:t})},v.postMessage({cmd:"init",typeSupported:d,vendor:f,id:r,config:JSON.stringify(s)})}catch(e){K.warn('Error setting up "'.concat(r,'" Web Worker, fallback to inline'),e),this.resetWorker(),this.error=null,this.transmuxer=new Xi(this.observer,d,s,f,r)}}return k(e,[{key:"resetWorker",value:function(){if(this.workerContext){var e=this.workerContext,t=e.worker,r=e.objectURL;r&&self.URL.revokeObjectURL(r),t.removeEventListener("message",this.onwmsg),t.onerror=null,t.terminate(),this.workerContext=null}}},{key:"destroy",value:function(){if(this.workerContext)this.resetWorker(),this.onwmsg=void 0;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var t=this.observer;t&&t.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null}},{key:"push",value:function(e,t,r,i,a,n,s,o,l,u){var c,h,d=this;l.transmuxing.start=self.performance.now();var f=this.transmuxer,v=n?n.start:a.start,g=a.decryptdata,m=this.frag,y=!(m&&a.cc===m.cc),p=!(m&&l.level===m.level),k=m?l.sn-m.sn:-1,T=this.part?l.part-this.part.index:-1,E=0===k&&l.id>1&&l.id===(null==m?void 0:m.stats.chunkCount),S=!p&&(1===k||0===k&&(1===T||E&&T<=0)),L=self.performance.now();(p||k||0===a.stats.parsing.start)&&(a.stats.parsing.start=L),!n||!T&&S||(n.stats.parsing.start=L);var A=!(m&&(null==(c=a.initSegment)?void 0:c.url)===(null==(h=m.initSegment)?void 0:h.url)),R=new Ji(y,S,o,p,v,A);if(!S||y||A){K.log("[transmuxer-interface, ".concat(a.type,"]: Starting new transmux session for sn: ").concat(l.sn," p: ").concat(l.part," level: ").concat(l.level," id: ").concat(l.id,"\n discontinuity: ").concat(y,"\n trackSwitch: ").concat(p,"\n contiguous: ").concat(S,"\n accurateTimeOffset: ").concat(o,"\n timeOffset: ").concat(v,"\n initSegmentChange: ").concat(A));var b=new $i(r,i,t,s,u);this.configureTransmuxer(b)}if(this.frag=a,this.part=n,this.workerContext)this.workerContext.worker.postMessage({cmd:"demux",data:e,decryptdata:g,chunkMeta:l,state:R},e instanceof ArrayBuffer?[e]:[]);else if(f){var D=f.push(e,g,l,R);Qi(D)?(f.async=!0,D.then((function(e){d.handleTransmuxComplete(e)})).catch((function(e){d.transmuxerError(e,l,"transmuxer-interface push error")}))):(f.async=!1,this.handleTransmuxComplete(D))}}},{key:"flush",value:function(e){var t=this;e.transmuxing.start=self.performance.now();var r=this.transmuxer;if(this.workerContext)this.workerContext.worker.postMessage({cmd:"flush",chunkMeta:e});else if(r){var i=r.flush(e);Qi(i)||r.async?(Qi(i)||(i=Promise.resolve(i)),i.then((function(r){t.handleFlushResult(r,e)})).catch((function(r){t.transmuxerError(r,e,"transmuxer-interface flush error")}))):this.handleFlushResult(i,e)}}},{key:"transmuxerError",value:function(e,t,r){this.hls&&(this.error=e,this.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_PARSING_ERROR,chunkMeta:t,fatal:!1,error:e,err:e,reason:r}))}},{key:"handleFlushResult",value:function(e,t){var r=this;e.forEach((function(e){r.handleTransmuxComplete(e)})),this.onFlush(t)}},{key:"onWorkerMessage",value:function(e){var t=e.data,r=this.hls;switch(t.event){case"init":var i,a=null==(i=this.workerContext)?void 0:i.objectURL;a&&self.URL.revokeObjectURL(a);break;case"transmuxComplete":this.handleTransmuxComplete(t.data);break;case"flush":this.onFlush(t.data);break;case"workerLog":K[t.data.logType]&&K[t.data.logType](t.data.message);break;default:t.data=t.data||{},t.data.frag=this.frag,t.data.id=this.id,r.trigger(t.event,t.data)}}},{key:"configureTransmuxer",value:function(e){var t=this.transmuxer;this.workerContext?this.workerContext.worker.postMessage({cmd:"configure",config:e}):t&&t.configure(e)}},{key:"handleTransmuxComplete",value:function(e){e.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(e)}}]),e}(),ia=function(){function e(t,r,i,a){y(this,e),this.config=void 0,this.media=null,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=t,this.media=r,this.fragmentTracker=i,this.hls=a}return k(e,[{key:"destroy",value:function(){this.media=null,this.hls=this.fragmentTracker=null}},{key:"poll",value:function(e,t){var r=this.config,i=this.media,a=this.stalled;if(null!==i){var n=i.currentTime,s=i.seeking,o=this.seeking&&!s,l=!this.seeking&&s;if(this.seeking=s,n===e){if(l||o)this.stalled=null;else if(!(i.paused&&!s||i.ended||0===i.playbackRate)&&br.getBuffered(i).length){var u=br.bufferInfo(i,n,0),c=u.len>0,h=u.nextStart||0;if(c||h){if(s){var d=u.len>2,f=!h||t&&t.start<=n||h-n>2&&!this.fragmentTracker.getPartialFragment(n);if(d||f)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var v,g=Math.max(h,u.start||0)-n,m=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,y=(null==m||null==(v=m.details)?void 0:v.live)?2*m.details.targetduration:2,p=this.fragmentTracker.getPartialFragment(n);if(g>0&&(g<=y||p))return void this._trySkipBufferHole(p)}var k=self.performance.now();if(null!==a){var T=k-a;if(s||!(T>=250)||(this._reportStall(u),this.media)){var E=br.bufferInfo(i,n,r.maxBufferHole);this._tryFixBufferStall(E,T)}}else this.stalled=k}}}else if(this.moved=!0,null!==a){if(this.stallReported){var S=self.performance.now()-a;K.warn("playback not stuck anymore @".concat(n,", after ").concat(Math.round(S),"ms")),this.stallReported=!1}this.stalled=null,this.nudgeRetry=0}}}},{key:"_tryFixBufferStall",value:function(e,t){var r=this.config,i=this.fragmentTracker,a=this.media;if(null!==a){var n=a.currentTime,s=i.getPartialFragment(n);if(s&&(this._trySkipBufferHole(s)||!this.media))return;(e.len>r.maxBufferHole||e.nextStart&&e.nextStart-n<r.maxBufferHole)&&t>1e3*r.highBufferWatchdogPeriod&&(K.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}}},{key:"_reportStall",value:function(e){var t=this.hls,r=this.media;if(!this.stallReported&&r){this.stallReported=!0;var i=new Error("Playback stalling at @".concat(r.currentTime," due to low buffer (").concat(JSON.stringify(e),")"));K.warn(i.message),t.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_STALLED_ERROR,fatal:!1,error:i,buffer:e.len})}}},{key:"_trySkipBufferHole",value:function(e){var t=this.config,r=this.hls,i=this.media;if(null===i)return 0;var a=i.currentTime,n=br.bufferInfo(i,a,0),s=a<n.start?n.start:n.nextStart;if(s){var o=n.len<=t.maxBufferHole,l=n.len>0&&n.len<1&&i.readyState<3,u=s-a;if(u>0&&(o||l)){if(u>t.maxBufferHole){var c=this.fragmentTracker,h=!1;if(0===a){var d=c.getAppendedFrag(0,At);d&&s<d.end&&(h=!0)}if(!h){var f=e||c.getAppendedFrag(a,At);if(f){for(var v=!1,g=f.end;g<s;){var m=c.getPartialFragment(g);if(!m){v=!0;break}g+=m.duration}if(v)return 0}}}var y=Math.max(s+.05,a+.1);if(K.warn("skipping hole, adjusting currentTime from ".concat(a," to ").concat(y)),this.moved=!0,this.stalled=null,i.currentTime=y,e&&!e.gap){var p=new Error("fragment loaded with buffer holes, seeking from ".concat(a," to ").concat(y));r.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_SEEK_OVER_HOLE,fatal:!1,error:p,reason:p.message,frag:e})}return y}}return 0}},{key:"_tryNudgeBuffer",value:function(){var e=this.config,t=this.hls,r=this.media,i=this.nudgeRetry;if(null!==r){var a=r.currentTime;if(this.nudgeRetry++,i<e.nudgeMaxRetry){var n=a+(i+1)*e.nudgeOffset,s=new Error("Nudging 'currentTime' from ".concat(a," to ").concat(n));K.warn(s.message),r.currentTime=n,t.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_NUDGE_ON_STALL,error:s,fatal:!1})}else{var o=new Error("Playhead still not moving while enough data buffered @".concat(a," after ").concat(e.nudgeMaxRetry," nudges"));K.error(o.message),t.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_STALLED_ERROR,error:o,fatal:!0})}}}}]),e}(),aa=function(e){c(r,e);var t=d(r);function r(e,i,a){var n;return y(this,r),(n=t.call(this,e,i,a,"[stream-controller]",At)).audioCodecSwap=!1,n.gapController=null,n.level=-1,n._forceStartLoad=!1,n.altAudio=!1,n.audioOnly=!1,n.fragPlaying=null,n.onvplaying=null,n.onvseeked=null,n.fragLastKbps=0,n.couldBacktrack=!1,n.backtrackFragment=null,n.audioCodecSwitch=!1,n.videoBuffer=null,n._registerListeners(),n}return k(r,[{key:"_registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.MANIFEST_PARSED,this.onManifestParsed,this),e.on(O.LEVEL_LOADING,this.onLevelLoading,this),e.on(O.LEVEL_LOADED,this.onLevelLoaded,this),e.on(O.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.on(O.ERROR,this.onError,this),e.on(O.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(O.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.on(O.BUFFER_CREATED,this.onBufferCreated,this),e.on(O.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(O.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(O.FRAG_BUFFERED,this.onFragBuffered,this)}},{key:"_unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_PARSED,this.onManifestParsed,this),e.off(O.LEVEL_LOADED,this.onLevelLoaded,this),e.off(O.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.off(O.ERROR,this.onError,this),e.off(O.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(O.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.off(O.BUFFER_CREATED,this.onBufferCreated,this),e.off(O.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(O.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(O.FRAG_BUFFERED,this.onFragBuffered,this)}},{key:"onHandlerDestroying",value:function(){this._unregisterListeners(),this.onMediaDetaching()}},{key:"startLoad",value:function(e){if(this.levels){var t=this.lastCurrentTime,r=this.hls;if(this.stopLoad(),this.setInterval(100),this.level=-1,!this.startFragRequested){var i=r.startLevel;-1===i&&(r.config.testBandwidth&&this.levels.length>1?(i=0,this.bitrateTest=!0):i=r.nextAutoLevel),this.level=r.nextLoadLevel=i,this.loadedmetadata=!1}t>0&&-1===e&&(this.log("Override startPosition with lastCurrentTime @".concat(t.toFixed(3))),e=t),this.state=Nr,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}else this._forceStartLoad=!0,this.state=Mr}},{key:"stopLoad",value:function(){this._forceStartLoad=!1,u(g(r.prototype),"stopLoad",this).call(this)}},{key:"doTick",value:function(){switch(this.state){case qr:var e,t=this.levels,r=this.level,i=null==t||null==(e=t[r])?void 0:e.details;if(i&&(!i.live||this.levelLastLoaded===this.level)){if(this.waitForCdnTuneIn(i))break;this.state=Nr;break}if(this.hls.nextLoadLevel!==this.level){this.state=Nr;break}break;case Gr:var a,n=self.performance.now(),s=this.retryDate;(!s||n>=s||null!=(a=this.media)&&a.seeking)&&(this.resetStartWhenNotLoaded(this.level),this.state=Nr)}this.state===Nr&&this.doTickIdle(),this.onTickEnd()}},{key:"onTickEnd",value:function(){u(g(r.prototype),"onTickEnd",this).call(this),this.checkBuffer(),this.checkFragmentChanged()}},{key:"doTickIdle",value:function(){var e=this.hls,t=this.levelLastLoaded,r=this.levels,i=this.media,a=e.config,n=e.nextLoadLevel;if(null!==t&&(i||!this.startFragRequested&&a.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)&&null!=r&&r[n]){var s=r[n],o=this.getMainFwdBufferInfo();if(null!==o){var l=this.getLevelDetails();if(l&&this._streamEnded(o,l)){var u={};return this.altAudio&&(u.type="video"),this.hls.trigger(O.BUFFER_EOS,u),void(this.state=Yr)}e.loadLevel!==n&&-1===e.manualLevel&&this.log("Adapting to level ".concat(n," from level ").concat(this.level)),this.level=e.nextLoadLevel=n;var c=s.details;if(!c||this.state===qr||c.live&&this.levelLastLoaded!==n)return this.level=n,void(this.state=qr);var h=o.len,d=this.getMaxBufferLength(s.maxBitrate);if(!(h>=d)){this.backtrackFragment&&this.backtrackFragment.start>o.end&&(this.backtrackFragment=null);var f=this.backtrackFragment?this.backtrackFragment.start:o.end,v=this.getNextFragment(f,c);if(this.couldBacktrack&&!this.fragPrevious&&v&&"initSegment"!==v.sn&&this.fragmentTracker.getState(v)!==vr){var g,m=(null!=(g=this.backtrackFragment)?g:v).sn-c.startSN,y=c.fragments[m-1];y&&v.cc===y.cc&&(v=y,this.fragmentTracker.removeFragment(y))}else this.backtrackFragment&&o.len&&(this.backtrackFragment=null);if(v&&this.isLoopLoading(v,f)){if(!v.gap){var p=this.audioOnly&&!this.altAudio?X:z,k=(p===z?this.videoBuffer:this.mediaBuffer)||this.media;k&&this.afterBufferFlushed(k,p,At)}v=this.getNextFragmentLoopLoading(v,c,o,At,d)}v&&(!v.initSegment||v.initSegment.data||this.bitrateTest||(v=v.initSegment),this.loadFragment(v,s,f))}}}}},{key:"loadFragment",value:function(e,t,i){var a=this.fragmentTracker.getState(e);this.fragCurrent=e,a===hr||a===fr?"initSegment"===e.sn?this._loadInitSegment(e,t):this.bitrateTest?(this.log("Fragment ".concat(e.sn," of level ").concat(e.level," is being downloaded to test bitrate and will not be buffered")),this._loadBitrateTestFrag(e,t)):(this.startFragRequested=!0,u(g(r.prototype),"loadFragment",this).call(this,e,t,i)):this.clearTrackerIfNeeded(e)}},{key:"getBufferedFrag",value:function(e){return this.fragmentTracker.getBufferedFrag(e,At)}},{key:"followingBufferedFrag",value:function(e){return e?this.getBufferedFrag(e.end+.5):null}},{key:"immediateLevelSwitch",value:function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)}},{key:"nextLevelSwitch",value:function(){var e=this.levels,t=this.media;if(null!=t&&t.readyState){var r,i=this.getAppendedFrag(t.currentTime);i&&i.start>1&&this.flushMainBuffer(0,i.start-1);var a=this.getLevelDetails();if(null!=a&&a.live){var n=this.getMainFwdBufferInfo();if(!n||n.len<2*a.targetduration)return}if(!t.paused&&e){var s=e[this.hls.nextLoadLevel],o=this.fragLastKbps;r=o&&this.fragCurrent?this.fragCurrent.duration*s.maxBitrate/(1e3*o)+1:0}else r=0;var l=this.getBufferedFrag(t.currentTime+r);if(l){var u=this.followingBufferedFrag(l);if(u){this.abortCurrentFrag();var c=u.maxStartPTS?u.maxStartPTS:u.start,h=u.duration,d=Math.max(l.end,c+Math.min(Math.max(h-this.config.maxFragLookUpTolerance,.5*h),.75*h));this.flushMainBuffer(d,Number.POSITIVE_INFINITY)}}}}},{key:"abortCurrentFrag",value:function(){var e=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,e&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.state){case Ur:case Br:case Gr:case Hr:case Vr:this.state=Nr}this.nextLoadPosition=this.getLoadPosition()}},{key:"flushMainBuffer",value:function(e,t){u(g(r.prototype),"flushMainBuffer",this).call(this,e,t,this.altAudio?"video":null)}},{key:"onMediaAttached",value:function(e,t){u(g(r.prototype),"onMediaAttached",this).call(this,e,t);var i=t.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),i.addEventListener("playing",this.onvplaying),i.addEventListener("seeked",this.onvseeked),this.gapController=new ia(this.config,i,this.fragmentTracker,this.hls)}},{key:"onMediaDetaching",value:function(){var e=this.media;e&&this.onvplaying&&this.onvseeked&&(e.removeEventListener("playing",this.onvplaying),e.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),u(g(r.prototype),"onMediaDetaching",this).call(this)}},{key:"onMediaPlaying",value:function(){this.tick()}},{key:"onMediaSeeked",value:function(){var e=this.media,t=e?e.currentTime:null;F(t)&&this.log("Media seeked to ".concat(t.toFixed(3)));var r=this.getMainFwdBufferInfo();null!==r&&0!==r.len?this.tick():this.warn('Main forward buffer length on "seeked" event '.concat(r?r.len:"empty",")"))}},{key:"onManifestLoading",value:function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(O.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=0,this.levels=this.fragPlaying=this.backtrackFragment=null,this.altAudio=this.audioOnly=!1}},{key:"onManifestParsed",value:function(e,t){var r,i,a,n=!1,s=!1;t.levels.forEach((function(e){(r=e.audioCodec)&&(-1!==r.indexOf("mp4a.40.2")&&(n=!0),-1!==r.indexOf("mp4a.40.5")&&(s=!0))})),this.audioCodecSwitch=n&&s&&!("function"==typeof(null==(a=zr())||null==(i=a.prototype)?void 0:i.changeType)),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=t.levels,this.startFragRequested=!1}},{key:"onLevelLoading",value:function(e,t){var r=this.levels;if(r&&this.state===Nr){var i=r[t.level];(!i.details||i.details.live&&this.levelLastLoaded!==t.level||this.waitForCdnTuneIn(i.details))&&(this.state=qr)}}},{key:"onLevelLoaded",value:function(e,t){var r,i=this.levels,a=t.level,n=t.details,s=n.totalduration;if(i){this.log("Level ".concat(a," loaded [").concat(n.startSN,",").concat(n.endSN,"]").concat(n.lastPartSn?"[part-".concat(n.lastPartSn,"-").concat(n.lastPartIndex,"]"):"",", cc [").concat(n.startCC,", ").concat(n.endCC,"] duration:").concat(s));var o=i[a],l=this.fragCurrent;!l||this.state!==Br&&this.state!==Gr||l.level===t.level&&l.urlId===o.urlId||!l.loader||this.abortCurrentFrag();var u=0;if(n.live||null!=(r=o.details)&&r.live){if(this.checkLiveUpdate(n),n.deltaUpdateFailed)return;u=this.alignPlaylists(n,o.details)}if(o.details=n,this.levelLastLoaded=a,this.hls.trigger(O.LEVEL_UPDATED,{details:n,level:a}),this.state===qr){if(this.waitForCdnTuneIn(n))return;this.state=Nr}this.startFragRequested?n.live&&this.synchronizeToLiveEdge(n):this.setStartPosition(n,u),this.tick()}else this.warn("Levels were reset while loading level ".concat(a))}},{key:"_handleFragmentLoadProgress",value:function(e){var t,r=e.frag,i=e.part,a=e.payload,n=this.levels;if(n){var s=n[r.level],o=s.details;if(!o)return this.warn("Dropping fragment ".concat(r.sn," of level ").concat(r.level," after level details were reset")),void this.fragmentTracker.removeFragment(r);var l=s.videoCodec,u=o.PTSKnown||!o.live,c=null==(t=r.initSegment)?void 0:t.data,h=this._getAudioCodec(s),d=this.transmuxer=this.transmuxer||new ra(this.hls,At,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),f=i?i.index:-1,v=-1!==f,g=new Dr(r.level,r.sn,r.stats.chunkCount,a.byteLength,f,v),m=this.initPTS[r.cc];d.push(a,c,h,l,r,i,o.totalduration,u,g,m)}else this.warn("Levels were reset while fragment load was in progress. Fragment ".concat(r.sn," of level ").concat(r.level," will not be buffered"))}},{key:"onAudioTrackSwitching",value:function(e,t){var r=this.altAudio;if(!t.url){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var i=this.fragCurrent;i&&(this.log("Switching to main audio track, cancel main fragment load"),i.abortRequests(),this.fragmentTracker.removeFragment(i)),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var a=this.hls;r&&(a.trigger(O.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),a.trigger(O.AUDIO_TRACK_SWITCHED,t)}}},{key:"onAudioTrackSwitched",value:function(e,t){var r=t.id,i=!!this.hls.audioTracks[r].url;if(i){var a=this.videoBuffer;a&&this.mediaBuffer!==a&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=a)}this.altAudio=i,this.tick()}},{key:"onBufferCreated",value:function(e,t){var r,i,a=t.tracks,n=!1;for(var s in a){var o=a[s];if("main"===o.id){if(i=s,r=o,"video"===s){var l=a[s];l&&(this.videoBuffer=l.buffer)}}else n=!0}n&&r?(this.log("Alternate track found, use ".concat(i,".buffered to schedule main fragment loading")),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media}},{key:"onFragBuffered",value:function(e,t){var r=t.frag,i=t.part;if(!r||r.type===At){if(this.fragContextChanged(r))return this.warn("Fragment ".concat(r.sn).concat(i?" p: "+i.index:""," of level ").concat(r.level," finished buffering, but was aborted. state: ").concat(this.state)),void(this.state===Vr&&(this.state=Nr));var a=i?i.stats:r.stats;this.fragLastKbps=Math.round(8*a.total/(a.buffering.end-a.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,i)}}},{key:"onError",value:function(e,t){var r;if(t.fatal)this.state=Wr;else switch(t.details){case N.FRAG_GAP:case N.FRAG_PARSING_ERROR:case N.FRAG_DECRYPT_ERROR:case N.FRAG_LOAD_ERROR:case N.FRAG_LOAD_TIMEOUT:case N.KEY_LOAD_ERROR:case N.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(At,t);break;case N.LEVEL_LOAD_ERROR:case N.LEVEL_LOAD_TIMEOUT:case N.LEVEL_PARSING_ERROR:t.levelRetry||this.state!==qr||(null==(r=t.context)?void 0:r.type)!==Et||(this.state=Nr);break;case N.BUFFER_FULL_ERROR:if(!t.parent||"main"!==t.parent)return;this.reduceLengthAndFlushBuffer(t)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case N.INTERNAL_EXCEPTION:this.recoverWorkerError(t)}}},{key:"checkBuffer",value:function(){var e=this.media,t=this.gapController;if(e&&t&&e.readyState){if(this.loadedmetadata||!br.getBuffered(e).length){var r=this.state!==Nr?this.fragCurrent:null;t.poll(this.lastCurrentTime,r)}this.lastCurrentTime=e.currentTime}}},{key:"onFragLoadEmergencyAborted",value:function(){this.state=Nr,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()}},{key:"onBufferFlushed",value:function(e,t){var r=t.type;if(r!==X||this.audioOnly&&!this.altAudio){var i=(r===z?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(i,r,At)}}},{key:"onLevelsUpdated",value:function(e,t){this.levels=t.levels}},{key:"swapAudioCodec",value:function(){this.audioCodecSwap=!this.audioCodecSwap}},{key:"seekToStartPos",value:function(){var e=this.media;if(e){var t=e.currentTime,r=this.startPosition;if(r>=0&&t<r){if(e.seeking)return void this.log("could not seek to ".concat(r,", already seeking at ").concat(t));var i=br.getBuffered(e),a=(i.length?i.start(0):0)-r;a>0&&(a<this.config.maxBufferHole||a<this.config.maxFragLookUpTolerance)&&(this.log("adjusting start position by ".concat(a," to match buffer start")),r+=a,this.startPosition=r),this.log("seek to target start position ".concat(r," from current time ").concat(t)),e.currentTime=r}}}},{key:"_getAudioCodec",value:function(e){var t=this.config.defaultAudioCodec||e.audioCodec;return this.audioCodecSwap&&t&&(this.log("Swapping audio codec"),t=-1!==t.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),t}},{key:"_loadBitrateTestFrag",value:function(e,t){var r=this;e.bitrateTest=!0,this._doFragLoad(e,t).then((function(i){var a=r.hls;if(i&&!r.fragContextChanged(e)){t.fragmentError=0,r.state=Nr,r.startFragRequested=!1,r.bitrateTest=!1;var n=e.stats;n.parsing.start=n.parsing.end=n.buffering.start=n.buffering.end=self.performance.now(),a.trigger(O.FRAG_LOADED,i),e.bitrateTest=!1}}))}},{key:"_handleTransmuxComplete",value:function(e){var t,r="main",i=this.hls,a=e.remuxResult,n=e.chunkMeta,s=this.getCurrentContext(n);if(s){var o=s.frag,l=s.part,u=s.level,c=a.video,h=a.text,d=a.id3,f=a.initSegment,v=u.details,g=this.altAudio?void 0:a.audio;if(this.fragContextChanged(o))this.fragmentTracker.removeFragment(o);else{if(this.state=Hr,f){if(null!=f&&f.tracks){var m=o.initSegment||o;this._bufferInitSegment(u,f.tracks,m,n),i.trigger(O.FRAG_PARSING_INIT_SEGMENT,{frag:m,id:r,tracks:f.tracks})}var y=f.initPTS,p=f.timescale;F(y)&&(this.initPTS[o.cc]={baseTime:y,timescale:p},i.trigger(O.INIT_PTS_FOUND,{frag:o,id:r,initPTS:y,timescale:p}))}if(c&&v&&"initSegment"!==o.sn){var k=v.fragments[o.sn-1-v.startSN],T=o.sn===v.startSN,E=!k||o.cc>k.cc;if(!1!==a.independent){var S=c.startPTS,L=c.endPTS,A=c.startDTS,R=c.endDTS;if(l)l.elementaryStreams[c.type]={startPTS:S,endPTS:L,startDTS:A,endDTS:R};else if(c.firstKeyFrame&&c.independent&&1===n.id&&!E&&(this.couldBacktrack=!0),c.dropped&&c.independent){var b=this.getMainFwdBufferInfo(),D=(b?b.end:this.getLoadPosition())+this.config.maxBufferHole,I=c.firstKeyFramePTS?c.firstKeyFramePTS:S;if(!T&&D<I-this.config.maxBufferHole&&!E)return void this.backtrack(o);E&&(o.gap=!0),o.setElementaryStreamInfo(c.type,o.start,L,o.start,R,!0)}o.setElementaryStreamInfo(c.type,S,L,A,R),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(c,o,l,n,T||E)}else{if(!T&&!E)return void this.backtrack(o);o.gap=!0}}if(g){var w=g.startPTS,C=g.endPTS,_=g.startDTS,P=g.endDTS;l&&(l.elementaryStreams[X]={startPTS:w,endPTS:C,startDTS:_,endDTS:P}),o.setElementaryStreamInfo(X,w,C,_,P),this.bufferFragmentData(g,o,l,n)}if(v&&null!=d&&null!=(t=d.samples)&&t.length){var x={id:r,frag:o,details:v,samples:d.samples};i.trigger(O.FRAG_PARSING_METADATA,x)}if(v&&h){var M={id:r,frag:o,details:v,samples:h.samples};i.trigger(O.FRAG_PARSING_USERDATA,M)}}}else this.resetWhenMissingContext(n)}},{key:"_bufferInitSegment",value:function(e,t,r,i){var a=this;if(this.state===Hr){this.audioOnly=!!t.audio&&!t.video,this.altAudio&&!this.audioOnly&&delete t.audio;var n=t.audio,s=t.video,o=t.audiovideo;if(n){var l=e.audioCodec,u=navigator.userAgent.toLowerCase();this.audioCodecSwitch&&(l&&(l=-1!==l.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),1!==n.metadata.channelCount&&-1===u.indexOf("firefox")&&(l="mp4a.40.5")),-1!==u.indexOf("android")&&"audio/mpeg"!==n.container&&(l="mp4a.40.2",this.log("Android: force audio codec to ".concat(l))),e.audioCodec&&e.audioCodec!==l&&this.log('Swapping manifest audio codec "'.concat(e.audioCodec,'" for "').concat(l,'"')),n.levelCodec=l,n.id="main",this.log("Init audio buffer, container:".concat(n.container,", codecs[selected/level/parsed]=[").concat(l||"","/").concat(e.audioCodec||"","/").concat(n.codec,"]"))}s&&(s.levelCodec=e.videoCodec,s.id="main",this.log("Init video buffer, container:".concat(s.container,", codecs[level/parsed]=[").concat(e.videoCodec||"","/").concat(s.codec,"]"))),o&&this.log("Init audiovideo buffer, container:".concat(o.container,", codecs[level/parsed]=[").concat(e.attrs.CODECS||"","/").concat(o.codec,"]")),this.hls.trigger(O.BUFFER_CODECS,t),Object.keys(t).forEach((function(e){var n=t[e].initSegment;null!=n&&n.byteLength&&a.hls.trigger(O.BUFFER_APPENDING,{type:e,data:n,frag:r,part:null,chunkMeta:i,parent:r.type})})),this.tick()}}},{key:"getMainFwdBufferInfo",value:function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,At)}},{key:"backtrack",value:function(e){this.couldBacktrack=!0,this.backtrackFragment=e,this.resetTransmuxer(),this.flushBufferGap(e),this.fragmentTracker.removeFragment(e),this.fragPrevious=null,this.nextLoadPosition=e.start,this.state=Nr}},{key:"checkFragmentChanged",value:function(){var e=this.media,t=null;if(e&&e.readyState>1&&!1===e.seeking){var r=e.currentTime;if(br.isBuffered(e,r)?t=this.getAppendedFrag(r):br.isBuffered(e,r+.1)&&(t=this.getAppendedFrag(r+.1)),t){this.backtrackFragment=null;var i=this.fragPlaying,a=t.level;i&&t.sn===i.sn&&i.level===a&&t.urlId===i.urlId||(this.fragPlaying=t,this.hls.trigger(O.FRAG_CHANGED,{frag:t}),i&&i.level===a||this.hls.trigger(O.LEVEL_SWITCHED,{level:a}))}}}},{key:"nextLevel",get:function(){var e=this.nextBufferedFrag;return e?e.level:-1}},{key:"currentFrag",get:function(){var e=this.media;return e?this.fragPlaying||this.getAppendedFrag(e.currentTime):null}},{key:"currentProgramDateTime",get:function(){var e=this.media;if(e){var t=e.currentTime,r=this.currentFrag;if(r&&F(t)&&F(r.programDateTime)){var i=r.programDateTime+1e3*(t-r.start);return new Date(i)}}return null}},{key:"currentLevel",get:function(){var e=this.currentFrag;return e?e.level:-1}},{key:"nextBufferedFrag",get:function(){var e=this.currentFrag;return e?this.followingBufferedFrag(e):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}]),r}(Xr),na=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;y(this,e),this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=t,this.alpha_=t?Math.exp(Math.log(.5)/t):0,this.estimate_=r,this.totalWeight_=i}return k(e,[{key:"sample",value:function(e,t){var r=Math.pow(this.alpha_,e);this.estimate_=t*(1-r)+r*this.estimate_,this.totalWeight_+=e}},{key:"getTotalWeight",value:function(){return this.totalWeight_}},{key:"getEstimate",value:function(){if(this.alpha_){var e=1-Math.pow(this.alpha_,this.totalWeight_);if(e)return this.estimate_/e}return this.estimate_}}]),e}(),sa=function(){function e(t,r,i){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:100;y(this,e),this.defaultEstimate_=void 0,this.minWeight_=void 0,this.minDelayMs_=void 0,this.slow_=void 0,this.fast_=void 0,this.defaultTTFB_=void 0,this.ttfb_=void 0,this.defaultEstimate_=i,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new na(t),this.fast_=new na(r),this.defaultTTFB_=a,this.ttfb_=new na(t)}return k(e,[{key:"update",value:function(e,t){var r=this.slow_,i=this.fast_,a=this.ttfb_;r.halfLife!==e&&(this.slow_=new na(e,r.getEstimate(),r.getTotalWeight())),i.halfLife!==t&&(this.fast_=new na(t,i.getEstimate(),i.getTotalWeight())),a.halfLife!==e&&(this.ttfb_=new na(e,a.getEstimate(),a.getTotalWeight()))}},{key:"sample",value:function(e,t){var r=(e=Math.max(e,this.minDelayMs_))/1e3,i=8*t/r;this.fast_.sample(r,i),this.slow_.sample(r,i)}},{key:"sampleTTFB",value:function(e){var t=e/1e3,r=Math.sqrt(2)*Math.exp(-Math.pow(t,2)/2);this.ttfb_.sample(r,Math.max(e,5))}},{key:"canEstimate",value:function(){return this.fast_.getTotalWeight()>=this.minWeight_}},{key:"getEstimate",value:function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_}},{key:"getEstimateTTFB",value:function(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_}},{key:"destroy",value:function(){}}]),e}(),oa=function(){function e(t){y(this,e),this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=0,this._nextAutoLevel=-1,this.timer=-1,this.onCheck=this._abandonRulesCheck.bind(this),this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this.hls=t;var r=t.config;this.bwEstimator=new sa(r.abrEwmaSlowVoD,r.abrEwmaFastVoD,r.abrEwmaDefaultEstimate),this.registerListeners()}return k(e,[{key:"registerListeners",value:function(){var e=this.hls;e.on(O.FRAG_LOADING,this.onFragLoading,this),e.on(O.FRAG_LOADED,this.onFragLoaded,this),e.on(O.FRAG_BUFFERED,this.onFragBuffered,this),e.on(O.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(O.LEVEL_LOADED,this.onLevelLoaded,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e.off(O.FRAG_LOADING,this.onFragLoading,this),e.off(O.FRAG_LOADED,this.onFragLoaded,this),e.off(O.FRAG_BUFFERED,this.onFragBuffered,this),e.off(O.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(O.LEVEL_LOADED,this.onLevelLoaded,this)}},{key:"destroy",value:function(){this.unregisterListeners(),this.clearTimer(),this.hls=this.onCheck=null,this.fragCurrent=this.partCurrent=null}},{key:"onFragLoading",value:function(e,t){var r,i=t.frag;this.ignoreFragment(i)||(this.fragCurrent=i,this.partCurrent=null!=(r=t.part)?r:null,this.clearTimer(),this.timer=self.setInterval(this.onCheck,100))}},{key:"onLevelSwitching",value:function(e,t){this.clearTimer()}},{key:"getTimeToLoadFrag",value:function(e,t,r,i){return e+r/t+(i?this.lastLevelLoadSec:0)}},{key:"onLevelLoaded",value:function(e,t){var r=this.hls.config,i=t.stats,a=i.total,n=i.bwEstimate;F(a)&&F(n)&&(this.lastLevelLoadSec=8*a/n),t.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)}},{key:"_abandonRulesCheck",value:function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls,i=r.autoLevelEnabled,a=r.media;if(e&&a){var n=performance.now(),s=t?t.stats:e.stats,o=t?t.duration:e.duration,l=n-s.loading.start;if(s.aborted||s.loaded&&s.loaded===s.total||0===e.level)return this.clearTimer(),void(this._nextAutoLevel=-1);if(i&&!a.paused&&a.playbackRate&&a.readyState){var u=r.mainForwardBufferInfo;if(null!==u){var c=this.bwEstimator.getEstimateTTFB(),h=Math.abs(a.playbackRate);if(!(l<=Math.max(c,o/(2*h)*1e3))){var d=u.len/h;if(!(d>=2*o/h)){var f=s.loading.first?s.loading.first-s.loading.start:-1,v=s.loaded&&f>-1,g=this.bwEstimator.getEstimate(),m=r.levels,y=r.minAutoLevel,p=m[e.level],k=s.total||Math.max(s.loaded,Math.round(o*p.maxBitrate/8)),T=l-f;T<1&&v&&(T=Math.min(l,8*s.loaded/g));var E=v?1e3*s.loaded/T:0,S=E?(k-s.loaded)/E:8*k/g+c/1e3;if(!(S<=d)){var L,A=E?8*E:g,R=Number.POSITIVE_INFINITY;for(L=e.level-1;L>y;L--){var b=m[L].maxBitrate;if((R=this.getTimeToLoadFrag(c/1e3,A,o*b,!m[L].details))<d)break}R>=S||R>10*o||(r.nextLoadLevel=L,v?this.bwEstimator.sample(l-Math.min(c,f),s.loaded):this.bwEstimator.sampleTTFB(l),this.clearTimer(),K.warn("[abr] Fragment ".concat(e.sn).concat(t?" part "+t.index:""," of level ").concat(e.level," is loading too slowly;\n Time to underbuffer: ").concat(d.toFixed(3)," s\n Estimated load time for current fragment: ").concat(S.toFixed(3)," s\n Estimated load time for down switch fragment: ").concat(R.toFixed(3)," s\n TTFB estimate: ").concat(f,"\n Current BW estimate: ").concat(F(g)?(g/1024).toFixed(3):"Unknown"," Kb/s\n New BW estimate: ").concat((this.bwEstimator.getEstimate()/1024).toFixed(3)," Kb/s\n Aborting and switching to level ").concat(L)),e.loader&&(this.fragCurrent=this.partCurrent=null,e.abortRequests()),r.trigger(O.FRAG_LOAD_EMERGENCY_ABORTED,{frag:e,part:t,stats:s}))}}}}}}}},{key:"onFragLoaded",value:function(e,t){var r=t.frag,i=t.part,a=i?i.stats:r.stats;if(r.type===At&&this.bwEstimator.sampleTTFB(a.loading.first-a.loading.start),!this.ignoreFragment(r)){if(this.clearTimer(),this.lastLoadedFragLevel=r.level,this._nextAutoLevel=-1,this.hls.config.abrMaxWithRealBitrate){var n=i?i.duration:r.duration,s=this.hls.levels[r.level],o=(s.loaded?s.loaded.bytes:0)+a.loaded,l=(s.loaded?s.loaded.duration:0)+n;s.loaded={bytes:o,duration:l},s.realBitrate=Math.round(8*o/l)}if(r.bitrateTest){var u={stats:a,frag:r,part:i,id:r.type};this.onFragBuffered(O.FRAG_BUFFERED,u),r.bitrateTest=!1}}}},{key:"onFragBuffered",value:function(e,t){var r=t.frag,i=t.part,a=null!=i&&i.stats.loaded?i.stats:r.stats;if(!a.aborted&&!this.ignoreFragment(r)){var n=a.parsing.end-a.loading.start-Math.min(a.loading.first-a.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(n,a.loaded),a.bwEstimate=this.bwEstimator.getEstimate(),r.bitrateTest?this.bitrateTestDelay=n/1e3:this.bitrateTestDelay=0}}},{key:"ignoreFragment",value:function(e){return e.type!==At||"initSegment"===e.sn}},{key:"clearTimer",value:function(){self.clearInterval(this.timer)}},{key:"nextAutoLevel",get:function(){var e=this._nextAutoLevel,t=this.bwEstimator;if(-1!==e&&!t.canEstimate())return e;var r=this.getNextABRAutoLevel();if(-1!==e){var i=this.hls.levels;if(i.length>Math.max(e,r)&&i[e].loadError<=i[r].loadError)return e}return-1!==e&&(r=Math.min(e,r)),r},set:function(e){this._nextAutoLevel=e}},{key:"getNextABRAutoLevel",value:function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls,i=r.maxAutoLevel,a=r.config,n=r.minAutoLevel,s=r.media,o=t?t.duration:e?e.duration:0,l=s&&0!==s.playbackRate?Math.abs(s.playbackRate):1,u=this.bwEstimator?this.bwEstimator.getEstimate():a.abrEwmaDefaultEstimate,c=r.mainForwardBufferInfo,h=(c?c.len:0)/l,d=this.findBestLevel(u,n,i,h,a.abrBandWidthFactor,a.abrBandWidthUpFactor);if(d>=0)return d;K.trace("[abr] ".concat(h?"rebuffering expected":"buffer is empty",", finding optimal quality level"));var f=o?Math.min(o,a.maxStarvationDelay):a.maxStarvationDelay,v=a.abrBandWidthFactor,g=a.abrBandWidthUpFactor;if(!h){var m=this.bitrateTestDelay;m&&(f=(o?Math.min(o,a.maxLoadingDelay):a.maxLoadingDelay)-m,K.trace("[abr] bitrate test took ".concat(Math.round(1e3*m),"ms, set first fragment max fetchDuration to ").concat(Math.round(1e3*f)," ms")),v=g=1)}return d=this.findBestLevel(u,n,i,h+f,v,g),Math.max(d,0)}},{key:"findBestLevel",value:function(e,t,r,i,a,n){for(var s,o=this.fragCurrent,l=this.partCurrent,u=this.lastLoadedFragLevel,c=this.hls.levels,h=c[u],d=!(null==h||null==(s=h.details)||!s.live),f=null==h?void 0:h.codecSet,v=l?l.duration:o?o.duration:0,g=this.bwEstimator.getEstimateTTFB()/1e3,m=t,y=-1,p=r;p>=t;p--){var k=c[p];if(!k||f&&k.codecSet!==f)k&&(m=Math.min(p,m),y=Math.max(p,y));else{-1!==y&&K.trace("[abr] Skipped level(s) ".concat(m,"-").concat(y,' with CODECS:"').concat(c[y].attrs.CODECS,'"; not compatible with "').concat(h.attrs.CODECS,'"'));var T,E=k.details,S=(l?null==E?void 0:E.partTarget:null==E?void 0:E.averagetargetduration)||v;T=p<=u?a*e:n*e;var L=c[p].maxBitrate,A=this.getTimeToLoadFrag(g,T,L*S,void 0===E);if(K.trace("[abr] level:".concat(p," adjustedbw-bitrate:").concat(Math.round(T-L)," avgDuration:").concat(S.toFixed(1)," maxFetchDuration:").concat(i.toFixed(1)," fetchDuration:").concat(A.toFixed(1))),T>L&&(0===A||!F(A)||d&&!this.bitrateTestDelay||A<i))return p}}return-1}}]),e}(),la=function(){function e(){y(this,e),this.chunks=[],this.dataLength=0}return k(e,[{key:"push",value:function(e){this.chunks.push(e),this.dataLength+=e.length}},{key:"flush",value:function(){var e,t=this.chunks,r=this.dataLength;return t.length?(e=1===t.length?t[0]:function(e,t){for(var r=new Uint8Array(t),i=0,a=0;a<e.length;a++){var n=e[a];r.set(n,i),i+=n.length}return r}(t,r),this.reset(),e):new Uint8Array(0)}},{key:"reset",value:function(){this.chunks.length=0,this.dataLength=0}}]),e}(),ua=function(e){c(r,e);var t=d(r);function r(e,i,a){var n;return y(this,r),(n=t.call(this,e,i,a,"[audio-stream-controller]",Rt)).videoBuffer=null,n.videoTrackCC=-1,n.waitingVideoCC=-1,n.bufferedTrack=null,n.switchingTrack=null,n.trackId=-1,n.waitingData=null,n.mainDetails=null,n.bufferFlushed=!1,n.cachedTrackLoadedData=null,n._registerListeners(),n}return k(r,[{key:"onHandlerDestroying",value:function(){this._unregisterListeners(),this.mainDetails=null,this.bufferedTrack=null,this.switchingTrack=null}},{key:"_registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.LEVEL_LOADED,this.onLevelLoaded,this),e.on(O.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),e.on(O.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(O.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.on(O.ERROR,this.onError,this),e.on(O.BUFFER_RESET,this.onBufferReset,this),e.on(O.BUFFER_CREATED,this.onBufferCreated,this),e.on(O.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(O.INIT_PTS_FOUND,this.onInitPtsFound,this),e.on(O.FRAG_BUFFERED,this.onFragBuffered,this)}},{key:"_unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.LEVEL_LOADED,this.onLevelLoaded,this),e.off(O.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),e.off(O.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(O.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.off(O.ERROR,this.onError,this),e.off(O.BUFFER_RESET,this.onBufferReset,this),e.off(O.BUFFER_CREATED,this.onBufferCreated,this),e.off(O.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(O.INIT_PTS_FOUND,this.onInitPtsFound,this),e.off(O.FRAG_BUFFERED,this.onFragBuffered,this)}},{key:"onInitPtsFound",value:function(e,t){var r=t.frag,i=t.id,a=t.initPTS,n=t.timescale;if("main"===i){var s=r.cc;this.initPTS[r.cc]={baseTime:a,timescale:n},this.log("InitPTS for cc: ".concat(s," found from main: ").concat(a)),this.videoTrackCC=s,this.state===jr&&this.tick()}}},{key:"startLoad",value:function(e){if(!this.levels)return this.startPosition=e,void(this.state=Mr);var t=this.lastCurrentTime;this.stopLoad(),this.setInterval(100),t>0&&-1===e?(this.log("Override startPosition with lastCurrentTime @".concat(t.toFixed(3))),e=t,this.state=Nr):(this.loadedmetadata=!1,this.state=Kr),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}},{key:"doTick",value:function(){switch(this.state){case Nr:this.doTickIdle();break;case Kr:var e,t=this.levels,i=this.trackId,a=null==t||null==(e=t[i])?void 0:e.details;if(a){if(this.waitForCdnTuneIn(a))break;this.state=jr}break;case Gr:var n,s=performance.now(),o=this.retryDate;(!o||s>=o||null!=(n=this.media)&&n.seeking)&&(this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.trackId),this.state=Nr);break;case jr:var l=this.waitingData;if(l){var c=l.frag,h=l.part,d=l.cache,f=l.complete;if(void 0!==this.initPTS[c.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=Br;var v={frag:c,part:h,payload:d.flush(),networkDetails:null};this._handleFragmentLoadProgress(v),f&&u(g(r.prototype),"_handleFragmentLoadComplete",this).call(this,v)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log("Waiting fragment cc (".concat(c.cc,") cancelled because video is at cc ").concat(this.videoTrackCC)),this.clearWaitingFragment();else{var m=this.getLoadPosition(),y=br.bufferInfo(this.mediaBuffer,m,this.config.maxBufferHole);ir(y.end,this.config.maxFragLookUpTolerance,c)<0&&(this.log("Waiting fragment cc (".concat(c.cc,") @ ").concat(c.start," cancelled because another fragment at ").concat(y.end," is needed")),this.clearWaitingFragment())}}else this.state=Nr}this.onTickEnd()}},{key:"clearWaitingFragment",value:function(){var e=this.waitingData;e&&(this.fragmentTracker.removeFragment(e.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=Nr)}},{key:"resetLoadingState",value:function(){this.clearWaitingFragment(),u(g(r.prototype),"resetLoadingState",this).call(this)}},{key:"onTickEnd",value:function(){var e=this.media;null!=e&&e.readyState&&(this.lastCurrentTime=e.currentTime)}},{key:"doTickIdle",value:function(){var e=this.hls,t=this.levels,r=this.media,i=this.trackId,a=e.config;if(null!=t&&t[i]&&(r||!this.startFragRequested&&a.startFragPrefetch)){var n=t[i],s=n.details;if(!s||s.live&&this.levelLastLoaded!==i||this.waitForCdnTuneIn(s))this.state=Kr;else{var o=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&o&&(this.bufferFlushed=!1,this.afterBufferFlushed(o,X,Rt));var l=this.getFwdBufferInfo(o,Rt);if(null!==l){var u=this.bufferedTrack,c=this.switchingTrack;if(!c&&this._streamEnded(l,s))return e.trigger(O.BUFFER_EOS,{type:"audio"}),void(this.state=Yr);var h=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,At),d=l.len,f=this.getMaxBufferLength(null==h?void 0:h.len);if(!(d>=f)||c){var v=s.fragments[0].start,g=l.end;if(c&&r){var m=this.getLoadPosition();u&&c.attrs!==u.attrs&&(g=m),s.PTSKnown&&m<v&&(l.end>v||l.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),r.currentTime=v+.05)}var y=this.getNextFragment(g,s),p=!1;if(y&&this.isLoopLoading(y,g)&&(p=!!y.gap,y=this.getNextFragmentLoopLoading(y,s,l,At,f)),y){var k=h&&y.start>h.end+s.targetduration;if(k||(null==h||!h.len)&&l.len){var T=this.getAppendedFrag(y.start,At);if(null===T)return;if(p||(p=!!T.gap||!!k&&0===h.len),k&&!p||p&&l.nextStart&&l.nextStart<T.end)return}this.loadFragment(y,n,g)}else this.bufferFlushed=!0}}}}}},{key:"getMaxBufferLength",value:function(e){var t=u(g(r.prototype),"getMaxBufferLength",this).call(this);return e?Math.min(Math.max(t,e),this.config.maxMaxBufferLength):t}},{key:"onMediaDetaching",value:function(){this.videoBuffer=null,u(g(r.prototype),"onMediaDetaching",this).call(this)}},{key:"onAudioTracksUpdated",value:function(e,t){var r=t.audioTracks;this.resetTransmuxer(),this.levels=r.map((function(e){return new Vt(e)}))}},{key:"onAudioTrackSwitching",value:function(e,t){var r=!!t.url;this.trackId=t.id;var i=this.fragCurrent;i&&(i.abortRequests(),this.removeUnbufferedFrags(i.start)),this.resetLoadingState(),r?this.setInterval(100):this.resetTransmuxer(),r?(this.switchingTrack=t,this.state=Nr):(this.switchingTrack=null,this.bufferedTrack=t,this.state=Mr),this.tick()}},{key:"onManifestLoading",value:function(){this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1,this.levels=this.mainDetails=this.waitingData=this.bufferedTrack=this.cachedTrackLoadedData=this.switchingTrack=null,this.startFragRequested=!1,this.trackId=this.videoTrackCC=this.waitingVideoCC=-1}},{key:"onLevelLoaded",value:function(e,t){this.mainDetails=t.details,null!==this.cachedTrackLoadedData&&(this.hls.trigger(O.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)}},{key:"onAudioTrackLoaded",value:function(e,t){var r;if(null!=this.mainDetails){var i=this.levels,a=t.details,n=t.id;if(i){this.log("Track ".concat(n," loaded [").concat(a.startSN,",").concat(a.endSN,"]").concat(a.lastPartSn?"[part-".concat(a.lastPartSn,"-").concat(a.lastPartIndex,"]"):"",",duration:").concat(a.totalduration));var s=i[n],o=0;if(a.live||null!=(r=s.details)&&r.live){this.checkLiveUpdate(a);var l=this.mainDetails;if(a.deltaUpdateFailed||!l)return;!s.details&&a.hasProgramDateTime&&l.hasProgramDateTime?(_r(a,l),o=a.fragments[0].start):o=this.alignPlaylists(a,s.details)}s.details=a,this.levelLastLoaded=n,this.startFragRequested||!this.mainDetails&&a.live||this.setStartPosition(s.details,o),this.state!==Kr||this.waitForCdnTuneIn(a)||(this.state=Nr),this.tick()}else this.warn("Audio tracks were reset while loading level ".concat(n))}else this.cachedTrackLoadedData=t}},{key:"_handleFragmentLoadProgress",value:function(e){var t,r=e.frag,i=e.part,a=e.payload,n=this.config,s=this.trackId,o=this.levels;if(o){var l=o[s];if(l){var u=l.details;if(!u)return this.warn("Audio track details undefined on fragment load progress"),void this.removeUnbufferedFrags(r.start);var c=n.defaultAudioCodec||l.audioCodec||"mp4a.40.2",h=this.transmuxer;h||(h=this.transmuxer=new ra(this.hls,Rt,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));var d=this.initPTS[r.cc],f=null==(t=r.initSegment)?void 0:t.data;if(void 0!==d){var v=i?i.index:-1,g=-1!==v,m=new Dr(r.level,r.sn,r.stats.chunkCount,a.byteLength,v,g);h.push(a,f,c,"",r,i,u.totalduration,!1,m,d)}else this.log("Unknown video PTS for cc ".concat(r.cc,", waiting for video PTS before demuxing audio frag ").concat(r.sn," of [").concat(u.startSN," ,").concat(u.endSN,"],track ").concat(s)),(this.waitingData=this.waitingData||{frag:r,part:i,cache:new la,complete:!1}).cache.push(new Uint8Array(a)),this.waitingVideoCC=this.videoTrackCC,this.state=jr}else this.warn("Audio track is undefined on fragment load progress")}else this.warn("Audio tracks were reset while fragment load was in progress. Fragment ".concat(r.sn," of level ").concat(r.level," will not be buffered"))}},{key:"_handleFragmentLoadComplete",value:function(e){this.waitingData?this.waitingData.complete=!0:u(g(r.prototype),"_handleFragmentLoadComplete",this).call(this,e)}},{key:"onBufferReset",value:function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1}},{key:"onBufferCreated",value:function(e,t){var r=t.tracks.audio;r&&(this.mediaBuffer=r.buffer||null),t.tracks.video&&(this.videoBuffer=t.tracks.video.buffer||null)}},{key:"onFragBuffered",value:function(e,t){var r=t.frag,i=t.part;if(r.type===Rt)if(this.fragContextChanged(r))this.warn("Fragment ".concat(r.sn).concat(i?" p: "+i.index:""," of level ").concat(r.level," finished buffering, but was aborted. state: ").concat(this.state,", audioSwitch: ").concat(this.switchingTrack?this.switchingTrack.name:"false"));else{if("initSegment"!==r.sn){this.fragPrevious=r;var a=this.switchingTrack;a&&(this.bufferedTrack=a,this.switchingTrack=null,this.hls.trigger(O.AUDIO_TRACK_SWITCHED,_({},a)))}this.fragBufferedComplete(r,i)}else if(!this.loadedmetadata&&r.type===At){var n=this.videoBuffer||this.media;n&&br.getBuffered(n).length&&(this.loadedmetadata=!0)}}},{key:"onError",value:function(e,t){var i;if(t.fatal)this.state=Wr;else switch(t.details){case N.FRAG_GAP:case N.FRAG_PARSING_ERROR:case N.FRAG_DECRYPT_ERROR:case N.FRAG_LOAD_ERROR:case N.FRAG_LOAD_TIMEOUT:case N.KEY_LOAD_ERROR:case N.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(Rt,t);break;case N.AUDIO_TRACK_LOAD_ERROR:case N.AUDIO_TRACK_LOAD_TIMEOUT:case N.LEVEL_PARSING_ERROR:t.levelRetry||this.state!==Kr||(null==(i=t.context)?void 0:i.type)!==St||(this.state=Nr);break;case N.BUFFER_FULL_ERROR:if(!t.parent||"audio"!==t.parent)return;this.reduceLengthAndFlushBuffer(t)&&(this.bufferedTrack=null,u(g(r.prototype),"flushMainBuffer",this).call(this,0,Number.POSITIVE_INFINITY,"audio"));break;case N.INTERNAL_EXCEPTION:this.recoverWorkerError(t)}}},{key:"onBufferFlushed",value:function(e,t){t.type===X&&(this.bufferFlushed=!0,this.state===Yr&&(this.state=Nr))}},{key:"_handleTransmuxComplete",value:function(e){var t,r="audio",i=this.hls,a=e.remuxResult,n=e.chunkMeta,s=this.getCurrentContext(n);if(s){var o=s.frag,l=s.part,u=s.level.details,c=a.audio,h=a.text,d=a.id3,f=a.initSegment;if(!this.fragContextChanged(o)&&u){if(this.state=Hr,this.switchingTrack&&c&&this.completeAudioSwitch(this.switchingTrack),null!=f&&f.tracks){var v=o.initSegment||o;this._bufferInitSegment(f.tracks,v,n),i.trigger(O.FRAG_PARSING_INIT_SEGMENT,{frag:v,id:r,tracks:f.tracks})}if(c){var g=c.startPTS,m=c.endPTS,y=c.startDTS,p=c.endDTS;l&&(l.elementaryStreams[X]={startPTS:g,endPTS:m,startDTS:y,endDTS:p}),o.setElementaryStreamInfo(X,g,m,y,p),this.bufferFragmentData(c,o,l,n)}if(null!=d&&null!=(t=d.samples)&&t.length){var k=x({id:r,frag:o,details:u},d);i.trigger(O.FRAG_PARSING_METADATA,k)}if(h){var T=x({id:r,frag:o,details:u},h);i.trigger(O.FRAG_PARSING_USERDATA,T)}}else this.fragmentTracker.removeFragment(o)}else this.resetWhenMissingContext(n)}},{key:"_bufferInitSegment",value:function(e,t,r){if(this.state===Hr){e.video&&delete e.video;var i=e.audio;if(i){i.levelCodec=i.codec,i.id="audio",this.log("Init audio buffer, container:".concat(i.container,", codecs[parsed]=[").concat(i.codec,"]")),this.hls.trigger(O.BUFFER_CODECS,e);var a=i.initSegment;if(null!=a&&a.byteLength){var n={type:"audio",frag:t,part:null,chunkMeta:r,parent:t.type,data:a};this.hls.trigger(O.BUFFER_APPENDING,n)}this.tick()}}}},{key:"loadFragment",value:function(e,t,i){var a,n=this.fragmentTracker.getState(e);this.fragCurrent=e,this.switchingTrack||n===hr||n===fr?"initSegment"===e.sn?this._loadInitSegment(e,t):null!=(a=t.details)&&a.live&&!this.initPTS[e.cc]?(this.log("Waiting for video PTS in continuity counter ".concat(e.cc," of live stream before loading audio fragment ").concat(e.sn," of level ").concat(this.trackId)),this.state=jr):(this.startFragRequested=!0,u(g(r.prototype),"loadFragment",this).call(this,e,t,i)):this.clearTrackerIfNeeded(e)}},{key:"completeAudioSwitch",value:function(e){var t=this.hls,i=this.media,a=this.bufferedTrack,n=null==a?void 0:a.attrs,s=e.attrs;i&&n&&(n.CHANNELS!==s.CHANNELS||n.NAME!==s.NAME||n.LANGUAGE!==s.LANGUAGE)&&(this.log("Switching audio track : flushing all audio"),u(g(r.prototype),"flushMainBuffer",this).call(this,0,Number.POSITIVE_INFINITY,"audio")),this.bufferedTrack=e,this.switchingTrack=null,t.trigger(O.AUDIO_TRACK_SWITCHED,_({},e))}}]),r}(Xr),ca=function(e){c(r,e);var t=d(r);function r(e){var i;return y(this,r),(i=t.call(this,e,"[audio-track-controller]")).tracks=[],i.groupId=null,i.tracksInGroup=[],i.trackId=-1,i.currentTrack=null,i.selectDefaultTrack=!0,i.registerListeners(),i}return k(r,[{key:"registerListeners",value:function(){var e=this.hls;e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.MANIFEST_PARSED,this.onManifestParsed,this),e.on(O.LEVEL_LOADING,this.onLevelLoading,this),e.on(O.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(O.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.on(O.ERROR,this.onError,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_PARSED,this.onManifestParsed,this),e.off(O.LEVEL_LOADING,this.onLevelLoading,this),e.off(O.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(O.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.off(O.ERROR,this.onError,this)}},{key:"destroy",value:function(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.currentTrack=null,u(g(r.prototype),"destroy",this).call(this)}},{key:"onManifestLoading",value:function(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.currentTrack=null,this.selectDefaultTrack=!0}},{key:"onManifestParsed",value:function(e,t){this.tracks=t.audioTracks||[]}},{key:"onAudioTrackLoaded",value:function(e,t){var r=t.id,i=t.groupId,a=t.details,n=this.tracksInGroup[r];if(n&&n.groupId===i){var s=n.details;n.details=t.details,this.log("audio-track ".concat(r,' "').concat(n.name,'" lang:').concat(n.lang," group:").concat(i," loaded [").concat(a.startSN,"-").concat(a.endSN,"]")),r===this.trackId&&this.playlistLoaded(r,t,s)}else this.warn("Track with id:".concat(r," and group:").concat(i," not found in active group ").concat(n.groupId))}},{key:"onLevelLoading",value:function(e,t){this.switchLevel(t.level)}},{key:"onLevelSwitching",value:function(e,t){this.switchLevel(t.level)}},{key:"switchLevel",value:function(e){var t=this.hls.levels[e];if(null!=t&&t.audioGroupIds){var r=t.audioGroupIds[t.urlId];if(this.groupId!==r){this.groupId=r||null;var i=this.tracks.filter((function(e){return!r||e.groupId===r}));this.selectDefaultTrack&&!i.some((function(e){return e.default}))&&(this.selectDefaultTrack=!1),this.tracksInGroup=i;var a={audioTracks:i};this.log("Updating audio tracks, ".concat(i.length," track(s) found in group:").concat(r)),this.hls.trigger(O.AUDIO_TRACKS_UPDATED,a),this.selectInitialTrack()}else this.shouldReloadPlaylist(this.currentTrack)&&this.setAudioTrack(this.trackId)}}},{key:"onError",value:function(e,t){!t.fatal&&t.context&&t.context.type===St&&t.context.id===this.trackId&&t.context.groupId===this.groupId&&(this.requestScheduled=-1,this.checkRetry(t))}},{key:"audioTracks",get:function(){return this.tracksInGroup}},{key:"audioTrack",get:function(){return this.trackId},set:function(e){this.selectDefaultTrack=!1,this.setAudioTrack(e)}},{key:"setAudioTrack",value:function(e){var t=this.tracksInGroup;if(e<0||e>=t.length)this.warn("Invalid id passed to audio-track controller");else{this.clearTimer();var r=this.currentTrack;t[this.trackId];var i=t[e],a=i.groupId,n=i.name;if(this.log("Switching to audio-track ".concat(e,' "').concat(n,'" lang:').concat(i.lang," group:").concat(a)),this.trackId=e,this.currentTrack=i,this.selectDefaultTrack=!1,this.hls.trigger(O.AUDIO_TRACK_SWITCHING,_({},i)),!i.details||i.details.live){var s=this.switchParams(i.url,null==r?void 0:r.details);this.loadPlaylist(s)}}}},{key:"selectInitialTrack",value:function(){var e=this.tracksInGroup,t=this.findTrackId(this.currentTrack)|this.findTrackId(null);if(-1!==t)this.setAudioTrack(t);else{var r=new Error("No track found for running audio group-ID: ".concat(this.groupId," track count: ").concat(e.length));this.warn(r.message),this.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.AUDIO_TRACK_LOAD_ERROR,fatal:!0,error:r})}}},{key:"findTrackId",value:function(e){for(var t=this.tracksInGroup,r=0;r<t.length;r++){var i=t[r];if(!this.selectDefaultTrack||i.default){if(!e||void 0!==e.attrs["STABLE-RENDITION-ID"]&&e.attrs["STABLE-RENDITION-ID"]===i.attrs["STABLE-RENDITION-ID"])return i.id;if(e.name===i.name&&e.lang===i.lang)return i.id}}return-1}},{key:"loadPlaylist",value:function(e){u(g(r.prototype),"loadPlaylist",this).call(this);var t=this.tracksInGroup[this.trackId];if(this.shouldLoadPlaylist(t)){var i=t.id,a=t.groupId,n=t.url;if(e)try{n=e.addDirectives(n)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: ".concat(e))}this.log("loading audio-track playlist ".concat(i,' "').concat(t.name,'" lang:').concat(t.lang," group:").concat(a)),this.clearTimer(),this.hls.trigger(O.AUDIO_TRACK_LOADING,{url:n,id:i,groupId:a,deliveryDirectives:e||null})}}}]),r}(or);function ha(e,t){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(!da(e[r].attrs,t[r].attrs))return!1;return!0}function da(e,t){var r=e["STABLE-RENDITION-ID"];return r?r===t["STABLE-RENDITION-ID"]:!["LANGUAGE","NAME","CHARACTERISTICS","AUTOSELECT","DEFAULT","FORCED"].some((function(r){return e[r]!==t[r]}))}var fa=function(e){c(r,e);var t=d(r);function r(e,i,a){var n;return y(this,r),(n=t.call(this,e,i,a,"[subtitle-stream-controller]",bt)).levels=[],n.currentTrackId=-1,n.tracksBuffered=[],n.mainDetails=null,n._registerListeners(),n}return k(r,[{key:"onHandlerDestroying",value:function(){this._unregisterListeners(),this.mainDetails=null}},{key:"_registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.LEVEL_LOADED,this.onLevelLoaded,this),e.on(O.ERROR,this.onError,this),e.on(O.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.on(O.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),e.on(O.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.on(O.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),e.on(O.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(O.FRAG_BUFFERED,this.onFragBuffered,this)}},{key:"_unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.LEVEL_LOADED,this.onLevelLoaded,this),e.off(O.ERROR,this.onError,this),e.off(O.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.off(O.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),e.off(O.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.off(O.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),e.off(O.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(O.FRAG_BUFFERED,this.onFragBuffered,this)}},{key:"startLoad",value:function(e){this.stopLoad(),this.state=Nr,this.setInterval(500),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}},{key:"onManifestLoading",value:function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()}},{key:"onMediaDetaching",value:function(){this.tracksBuffered=[],u(g(r.prototype),"onMediaDetaching",this).call(this)}},{key:"onLevelLoaded",value:function(e,t){this.mainDetails=t.details}},{key:"onSubtitleFragProcessed",value:function(e,t){var r=t.frag,i=t.success;if(this.fragPrevious=r,this.state=Nr,i){var a=this.tracksBuffered[this.currentTrackId];if(a){for(var n,s=r.start,o=0;o<a.length;o++)if(s>=a[o].start&&s<=a[o].end){n=a[o];break}var l=r.start+r.duration;n?n.end=l:(n={start:s,end:l},a.push(n)),this.fragmentTracker.fragBuffered(r)}}}},{key:"onBufferFlushing",value:function(e,t){var r=t.startOffset,i=t.endOffset;if(0===r&&i!==Number.POSITIVE_INFINITY){var a=i-1;if(a<=0)return;t.endOffsetSubtitles=Math.max(0,a),this.tracksBuffered.forEach((function(e){for(var t=0;t<e.length;)if(e[t].end<=a)e.shift();else{if(!(e[t].start<a))break;e[t].start=a,t++}})),this.fragmentTracker.removeFragmentsInRange(r,a,bt)}}},{key:"onFragBuffered",value:function(e,t){var r;this.loadedmetadata||t.frag.type!==At||null!=(r=this.media)&&r.buffered.length&&(this.loadedmetadata=!0)}},{key:"onError",value:function(e,t){var r=t.frag;(null==r?void 0:r.type)===bt&&(this.fragCurrent&&this.fragCurrent.abortRequests(),this.state!==Mr&&(this.state=Nr))}},{key:"onSubtitleTracksUpdated",value:function(e,t){var r=this,i=t.subtitleTracks;ha(this.levels,i)?this.levels=i.map((function(e){return new Vt(e)})):(this.tracksBuffered=[],this.levels=i.map((function(e){var t=new Vt(e);return r.tracksBuffered[t.id]=[],t})),this.fragmentTracker.removeFragmentsInRange(0,Number.POSITIVE_INFINITY,bt),this.fragPrevious=null,this.mediaBuffer=null)}},{key:"onSubtitleTrackSwitch",value:function(e,t){if(this.currentTrackId=t.id,this.levels.length&&-1!==this.currentTrackId){var r=this.levels[this.currentTrackId];null!=r&&r.details?this.mediaBuffer=this.mediaBufferTimeRanges:this.mediaBuffer=null,r&&this.setInterval(500)}else this.clearInterval()}},{key:"onSubtitleTrackLoaded",value:function(e,t){var r,i=t.details,a=t.id,n=this.currentTrackId,s=this.levels;if(s.length){var o=s[n];if(!(a>=s.length||a!==n)&&o){this.mediaBuffer=this.mediaBufferTimeRanges;var l=0;if(i.live||null!=(r=o.details)&&r.live){var u=this.mainDetails;if(i.deltaUpdateFailed||!u)return;var c=u.fragments[0];o.details?0===(l=this.alignPlaylists(i,o.details))&&c&&qt(i,l=c.start):i.hasProgramDateTime&&u.hasProgramDateTime?(_r(i,u),l=i.fragments[0].start):c&&qt(i,l=c.start)}o.details=i,this.levelLastLoaded=a,this.startFragRequested||!this.mainDetails&&i.live||this.setStartPosition(o.details,l),this.tick(),i.live&&!this.fragCurrent&&this.media&&this.state===Nr&&(rr(null,i.fragments,this.media.currentTime,0)||(this.warn("Subtitle playlist not aligned with playback"),o.details=void 0))}}}},{key:"_handleFragmentLoadComplete",value:function(e){var t=this,r=e.frag,i=e.payload,a=r.decryptdata,n=this.hls;if(!this.fragContextChanged(r)&&i&&i.byteLength>0&&a&&a.key&&a.iv&&"AES-128"===a.method){var s=performance.now();this.decrypter.decrypt(new Uint8Array(i),a.key.buffer,a.iv.buffer).catch((function(e){throw n.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.FRAG_DECRYPT_ERROR,fatal:!1,error:e,reason:e.message,frag:r}),e})).then((function(e){var t=performance.now();n.trigger(O.FRAG_DECRYPTED,{frag:r,payload:e,stats:{tstart:s,tdecrypt:t}})})).catch((function(e){t.warn("".concat(e.name,": ").concat(e.message)),t.state=Nr}))}}},{key:"doTick",value:function(){if(this.media){if(this.state===Nr){var e=this.currentTrackId,t=this.levels,r=t[e];if(!t.length||!r||!r.details)return;var i=this.config,a=this.getLoadPosition(),n=br.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],a,i.maxBufferHole),s=n.end,o=n.len,l=this.getFwdBufferInfo(this.media,At),u=r.details;if(o>this.getMaxBufferLength(null==l?void 0:l.len)+u.levelTargetDuration)return;var c=u.fragments,h=c.length,d=u.edge,f=null,v=this.fragPrevious;if(s<d){var g=i.maxFragLookUpTolerance,m=s>d-g?0:g;!(f=rr(v,c,Math.max(c[0].start,s),m))&&v&&v.start<c[0].start&&(f=c[0])}else f=c[h-1];if(!f)return;if("initSegment"!==(f=this.mapToInitFragWhenRequired(f)).sn){var y=c[f.sn-u.startSN-1];y&&y.cc===f.cc&&this.fragmentTracker.getState(y)===hr&&(f=y)}this.fragmentTracker.getState(f)===hr&&this.loadFragment(f,r,s)}}else this.state=Nr}},{key:"getMaxBufferLength",value:function(e){var t=u(g(r.prototype),"getMaxBufferLength",this).call(this);return e?Math.max(t,e):t}},{key:"loadFragment",value:function(e,t,i){this.fragCurrent=e,"initSegment"===e.sn?this._loadInitSegment(e,t):(this.startFragRequested=!0,u(g(r.prototype),"loadFragment",this).call(this,e,t,i))}},{key:"mediaBufferTimeRanges",get:function(){return new va(this.tracksBuffered[this.currentTrackId]||[])}}]),r}(Xr),va=k((function e(t){y(this,e),this.buffered=void 0;var r=function(e,r,i){if((r>>>=0)>i-1)throw new DOMException("Failed to execute '".concat(e,"' on 'TimeRanges': The index provided (").concat(r,") is greater than the maximum bound (").concat(i,")"));return t[r][e]};this.buffered={get length(){return t.length},end:function(e){return r("end",e,t.length)},start:function(e){return r("start",e,t.length)}}})),ga=function(e){c(r,e);var t=d(r);function r(e){var i;return y(this,r),(i=t.call(this,e,"[subtitle-track-controller]")).media=null,i.tracks=[],i.groupId=null,i.tracksInGroup=[],i.trackId=-1,i.selectDefaultTrack=!0,i.queuedDefaultTrack=-1,i.trackChangeListener=function(){return i.onTextTracksChanged()},i.asyncPollTrackChange=function(){return i.pollTrackChange(0)},i.useTextTrackPolling=!1,i.subtitlePollingInterval=-1,i._subtitleDisplay=!0,i.registerListeners(),i}return k(r,[{key:"destroy",value:function(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.trackChangeListener=this.asyncPollTrackChange=null,u(g(r.prototype),"destroy",this).call(this)}},{key:"subtitleDisplay",get:function(){return this._subtitleDisplay},set:function(e){this._subtitleDisplay=e,this.trackId>-1&&this.toggleTrackModes(this.trackId)}},{key:"registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.MANIFEST_PARSED,this.onManifestParsed,this),e.on(O.LEVEL_LOADING,this.onLevelLoading,this),e.on(O.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(O.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.on(O.ERROR,this.onError,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_PARSED,this.onManifestParsed,this),e.off(O.LEVEL_LOADING,this.onLevelLoading,this),e.off(O.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(O.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.off(O.ERROR,this.onError,this)}},{key:"onMediaAttached",value:function(e,t){this.media=t.media,this.media&&(this.queuedDefaultTrack>-1&&(this.subtitleTrack=this.queuedDefaultTrack,this.queuedDefaultTrack=-1),this.useTextTrackPolling=!(this.media.textTracks&&"onchange"in this.media.textTracks),this.useTextTrackPolling?this.pollTrackChange(500):this.media.textTracks.addEventListener("change",this.asyncPollTrackChange))}},{key:"pollTrackChange",value:function(e){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.trackChangeListener,e)}},{key:"onMediaDetaching",value:function(){this.media&&(self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),this.trackId>-1&&(this.queuedDefaultTrack=this.trackId),ma(this.media.textTracks).forEach((function(e){Pt(e)})),this.subtitleTrack=-1,this.media=null)}},{key:"onManifestLoading",value:function(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.selectDefaultTrack=!0}},{key:"onManifestParsed",value:function(e,t){this.tracks=t.subtitleTracks}},{key:"onSubtitleTrackLoaded",value:function(e,t){var r=t.id,i=t.details,a=this.trackId,n=this.tracksInGroup[a];if(n){var s=n.details;n.details=t.details,this.log("subtitle track ".concat(r," loaded [").concat(i.startSN,"-").concat(i.endSN,"]")),r===this.trackId&&this.playlistLoaded(r,t,s)}else this.warn("Invalid subtitle track id ".concat(r))}},{key:"onLevelLoading",value:function(e,t){this.switchLevel(t.level)}},{key:"onLevelSwitching",value:function(e,t){this.switchLevel(t.level)}},{key:"switchLevel",value:function(e){var t=this.hls.levels[e];if(null!=t&&t.textGroupIds){var r=t.textGroupIds[t.urlId],i=this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0;if(this.groupId!==r){var a=this.tracks.filter((function(e){return!r||e.groupId===r}));this.tracksInGroup=a;var n=this.findTrackId(null==i?void 0:i.name)||this.findTrackId();this.groupId=r||null;var s={subtitleTracks:a};this.log("Updating subtitle tracks, ".concat(a.length,' track(s) found in "').concat(r,'" group-id')),this.hls.trigger(O.SUBTITLE_TRACKS_UPDATED,s),-1!==n&&this.setSubtitleTrack(n,i)}else this.shouldReloadPlaylist(i)&&this.setSubtitleTrack(this.trackId,i)}}},{key:"findTrackId",value:function(e){for(var t=this.tracksInGroup,r=0;r<t.length;r++){var i=t[r];if((!this.selectDefaultTrack||i.default)&&(!e||e===i.name))return i.id}return-1}},{key:"onError",value:function(e,t){!t.fatal&&t.context&&t.context.type===Lt&&t.context.id===this.trackId&&t.context.groupId===this.groupId&&this.checkRetry(t)}},{key:"subtitleTracks",get:function(){return this.tracksInGroup}},{key:"subtitleTrack",get:function(){return this.trackId},set:function(e){this.selectDefaultTrack=!1;var t=this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0;this.setSubtitleTrack(e,t)}},{key:"loadPlaylist",value:function(e){u(g(r.prototype),"loadPlaylist",this).call(this);var t=this.tracksInGroup[this.trackId];if(this.shouldLoadPlaylist(t)){var i=t.id,a=t.groupId,n=t.url;if(e)try{n=e.addDirectives(n)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: ".concat(e))}this.log("Loading subtitle playlist for id ".concat(i)),this.hls.trigger(O.SUBTITLE_TRACK_LOADING,{url:n,id:i,groupId:a,deliveryDirectives:e||null})}}},{key:"toggleTrackModes",value:function(e){var t=this,r=this.media,i=this.trackId;if(r){var a=ma(r.textTracks),n=a.filter((function(e){return e.groupId===t.groupId}));if(-1===e)[].slice.call(a).forEach((function(e){e.mode="disabled"}));else{var s=n[i];s&&(s.mode="disabled")}var o=n[e];o&&(o.mode=this.subtitleDisplay?"showing":"hidden")}}},{key:"setSubtitleTrack",value:function(e,t){var r,i=this.tracksInGroup;if(this.media){if(this.trackId!==e&&this.toggleTrackModes(e),!(this.trackId===e&&(-1===e||null!=(r=i[e])&&r.details)||e<-1||e>=i.length)){this.clearTimer();var a=i[e];if(this.log("Switching to subtitle-track ".concat(e)+(a?' "'.concat(a.name,'" lang:').concat(a.lang," group:").concat(a.groupId):"")),this.trackId=e,a){var n=a.id,s=a.groupId,o=void 0===s?"":s,l=a.name,u=a.type,c=a.url;this.hls.trigger(O.SUBTITLE_TRACK_SWITCH,{id:n,groupId:o,name:l,type:u,url:c});var h=this.switchParams(a.url,null==t?void 0:t.details);this.loadPlaylist(h)}else this.hls.trigger(O.SUBTITLE_TRACK_SWITCH,{id:e})}}else this.queuedDefaultTrack=e}},{key:"onTextTracksChanged",value:function(){if(this.useTextTrackPolling||self.clearInterval(this.subtitlePollingInterval),this.media&&this.hls.config.renderTextTracksNatively){for(var e=-1,t=ma(this.media.textTracks),r=0;r<t.length;r++)if("hidden"===t[r].mode)e=r;else if("showing"===t[r].mode){e=r;break}this.subtitleTrack!==e&&(this.subtitleTrack=e)}}}]),r}(or);function ma(e){for(var t=[],r=0;r<e.length;r++){var i=e[r];"subtitles"!==i.kind&&"captions"!==i.kind||!i.label||t.push(e[r])}return t}var ya=function(){function e(t){y(this,e),this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=t}return k(e,[{key:"append",value:function(e,t){var r=this.queues[t];r.push(e),1===r.length&&this.buffers[t]&&this.executeNext(t)}},{key:"insertAbort",value:function(e,t){this.queues[t].unshift(e),this.executeNext(t)}},{key:"appendBlocker",value:function(e){var t,r=new Promise((function(e){t=e})),i={execute:t,onStart:function(){},onComplete:function(){},onError:function(){}};return this.append(i,e),r}},{key:"executeNext",value:function(e){var t=this.buffers,r=this.queues,i=t[e],a=r[e];if(a.length){var n=a[0];try{n.execute()}catch(t){K.warn("[buffer-operation-queue]: Unhandled exception executing the current operation"),n.onError(t),null!=i&&i.updating||(a.shift(),this.executeNext(e))}}}},{key:"shiftAndExecuteNext",value:function(e){this.queues[e].shift(),this.executeNext(e)}},{key:"current",value:function(e){return this.queues[e][0]}}]),e}(),pa=it(),ka=/([ha]vc.)(?:\.[^.,]+)+/,Ta=function(){function e(t){var r=this;y(this,e),this.details=null,this._objectUrl=null,this.operationQueue=void 0,this.listeners=void 0,this.hls=void 0,this.bufferCodecEventsExpected=0,this._bufferCodecEventsTotal=0,this.media=null,this.mediaSource=null,this.lastMpegAudioChunk=null,this.appendError=0,this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this._onMediaSourceOpen=function(){var e=r.media,t=r.mediaSource;K.log("[buffer-controller]: Media source opened"),e&&(e.removeEventListener("emptied",r._onMediaEmptied),r.updateMediaElementDuration(),r.hls.trigger(O.MEDIA_ATTACHED,{media:e})),t&&t.removeEventListener("sourceopen",r._onMediaSourceOpen),r.checkPendingTracks()},this._onMediaSourceClose=function(){K.log("[buffer-controller]: Media source closed")},this._onMediaSourceEnded=function(){K.log("[buffer-controller]: Media source ended")},this._onMediaEmptied=function(){var e=r.media,t=r._objectUrl;e&&e.src!==t&&K.error("Media element src was set while attaching MediaSource (".concat(t," > ").concat(e.src,")"))},this.hls=t,this._initSourceBuffer(),this.registerListeners()}return k(e,[{key:"hasSourceTypes",value:function(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0}},{key:"destroy",value:function(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null}},{key:"registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.MANIFEST_PARSED,this.onManifestParsed,this),e.on(O.BUFFER_RESET,this.onBufferReset,this),e.on(O.BUFFER_APPENDING,this.onBufferAppending,this),e.on(O.BUFFER_CODECS,this.onBufferCodecs,this),e.on(O.BUFFER_EOS,this.onBufferEos,this),e.on(O.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(O.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(O.FRAG_PARSED,this.onFragParsed,this),e.on(O.FRAG_CHANGED,this.onFragChanged,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_PARSED,this.onManifestParsed,this),e.off(O.BUFFER_RESET,this.onBufferReset,this),e.off(O.BUFFER_APPENDING,this.onBufferAppending,this),e.off(O.BUFFER_CODECS,this.onBufferCodecs,this),e.off(O.BUFFER_EOS,this.onBufferEos,this),e.off(O.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(O.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(O.FRAG_PARSED,this.onFragParsed,this),e.off(O.FRAG_CHANGED,this.onFragChanged,this)}},{key:"_initSourceBuffer",value:function(){this.sourceBuffer={},this.operationQueue=new ya(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.lastMpegAudioChunk=null}},{key:"onManifestLoading",value:function(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null}},{key:"onManifestParsed",value:function(e,t){var r=2;(t.audio&&!t.video||!t.altAudio)&&(r=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=r,K.log("".concat(this.bufferCodecEventsExpected," bufferCodec event(s) expected"))}},{key:"onMediaAttaching",value:function(e,t){var r=this.media=t.media;if(r&&pa){var i=this.mediaSource=new pa;i.addEventListener("sourceopen",this._onMediaSourceOpen),i.addEventListener("sourceended",this._onMediaSourceEnded),i.addEventListener("sourceclose",this._onMediaSourceClose),r.src=self.URL.createObjectURL(i),this._objectUrl=r.src,r.addEventListener("emptied",this._onMediaEmptied)}}},{key:"onMediaDetaching",value:function(){var e=this.media,t=this.mediaSource,r=this._objectUrl;if(t){if(K.log("[buffer-controller]: media source detaching"),"open"===t.readyState)try{t.endOfStream()}catch(e){K.warn("[buffer-controller]: onMediaDetaching: ".concat(e.message," while calling endOfStream"))}this.onBufferReset(),t.removeEventListener("sourceopen",this._onMediaSourceOpen),t.removeEventListener("sourceended",this._onMediaSourceEnded),t.removeEventListener("sourceclose",this._onMediaSourceClose),e&&(e.removeEventListener("emptied",this._onMediaEmptied),r&&self.URL.revokeObjectURL(r),e.src===r?(e.removeAttribute("src"),e.load()):K.warn("[buffer-controller]: media.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={}}this.hls.trigger(O.MEDIA_DETACHED,void 0)}},{key:"onBufferReset",value:function(){var e=this;this.getSourceBufferTypes().forEach((function(t){var r=e.sourceBuffer[t];try{r&&(e.removeBufferListeners(t),e.mediaSource&&e.mediaSource.removeSourceBuffer(r),e.sourceBuffer[t]=void 0)}catch(e){K.warn("[buffer-controller]: Failed to reset the ".concat(t," buffer"),e)}})),this._initSourceBuffer()}},{key:"onBufferCodecs",value:function(e,t){var r=this,i=this.getSourceBufferTypes().length;Object.keys(t).forEach((function(e){if(i){var a=r.tracks[e];if(a&&"function"==typeof a.buffer.changeType){var n=t[e],s=n.id,o=n.codec,l=n.levelCodec,u=n.container,c=n.metadata,h=(a.levelCodec||a.codec).replace(ka,"$1"),d=(l||o).replace(ka,"$1");if(h!==d){var f="".concat(u,";codecs=").concat(l||o);r.appendChangeType(e,f),K.log("[buffer-controller]: switching codec ".concat(h," to ").concat(d)),r.tracks[e]={buffer:a.buffer,codec:o,container:u,levelCodec:l,metadata:c,id:s}}}}else r.pendingTracks[e]=t[e]})),i||(this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks())}},{key:"appendChangeType",value:function(e,t){var r=this,i=this.operationQueue,a={execute:function(){var a=r.sourceBuffer[e];a&&(K.log("[buffer-controller]: changing ".concat(e," sourceBuffer type to ").concat(t)),a.changeType(t)),i.shiftAndExecuteNext(e)},onStart:function(){},onComplete:function(){},onError:function(t){K.warn("[buffer-controller]: Failed to change ".concat(e," SourceBuffer type"),t)}};i.append(a,e)}},{key:"onBufferAppending",value:function(e,t){var r=this,i=this.hls,a=this.operationQueue,n=this.tracks,s=t.data,o=t.type,l=t.frag,u=t.part,c=t.chunkMeta,h=c.buffering[o],d=self.performance.now();h.start=d;var f=l.stats.buffering,v=u?u.stats.buffering:null;0===f.start&&(f.start=d),v&&0===v.start&&(v.start=d);var g=n.audio,m=!1;"audio"===o&&"audio/mpeg"===(null==g?void 0:g.container)&&(m=!this.lastMpegAudioChunk||1===c.id||this.lastMpegAudioChunk.sn!==c.sn,this.lastMpegAudioChunk=c);var y=l.start,p={execute:function(){if(h.executeStart=self.performance.now(),m){var e=r.sourceBuffer[o];if(e){var t=y-e.timestampOffset;Math.abs(t)>=.1&&(K.log("[buffer-controller]: Updating audio SourceBuffer timestampOffset to ".concat(y," (delta: ").concat(t,") sn: ").concat(l.sn,")")),e.timestampOffset=y)}}r.appendExecutor(s,o)},onStart:function(){},onComplete:function(){var e=self.performance.now();h.executeEnd=h.end=e,0===f.first&&(f.first=e),v&&0===v.first&&(v.first=e);var t=r.sourceBuffer,i={};for(var a in t)i[a]=br.getBuffered(t[a]);r.appendError=0,r.hls.trigger(O.BUFFER_APPENDED,{type:o,frag:l,part:u,chunkMeta:c,parent:l.type,timeRanges:i})},onError:function(e){K.error("[buffer-controller]: Error encountered while trying to append to the ".concat(o," SourceBuffer"),e);var t={type:M.MEDIA_ERROR,parent:l.type,details:N.BUFFER_APPEND_ERROR,frag:l,part:u,chunkMeta:c,error:e,err:e,fatal:!1};e.code===DOMException.QUOTA_EXCEEDED_ERR?t.details=N.BUFFER_FULL_ERROR:(r.appendError++,t.details=N.BUFFER_APPEND_ERROR,r.appendError>i.config.appendErrorMaxRetry&&(K.error("[buffer-controller]: Failed ".concat(i.config.appendErrorMaxRetry," times to append segment in sourceBuffer")),t.fatal=!0)),i.trigger(O.ERROR,t)}};a.append(p,o)}},{key:"onBufferFlushing",value:function(e,t){var r=this,i=this.operationQueue,a=function(e){return{execute:r.removeExecutor.bind(r,e,t.startOffset,t.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(O.BUFFER_FLUSHED,{type:e})},onError:function(t){K.warn("[buffer-controller]: Failed to remove from ".concat(e," SourceBuffer"),t)}}};t.type?i.append(a(t.type),t.type):this.getSourceBufferTypes().forEach((function(e){i.append(a(e),e)}))}},{key:"onFragParsed",value:function(e,t){var r=this,i=t.frag,a=t.part,n=[],s=a?a.elementaryStreams:i.elementaryStreams;s[Q]?n.push("audiovideo"):(s[X]&&n.push("audio"),s[z]&&n.push("video")),0===n.length&&K.warn("Fragments must have at least one ElementaryStreamType set. type: ".concat(i.type," level: ").concat(i.level," sn: ").concat(i.sn)),this.blockBuffers((function(){var e=self.performance.now();i.stats.buffering.end=e,a&&(a.stats.buffering.end=e);var t=a?a.stats:i.stats;r.hls.trigger(O.FRAG_BUFFERED,{frag:i,part:a,stats:t,id:i.type})}),n)}},{key:"onFragChanged",value:function(e,t){this.flushBackBuffer()}},{key:"onBufferEos",value:function(e,t){var r=this;this.getSourceBufferTypes().reduce((function(e,i){var a=r.sourceBuffer[i];return!a||t.type&&t.type!==i||(a.ending=!0,a.ended||(a.ended=!0,K.log("[buffer-controller]: ".concat(i," sourceBuffer now EOS")))),e&&!(a&&!a.ended)}),!0)&&(K.log("[buffer-controller]: Queueing mediaSource.endOfStream()"),this.blockBuffers((function(){r.getSourceBufferTypes().forEach((function(e){var t=r.sourceBuffer[e];t&&(t.ending=!1)}));var e=r.mediaSource;e&&"open"===e.readyState?(K.log("[buffer-controller]: Calling mediaSource.endOfStream()"),e.endOfStream()):e&&K.info("[buffer-controller]: Could not call mediaSource.endOfStream(). mediaSource.readyState: ".concat(e.readyState))})))}},{key:"onLevelUpdated",value:function(e,t){var r=t.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())}},{key:"flushBackBuffer",value:function(){var e=this.hls,t=this.details,r=this.media,i=this.sourceBuffer;if(r&&null!==t){var a=this.getSourceBufferTypes();if(a.length){var n=t.live&&null!==e.config.liveBackBufferLength?e.config.liveBackBufferLength:e.config.backBufferLength;if(F(n)&&!(n<0)){var s=r.currentTime,o=t.levelTargetDuration,l=Math.max(n,o),u=Math.floor(s/o)*o-l;a.forEach((function(r){var a=i[r];if(a){var n=br.getBuffered(a);if(n.length>0&&u>n.start(0)){if(e.trigger(O.BACK_BUFFER_REACHED,{bufferEnd:u}),t.live)e.trigger(O.LIVE_BACK_BUFFER_REACHED,{bufferEnd:u});else if(a.ended&&n.end(n.length-1)-s<2*o)return void K.info("[buffer-controller]: Cannot flush ".concat(r," back buffer while SourceBuffer is in ended state"));e.trigger(O.BUFFER_FLUSHING,{startOffset:0,endOffset:u,type:r})}}}))}}}}},{key:"updateMediaElementDuration",value:function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var e=this.details,t=this.hls,r=this.media,i=this.mediaSource,a=e.fragments[0].start+e.totalduration,n=r.duration,s=F(i.duration)?i.duration:0;e.live&&t.config.liveDurationInfinity?(K.log("[buffer-controller]: Media Source duration is set to Infinity"),i.duration=1/0,this.updateSeekableRange(e)):(a>s&&a>n||!F(n))&&(K.log("[buffer-controller]: Updating Media Source duration to ".concat(a.toFixed(3))),i.duration=a)}}},{key:"updateSeekableRange",value:function(e){var t=this.mediaSource,r=e.fragments;if(r.length&&e.live&&null!=t&&t.setLiveSeekableRange){var i=Math.max(0,r[0].start),a=Math.max(i,i+e.totalduration);t.setLiveSeekableRange(i,a)}}},{key:"checkPendingTracks",value:function(){var e=this.bufferCodecEventsExpected,t=this.operationQueue,r=this.pendingTracks,i=Object.keys(r).length;if(i&&!e||2===i){this.createSourceBuffers(r),this.pendingTracks={};var a=this.getSourceBufferTypes();if(a.length)this.hls.trigger(O.BUFFER_CREATED,{tracks:this.tracks}),a.forEach((function(e){t.executeNext(e)}));else{var n=new Error("could not create source buffer for media codec(s)");this.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:n,reason:n.message})}}}},{key:"createSourceBuffers",value:function(e){var t=this.sourceBuffer,r=this.mediaSource;if(!r)throw Error("createSourceBuffers called when mediaSource was null");for(var i in e)if(!t[i]){var a=e[i];if(!a)throw Error("source buffer exists for track ".concat(i,", however track does not"));var n=a.levelCodec||a.codec,s="".concat(a.container,";codecs=").concat(n);K.log("[buffer-controller]: creating sourceBuffer(".concat(s,")"));try{var o=t[i]=r.addSourceBuffer(s),l=i;this.addBufferListener(l,"updatestart",this._onSBUpdateStart),this.addBufferListener(l,"updateend",this._onSBUpdateEnd),this.addBufferListener(l,"error",this._onSBUpdateError),this.tracks[i]={buffer:o,codec:n,container:a.container,levelCodec:a.levelCodec,metadata:a.metadata,id:a.id}}catch(e){K.error("[buffer-controller]: error while trying to add sourceBuffer: ".concat(e.message)),this.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:e,mimeType:s})}}}},{key:"_onSBUpdateStart",value:function(e){this.operationQueue.current(e).onStart()}},{key:"_onSBUpdateEnd",value:function(e){var t=this.operationQueue;t.current(e).onComplete(),t.shiftAndExecuteNext(e)}},{key:"_onSBUpdateError",value:function(e,t){var r=new Error("".concat(e," SourceBuffer error"));K.error("[buffer-controller]: ".concat(r),t),this.hls.trigger(O.ERROR,{type:M.MEDIA_ERROR,details:N.BUFFER_APPENDING_ERROR,error:r,fatal:!1});var i=this.operationQueue.current(e);i&&i.onError(t)}},{key:"removeExecutor",value:function(e,t,r){var i=this.media,a=this.mediaSource,n=this.operationQueue,s=this.sourceBuffer[e];if(!i||!a||!s)return K.warn("[buffer-controller]: Attempting to remove from the ".concat(e," SourceBuffer, but it does not exist")),void n.shiftAndExecuteNext(e);var o=F(i.duration)?i.duration:1/0,l=F(a.duration)?a.duration:1/0,u=Math.max(0,t),c=Math.min(r,o,l);c>u&&!s.ending?(s.ended=!1,K.log("[buffer-controller]: Removing [".concat(u,",").concat(c,"] from the ").concat(e," SourceBuffer")),s.remove(u,c)):n.shiftAndExecuteNext(e)}},{key:"appendExecutor",value:function(e,t){var r=this.operationQueue,i=this.sourceBuffer[t];if(!i)return K.warn("[buffer-controller]: Attempting to append to the ".concat(t," SourceBuffer, but it does not exist")),void r.shiftAndExecuteNext(t);i.ended=!1,i.appendBuffer(e)}},{key:"blockBuffers",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.getSourceBufferTypes();if(!r.length)return K.log("[buffer-controller]: Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(e);var i=this.operationQueue,a=r.map((function(e){return i.appendBlocker(e)}));Promise.all(a).then((function(){e(),r.forEach((function(e){var r=t.sourceBuffer[e];null!=r&&r.updating||i.shiftAndExecuteNext(e)}))}))}},{key:"getSourceBufferTypes",value:function(){return Object.keys(this.sourceBuffer)}},{key:"addBufferListener",value:function(e,t,r){var i=this.sourceBuffer[e];if(i){var a=r.bind(this,e);this.listeners[e].push({event:t,listener:a}),i.addEventListener(t,a)}}},{key:"removeBufferListeners",value:function(e){var t=this.sourceBuffer[e];t&&this.listeners[e].forEach((function(e){t.removeEventListener(e.event,e.listener)}))}}]),e}(),Ea={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,128:174,129:176,130:189,131:191,132:8482,133:162,134:163,135:9834,136:224,137:32,138:232,139:226,140:234,141:238,142:244,143:251,144:193,145:201,146:211,147:218,148:220,149:252,150:8216,151:161,152:42,153:8217,154:9473,155:169,156:8480,157:8226,158:8220,159:8221,160:192,161:194,162:199,163:200,164:202,165:203,166:235,167:206,168:207,169:239,170:212,171:217,172:249,173:219,174:171,175:187,176:195,177:227,178:205,179:204,180:236,181:210,182:242,183:213,184:245,185:123,186:125,187:92,188:94,189:95,190:124,191:8764,192:196,193:228,194:214,195:246,196:223,197:165,198:164,199:9475,200:197,201:229,202:216,203:248,204:9487,205:9491,206:9495,207:9499},Sa=function(e){var t=e;return Ea.hasOwnProperty(e)&&(t=Ea[e]),String.fromCharCode(t)},La=15,Aa=100,Ra={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},ba={17:2,18:4,21:6,22:8,23:10,19:13,20:15},Da={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},Ia={25:2,26:4,29:6,30:8,31:10,27:13,28:15},wa=["white","green","blue","cyan","red","yellow","magenta","black","transparent"],Ca=function(){function e(){y(this,e),this.time=null,this.verboseLevel=0}return k(e,[{key:"log",value:function(e,t){if(this.verboseLevel>=e){var r="function"==typeof t?t():t;K.log("".concat(this.time," [").concat(e,"] ").concat(r))}}}]),e}(),_a=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].toString(16));return t},Pa=function(){function e(t,r,i,a,n){y(this,e),this.foreground=void 0,this.underline=void 0,this.italics=void 0,this.background=void 0,this.flash=void 0,this.foreground=t||"white",this.underline=r||!1,this.italics=i||!1,this.background=a||"black",this.flash=n||!1}return k(e,[{key:"reset",value:function(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1}},{key:"setStyles",value:function(e){for(var t=["foreground","underline","italics","background","flash"],r=0;r<t.length;r++){var i=t[r];e.hasOwnProperty(i)&&(this[i]=e[i])}}},{key:"isDefault",value:function(){return"white"===this.foreground&&!this.underline&&!this.italics&&"black"===this.background&&!this.flash}},{key:"equals",value:function(e){return this.foreground===e.foreground&&this.underline===e.underline&&this.italics===e.italics&&this.background===e.background&&this.flash===e.flash}},{key:"copy",value:function(e){this.foreground=e.foreground,this.underline=e.underline,this.italics=e.italics,this.background=e.background,this.flash=e.flash}},{key:"toString",value:function(){return"color="+this.foreground+", underline="+this.underline+", italics="+this.italics+", background="+this.background+", flash="+this.flash}}]),e}(),xa=function(){function e(t,r,i,a,n,s){y(this,e),this.uchar=void 0,this.penState=void 0,this.uchar=t||" ",this.penState=new Pa(r,i,a,n,s)}return k(e,[{key:"reset",value:function(){this.uchar=" ",this.penState.reset()}},{key:"setChar",value:function(e,t){this.uchar=e,this.penState.copy(t)}},{key:"setPenState",value:function(e){this.penState.copy(e)}},{key:"equals",value:function(e){return this.uchar===e.uchar&&this.penState.equals(e.penState)}},{key:"copy",value:function(e){this.uchar=e.uchar,this.penState.copy(e.penState)}},{key:"isEmpty",value:function(){return" "===this.uchar&&this.penState.isDefault()}}]),e}(),Fa=function(){function e(t){y(this,e),this.chars=void 0,this.pos=void 0,this.currPenState=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chars=[];for(var r=0;r<Aa;r++)this.chars.push(new xa);this.logger=t,this.pos=0,this.currPenState=new Pa}return k(e,[{key:"equals",value:function(e){for(var t=!0,r=0;r<Aa;r++)if(!this.chars[r].equals(e.chars[r])){t=!1;break}return t}},{key:"copy",value:function(e){for(var t=0;t<Aa;t++)this.chars[t].copy(e.chars[t])}},{key:"isEmpty",value:function(){for(var e=!0,t=0;t<Aa;t++)if(!this.chars[t].isEmpty()){e=!1;break}return e}},{key:"setCursor",value:function(e){this.pos!==e&&(this.pos=e),this.pos<0?(this.logger.log(3,"Negative cursor position "+this.pos),this.pos=0):this.pos>Aa&&(this.logger.log(3,"Too large cursor position "+this.pos),this.pos=Aa)}},{key:"moveCursor",value:function(e){var t=this.pos+e;if(e>1)for(var r=this.pos+1;r<t+1;r++)this.chars[r].setPenState(this.currPenState);this.setCursor(t)}},{key:"backSpace",value:function(){this.moveCursor(-1),this.chars[this.pos].setChar(" ",this.currPenState)}},{key:"insertChar",value:function(e){var t=this;e>=144&&this.backSpace();var r=Sa(e);this.pos>=Aa?this.logger.log(0,(function(){return"Cannot insert "+e.toString(16)+" ("+r+") at position "+t.pos+". Skipping it!"})):(this.chars[this.pos].setChar(r,this.currPenState),this.moveCursor(1))}},{key:"clearFromPos",value:function(e){var t;for(t=e;t<Aa;t++)this.chars[t].reset()}},{key:"clear",value:function(){this.clearFromPos(0),this.pos=0,this.currPenState.reset()}},{key:"clearToEndOfRow",value:function(){this.clearFromPos(this.pos)}},{key:"getTextString",value:function(){for(var e=[],t=!0,r=0;r<Aa;r++){var i=this.chars[r].uchar;" "!==i&&(t=!1),e.push(i)}return t?"":e.join("")}},{key:"setPenStyles",value:function(e){this.currPenState.setStyles(e),this.chars[this.pos].setPenState(this.currPenState)}}]),e}(),Oa=function(){function e(t){y(this,e),this.rows=void 0,this.currRow=void 0,this.nrRollUpRows=void 0,this.lastOutputScreen=void 0,this.logger=void 0,this.rows=[];for(var r=0;r<La;r++)this.rows.push(new Fa(t));this.logger=t,this.currRow=14,this.nrRollUpRows=null,this.lastOutputScreen=null,this.reset()}return k(e,[{key:"reset",value:function(){for(var e=0;e<La;e++)this.rows[e].clear();this.currRow=14}},{key:"equals",value:function(e){for(var t=!0,r=0;r<La;r++)if(!this.rows[r].equals(e.rows[r])){t=!1;break}return t}},{key:"copy",value:function(e){for(var t=0;t<La;t++)this.rows[t].copy(e.rows[t])}},{key:"isEmpty",value:function(){for(var e=!0,t=0;t<La;t++)if(!this.rows[t].isEmpty()){e=!1;break}return e}},{key:"backSpace",value:function(){this.rows[this.currRow].backSpace()}},{key:"clearToEndOfRow",value:function(){this.rows[this.currRow].clearToEndOfRow()}},{key:"insertChar",value:function(e){this.rows[this.currRow].insertChar(e)}},{key:"setPen",value:function(e){this.rows[this.currRow].setPenStyles(e)}},{key:"moveCursor",value:function(e){this.rows[this.currRow].moveCursor(e)}},{key:"setCursor",value:function(e){this.logger.log(2,"setCursor: "+e),this.rows[this.currRow].setCursor(e)}},{key:"setPAC",value:function(e){this.logger.log(2,(function(){return"pacData = "+JSON.stringify(e)}));var t=e.row-1;if(this.nrRollUpRows&&t<this.nrRollUpRows-1&&(t=this.nrRollUpRows-1),this.nrRollUpRows&&this.currRow!==t){for(var r=0;r<La;r++)this.rows[r].clear();var i=this.currRow+1-this.nrRollUpRows,a=this.lastOutputScreen;if(a){var n=a.rows[i].cueStartTime,s=this.logger.time;if(n&&null!==s&&n<s)for(var o=0;o<this.nrRollUpRows;o++)this.rows[t-this.nrRollUpRows+o+1].copy(a.rows[i+o])}}this.currRow=t;var l=this.rows[this.currRow];if(null!==e.indent){var u=e.indent,c=Math.max(u-1,0);l.setCursor(e.indent),e.color=l.chars[c].penState.foreground}var h={foreground:e.color,underline:e.underline,italics:e.italics,background:"black",flash:!1};this.setPen(h)}},{key:"setBkgData",value:function(e){this.logger.log(2,(function(){return"bkgData = "+JSON.stringify(e)})),this.backSpace(),this.setPen(e),this.insertChar(32)}},{key:"setRollUpRows",value:function(e){this.nrRollUpRows=e}},{key:"rollUp",value:function(){var e=this;if(null!==this.nrRollUpRows){this.logger.log(1,(function(){return e.getDisplayText()}));var t=this.currRow+1-this.nrRollUpRows,r=this.rows.splice(t,1)[0];r.clear(),this.rows.splice(this.currRow,0,r),this.logger.log(2,"Rolling up")}else this.logger.log(3,"roll_up but nrRollUpRows not set yet")}},{key:"getDisplayText",value:function(e){e=e||!1;for(var t=[],r="",i=-1,a=0;a<La;a++){var n=this.rows[a].getTextString();n&&(i=a+1,e?t.push("Row "+i+": '"+n+"'"):t.push(n.trim()))}return t.length>0&&(r=e?"["+t.join(" | ")+"]":t.join("\n")),r}},{key:"getTextAndFormat",value:function(){return this.rows}}]),e}(),Ma=function(){function e(t,r,i){y(this,e),this.chNr=void 0,this.outputFilter=void 0,this.mode=void 0,this.verbose=void 0,this.displayedMemory=void 0,this.nonDisplayedMemory=void 0,this.lastOutputScreen=void 0,this.currRollUpRow=void 0,this.writeScreen=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chNr=t,this.outputFilter=r,this.mode=null,this.verbose=0,this.displayedMemory=new Oa(i),this.nonDisplayedMemory=new Oa(i),this.lastOutputScreen=new Oa(i),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=i}return k(e,[{key:"reset",value:function(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.outputFilter.reset(),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null}},{key:"getHandler",value:function(){return this.outputFilter}},{key:"setHandler",value:function(e){this.outputFilter=e}},{key:"setPAC",value:function(e){this.writeScreen.setPAC(e)}},{key:"setBkgData",value:function(e){this.writeScreen.setBkgData(e)}},{key:"setMode",value:function(e){e!==this.mode&&(this.mode=e,this.logger.log(2,(function(){return"MODE="+e})),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=e)}},{key:"insertChars",value:function(e){for(var t=this,r=0;r<e.length;r++)this.writeScreen.insertChar(e[r]);var i=this.writeScreen===this.displayedMemory?"DISP":"NON_DISP";this.logger.log(2,(function(){return i+": "+t.writeScreen.getDisplayText(!0)})),"MODE_PAINT-ON"!==this.mode&&"MODE_ROLL-UP"!==this.mode||(this.logger.log(1,(function(){return"DISPLAYED: "+t.displayedMemory.getDisplayText(!0)})),this.outputDataUpdate())}},{key:"ccRCL",value:function(){this.logger.log(2,"RCL - Resume Caption Loading"),this.setMode("MODE_POP-ON")}},{key:"ccBS",value:function(){this.logger.log(2,"BS - BackSpace"),"MODE_TEXT"!==this.mode&&(this.writeScreen.backSpace(),this.writeScreen===this.displayedMemory&&this.outputDataUpdate())}},{key:"ccAOF",value:function(){}},{key:"ccAON",value:function(){}},{key:"ccDER",value:function(){this.logger.log(2,"DER- Delete to End of Row"),this.writeScreen.clearToEndOfRow(),this.outputDataUpdate()}},{key:"ccRU",value:function(e){this.logger.log(2,"RU("+e+") - Roll Up"),this.writeScreen=this.displayedMemory,this.setMode("MODE_ROLL-UP"),this.writeScreen.setRollUpRows(e)}},{key:"ccFON",value:function(){this.logger.log(2,"FON - Flash On"),this.writeScreen.setPen({flash:!0})}},{key:"ccRDC",value:function(){this.logger.log(2,"RDC - Resume Direct Captioning"),this.setMode("MODE_PAINT-ON")}},{key:"ccTR",value:function(){this.logger.log(2,"TR"),this.setMode("MODE_TEXT")}},{key:"ccRTD",value:function(){this.logger.log(2,"RTD"),this.setMode("MODE_TEXT")}},{key:"ccEDM",value:function(){this.logger.log(2,"EDM - Erase Displayed Memory"),this.displayedMemory.reset(),this.outputDataUpdate(!0)}},{key:"ccCR",value:function(){this.logger.log(2,"CR - Carriage Return"),this.writeScreen.rollUp(),this.outputDataUpdate(!0)}},{key:"ccENM",value:function(){this.logger.log(2,"ENM - Erase Non-displayed Memory"),this.nonDisplayedMemory.reset()}},{key:"ccEOC",value:function(){var e=this;if(this.logger.log(2,"EOC - End Of Caption"),"MODE_POP-ON"===this.mode){var t=this.displayedMemory;this.displayedMemory=this.nonDisplayedMemory,this.nonDisplayedMemory=t,this.writeScreen=this.nonDisplayedMemory,this.logger.log(1,(function(){return"DISP: "+e.displayedMemory.getDisplayText()}))}this.outputDataUpdate(!0)}},{key:"ccTO",value:function(e){this.logger.log(2,"TO("+e+") - Tab Offset"),this.writeScreen.moveCursor(e)}},{key:"ccMIDROW",value:function(e){var t={flash:!1};if(t.underline=e%2==1,t.italics=e>=46,t.italics)t.foreground="white";else{var r=Math.floor(e/2)-16;t.foreground=["white","green","blue","cyan","red","yellow","magenta"][r]}this.logger.log(2,"MIDROW: "+JSON.stringify(t)),this.writeScreen.setPen(t)}},{key:"outputDataUpdate",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.logger.time;null!==t&&this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?this.displayedMemory.equals(this.lastOutputScreen)||(this.outputFilter.newCue(this.cueStartTime,t,this.lastOutputScreen),e&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:t):this.cueStartTime=t,this.lastOutputScreen.copy(this.displayedMemory))}},{key:"cueSplitAtTime",value:function(e){this.outputFilter&&(this.displayedMemory.isEmpty()||(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,e,this.displayedMemory),this.cueStartTime=e))}}]),e}(),Na=function(){function e(t,r,i){y(this,e),this.channels=void 0,this.currentChannel=0,this.cmdHistory=void 0,this.logger=void 0;var a=new Ca;this.channels=[null,new Ma(t,r,a),new Ma(t+1,i,a)],this.cmdHistory={a:null,b:null},this.logger=a}return k(e,[{key:"getHandler",value:function(e){return this.channels[e].getHandler()}},{key:"setHandler",value:function(e,t){this.channels[e].setHandler(t)}},{key:"addData",value:function(e,t){var r,i,a,n=!1;this.logger.time=e;for(var s=0;s<t.length;s+=2)if(i=127&t[s],a=127&t[s+1],0!==i||0!==a){if(this.logger.log(3,"["+_a([t[s],t[s+1]])+"] -> ("+_a([i,a])+")"),(r=this.parseCmd(i,a))||(r=this.parseMidrow(i,a)),r||(r=this.parsePAC(i,a)),r||(r=this.parseBackgroundAttributes(i,a)),!r&&(n=this.parseChars(i,a))){var o=this.currentChannel;o&&o>0?this.channels[o].insertChars(n):this.logger.log(2,"No channel found yet. TEXT-MODE?")}r||n||this.logger.log(2,"Couldn't parse cleaned data "+_a([i,a])+" orig: "+_a([t[s],t[s+1]]))}}},{key:"parseCmd",value:function(e,t){var r=this.cmdHistory;if(!((20===e||28===e||21===e||29===e)&&t>=32&&t<=47||(23===e||31===e)&&t>=33&&t<=35))return!1;if(Ba(e,t,r))return Ua(null,null,r),this.logger.log(3,"Repeated command ("+_a([e,t])+") is dropped"),!0;var i=20===e||21===e||23===e?1:2,a=this.channels[i];return 20===e||21===e||28===e||29===e?32===t?a.ccRCL():33===t?a.ccBS():34===t?a.ccAOF():35===t?a.ccAON():36===t?a.ccDER():37===t?a.ccRU(2):38===t?a.ccRU(3):39===t?a.ccRU(4):40===t?a.ccFON():41===t?a.ccRDC():42===t?a.ccTR():43===t?a.ccRTD():44===t?a.ccEDM():45===t?a.ccCR():46===t?a.ccENM():47===t&&a.ccEOC():a.ccTO(t-32),Ua(e,t,r),this.currentChannel=i,!0}},{key:"parseMidrow",value:function(e,t){var r=0;if((17===e||25===e)&&t>=32&&t<=47){if((r=17===e?1:2)!==this.currentChannel)return this.logger.log(0,"Mismatch channel in midrow parsing"),!1;var i=this.channels[r];return!!i&&(i.ccMIDROW(t),this.logger.log(3,"MIDROW ("+_a([e,t])+")"),!0)}return!1}},{key:"parsePAC",value:function(e,t){var r,i=this.cmdHistory;if(!((e>=17&&e<=23||e>=25&&e<=31)&&t>=64&&t<=127||(16===e||24===e)&&t>=64&&t<=95))return!1;if(Ba(e,t,i))return Ua(null,null,i),!0;var a=e<=23?1:2;r=t>=64&&t<=95?1===a?Ra[e]:Da[e]:1===a?ba[e]:Ia[e];var n=this.channels[a];return!!n&&(n.setPAC(this.interpretPAC(r,t)),Ua(e,t,i),this.currentChannel=a,!0)}},{key:"interpretPAC",value:function(e,t){var r,i={color:null,italics:!1,indent:null,underline:!1,row:e};return r=t>95?t-96:t-64,i.underline=1==(1&r),r<=13?i.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(r/2)]:r<=15?(i.italics=!0,i.color="white"):i.indent=4*Math.floor((r-16)/2),i}},{key:"parseChars",value:function(e,t){var r,i,a=null,n=null;if(e>=25?(r=2,n=e-8):(r=1,n=e),n>=17&&n<=19?(i=17===n?t+80:18===n?t+112:t+144,this.logger.log(2,"Special char '"+Sa(i)+"' in channel "+r),a=[i]):e>=32&&e<=127&&(a=0===t?[e]:[e,t]),a){var s=_a(a);this.logger.log(3,"Char codes = "+s.join(",")),Ua(e,t,this.cmdHistory)}return a}},{key:"parseBackgroundAttributes",value:function(e,t){var r;if(!((16===e||24===e)&&t>=32&&t<=47||(23===e||31===e)&&t>=45&&t<=47))return!1;var i={};16===e||24===e?(r=Math.floor((t-32)/2),i.background=wa[r],t%2==1&&(i.background=i.background+"_semi")):45===t?i.background="transparent":(i.foreground="black",47===t&&(i.underline=!0));var a=e<=23?1:2;return this.channels[a].setBkgData(i),Ua(e,t,this.cmdHistory),!0}},{key:"reset",value:function(){for(var e=0;e<Object.keys(this.channels).length;e++){var t=this.channels[e];t&&t.reset()}this.cmdHistory={a:null,b:null}}},{key:"cueSplitAtTime",value:function(e){for(var t=0;t<this.channels.length;t++){var r=this.channels[t];r&&r.cueSplitAtTime(e)}}}]),e}();function Ua(e,t,r){r.a=e,r.b=t}function Ba(e,t,r){return r.a===e&&r.b===t}var Ga=function(){function e(t,r){y(this,e),this.timelineController=void 0,this.cueRanges=[],this.trackName=void 0,this.startTime=null,this.endTime=null,this.screen=null,this.timelineController=t,this.trackName=r}return k(e,[{key:"dispatchCue",value:function(){null!==this.startTime&&(this.timelineController.addCues(this.trackName,this.startTime,this.endTime,this.screen,this.cueRanges),this.startTime=null)}},{key:"newCue",value:function(e,t,r){(null===this.startTime||this.startTime>e)&&(this.startTime=e),this.endTime=t,this.screen=r,this.timelineController.createCaptionsTrack(this.trackName)}},{key:"reset",value:function(){this.cueRanges=[],this.startTime=null}}]),e}(),Ka=function(){if("undefined"!=typeof self&&self.VTTCue)return self.VTTCue;var e=["","lr","rl"],t=["start","middle","end","left","right"];function r(e,t){if("string"!=typeof t)return!1;if(!Array.isArray(e))return!1;var r=t.toLowerCase();return!!~e.indexOf(r)&&r}function i(e){return r(t,e)}function a(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var s in n)e[s]=n[s]}return e}function n(t,n,s){var o=this,l={enumerable:!0};o.hasBeenReset=!1;var u="",c=!1,h=t,d=n,f=s,v=null,g="",m=!0,y="auto",p="start",k=50,T="middle",E=50,S="middle";Object.defineProperty(o,"id",a({},l,{get:function(){return u},set:function(e){u=""+e}})),Object.defineProperty(o,"pauseOnExit",a({},l,{get:function(){return c},set:function(e){c=!!e}})),Object.defineProperty(o,"startTime",a({},l,{get:function(){return h},set:function(e){if("number"!=typeof e)throw new TypeError("Start time must be set to a number.");h=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"endTime",a({},l,{get:function(){return d},set:function(e){if("number"!=typeof e)throw new TypeError("End time must be set to a number.");d=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"text",a({},l,{get:function(){return f},set:function(e){f=""+e,this.hasBeenReset=!0}})),Object.defineProperty(o,"region",a({},l,{get:function(){return v},set:function(e){v=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"vertical",a({},l,{get:function(){return g},set:function(t){var i=function(t){return r(e,t)}(t);if(!1===i)throw new SyntaxError("An invalid or illegal string was specified.");g=i,this.hasBeenReset=!0}})),Object.defineProperty(o,"snapToLines",a({},l,{get:function(){return m},set:function(e){m=!!e,this.hasBeenReset=!0}})),Object.defineProperty(o,"line",a({},l,{get:function(){return y},set:function(e){if("number"!=typeof e&&"auto"!==e)throw new SyntaxError("An invalid number or illegal string was specified.");y=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"lineAlign",a({},l,{get:function(){return p},set:function(e){var t=i(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");p=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"position",a({},l,{get:function(){return k},set:function(e){if(e<0||e>100)throw new Error("Position must be between 0 and 100.");k=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"positionAlign",a({},l,{get:function(){return T},set:function(e){var t=i(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");T=t,this.hasBeenReset=!0}})),Object.defineProperty(o,"size",a({},l,{get:function(){return E},set:function(e){if(e<0||e>100)throw new Error("Size must be between 0 and 100.");E=e,this.hasBeenReset=!0}})),Object.defineProperty(o,"align",a({},l,{get:function(){return S},set:function(e){var t=i(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");S=t,this.hasBeenReset=!0}})),o.displayState=void 0}return n.prototype.getCueAsHTML=function(){return self.WebVTT.convertCueToDOMTree(self,this.text)},n}(),Ha=function(){function e(){y(this,e)}return k(e,[{key:"decode",value:function(e,t){if(!e)return"";if("string"!=typeof e)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(e))}}]),e}();function Va(e){function t(e,t,r,i){return 3600*(0|e)+60*(0|t)+(0|r)+parseFloat(i||0)}var r=e.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return r?parseFloat(r[2])>59?t(r[2],r[3],0,r[4]):t(r[1],r[2],r[3],r[4]):null}var Ya=function(){function e(){y(this,e),this.values=Object.create(null)}return k(e,[{key:"set",value:function(e,t){this.get(e)||""===t||(this.values[e]=t)}},{key:"get",value:function(e,t,r){return r?this.has(e)?this.values[e]:t[r]:this.has(e)?this.values[e]:t}},{key:"has",value:function(e){return e in this.values}},{key:"alt",value:function(e,t,r){for(var i=0;i<r.length;++i)if(t===r[i]){this.set(e,t);break}}},{key:"integer",value:function(e,t){/^-?\d+$/.test(t)&&this.set(e,parseInt(t,10))}},{key:"percent",value:function(e,t){if(/^([\d]{1,3})(\.[\d]*)?%$/.test(t)){var r=parseFloat(t);if(r>=0&&r<=100)return this.set(e,r),!0}return!1}}]),e}();function Wa(e,t,r,i){var a=i?e.split(i):[e];for(var n in a)if("string"==typeof a[n]){var s=a[n].split(r);2===s.length&&t(s[0],s[1])}}var ja=new Ka(0,0,""),qa="middle"===ja.align?"middle":"center";function Xa(e,t,r){var i=e;function a(){var t=Va(e);if(null===t)throw new Error("Malformed timestamp: "+i);return e=e.replace(/^[^\sa-zA-Z-]+/,""),t}function n(){e=e.replace(/^\s+/,"")}if(n(),t.startTime=a(),n(),"--\x3e"!==e.slice(0,3))throw new Error("Malformed time stamp (time stamps must be separated by '--\x3e'): "+i);e=e.slice(3),n(),t.endTime=a(),n(),function(e,t){var i=new Ya;Wa(e,(function(e,t){var a;switch(e){case"region":for(var n=r.length-1;n>=0;n--)if(r[n].id===t){i.set(e,r[n].region);break}break;case"vertical":i.alt(e,t,["rl","lr"]);break;case"line":a=t.split(","),i.integer(e,a[0]),i.percent(e,a[0])&&i.set("snapToLines",!1),i.alt(e,a[0],["auto"]),2===a.length&&i.alt("lineAlign",a[1],["start",qa,"end"]);break;case"position":a=t.split(","),i.percent(e,a[0]),2===a.length&&i.alt("positionAlign",a[1],["start",qa,"end","line-left","line-right","auto"]);break;case"size":i.percent(e,t);break;case"align":i.alt(e,t,["start",qa,"end","left","right"])}}),/:/,/\s/),t.region=i.get("region",null),t.vertical=i.get("vertical","");var a=i.get("line","auto");"auto"===a&&-1===ja.line&&(a=-1),t.line=a,t.lineAlign=i.get("lineAlign","start"),t.snapToLines=i.get("snapToLines",!0),t.size=i.get("size",100),t.align=i.get("align",qa);var n=i.get("position","auto");"auto"===n&&50===ja.position&&(n="start"===t.align||"left"===t.align?0:"end"===t.align||"right"===t.align?100:50),t.position=n}(e,t)}function za(e){return e.replace(/<br(?: \/)?>/gi,"\n")}var Qa=function(){function e(){y(this,e),this.state="INITIAL",this.buffer="",this.decoder=new Ha,this.regionList=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}return k(e,[{key:"parse",value:function(e){var t=this;function r(){var e=t.buffer,r=0;for(e=za(e);r<e.length&&"\r"!==e[r]&&"\n"!==e[r];)++r;var i=e.slice(0,r);return"\r"===e[r]&&++r,"\n"===e[r]&&++r,t.buffer=e.slice(r),i}e&&(t.buffer+=t.decoder.decode(e,{stream:!0}));try{var i="";if("INITIAL"===t.state){if(!/\r\n|\n/.test(t.buffer))return this;var a=(i=r()).match(/^()?WEBVTT([ \t].*)?$/);if(null==a||!a[0])throw new Error("Malformed WebVTT signature.");t.state="HEADER"}for(var n=!1;t.buffer;){if(!/\r\n|\n/.test(t.buffer))return this;switch(n?n=!1:i=r(),t.state){case"HEADER":/:/.test(i)?Wa(i,(function(e,t){}),/:/):i||(t.state="ID");continue;case"NOTE":i||(t.state="ID");continue;case"ID":if(/^NOTE($|[ \t])/.test(i)){t.state="NOTE";break}if(!i)continue;if(t.cue=new Ka(0,0,""),t.state="CUE",-1===i.indexOf("--\x3e")){t.cue.id=i;continue}case"CUE":if(!t.cue){t.state="BADCUE";continue}try{Xa(i,t.cue,t.regionList)}catch(e){t.cue=null,t.state="BADCUE";continue}t.state="CUETEXT";continue;case"CUETEXT":var s=-1!==i.indexOf("--\x3e");if(!i||s&&(n=!0)){t.oncue&&t.cue&&t.oncue(t.cue),t.cue=null,t.state="ID";continue}if(null===t.cue)continue;t.cue.text&&(t.cue.text+="\n"),t.cue.text+=i;continue;case"BADCUE":i||(t.state="ID")}}}catch(e){"CUETEXT"===t.state&&t.cue&&t.oncue&&t.oncue(t.cue),t.cue=null,t.state="INITIAL"===t.state?"BADWEBVTT":"BADCUE"}return this}},{key:"flush",value:function(){var e=this;try{if((e.cue||"HEADER"===e.state)&&(e.buffer+="\n\n",e.parse()),"INITIAL"===e.state||"BADWEBVTT"===e.state)throw new Error("Malformed WebVTT signature.")}catch(t){e.onparsingerror&&e.onparsingerror(t)}return e.onflush&&e.onflush(),this}}]),e}(),$a=/\r\n|\n\r|\n|\r/g,Ja=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return e.slice(r,r+t.length)===t},Za=function(e){for(var t=5381,r=e.length;r;)t=33*t^e.charCodeAt(--r);return(t>>>0).toString()};function en(e,t,r){return Za(e.toString())+Za(t.toString())+Za(r)}var tn="stpp.ttml.im1t",rn=/^(\d{2,}):(\d{2}):(\d{2}):(\d{2})\.?(\d+)?$/,an=/^(\d*(?:\.\d*)?)(h|m|s|ms|f|t)$/,nn={left:"start",center:"center",right:"end",start:"start",end:"end"};function sn(e,t,r,i){var a=Be(new Uint8Array(e),["mdat"]);if(0!==a.length){var n=a.map((function(e){return Ie(e)})),s=function(e,t){return Fi(e,t,1/(arguments.length>2&&void 0!==arguments[2]?arguments[2]:1),arguments.length>3&&void 0!==arguments[3]&&arguments[3])}(t.baseTime,1,t.timescale);try{n.forEach((function(e){return r(function(e,t){var r=(new DOMParser).parseFromString(e,"text/xml").getElementsByTagName("tt")[0];if(!r)throw new Error("Invalid ttml");var i={frameRate:30,subFrameRate:1,frameRateMultiplier:0,tickRate:0},a=Object.keys(i).reduce((function(e,t){return e[t]=r.getAttribute("ttp:".concat(t))||i[t],e}),{}),n="preserve"!==r.getAttribute("xml:space"),s=ln(on(r,"styling","style")),o=ln(on(r,"layout","region")),l=on(r,"body","[begin]");return[].map.call(l,(function(e){var r=un(e,n);if(!r||!e.hasAttribute("begin"))return null;var i=dn(e.getAttribute("begin"),a),l=dn(e.getAttribute("dur"),a),u=dn(e.getAttribute("end"),a);if(null===i)throw hn(e);if(null===u){if(null===l)throw hn(e);u=i+l}var c=new Ka(i-t,u-t,r);c.id=en(c.startTime,c.endTime,c.text);var h=function(e,t,r){var i="http://www.w3.org/ns/ttml#styling",a=null,n=null!=e&&e.hasAttribute("style")?e.getAttribute("style"):null;return n&&r.hasOwnProperty(n)&&(a=r[n]),["displayAlign","textAlign","color","backgroundColor","fontSize","fontFamily"].reduce((function(r,n){var s=cn(t,i,n)||cn(e,i,n)||cn(a,i,n);return s&&(r[n]=s),r}),{})}(o[e.getAttribute("region")],s[e.getAttribute("style")],s),d=h.textAlign;if(d){var f=nn[d];f&&(c.lineAlign=f),c.align=d}return x(c,h),c})).filter((function(e){return null!==e}))}(e,s))}))}catch(e){i(e)}}else i(new Error("Could not parse IMSC1 mdat"))}function on(e,t,r){var i=e.getElementsByTagName(t)[0];return i?[].slice.call(i.querySelectorAll(r)):[]}function ln(e){return e.reduce((function(e,t){var r=t.getAttribute("xml:id");return r&&(e[r]=t),e}),{})}function un(e,t){return[].slice.call(e.childNodes).reduce((function(e,r,i){var a;return"br"===r.nodeName&&i?e+"\n":null!=(a=r.childNodes)&&a.length?un(r,t):t?e+r.textContent.trim().replace(/\s+/g," "):e+r.textContent}),"")}function cn(e,t,r){return e&&e.hasAttributeNS(t,r)?e.getAttributeNS(t,r):null}function hn(e){return new Error("Could not parse ttml timestamp ".concat(e))}function dn(e,t){if(!e)return null;var r=Va(e);return null===r&&(rn.test(e)?r=function(e,t){var r=rn.exec(e),i=(0|r[4])+(0|r[5])/t.subFrameRate;return 3600*(0|r[1])+60*(0|r[2])+(0|r[3])+i/t.frameRate}(e,t):an.test(e)&&(r=function(e,t){var r=an.exec(e),i=Number(r[1]);switch(r[2]){case"h":return 3600*i;case"m":return 60*i;case"ms":return 1e3*i;case"f":return i/t.frameRate;case"t":return i/t.tickRate}return i}(e,t))),r}var fn=function(){function e(t){if(y(this,e),this.hls=void 0,this.media=null,this.config=void 0,this.enabled=!0,this.Cues=void 0,this.textTracks=[],this.tracks=[],this.initPTS=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this.captionsProperties=void 0,this.hls=t,this.config=t.config,this.Cues=t.config.cueHandler,this.captionsProperties={textTrack1:{label:this.config.captionsTextTrack1Label,languageCode:this.config.captionsTextTrack1LanguageCode},textTrack2:{label:this.config.captionsTextTrack2Label,languageCode:this.config.captionsTextTrack2LanguageCode},textTrack3:{label:this.config.captionsTextTrack3Label,languageCode:this.config.captionsTextTrack3LanguageCode},textTrack4:{label:this.config.captionsTextTrack4Label,languageCode:this.config.captionsTextTrack4LanguageCode}},this.config.enableCEA708Captions){var r=new Ga(this,"textTrack1"),i=new Ga(this,"textTrack2"),a=new Ga(this,"textTrack3"),n=new Ga(this,"textTrack4");this.cea608Parser1=new Na(1,r,i),this.cea608Parser2=new Na(3,a,n)}t.on(O.MEDIA_ATTACHING,this.onMediaAttaching,this),t.on(O.MEDIA_DETACHING,this.onMediaDetaching,this),t.on(O.MANIFEST_LOADING,this.onManifestLoading,this),t.on(O.MANIFEST_LOADED,this.onManifestLoaded,this),t.on(O.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),t.on(O.FRAG_LOADING,this.onFragLoading,this),t.on(O.FRAG_LOADED,this.onFragLoaded,this),t.on(O.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),t.on(O.FRAG_DECRYPTED,this.onFragDecrypted,this),t.on(O.INIT_PTS_FOUND,this.onInitPtsFound,this),t.on(O.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),t.on(O.BUFFER_FLUSHING,this.onBufferFlushing,this)}return k(e,[{key:"destroy",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(O.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.off(O.FRAG_LOADING,this.onFragLoading,this),e.off(O.FRAG_LOADED,this.onFragLoaded,this),e.off(O.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),e.off(O.FRAG_DECRYPTED,this.onFragDecrypted,this),e.off(O.INIT_PTS_FOUND,this.onInitPtsFound,this),e.off(O.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),e.off(O.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=this.cea608Parser1=this.cea608Parser2=null}},{key:"addCues",value:function(e,t,r,i,a){for(var n,s,o,l,u=!1,c=a.length;c--;){var h=a[c],d=(n=h[0],s=h[1],o=t,l=r,Math.min(s,l)-Math.max(n,o));if(d>=0&&(h[0]=Math.min(h[0],t),h[1]=Math.max(h[1],r),u=!0,d/(r-t)>.5))return}if(u||a.push([t,r]),this.config.renderTextTracksNatively){var f=this.captionsTracks[e];this.Cues.newCue(f,t,r,i)}else{var v=this.Cues.newCue(null,t,r,i);this.hls.trigger(O.CUES_PARSED,{type:"captions",cues:v,track:e})}}},{key:"onInitPtsFound",value:function(e,t){var r=this,i=t.frag,a=t.id,n=t.initPTS,s=t.timescale,o=this.unparsedVttFrags;"main"===a&&(this.initPTS[i.cc]={baseTime:n,timescale:s}),o.length&&(this.unparsedVttFrags=[],o.forEach((function(e){r.onFragLoaded(O.FRAG_LOADED,e)})))}},{key:"getExistingTrack",value:function(e){var t=this.media;if(t)for(var r=0;r<t.textTracks.length;r++){var i=t.textTracks[r];if(i[e])return i}return null}},{key:"createCaptionsTrack",value:function(e){this.config.renderTextTracksNatively?this.createNativeTrack(e):this.createNonNativeTrack(e)}},{key:"createNativeTrack",value:function(e){if(!this.captionsTracks[e]){var t=this.captionsProperties,r=this.captionsTracks,i=this.media,a=t[e],n=a.label,s=a.languageCode,o=this.getExistingTrack(e);if(o)r[e]=o,Pt(r[e]),Ct(r[e],i);else{var l=this.createTextTrack("captions",n,s);l&&(l[e]=!0,r[e]=l)}}}},{key:"createNonNativeTrack",value:function(e){if(!this.nonNativeCaptionsTracks[e]){var t=this.captionsProperties[e];if(t){var r={_id:e,label:t.label,kind:"captions",default:!!t.media&&!!t.media.default,closedCaptions:t.media};this.nonNativeCaptionsTracks[e]=r,this.hls.trigger(O.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:[r]})}}}},{key:"createTextTrack",value:function(e,t,r){var i=this.media;if(i)return i.addTextTrack(e,t,r)}},{key:"onMediaAttaching",value:function(e,t){this.media=t.media,this._cleanTracks()}},{key:"onMediaDetaching",value:function(){var e=this.captionsTracks;Object.keys(e).forEach((function(t){Pt(e[t]),delete e[t]})),this.nonNativeCaptionsTracks={}}},{key:"onManifestLoading",value:function(){this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs={ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}},this._cleanTracks(),this.tracks=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.textTracks=[],this.unparsedVttFrags=[],this.initPTS=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())}},{key:"_cleanTracks",value:function(){var e=this.media;if(e){var t=e.textTracks;if(t)for(var r=0;r<t.length;r++)Pt(t[r])}}},{key:"onSubtitleTracksUpdated",value:function(e,t){var r=this,i=t.subtitleTracks||[],a=i.some((function(e){return e.textCodec===tn}));if(this.config.enableWebVTT||a&&this.config.enableIMSC1){if(ha(this.tracks,i))return void(this.tracks=i);if(this.textTracks=[],this.tracks=i,this.config.renderTextTracksNatively){var n=this.media?this.media.textTracks:null;this.tracks.forEach((function(e,t){var i;if(n&&t<n.length){for(var a=null,s=0;s<n.length;s++)if(vn(n[s],e)){a=n[s];break}a&&(i=a)}if(i)Pt(i);else{var o=r._captionsOrSubtitlesFromCharacteristics(e);(i=r.createTextTrack(o,e.name,e.lang))&&(i.mode="disabled")}i&&(i.groupId=e.groupId,r.textTracks.push(i))}))}else if(this.tracks.length){var s=this.tracks.map((function(e){return{label:e.name,kind:e.type.toLowerCase(),default:e.default,subtitleTrack:e}}));this.hls.trigger(O.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:s})}}}},{key:"_captionsOrSubtitlesFromCharacteristics",value:function(e){if(e.attrs.CHARACTERISTICS){var t=/transcribes-spoken-dialog/gi.test(e.attrs.CHARACTERISTICS),r=/describes-music-and-sound/gi.test(e.attrs.CHARACTERISTICS);if(t&&r)return"captions"}return"subtitles"}},{key:"onManifestLoaded",value:function(e,t){var r=this;this.config.enableCEA708Captions&&t.captions&&t.captions.forEach((function(e){var t=/(?:CC|SERVICE)([1-4])/.exec(e.instreamId);if(t){var i="textTrack".concat(t[1]),a=r.captionsProperties[i];a&&(a.label=e.name,e.lang&&(a.languageCode=e.lang),a.media=e)}}))}},{key:"closedCaptionsForLevel",value:function(e){var t=this.hls.levels[e.level];return null==t?void 0:t.attrs["CLOSED-CAPTIONS"]}},{key:"onFragLoading",value:function(e,t){var r=this.cea608Parser1,i=this.cea608Parser2,a=this.lastSn,n=this.lastPartIndex;if(this.enabled&&r&&i&&t.frag.type===At){var s,o,l=t.frag.sn,u=null!=(s=null==t||null==(o=t.part)?void 0:o.index)?s:-1;l===a+1||l===a&&u===n+1||(r.reset(),i.reset()),this.lastSn=l,this.lastPartIndex=u}}},{key:"onFragLoaded",value:function(e,t){var r=t.frag,i=t.payload;if(r.type===bt)if(i.byteLength){var a=r.decryptdata,n="stats"in t;if(null==a||!a.encrypted||n){var s=this.tracks[r.level],o=this.vttCCs;o[r.cc]||(o[r.cc]={start:r.start,prevCC:this.prevCC,new:!0},this.prevCC=r.cc),s&&s.textCodec===tn?this._parseIMSC1(r,i):this._parseVTTs(t)}}else this.hls.trigger(O.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Empty subtitle payload")})}},{key:"_parseIMSC1",value:function(e,t){var r=this,i=this.hls;sn(t,this.initPTS[e.cc],(function(t){r._appendCues(t,e.level),i.trigger(O.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:e})}),(function(t){K.log("Failed to parse IMSC1: ".concat(t)),i.trigger(O.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:e,error:t})}))}},{key:"_parseVTTs",value:function(e){var t,r=this,i=e.frag,a=e.payload,n=this.initPTS,s=this.unparsedVttFrags,o=n.length-1;if(n[i.cc]||-1!==o){var l=this.hls;!function(e,t,r,i,a,n,s){var o,l=new Qa,u=Ie(new Uint8Array(e)).trim().replace($a,"\n").split("\n"),c=[],h=t?function(e){return Fi(e,9e4,1/(arguments.length>1&&void 0!==arguments[1]?arguments[1]:1))}(t.baseTime,t.timescale):0,d="00:00.000",f=0,v=0,g=!0;l.oncue=function(e){var n=r[i],s=r.ccOffset,l=(f-h)/9e4;if(null!=n&&n.new&&(void 0!==v?s=r.ccOffset=n.start:function(e,t,r){var i=e[t],a=e[i.prevCC];if(!a||!a.new&&i.new)return e.ccOffset=e.presentationOffset=i.start,void(i.new=!1);for(;null!=(n=a)&&n.new;){var n;e.ccOffset+=i.start-a.start,i.new=!1,a=e[(i=a).prevCC]}e.presentationOffset=r}(r,i,l)),l){if(!t)return void(o=new Error("Missing initPTS for VTT MPEGTS"));s=l-r.presentationOffset}var u=e.endTime-e.startTime,d=Bi(9e4*(e.startTime+s-v),9e4*a)/9e4;e.startTime=Math.max(d,0),e.endTime=Math.max(d+u,0);var g=e.text.trim();e.text=decodeURIComponent(encodeURIComponent(g)),e.id||(e.id=en(e.startTime,e.endTime,g)),e.endTime>0&&c.push(e)},l.onparsingerror=function(e){o=e},l.onflush=function(){o?s(o):n(c)},u.forEach((function(e){if(g){if(Ja(e,"X-TIMESTAMP-MAP=")){g=!1,e.slice(16).split(",").forEach((function(e){Ja(e,"LOCAL:")?d=e.slice(6):Ja(e,"MPEGTS:")&&(f=parseInt(e.slice(7)))}));try{v=function(e){var t=parseInt(e.slice(-3)),r=parseInt(e.slice(-6,-4)),i=parseInt(e.slice(-9,-7)),a=e.length>9?parseInt(e.substring(0,e.indexOf(":"))):0;if(!(F(t)&&F(r)&&F(i)&&F(a)))throw Error("Malformed X-TIMESTAMP-MAP: Local:".concat(e));return t+=1e3*r,(t+=6e4*i)+36e5*a}(d)/1e3}catch(e){o=e}return}""===e&&(g=!1)}l.parse(e+"\n")})),l.flush()}(null!=(t=i.initSegment)&&t.data?Ye(i.initSegment.data,new Uint8Array(a)):a,this.initPTS[i.cc],this.vttCCs,i.cc,i.start,(function(e){r._appendCues(e,i.level),l.trigger(O.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:i})}),(function(t){var n="Missing initPTS for VTT MPEGTS"===t.message;n?s.push(e):r._fallbackToIMSC1(i,a),K.log("Failed to parse VTT cue: ".concat(t)),n&&o>i.cc||l.trigger(O.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:i,error:t})}))}else s.push(e)}},{key:"_fallbackToIMSC1",value:function(e,t){var r=this,i=this.tracks[e.level];i.textCodec||sn(t,this.initPTS[e.cc],(function(){i.textCodec=tn,r._parseIMSC1(e,t)}),(function(){i.textCodec="wvtt"}))}},{key:"_appendCues",value:function(e,t){var r=this.hls;if(this.config.renderTextTracksNatively){var i=this.textTracks[t];if(!i||"disabled"===i.mode)return;e.forEach((function(e){return _t(i,e)}))}else{var a=this.tracks[t];if(!a)return;var n=a.default?"default":"subtitles"+t;r.trigger(O.CUES_PARSED,{type:"subtitles",cues:e,track:n})}}},{key:"onFragDecrypted",value:function(e,t){t.frag.type===bt&&this.onFragLoaded(O.FRAG_LOADED,t)}},{key:"onSubtitleTracksCleared",value:function(){this.tracks=[],this.captionsTracks={}}},{key:"onFragParsingUserdata",value:function(e,t){var r=this.cea608Parser1,i=this.cea608Parser2;if(this.enabled&&r&&i){var a=t.frag,n=t.samples;if(a.type!==At||"NONE"!==this.closedCaptionsForLevel(a))for(var s=0;s<n.length;s++){var o=n[s].bytes;if(o){var l=this.extractCea608Data(o);r.addData(n[s].pts,l[0]),i.addData(n[s].pts,l[1])}}}}},{key:"onBufferFlushing",value:function(e,t){var r=t.startOffset,i=t.endOffset,a=t.endOffsetSubtitles,n=t.type,s=this.media;if(s&&!(s.currentTime<i)){if(!n||"video"===n){var o=this.captionsTracks;Object.keys(o).forEach((function(e){return xt(o[e],r,i)}))}if(this.config.renderTextTracksNatively&&0===r&&void 0!==a){var l=this.textTracks;Object.keys(l).forEach((function(e){return xt(l[e],r,a)}))}}}},{key:"extractCea608Data",value:function(e){for(var t=[[],[]],r=31&e[0],i=2,a=0;a<r;a++){var n=e[i++],s=127&e[i++],o=127&e[i++];if((0!==s||0!==o)&&0!=(4&n)){var l=3&n;0!==l&&1!==l||(t[l].push(s),t[l].push(o))}}return t}}]),e}();function vn(e,t){return!!e&&e.label===t.name&&!(e.textTrack1||e.textTrack2)}var gn=function(){function e(t){y(this,e),this.hls=void 0,this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.clientRect=void 0,this.streamController=void 0,this.hls=t,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}return k(e,[{key:"setStreamController",value:function(e){this.streamController=e}},{key:"destroy",value:function(){this.unregisterListener(),this.hls.config.capLevelToPlayerSize&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null}},{key:"registerListeners",value:function(){var e=this.hls;e.on(O.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.on(O.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(O.MANIFEST_PARSED,this.onManifestParsed,this),e.on(O.BUFFER_CODECS,this.onBufferCodecs,this),e.on(O.MEDIA_DETACHING,this.onMediaDetaching,this)}},{key:"unregisterListener",value:function(){var e=this.hls;e.off(O.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.off(O.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(O.MANIFEST_PARSED,this.onManifestParsed,this),e.off(O.BUFFER_CODECS,this.onBufferCodecs,this),e.off(O.MEDIA_DETACHING,this.onMediaDetaching,this)}},{key:"onFpsDropLevelCapping",value:function(e,t){var r=this.hls.levels[t.droppedLevel];this.isLevelAllowed(r)&&this.restrictedLevels.push({bitrate:r.bitrate,height:r.height,width:r.width})}},{key:"onMediaAttaching",value:function(e,t){this.media=t.media instanceof HTMLVideoElement?t.media:null,this.clientRect=null}},{key:"onManifestParsed",value:function(e,t){var r=this.hls;this.restrictedLevels=[],this.firstLevel=t.firstLevel,r.config.capLevelToPlayerSize&&t.video&&this.startCapping()}},{key:"onBufferCodecs",value:function(e,t){this.hls.config.capLevelToPlayerSize&&t.video&&this.startCapping()}},{key:"onMediaDetaching",value:function(){this.stopCapping()}},{key:"detectPlayerSize",value:function(){if(this.media&&this.mediaHeight>0&&this.mediaWidth>0){var e=this.hls.levels;if(e.length){var t=this.hls;t.autoLevelCapping=this.getMaxLevel(e.length-1),t.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}}},{key:"getMaxLevel",value:function(t){var r=this,i=this.hls.levels;if(!i.length)return-1;var a=i.filter((function(e,i){return r.isLevelAllowed(e)&&i<=t}));return this.clientRect=null,e.getMaxLevelByMediaSize(a,this.mediaWidth,this.mediaHeight)}},{key:"startCapping",value:function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,this.hls.firstLevel=this.getMaxLevel(this.firstLevel),self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())}},{key:"stopCapping",value:function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)}},{key:"getDimensions",value:function(){if(this.clientRect)return this.clientRect;var e=this.media,t={width:0,height:0};if(e){var r=e.getBoundingClientRect();t.width=r.width,t.height=r.height,t.width||t.height||(t.width=r.right-r.left||e.width||0,t.height=r.bottom-r.top||e.height||0)}return this.clientRect=t,t}},{key:"mediaWidth",get:function(){return this.getDimensions().width*this.contentScaleFactor}},{key:"mediaHeight",get:function(){return this.getDimensions().height*this.contentScaleFactor}},{key:"contentScaleFactor",get:function(){var e=1;if(!this.hls.config.ignoreDevicePixelRatio)try{e=self.devicePixelRatio}catch(e){}return e}},{key:"isLevelAllowed",value:function(e){return!this.restrictedLevels.some((function(t){return e.bitrate===t.bitrate&&e.width===t.width&&e.height===t.height}))}}],[{key:"getMaxLevelByMediaSize",value:function(e,t,r){if(null==e||!e.length)return-1;for(var i,a,n=e.length-1,s=0;s<e.length;s+=1){var o=e[s];if((o.width>=t||o.height>=r)&&(i=o,!(a=e[s+1])||i.width!==a.width||i.height!==a.height)){n=s;break}}return n}}]),e}(),mn=function(){function e(t){y(this,e),this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=t,this.registerListeners()}return k(e,[{key:"setStreamController",value:function(e){this.streamController=e}},{key:"registerListeners",value:function(){this.hls.on(O.MEDIA_ATTACHING,this.onMediaAttaching,this)}},{key:"unregisterListeners",value:function(){this.hls.off(O.MEDIA_ATTACHING,this.onMediaAttaching,this)}},{key:"destroy",value:function(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null}},{key:"onMediaAttaching",value:function(e,t){var r=this.hls.config;if(r.capLevelOnFPSDrop){var i=t.media instanceof self.HTMLVideoElement?t.media:null;this.media=i,i&&"function"==typeof i.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),r.fpsDroppedMonitoringPeriod)}}},{key:"checkFPS",value:function(e,t,r){var i=performance.now();if(t){if(this.lastTime){var a=i-this.lastTime,n=r-this.lastDroppedFrames,s=t-this.lastDecodedFrames,o=1e3*n/a,l=this.hls;if(l.trigger(O.FPS_DROP,{currentDropped:n,currentDecoded:s,totalDroppedFrames:r}),o>0&&n>l.config.fpsDroppedMonitoringThreshold*s){var u=l.currentLevel;K.warn("drop FPS ratio greater than max allowed value for currentLevel: "+u),u>0&&(-1===l.autoLevelCapping||l.autoLevelCapping>=u)&&(u-=1,l.trigger(O.FPS_DROP_LEVEL_CAPPING,{level:u,droppedLevel:l.currentLevel}),l.autoLevelCapping=u,this.streamController.nextLevelSwitch())}}this.lastTime=i,this.lastDroppedFrames=r,this.lastDecodedFrames=t}}},{key:"checkFPSInterval",value:function(){var e=this.media;if(e)if(this.isVideoPlaybackQualityAvailable){var t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)}}]),e}(),yn="[eme]",pn=function(){function e(t){y(this,e),this.hls=void 0,this.config=void 0,this.media=null,this.keyFormatPromise=null,this.keySystemAccessPromises={},this._requestLicenseFailureCount=0,this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},this.setMediaKeysQueue=e.CDMCleanupPromise?[e.CDMCleanupPromise]:[],this.onMediaEncrypted=this._onMediaEncrypted.bind(this),this.onWaitingForKey=this._onWaitingForKey.bind(this),this.debug=K.debug.bind(K,yn),this.log=K.log.bind(K,yn),this.warn=K.warn.bind(K,yn),this.error=K.error.bind(K,yn),this.hls=t,this.config=t.config,this.registerListeners()}return k(e,[{key:"destroy",value:function(){this.unregisterListeners(),this.onMediaDetached();var e=this.config;e.requestMediaKeySystemAccessFunc=null,e.licenseXhrSetup=e.licenseResponseCallback=void 0,e.drmSystems=e.drmSystemOptions={},this.hls=this.onMediaEncrypted=this.onWaitingForKey=this.keyIdToKeySessionPromise=null,this.config=null}},{key:"registerListeners",value:function(){this.hls.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(O.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.on(O.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(O.MANIFEST_LOADED,this.onManifestLoaded,this)}},{key:"unregisterListeners",value:function(){this.hls.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(O.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.off(O.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(O.MANIFEST_LOADED,this.onManifestLoaded,this)}},{key:"getLicenseServerUrl",value:function(e){var t=this.config,r=t.drmSystems,i=t.widevineLicenseUrl,a=r[e];if(a)return a.licenseUrl;if(e===ie.WIDEVINE&&i)return i;throw new Error('no license server URL configured for key-system "'.concat(e,'"'))}},{key:"getServerCertificateUrl",value:function(e){var t=this.config.drmSystems[e];if(t)return t.serverCertificateUrl;this.log('No Server Certificate in config.drmSystems["'.concat(e,'"]'))}},{key:"attemptKeySystemAccess",value:function(e){var t=this,r=this.hls.levels,i=function(e,t,r){return!!e&&r.indexOf(e)===t},a=r.map((function(e){return e.audioCodec})).filter(i),n=r.map((function(e){return e.videoCodec})).filter(i);return a.length+n.length===0&&n.push("avc1.42e01e"),new Promise((function(r,i){!function e(s){var o=s.shift();t.getMediaKeysPromise(o,a,n).then((function(e){return r({keySystem:o,mediaKeys:e})})).catch((function(t){s.length?e(s):i(t instanceof kn?t:new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_NO_ACCESS,error:t,fatal:!0},t.message))}))}(e)}))}},{key:"requestMediaKeySystemAccess",value:function(e,t){var r=this.config.requestMediaKeySystemAccessFunc;if("function"!=typeof r){var i="Configured requestMediaKeySystemAccess is not a function ".concat(r);return null===de&&"http:"===self.location.protocol&&(i="navigator.requestMediaKeySystemAccess is not available over insecure protocol ".concat(location.protocol)),Promise.reject(new Error(i))}return r(e,t)}},{key:"getMediaKeysPromise",value:function(e,t,r){var i=this,a=function(e,t,r,i){var a;switch(e){case ie.FAIRPLAY:a=["cenc","sinf"];break;case ie.WIDEVINE:case ie.PLAYREADY:a=["cenc"];break;case ie.CLEARKEY:a=["cenc","keyids"];break;default:throw new Error("Unknown key-system: ".concat(e))}return function(e,t,r,i){return[{initDataTypes:e,persistentState:i.persistentState||"not-allowed",distinctiveIdentifier:i.distinctiveIdentifier||"not-allowed",sessionTypes:i.sessionTypes||[i.sessionType||"temporary"],audioCapabilities:t.map((function(e){return{contentType:'audio/mp4; codecs="'.concat(e,'"'),robustness:i.audioRobustness||"",encryptionScheme:i.audioEncryptionScheme||null}})),videoCapabilities:r.map((function(e){return{contentType:'video/mp4; codecs="'.concat(e,'"'),robustness:i.videoRobustness||"",encryptionScheme:i.videoEncryptionScheme||null}}))}]}(a,t,r,i)}(e,t,r,this.config.drmSystemOptions),n=this.keySystemAccessPromises[e],s=null==n?void 0:n.keySystemAccess;if(!s){this.log('Requesting encrypted media "'.concat(e,'" key-system access with config: ').concat(JSON.stringify(a))),s=this.requestMediaKeySystemAccess(e,a);var o=this.keySystemAccessPromises[e]={keySystemAccess:s};return s.catch((function(t){i.log('Failed to obtain access to key-system "'.concat(e,'": ').concat(t))})),s.then((function(t){i.log('Access for key-system "'.concat(t.keySystem,'" obtained'));var r=i.fetchServerCertificate(e);return i.log('Create media-keys for "'.concat(e,'"')),o.mediaKeys=t.createMediaKeys().then((function(t){return i.log('Media-keys created for "'.concat(e,'"')),r.then((function(r){return r?i.setMediaKeysServerCertificate(t,e,r):t}))})),o.mediaKeys.catch((function(t){i.error('Failed to create media-keys for "'.concat(e,'"}: ').concat(t))})),o.mediaKeys}))}return s.then((function(){return n.mediaKeys}))}},{key:"createMediaKeySessionContext",value:function(e){var t=e.decryptdata,r=e.keySystem,i=e.mediaKeys;this.log('Creating key-system session "'.concat(r,'" keyId: ').concat(Ce(t.keyId||[])));var a=i.createSession(),n={decryptdata:t,keySystem:r,mediaKeys:i,mediaKeysSession:a,keyStatus:"status-pending"};return this.mediaKeySessions.push(n),n}},{key:"renewKeySession",value:function(e){var t=e.decryptdata;if(t.pssh){var r=this.createMediaKeySessionContext(e),i=this.getKeyIdString(t);this.keyIdToKeySessionPromise[i]=this.generateRequestWithPreferredKeySession(r,"cenc",t.pssh,"expired")}else this.warn("Could not renew expired session. Missing pssh initData.");this.removeSession(e)}},{key:"getKeyIdString",value:function(e){if(!e)throw new Error("Could not read keyId of undefined decryptdata");if(null===e.keyId)throw new Error("keyId is null");return Ce(e.keyId)}},{key:"updateKeySession",value:function(e,t){var r,i=e.mediaKeysSession;return this.log('Updating key-session "'.concat(i.sessionId,'" for keyID ').concat(Ce((null==(r=e.decryptdata)?void 0:r.keyId)||[]),"\n } (data length: ").concat(t?t.byteLength:t,")")),i.update(t)}},{key:"selectKeySystemFormat",value:function(e){var t=Object.keys(e.levelkeys||{});return this.keyFormatPromise||(this.log("Selecting key-system from fragment (sn: ".concat(e.sn," ").concat(e.type,": ").concat(e.level,") key formats ").concat(t.join(", "))),this.keyFormatPromise=this.getKeyFormatPromise(t)),this.keyFormatPromise}},{key:"getKeyFormatPromise",value:function(e){var t=this;return new Promise((function(r,i){var a=he(t.config),n=e.map(le).filter((function(e){return!!e&&-1!==a.indexOf(e)}));return t.getKeySystemSelectionPromise(n).then((function(e){var t=e.keySystem,a=ce(t);a?r(a):i(new Error('Unable to find format for key-system "'.concat(t,'"')))})).catch(i)}))}},{key:"loadKey",value:function(e){var t=this,r=e.keyInfo.decryptdata,i=this.getKeyIdString(r),a="(keyId: ".concat(i,' format: "').concat(r.keyFormat,'" method: ').concat(r.method," uri: ").concat(r.uri,")");this.log("Starting session for key ".concat(a));var n=this.keyIdToKeySessionPromise[i];return n||(n=this.keyIdToKeySessionPromise[i]=this.getKeySystemForKeyPromise(r).then((function(i){var n=i.keySystem,s=i.mediaKeys;return t.throwIfDestroyed(),t.log("Handle encrypted media sn: ".concat(e.frag.sn," ").concat(e.frag.type,": ").concat(e.frag.level," using key ").concat(a)),t.attemptSetMediaKeys(n,s).then((function(){t.throwIfDestroyed();var e=t.createMediaKeySessionContext({keySystem:n,mediaKeys:s,decryptdata:r});return t.generateRequestWithPreferredKeySession(e,"cenc",r.pssh,"playlist-key")}))}))).catch((function(e){return t.handleError(e)})),n}},{key:"throwIfDestroyed",value:function(){if(!this.hls)throw new Error("invalid state")}},{key:"handleError",value:function(e){this.hls&&(this.error(e.message),e instanceof kn?this.hls.trigger(O.ERROR,e.data):this.hls.trigger(O.ERROR,{type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_NO_KEYS,error:e,fatal:!0}))}},{key:"getKeySystemForKeyPromise",value:function(e){var t=this.getKeyIdString(e),r=this.keyIdToKeySessionPromise[t];if(!r){var i=le(e.keyFormat),a=i?[i]:he(this.config);return this.attemptKeySystemAccess(a)}return r}},{key:"getKeySystemSelectionPromise",value:function(e){if(e.length||(e=he(this.config)),0===e.length)throw new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_NO_CONFIGURED_LICENSE,fatal:!0},"Missing key-system license configuration options ".concat(JSON.stringify({drmSystems:this.config.drmSystems})));return this.attemptKeySystemAccess(e)}},{key:"_onMediaEncrypted",value:function(e){var t=this,r=e.initDataType,i=e.initData;if(this.debug('"'.concat(e.type,'" event: init data type: "').concat(r,'"')),null!==i){var a,n;if("sinf"===r&&this.config.drmSystems[ie.FAIRPLAY]){var s=Fe(new Uint8Array(i));try{var o=te(JSON.parse(s).sinf),l=He(new Uint8Array(o));if(!l)return;a=l.subarray(8,24),n=ie.FAIRPLAY}catch(e){return void this.warn('Failed to parse sinf "encrypted" event message initData')}}else{var u=function(e){if(!(e instanceof ArrayBuffer)||e.byteLength<32)return null;var t={version:0,systemId:"",kids:null,data:null},r=new DataView(e),i=r.getUint32(0);if(e.byteLength!==i&&i>44)return null;if(1886614376!==r.getUint32(4))return null;if(t.version=r.getUint32(8)>>>24,t.version>1)return null;t.systemId=Ce(new Uint8Array(e,12,16));var a=r.getUint32(28);if(0===t.version){if(i-32<a)return null;t.data=new Uint8Array(e,32,a)}else if(1===t.version){t.kids=[];for(var n=0;n<a;n++)t.kids.push(new Uint8Array(e,32+16*n,16))}return t}(i);if(null===u)return;0===u.version&&u.systemId===ue&&u.data&&(a=u.data.subarray(8,24)),n=function(e){if(e===ue)return ie.WIDEVINE}(u.systemId)}if(n&&a){for(var c,h=Ce(a),d=this.keyIdToKeySessionPromise,f=this.mediaKeySessions,v=d[h],g=function(){var e=f[m],n=e.decryptdata;if(n.pssh||!n.keyId)return 0;var s=Ce(n.keyId);return h===s||-1!==n.uri.replace(/-/g,"").indexOf(h)?(v=d[s],delete d[s],n.pssh=new Uint8Array(i),n.keyId=a,v=d[h]=v.then((function(){return t.generateRequestWithPreferredKeySession(e,r,i,"encrypted-event-key-match")})),1):void 0},m=0;m<f.length&&(0===(c=g())||1!==c);m++);v||(v=d[h]=this.getKeySystemSelectionPromise([n]).then((function(e){var n,s=e.keySystem,o=e.mediaKeys;t.throwIfDestroyed();var l=new Qe("ISO-23001-7",h,null!=(n=ce(s))?n:"");return l.pssh=new Uint8Array(i),l.keyId=a,t.attemptSetMediaKeys(s,o).then((function(){t.throwIfDestroyed();var e=t.createMediaKeySessionContext({decryptdata:l,keySystem:s,mediaKeys:o});return t.generateRequestWithPreferredKeySession(e,r,i,"encrypted-event-no-match")}))}))),v.catch((function(e){return t.handleError(e)}))}}}},{key:"_onWaitingForKey",value:function(e){this.log('"'.concat(e.type,'" event'))}},{key:"attemptSetMediaKeys",value:function(e,t){var r=this,i=this.setMediaKeysQueue.slice();this.log('Setting media-keys for "'.concat(e,'"'));var a=Promise.all(i).then((function(){if(!r.media)throw new Error("Attempted to set mediaKeys without media element attached");return r.media.setMediaKeys(t)}));return this.setMediaKeysQueue.push(a),a.then((function(){r.log('Media-keys set for "'.concat(e,'"')),i.push(a),r.setMediaKeysQueue=r.setMediaKeysQueue.filter((function(e){return-1===i.indexOf(e)}))}))}},{key:"generateRequestWithPreferredKeySession",value:function(e,t,r,i){var a,n,s=this,o=null==(a=this.config.drmSystems)||null==(n=a[e.keySystem])?void 0:n.generateRequest;if(o)try{var l=o.call(this.hls,t,r,e);if(!l)throw new Error("Invalid response from configured generateRequest filter");t=l.initDataType,r=e.decryptdata.pssh=l.initData?new Uint8Array(l.initData):null}catch(e){var u;if(this.warn(e.message),null!=(u=this.hls)&&u.config.debug)throw e}if(null===r)return this.log('Skipping key-session request for "'.concat(i,'" (no initData)')),Promise.resolve(e);var c=this.getKeyIdString(e.decryptdata);this.log('Generating key-session request for "'.concat(i,'": ').concat(c," (init data type: ").concat(t," length: ").concat(r?r.byteLength:null,")"));var h=new ea;e.mediaKeysSession.onmessage=function(t){var r=e.mediaKeysSession;if(r){var i=t.messageType,a=t.message;s.log('"'.concat(i,'" message event for session "').concat(r.sessionId,'" message size: ').concat(a.byteLength)),"license-request"===i||"license-renewal"===i?s.renewLicense(e,a).catch((function(e){s.handleError(e),h.emit("error",e)})):"license-release"===i?e.keySystem===ie.FAIRPLAY&&(s.updateKeySession(e,re("acknowledged")),s.removeSession(e)):s.warn('unhandled media key message type "'.concat(i,'"'))}else h.emit("error",new Error("invalid state"))},e.mediaKeysSession.onkeystatuseschange=function(t){if(e.mediaKeysSession){s.onKeyStatusChange(e);var r=e.keyStatus;h.emit("keyStatus",r),"expired"===r&&(s.warn("".concat(e.keySystem," expired for key ").concat(c)),s.renewKeySession(e))}else h.emit("error",new Error("invalid state"))};var d=new Promise((function(e,t){h.on("error",t),h.on("keyStatus",(function(r){r.startsWith("usable")?e():"output-restricted"===r?t(new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED,fatal:!1},"HDCP level output restricted")):"internal-error"===r?t(new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_STATUS_INTERNAL_ERROR,fatal:!0},'key status changed to "'.concat(r,'"'))):"expired"===r?t(new Error("key expired while generating request")):s.warn('unhandled key status change "'.concat(r,'"'))}))}));return e.mediaKeysSession.generateRequest(t,r).then((function(){var t;s.log('Request generated for key-session "'.concat(null==(t=e.mediaKeysSession)?void 0:t.sessionId,'" keyId: ').concat(c))})).catch((function(e){throw new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_NO_SESSION,error:e,fatal:!1},"Error generating key-session request: ".concat(e))})).then((function(){return d})).catch((function(t){throw h.removeAllListeners(),s.removeSession(e),t})).then((function(){return h.removeAllListeners(),e}))}},{key:"onKeyStatusChange",value:function(e){var t=this;e.mediaKeysSession.keyStatuses.forEach((function(r,i){t.log('key status change "'.concat(r,'" for keyStatuses keyId: ').concat(Ce("buffer"in i?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):new Uint8Array(i))," session keyId: ").concat(Ce(new Uint8Array(e.decryptdata.keyId||[]))," uri: ").concat(e.decryptdata.uri)),e.keyStatus=r}))}},{key:"fetchServerCertificate",value:function(e){var t=this.config,r=new(0,t.loader)(t),i=this.getServerCertificateUrl(e);return i?(this.log('Fetching serverCertificate for "'.concat(e,'"')),new Promise((function(a,n){var s={responseType:"arraybuffer",url:i},o=t.certLoadPolicy.default,l={loadPolicy:o,timeout:o.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},u={onSuccess:function(e,t,r,i){a(e.data)},onError:function(t,r,a,o){n(new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:a,response:_({url:s.url,data:void 0},t)},'"'.concat(e,'" certificate request failed (').concat(i,"). Status: ").concat(t.code," (").concat(t.text,")")))},onTimeout:function(t,r,a){n(new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:a,response:{url:s.url,data:void 0}},'"'.concat(e,'" certificate request timed out (').concat(i,")")))},onAbort:function(e,t,r){n(new Error("aborted"))}};r.load(s,l,u)}))):Promise.resolve()}},{key:"setMediaKeysServerCertificate",value:function(e,t,r){var i=this;return new Promise((function(a,n){e.setServerCertificate(r).then((function(n){i.log("setServerCertificate ".concat(n?"success":"not supported by CDM"," (").concat(null==r?void 0:r.byteLength,') on "').concat(t,'"')),a(e)})).catch((function(e){n(new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED,error:e,fatal:!0},e.message))}))}))}},{key:"renewLicense",value:function(e,t){var r=this;return this.requestLicense(e,new Uint8Array(t)).then((function(t){return r.updateKeySession(e,new Uint8Array(t)).catch((function(e){throw new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_SESSION_UPDATE_FAILED,error:e,fatal:!0},e.message)}))}))}},{key:"setupLicenseXHR",value:function(e,t,r,i){var a=this,n=this.config.licenseXhrSetup;return n?Promise.resolve().then((function(){if(!r.decryptdata)throw new Error("Key removed");return n.call(a.hls,e,t,r,i)})).catch((function(s){if(!r.decryptdata)throw s;return e.open("POST",t,!0),n.call(a.hls,e,t,r,i)})).then((function(r){return e.readyState||e.open("POST",t,!0),{xhr:e,licenseChallenge:r||i}})):(e.open("POST",t,!0),Promise.resolve({xhr:e,licenseChallenge:i}))}},{key:"requestLicense",value:function(e,t){var r=this,i=this.config.keyLoadPolicy.default;return new Promise((function(a,n){var s=r.getLicenseServerUrl(e.keySystem);r.log("Sending license request to URL: ".concat(s));var o=new XMLHttpRequest;o.responseType="arraybuffer",o.onreadystatechange=function(){if(!r.hls||!e.mediaKeysSession)return n(new Error("invalid state"));if(4===o.readyState)if(200===o.status){r._requestLicenseFailureCount=0;var l=o.response;r.log("License received ".concat(l instanceof ArrayBuffer?l.byteLength:l));var u=r.config.licenseResponseCallback;if(u)try{l=u.call(r.hls,o,s,e)}catch(e){r.error(e)}a(l)}else{var c=i.errorRetry,h=c?c.maxNumRetry:0;if(r._requestLicenseFailureCount++,r._requestLicenseFailureCount>h||o.status>=400&&o.status<500)n(new kn({type:M.KEY_SYSTEM_ERROR,details:N.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0,networkDetails:o,response:{url:s,data:void 0,code:o.status,text:o.statusText}},"License Request XHR failed (".concat(s,"). Status: ").concat(o.status," (").concat(o.statusText,")")));else{var d=h-r._requestLicenseFailureCount+1;r.warn("Retrying license request, ".concat(d," attempts left")),r.requestLicense(e,t).then(a,n)}}},e.licenseXhr&&e.licenseXhr.readyState!==XMLHttpRequest.DONE&&e.licenseXhr.abort(),e.licenseXhr=o,r.setupLicenseXHR(o,s,e,t).then((function(e){var t=e.xhr,r=e.licenseChallenge;t.send(r)}))}))}},{key:"onMediaAttached",value:function(e,t){if(this.config.emeEnabled){var r=t.media;this.media=r,r.addEventListener("encrypted",this.onMediaEncrypted),r.addEventListener("waitingforkey",this.onWaitingForKey)}}},{key:"onMediaDetached",value:function(){var t=this,r=this.media,i=this.mediaKeySessions;r&&(r.removeEventListener("encrypted",this.onMediaEncrypted),r.removeEventListener("waitingforkey",this.onWaitingForKey),this.media=null),this._requestLicenseFailureCount=0,this.setMediaKeysQueue=[],this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},Qe.clearKeyUriToKeyIdMap();var a=i.length;e.CDMCleanupPromise=Promise.all(i.map((function(e){return t.removeSession(e)})).concat(null==r?void 0:r.setMediaKeys(null).catch((function(e){t.log("Could not clear media keys: ".concat(e,". media.src: ").concat(null==r?void 0:r.src))})))).then((function(){a&&(t.log("finished closing key sessions and clearing media keys"),i.length=0)})).catch((function(e){t.log("Could not close sessions and clear media keys: ".concat(e,". media.src: ").concat(null==r?void 0:r.src))}))}},{key:"onManifestLoading",value:function(){this.keyFormatPromise=null}},{key:"onManifestLoaded",value:function(e,t){var r=t.sessionKeys;if(r&&this.config.emeEnabled&&!this.keyFormatPromise){var i=r.reduce((function(e,t){return-1===e.indexOf(t.keyFormat)&&e.push(t.keyFormat),e}),[]);this.log("Selecting key-system from session-keys ".concat(i.join(", "))),this.keyFormatPromise=this.getKeyFormatPromise(i)}}},{key:"removeSession",value:function(e){var t=this,r=e.mediaKeysSession,i=e.licenseXhr;if(r){this.log("Remove licenses and keys and close session ".concat(r.sessionId)),r.onmessage=null,r.onkeystatuseschange=null,i&&i.readyState!==XMLHttpRequest.DONE&&i.abort(),e.mediaKeysSession=e.decryptdata=e.licenseXhr=void 0;var a=this.mediaKeySessions.indexOf(e);return a>-1&&this.mediaKeySessions.splice(a,1),r.remove().catch((function(e){t.log("Could not remove session: ".concat(e))})).then((function(){return r.close()})).catch((function(e){t.log("Could not close session: ".concat(e))}))}}}]),e}();pn.CDMCleanupPromise=void 0;var kn=function(e){c(r,e);var t=d(r);function r(e,i){var a;return y(this,r),(a=t.call(this,i)).data=void 0,e.error||(e.error=new Error(i)),a.data=e,e.err=e.error,a}return k(r)}(o(Error)),Tn="a",En="av",Sn=function(){function e(t){var r=this;y(this,e),this.hls=void 0,this.config=void 0,this.media=void 0,this.sid=void 0,this.cid=void 0,this.useHeaders=!1,this.initialized=!1,this.starved=!1,this.buffering=!0,this.audioBuffer=void 0,this.videoBuffer=void 0,this.onWaiting=function(){r.initialized&&(r.starved=!0),r.buffering=!0},this.onPlaying=function(){r.initialized||(r.initialized=!0),r.buffering=!1},this.applyPlaylistData=function(e){try{r.apply(e,{ot:"m",su:!r.initialized})}catch(e){K.warn("Could not generate manifest CMCD data.",e)}},this.applyFragmentData=function(e){try{var t=e.frag,i=r.hls.levels[t.level],a=r.getObjectType(t),n={d:1e3*t.duration,ot:a};"v"!==a&&a!==Tn&&a!=En||(n.br=i.bitrate/1e3,n.tb=r.getTopBandwidth(a)/1e3,n.bl=r.getBufferLength(a)),r.apply(e,n)}catch(e){K.warn("Could not generate segment CMCD data.",e)}},this.hls=t;var i=this.config=t.config,a=i.cmcd;null!=a&&(i.pLoader=this.createPlaylistLoader(),i.fLoader=this.createFragmentLoader(),this.sid=a.sessionId||e.uuid(),this.cid=a.contentId,this.useHeaders=!0===a.useHeaders,this.registerListeners())}return k(e,[{key:"registerListeners",value:function(){var e=this.hls;e.on(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(O.MEDIA_DETACHED,this.onMediaDetached,this),e.on(O.BUFFER_CREATED,this.onBufferCreated,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e.off(O.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(O.MEDIA_DETACHED,this.onMediaDetached,this),e.off(O.BUFFER_CREATED,this.onBufferCreated,this)}},{key:"destroy",value:function(){this.unregisterListeners(),this.onMediaDetached(),this.hls=this.config=this.audioBuffer=this.videoBuffer=null}},{key:"onMediaAttached",value:function(e,t){this.media=t.media,this.media.addEventListener("waiting",this.onWaiting),this.media.addEventListener("playing",this.onPlaying)}},{key:"onMediaDetached",value:function(){this.media&&(this.media.removeEventListener("waiting",this.onWaiting),this.media.removeEventListener("playing",this.onPlaying),this.media=null)}},{key:"onBufferCreated",value:function(e,t){var r,i;this.audioBuffer=null==(r=t.tracks.audio)?void 0:r.buffer,this.videoBuffer=null==(i=t.tracks.video)?void 0:i.buffer}},{key:"createData",value:function(){var e;return{v:1,sf:"h",sid:this.sid,cid:this.cid,pr:null==(e=this.media)?void 0:e.playbackRate,mtp:this.hls.bandwidthEstimate/1e3}}},{key:"apply",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};x(r,this.createData());var i="i"===r.ot||"v"===r.ot||r.ot===En;if(this.starved&&i&&(r.bs=!0,r.su=!0,this.starved=!1),null==r.su&&(r.su=this.buffering),this.useHeaders){var a=e.toHeaders(r);if(!Object.keys(a).length)return;t.headers||(t.headers={}),x(t.headers,a)}else{var n=e.toQuery(r);if(!n)return;t.url=e.appendQueryToUri(t.url,n)}}},{key:"getObjectType",value:function(e){var t=e.type;return"subtitle"===t?"tt":"initSegment"===e.sn?"i":"audio"===t?Tn:"main"===t?this.hls.audioTracks.length?"v":En:void 0}},{key:"getTopBandwidth",value:function(e){var t,r=0,i=this.hls;if(e===Tn)t=i.audioTracks;else{var n=i.maxAutoLevel,s=n>-1?n+1:i.levels.length;t=i.levels.slice(0,s)}var o,l=a(t);try{for(l.s();!(o=l.n()).done;){var u=o.value;u.bitrate>r&&(r=u.bitrate)}}catch(e){l.e(e)}finally{l.f()}return r>0?r:NaN}},{key:"getBufferLength",value:function(e){var t=this.hls.media,r=e===Tn?this.audioBuffer:this.videoBuffer;return r&&t?1e3*br.bufferInfo(r,t.currentTime,this.config.maxBufferHole).len:NaN}},{key:"createPlaylistLoader",value:function(){var e=this.config.pLoader,t=this.applyPlaylistData,r=e||this.config.loader;return function(){function e(t){y(this,e),this.loader=void 0,this.loader=new r(t)}return k(e,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}},{key:"destroy",value:function(){this.loader.destroy()}},{key:"abort",value:function(){this.loader.abort()}},{key:"load",value:function(e,r,i){t(e),this.loader.load(e,r,i)}}]),e}()}},{key:"createFragmentLoader",value:function(){var e=this.config.fLoader,t=this.applyFragmentData,r=e||this.config.loader;return function(){function e(t){y(this,e),this.loader=void 0,this.loader=new r(t)}return k(e,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}},{key:"destroy",value:function(){this.loader.destroy()}},{key:"abort",value:function(){this.loader.abort()}},{key:"load",value:function(e,r,i){t(e),this.loader.load(e,r,i)}}]),e}()}}],[{key:"uuid",value:function(){var e=URL.createObjectURL(new Blob),t=e.toString();return URL.revokeObjectURL(e),t.slice(t.lastIndexOf("/")+1)}},{key:"serialize",value:function(e){var t,r=[],i=function(e){return!Number.isNaN(e)&&null!=e&&""!==e&&!1!==e},n=function(e){return Math.round(e)},s=function(e){return 100*n(e/100)},o={br:n,d:n,bl:s,dl:s,mtp:s,nor:function(e){return encodeURIComponent(e)},rtp:s,tb:n},l=a(Object.keys(e||{}).sort());try{for(l.s();!(t=l.n()).done;){var u=t.value,c=e[u];if(i(c)&&!("v"===u&&1===c||"pr"==u&&1===c)){var h=o[u];h&&(c=h(c));var d,f=E(c);d="ot"===u||"sf"===u||"st"===u?"".concat(u,"=").concat(c):"boolean"===f?u:"number"===f?"".concat(u,"=").concat(c):"".concat(u,"=").concat(JSON.stringify(c)),r.push(d)}}}catch(e){l.e(e)}finally{l.f()}return r.join(",")}},{key:"toHeaders",value:function(t){for(var r={},i=["Object","Request","Session","Status"],a=[{},{},{},{}],n={br:0,d:0,ot:0,tb:0,bl:1,dl:1,mtp:1,nor:1,nrr:1,su:1,cid:2,pr:2,sf:2,sid:2,st:2,v:2,bs:3,rtp:3},s=0,o=Object.keys(t);s<o.length;s++){var l=o[s];a[null!=n[l]?n[l]:1][l]=t[l]}for(var u=0;u<a.length;u++){var c=e.serialize(a[u]);c&&(r["CMCD-".concat(i[u])]=c)}return r}},{key:"toQuery",value:function(t){return"CMCD=".concat(encodeURIComponent(e.serialize(t)))}},{key:"appendQueryToUri",value:function(e,t){if(!t)return e;var r=e.includes("?")?"&":"?";return"".concat(e).concat(r).concat(t)}}]),e}(),Ln=function(){function e(t){y(this,e),this.hls=void 0,this.log=void 0,this.loader=null,this.uri=null,this.pathwayId=".",this.pathwayPriority=null,this.timeToLoad=300,this.reloadTimer=-1,this.updated=0,this.started=!1,this.enabled=!0,this.levels=null,this.audioTracks=null,this.subtitleTracks=null,this.penalizedPathways={},this.hls=t,this.log=K.log.bind(K,"[content-steering]:"),this.registerListeners()}return k(e,[{key:"registerListeners",value:function(){var e=this.hls;e.on(O.MANIFEST_LOADING,this.onManifestLoading,this),e.on(O.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(O.MANIFEST_PARSED,this.onManifestParsed,this),e.on(O.ERROR,this.onError,this)}},{key:"unregisterListeners",value:function(){var e=this.hls;e&&(e.off(O.MANIFEST_LOADING,this.onManifestLoading,this),e.off(O.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(O.MANIFEST_PARSED,this.onManifestParsed,this),e.off(O.ERROR,this.onError,this))}},{key:"startLoad",value:function(){if(this.started=!0,self.clearTimeout(this.reloadTimer),this.enabled&&this.uri)if(this.updated){var e=Math.max(1e3*this.timeToLoad-(performance.now()-this.updated),0);this.scheduleRefresh(this.uri,e)}else this.loadSteeringManifest(this.uri)}},{key:"stopLoad",value:function(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),self.clearTimeout(this.reloadTimer)}},{key:"destroy",value:function(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null}},{key:"removeLevel",value:function(e){var t=this.levels;t&&(this.levels=t.filter((function(t){return t!==e})))}},{key:"onManifestLoading",value:function(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null}},{key:"onManifestLoaded",value:function(e,t){var r=t.contentSteering;null!==r&&(this.pathwayId=r.pathwayId,this.uri=r.uri,this.started&&this.startLoad())}},{key:"onManifestParsed",value:function(e,t){this.audioTracks=t.audioTracks,this.subtitleTracks=t.subtitleTracks}},{key:"onError",value:function(e,t){var r=t.errorAction;if(2===(null==r?void 0:r.action)&&1===r.flags){var i=this.pathwayPriority,a=this.pathwayId;this.penalizedPathways[a]||(this.penalizedPathways[a]=performance.now()),!i&&this.levels&&(i=this.levels.reduce((function(e,t){return-1===e.indexOf(t.pathwayId)&&e.push(t.pathwayId),e}),[])),i&&i.length>1&&(this.updatePathwayPriority(i),r.resolved=this.pathwayId!==a)}}},{key:"filterParsedLevels",value:function(e){this.levels=e;var t=this.getLevelsForPathway(this.pathwayId);if(0===t.length){var r=e[0].pathwayId;this.log("No levels found in Pathway ".concat(this.pathwayId,'. Setting initial Pathway to "').concat(r,'"')),t=this.getLevelsForPathway(r),this.pathwayId=r}return t.length!==e.length?(this.log("Found ".concat(t.length,"/").concat(e.length,' levels in Pathway "').concat(this.pathwayId,'"')),t):e}},{key:"getLevelsForPathway",value:function(e){return null===this.levels?[]:this.levels.filter((function(t){return e===t.pathwayId}))}},{key:"updatePathwayPriority",value:function(e){var t;this.pathwayPriority=e;var r=this.penalizedPathways,i=performance.now();Object.keys(r).forEach((function(e){i-r[e]>3e5&&delete r[e]}));for(var a=0;a<e.length;a++){var n=e[a];if(!r[n]){if(n===this.pathwayId)return;var s=this.hls.nextLoadLevel,o=this.hls.levels[s];if((t=this.getLevelsForPathway(n)).length>0){this.log('Setting Pathway to "'.concat(n,'"')),this.pathwayId=n,this.hls.trigger(O.LEVELS_UPDATED,{levels:t});var l=this.hls.levels[s];o&&l&&this.levels&&(l.attrs["STABLE-VARIANT-ID"]!==o.attrs["STABLE-VARIANT-ID"]&&l.bitrate!==o.bitrate&&this.log("Unstable Pathways change from bitrate ".concat(o.bitrate," to ").concat(l.bitrate)),this.hls.nextLoadLevel=s);break}}}}},{key:"clonePathways",value:function(e){var t=this,r=this.levels;if(r){var a={},n={};e.forEach((function(e){var s=e.ID,o=e["BASE-ID"],l=e["URI-REPLACEMENT"];if(!r.some((function(e){return e.pathwayId===s}))){var u=t.getLevelsForPathway(o).map((function(e){var t=x({},e);t.details=void 0,t.url=Rn(e.uri,e.attrs["STABLE-VARIANT-ID"],"PER-VARIANT-URIS",l);var r=new Y(e.attrs);r["PATHWAY-ID"]=s;var i=r.AUDIO&&"".concat(r.AUDIO,"_clone_").concat(s),o=r.SUBTITLES&&"".concat(r.SUBTITLES,"_clone_").concat(s);i&&(a[r.AUDIO]=i,r.AUDIO=i),o&&(n[r.SUBTITLES]=o,r.SUBTITLES=o),t.attrs=r;var u=new Vt(t);return ur(u,"audio",i),ur(u,"text",o),u}));r.push.apply(r,i(u)),An(t.audioTracks,a,l,s),An(t.subtitleTracks,n,l,s)}}))}}},{key:"loadSteeringManifest",value:function(e){var t,r=this,i=this.hls.config,a=i.loader;this.loader&&this.loader.destroy(),this.loader=new a(i);try{t=new self.URL(e)}catch(t){return this.enabled=!1,void this.log("Failed to parse Steering Manifest URI: ".concat(e))}if("data:"!==t.protocol){var n=0|(this.hls.bandwidthEstimate||i.abrEwmaDefaultEstimate);t.searchParams.set("_HLS_pathway",this.pathwayId),t.searchParams.set("_HLS_throughput",""+n)}var s={responseType:"json",url:t.href},o=i.steeringManifestLoadPolicy.default,l=o.errorRetry||o.timeoutRetry||{},u={loadPolicy:o,timeout:o.maxLoadTimeMs,maxRetry:l.maxNumRetry||0,retryDelay:l.retryDelayMs||0,maxRetryDelay:l.maxRetryDelayMs||0},c={onSuccess:function(e,i,a,n){r.log('Loaded steering manifest: "'.concat(t,'"'));var s=e.data;if(1===s.VERSION){r.updated=performance.now(),r.timeToLoad=s.TTL;var o=s["RELOAD-URI"],l=s["PATHWAY-CLONES"],u=s["PATHWAY-PRIORITY"];if(o)try{r.uri=new self.URL(o,t).href}catch(e){return r.enabled=!1,void r.log("Failed to parse Steering Manifest RELOAD-URI: ".concat(o))}r.scheduleRefresh(r.uri||a.url),l&&r.clonePathways(l),u&&r.updatePathwayPriority(u)}else r.log("Steering VERSION ".concat(s.VERSION," not supported!"))},onError:function(e,t,i,a){if(r.log("Error loading steering manifest: ".concat(e.code," ").concat(e.text," (").concat(t.url,")")),r.stopLoad(),410===e.code)return r.enabled=!1,void r.log("Steering manifest ".concat(t.url," no longer available"));var n=1e3*r.timeToLoad;if(429!==e.code)r.scheduleRefresh(r.uri||t.url,n);else{var s=r.loader;if("function"==typeof(null==s?void 0:s.getResponseHeader)){var o=s.getResponseHeader("Retry-After");o&&(n=1e3*parseFloat(o))}r.log("Steering manifest ".concat(t.url," rate limited"))}},onTimeout:function(e,t,i){r.log("Timeout loading steering manifest (".concat(t.url,")")),r.scheduleRefresh(r.uri||t.url)}};this.log("Requesting steering manifest: ".concat(t)),this.loader.load(s,u,c)}},{key:"scheduleRefresh",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3*this.timeToLoad;self.clearTimeout(this.reloadTimer),this.reloadTimer=self.setTimeout((function(){t.loadSteeringManifest(e)}),r)}}]),e}();function An(e,t,r,a){e&&Object.keys(t).forEach((function(n){var s=e.filter((function(e){return e.groupId===n})).map((function(e){var i=x({},e);return i.details=void 0,i.attrs=new Y(i.attrs),i.url=i.attrs.URI=Rn(e.url,e.attrs["STABLE-RENDITION-ID"],"PER-RENDITION-URIS",r),i.groupId=i.attrs["GROUP-ID"]=t[n],i.attrs["PATHWAY-ID"]=a,i}));e.push.apply(e,i(s))}))}function Rn(e,t,r,i){var a,n=i.HOST,s=i.PARAMS,o=i[r];t&&(a=null==o?void 0:o[t])&&(e=a);var l=new self.URL(e);return n&&!a&&(l.host=n),s&&Object.keys(s).sort().forEach((function(e){e&&l.searchParams.set(e,s[e])})),l.href}var bn=/^age:\s*[\d.]+\s*$/im,Dn=function(){function e(t){y(this,e),this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrSetup=t&&t.xhrSetup||null,this.stats=new q,this.retryDelay=0}return k(e,[{key:"destroy",value:function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null}},{key:"abortInternal",value:function(){var e=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),e&&(e.onreadystatechange=null,e.onprogress=null,4!==e.readyState&&(this.stats.aborted=!0,e.abort()))}},{key:"abort",value:function(){var e;this.abortInternal(),null!=(e=this.callbacks)&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)}},{key:"load",value:function(e,t,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=e,this.config=t,this.callbacks=r,this.loadInternal()}},{key:"loadInternal",value:function(){var e=this,t=this.config,r=this.context;if(t){var i=this.loader=new self.XMLHttpRequest,a=this.stats;a.loading.first=0,a.loaded=0,a.aborted=!1;var n=this.xhrSetup;n?Promise.resolve().then((function(){if(!e.stats.aborted)return n(i,r.url)})).catch((function(e){return i.open("GET",r.url,!0),n(i,r.url)})).then((function(){e.stats.aborted||e.openAndSendXhr(i,r,t)})).catch((function(t){e.callbacks.onError({code:i.status,text:t.message},r,i,a)})):this.openAndSendXhr(i,r,t)}}},{key:"openAndSendXhr",value:function(e,t,r){e.readyState||e.open("GET",t.url,!0);var i=this.context.headers,a=r.loadPolicy,n=a.maxTimeToFirstByteMs,s=a.maxLoadTimeMs;if(i)for(var o in i)e.setRequestHeader(o,i[o]);t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=t.responseType,self.clearTimeout(this.requestTimeout),r.timeout=n&&F(n)?n:s,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),r.timeout),e.send()}},{key:"readystatechange",value:function(){var e=this.context,t=this.loader,r=this.stats;if(e&&t){var i=t.readyState,a=this.config;if(!r.aborted&&i>=2&&(0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start),a.timeout!==a.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),a.timeout=a.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),a.loadPolicy.maxLoadTimeMs-(r.loading.first-r.loading.start)))),4===i)){self.clearTimeout(this.requestTimeout),t.onreadystatechange=null,t.onprogress=null;var n=t.status,s="text"!==t.responseType;if(n>=200&&n<300&&(s&&t.response||null!==t.responseText)){r.loading.end=Math.max(self.performance.now(),r.loading.first);var o=s?t.response:t.responseText,l="arraybuffer"===t.responseType?o.byteLength:o.length;if(r.loaded=r.total=l,r.bwEstimate=8e3*r.total/(r.loading.end-r.loading.first),!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,e,o,t),!this.callbacks)return;var c={url:t.responseURL,data:o,code:n};this.callbacks.onSuccess(c,r,e,t)}else{var h=a.loadPolicy.errorRetry;er(h,r.retry,!1,n)?this.retry(h):(K.error("".concat(n," while loading ").concat(e.url)),this.callbacks.onError({code:n,text:t.statusText},e,t,r))}}}}},{key:"loadtimeout",value:function(){var e,t=null==(e=this.config)?void 0:e.loadPolicy.timeoutRetry;if(er(t,this.stats.retry,!0))this.retry(t);else{K.warn("timeout while loading ".concat(this.context.url));var r=this.callbacks;r&&(this.abortInternal(),r.onTimeout(this.stats,this.context,this.loader))}}},{key:"retry",value:function(e){var t=this.context,r=this.stats;this.retryDelay=Jt(e,r.retry),r.retry++,K.warn("".concat(status?"HTTP Status "+status:"Timeout"," while loading ").concat(t.url,", retrying ").concat(r.retry,"/").concat(e.maxNumRetry," in ").concat(this.retryDelay,"ms")),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)}},{key:"loadprogress",value:function(e){var t=this.stats;t.loaded=e.loaded,e.lengthComputable&&(t.total=e.total)}},{key:"getCacheAge",value:function(){var e=null;if(this.loader&&bn.test(this.loader.getAllResponseHeaders())){var t=this.loader.getResponseHeader("age");e=t?parseFloat(t):null}return e}},{key:"getResponseHeader",value:function(e){return this.loader&&new RegExp("^".concat(e,":\\s*[\\d.]+\\s*$"),"im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(e):null}}]),e}(),In=/(\d+)-(\d+)\/(\d+)/,wn=function(){function e(t){y(this,e),this.fetchSetup=void 0,this.requestTimeout=void 0,this.request=void 0,this.response=void 0,this.controller=void 0,this.context=void 0,this.config=null,this.callbacks=null,this.stats=void 0,this.loader=null,this.fetchSetup=t.fetchSetup||Cn,this.controller=new self.AbortController,this.stats=new q}return k(e,[{key:"destroy",value:function(){this.loader=this.callbacks=null,this.abortInternal()}},{key:"abortInternal",value:function(){var e=this.response;null!=e&&e.ok||(this.stats.aborted=!0,this.controller.abort())}},{key:"abort",value:function(){var e;this.abortInternal(),null!=(e=this.callbacks)&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.response)}},{key:"load",value:function(e,t,r){var i=this,a=this.stats;if(a.loading.start)throw new Error("Loader can only be used once.");a.loading.start=self.performance.now();var n=function(e,t){var r={method:"GET",mode:"cors",credentials:"same-origin",signal:t,headers:new self.Headers(x({},e.headers))};return e.rangeEnd&&r.headers.set("Range","bytes="+e.rangeStart+"-"+String(e.rangeEnd-1)),r}(e,this.controller.signal),s=r.onProgress,o="arraybuffer"===e.responseType,l=o?"byteLength":"length",u=t.loadPolicy,c=u.maxTimeToFirstByteMs,h=u.maxLoadTimeMs;this.context=e,this.config=t,this.callbacks=r,this.request=this.fetchSetup(e,n),self.clearTimeout(this.requestTimeout),t.timeout=c&&F(c)?c:h,this.requestTimeout=self.setTimeout((function(){i.abortInternal(),r.onTimeout(a,e,i.response)}),t.timeout),self.fetch(this.request).then((function(n){i.response=i.loader=n;var l=Math.max(self.performance.now(),a.loading.start);if(self.clearTimeout(i.requestTimeout),t.timeout=h,i.requestTimeout=self.setTimeout((function(){i.abortInternal(),r.onTimeout(a,e,i.response)}),h-(l-a.loading.start)),!n.ok){var u=n.status,c=n.statusText;throw new _n(c||"fetch, bad network response",u,n)}return a.loading.first=l,a.total=function(e){var t=e.get("Content-Range");if(t){var r=function(e){var t=In.exec(e);if(t)return parseInt(t[2])-parseInt(t[1])+1}(t);if(F(r))return r}var i=e.get("Content-Length");if(i)return parseInt(i)}(n.headers)||a.total,s&&F(t.highWaterMark)?i.loadProgressively(n,a,e,t.highWaterMark,s):o?n.arrayBuffer():"json"===e.responseType?n.json():n.text()})).then((function(n){var o=i.response;self.clearTimeout(i.requestTimeout),a.loading.end=Math.max(self.performance.now(),a.loading.first);var u=n[l];u&&(a.loaded=a.total=u);var c={url:o.url,data:n,code:o.status};s&&!F(t.highWaterMark)&&s(a,e,n,o),r.onSuccess(c,a,e,o)})).catch((function(t){if(self.clearTimeout(i.requestTimeout),!a.aborted){var n=t&&t.code||0,s=t?t.message:null;r.onError({code:n,text:s},e,t?t.details:null,a)}}))}},{key:"getCacheAge",value:function(){var e=null;if(this.response){var t=this.response.headers.get("age");e=t?parseFloat(t):null}return e}},{key:"getResponseHeader",value:function(e){return this.response?this.response.headers.get(e):null}},{key:"loadProgressively",value:function(e,t,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=arguments.length>4?arguments[4]:void 0,n=new la,s=e.body.getReader();return function o(){return s.read().then((function(s){if(s.done)return n.dataLength&&a(t,r,n.flush(),e),Promise.resolve(new ArrayBuffer(0));var l=s.value,u=l.length;return t.loaded+=u,u<i||n.dataLength?(n.push(l),n.dataLength>=i&&a(t,r,n.flush(),e)):a(t,r,l,e),o()})).catch((function(){return Promise.reject()}))}()}}]),e}();function Cn(e,t){return new self.Request(e.url,t)}var _n=function(e){c(r,e);var t=d(r);function r(e,i,a){var n;return y(this,r),(n=t.call(this,e)).code=void 0,n.details=void 0,n.code=i,n.details=a,n}return k(r)}(o(Error)),Pn=/\s/,xn=_(_({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,maxBufferSize:6e7,maxBufferHole:.1,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,maxFragLookUpTolerance:.25,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxLiveSyncPlaybackRate:1,liveDurationInfinity:!1,liveBackBufferLength:null,maxMaxBufferLength:600,enableWorker:!0,workerPath:null,enableSoftwareAES:!0,startLevel:void 0,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,loader:Dn,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:oa,bufferController:Ta,capLevelController:gn,errorController:sr,fpsController:mn,stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystems:{},drmSystemOptions:{},requestMediaKeySystemAccessFunc:de,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,certLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null}},keyLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"},errorRetry:{maxNumRetry:8,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"}}},manifestLoadPolicy:{default:{maxTimeToFirstByteMs:1/0,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},playlistLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:2,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},fragLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:12e4,timeoutRetry:{maxNumRetry:4,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:6,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},steeringManifestLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3},{cueHandler:{newCue:function(e,t,r,i){for(var a,n,s,o,l,u=[],c=self.VTTCue||self.TextTrackCue,h=0;h<i.rows.length;h++)if(s=!0,o=0,l="",!(a=i.rows[h]).isEmpty()){for(var d,f=0;f<a.chars.length;f++)Pn.test(a.chars[f].uchar)&&s?o++:(l+=a.chars[f].uchar,s=!1);a.cueStartTime=t,t===r&&(r+=1e-4),o>=16?o--:o++;var v=za(l.trim()),g=en(t,r,v);null!=e&&null!=(d=e.cues)&&d.getCueById(g)||((n=new c(t,r,v)).id=g,n.line=h+1,n.align="left",n.position=10+Math.min(80,10*Math.floor(8*o/32)),u.push(n))}return e&&u.length&&(u.sort((function(e,t){return"auto"===e.line||"auto"===t.line?0:e.line>8&&t.line>8?t.line-e.line:e.line-t.line})),u.forEach((function(t){return _t(e,t)}))),u}},enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}),{},{subtitleStreamController:fa,subtitleTrackController:ga,timelineController:fn,audioStreamController:ua,audioTrackController:ca,emeController:pn,cmcdController:Sn,contentSteeringController:Ln});function Fn(e){return e&&"object"===E(e)?Array.isArray(e)?e.map(Fn):Object.keys(e).reduce((function(t,r){return t[r]=Fn(e[r]),t}),{}):e}var On=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};y(this,e),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this._emitter=new ea,this._autoLevelCapping=void 0,this._maxHdcpLevel=null,this.abrController=void 0,this.bufferController=void 0,this.capLevelController=void 0,this.latencyController=void 0,this.levelController=void 0,this.streamController=void 0,this.audioTrackController=void 0,this.subtitleTrackController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this.url=null,function(e,t){if(self.console&&!0===e||"object"===E(e)){!function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),i=1;i<t;i++)r[i-1]=arguments[i];r.forEach((function(t){G[t]=e[t]?e[t].bind(e):function(e){var t=self.console[e];return t?t.bind(self.console,"[".concat(e,"] >")):U}(t)}))}(e,"debug","log","info","warn","error");try{G.log('Debug logs enabled for "'.concat("Hls instance",'" in hls.js version ',"1.4.12"))}catch(e){G=B}}else G=B}(t.debug||!1);var r=this.config=function(e,t){if((t.liveSyncDurationCount||t.liveMaxLatencyDurationCount)&&(t.liveSyncDuration||t.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==t.liveMaxLatencyDurationCount&&(void 0===t.liveSyncDurationCount||t.liveMaxLatencyDurationCount<=t.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==t.liveMaxLatencyDuration&&(void 0===t.liveSyncDuration||t.liveMaxLatencyDuration<=t.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');var r=Fn(e),i=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((function(e){var a="".concat("level"===e?"playlist":e,"LoadPolicy"),n=void 0===t[a],s=[];i.forEach((function(i){var o="".concat(e,"Loading").concat(i),l=t[o];if(void 0!==l&&n){s.push(o);var u=r[a].default;switch(t[a]={default:u},i){case"TimeOut":u.maxLoadTimeMs=l,u.maxTimeToFirstByteMs=l;break;case"MaxRetry":u.errorRetry.maxNumRetry=l,u.timeoutRetry.maxNumRetry=l;break;case"RetryDelay":u.errorRetry.retryDelayMs=l,u.timeoutRetry.retryDelayMs=l;break;case"MaxRetryTimeout":u.errorRetry.maxRetryDelayMs=l,u.timeoutRetry.maxRetryDelayMs=l}}})),s.length&&K.warn('hls.js config: "'.concat(s.join('", "'),'" setting(s) are deprecated, use "').concat(a,'": ').concat(JSON.stringify(t[a])))})),_(_({},r),t)}(e.DefaultConfig,t);this.userConfig=t,this._autoLevelCapping=-1,r.progressive&&function(e){var t=e.loader;t!==wn&&t!==Dn?(K.log("[config]: Custom loader detected, cannot enable progressive streaming"),e.progressive=!1):function(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(e){}return!1}()&&(e.loader=wn,e.progressive=!0,e.enableSoftwareAES=!0,K.log("[config]: Progressive streaming enabled, using FetchLoader"))}(r);var i=r.abrController,a=r.bufferController,n=r.capLevelController,s=r.errorController,o=r.fpsController,l=new s(this),u=this.abrController=new i(this),c=this.bufferController=new a(this),h=this.capLevelController=new n(this),d=new o(this),f=new wt(this),v=new Bt(this),g=r.contentSteeringController,m=g?new g(this):null,p=this.levelController=new lr(this,m),k=new gr(this),T=new Lr(this.config),S=this.streamController=new aa(this,k,T);h.setStreamController(S),d.setStreamController(S);var L=[f,p,S];m&&L.splice(1,0,m),this.networkControllers=L;var A=[u,c,h,d,v,k];this.audioTrackController=this.createController(r.audioTrackController,L);var R=r.audioStreamController;R&&L.push(new R(this,k,T)),this.subtitleTrackController=this.createController(r.subtitleTrackController,L);var b=r.subtitleStreamController;b&&L.push(new b(this,k,T)),this.createController(r.timelineController,A),T.emeController=this.emeController=this.createController(r.emeController,A),this.cmcdController=this.createController(r.cmcdController,A),this.latencyController=this.createController(Gt,A),this.coreComponents=A,L.push(l);var D=l.onErrorOut;"function"==typeof D&&this.on(O.ERROR,D,l)}return k(e,[{key:"createController",value:function(e,t){if(e){var r=new e(this);return t&&t.push(r),r}return null}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this;this._emitter.on(e,t,r)}},{key:"once",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this;this._emitter.once(e,t,r)}},{key:"removeAllListeners",value:function(e){this._emitter.removeAllListeners(e)}},{key:"off",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this,i=arguments.length>3?arguments[3]:void 0;this._emitter.off(e,t,r,i)}},{key:"listeners",value:function(e){return this._emitter.listeners(e)}},{key:"emit",value:function(e,t,r){return this._emitter.emit(e,t,r)}},{key:"trigger",value:function(e,t){if(this.config.debug)return this.emit(e,e,t);try{return this.emit(e,e,t)}catch(t){K.error("An internal error happened while handling event "+e+'. Error message: "'+t.message+'". Here is a stacktrace:',t),this.trigger(O.ERROR,{type:M.OTHER_ERROR,details:N.INTERNAL_EXCEPTION,fatal:!1,event:e,error:t})}return!1}},{key:"listenerCount",value:function(e){return this._emitter.listenerCount(e)}},{key:"destroy",value:function(){K.log("destroy"),this.trigger(O.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((function(e){return e.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(e){return e.destroy()})),this.coreComponents.length=0;var e=this.config;e.xhrSetup=e.fetchSetup=void 0,this.userConfig=null}},{key:"attachMedia",value:function(e){K.log("attachMedia"),this._media=e,this.trigger(O.MEDIA_ATTACHING,{media:e})}},{key:"detachMedia",value:function(){K.log("detachMedia"),this.trigger(O.MEDIA_DETACHING,void 0),this._media=null}},{key:"loadSource",value:function(e){this.stopLoad();var t=this.media,r=this.url,i=this.url=w.buildAbsoluteURL(self.location.href,e,{alwaysNormalize:!0});K.log("loadSource:".concat(i)),t&&r&&(r!==i||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(t)),this.trigger(O.MANIFEST_LOADING,{url:e})}},{key:"startLoad",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1;K.log("startLoad(".concat(e,")")),this.networkControllers.forEach((function(t){t.startLoad(e)}))}},{key:"stopLoad",value:function(){K.log("stopLoad"),this.networkControllers.forEach((function(e){e.stopLoad()}))}},{key:"swapAudioCodec",value:function(){K.log("swapAudioCodec"),this.streamController.swapAudioCodec()}},{key:"recoverMediaError",value:function(){K.log("recoverMediaError");var e=this._media;this.detachMedia(),e&&this.attachMedia(e)}},{key:"removeLevel",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.levelController.removeLevel(e,t)}},{key:"levels",get:function(){return this.levelController.levels||[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(e){K.log("set currentLevel:".concat(e)),this.loadLevel=e,this.abrController.clearTimer(),this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(e){K.log("set nextLevel:".concat(e)),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(e){K.log("set loadLevel:".concat(e)),this.levelController.manualLevel=e}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(e){this.levelController.nextLoadLevel=e}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(e){K.log("set firstLevel:".concat(e)),this.levelController.firstLevel=e}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(e){K.log("set startLevel:".concat(e)),-1!==e&&(e=Math.max(e,this.minAutoLevel)),this.levelController.startLevel=e}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(e){var t=!!e;t!==this.config.capLevelToPlayerSize&&(t?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=t)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping!==e&&(K.log("set autoLevelCapping:".concat(e)),this._autoLevelCapping=e)}},{key:"bandwidthEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimate():NaN}},{key:"ttfbEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimateTTFB():NaN}},{key:"maxHdcpLevel",get:function(){return this._maxHdcpLevel},set:function(e){Kt.indexOf(e)>-1&&(this._maxHdcpLevel=e)}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var e=this.levels,t=this.config.minAutoBitrate;if(!e)return 0;for(var r=e.length,i=0;i<r;i++)if(e[i].maxBitrate>=t)return i;return 0}},{key:"maxAutoLevel",get:function(){var e,t=this.levels,r=this.autoLevelCapping,i=this.maxHdcpLevel;if(e=-1===r&&t&&t.length?t.length-1:r,i)for(var a=e;a--;){var n=t[a].attrs["HDCP-LEVEL"];if(n&&n<=i)return a}return e}},{key:"nextAutoLevel",get:function(){return Math.min(Math.max(this.abrController.nextAutoLevel,this.minAutoLevel),this.maxAutoLevel)},set:function(e){this.abrController.nextAutoLevel=Math.max(this.minAutoLevel,e)}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"mainForwardBufferInfo",get:function(){return this.streamController.getMainFwdBufferInfo()}},{key:"audioTracks",get:function(){var e=this.audioTrackController;return e?e.audioTracks:[]}},{key:"audioTrack",get:function(){var e=this.audioTrackController;return e?e.audioTrack:-1},set:function(e){var t=this.audioTrackController;t&&(t.audioTrack=e)}},{key:"subtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTrack:-1},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var e=this.subtitleTrackController;return!!e&&e.subtitleDisplay},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(e){this.config.lowLatencyMode=e}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}}],[{key:"version",get:function(){return"1.4.12"}},{key:"isSupported",value:function(){return function(){var e=it();if(!e)return!1;var t=zr(),r=e&&"function"==typeof e.isTypeSupported&&e.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'),i=!t||t.prototype&&"function"==typeof t.prototype.appendBuffer&&"function"==typeof t.prototype.remove;return!!r&&!!i}()}},{key:"Events",get:function(){return O}},{key:"ErrorTypes",get:function(){return M}},{key:"ErrorDetails",get:function(){return N}},{key:"DefaultConfig",get:function(){return e.defaultConfig?e.defaultConfig:xn},set:function(t){e.defaultConfig=t}}]),e}();On.defaultConfig=void 0}}]);
|