UNPKG

hls.js-esm

Version:

1 lines 216 kB
!function(e){var t={};function i(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=e,i.c=t,i.d=function(e,t,r){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(r,s,function(t){return e[t]}.bind(null,s));return r},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=13)}([function(e,t,i){"use strict";i.d(t,"a",function(){return d}),i.d(t,"b",function(){return h});var r=i(4);function s(){}const a={trace:s,debug:s,log:s,warn:s,info:s,error:s};let n=a;const o=Object(r.a)();function l(e,...t){t.forEach(function(t){n[t]=e[t]?e[t].bind(e):function(e){const t=o.console[e];return t?function(...i){i[0]&&(i[0]=function(e,t){return t="["+e+"] > "+t}(e,i[0])),t.apply(o.console,i)}:s}(t)})}var d=function(e){if(!0===e||"object"==typeof e){l(e,"debug","log","info","warn","error");try{n.log()}catch(e){n=a}}else n=a},h=n},function(e,t,i){"use strict";t.a={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",BUFFER_RESET:"hlsBufferReset",BUFFER_CODECS:"hlsBufferCodecs",BUFFER_CREATED:"hlsBufferCreated",BUFFER_APPENDING:"hlsBufferAppending",BUFFER_APPENDED:"hlsBufferAppended",BUFFER_EOS:"hlsBufferEos",BUFFER_FLUSHING:"hlsBufferFlushing",BUFFER_FLUSHED:"hlsBufferFlushed",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_SWITCHING:"hlsLevelSwitching",LEVEL_SWITCHED:"hlsLevelSwitched",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsLevelPtsUpdated",AUDIO_TRACKS_UPDATED:"hlsAudioTracksUpdated",AUDIO_TRACK_SWITCHING:"hlsAudioTrackSwitching",AUDIO_TRACK_SWITCHED:"hlsAudioTrackSwitched",AUDIO_TRACK_LOADING:"hlsAudioTrackLoading",AUDIO_TRACK_LOADED:"hlsAudioTrackLoaded",SUBTITLE_TRACKS_UPDATED:"hlsSubtitleTracksUpdated",SUBTITLE_TRACK_SWITCH:"hlsSubtitleTrackSwitch",SUBTITLE_TRACK_LOADING:"hlsSubtitleTrackLoading",SUBTITLE_TRACK_LOADED:"hlsSubtitleTrackLoaded",SUBTITLE_FRAG_PROCESSED:"hlsSubtitleFragProcessed",INIT_PTS_FOUND:"hlsInitPtsFound",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_PROGRESS:"hlsFragLoadProgress",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_DECRYPTED:"hlsFragDecrypted",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_USERDATA:"hlsFragParsingUserdata",FRAG_PARSING_METADATA:"hlsFragParsingMetadata",FRAG_PARSING_DATA:"hlsFragParsingData",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFpsDrop",FPS_DROP_LEVEL_CAPPING:"hlsFpsDropLevelCapping",ERROR:"hlsError",DESTROYING:"hlsDestroying",KEY_LOADING:"hlsKeyLoading",KEY_LOADED:"hlsKeyLoaded",STREAM_STATE_TRANSITION:"hlsStreamStateTransition"}},function(e,t,i){"use strict";i.d(t,"b",function(){return r}),i.d(t,"a",function(){return s});const r={NETWORK_ERROR:"networkError",MEDIA_ERROR:"mediaError",KEY_SYSTEM_ERROR:"keySystemError",MUX_ERROR:"muxError",OTHER_ERROR:"otherError"},s={KEY_SYSTEM_NO_KEYS:"keySystemNoKeys",KEY_SYSTEM_NO_ACCESS:"keySystemNoAccess",KEY_SYSTEM_NO_SESSION:"keySystemNoSession",KEY_SYSTEM_LICENSE_REQUEST_FAILED:"keySystemLicenseRequestFailed",MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",MANIFEST_INCOMPATIBLE_CODECS_ERROR:"manifestIncompatibleCodecsError",LEVEL_LOAD_ERROR:"levelLoadError",LEVEL_LOAD_TIMEOUT:"levelLoadTimeOut",LEVEL_SWITCH_ERROR:"levelSwitchError",AUDIO_TRACK_LOAD_ERROR:"audioTrackLoadError",AUDIO_TRACK_LOAD_TIMEOUT:"audioTrackLoadTimeOut",FRAG_LOAD_ERROR:"fragLoadError",FRAG_LOAD_TIMEOUT:"fragLoadTimeOut",FRAG_DECRYPT_ERROR:"fragDecryptError",FRAG_PARSING_ERROR:"fragParsingError",REMUX_ALLOC_ERROR:"remuxAllocError",KEY_LOAD_ERROR:"keyLoadError",KEY_LOAD_TIMEOUT:"keyLoadTimeOut",BUFFER_ADD_CODEC_ERROR:"bufferAddCodecError",BUFFER_APPEND_ERROR:"bufferAppendError",BUFFER_APPENDING_ERROR:"bufferAppendingError",BUFFER_STALLED_ERROR:"bufferStalledError",BUFFER_FULL_ERROR:"bufferFullError",BUFFER_SEEK_OVER_HOLE:"bufferSeekOverHole",BUFFER_NUDGE_ON_STALL:"bufferNudgeOnStall",INTERNAL_EXCEPTION:"internalException"}},function(e,t,i){"use strict";i.d(t,"b",function(){return s});class r{static isHeader(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}static isFooter(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}static getID3Data(e,t){const i=t;let s=0;for(;r.isHeader(e,t);){s+=10,s+=r._readSize(e,t+6),r.isFooter(e,t+10)&&(s+=10),t+=s}if(s>0)return e.subarray(i,i+s)}static _readSize(e,t){let i=0;return i=(127&e[t])<<21,i|=(127&e[t+1])<<14,i|=(127&e[t+2])<<7,i|=127&e[t+3]}static getTimeStamp(e){const t=r.getID3Frames(e);for(let e=0;e<t.length;e++){const i=t[e];if(r.isTimeStampFrame(i))return r._readTimeStamp(i)}}static isTimeStampFrame(e){return e&&"PRIV"===e.key&&"com.apple.streaming.transportStreamTimestamp"===e.info}static _getFrameData(e){const t=String.fromCharCode(e[0],e[1],e[2],e[3]),i=r._readSize(e,4);return{type:t,size:i,data:e.subarray(10,10+i)}}static getID3Frames(e){let t=0;const i=[];for(;r.isHeader(e,t);){const s=r._readSize(e,t+6),a=(t+=10)+s;for(;t+8<a;){const s=r._getFrameData(e.subarray(t)),a=r._decodeFrame(s);a&&i.push(a),t+=s.size+10}r.isFooter(e,t)&&(t+=10)}return i}static _decodeFrame(e){return"PRIV"===e.type?r._decodePrivFrame(e):"T"===e.type[0]?r._decodeTextFrame(e):"W"===e.type[0]?r._decodeURLFrame(e):void 0}static _readTimeStamp(e){if(8===e.data.byteLength){const t=new Uint8Array(e.data),i=1&t[3];let r=(t[4]<<23)+(t[5]<<15)+(t[6]<<7)+t[7];return r/=45,i&&(r+=47721858.84),Math.round(r)}}static _decodePrivFrame(e){if(e.size<2)return;const t=r._utf8ArrayToStr(e.data,!0),i=new Uint8Array(e.data.subarray(t.length+1));return{key:e.type,info:t,data:i.buffer}}static _decodeTextFrame(e){if(!(e.size<2)){if("TXXX"===e.type){let t=1;const i=r._utf8ArrayToStr(e.data.subarray(t));t+=i.length+1;const s=r._utf8ArrayToStr(e.data.subarray(t));return{key:e.type,info:i,data:s}}{const t=r._utf8ArrayToStr(e.data.subarray(1));return{key:e.type,data:t}}}}static _decodeURLFrame(e){if("WXXX"===e.type){if(e.size<2)return;let t=1;const i=r._utf8ArrayToStr(e.data.subarray(t));t+=i.length+1;const s=r._utf8ArrayToStr(e.data.subarray(t));return{key:e.type,info:i,data:s}}{const t=r._utf8ArrayToStr(e.data);return{key:e.type,data:t}}}static _utf8ArrayToStr(e,t=!1){const i=e.length;let r,s,a,n="",o=0;for(;o<i;){if(0===(r=e[o++])&&t)return n;if(0!==r&&3!==r)switch(r>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:n+=String.fromCharCode(r);break;case 12:case 13:s=e[o++],n+=String.fromCharCode((31&r)<<6|63&s);break;case 14:s=e[o++],a=e[o++],n+=String.fromCharCode((15&r)<<12|(63&s)<<6|(63&a)<<0)}}return n}}const s=r._utf8ArrayToStr;t.a=r},function(e,t,i){"use strict";function r(){return"undefined"==typeof window?self:window}i.d(t,"a",function(){return r})},function(e,t,i){var r,s,a,n,o;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,s=/^([^\/?#]*)(.*)$/,a=/(?:\/|^)\.(?=\/)/g,n=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,o={buildAbsoluteURL:function(e,t,i){if(i=i||{},e=e.trim(),!(t=t.trim())){if(!i.alwaysNormalize)return e;var r=o.parseURL(e);if(!r)throw new Error("Error trying to parse base URL.");return r.path=o.normalizePath(r.path),o.buildURLFromParts(r)}var a=o.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return i.alwaysNormalize?(a.path=o.normalizePath(a.path),o.buildURLFromParts(a)):t;var n=o.parseURL(e);if(!n)throw new Error("Error trying to parse base URL.");if(!n.netLoc&&n.path&&"/"!==n.path[0]){var l=s.exec(n.path);n.netLoc=l[1],n.path=l[2]}n.netLoc&&!n.path&&(n.path="/");var d={scheme:n.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(d.netLoc=n.netLoc,"/"!==a.path[0]))if(a.path){var h=n.path,u=h.substring(0,h.lastIndexOf("/")+1)+a.path;d.path=o.normalizePath(u)}else d.path=n.path,a.params||(d.params=n.params,a.query||(d.query=n.query));return null===d.path&&(d.path=i.alwaysNormalize?o.normalizePath(a.path):a.path),o.buildURLFromParts(d)},parseURL:function(e){var t=r.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(a,"");e.length!==(e=e.replace(n,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=o},function(e,t,i){"use strict";class r{constructor(e,t){this.subtle=e,this.aesIV=t}decrypt(e,t){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},t,e)}}var s=class{constructor(e,t){this.subtle=e,this.key=t}expandKey(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])}};var a=class{constructor(){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.initTable()}uint8ArrayToUint32Array_(e){let t=new DataView(e),i=new Uint32Array(4);for(let e=0;e<4;e++)i[e]=t.getUint32(4*e);return i}initTable(){let e=this.sBox,t=this.invSBox,i=this.subMix,r=i[0],s=i[1],a=i[2],n=i[3],o=this.invSubMix,l=o[0],d=o[1],h=o[2],u=o[3],c=new Uint32Array(256),f=0,g=0,p=0;for(p=0;p<256;p++)c[p]=p<128?p<<1:p<<1^283;for(p=0;p<256;p++){let i=g^g<<1^g<<2^g<<3^g<<4;i=i>>>8^255&i^99,e[f]=i,t[i]=f;let o=c[f],p=c[o],m=c[p],y=257*c[i]^16843008*i;r[f]=y<<24|y>>>8,s[f]=y<<16|y>>>16,a[f]=y<<8|y>>>24,n[f]=y,y=16843009*m^65537*p^257*o^16843008*f,l[i]=y<<24|y>>>8,d[i]=y<<16|y>>>16,h[i]=y<<8|y>>>24,u[i]=y,f?(f=o^c[c[c[m^o]]],g^=c[c[g]]):f=g=1}}expandKey(e){let t=this.uint8ArrayToUint32Array_(e),i=!0,r=0;for(;r<t.length&&i;)i=t[r]===this.key[r],r++;if(i)return;this.key=t;let s=this.keySize=t.length;if(4!==s&&6!==s&&8!==s)throw new Error("Invalid aes key size="+s);let a,n,o,l,d=this.ksRows=4*(s+6+1),h=this.keySchedule=new Uint32Array(d),u=this.invKeySchedule=new Uint32Array(d),c=this.sBox,f=this.rcon,g=this.invSubMix,p=g[0],m=g[1],y=g[2],E=g[3];for(a=0;a<d;a++)a<s?o=h[a]=t[a]:(l=o,a%s==0?(l=c[(l=l<<8|l>>>24)>>>24]<<24|c[l>>>16&255]<<16|c[l>>>8&255]<<8|c[255&l],l^=f[a/s|0]<<24):s>6&&a%s==4&&(l=c[l>>>24]<<24|c[l>>>16&255]<<16|c[l>>>8&255]<<8|c[255&l]),h[a]=o=(h[a-s]^l)>>>0);for(n=0;n<d;n++)a=d-n,l=3&n?h[a]:h[a-4],u[n]=n<4||a<=4?l:p[c[l>>>24]]^m[c[l>>>16&255]]^y[c[l>>>8&255]]^E[c[255&l]],u[n]=u[n]>>>0}networkToHostOrderSwap(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24}decrypt(e,t,i,r){let s,a,n,o,l,d,h,u,c,f,g,p,m,y,E=this.keySize+6,b=this.invKeySchedule,T=this.invSBox,v=this.invSubMix,S=v[0],R=v[1],A=v[2],_=v[3],L=this.uint8ArrayToUint32Array_(i),D=L[0],w=L[1],I=L[2],k=L[3],C=new Int32Array(e),O=new Int32Array(C.length),P=this.networkToHostOrderSwap;for(;t<C.length;){for(c=P(C[t]),f=P(C[t+1]),g=P(C[t+2]),p=P(C[t+3]),l=c^b[0],d=p^b[1],h=g^b[2],u=f^b[3],m=4,y=1;y<E;y++)s=S[l>>>24]^R[d>>16&255]^A[h>>8&255]^_[255&u]^b[m],a=S[d>>>24]^R[h>>16&255]^A[u>>8&255]^_[255&l]^b[m+1],n=S[h>>>24]^R[u>>16&255]^A[l>>8&255]^_[255&d]^b[m+2],o=S[u>>>24]^R[l>>16&255]^A[d>>8&255]^_[255&h]^b[m+3],l=s,d=a,h=n,u=o,m+=4;s=T[l>>>24]<<24^T[d>>16&255]<<16^T[h>>8&255]<<8^T[255&u]^b[m],a=T[d>>>24]<<24^T[h>>16&255]<<16^T[u>>8&255]<<8^T[255&l]^b[m+1],n=T[h>>>24]<<24^T[u>>16&255]<<16^T[l>>8&255]<<8^T[255&d]^b[m+2],o=T[u>>>24]<<24^T[l>>16&255]<<16^T[d>>8&255]<<8^T[255&h]^b[m+3],m+=3,O[t]=P(s^D),O[t+1]=P(o^w),O[t+2]=P(n^I),O[t+3]=P(a^k),D=c,w=f,I=g,k=p,t+=4}return r?function(e){const t=e.byteLength,i=t&&new DataView(e).getUint8(t-1);return i?e.slice(0,t-i):e}(O.buffer):O.buffer}destroy(){this.key=void 0,this.keySize=void 0,this.ksRows=void 0,this.sBox=void 0,this.invSBox=void 0,this.subMix=void 0,this.invSubMix=void 0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.rcon=void 0}},n=i(2),o=i(0),l=i(1),d=i(4);const h=Object(d.a)();t.a=class{constructor(e,t,{removePKCS7Padding:i=!0}={}){if(this.logEnabled=!0,this.observer=e,this.config=t,this.removePKCS7Padding=i,i)try{const e=h.crypto;e&&(this.subtle=e.subtle||e.webkitSubtle)}catch(e){}this.disableWebCrypto=!this.subtle}isSync(){return this.disableWebCrypto&&this.config.enableSoftwareAES}decrypt(e,t,i,n){if(this.disableWebCrypto&&this.config.enableSoftwareAES){this.logEnabled&&(o.b.log("JS AES decrypt"),this.logEnabled=!1);let r=this.decryptor;r||(this.decryptor=r=new a),r.expandKey(t),n(r.decrypt(e,0,i,this.removePKCS7Padding))}else{this.logEnabled&&(o.b.log("WebCrypto AES decrypt"),this.logEnabled=!1);const a=this.subtle;this.key!==t&&(this.key=t,this.fastAesKey=new s(a,t)),this.fastAesKey.expandKey().then(s=>{new r(a,i).decrypt(e,s).catch(r=>{this.onWebCryptoError(r,e,t,i,n)}).then(e=>{n(e)})}).catch(r=>{this.onWebCryptoError(r,e,t,i,n)})}}onWebCryptoError(e,t,i,r,s){this.config.enableSoftwareAES?(o.b.log("WebCrypto Error, disable WebCrypto API"),this.disableWebCrypto=!0,this.logEnabled=!0,this.decrypt(t,i,r,s)):(o.b.error(`decrypting error : ${e.message}`),this.observer.trigger(l.a.ERROR,{type:n.b.MEDIA_ERROR,details:n.a.FRAG_DECRYPT_ERROR,fatal:!0,reason:e.message}))}destroy(){let e=this.decryptor;e&&(e.destroy(),this.decryptor=void 0)}}},function(e,t,i){"use strict";var r=i(1),s=i(2),a=i(6),n=i(0),o=i(4);function l(e,t){return 255===e[t]&&240==(246&e[t+1])}function d(e,t){return 1&e[t+1]?7:9}function h(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function u(e,t){return!!(t+1<e.length&&l(e,t))}function c(e,t){if(t+1<e.length&&l(e,t)){let i=d(e,t);t+5<e.length&&(i=h(e,t));let r=t+i;if(r===e.length||r+1<e.length&&l(e,r))return!0}return!1}function f(e,t,i,a,o){if(!e.samplerate){let l=function(e,t,i,a){let o,l,d,h,u,c=navigator.userAgent.toLowerCase(),f=a,g=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];if(o=1+((192&t[i+2])>>>6),!((l=(60&t[i+2])>>>2)>g.length-1))return h=(1&t[i+2])<<2,h|=(192&t[i+3])>>>6,n.b.log(`manifest codec:${a},ADTS data:type:${o},sampleingIndex:${l}[${g[l]}Hz],channelConfig:${h}`),/firefox/i.test(c)?l>=6?(o=5,u=new Array(4),d=l-3):(o=2,u=new Array(2),d=l):-1!==c.indexOf("android")?(o=2,u=new Array(2),d=l):(o=5,u=new Array(4),a&&(-1!==a.indexOf("mp4a.40.29")||-1!==a.indexOf("mp4a.40.5"))||!a&&l>=6?d=l-3:((a&&-1!==a.indexOf("mp4a.40.2")&&(l>=6&&1===h||/vivaldi/i.test(c))||!a&&1===h)&&(o=2,u=new Array(2)),d=l)),u[0]=o<<3,u[0]|=(14&l)>>1,u[1]|=(1&l)<<7,u[1]|=h<<3,5===o&&(u[1]|=(14&d)>>1,u[2]=(1&d)<<7,u[2]|=8,u[3]=0),{config:u,samplerate:g[l],channelCount:h,codec:"mp4a.40."+o,manifestCodec:f};e.trigger(r.a.ERROR,{type:s.b.MEDIA_ERROR,details:s.a.FRAG_PARSING_ERROR,fatal:!0,reason:`invalid ADTS sampling index:${l}`})}(t,i,a,o);e.config=l.config,e.samplerate=l.samplerate,e.channelCount=l.channelCount,e.codec=l.codec,e.manifestCodec=l.manifestCodec,n.b.log(`parsed codec:${e.codec},rate:${l.samplerate},nb channel:${l.channelCount}`)}}function g(e){return 9216e4/e}function p(e,t,i,r,s){let a=function(e,t,i,r,s){let a,n,o,l=e.length;if(a=d(e,t),n=h(e,t),(n-=a)>0&&t+a+n<=l)return{headerLength:a,frameLength:n,stamp:o=i+r*s}}(t,i,r,s,g(e.samplerate));if(a){let r=a.stamp,s=a.headerLength,n=a.frameLength,o={unit:t.subarray(i+s,i+s+n),pts:r,dts:r};return e.samples.push(o),e.len+=n,{sample:o,length:n+s}}}var m=i(3);var y=class{constructor(e,t,i){this.observer=e,this.config=i,this.remuxer=t}resetInitSegment(e,t,i,r){this._audioTrack={container:"audio/adts",type:"audio",id:0,sequenceNumber:0,isAAC:!0,samples:[],len:0,manifestCodec:t,duration:r,inputTimeScale:9e4}}resetTimeStamp(){}static probe(e){if(!e)return!1;let t=(m.a.getID3Data(e,0)||[]).length;for(let i=e.length;t<i;t++)if(c(e,t))return n.b.log("ADTS sync word found !"),!0;return!1}append(e,t,i,r){let s=this._audioTrack,a=m.a.getID3Data(e,0)||[],o=m.a.getTimeStamp(a),l=Number.isFinite(o)?90*o:9e4*t,d=0,h=l,c=e.length,g=a.length,y=[{pts:h,dts:h,data:a}];for(;g<c-1;)if(u(e,g)&&g+5<c){f(s,this.observer,e,g,s.manifestCodec);let t=p(s,e,g,l,d);if(!t){n.b.log("Unable to parse AAC frame");break}g+=t.length,h=t.sample.pts,d++}else m.a.isHeader(e,g)?(a=m.a.getID3Data(e,g),y.push({pts:h,dts:h,data:a}),g+=a.length):g++;this.remuxer.remux(s,{samples:[]},{samples:y,inputTimeScale:9e4},{samples:[]},t,i,r)}destroy(){}},E=i(8);const b={BitratesMap:[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],SamplingRateMap:[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],SamplesCoefficients:[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],BytesInSlot:[0,1,1,4],appendFrame:function(e,t,i,r,s){if(i+24>t.length)return;let a=this.parseHeader(t,i);if(a&&i+a.frameLength<=t.length){let n=r+s*(9e4*a.samplesPerFrame/a.sampleRate),o={unit:t.subarray(i,i+a.frameLength),pts:n,dts:n};return e.config=[],e.channelCount=a.channelCount,e.samplerate=a.sampleRate,e.samples.push(o),e.len+=a.frameLength,{sample:o,length:a.frameLength}}},parseHeader:function(e,t){let i=e[t+1]>>3&3,r=e[t+1]>>1&3,s=e[t+2]>>4&15,a=e[t+2]>>2&3,n=e[t+2]>>1&1;if(1!==i&&0!==s&&15!==s&&3!==a){let o=3===i?3-r:3===r?3:4,l=1e3*b.BitratesMap[14*o+s-1],d=3===i?0:2===i?1:2,h=b.SamplingRateMap[3*d+a],u=e[t+3]>>6==3?1:2,c=b.SamplesCoefficients[i][r],f=b.BytesInSlot[r],g=8*c*f;return{sampleRate:h,channelCount:u,frameLength:parseInt(c*l/h+n,10)*f,samplesPerFrame:g}}},isHeaderPattern:function(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])},isHeader:function(e,t){return!!(t+1<e.length&&this.isHeaderPattern(e,t))},probe:function(e,t){if(t+1<e.length&&this.isHeaderPattern(e,t)){let i=4,r=this.parseHeader(e,t),s=i;r&&r.frameLength&&(s=r.frameLength);let a=t+s;if(a===e.length||a+1<e.length&&this.isHeaderPattern(e,a))return!0}return!1}};var T=b;var v=class{constructor(e){this.data=e,this.bytesAvailable=e.byteLength,this.word=0,this.bitsAvailable=0}loadWord(){let e=this.data,t=this.bytesAvailable,i=e.byteLength-t,r=new Uint8Array(4),s=Math.min(4,t);if(0===s)throw new Error("no bytes available");r.set(e.subarray(i,i+s)),this.word=new DataView(r.buffer).getUint32(0),this.bitsAvailable=8*s,this.bytesAvailable-=s}skipBits(e){let t;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)}readBits(e){let t=Math.min(this.bitsAvailable,e),i=this.word>>>32-t;return e>32&&n.b.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0?this.word<<=t:this.bytesAvailable>0&&this.loadWord(),(t=e-t)>0&&this.bitsAvailable?i<<t|this.readBits(t):i}skipLZ(){let 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()}skipUEG(){this.skipBits(1+this.skipLZ())}skipEG(){this.skipBits(1+this.skipLZ())}readUEG(){let e=this.skipLZ();return this.readBits(e+1)-1}readEG(){let e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}readBoolean(){return 1===this.readBits(1)}readUByte(){return this.readBits(8)}readUShort(){return this.readBits(16)}readUInt(){return this.readBits(32)}skipScalingList(e){let t,i,r=8,s=8;for(t=0;t<e;t++)0!==s&&(s=(r+(i=this.readEG())+256)%256),r=0===s?r:s}readSPS(){let e,t,i,r,s,a,n,o,l,d=0,h=0,u=0,c=0,f=this.readUByte.bind(this),g=this.readBits.bind(this),p=this.readUEG.bind(this),m=this.readBoolean.bind(this),y=this.skipBits.bind(this),E=this.skipEG.bind(this),b=this.skipUEG.bind(this),T=this.skipScalingList.bind(this);if(f(),e=f(),t=g(5),y(3),i=f(),b(),100===e||110===e||122===e||244===e||44===e||83===e||86===e||118===e||128===e){let e=p();if(3===e&&y(1),b(),b(),y(1),m())for(o=3!==e?8:12,l=0;l<o;l++)m()&&T(l<6?16:64)}b();let v=p();if(0===v)p();else if(1===v)for(y(1),E(),E(),r=p(),l=0;l<r;l++)E();b(),y(1),s=p(),a=p(),0===(n=g(1))&&y(1),y(1),m()&&(d=p(),h=p(),u=p(),c=p());let S=[1,1];if(m()&&m())switch(f()){case 1:S=[1,1];break;case 2:S=[12,11];break;case 3:S=[10,11];break;case 4:S=[16,11];break;case 5:S=[40,33];break;case 6:S=[24,11];break;case 7:S=[20,11];break;case 8:S=[32,11];break;case 9:S=[80,33];break;case 10:S=[18,11];break;case 11:S=[15,11];break;case 12:S=[64,33];break;case 13:S=[160,99];break;case 14:S=[4,3];break;case 15:S=[3,2];break;case 16:S=[2,1];break;case 255:S=[f()<<8|f(),f()<<8|f()]}return{width:Math.ceil(16*(s+1)-2*d-2*h),height:(2-n)*(a+1)*16-(n?2:4)*(u+c),pixelRatio:S}}readSliceType(){return this.readUByte(),this.readUEG(),this.readUEG()}};var S=class{constructor(e,t,i,r){this.decryptdata=i,this.discardEPB=r,this.decrypter=new a.a(e,t,{removePKCS7Padding:!1})}decryptBuffer(e,t){this.decrypter.decrypt(e,this.decryptdata.key.buffer,this.decryptdata.iv.buffer,t)}decryptAacSample(e,t,i,r){let s=e[t].unit,a=s.subarray(16,s.length-s.length%16),n=a.buffer.slice(a.byteOffset,a.byteOffset+a.length),o=this;this.decryptBuffer(n,function(a){a=new Uint8Array(a),s.set(a,16),r||o.decryptAacSamples(e,t+1,i)})}decryptAacSamples(e,t,i){for(;;t++){if(t>=e.length)return void i();if(e[t].unit.length<32)continue;let r=this.decrypter.isSync();if(this.decryptAacSample(e,t,i,r),!r)return}}getAvcEncryptedData(e){let t=16*Math.floor((e.length-48)/160)+16,i=new Int8Array(t),r=0;for(let t=32;t<=e.length-16;t+=160,r+=16)i.set(e.subarray(t,t+16),r);return i}getAvcDecryptedUnit(e,t){t=new Uint8Array(t);let i=0;for(let r=32;r<=e.length-16;r+=160,i+=16)e.set(t.subarray(i,i+16),r);return e}decryptAvcSample(e,t,i,r,s,a){let n=this.discardEPB(s.data),o=this.getAvcEncryptedData(n),l=this;this.decryptBuffer(o.buffer,function(o){s.data=l.getAvcDecryptedUnit(n,o),a||l.decryptAvcSamples(e,t,i+1,r)})}decryptAvcSamples(e,t,i,r){for(;;t++,i=0){if(t>=e.length)return void r();let s=e[t].units;for(;!(i>=s.length);i++){let a=s[i];if(a.length<=48||1!==a.type&&5!==a.type)continue;let n=this.decrypter.isSync();if(this.decryptAvcSample(e,t,i,r,a,n),!n)return}}}};const R={video:1,audio:2,id3:3,text:4};class A{constructor(e,t,i,r){this.observer=e,this.config=i,this.typeSupported=r,this.remuxer=t,this.sampleAes=null}setDecryptData(e){null!=e&&null!=e.key&&"SAMPLE-AES"===e.method?this.sampleAes=new S(this.observer,this.config,e,this.discardEPB):this.sampleAes=null}static probe(e){const t=A._syncOffset(e);return!(t<0)&&(t&&n.b.warn(`MPEG2-TS detected but first sync word found @ offset ${t}, junk ahead ?`),!0)}static _syncOffset(e){const t=Math.min(1e3,e.length-564);let i=0;for(;i<t;){if(71===e[i]&&71===e[i+188]&&71===e[i+376])return i;i++}return-1}static createTrack(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:R[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],len:0,dropped:"video"===e?0:void 0,isAAC:"audio"===e||void 0,duration:"audio"===e?t:void 0}}resetInitSegment(e,t,i,r){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack=A.createTrack("video",r),this._audioTrack=A.createTrack("audio",r),this._id3Track=A.createTrack("id3",r),this._txtTrack=A.createTrack("text",r),this.aacOverFlow=null,this.aacLastPTS=null,this.avcSample=null,this.audioCodec=t,this.videoCodec=i,this._duration=r}resetTimeStamp(){}append(e,t,i,a){let o,l,d,h,u,c,f=e.length,g=!1;this.contiguous=i;let p=this.pmtParsed,m=this._avcTrack,y=this._audioTrack,E=this._id3Track,b=m.pid,T=y.pid,v=E.pid,S=this._pmtId,R=m.pesData,_=y.pesData,L=E.pesData,D=this._parsePAT,w=this._parsePMT,I=this._parsePES,k=this._parseAVCPES.bind(this),C=this._parseAACPES.bind(this),O=this._parseMPEGPES.bind(this),P=this._parseID3PES.bind(this);const x=A._syncOffset(e);for(f-=(f+x)%188,o=x;o<f;o+=188)if(71===e[o]){if(l=!!(64&e[o+1]),d=((31&e[o+1])<<8)+e[o+2],(h=(48&e[o+3])>>4)>1){if((u=o+5+e[o+4])===o+188)continue}else u=o+4;switch(d){case b:l&&(R&&(c=I(R))&&void 0!==c.pts&&k(c,!1),R={data:[],size:0}),R&&(R.data.push(e.subarray(u,o+188)),R.size+=o+188-u);break;case T:l&&(_&&(c=I(_))&&void 0!==c.pts&&(y.isAAC?C(c):O(c)),_={data:[],size:0}),_&&(_.data.push(e.subarray(u,o+188)),_.size+=o+188-u);break;case v:l&&(L&&(c=I(L))&&void 0!==c.pts&&P(c),L={data:[],size:0}),L&&(L.data.push(e.subarray(u,o+188)),L.size+=o+188-u);break;case 0:l&&(u+=e[u]+1),S=this._pmtId=D(e,u);break;case S:l&&(u+=e[u]+1);let t=w(e,u,!0===this.typeSupported.mpeg||!0===this.typeSupported.mp3,null!=this.sampleAes);(b=t.avc)>0&&(m.pid=b),(T=t.audio)>0&&(y.pid=T,y.isAAC=t.isAAC),(v=t.id3)>0&&(E.pid=v),g&&!p&&(n.b.log("reparse from beginning"),g=!1,o=x-188),p=this.pmtParsed=!0;break;case 17:case 8191:break;default:g=!0}}else this.observer.trigger(r.a.ERROR,{type:s.b.MEDIA_ERROR,details:s.a.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});R&&(c=I(R))&&void 0!==c.pts?(k(c,!0),m.pesData=null):m.pesData=R,_&&(c=I(_))&&void 0!==c.pts?(y.isAAC?C(c):O(c),y.pesData=null):(_&&_.size&&n.b.log("last AAC PES packet truncated,might overlap between fragments"),y.pesData=_),L&&(c=I(L))&&void 0!==c.pts?(P(c),E.pesData=null):E.pesData=L,null==this.sampleAes?this.remuxer.remux(y,m,E,this._txtTrack,t,i,a):this.decryptAndRemux(y,m,E,this._txtTrack,t,i,a)}decryptAndRemux(e,t,i,r,s,a,n){if(e.samples&&e.isAAC){let o=this;this.sampleAes.decryptAacSamples(e.samples,0,function(){o.decryptAndRemuxAvc(e,t,i,r,s,a,n)})}else this.decryptAndRemuxAvc(e,t,i,r,s,a,n)}decryptAndRemuxAvc(e,t,i,r,s,a,n){if(t.samples){let o=this;this.sampleAes.decryptAvcSamples(t.samples,0,0,function(){o.remuxer.remux(e,t,i,r,s,a,n)})}else this.remuxer.remux(e,t,i,r,s,a,n)}destroy(){this._initPTS=this._initDTS=void 0,this._duration=0}_parsePAT(e,t){return(31&e[t+10])<<8|e[t+11]}_parsePMT(e,t,i,r){let s,a,o,l,d={audio:-1,avc:-1,id3:-1,isAAC:!0};for(a=t+3+(s=(15&e[t+1])<<8|e[t+2])-4,t+=12+(o=(15&e[t+10])<<8|e[t+11]);t<a;){switch(l=(31&e[t+1])<<8|e[t+2],e[t]){case 207:if(!r){n.b.log("unkown stream type:"+e[t]);break}case 15:-1===d.audio&&(d.audio=l);break;case 21:-1===d.id3&&(d.id3=l);break;case 219:if(!r){n.b.log("unkown stream type:"+e[t]);break}case 27:-1===d.avc&&(d.avc=l);break;case 3:case 4:i?-1===d.audio&&(d.audio=l,d.isAAC=!1):n.b.log("MPEG audio found, not supported in this browser for now");break;case 36:n.b.warn("HEVC stream type found, not supported for now");break;default:n.b.log("unkown stream type:"+e[t])}t+=5+((15&e[t+3])<<8|e[t+4])}return d}_parsePES(e){let t,i,r,s,a,o,l,d,h,u=0,c=e.data;if(!e||0===e.size)return null;for(;c[0].length<19&&c.length>1;){let e=new Uint8Array(c[0].length+c[1].length);e.set(c[0]),e.set(c[1],c[0].length),c[0]=e,c.splice(1,1)}if(1===(r=((t=c[0])[0]<<16)+(t[1]<<8)+t[2])){if((s=(t[4]<<8)+t[5])&&s>e.size-6)return null;192&(i=t[7])&&((l=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2)>4294967295&&(l-=8589934592),64&i?((d=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2)>4294967295&&(d-=8589934592),l-d>54e5&&(n.b.warn(`${Math.round((l-d)/9e4)}s delta between PTS and DTS, align them`),l=d)):d=l),h=(a=t[8])+9,e.size-=h,o=new Uint8Array(e.size);for(let e=0,i=c.length;e<i;e++){let i=(t=c[e]).byteLength;if(h){if(h>i){h-=i;continue}t=t.subarray(h),i-=h,h=0}o.set(t,u),u+=i}return s&&(s-=a+3),{data:o,pts:l,dts:d,len:s}}return null}pushAccesUnit(e,t){if(e.units.length&&e.frame){const i=t.samples,r=i.length;!this.config.forceKeyFrameOnDiscontinuity||!0===e.key||t.sps&&(r||this.contiguous)?(e.id=r,i.push(e)):t.dropped++}e.debug.length&&n.b.log(e.pts+"/"+e.dts+":"+e.debug)}_parseAVCPES(e,t){let i,r,s,a=this._avcTrack,n=this._parseAVCNALu(e.data),o=this.avcSample,l=!1,d=this.pushAccesUnit.bind(this),h=function(e,t,i,r){return{key:e,pts:t,dts:i,units:[],debug:r}};e.data=null,o&&n.length&&!a.audFound&&(d(o,a),o=this.avcSample=h(!1,e.pts,e.dts,"")),n.forEach(t=>{switch(t.type){case 1:r=!0,o||(o=this.avcSample=h(!0,e.pts,e.dts,"")),o.frame=!0;let g=t.data;if(l&&g.length>4){let e=new v(g).readSliceType();2!==e&&4!==e&&7!==e&&9!==e||(o.key=!0)}break;case 5:r=!0,o||(o=this.avcSample=h(!0,e.pts,e.dts,"")),o.key=!0,o.frame=!0;break;case 6:r=!0,(i=new v(this.discardEPB(t.data))).readUByte();for(var n=0,u=0,c=!1,f=0;!c&&i.bytesAvailable>1;){n=0;do{n+=f=i.readUByte()}while(255===f);u=0;do{u+=f=i.readUByte()}while(255===f);if(4===n&&0!==i.bytesAvailable){if(c=!0,181===i.readUByte()){if(49===i.readUShort()){if(1195456820===i.readUInt()){if(3===i.readUByte()){let t=i.readUByte(),r=31&t,a=[t,i.readUByte()];for(s=0;s<r;s++)a.push(i.readUByte()),a.push(i.readUByte()),a.push(i.readUByte());this._insertSampleInOrder(this._txtTrack.samples,{type:3,pts:e.pts,bytes:a})}}}}}else if(u<i.bytesAvailable)for(s=0;s<u;s++)i.readUByte()}break;case 7:if(r=!0,l=!0,!a.sps){let e=(i=new v(t.data)).readSPS();a.width=e.width,a.height=e.height,a.pixelRatio=e.pixelRatio,a.sps=[t.data],a.duration=this._duration;let r=t.data.subarray(1,4),n="avc1.";for(s=0;s<3;s++){let e=r[s].toString(16);e.length<2&&(e="0"+e),n+=e}a.codec=n}break;case 8:r=!0,a.pps||(a.pps=[t.data]);break;case 9:r=!1,a.audFound=!0,o&&d(o,a),o=this.avcSample=h(!1,e.pts,e.dts,"");break;case 12:r=!1;break;default:r=!1,o&&(o.debug+="unknown NAL "+t.type+" ")}if(o&&r){o.units.push(t)}}),t&&o&&(d(o,a),this.avcSample=null)}_insertSampleInOrder(e,t){let i=e.length;if(i>0){if(t.pts>=e[i-1].pts)e.push(t);else for(let r=i-1;r>=0;r--)if(t.pts<e[r].pts){e.splice(r,0,t);break}}else e.push(t)}_getLastNalUnit(){let e,t=this.avcSample;if(!t||0===t.units.length){let e=this._avcTrack.samples;t=e[e.length-1]}if(t){let i=t.units;e=i[i.length-1]}return e}_parseAVCNALu(e){let t,i,r,s,a,n=0,o=e.byteLength,l=this._avcTrack,d=l.naluState||0,h=d,u=[],c=-1;for(-1===d&&(c=0,a=31&e[0],d=0,n=1);n<o;)if(t=e[n++],d)if(1!==d)if(t)if(1===t){if(c>=0)r={data:e.subarray(c,n-d-1),type:a},u.push(r);else{let t=this._getLastNalUnit();if(t&&(h&&n<=4-h&&t.state&&(t.data=t.data.subarray(0,t.data.byteLength-h)),(i=n-d-1)>0)){let r=new Uint8Array(t.data.byteLength+i);r.set(t.data,0),r.set(e.subarray(0,i),t.data.byteLength),t.data=r}}n<o?(c=n,a=s=31&e[n],d=0):d=-1}else d=0;else d=3;else d=t?0:2;else d=t?0:1;if(c>=0&&d>=0&&(r={data:e.subarray(c,o),type:a,state:d},u.push(r)),0===u.length){let t=this._getLastNalUnit();if(t){let i=new Uint8Array(t.data.byteLength+e.byteLength);i.set(t.data,0),i.set(e,t.data.byteLength),t.data=i}}return l.naluState=d,u}discardEPB(e){let t,i,r=e.byteLength,s=[],a=1;for(;a<r-2;)0===e[a]&&0===e[a+1]&&3===e[a+2]?(s.push(a+2),a+=2):a++;if(0===s.length)return e;t=r-s.length,i=new Uint8Array(t);let n=0;for(a=0;a<t;n++,a++)n===s[0]&&(n++,s.shift()),i[a]=e[n];return i}_parseAACPES(e){let t,i,a,o,l,d=this._audioTrack,h=e.data,c=e.pts,m=this.aacOverFlow,y=this.aacLastPTS;if(m){let e=new Uint8Array(m.byteLength+h.byteLength);e.set(m,0),e.set(h,m.byteLength),h=e}for(a=0,l=h.length;a<l-1&&!u(h,a);a++);if(a){let e,t;if(a<l-1?(e=`AAC PES did not start with ADTS header,offset:${a}`,t=!1):(e="no ADTS header found in AAC PES",t=!0),n.b.warn(`parsing error:${e}`),this.observer.trigger(r.a.ERROR,{type:s.b.MEDIA_ERROR,details:s.a.FRAG_PARSING_ERROR,fatal:t,reason:e}),t)return}if(f(d,this.observer,h,a,this.audioCodec),i=0,t=g(d.samplerate),m&&y){let e=y+t;Math.abs(e-c)>1&&(n.b.log(`AAC: align PTS for overlapping frames by ${Math.round((e-c)/90)}`),c=e)}for(;a<l;)if(u(h,a)&&a+5<l){let e=p(d,h,a,c,i);if(!e)break;a+=e.length,o=e.sample.pts,i++}else a++;m=a<l?h.subarray(a,l):null,this.aacOverFlow=m,this.aacLastPTS=o}_parseMPEGPES(e){let t=e.data,i=t.length,r=0,s=0,a=e.pts;for(;s<i;)if(T.isHeader(t,s)){let e=T.appendFrame(this._audioTrack,t,s,a,r);if(!e)break;s+=e.length,r++}else s++}_parseID3PES(e){this._id3Track.samples.push(e)}}var _=A;var L=class{constructor(e,t,i){this.observer=e,this.config=i,this.remuxer=t}resetInitSegment(e,t,i,r){this._audioTrack={container:"audio/mpeg",type:"audio",id:-1,sequenceNumber:0,isAAC:!1,samples:[],len:0,manifestCodec:t,duration:r,inputTimeScale:9e4}}resetTimeStamp(){}static probe(e){let t,i,r=m.a.getID3Data(e,0);if(r&&void 0!==m.a.getTimeStamp(r))for(t=r.length,i=Math.min(e.length-1,t+100);t<i;t++)if(T.probe(e,t))return n.b.log("MPEG Audio sync word found !"),!0;return!1}append(e,t,i,r){let s=m.a.getID3Data(e,0),a=m.a.getTimeStamp(s),n=a?90*a:9e4*t,o=s.length,l=e.length,d=0,h=0,u=this._audioTrack,c=[{pts:n,dts:n,data:s}];for(;o<l;)if(T.isHeader(e,o)){let t=T.appendFrame(u,e,o,n,d);if(!t)break;o+=t.length,h=t.sample.pts,d++}else m.a.isHeader(e,o)?(s=m.a.getID3Data(e,o),c.push({pts:h,dts:h,data:s}),o+=s.length):o++;this.remuxer.remux(u,{samples:[]},{samples:c,inputTimeScale:9e4},{samples:[]},t,i,r)}destroy(){}};var D=class{static getSilentFrame(e,t){switch(e){case"mp4a.40.2":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]);break;default: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])}return null}};const w=Math.pow(2,32)-1;class I{static init(){let e;for(e in I.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:[]},I.types)I.types.hasOwnProperty(e)&&(I.types[e]=[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]);let t=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]);I.HDLR_TYPES={video:t,audio:i};let r=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),s=new Uint8Array([0,0,0,0,0,0,0,0]);I.STTS=I.STSC=I.STCO=s,I.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),I.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),I.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),I.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);let a=new Uint8Array([105,115,111,109]),n=new Uint8Array([97,118,99,49]),o=new Uint8Array([0,0,0,1]);I.FTYP=I.box(I.types.ftyp,a,o,a,n),I.DINF=I.box(I.types.dinf,I.box(I.types.dref,r))}static box(e){let t,i=Array.prototype.slice.call(arguments,1),r=8,s=i.length,a=s;for(;s--;)r+=i[s].byteLength;for((t=new Uint8Array(r))[0]=r>>24&255,t[1]=r>>16&255,t[2]=r>>8&255,t[3]=255&r,t.set(e,4),s=0,r=8;s<a;s++)t.set(i[s],r),r+=i[s].byteLength;return t}static hdlr(e){return I.box(I.types.hdlr,I.HDLR_TYPES[e])}static mdat(e){return I.box(I.types.mdat,e)}static mdhd(e,t){t*=e;const i=Math.floor(t/(w+1)),r=Math.floor(t%(w+1));return I.box(I.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,i>>24,i>>16&255,i>>8&255,255&i,r>>24,r>>16&255,r>>8&255,255&r,85,196,0,0]))}static mdia(e){return I.box(I.types.mdia,I.mdhd(e.timescale,e.duration),I.hdlr(e.type),I.minf(e))}static mfhd(e){return I.box(I.types.mfhd,new Uint8Array([0,0,0,0,e>>24,e>>16&255,e>>8&255,255&e]))}static minf(e){return"audio"===e.type?I.box(I.types.minf,I.box(I.types.smhd,I.SMHD),I.DINF,I.stbl(e)):I.box(I.types.minf,I.box(I.types.vmhd,I.VMHD),I.DINF,I.stbl(e))}static moof(e,t,i){return I.box(I.types.moof,I.mfhd(e),I.traf(i,t))}static moov(e){let t=e.length,i=[];for(;t--;)i[t]=I.trak(e[t]);return I.box.apply(null,[I.types.moov,I.mvhd(e[0].timescale,e[0].duration)].concat(i).concat(I.mvex(e)))}static mvex(e){let t=e.length,i=[];for(;t--;)i[t]=I.trex(e[t]);return I.box.apply(null,[I.types.mvex].concat(i))}static mvhd(e,t){t*=e;const i=Math.floor(t/(w+1)),r=Math.floor(t%(w+1));let s=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,e>>24&255,e>>16&255,e>>8&255,255&e,i>>24,i>>16&255,i>>8&255,255&i,r>>24,r>>16&255,r>>8&255,255&r,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 I.box(I.types.mvhd,s)}static sdtp(e){let t,i,r=e.samples||[],s=new Uint8Array(4+r.length);for(i=0;i<r.length;i++)t=r[i].flags,s[i+4]=t.dependsOn<<4|t.isDependedOn<<2|t.hasRedundancy;return I.box(I.types.sdtp,s)}static stbl(e){return I.box(I.types.stbl,I.stsd(e),I.box(I.types.stts,I.STTS),I.box(I.types.stsc,I.STSC),I.box(I.types.stsz,I.STSZ),I.box(I.types.stco,I.STCO))}static avc1(e){let t,i,r,s=[],a=[];for(t=0;t<e.sps.length;t++)r=(i=e.sps[t]).byteLength,s.push(r>>>8&255),s.push(255&r),s=s.concat(Array.prototype.slice.call(i));for(t=0;t<e.pps.length;t++)r=(i=e.pps[t]).byteLength,a.push(r>>>8&255),a.push(255&r),a=a.concat(Array.prototype.slice.call(i));let n=I.box(I.types.avcC,new Uint8Array([1,s[3],s[4],s[5],255,224|e.sps.length].concat(s).concat([e.pps.length]).concat(a))),o=e.width,l=e.height,d=e.pixelRatio[0],h=e.pixelRatio[1];return I.box(I.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,o>>8&255,255&o,l>>8&255,255&l,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]),n,I.box(I.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),I.box(I.types.pasp,new Uint8Array([d>>24,d>>16&255,d>>8&255,255&d,h>>24,h>>16&255,h>>8&255,255&h])))}static esds(e){let 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]))}static mp4a(e){let t=e.samplerate;return I.box(I.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,t>>8&255,255&t,0,0]),I.box(I.types.esds,I.esds(e)))}static mp3(e){let t=e.samplerate;return I.box(I.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,t>>8&255,255&t,0,0]))}static stsd(e){return"audio"===e.type?e.isAAC||"mp3"!==e.codec?I.box(I.types.stsd,I.STSD,I.mp4a(e)):I.box(I.types.stsd,I.STSD,I.mp3(e)):I.box(I.types.stsd,I.STSD,I.avc1(e))}static tkhd(e){let t=e.id,i=e.duration*e.timescale,r=e.width,s=e.height,a=Math.floor(i/(w+1)),n=Math.floor(i%(w+1));return I.box(I.types.tkhd,new Uint8Array([1,0,0,7,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,0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a,n>>24,n>>16&255,n>>8&255,255&n,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,r>>8&255,255&r,0,0,s>>8&255,255&s,0,0]))}static traf(e,t){let i=I.sdtp(e),r=e.id,s=Math.floor(t/(w+1)),a=Math.floor(t%(w+1));return I.box(I.types.traf,I.box(I.types.tfhd,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),I.box(I.types.tfdt,new Uint8Array([1,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,a>>24,a>>16&255,a>>8&255,255&a])),I.trun(e,i.length+16+20+8+16+8+8),i)}static trak(e){return e.duration=e.duration||4294967295,I.box(I.types.trak,I.tkhd(e),I.mdia(e))}static trex(e){let t=e.id;return I.box(I.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}static trun(e,t){let i,r,s,a,n,o,l=e.samples||[],d=l.length,h=12+16*d,u=new Uint8Array(h);for(t+=8+h,u.set([0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,t>>>24&255,t>>>16&255,t>>>8&255,255&t],0),i=0;i<d;i++)s=(r=l[i]).duration,a=r.size,n=r.flags,o=r.cts,u.set([s>>>24&255,s>>>16&255,s>>>8&255,255&s,a>>>24&255,a>>>16&255,a>>>8&255,255&a,n.isLeading<<2|n.dependsOn,n.isDependedOn<<6|n.hasRedundancy<<4|n.paddingValue<<1|n.isNonSync,61440&n.degradPrio,15&n.degradPrio,o>>>24&255,o>>>16&255,o>>>8&255,255&o],12+16*i);return I.box(I.types.trun,u)}static initSegment(e){I.types||I.init();let t,i=I.moov(e);return(t=new Uint8Array(I.FTYP.byteLength+i.byteLength)).set(I.FTYP),t.set(i,I.FTYP.byteLength),t}}var k=I;const C=1e4;var O=class{constructor(e,t,i,r){this.observer=e,this.config=t,this.typeSupported=i;const s=navigator.userAgent;this.isSafari=r&&r.indexOf("Apple")>-1&&s&&!s.match("CriOS"),this.ISGenerated=!1}destroy(){}resetTimeStamp(e){this._initPTS=this._initDTS=e}resetInitSegment(){this.ISGenerated=!1}remux(e,t,i,s,a,o,l){if(this.ISGenerated||this.generateIS(e,t,a),this.ISGenerated){const i=e.samples.length,r=t.samples.length;let s=a,d=a;if(i&&r){let i=(e.samples[0].pts-t.samples[0].pts)/t.inputTimeScale;s+=Math.max(0,i),d+=Math.max(0,-i)}if(i){e.timescale||(n.b.warn("regenerate InitSegment as audio detected"),this.generateIS(e,t,a));let i=this.remuxAudio(e,s,o,l);if(r){let r;i&&(r=i.endPTS-i.startPTS),t.timescale||(n.b.warn("regenerate InitSegment as video detected"),this.generateIS(e,t,a)),this.remuxVideo(t,d,o,r,l)}}else if(r){let i=this.remuxVideo(t,d,o,0,l);i&&e.codec&&this.remuxEmptyAudio(e,s,o,i)}}i.samples.length&&this.remuxID3(i,a),s.samples.length&&this.remuxText(s,a),this.observer.trigger(r.a.FRAG_PARSED)}generateIS(e,t,i){let a,o,l=this.observer,d=e.samples,h=t.samples,u=this.typeSupported,c="audio/mp4",f={},g={tracks:f},p=void 0===this._initPTS;if(p&&(a=o=1/0),e.config&&d.length&&(e.timescale=e.samplerate,n.b.log(`audio sampling rate : ${e.samplerate}`),e.isAAC||(u.mpeg?(c="audio/mpeg",e.codec=""):u.mp3&&(e.codec="mp3")),f.audio={container:c,codec:e.codec,initSegment:!e.isAAC&&u.mpeg?new Uint8Array:k.initSegment([e]),metadata:{channelCount:e.channelCount}},p&&(a=o=d[0].pts-e.inputTimeScale*i)),t.sps&&t.pps&&h.length){const e=t.inputTimeScale;t.timescale=e,f.video={container:"video/mp4",codec:t.codec,initSegment:k.initSegment([t]),metadata:{width:t.width,height:t.height}},p&&(a=Math.min(a,h[0].pts-e*i),o=Math.min(o,h[0].dts-e*i),this.observer.trigger(r.a.INIT_PTS_FOUND,{initPTS:a}))}Object.keys(f).length?(l.trigger(r.a.FRAG_PARSING_INIT_SEGMENT,g),this.ISGenerated=!0,p&&(this._initPTS=a,this._initDTS=o)):l.trigger(r.a.ERROR,{type:s.b.MEDIA_ERROR,details:s.a.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"})}remuxVideo(e,t,i,a,o){let l,d,h,u,c,f,g,p=8;const m=e.timescale,y=e.samples,E=[],b=y.length,T=this._PTSNormalize,v=this._initPTS;let S=this.nextAvcDts;const R=this.isSafari;if(0===b)return;R&&(i|=y.length&&S&&(o&&Math.abs(t-S/m)<.1||Math.abs(y[0].pts-S-v)<m/5)),i||(S=t*m),y.forEach(function(e){e.pts=T(e.pts-v,S),e.dts=T(e.dts-v,S)}),y.sort(function(e,t){const i=e.dts-t.dts,r=e.pts-t.pts;return i||r||e.id-t.id});let A=y.reduce((e,t)=>Math.max(Math.min(e,t.pts-t.dts),-18e3),0);if(A<0){n.b.warn(`PTS < DTS detected in video samples, shifting DTS by ${Math.round(A/90)} ms to overcome this issue`);for(let e=0;e<y.length;e++)y[e].dts+=A}let _=y[0];c=Math.max(_.dts,0),u=Math.max(_.pts,0);let L=Math.round((c-S)/90);i&&L&&(L>1?n.b.log(`AVC:${L} ms hole between fragments detected,filling it`):L<-1&&n.b.log(`AVC:${-L} ms overlapping between fragments detected`),c=S,y[0].dts=c,u=Math.max(u-L,S),y[0].pts=u,n.b.log(`Video/PTS/DTS adjusted: ${Math.round(u/90)}/${Math.round(c/90)},delta:${L} ms`)),_=y[y.length-1],g=Math.max(_.dts,0),f=Math.max(_.pts,0,g),R&&(l=Math.round((g-c)/(y.length-1)));let D=0,w=0;for(let e=0;e<b;e++){let t=y[e],i=t.units,r=i.length,s=0;for(let e=0;e<r;e++)s+=i[e].data.length;w+=s,D+=r,t.length=s,t.dts=R?c+e*l:Math.max(t.dts,c),t.pts=Math.max(t.pts,t.dts)}let I=w+4*D+8;try{d=new Uint8Array(I)}catch(e){return void this.observer.trigger(r.a.ERROR,{type:s.b.MUX_ERROR,details:s.a.REMUX_ALLOC_ERROR,fatal:!1,bytes:I,reason:`fail allocating video mdat ${I}`})}let C=new DataView(d.buffer);C.setUint32(0,I),d.set(k.types.mdat,4);for(let e=0;e<b;e++){let t,i=y[e],r=i.units,s=0;for(let e=0,t=r.length;e<t;e++){let t=r[e],i=t.data,a=t.data.byteLength;C.setUint32(p,a),p+=4,d.set(i,p),p+=a,s+=4+a}if(R)t=Math.max(0,l*Math.round((i.pts-i.dts)/l));else{if(e<b-1)l=y[e+1].dts-i.dts;else{let t=this.config,r=i.dts-y[e>0?e-1:e].dts;if(t.stretchShortVideoTrack){let e=t.maxBufferHole,s=Math.floor(e*m),o=(a?u+a*m:this.nextAudioPts)-i.pts;o>s?((l=o-r)<0&&(l=r),n.b.log(`It is approximately ${o/90} ms to the next segment; using duration ${l/90} ms for the last video frame.`)):l=r}else l=r}t=Math.round(i.pts-i.dts)}E.push({size:s,duration:l,cts:t,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:i.key?2:1,isNonSync:i.key?0:1}})}this.nextAvcDts=g+l;let O=e.dropped;if(e.len=0,e.nbNalu=0,e.dropped=0,E.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1){let e=E[0].flags;e.dependsOn=2,e.isNonSync=0}e.samples=E,h=k.moof(e.sequenceNumber++,c,e),e.samples=[];let P={data1:h,data2:d,startPTS:u/m,endPTS:(f+l)/m,startDTS:c/m,endDTS:this.nextAvcDts/m,type:"video",hasAudio:!1,hasVideo:!0,nb:E.length,dropped:O};return this.observer.trigger(r.a.FRAG_PARSING_DATA,P),P}remuxAudio(e,t,i,a){const o=e.inputTimeScale,l=e.timescale,d=o/l,h=(e.isAAC?1024:1152)*d,u=this._PTSNormalize,c=this._initPTS,f=!e.isAAC&&this.typeSupported.mpeg;let g,p,m,y,E,b,T,v=e.samples,S=[],R=this.nextAudioPts;if(i|=v.length&&R&&(a&&Math.abs(t-R/o)<.1||Math.abs(v[0].pts-R-c)<20*h),v.forEach(function(e){e.pts=e.dts=u(e.pts-c,t*o)}),0===(v=v.filter(function(e){return e.pts>=0})).length)return;if(i||(R=a?t*o:v[0].pts),e.isAAC){const t=this.config.maxAudioFramesDrift;for(let i=0,r=R;i<v.length;){var A,_=v[i];A=_.pts-r;const s=Math.abs(1e3*A/o);if(A<=-t*h)n.b.warn(`Dropping 1 audio frame @ ${(r/o).toFixed(3)}s due to ${Math.round(s)} ms overlap.`),v.splice(i,1),e.len-=_.unit.length;else if(A>=t*h&&s<C&&r){let t=Math.round(A/h);n.b.warn(`Injecting ${t} audio frame @ ${(r/o).toFixed(3)}s due to ${Math.round(1e3*A/o)} ms gap.`);for(let s=0;s<t;s++){let t=Math.max(r,0);(m=D.getSilentFrame(e.manifestCodec||e.codec,e.channelCount))||(n.b.log("Unable to get silent frame for given audio codec; duplicating last frame instead."),m=_.unit.subarray()),v.splice(i,0,{unit:m,pts:t,dts:t}),e.len+=m.length,r+=h,i++}_.pts=_.dts=r,r+=h,i++}else Math.abs(A),_.pts=_.dts=r,r+=h,i++}}for(let t=0,a=v.length;t<a;t++){let a=v[t],l=a.unit,u=a.pts;if(void 0!==T)p.duration=Math.round((u-T)/d);else{let t=Math.round(1e3*(u-R)/o),a=0;if(i&&e.isAAC&&t){if(t>0&&t<C)a=Math.round((u-R)/h),n.b.log(`${t} ms hole between AAC samples detected,filling it`),a>0&&((m=D.getSilentFrame(e.manifestCodec||e.codec,e.channelCount))||(m=l.subarray()),e.len+=a*m.length);else if(t<-12){n.b.log(`drop overlapping AAC sample, expected/parsed/delta:${(R/o).toFixed(3)}s/${(u/o).toFixed(3)}s/${-t}ms`),e.len-=l.byteLength;continue}u=R}if(b=u,!(e.len>0))return;{let t=f?e.len:e.len+8;g=f?0:8;try{y=new Uint8Array(t)}catch(e){return void this.observer.trigger(r.a.ERROR,{type:s.b.MUX_ERROR,details:s.a.REMUX_ALLOC_ERROR,fatal:!1,bytes:t,reason:`fail allocating audio mdat ${t}`})}f||(new DataView(y.buffer).setUint32(0,t),y.set(k.types.mdat,4))}for(let t=0;t<a;t++)(m=D.getSilentFrame(e.manifestCodec||e.codec,e.channelCount))||(n.b.log("Unable to get silent frame for given audio codec; duplicating this frame instead."),m=l.subarray()),y.set(m,g),g+=m.byteLength,p={size:m.byteLength,cts:0,duration:1024,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},S.push(p)}y.set(l,g);let c=l.byteLength;g+=c,p={size:c,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},S.push(p),T=u}let L=0,w=S.length;if(w>=2&&(L=S[w-2].duration,p.duration=L),w){this.nextAudioPts=R=T+d*L,e.len=0,e.samples=S,E=f?new Uint8Array:k.moof(e.sequenceNumber++,b/d,e),e.samples=[];const t=b/o,i=R/o,s={data1:E,data2:y,startPTS:t,endPTS:i,startDTS:t,endDTS:i,type:"audio",hasAudio:!0,hasVideo:!1,nb:w};return this.observer.trigger(r.a.FRAG_PARSING_DATA,s),s}return null}remuxEmptyAudio(e,t,i,r){let s=e.inputTimeScale,a=s/(e.samplerate?e.samplerate:s),o=this.nextAudioPts,l=(void 0!==o?o:r.startDTS*s)+this._initDTS,d=r.endDTS*s+this._initDTS,h=1024*a,u=Math.ceil((d-l)/h),c=D.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(n.b.warn("remux empty Audio"),!c)return void n.b.trace("Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec!");let f=[];for(let t=0;t<u;t++){let i=l+t*h;f.push({unit:c,pts:i,dts:i}),e.len+=c.length}e.samples=f,this.remuxAudio(e,t,i)}remuxID3(e){let t,i=e.samples.length;const s=e.inputTimeScale,a=this._initPTS,n=this._initDTS;if(i){for(let r=0;r<i;r++)(t=e.samples[r]).pts=(t.pts-a)/s,t.dts=(t.dts-n)/s;this.observer.trigger(r.a.FRAG_PARSING_METADATA,{samples:e.samples})}e.samples=[]}remuxText(e){e.samples.sort(function(e,t){return e.pts-t.pts});let t,i=e.samples.length;const s=e.inputTimeScale,a=this._initPTS;if(i){for(let r=0;r<i;r++)(t=e.samples[r]).pts=(t.pts-a)/s;this.observer.trigger(r.a.FRAG_PARSING_USERDATA,{samples:e.samples})}e.samples=[]}_PTSNormalize(e,t){let i;if(void 0===t)return e;for(i