!function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,r={exports:{}};var a=(t||(t=1,function(e){var t=Object.prototype.hasOwnProperty,r="~";function a(){}function i(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function n(e,t,a,n,s){if("function"!=typeof a)throw new TypeError("The listener must be a function");var o=new i(a,n||e,s),u=r?r+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],o]:e._events[u].push(o):(e._events[u]=o,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new a:delete e._events[t]}function o(){this._events=new a,this._eventsCount=0}Object.create&&(a.prototype=Object.create(null),(new a).__proto__||(r=!1)),o.prototype.eventNames=function(){var e,a,i=[];if(0===this._eventsCount)return i;for(a in e=this._events)t.call(e,a)&&i.push(r?a.slice(1):a);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},o.prototype.listeners=function(e){var t=r?r+e:e,a=this._events[t];if(!a)return[];if(a.fn)return[a.fn];for(var i=0,n=a.length,s=new Array(n);i0)return e.subarray(r,r+a)}var 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}({}),v=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.KEY_SYSTEM_DESTROY_MEDIA_KEYS_ERROR="keySystemDestroyMediaKeysError",e.KEY_SYSTEM_DESTROY_CLOSE_SESSION_ERROR="keySystemDestroyCloseSessionError",e.KEY_SYSTEM_DESTROY_REMOVE_SESSION_ERROR="keySystemDestroyRemoveSessionError",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.ASSET_LIST_LOAD_ERROR="assetListLoadError",e.ASSET_LIST_LOAD_TIMEOUT="assetListLoadTimeout",e.ASSET_LIST_PARSING_ERROR="assetListParsingError",e.INTERSTITIAL_ASSET_ITEM_ERROR="interstitialAssetItemError",e.INTERNAL_EXCEPTION="internalException",e.INTERNAL_ABORTED="aborted",e.ATTACH_MEDIA_ERROR="attachMediaError",e.UNKNOWN="unknown",e}({}),y=function(e){return e.MEDIA_ATTACHING="hlsMediaAttaching",e.MEDIA_ATTACHED="hlsMediaAttached",e.MEDIA_DETACHING="hlsMediaDetaching",e.MEDIA_DETACHED="hlsMediaDetached",e.MEDIA_ENDED="hlsMediaEnded",e.STALL_RESOLVED="hlsStallResolved",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.BUFFERED_TO_END="hlsBufferedToEnd",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.AUDIO_TRACK_UPDATED="hlsAudioTrackUpdated",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_TRACK_UPDATED="hlsSubtitleTrackUpdated",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.MAX_AUTO_LEVEL_UPDATED="hlsMaxAutoLevelUpdated",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.STEERING_MANIFEST_LOADED="hlsSteeringManifestLoaded",e.ASSET_LIST_LOADING="hlsAssetListLoading",e.ASSET_LIST_LOADED="hlsAssetListLoaded",e.INTERSTITIALS_UPDATED="hlsInterstitialsUpdated",e.INTERSTITIALS_BUFFERED_TO_BOUNDARY="hlsInterstitialsBufferedToBoundary",e.INTERSTITIAL_ASSET_PLAYER_CREATED="hlsInterstitialAssetPlayerCreated",e.INTERSTITIAL_STARTED="hlsInterstitialStarted",e.INTERSTITIAL_ASSET_STARTED="hlsInterstitialAssetStarted",e.INTERSTITIAL_ASSET_ENDED="hlsInterstitialAssetEnded",e.INTERSTITIAL_ASSET_ERROR="hlsInterstitialAssetError",e.INTERSTITIAL_ENDED="hlsInterstitialEnded",e.INTERSTITIALS_PRIMARY_RESUMED="hlsInterstitialsPrimaryResumed",e.PLAYOUT_LIMIT_REACHED="hlsPlayoutLimitReached",e.EVENT_CUE_ENTER="hlsEventCueEnter",e}({}),g=function(e,t){this.trace=void 0,this.debug=void 0,this.log=void 0,this.warn=void 0,this.info=void 0,this.error=void 0;var r="["+e+"]:";this.trace=S,this.debug=t.debug.bind(null,r),this.log=t.log.bind(null,r),this.warn=t.warn.bind(null,r),this.info=t.info.bind(null,r),this.error=t.error.bind(null,r)},S=function(){},T={trace:S,debug:S,log:S,warn:S,info:S,error:S};function E(){return s({},T)}function b(e,t,r){return t[e]?t[e].bind(t):(a=e,(i=self.console[a])?i.bind(self.console,"["+a+"] >"):S);var a,i}var A=E();var _=A;function k(e,t){return 255===e[t]&&240==(246&e[t+1])}function R(e,t){return 1&e[t+1]?7:9}function I(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function w(e,t){return t+1=e.length)return!1;var a=I(e,t);if(a<=r)return!1;var i=t+a;return i===e.length||w(e,i)}return!1}function U(e,t,r,a,i){if(!e.samplerate){var n=function(e,t,r,a){var i=t[r+2],n=i>>2&15;if(!(n>12)){var s=1+(i>>6&3),o=t[r+3]>>6&3|(1&i)<<2,u="mp4a.40."+s,d=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][n],c=n;5!==s&&29!==s||(c-=3);var l=[s<<3|(14&c)>>1,(1&c)<<7|o<<3];return _.log("manifest codec:"+a+", parsed codec:"+u+", channels:"+o+", rate:"+d+" (ADTS object type:"+s+" sampling index:"+n+")"),{config:l,samplerate:d,channelCount:o,codec:u,parsedCodec:u,manifestCodec:a}}var h=new Error("invalid ADTS sampling index:"+n);e.emit(y.ERROR,y.ERROR,{type:m.MEDIA_ERROR,details:v.FRAG_PARSING_ERROR,fatal:!0,error:h,reason:h.message})}(t,r,a,i);if(!n)return;s(e,n)}}function x(e){return 9216e4/e}function D(e,t,r,a,i){var n,s=a+i*x(e.samplerate),o=function(e,t){var r=R(e,t);if(t+r<=e.length){var a=I(e,t)-r;if(a>0)return{headerLength:r,frameLength:a}}}(t,r);if(o){var u=o.frameLength,d=o.headerLength,c=d+u,l=Math.max(0,r+c-t.length);l?(n=new Uint8Array(c-d)).set(t.subarray(r+d,t.length),0):n=t.subarray(r+d,r+c);var h={unit:n,pts:s};return l||e.samples.push(h),{sample:h,length:c,missing:l}}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 C=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},L=Number.isSafeInteger||function(e){return"number"==typeof e&&Math.abs(e)<=O},O=Number.MAX_SAFE_INTEGER||9007199254740991;function B(e,t){return h(e,t)&&f(e,t+6)+10<=e.length-t}function M(e,t){if(void 0===t&&(t=!1),"undefined"!=typeof TextDecoder){var r=new TextDecoder("utf-8").decode(e);if(t){var a=r.indexOf("\0");return-1!==a?r.substring(0,a):r}return r.replace(/\0/g,"")}for(var i,n,s,o=e.length,u="",d=0;d>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=String.fromCharCode(i);break;case 12:case 13:n=e[d++],u+=String.fromCharCode((31&i)<<6|63&n);break;case 14:n=e[d++],s=e[d++],u+=String.fromCharCode((15&i)<<12|(63&n)<<6|(63&s)<<0)}}return u}function N(e,t,r){return void 0===t&&(t=0),void 0===r&&(r=1/0),function(e,t,r,a){var i=function(e){return e instanceof ArrayBuffer?e:e.buffer}(e),n=1;"BYTES_PER_ELEMENT"in a&&(n=a.BYTES_PER_ELEMENT);var s=(l=e,l&&l.buffer instanceof ArrayBuffer&&void 0!==l.byteLength&&void 0!==l.byteOffset?e.byteOffset:0),o=(s+e.byteLength)/n,u=(s+t)/n,d=Math.floor(Math.max(0,Math.min(u,o))),c=Math.floor(Math.min(d+Math.max(r,0),o));var l;return new a(i,d,c-d)}(e,t,r,Uint8Array)}function F(e){var t={key:e.type,description:"",data:"",mimeType:null,pictureType:null};if(!(e.size<2))if(3===e.data[0]){var r=e.data.subarray(1).indexOf(0);if(-1!==r){var a=M(N(e.data,1,r)),i=e.data[2+r],n=e.data.subarray(3+r).indexOf(0);if(-1!==n){var s,o=M(N(e.data,3+r,n));return s="--\x3e"===a?M(N(e.data,4+r+n)):function(e){return e instanceof ArrayBuffer?e:0==e.byteOffset&&e.byteLength==e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer}(e.data.subarray(4+r+n)),t.mimeType=a,t.pictureType=i,t.description=o,t.data=s,t}}}else console.log("Ignore frame with unrecognized character encoding")}function G(e){return"PRIV"===e.type?function(e){if(!(e.size<2)){var t=M(e.data,!0),r=new Uint8Array(e.data.subarray(t.length+1));return{key:e.type,info:t,data:r.buffer}}}(e):"W"===e.type[0]?function(e){if("WXXX"===e.type){if(e.size<2)return;var t=1,r=M(e.data.subarray(t),!0);t+=r.length+1;var a=M(e.data.subarray(t));return{key:e.type,info:r,data:a}}var i=M(e.data);return{key:e.type,info:"",data:i}}(e):"APIC"===e.type?F(e):function(e){if(!(e.size<2)){if("TXXX"===e.type){var t=1,r=M(e.data.subarray(t),!0);t+=r.length+1;var a=M(e.data.subarray(t));return{key:e.type,info:r,data:a}}var i=M(e.data.subarray(1));return{key:e.type,info:"",data:i}}}(e)}function V(e){var t=String.fromCharCode(e[0],e[1],e[2],e[3]),r=f(e,4);return{type:t,size:r,data:e.subarray(10,10+r)}}var K=10,Y=10;function j(e){return e&&"PRIV"===e.key&&"com.apple.streaming.transportStreamTimestamp"===e.info}function z(e){if(8===e.data.byteLength){var t=new Uint8Array(e.data),r=1&t[3],a=(t[4]<<23)+(t[5]<<15)+(t[6]<<7)+t[7];return a/=45,r&&(a+=47721858.84),Math.round(a)}}function H(e){for(var t=function(e){for(var t=0,r=[];h(e,t);){var a=f(e,t+6);e[t+5]>>6&1&&(t+=K);for(var i=(t+=K)+a;t+Y1?i+n:a;if(oe(e.subarray(i+4,i+8))===t[0])if(1===t.length)r.push(e.subarray(i+8,s));else{var o=he(e.subarray(i+8,s),t.slice(1));o.length&&ne.apply(r,o)}i=s}return r}function fe(e){var t=[],r=e[0],a=8,i=de(e,a);a+=4;var n=0,s=0;0===r?(n=de(e,a),s=de(e,a+4),a+=8):(n=ce(e,a),s=ce(e,a+8),a+=16),a+=2;var o=e.length+s,u=ue(e,a);a+=2;for(var d=0;d>>31)return _.warn("SIDX has hierarchical references (not supported)"),null;var f=de(e,c);c+=4,t.push({referenceSize:h,subsegmentDuration:f,info:{duration:f/i,start:o,end:o+h-1}}),o+=h,a=c+=4}return{earliestPresentationTime:n,timescale:i,version:r,referencesCount:u,references:t}}function pe(e){for(var t=[],r=he(e,["moov","trak"]),a=0;a3&&(n+="."+ge(d[1])+ge(d[2])+ge(d[3]),t=ve("avc1"===u?"dva1":"dvav",a));break;case"mp4a":var c=he(r,[i])[0],l=he(c.subarray(28),["esds"])[0];if(l&&l.length>7){var h=4;if(3!==l[h++])break;h=ye(l,h),h+=2;var f=l[h++];if(128&f&&(h+=2),64&f&&(h+=l[h++]),4!==l[h++])break;h=ye(l,h);var p=l[h++];if(64!==p)break;if(n+="."+ge(p),h+=12,5!==l[h++])break;h=ye(l,h);var m=l[h++],v=(248&m)>>3;31===v&&(v+=1+((7&m)<<3)+((224&l[h])>>5)),n+="."+v}break;case"hvc1":case"hev1":var y=he(a,["hvcC"])[0];if(y&&y.length>12){var g=y[1],S=["","A","B","C"][g>>6],T=31&g,E=de(y,2),b=(32&g)>>5?"H":"L",A=y[12],_=y.subarray(6,12);n+="."+S+T,n+="."+function(e){for(var t=0,r=0;r<32;r++)t|=(e>>r&1)<<31-r;return t>>>0}(E).toString(16).toUpperCase(),n+="."+b+A;for(var k="",R=_.length;R--;){var I=_[R];if(I||k)k="."+I.toString(16).toUpperCase()+k}n+=k}t=ve("hev1"==u?"dvhe":"dvh1",a);break;case"dvh1":case"dvhe":case"dvav":case"dva1":case"dav1":n=ve(n,a)||n;break;case"vp09":var w=he(a,["vpcC"])[0];if(w&&w.length>6){var P=w[4],U=w[5],x=w[6]>>4&15;n+="."+Se(P)+"."+Se(U)+"."+Se(x)}break;case"av01":var D=he(a,["av1C"])[0];if(D&&D.length>2){var C=D[1]>>>5,L=31&D[1],O=D[2]>>>7?"H":"M",B=(64&D[2])>>6,M=(32&D[2])>>5,N=2===C&&B?M?12:10:B?10:8,F=(16&D[2])>>4,G=(8&D[2])>>3,V=(4&D[2])>>2,K=3&D[2];n+="."+C+"."+Se(L)+O+"."+Se(N)+"."+F+"."+G+V+K+"."+Se(1)+"."+Se(1)+"."+Se(1)+".0",t=ve("dav1",a)}}return{codec:n,encrypted:s,supplemental:t}}function ve(e,t){var r=he(t,["dvvC"]),a=r.length?r[0]:he(t,["dvcC"])[0];if(a){var i=a[2]>>1&127,n=a[2]<<5&32|a[3]>>3&31;return e+"."+Se(i)+"."+Se(n)}}function ye(e,t){for(var r=t+5;128&e[t++]&&t0;n||(i=he(a,["encv"])),i.forEach((function(e){he(n?e.subarray(28):e.subarray(78),["sinf"]).forEach((function(e){var r=function(e){var t=he(e,["schm"])[0];if(t){var r=oe(t.subarray(4,8));if("cbcs"===r||"cenc"===r){var a=he(e,["schi","tenc"])[0];if(a)return a}}}(e);r&&t(r,n)}))}))}}))}(e,(function(e,t){var a=e.subarray(8,24);a.some((function(e){return 0!==e}))||(_.log("[eme] Patching keyId in 'enc"+(t?"a":"v")+">sinf>>tenc' box: "+q(a)+" -> "+q(r)),e.set(r,8))}))}}function Ee(e,t){var r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}function be(e,t){var r=[],a=t.samples,i=t.timescale,n=t.id,s=!1;return he(a,["moof"]).map((function(o){var u=o.byteOffset-8;he(o,["traf"]).map((function(o){var d=he(o,["tfdt"]).map((function(e){var t=e[0],r=de(e,4);return 1===t&&(r*=Math.pow(2,32),r+=de(e,8)),r/i}))[0];return void 0!==d&&(e=d),he(o,["tfhd"]).map((function(d){var c=de(d,4),l=16777215&de(d,0),h=0,f=0!=(16&l),p=0,m=0!=(32&l),v=8;c===n&&(0!=(1&l)&&(v+=8),0!=(2&l)&&(v+=4),0!=(8&l)&&(h=de(d,v),v+=4),f&&(p=de(d,v),v+=4),m&&(v+=4),"video"===t.type&&(s=function(e){if(!e)return!1;var t=e.substring(0,4);return"hvc1"===t||"hev1"===t||"dvh1"===t||"dvhe"===t}(t.codec)),he(o,["trun"]).map((function(n){var o=n[0],d=16777215&de(n,0),c=0!=(1&d),l=0,f=0!=(4&d),m=0!=(256&d),v=0,y=0!=(512&d),g=0,S=0!=(1024&d),T=0!=(2048&d),E=0,b=de(n,4),A=8;c&&(l=de(n,A),A+=4),f&&(A+=4);for(var _=l+u,k=0;k>1&63;return 39===r||40===r}return 6===(31&t)}function _e(e,t,r,a){var i=ke(e),n=0;n+=t;for(var s=0,o=0,u=0;n=i.length)break;s+=u=i[n++]}while(255===u);o=0;do{if(n>=i.length)break;o+=u=i[n++]}while(255===u);var d=i.length-n,c=n;if(od){_.error("Malformed SEI payload. "+o+" is too small, only "+d+" bytes left to parse.");break}if(4===s){if(181===i[c++]){var l=ue(i,c);if(c+=2,49===l){var h=de(i,c);if(c+=4,1195456820===h){var f=i[c++];if(3===f){var p=i[c++],m=64&p,v=m?2+3*(31&p):0,y=new Uint8Array(v);if(m){y[0]=p;for(var g=1;g16){for(var S=[],T=0;T<16;T++){var E=i[c++].toString(16);S.push(1==E.length?"0"+E:E),3!==T&&5!==T&&7!==T&&9!==T||S.push("-")}for(var b=o-16,A=new Uint8Array(b),k=0;k0&&s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:a,type:W.audioId3,duration:Number.POSITIVE_INFINITY});it.length)){var n=Oe(t,r);if(n&&r+n.frameLength<=t.length){var s=a+i*(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 Oe(e,t){var r=e[t+1]>>3&3,a=e[t+1]>>1&3,i=e[t+2]>>4&15,n=e[t+2]>>2&3;if(1!==r&&0!==i&&15!==i&&3!==n){var s=e[t+2]>>1&1,o=e[t+3]>>6,u=1e3*Ue[14*(3===r?3-a:3===a?3:4)+i-1],d=xe[3*(3===r?0:2===r?1:2)+n],c=3===o?1:2,l=De[r][a],h=Ce[a],f=8*l*h,p=Math.floor(l*u/d+s)*h;if(null===Pe){var m=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Pe=m?parseInt(m[1]):0}return!!Pe&&Pe<=87&&2===a&&u>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:d,channelCount:c,frameLength:p,samplesPerFrame:f}}}function Be(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}function Me(e,t){return t+10;){s[0]=e[t];var o=Math.min(a,8),u=8-o;n[0]=4278190080>>>24+u<>u,r=r?r<t.length)return-1;if(11!==t[r]||119!==t[r+1])return-1;var n=t[r+4]>>6;if(n>=3)return-1;var s=[48e3,44100,32e3][n],o=63&t[r+4],u=2*[64,69,96,64,70,96,80,87,120,80,88,120,96,104,144,96,105,144,112,121,168,112,122,168,128,139,192,128,140,192,160,174,240,160,175,240,192,208,288,192,209,288,224,243,336,224,244,336,256,278,384,256,279,384,320,348,480,320,349,480,384,417,576,384,418,576,448,487,672,448,488,672,512,557,768,512,558,768,640,696,960,640,697,960,768,835,1152,768,836,1152,896,975,1344,896,976,1344,1024,1114,1536,1024,1115,1536,1152,1253,1728,1152,1254,1728,1280,1393,1920,1280,1394,1920][3*o+n];if(r+u>t.length)return-1;var d=t[r+6]>>5,c=0;2===d?c+=2:(1&d&&1!==d&&(c+=2),4&d&&(c+=2));var l=(t[r+6]<<8|t[r+7])>>12-c&1,h=[2,1,2,3,3,4,4,5][d]+l,f=t[r+5]>>3,p=7&t[r+5],m=new Uint8Array([n<<6|f<<1|p>>2,(3&p)<<6|d<<3|l<<2|o>>4,o<<4&224]),v=a+i*(1536/s*9e4),y=t.subarray(r,r+u);return e.config=m,e.channelCount=h,e.samplerate=s,e.samples.push({unit:y,pts:v}),u}var Ye=function(e){function t(){return e.apply(this,arguments)||this}o(t,e);var r=t.prototype;return r.resetInitSegment=function(t,r,a,i){e.prototype.resetInitSegment.call(this,t,r,a,i),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:i,inputTimeScale:9e4,dropped:0}},t.probe=function(e){if(!e)return!1;var t=p(e,0),r=(null==t?void 0:t.length)||0;if(t&&11===e[r]&&119===e[r+1]&&void 0!==H(t)&&Ge(e,r)<=16)return!1;for(var a=e.length;r>>8^255&v^99,e[f]=v,t[v]=f;var y=h[f],g=h[y],S=h[g],T=257*h[v]^16843008*v;a[f]=T<<24|T>>>8,i[f]=T<<16|T>>>16,n[f]=T<<8|T>>>24,s[f]=T,T=16843009*S^65537*g^257*y^16843008*f,u[v]=T<<24|T>>>8,d[v]=T<<16|T>>>16,c[v]=T<<8|T>>>24,l[v]=T,f?(f=y^h[h[h[S^y]]],p^=h[h[p]]):f=p=1}},t.expandKey=function(e){for(var t=this.uint8ArrayToUint32Array_(e),r=!0,a=0;a8&&109===e[r+4]&&111===e[r+5]&&111===e[r+6]&&102===e[r+7])return!0;r=a>1?r+a:t}return!1}(e)},t.demux=function(e,t){this.timeOffset=t;var r=e,a=this.videoTrack,i=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=Ee(this.remainderData,e));var n=function(e){var t={valid:null,remainder:null},r=he(e,["moof"]);if(r.length<2)return t.remainder=e,t;var a=r[r.length-1];return t.valid=e.slice(0,a.byteOffset-8),t.remainder=e.slice(a.byteOffset-8),t}(r);this.remainderData=n.remainder,a.samples=n.valid||new Uint8Array}else a.samples=r;var s=this.extractID3Track(a,t);return i.samples=be(t,a),{videoTrack:a,audioTrack:this.audioTrack,id3Track:s,textTrack:this.txtTrack}},t.flush=function(){var e=this.timeOffset,t=this.videoTrack,r=this.txtTrack;t.samples=this.remainderData||new Uint8Array,this.remainderData=null;var a=this.extractID3Track(t,this.timeOffset);return r.samples=be(e,t),{videoTrack:t,audioTrack:Re(),id3Track:a,textTrack:Re()}},t.extractID3Track=function(e,t){var r=this,a=this.id3Track;if(e.samples.length){var i=he(e.samples,["emsg"]);i&&i.forEach((function(e){var i=function(e){var t=e[0],r="",a="",i=0,n=0,s=0,o=0,u=0,d=0;if(0===t){for(;"\0"!==oe(e.subarray(d,d+1));)r+=oe(e.subarray(d,d+1)),d+=1;for(r+=oe(e.subarray(d,d+1)),d+=1;"\0"!==oe(e.subarray(d,d+1));)a+=oe(e.subarray(d,d+1)),d+=1;a+=oe(e.subarray(d,d+1)),d+=1,i=de(e,12),n=de(e,16),o=de(e,20),u=de(e,24),d=28}else if(1===t){i=de(e,d+=4);var c=de(e,d+=4),l=de(e,d+=4);for(d+=4,s=Math.pow(2,32)*c+l,L(s)||(s=Number.MAX_SAFE_INTEGER,_.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=de(e,d),u=de(e,d+=4),d+=4;"\0"!==oe(e.subarray(d,d+1));)r+=oe(e.subarray(d,d+1)),d+=1;for(r+=oe(e.subarray(d,d+1)),d+=1;"\0"!==oe(e.subarray(d,d+1));)a+=oe(e.subarray(d,d+1)),d+=1;a+=oe(e.subarray(d,d+1)),d+=1}return{schemeIdUri:r,value:a,timeScale:i,presentationTime:s,presentationTimeDelta:n,eventDuration:o,id:u,payload:e.subarray(d,e.byteLength)}}(e);if(Ze.test(i.schemeIdUri)){var n=Qe(i,t),s=4294967295===i.eventDuration?Number.POSITIVE_INFINITY:i.eventDuration/i.timeScale;s<=.001&&(s=Number.POSITIVE_INFINITY);var o=i.payload;a.samples.push({data:o,len:o.byteLength,dts:n,pts:n,type:W.emsg,duration:s})}else if(r.config.enableEmsgKLVMetadata&&i.schemeIdUri.startsWith("urn:misb:KLV:bin:1910.1")){var u=Qe(i,t);a.samples.push({data:i.payload,len:i.payload.byteLength,dts:u,pts:u,type:W.misbklv,duration:Number.POSITIVE_INFINITY})}}))}return a},t.demuxSampleAes=function(e,t,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},t.destroy=function(){this.config=null,this.remainderData=null,this.videoTrack=this.audioTrack=this.id3Track=this.txtTrack=void 0},e}();function Qe(e,t){return C(e.presentationTime)?e.presentationTime/e.timeScale:t+e.presentationTimeDelta/e.timeScale}var $e=function(){function e(e,t,r){this.keyData=void 0,this.decrypter=void 0,this.keyData=r,this.decrypter=new Xe(t,{removePKCS7Padding:!1})}var t=e.prototype;return t.decryptBuffer=function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer,je)},t.decryptAacSample=function(e,t,r){var a=this,i=e[t].unit;if(!(i.length<=16)){var n=i.subarray(16,i.length-i.length%16),s=n.buffer.slice(n.byteOffset,n.byteOffset+n.length);this.decryptBuffer(s).then((function(n){var s=new Uint8Array(n);i.set(s,16),a.decrypter.isSync()||a.decryptAacSamples(e,t+1,r)})).catch(r)}},t.decryptAacSamples=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}},t.getAvcEncryptedData=function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),a=0,i=32;i=e.length)return void a();for(var i=e[t].units;!(r>=i.length);r++){var n=i[r];if(!(n.data.length<=48||1!==n.type&&5!==n.type||(this.decryptAvcSample(e,t,r,a,n),this.decrypter.isSync())))return}}},e}(),et=function(){function e(){this.VideoSample=null}var t=e.prototype;return t.createVideoSample=function(e,t,r){return{key:e,frame:!1,pts:t,dts:r,units:[],length:0}},t.getLastNalUnit=function(e){var t,r,a=this.VideoSample;if(a&&0!==a.units.length||(a=e[e.length-1]),null!=(t=a)&&t.units){var i=a.units;r=i[i.length-1]}return r},t.pushAccessUnit=function(e,t){if(e.units.length&&e.frame){if(void 0===e.pts){var r=t.samples,a=r.length;if(!a)return void t.dropped++;var i=r[a-1];e.pts=i.pts,e.dts=i.dts}t.samples.push(e)}},t.parseNALu=function(e,t,r){var a,i,n=t.byteLength,s=e.naluState||0,o=s,u=[],d=0,c=-1,l=0;for(-1===s&&(c=0,l=this.getNALuType(t,0),s=0,d=1);d=0){var h={data:t.subarray(c,i),type:l};u.push(h)}else{var f=this.getLastNalUnit(e.samples);f&&(o&&d<=4-o&&f.state&&(f.data=f.data.subarray(0,f.data.byteLength-o)),i>0&&(f.data=Ee(f.data,t.subarray(0,i)),f.state=0))}d=0&&s>=0){var p={data:t.subarray(c,n),type:l,state:s};u.push(p)}if(0===u.length){var m=this.getLastNalUnit(e.samples);m&&(m.data=Ee(m.data,t))}return e.naluState=s,u},e}(),tt=function(){function e(e){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=e,this.bytesAvailable=e.byteLength,this.word=0,this.bitsAvailable=0}var t=e.prototype;return t.loadWord=function(){var e=this.data,t=this.bytesAvailable,r=e.byteLength-t,a=new Uint8Array(4),i=Math.min(4,t);if(0===i)throw new Error("no bytes available");a.set(e.subarray(r,r+i)),this.word=new DataView(a.buffer).getUint32(0),this.bitsAvailable=8*i,this.bytesAvailable-=i},t.skipBits=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)},t.readBits=function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(e>32&&_.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<>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()},t.skipUEG=function(){this.skipBits(1+this.skipLZ())},t.skipEG=function(){this.skipBits(1+this.skipLZ())},t.readUEG=function(){var e=this.skipLZ();return this.readBits(e+1)-1},t.readEG=function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)},t.readBoolean=function(){return 1===this.readBits(1)},t.readUByte=function(){return this.readBits(8)},t.readUShort=function(){return this.readBits(16)},t.readUInt=function(){return this.readBits(32)},e}(),rt=function(e){function t(){return e.apply(this,arguments)||this}o(t,e);var r=t.prototype;return r.parsePES=function(e,t,r,a){var i,n=this,s=this.parseNALu(e,r.data,a),o=this.VideoSample,u=!1;r.data=null,o&&s.length&&!e.audFound&&(this.pushAccessUnit(o,e),o=this.VideoSample=this.createVideoSample(!1,r.pts,r.dts)),s.forEach((function(a){var s,d;switch(a.type){case 1:var c=!1;i=!0;var l,h=a.data;if(u&&h.length>4){var f=n.readSliceType(h);2!==f&&4!==f&&7!==f&&9!==f||(c=!0)}if(c)null!=(l=o)&&l.frame&&!o.key&&(n.pushAccessUnit(o,e),o=n.VideoSample=null);o||(o=n.VideoSample=n.createVideoSample(!0,r.pts,r.dts)),o.frame=!0,o.key=c;break;case 5:i=!0,null!=(s=o)&&s.frame&&!o.key&&(n.pushAccessUnit(o,e),o=n.VideoSample=null),o||(o=n.VideoSample=n.createVideoSample(!0,r.pts,r.dts)),o.key=!0,o.frame=!0;break;case 6:i=!0,_e(a.data,1,r.pts,t.samples);break;case 7:var p,m;i=!0,u=!0;var v=a.data,y=n.readSPS(v);if(!e.sps||e.width!==y.width||e.height!==y.height||(null==(p=e.pixelRatio)?void 0:p[0])!==y.pixelRatio[0]||(null==(m=e.pixelRatio)?void 0:m[1])!==y.pixelRatio[1]){e.width=y.width,e.height=y.height,e.pixelRatio=y.pixelRatio,e.sps=[v];for(var g=v.subarray(1,4),S="avc1.",T=0;T<3;T++){var E=g[T].toString(16);E.length<2&&(E="0"+E),S+=E}e.codec=S}break;case 8:i=!0,e.pps=[a.data];break;case 9:i=!0,e.audFound=!0,null!=(d=o)&&d.frame&&(n.pushAccessUnit(o,e),o=null),o||(o=n.VideoSample=n.createVideoSample(!1,r.pts,r.dts));break;case 12:i=!0;break;default:i=!1}o&&i&&o.units.push(a)})),a&&o&&(this.pushAccessUnit(o,e),this.VideoSample=null)},r.getNALuType=function(e,t){return 31&e[t]},r.readSliceType=function(e){var t=new tt(e);return t.readUByte(),t.readUEG(),t.readUEG()},r.skipScalingList=function(e,t){for(var r=8,a=8,i=0;i>>1},r.ebsp2rbsp=function(e){for(var t=new Uint8Array(e.byteLength),r=0,a=0;a=2&&3===e[a]&&0===e[a-1]&&0===e[a-2]||(t[r]=e[a],r++);return new Uint8Array(t.buffer,0,r)},r.pushAccessUnit=function(t,r){e.prototype.pushAccessUnit.call(this,t,r),this.initVPS&&(this.initVPS=null)},r.readVPS=function(e){var t=new tt(e);return t.readUByte(),t.readUByte(),t.readBits(4),t.skipBits(2),t.readBits(6),{numTemporalLayers:t.readBits(3)+1,temporalIdNested:t.readBoolean()}},r.readSPS=function(e){var t=new tt(this.ebsp2rbsp(e));t.readUByte(),t.readUByte(),t.readBits(4);var r=t.readBits(3);t.readBoolean();for(var a=t.readBits(2),i=t.readBoolean(),n=t.readBits(5),s=t.readUByte(),o=t.readUByte(),u=t.readUByte(),d=t.readUByte(),c=t.readUByte(),l=t.readUByte(),h=t.readUByte(),f=t.readUByte(),p=t.readUByte(),m=t.readUByte(),v=t.readUByte(),y=[],g=[],S=0;S0)for(var T=r;T<8;T++)t.readBits(2);for(var E=0;E1&&t.readEG();for(var M=0;M0&&ne<16?(ee=[1,12,10,16,40,24,20,32,80,18,15,64,160,4,3,2][ne-1],te=[1,11,11,11,33,11,11,11,33,11,11,33,99,3,2,1][ne-1]):255===ne&&(ee=t.readBits(16),te=t.readBits(16))}if(t.readBoolean()&&t.readBoolean(),t.readBoolean())t.readBits(3),t.readBoolean(),t.readBoolean()&&(t.readUByte(),t.readUByte(),t.readUByte());if(t.readBoolean()&&(t.readUEG(),t.readUEG()),t.readBoolean(),t.readBoolean(),t.readBoolean(),t.readBoolean()&&(t.skipUEG(),t.skipUEG(),t.skipUEG(),t.skipUEG()),t.readBoolean())if(ae=t.readBits(32),ie=t.readBits(32),t.readBoolean()&&t.readUEG(),t.readBoolean()){var se=t.readBoolean(),oe=t.readBoolean(),ue=!1;(se||oe)&&((ue=t.readBoolean())&&(t.readUByte(),t.readBits(5),t.readBoolean(),t.readBits(5)),t.readBits(4),t.readBits(4),ue&&t.readBits(4),t.readBits(5),t.readBits(5),t.readBits(5));for(var de=0;de<=r;de++){var ce=!1;(re=t.readBoolean())||t.readBoolean()?t.readEG():ce=t.readBoolean();var le=ce?1:t.readUEG()+1;if(se)for(var he=0;he>Ee&1)<<31-Ee)>>>0;var be=Te.toString(16);return 1===n&&"2"===be&&(be="6"),{codecString:"hvc1."+ge+n+"."+be+"."+(i?"H":"L")+v+".B0",params:{general_tier_flag:i,general_profile_idc:n,general_profile_space:a,general_profile_compatibility_flags:[s,o,u,d],general_constraint_indicator_flags:[c,l,h,f,p,m],general_level_idc:v,bit_depth:U+8,bit_depth_luma_minus8:U,bit_depth_chroma_minus8:x,min_spatial_segmentation_idc:$,chroma_format_idc:b,frame_rate:{fixed:re,fps:ie/ae}},width:pe,height:me,pixelRatio:[ee,te]}},r.readPPS=function(e){var t=new tt(this.ebsp2rbsp(e));t.readUByte(),t.readUByte(),t.skipUEG(),t.skipUEG(),t.skipBits(2),t.skipBits(3),t.skipBits(2),t.skipUEG(),t.skipUEG(),t.skipEG(),t.skipBits(2),t.readBoolean()&&t.skipUEG(),t.skipEG(),t.skipEG(),t.skipBits(4);var r=t.readBoolean(),a=t.readBoolean(),i=1;return a&&r?i=0:a?i=3:r&&(i=2),{parallelismType:i}},r.matchSPS=function(e,t){return String.fromCharCode.apply(null,e).substr(3)===String.fromCharCode.apply(null,t).substr(3)},t}(et),it=188,nt=function(){function e(e,t,r,a){this.logger=void 0,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._pmtId=-1,this._videoTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.remainderData=null,this.videoParser=void 0,this.observer=e,this.config=t,this.typeSupported=r,this.logger=a,this.videoParser=null}e.probe=function(t,r){var a=e.syncOffset(t);return a>0&&r.warn("MPEG2-TS detected but first sync word found @ offset "+a),-1!==a},e.syncOffset=function(e){for(var t=e.length,r=Math.min(940,t-it)+1,a=0;a1&&(0===n&&s>2||o+it>r))return n}a++}return-1},e.createTrack=function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:se[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}};var t=e.prototype;return t.resetInitSegment=function(t,r,a,i){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=e.createTrack("video"),this._videoTrack.duration=i,this._audioTrack=e.createTrack("audio",i),this._id3Track=e.createTrack("id3"),this._txtTrack=e.createTrack("text"),this._audioTrack.segmentCodec="aac",this.videoParser=null,this.aacOverFlow=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=a},t.resetTimeStamp=function(){},t.resetContiguity=function(){var e=this._audioTrack,t=this._videoTrack,r=this._id3Track;e&&(e.pesData=null),t&&(t.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.remainderData=null},t.demux=function(t,r,a,i){var n;void 0===a&&(a=!1),void 0===i&&(i=!1),a||(this.sampleAes=null);var s=this._videoTrack,o=this._audioTrack,u=this._id3Track,d=this._txtTrack,c=s.pid,l=s.pesData,h=o.pid,f=u.pid,p=o.pesData,m=u.pesData,v=null,y=this.pmtParsed,g=this._pmtId,S=t.length;if(this.remainderData&&(S=(t=Ee(this.remainderData,t)).length,this.remainderData=null),S>4>1){if((k=b+5+t[b+4])===b+it)continue}else k=b+4;switch(_){case c:A&&(l&&(n=lt(l,this.logger))&&(this.readyVideoParser(s.segmentCodec),null!==this.videoParser&&this.videoParser.parsePES(s,d,n,!1)),l={data:[],size:0}),l&&(l.data.push(t.subarray(k,b+it)),l.size+=b+it-k);break;case h:if(A){if(p&&(n=lt(p,this.logger)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,n);break;case"mp3":this.parseMPEGPES(o,n);break;case"ac3":this.parseAC3PES(o,n)}p={data:[],size:0}}p&&(p.data.push(t.subarray(k,b+it)),p.size+=b+it-k);break;case f:A&&(m&&(n=lt(m,this.logger))&&this.parseID3PES(u,n),m={data:[],size:0}),m&&(m.data.push(t.subarray(k,b+it)),m.size+=b+it-k);break;case 0:A&&(k+=t[k]+1),g=this._pmtId=ot(t,k);break;case g:A&&(k+=t[k]+1);var R=ut(t,k,this.typeSupported,a,this.observer,this.logger);(c=R.videoPid)>0&&(s.pid=c,s.segmentCodec=R.segmentVideoCodec),(h=R.audioPid)>0&&(o.pid=h,o.segmentCodec=R.segmentAudioCodec),(f=R.id3Pid)>0&&(u.pid=f),null===v||y||(this.logger.warn("MPEG-TS PMT found at "+b+" after unknown PID '"+v+"'. Backtracking to sync byte @"+T+" to parse all TS packets."),v=null,b=T-188),y=this.pmtParsed=!0;break;case 17:case 8191:break;default:v=_}}else E++;E>0&&dt(this.observer,new Error("Found "+E+" TS packet/s that do not start with 0x47"),void 0,this.logger),s.pesData=l,o.pesData=p,u.pesData=m;var I={audioTrack:o,videoTrack:s,id3Track:u,textTrack:d};return i&&this.extractRemainingSamples(I),I},t.flush=function(){var e,t=this.remainderData;return this.remainderData=null,e=t?this.demux(t,-1,!1,!0):{videoTrack:this._videoTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(e),this.sampleAes?this.decrypt(e,this.sampleAes):e},t.extractRemainingSamples=function(e){var t,r=e.audioTrack,a=e.videoTrack,i=e.id3Track,n=e.textTrack,s=a.pesData,o=r.pesData,u=i.pesData;if(s&&(t=lt(s,this.logger))?(this.readyVideoParser(a.segmentCodec),null!==this.videoParser&&(this.videoParser.parsePES(a,n,t,!0),a.pesData=null)):a.pesData=s,o&&(t=lt(o,this.logger))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,t);break;case"mp3":this.parseMPEGPES(r,t);break;case"ac3":this.parseAC3PES(r,t)}r.pesData=null}else null!=o&&o.size&&this.logger.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;u&&(t=lt(u,this.logger))?(this.parseID3PES(i,t),i.pesData=null):i.pesData=u},t.demuxSampleAes=function(e,t,r){var a=this.demux(e,r,!0,!this.config.progressive),i=this.sampleAes=new $e(this.observer,this.config,t);return this.decrypt(a,i)},t.readyVideoParser=function(e){null===this.videoParser&&("avc"===e?this.videoParser=new rt:"hevc"===e&&(this.videoParser=new at))},t.decrypt=function(e,t){return new Promise((function(r){var a=e.audioTrack,i=e.videoTrack;a.samples&&"aac"===a.segmentCodec?t.decryptAacSamples(a.samples,0,(function(){i.samples?t.decryptAvcSamples(i.samples,0,0,(function(){r(e)})):r(e)})):i.samples&&t.decryptAvcSamples(i.samples,0,0,(function(){r(e)}))}))},t.destroy=function(){this.observer&&this.observer.removeAllListeners(),this.config=this.logger=this.observer=null,this.aacOverFlow=this.videoParser=this.remainderData=this.sampleAes=null,this._videoTrack=this._audioTrack=this._id3Track=this._txtTrack=void 0},t.parseAACPES=function(e,t){var r,a,i,n=0,s=this.aacOverFlow,o=t.data;if(s){this.aacOverFlow=null;var u=s.missing,d=s.sample.unit.byteLength;if(-1===u)o=Ee(s.sample.unit,o);else{var c=d-u;s.sample.unit.set(o.subarray(0,u),c),e.samples.push(s.sample),n=s.missing}}for(r=n,a=o.length;r0;)o+=i;else this.logger.warn("[tsdemuxer]: AC3 PES unknown PTS")},t.parseID3PES=function(e,t){if(void 0!==t.pts){var r=s({},t,{type:this._videoTrack?W.emsg:W.audioId3,duration:Number.POSITIVE_INFINITY});e.samples.push(r)}else this.logger.warn("[tsdemuxer]: ID3 PES unknown PTS")},e}();function st(e,t){return((31&e[t+1])<<8)+e[t+2]}function ot(e,t){return(31&e[t+10])<<8|e[t+11]}function ut(e,t,r,a,i,n){var s={audioPid:-1,videoPid:-1,id3Pid:-1,segmentVideoCodec:"avc",segmentAudioCodec:"aac"},o=t+3+((15&e[t+1])<<8|e[t+2])-4;for(t+=12+((15&e[t+10])<<8|e[t+11]);t0)for(var c=t+5,l=d;l>2;){if(106===e[c])!0!==r.ac3?n.log("AC-3 audio found, not supported in this browser for now"):(s.audioPid=u,s.segmentAudioCodec="ac3");var h=e[c+1]+2;c+=h,l-=h}break;case 194:case 135:return dt(i,new Error("Unsupported EC-3 in M2TS found"),void 0,n),s;case 36:-1===s.videoPid&&(s.videoPid=u,s.segmentVideoCodec="hevc",n.log("HEVC in M2TS found"))}t+=d+5}return s}function dt(e,t,r,a){a.warn("parsing error: "+t.message),e.emit(y.ERROR,y.ERROR,{type:m.MEDIA_ERROR,details:v.FRAG_PARSING_ERROR,fatal:!1,levelRetry:r,error:t,reason:t.message})}function ct(e,t){t.log(e+" with AES-128-CBC encryption found in unencrypted stream")}function lt(e,t){var r,a,i,n,s,o=0,u=e.data;if(!e||0===e.size)return null;for(;u[0].length<19&&u.length>1;)u[0]=Ee(u[0],u[1]),u.splice(1,1);if(1===((r=u[0])[0]<<16)+(r[1]<<8)+r[2]){if((a=(r[4]<<8)+r[5])&&a>e.size-6)return null;var d=r[7];192&d&&(n=536870912*(14&r[9])+4194304*(255&r[10])+16384*(254&r[11])+128*(255&r[12])+(254&r[13])/2,64&d?n-(s=536870912*(14&r[14])+4194304*(255&r[15])+16384*(254&r[16])+128*(255&r[17])+(254&r[18])/2)>54e5&&(t.warn(Math.round((n-s)/9e4)+"s delta between PTS and DTS, align them"),n=s):s=n);var c=(i=r[8])+9;if(e.size<=c)return null;e.size-=c;for(var l=new Uint8Array(e.size),h=0,f=u.length;hp){c-=p;continue}r=r.subarray(c),p-=c,c=0}l.set(r,o),o+=p}return a&&(a-=i+3),{data:l,pts:n,dts:s,len:a}}return null}var ht=function(){function e(){}return e.getSilentFrame=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}(),ft=Math.pow(2,32)-1,pt=function(){function e(){}return e.init=function(){var t;for(t in e.types={avc1:[],avcC:[],hvc1:[],hvcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],dac3:[],"ac-3":[],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]),a=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:a};var i=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]),u=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,u,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,i))},e.box=function(e){for(var t=8,r=arguments.length,a=new Array(r>1?r-1:0),i=1;i>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>24&255,t>>16&255,t>>8&255,255&t,a>>24,a>>16&255,a>>8&255,255&a,i>>24,i>>16&255,i>>8&255,255&i,85,196,0,0]))},e.mdia=function(t){return e.box(e.types.mdia,e.mdhd(t.timescale||0,t.duration||0),e.hdlr(t.type),e.minf(t))},e.mfhd=function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))},e.minf=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))},e.moof=function(t,r,a){return e.box(e.types.moof,e.mfhd(t),e.traf(a,r))},e.moov=function(t){for(var r=t.length,a=[];r--;)a[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale||0,t[0].duration||0)].concat(a).concat(e.mvex(t)))},e.mvex=function(t){for(var r=t.length,a=[];r--;)a[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(a))},e.mvhd=function(t,r){r*=t;var a=Math.floor(r/(ft+1)),i=Math.floor(r%(ft+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,a>>24,a>>16&255,a>>8&255,255&a,i>>24,i>>16&255,i>>8&255,255&i,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)},e.sdtp=function(t){var r,a,i=t.samples||[],n=new Uint8Array(4+i.length);for(r=0;r>>8&255),n.push(255&i),n=n.concat(Array.prototype.slice.call(a));for(r=0;r>>8&255),s.push(255&i),s=s.concat(Array.prototype.slice.call(a));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))),u=t.width,d=t.height,c=t.pixelRatio[0],l=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,u>>8&255,255&u,d>>8&255,255&d,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,l>>24,l>>16&255,l>>8&255,255&l])))},e.esds=function(e){var t=e.config;return new Uint8Array([0,0,0,0,3,25,0,1,0,4,17,64,21,0,0,0,0,0,0,0,0,0,0,0,5,2].concat(t,[6,1,2]))},e.audioStsd=function(e){var t=e.samplerate||0;return new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount||0,0,16,0,0,0,0,t>>8&255,255&t,0,0])},e.mp4a=function(t){return e.box(e.types.mp4a,e.audioStsd(t),e.box(e.types.esds,e.esds(t)))},e.mp3=function(t){return e.box(e.types[".mp3"],e.audioStsd(t))},e.ac3=function(t){return e.box(e.types["ac-3"],e.audioStsd(t),e.box(e.types.dac3,t.config))},e.stsd=function(t){var r=t.segmentCodec;if("audio"===t.type){if("aac"===r)return e.box(e.types.stsd,e.STSD,e.mp4a(t));if("ac3"===r&&t.config)return e.box(e.types.stsd,e.STSD,e.ac3(t));if("mp3"===r&&"mp3"===t.codec)return e.box(e.types.stsd,e.STSD,e.mp3(t))}else{if(!t.pps||!t.sps)throw new Error("video track missing pps or sps");if("avc"===r)return e.box(e.types.stsd,e.STSD,e.avc1(t));if("hevc"===r&&t.vps)return e.box(e.types.stsd,e.STSD,e.hvc1(t))}throw new Error("unsupported "+t.type+" segment codec ("+r+"/"+t.codec+")")},e.tkhd=function(t){var r=t.id,a=(t.duration||0)*(t.timescale||0),i=t.width||0,n=t.height||0,s=Math.floor(a/(ft+1)),o=Math.floor(a%(ft+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,i>>8&255,255&i,0,0,n>>8&255,255&n,0,0]))},e.traf=function(t,r){var a=e.sdtp(t),i=t.id,n=Math.floor(r/(ft+1)),s=Math.floor(r%(ft+1));return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),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,a.length+16+20+8+16+8+8),a)},e.trak=function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))},e.trex=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]))},e.trun=function(t,r){var a,i,n,s,o,u,d=t.samples||[],c=d.length,l=12+16*c,h=new Uint8Array(l);for(r+=8+l,h.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),a=0;a>>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,u>>>24&255,u>>>16&255,u>>>8&255,255&u],12+16*a);return e.box(e.types.trun,h)},e.initSegment=function(t){e.types||e.init();var r=e.moov(t);return Ee(e.FTYP,r)},e.hvc1=function(t){for(var r=t.params,a=[t.vps,t.sps,t.pps],i=new Uint8Array([1,r.general_profile_space<<6|(r.general_tier_flag?32:0)|r.general_profile_idc,r.general_profile_compatibility_flags[0],r.general_profile_compatibility_flags[1],r.general_profile_compatibility_flags[2],r.general_profile_compatibility_flags[3],r.general_constraint_indicator_flags[0],r.general_constraint_indicator_flags[1],r.general_constraint_indicator_flags[2],r.general_constraint_indicator_flags[3],r.general_constraint_indicator_flags[4],r.general_constraint_indicator_flags[5],r.general_level_idc,240|r.min_spatial_segmentation_idc>>8,255&r.min_spatial_segmentation_idc,252|r.parallelismType,252|r.chroma_format_idc,248|r.bit_depth_luma_minus8,248|r.bit_depth_chroma_minus8,0,parseInt(r.frame_rate.fps),3|r.temporal_id_nested<<2|r.num_temporal_layers<<3|(r.frame_rate.fixed?64:0),a.length]),n=i.length,s=0;s>8,255&a[c][l].length]),n),n+=2,u.set(a[c][l],n),n+=a[c][l].length}var h=e.box(e.types.hvcC,u),f=t.width,p=t.height,m=t.pixelRatio[0],v=t.pixelRatio[1];return e.box(e.types.hvc1,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,f>>8&255,255&f,p>>8&255,255&p,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]),h,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([m>>24,m>>16&255,m>>8&255,255&m,v>>24,v>>16&255,v>>8&255,255&v])))},e}();pt.types=void 0,pt.HDLR_TYPES=void 0,pt.STTS=void 0,pt.STSC=void 0,pt.STCO=void 0,pt.STSZ=void 0,pt.VMHD=void 0,pt.SMHD=void 0,pt.STSD=void 0,pt.FTYP=void 0,pt.DINF=void 0;var mt="main",vt="audio";function yt(e,t){return function(e,t,r,a){var i=e*t*r;return Math.round(i)}(e,1e3,1/9e4)}function gt(e){var t=e.baseTime,r=e.timescale;return t/r+" ("+t+"/"+r+") trackId: "+e.trackId}var St=null,Tt=null;function Et(e,t,r,a){return{duration:t,size:r,cts:a,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:e?2:1,isNonSync:e?0:1}}}var bt=function(e){function t(t,r,a,i){var n;if((n=e.call(this,"mp4-remuxer",i)||this).observer=void 0,n.config=void 0,n.typeSupported=void 0,n.ISGenerated=!1,n._initPTS=null,n._initDTS=null,n.nextVideoTs=null,n.nextAudioTs=null,n.videoSampleDuration=null,n.isAudioContiguous=!1,n.isVideoContiguous=!1,n.videoTrackConfig=void 0,n.observer=t,n.config=r,n.typeSupported=a,n.ISGenerated=!1,null===St){var s=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);St=s?parseInt(s[1]):0}if(null===Tt){var o=navigator.userAgent.match(/Safari\/(\d+)/i);Tt=o?parseInt(o[1]):0}return n}o(t,e);var r=t.prototype;return r.destroy=function(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null},r.resetTimeStamp=function(e){var t=this._initPTS;t&&e&&e.trackId===t.trackId&&e.baseTime===t.baseTime&&e.timescale===t.timescale||this.log("Reset initPTS: "+(t?gt(t):t)+" > "+(e?gt(e):e)),this._initPTS=this._initDTS=e},r.resetNextTimestamp=function(){this.log("reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},r.resetInitSegment=function(){this.log("ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0},r.getVideoStartPts=function(e){var t=!1,r=e[0].pts,a=e.reduce((function(e,a){var i=a.pts,n=i-e;return n<-4294967296&&(t=!0,n=(i=At(i,r))-e),n>0?e:i}),r);return t&&this.debug("PTS rollover detected"),a},r.remux=function(e,t,r,a,i,n,s,o){var u,d,c,l,h,f,p=i,m=i,v=e.pid>-1,y=t.pid>-1,g=t.samples.length,S=e.samples.length>0,T=s&&g>0||g>1;if((!v||S)&&(!y||T)||this.ISGenerated||s){if(this.ISGenerated){var E,b,A,_,k=this.videoTrackConfig;(k&&(t.width!==k.width||t.height!==k.height||(null==(E=t.pixelRatio)?void 0:E[0])!==(null==(b=k.pixelRatio)?void 0:b[0])||(null==(A=t.pixelRatio)?void 0:A[1])!==(null==(_=k.pixelRatio)?void 0:_[1]))||!k&&T||null===this.nextAudioTs&&S)&&this.resetInitSegment()}this.ISGenerated||(c=this.generateIS(e,t,i,n));var R,I=this.isVideoContiguous,w=-1;if(T&&(w=function(e){for(var t=0;t0){this.warn("Dropped "+w+" out of "+g+" video samples due to a missing keyframe");var P=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(w),t.dropped+=w,R=m+=(t.samples[0].pts-P)/t.inputTimeScale}else-1===w&&(this.warn("No keyframe found out of "+g+" video samples"),f=!1);if(this.ISGenerated){if(S&&T){var U=this.getVideoStartPts(t.samples),x=(At(e.samples[0].pts,U)-U)/t.inputTimeScale;p+=Math.max(0,x),m+=Math.max(0,-x)}if(S){if(e.samplerate||(this.warn("regenerate InitSegment as audio detected"),c=this.generateIS(e,t,i,n)),d=this.remuxAudio(e,p,this.isAudioContiguous,n,y||T||o===vt?m:void 0),T){var D=d?d.endPTS-d.startPTS:0;t.inputTimeScale||(this.warn("regenerate InitSegment as video detected"),c=this.generateIS(e,t,i,n)),u=this.remuxVideo(t,m,I,D)}}else T&&(u=this.remuxVideo(t,m,I,0));u&&(u.firstKeyFrame=w,u.independent=-1!==w,u.firstKeyFramePTS=R)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(h=_t(r,i,this._initPTS,this._initDTS)),a.samples.length&&(l=kt(a,i,this._initPTS))),{audio:d,video:u,initSegment:c,independent:f,text:l,id3:h}},r.computeInitPts=function(e,t,r,a){var i=Math.round(r*t),n=At(e,i);if(n0?k-1:k].dts&&(E=!0)}E&&u.sort((function(e,t){var r=e.dts-t.dts,a=e.pts-t.pts;return r||a})),i=u[0].dts;var I=(n=u[u.length-1].dts)-i,w=I?Math.round(I/(c-1)):g||e.inputTimeScale/30;if(r){var P=i-_,U=P>w,x=P<-1;if((U||x)&&(U?this.warn((e.segmentCodec||"").toUpperCase()+": "+yt(P)+" ms ("+P+"dts) hole between fragments detected at "+t.toFixed(3)):this.warn((e.segmentCodec||"").toUpperCase()+": "+yt(-P)+" ms ("+P+"dts) overlapping between fragments detected at "+t.toFixed(3)),!x||_>=u[0].pts||St)){i=_;var D=u[0].pts-P;if(U)u[0].dts=i,u[0].pts=D;else for(var C=!0,L=0;LD&&C);L++){var O=u[L].pts;if(u[L].dts-=P,u[L].pts-=P,L0?te.dts-u[ee-1].dts:w;if(de=ee>0?te.pts-u[ee-1].pts:w,ce.stretchShortVideoTrack&&null!==this.nextAudioTs){var he=Math.floor(ce.maxBufferHole*o),fe=(a?S+a*o:this.nextAudioTs+h)-te.pts;fe>he?((g=fe-le)<0?g=le:X=!0,this.log("It is approximately "+fe/90+" ms to the next segment; using duration "+g/90+" ms for the last video frame.")):g=le}else g=le}var pe=Math.round(te.pts-te.dts);Z=Math.min(Z,g),Q=Math.max(Q,g),J=Math.min(J,de),$=Math.max($,de),d.push(Et(te.key,g,ae,pe))}if(d.length)if(St){if(St<70){var me=d[0].flags;me.dependsOn=2,me.isNonSync=0}}else if(Tt&&$-J0&&(a&&Math.abs(E-(S+T))<9e3||Math.abs(At(p[0].pts,E)-(S+T))<20*d),p.forEach((function(e){e.pts=At(e.pts,E)})),!r||S<0){var b=p.length;if(p=p.filter((function(e){return e.pts>=0})),b!==p.length&&this.warn("Removed "+(p.length-b)+" of "+b+" samples (initPTS "+T+" / "+n+")"),!p.length)return;S=0===i?0:a&&!f?Math.max(0,E-T):p[0].pts-T}if("aac"===e.segmentCodec)for(var A=this.config.maxAudioFramesDrift,_=0,k=S+T;_=A*d&&P<1e4&&f){var U=Math.round(w/d);for(k=I-U*d;k<0&&U&&d;)U--,k+=d;0===_&&(this.nextAudioTs=S=k-T),this.warn("Injecting "+U+" audio frames @ "+((k-T)/n).toFixed(3)+"s due to "+Math.round(1e3*w/n)+" ms gap.");for(var x=0;x0))return;B+=g;try{C=new Uint8Array(B)}catch(e){return void this.observer.emit(y.ERROR,y.ERROR,{type:m.MUX_ERROR,details:v.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:B,reason:"fail allocating audio mdat "+B})}l||(new DataView(C.buffer).setUint32(0,B),C.set(pt.types.mdat,4))}C.set(V,g);var Y=V.byteLength;g+=Y,h.push(Et(!0,u,Y,0)),O=K}var j=h.length;if(j){var z=h[h.length-1];S=O-T,this.nextAudioTs=S+o*z.duration;var H=l?new Uint8Array(0):pt.moof(e.sequenceNumber++,L/o,s({},e,{samples:h}));e.samples=[];var W=(L-T)/n,q=this.nextAudioTs/n,X={data1:H,data2:C,startPTS:W,endPTS:q,startDTS:W,endDTS:q,type:"audio",hasAudio:!0,hasVideo:!1,nb:j};return this.isAudioContiguous=!0,X}},t}(g);function At(e,t){var r;if(null===t)return e;for(r=t4294967296;)e+=r;return e}function _t(e,t,r,a){var i=e.samples.length;if(i){for(var n=e.inputTimeScale,s=0;si}(u,E,i,b)&&k===u.timescale||(u&&this.warn("Timestamps at playlist time: "+(n?"":"~")+i+" "+R/k+" != initPTS: "+u.baseTime/u.timescale+" ("+u.baseTime+"/"+u.timescale+") trackId: "+u.trackId),this.log("Found initPTS at playlist time: "+i+" offset: "+(E-i)+" ("+R+"/"+k+") trackId: "+I),u=null,h.initPTS=R,h.timescale=k,h.trackId=I)}else this.warn("No audio or video samples found for initPTS at playlist time: "+i);u?(h.initPTS=u.baseTime,h.timescale=u.timescale,h.trackId=u.trackId):(h.timescale&&void 0!==h.trackId&&void 0!==h.initPTS||(this.warn("Could not set initPTS"),h.initPTS=E,h.timescale=1,h.trackId=-1),this.initPTS=u={baseTime:h.initPTS,timescale:h.timescale,trackId:h.trackId});var w=E-u.baseTime/u.timescale,P=w+b;b>0?this.lastEndTime=P:(this.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var U=!!f.audio,x=!!f.video,D="";U&&(D+="audio"),x&&(D+="video");var L={data1:l,startPTS:w,startDTS:w,endPTS:P,endDTS:P,type:D,hasAudio:U,hasVideo:x,nb:1,dropped:0,encrypted:!!f.audio&&f.audio.encrypted||!!f.video&&f.video.encrypted};c.audio=U&&!x?L:void 0,c.video=x?L:void 0;var O=null==v?void 0:v.sampleCount;if(O){var B=v.keyFrameIndex,M=-1!==B;L.nb=O,L.dropped=0===B||this.isVideoContiguous?0:M?B:O,L.independent=M,L.firstKeyFrame=B,M&&v.keyFrameStart&&(L.firstKeyFramePTS=(v.keyFrameStart-u.baseTime)/u.timescale),this.isVideoContiguous||(c.independent=M),this.isVideoContiguous||(this.isVideoContiguous=M),L.dropped&&this.warn("fmp4 does not start with IDR: firstIDR "+B+"/"+O+" dropped: "+L.dropped+" start: "+(L.firstKeyFramePTS||"NA"))}return c.initSegment=h,c.id3=_t(r,i,u,u),a.samples.length&&(c.text=kt(a,i,u)),c},t}(g);function Ct(e,t,r){return void 0===r&&(r=!1),void 0!==(null==e?void 0:e.start)?(e.start+(r?e.duration:0))/e.timescale:t}function Lt(e,t,r){var a=e.codec;if(a&&a.length>4)return a;if(t===re){if("ec-3"===a||"ac-3"===a||"alac"===a)return a;if("fLaC"===a||"Opus"===a){return Ut(a,!1)}return r.warn('Unhandled audio codec "'+a+'" in mp4 MAP'),a||"mp4a"}return r.warn('Unhandled video codec "'+a+'" in mp4 MAP'),a||"avc1"}try{xt=self.performance.now.bind(self.performance)}catch(e){xt=Date.now}var Ot=[{demux:Je,remux:Dt},{demux:nt,remux:bt},{demux:Fe,remux:bt},{demux:Ye,remux:bt}];Ot.splice(2,0,{demux:Ve,remux:bt});var Bt=function(){function e(e,t,r,a,i,n){this.asyncResult=!1,this.logger=void 0,this.observer=void 0,this.typeSupported=void 0,this.config=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=e,this.typeSupported=t,this.config=r,this.id=i,this.logger=n}var t=e.prototype;return t.configure=function(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()},t.push=function(e,t,r,a){var i=this,n=r.transmuxing;n.executeStart=xt();var s=new Uint8Array(e),o=this.currentTransmuxState,u=this.transmuxConfig;a&&(this.currentTransmuxState=a);var d,c=a||o,l=c.contiguous,h=c.discontinuity,f=c.trackSwitch,p=c.accurateTimeOffset,g=c.timeOffset,S=c.initSegmentChange,T=u.audioCodec,E=u.videoCodec,b=u.defaultInitPts,A=u.duration,_=u.initSegmentData,k=function(e,t){var r=null;e.byteLength>0&&null!=(null==t?void 0:t.key)&&null!==t.iv&&null!=t.method&&(r=t);return r}(s,t);if(k&&("AES-128"===(d=k.method)||"AES-256"===d||"AES-256-CTR"===d)){var R=this.getDecrypter(),I=function(e){switch(e){case"AES-128":case"AES-256":return je;case"AES-256-CTR":return ze;default:throw new Error("invalid full segment method "+e)}}(k.method);if(!R.isSync())return this.asyncResult=!0,this.decryptionPromise=R.webCryptoDecrypt(s,k.key.buffer,k.iv.buffer,I).then((function(e){var t=i.push(e,null,r);return i.decryptionPromise=null,t})),this.decryptionPromise;var w=R.softwareDecrypt(s,k.key.buffer,k.iv.buffer,I);if(r.part>-1){var P=R.flush();w=P?P.buffer:P}if(!w)return n.executeEnd=xt(),Mt(r);s=new Uint8Array(w)}var U=this.needsProbing(h,f);if(U){var x=this.configureTransmuxer(s);if(x)return this.logger.warn("[transmuxer] "+x.message),this.observer.emit(y.ERROR,y.ERROR,{type:m.MEDIA_ERROR,details:v.FRAG_PARSING_ERROR,fatal:!1,error:x,reason:x.message}),n.executeEnd=xt(),Mt(r)}(h||f||S||U)&&this.resetInitSegment(_,T,E,A,t),(h||S||U)&&this.resetInitialTimestamp(b),l||this.resetContiguity();var D=this.transmux(s,k,g,p,r);this.asyncResult=Nt(D);var C=this.currentTransmuxState;return C.contiguous=!0,C.discontinuity=!1,C.trackSwitch=!1,n.executeEnd=xt(),D},t.flush=function(e){var t=this,r=e.transmuxing;r.executeStart=xt();var a=this.decrypter,i=this.currentTransmuxState,n=this.decryptionPromise;if(n)return this.asyncResult=!0,n.then((function(){return t.flush(e)}));var s=[],o=i.timeOffset;if(a){var u=a.flush();u&&s.push(this.push(u.buffer,null,e))}var d=this.demuxer,c=this.remuxer;if(!d||!c){r.executeEnd=xt();var l=[Mt(e)];return this.asyncResult?Promise.resolve(l):l}var h=d.flush(o);return Nt(h)?(this.asyncResult=!0,h.then((function(r){return t.flushRemux(s,r,e),s}))):(this.flushRemux(s,h,e),this.asyncResult?Promise.resolve(s):s)},t.flushRemux=function(e,t,r){var a=t.audioTrack,i=t.videoTrack,n=t.id3Track,s=t.textTrack,o=this.currentTransmuxState,u=o.accurateTimeOffset,d=o.timeOffset;this.logger.log("[transmuxer.ts]: Flushed "+this.id+" sn: "+r.sn+(r.part>-1?" part: "+r.part:"")+" of "+(this.id===mt?"level":"track")+" "+r.level);var c=this.remuxer.remux(a,i,n,s,d,u,!0,this.id);e.push({remuxResult:c,chunkMeta:r}),r.transmuxing.executeEnd=xt()},t.resetInitialTimestamp=function(e){var t=this.demuxer,r=this.remuxer;t&&r&&(t.resetTimeStamp(e),r.resetTimeStamp(e))},t.resetContiguity=function(){var e=this.demuxer,t=this.remuxer;e&&t&&(e.resetContiguity(),t.resetNextTimestamp())},t.resetInitSegment=function(e,t,r,a,i){var n=this.demuxer,s=this.remuxer;n&&s&&(n.resetInitSegment(e,t,r,a),s.resetInitSegment(e,t,r,i))},t.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},t.transmux=function(e,t,r,a,i){return t&&"SAMPLE-AES"===t.method?this.transmuxSampleAes(e,t,r,a,i):this.transmuxUnencrypted(e,r,a,i)},t.transmuxUnencrypted=function(e,t,r,a){var i=this.demuxer.demux(e,t,!1,!this.config.progressive),n=i.audioTrack,s=i.videoTrack,o=i.id3Track,u=i.textTrack;return{remuxResult:this.remuxer.remux(n,s,o,u,t,r,!1,this.id),chunkMeta:a}},t.transmuxSampleAes=function(e,t,r,a,i){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,a,!1,n.id),chunkMeta:i}}))},t.configureTransmuxer=function(e){for(var t,r=this.config,a=this.observer,i=this.typeSupported,n=0,s=Ot.length;n