xgplayer-transmuxer 3.0.0-next.21 → 3.0.0-next.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.array.map.js"),require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.string.includes.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.number.is-finite.js"),require("core-js/modules/es.number.constructor.js"),require("core-js/modules/es.array.splice.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.typed-array.uint8-array.js"),require("core-js/modules/esnext.typed-array.at.js"),require("core-js/modules/es.typed-array.copy-within.js"),require("core-js/modules/es.typed-array.every.js"),require("core-js/modules/es.typed-array.fill.js"),require("core-js/modules/es.typed-array.filter.js"),require("core-js/modules/es.typed-array.find.js"),require("core-js/modules/es.typed-array.find-index.js"),require("core-js/modules/esnext.typed-array.find-last.js"),require("core-js/modules/esnext.typed-array.find-last-index.js"),require("core-js/modules/es.typed-array.for-each.js"),require("core-js/modules/es.typed-array.includes.js"),require("core-js/modules/es.typed-array.index-of.js"),require("core-js/modules/es.typed-array.iterator.js"),require("core-js/modules/es.typed-array.join.js"),require("core-js/modules/es.typed-array.last-index-of.js"),require("core-js/modules/es.typed-array.map.js"),require("core-js/modules/es.typed-array.reduce.js"),require("core-js/modules/es.typed-array.reduce-right.js"),require("core-js/modules/es.typed-array.reverse.js"),require("core-js/modules/es.typed-array.set.js"),require("core-js/modules/es.typed-array.slice.js"),require("core-js/modules/es.typed-array.some.js"),require("core-js/modules/es.typed-array.sort.js"),require("core-js/modules/es.typed-array.subarray.js"),require("core-js/modules/es.typed-array.to-locale-string.js"),require("core-js/modules/es.typed-array.to-string.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.array.join.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.regexp.test.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.regexp.flags.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.string.pad-start.js"),require("core-js/modules/es.array.find.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/es.array-buffer.constructor.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.typed-array.int8-array.js"),require("core-js/modules/es.typed-array.uint8-clamped-array.js"),require("core-js/modules/es.typed-array.int16-array.js"),require("core-js/modules/es.typed-array.uint16-array.js"),require("core-js/modules/es.typed-array.int32-array.js"),require("core-js/modules/es.typed-array.uint32-array.js"),require("core-js/modules/es.typed-array.float32-array.js"),require("core-js/modules/es.typed-array.float64-array.js")):"function"==typeof define&&define.amd?define(["core-js/modules/es.array.concat.js","core-js/modules/es.object.to-string.js","core-js/modules/web.dom-collections.for-each.js","core-js/modules/es.array.map.js","core-js/modules/es.array.includes.js","core-js/modules/es.string.includes.js","core-js/modules/es.array.filter.js","core-js/modules/es.number.is-finite.js","core-js/modules/es.number.constructor.js","core-js/modules/es.array.splice.js","core-js/modules/es.array.iterator.js","core-js/modules/es.typed-array.uint8-array.js","core-js/modules/esnext.typed-array.at.js","core-js/modules/es.typed-array.copy-within.js","core-js/modules/es.typed-array.every.js","core-js/modules/es.typed-array.fill.js","core-js/modules/es.typed-array.filter.js","core-js/modules/es.typed-array.find.js","core-js/modules/es.typed-array.find-index.js","core-js/modules/esnext.typed-array.find-last.js","core-js/modules/esnext.typed-array.find-last-index.js","core-js/modules/es.typed-array.for-each.js","core-js/modules/es.typed-array.includes.js","core-js/modules/es.typed-array.index-of.js","core-js/modules/es.typed-array.iterator.js","core-js/modules/es.typed-array.join.js","core-js/modules/es.typed-array.last-index-of.js","core-js/modules/es.typed-array.map.js","core-js/modules/es.typed-array.reduce.js","core-js/modules/es.typed-array.reduce-right.js","core-js/modules/es.typed-array.reverse.js","core-js/modules/es.typed-array.set.js","core-js/modules/es.typed-array.slice.js","core-js/modules/es.typed-array.some.js","core-js/modules/es.typed-array.sort.js","core-js/modules/es.typed-array.subarray.js","core-js/modules/es.typed-array.to-locale-string.js","core-js/modules/es.typed-array.to-string.js","core-js/modules/es.regexp.to-string.js","core-js/modules/es.array.slice.js","core-js/modules/es.function.name.js","core-js/modules/es.array.join.js","core-js/modules/es.regexp.exec.js","core-js/modules/es.regexp.test.js","core-js/modules/es.object.keys.js","core-js/modules/es.regexp.flags.js","core-js/modules/web.dom-collections.iterator.js","core-js/modules/es.string.pad-start.js","core-js/modules/es.array.find.js","core-js/modules/es.array.from.js","core-js/modules/es.string.iterator.js","core-js/modules/es.array-buffer.constructor.js","core-js/modules/es.object.assign.js","core-js/modules/es.typed-array.int8-array.js","core-js/modules/es.typed-array.uint8-clamped-array.js","core-js/modules/es.typed-array.int16-array.js","core-js/modules/es.typed-array.uint16-array.js","core-js/modules/es.typed-array.int32-array.js","core-js/modules/es.typed-array.uint32-array.js","core-js/modules/es.typed-array.float32-array.js","core-js/modules/es.typed-array.float64-array.js"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).XGPlayerTransmuxer=t()}(this,(function(){"use strict";function e(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function t(t){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?e(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e,t,a){return t&&r(e.prototype,t),a&&r(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function l(e,t,a){return(l=c()?Reflect.construct.bind():function(e,t,a){var r=[null];r.push.apply(r,t);var s=new(Function.bind.apply(e,r));return a&&u(s,a.prototype),s}).apply(null,arguments)}function d(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function f(e){var t=c();return function(){var a,r=o(e);if(t){var s=o(this).constructor;a=Reflect.construct(r,arguments,s)}else a=r.apply(this,arguments);return d(this,a)}}function h(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}function p(){return p="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,a){var r=h(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(arguments.length<3?e:a):s.value}},p.apply(this,arguments)}function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var r,s,i=[],n=!0,o=!1;try{for(a=a.call(e);!(n=(r=a.next()).done)&&(i.push(r.value),!t||i.length!==t);n=!0);}catch(u){o=!0,s=u}finally{try{n||null==a.return||a.return()}finally{if(o)throw s}}return i}(e,t)||m(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e){return function(e){if(Array.isArray(e))return g(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||m(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){if(e){if("string"==typeof e)return g(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,r=new Array(t);a<t;a++)r[a]=e[a];return r}var k={VIDEO:"video",AUDIO:"audio",METADATA:"metadata"},b={AVC:"avc",HEVC:"hevc"},_={AAC:"aac",G711PCMA:"g7110a",G711PCMU:"g7110m"},x={LARGE_AV_SHIFT:"LARGE_AV_SHIFT",LARGE_VIDEO_GAP:"LARGE_VIDEO_GAP",LARGE_VIDEO_GAP_BETWEEN_CHUNK:"LARGE_VIDEO_GAP_BETWEEN_CHUNK",LARGE_AUDIO_GAP:"LARGE_AUDIO_GAP",AUDIO_FILLED:"AUDIO_FILLED",AUDIO_DROPPED:"AUDIO_DROPPED"},w=function(){function e(){a(this,e),i(this,"id",1),i(this,"type",k.VIDEO),i(this,"codecType",b.AVC),i(this,"pid",-1),i(this,"hvcC",void 0),i(this,"codec",""),i(this,"timescale",0),i(this,"formatTimescale",0),i(this,"sequenceNumber",0),i(this,"baseMediaDecodeTime",0),i(this,"baseDts",0),i(this,"duration",0),i(this,"warnings",[]),i(this,"samples",[]),i(this,"pps",[]),i(this,"sps",[]),i(this,"vps",[]),i(this,"fpsNum",0),i(this,"fpsDen",0),i(this,"sarRatio",[]),i(this,"width",0),i(this,"height",0),i(this,"nalUnitSize",4),i(this,"present",!1),i(this,"isVideoEncryption",!1),i(this,"isAudioEncryption",!1),i(this,"isVideo",!0),i(this,"kid",null),i(this,"pssh",null),i(this,"ext",void 0)}return s(e,[{key:"reset",value:function(){this.sequenceNumber=this.width=this.height=this.fpsDen=this.fpsNum=this.duration=this.baseMediaDecodeTime=this.timescale=0,this.codec="",this.present=!1,this.pid=-1,this.pps=[],this.sps=[],this.vps=[],this.sarRatio=[],this.samples=[],this.warnings=[],this.hvcC=null}},{key:"exist",value:function(){return!!(this.pps.length&&this.sps.length&&this.codec)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isVideoEncryption}}]),e}(),D=function(){function e(){a(this,e),i(this,"id",2),i(this,"type",k.AUDIO),i(this,"codecType",_.AAC),i(this,"pid",-1),i(this,"codec",""),i(this,"sequenceNumber",0),i(this,"sampleDuration",0),i(this,"timescale",0),i(this,"formatTimescale",0),i(this,"baseMediaDecodeTime",0),i(this,"duration",0),i(this,"warnings",[]),i(this,"samples",[]),i(this,"baseDts",0),i(this,"sampleSize",16),i(this,"sampleRate",0),i(this,"channelCount",0),i(this,"objectType",0),i(this,"sampleRateIndex",0),i(this,"config",[]),i(this,"present",!1),i(this,"isVideoEncryption",!1),i(this,"isAudioEncryption",!1),i(this,"kid",null),i(this,"ext",void 0)}return s(e,[{key:"reset",value:function(){this.sequenceNumber=0,this.timescale=0,this.sampleDuration=0,this.sampleRate=0,this.channelCount=0,this.baseMediaDecodeTime=0,this.present=!1,this.pid=-1,this.codec="",this.samples=[],this.config=[],this.warnings=[]}},{key:"exist",value:function(){return!!(this.sampleRate&&this.channelCount&&this.codec&&this.codecType===_.AAC)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isAudioEncryption}}]),e}(),S=function(){function e(t,r,s){a(this,e),i(this,"flag",{}),i(this,"keyframe",!1),i(this,"gopId",0),i(this,"duration",0),i(this,"size",0),i(this,"units",[]),i(this,"chromaFormat",420),this.originPts=this.pts=t,this.originDts=this.dts=r,s&&(this.units=s)}return s(e,[{key:"cts",get:function(){return this.pts-this.dts}},{key:"setToKeyframe",value:function(){this.keyframe=!0,this.flag.dependsOn=2,this.flag.isNonSyncSample=0}}]),e}(),A=s((function e(t,r,s,n){a(this,e),i(this,"duration",1024),i(this,"flag",{dependsOn:2,isNonSyncSample:0}),i(this,"keyframe",!0),this.originPts=this.pts=this.dts=t,this.data=r,this.size=r.byteLength,this.sampleOffset=n,s&&(this.duration=s)})),T=s((function e(t,r){a(this,e),i(this,"time",0),this.data=t,this.originPts=this.pts=r})),j=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(T),E=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(T),B=function(){function e(){a(this,e),i(this,"id",3),i(this,"type",k.METADATA),i(this,"timescale",0),i(this,"flvScriptSamples",[]),i(this,"seiSamples",[])}return s(e,[{key:"exist",value:function(){return!(!this.flvScriptSamples.length&&!this.seiSamples.length||!this.timescale)}},{key:"reset",value:function(){this.timescale=0,this.flvScriptSamples=[],this.seiSamples=[]}},{key:"hasSample",value:function(){return!(!this.flvScriptSamples.length&&!this.seiSamples.length)}}]),e}(),C=Object.freeze(Object.defineProperty({__proto__:null,VideoTrack:w,AudioTrack:D,VideoSample:S,AudioSample:A,FlvScriptSample:j,SeiSample:E,MetadataTrack:B,TrackType:k,VideoCodecType:b,AudioCodecType:_,WarningType:x},Symbol.toStringTag,{value:"Module"})),P=function(){function e(t){if(a(this,e),i(this,"_bytesAvailable",void 0),i(this,"_bitsAvailable",0),i(this,"_word",0),!t)throw new Error("ExpGolomb data params is required");this._data=t,this._bytesAvailable=t.byteLength,this._bytesAvailable&&this._loadWord()}return s(e,[{key:"_loadWord",value:function(){var e=this._data.byteLength-this._bytesAvailable,t=Math.min(4,this._bytesAvailable);if(0===t)throw new Error("No bytes available");var a=new Uint8Array(4);a.set(this._data.subarray(e,e+t)),this._word=new DataView(a.buffer).getUint32(0),this._bitsAvailable=8*t,this._bytesAvailable-=t}},{key:"skipBits",value:function(e){if(this._bitsAvailable>e)this._word<<=e,this._bitsAvailable-=e;else{e-=this._bitsAvailable;var t=Math.floor(e/8);e-=8*t,this._bytesAvailable-=t,this._loadWord(),this._word<<=e,this._bitsAvailable-=e}}},{key:"readBits",value:function(e){if(e>32)throw new Error("Cannot read more than 32 bits");var t=Math.min(this._bitsAvailable,e),a=this._word>>>32-t;return this._bitsAvailable-=t,this._bitsAvailable>0?this._word<<=t:this._bytesAvailable>0&&this._loadWord(),(t=e-t)>0&&this._bitsAvailable?a<<t|this.readBits(t):a}},{key:"skipLZ",value:function(){var e;for(e=0;e<this._bitsAvailable;++e)if(0!=(this._word&2147483648>>>e))return this._word<<=e,this._bitsAvailable-=e,e;return this._loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBool",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"skipScalingList",value:function(e){for(var t=8,a=8,r=0;r<e;r++)0!==a&&(a=(t+this.readEG()+256)%256),t=0===a?t:a}}]),e}(),U=function(){function e(t){a(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]")}return s(e,[{key:"warn",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).warn.apply(t,[this._prefix].concat(r))}}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();i(U,"disabled",!0);var I=function(){function e(){a(this,e)}return s(e,null,[{key:"decode",value:function(t){for(var a=[],r=t,s=0,i=t.length;s<i;)if(r[s]<128)a.push(String.fromCharCode(r[s])),++s;else{if(r[s]<192);else if(r[s]<224){if(e._checkContinuation(r,s,1)){var n=(31&r[s])<<6|63&r[s+1];if(n>=128){a.push(String.fromCharCode(65535&n)),s+=2;continue}}}else if(r[s]<240){if(e._checkContinuation(r,s,2)){var o=(15&r[s])<<12|(63&r[s+1])<<6|63&r[s+2];if(o>=2048&&55296!=(63488&o)){a.push(String.fromCharCode(65535&o)),s+=3;continue}}}else if(r[s]<248&&e._checkContinuation(r,s,3)){var u=(7&r[s])<<18|(63&r[s+1])<<12|(63&r[s+2])<<6|63&r[s+3];if(u>65536&&u<1114112){u-=65536,a.push(String.fromCharCode(u>>>10|55296)),a.push(String.fromCharCode(1023&u|56320)),s+=4;continue}}a.push(String.fromCharCode(65533)),++s}return a.join("")}},{key:"_checkContinuation",value:function(e,t,a){var r=e;if(t+a<r.length){for(;a--;)if(128!=(192&r[++t]))return!1;return!0}return!1}}]),e}(),M="undefined"!=typeof window,O=M&&navigator.userAgent.toLocaleLowerCase(),z=M&&/^((?!chrome|android).)*safari/.test(O),R=M&&O.includes("firefox"),V=M&&O.includes("android");function L(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];t=t.filter(Boolean);var r=new Uint8Array(t.reduce((function(e,t){return e+t.byteLength}),0)),s=0;return t.forEach((function(e){r.set(e,s),s+=e.byteLength})),r}var N=Math.pow(2,32);function F(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<8)+(e[t+1]||0)}function G(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+(e[t+3]||0)}function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return G(e,t)*N+G(e,t+4)}function H(e){for(var t,a="avc1.",r=0;r<3;r++)(t=e[r].toString(16)).length<2&&(t="0".concat(t)),a+=t;return a}function K(e){var t="";if(e.forEach((function(e){t+=function(e){return("0"+Number(e).toString(16)).slice(-2).toUpperCase()}(e)})),t.length<=32)for(var a=32-t.length,r=0;r<a;r++)t+="0";return t}function W(e){if(!Array.isArray(e)){for(var t=[],a="",r=0;r<e.length;r++)r%2&&(a=e[r-1]+e[r],t.push(parseInt(a,16)),a="");return t}return e.map((function(e){return parseInt(e,16)}))}var X=function(){function e(){a(this,e)}return s(e,null,[{key:"parseAnnexB",value:function(e){for(var t=e.length,a=2,r=0;null!==e[a]&&void 0!==e[a]&&1!==e[a];)a++;if((r=++a+2)>=t)return[];for(var s=[];r<t;)switch(e[r]){case 0:if(0!==e[r-1]){r+=2;break}if(0!==e[r-2]){r++;break}a!==r-2&&s.push(e.subarray(a,r-2));do{r++}while(1!==e[r]&&r<t);r=(a=r+1)+2;break;case 1:if(0!==e[r-1]||0!==e[r-2]){r+=3;break}a!==r-2&&s.push(e.subarray(a,r-2)),r=(a=r+1)+2;break;default:r+=3}return a<t&&s.push(e.subarray(a)),s}},{key:"parseAvcC",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(!(e.length<4)){for(var a,r=e.length,s=[],i=0;i+t<r;)if(a=G(e,i),3===t&&(a>>>=8),i+=t,a){if(i+a>r)break;s.push(e.subarray(i,i+a)),i+=a}return s}}},{key:"parseSEI",value:function(e){for(var t=e.length,a=1,r=0,s=0,i="";255===e[a];)r+=255,a++;for(r+=e[a++];255===e[a];)s+=255,a++;if(s+=e[a++],5===r&&t>a+16)for(var n=0;n<16;n++)i+=e[a].toString(16),a++;return{payload:e.subarray(a),type:r,size:s,uuid:i}}},{key:"removeEPB",value:function(e){for(var t=e.byteLength,a=[],r=1;r<t-2;)0===e[r]&&0===e[r+1]&&3===e[r+2]?(a.push(r+2),r+=2):r++;if(!a.length)return e;var s=t-a.length,i=new Uint8Array(s),n=0;for(r=0;r<s;n++,r++)n===a[0]&&(n++,a.shift()),i[r]=e[n];return i}}]),e}(),Y=function(){function e(){a(this,e)}return s(e,null,[{key:"parseAVCDecoderConfigurationRecord",value:function(t){if(!(t.length<7)){for(var a,r,s=1+(3&t[4]),i=[],n=[],o=6,u=31&t[5],c=0;c<u;c++)if(r=t[o]<<8|t[o+1],o+=2,r){var l=t.subarray(o,o+r);o+=r,i.push(l),a||(a=e.parseSPS(X.removeEPB(l)))}var d,f=t[o];o++;for(var h=0;h<f;h++)d=t[o]<<8|t[o+1],o+=2,d&&(n.push(t.subarray(o,o+d)),o+=d);return{sps:a,spsArr:i,ppsArr:n,nalUnitSize:s}}}},{key:"parseSPS",value:function(e){var t=new P(e);t.readUByte();var a=t.readUByte(),r=t.readUByte(),s=t.readUByte();t.skipUEG();var i=420;if(100===a||110===a||122===a||244===a||44===a||83===a||86===a||118===a||128===a||138===a||144===a){var n=t.readUEG();if(n<=3&&(i=[0,420,422,444][n]),3===n&&t.skipBits(1),t.skipUEG(),t.skipUEG(),t.skipBits(1),t.readBool())for(var o=3!==n?8:12,u=0;u<o;u++)t.readBool()&&(u<6?t.skipScalingList(16):t.skipScalingList(64))}t.skipUEG();var c=t.readUEG();if(0===c)t.readUEG();else if(1===c){t.skipBits(1),t.skipUEG(),t.skipUEG();for(var l=t.readUEG(),d=0;d<l;d++)t.skipUEG()}t.skipUEG(),t.skipBits(1);var f=t.readUEG(),h=t.readUEG(),p=t.readBits(1);0===p&&t.skipBits(1),t.skipBits(1);var v,y,m,g,k,b=0,_=0,x=0,w=0;if(t.readBool()&&(b=t.readUEG(),_=t.readUEG(),x=t.readUEG(),w=t.readUEG()),t.readBool()){if(t.readBool())switch(t.readUByte()){case 1:v=[1,1];break;case 2:v=[12,11];break;case 3:v=[10,11];break;case 4:v=[16,11];break;case 5:v=[40,33];break;case 6:v=[24,11];break;case 7:v=[20,11];break;case 8:v=[32,11];break;case 9:v=[80,33];break;case 10:v=[18,11];break;case 11:v=[15,11];break;case 12:v=[64,33];break;case 13:v=[160,99];break;case 14:v=[4,3];break;case 15:v=[3,2];break;case 16:v=[2,1];break;case 255:v=[t.readUByte()<<8|t.readUByte(),t.readUByte()<<8|t.readUByte()]}if(t.readBool()&&t.readBool(),t.readBool()&&(t.readBits(4),t.readBool()&&t.readBits(24)),t.readBool()&&(t.readUEG(),t.readUEG()),t.readBool()){var D=t.readBits(32),S=t.readBits(32);y=t.readBool(),k=(m=S)/(g=2*D)}}return{codec:H(e.subarray(1,4)),profileIdc:a,profileCompatibility:r,levelIdc:s,chromaFormat:i,width:Math.ceil(16*(f+1)-2*(b+_)),height:(2-p)*(h+1)*16-(p?2:4)*(x+w),sarRatio:v,fpsNum:m,fpsDen:g,fps:k,fixedFrame:y}}}]),e}(),Z=function(){function e(){a(this,e)}return s(e,null,[{key:"getRateIndexByRate",value:function(t){return e.FREQ.indexOf(t)}},{key:"parseADTS",value:function(t,a){for(var r=t.length,s=0;s+2<r&&(255!==t[s]||240!=(246&t[s+1]));)s++;if(!(s>=r)){var i=s,n=[],o=(60&t[s+2])>>>2,u=e.FREQ[o];if(!u)throw new Error("Invalid sampling index: ".concat(o));for(var c,l,d=1+((192&t[s+2])>>>6),f=(1&t[s+2])<<2|(192&t[s+3])>>>6,h=e._getConfig(o,f,d),p=h.config,v=h.codec,y=0,m=e.getFrameDuration(u);s+7<r;)if(255===t[s]&&240==(246&t[s+1])){if(r-s<(l=(3&t[s+3])<<11|t[s+4]<<3|(224&t[s+5])>>5))break;c=2*(1&~t[s+1]),n.push({pts:a+y*m,data:t.subarray(s+7+c,s+l)}),y++,s+=l}else s++;return{skip:i,remaining:s>=r?void 0:t.subarray(s),frames:n,samplingFrequencyIndex:o,sampleRate:u,objectType:d,channelCount:f,codec:v,config:p,originCodec:"mp4a.40.".concat(d)}}}},{key:"parseAudioSpecificConfig",value:function(t){if(t.length){var a=t[0]>>>3,r=(7&t[0])<<1|t[1]>>>7,s=(120&t[1])>>>3,i=e.FREQ[r];if(i){var n=e._getConfig(r,s,a);return{samplingFrequencyIndex:r,sampleRate:i,objectType:a,channelCount:s,config:n.config,codec:n.codec,originCodec:"mp4a.40.".concat(a)}}}}},{key:"getFrameDuration",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return 1024*t/e}},{key:"_getConfig",value:function(e,t,a){var r,s,i=[];return R?e>=6?(r=5,s=e-3):(r=2,s=e):V?(r=2,s=e):(r=2===a||5===a?a:5,s=e,e>=6?s=e-3:1===t&&(r=2,s=e)),i[0]=r<<3,i[0]|=(14&e)>>1,i[1]=(1&e)<<7,i[1]|=t<<3,5===r&&(i[1]|=(14&s)>>1,i[2]=(1&s)<<7,i[2]|=8,i[3]=0),{config:i,codec:"mp4a.40.".concat(r)}}},{key:"getSilentFrame",value:function(e,t){if("mp4a.40.2"===e){if(1===t)return new Uint8Array([0,200,0,128,35,128]);if(2===t)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224])}else{if(1===t)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}}}]),e}();i(Z,"FREQ",[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]);var Q=function(){function e(){a(this,e)}return s(e,null,[{key:"parseHEVCDecoderConfigurationRecord",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(t.length<23)){a=a||{};for(var r,s,i,n,o,u=1+(3&t[21]),c=[],l=[],d=[],f=23,h=t[22],p=0;p<h;p++){i=63&t[f],n=t[f+1]<<8|t[f+2],f+=3;for(var v=0;v<n;v++)if(o=t[f]<<8|t[f+1],f+=2,o){switch(i){case 32:var y=t.subarray(f,f+o);r||(r=e.parseVPS(X.removeEPB(y),a)),d.push(y);break;case 33:var m=t.subarray(f,f+o);s||(s=e.parseSPS(X.removeEPB(m),a)),c.push(m);break;case 34:l.push(t.subarray(f,f+o))}f+=o}}return{hvcC:a,sps:s,spsArr:c,ppsArr:l,vpsArr:d,nalUnitSize:u}}}},{key:"parseVPS",value:function(t,a){a=a||{};var r=new P(t);r.readUByte(),r.readUByte(),r.readBits(12);var s=r.readBits(3);return a.numTemporalLayers=Math.max(a.numTemporalLayers||0,s+1),r.readBits(17),e._parseProfileTierLevel(r,s,a),a}},{key:"parseSPS",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a=a||{};var r=new P(t);r.readUByte(),r.readUByte(),r.readBits(4);var s=r.readBits(3);a.numTemporalLayers=Math.max(s+1,a.numTemporalLayers||0),a.temporalIdNested=r.readBits(1),e._parseProfileTierLevel(r,s,a),r.readUEG();var i=a.chromaFormatIdc=r.readUEG(),n=420;i<=3&&(n=[0,420,422,444][i]);var o=0;3===i&&(o=r.readBits(1));var u,c,l,d,f=r.readUEG(),h=r.readUEG(),p=r.readBits(1);if(1===p&&(u=r.readUEG(),c=r.readUEG(),l=r.readUEG(),d=r.readUEG()),a.bitDepthLumaMinus8=r.readUEG(),a.bitDepthChromaMinus8=r.readUEG(),1===p){var v=1!==i&&2!==i||0!==o?1:2,y=1===i&&0===o?2:1;f-=v*(c+u),h-=y*(d+l)}return{codec:"hev1.1.6.L93.B0",width:f,height:h,chromaFormat:n,hvcC:a}}},{key:"_parseProfileTierLevel",value:function(e,t,a){var r=a.generalTierFlag||0;a.generalProfileSpace=e.readBits(2),a.generalTierFlag=Math.max(e.readBits(1),r),a.generalProfileIdc=Math.max(e.readBits(5),a.generalProfileIdc||0),a.generalProfileCompatibilityFlags=e.readBits(32),a.generalConstraintIndicatorFlags=[e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8)];var s=e.readBits(8);r<a.generalTierFlag?a.generalLevelIdc=s:a.generalLevelIdc=Math.max(s,a.generalLevelIdc||0);for(var i=[],n=[],o=0;o<t;o++)i[o]=e.readBits(1),n[o]=e.readBits(1);t>0&&e.readBits(2*(8-t));for(var u=0;u<t;u++)0!==i[u]&&(e.readBits(2),e.readBits(1),e.readBits(5),e.readBits(16),e.readBits(16),e.readBits(4),e.readBits(16),e.readBits(16),e.readBits(12)),0!==n[u]&&e.readBits(8)}}]),e}(),J=1e3,$=5e3,ee=function(){function e(t,r,s){a(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=s,this._baseDts=-1,this._baseDtsInited=!1,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=0,this._videoTimestampBreak=0,this._lastAudioExceptionGapDot=-1/0,this._lastAudioExceptionOverlapDot=-1/0,this._lastAudioExceptionLargeGapDot=-1/0,this._lastVideoExceptionLargeGapDot=-1/0,this._lastVideoExceptionChunkFirstDtsDot=-1/0}return s(e,[{key:"fix",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=Math.round(1e3*t);var s=this.videoTrack,i=this.audioTrack;if(!a&&r||(this._videoLastSample=null,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=0,this._videoTimestampBreak=0,this._lastAudioExceptionGapDot=-1/0,this._lastAudioExceptionOverlapDot=-1/0,this._lastAudioExceptionLargeGapDot=-1/0,this._lastVideoExceptionLargeGapDot=-1/0,this._lastVideoExceptionChunkFirstDtsDot=-1/0),a&&!r&&(this._baseDtsInited=!1),this._baseDtsInited||this._calculateBaseDts(i,s),this._baseDtsInited){if(!r&&t&&(this._audioNextPts=this._videoNextDts=t),this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(i),this._fixVideo(s),this.metadataTrack.exist()){var n=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/n})),this.metadataTrack.flvScriptSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/n}))}s.samples.length&&(s.baseMediaDecodeTime=s.samples[0].dts),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts*i.timescale/1e3)}}},{key:"_fixVideo",value:function(e){var t=this,a=e.samples;if(a.length){var r;if(a.forEach((function(e){e.dts-=t._baseDts,e.pts-=t._baseDts})),e.fpsNum&&e.fpsDen)r=e.timescale*(e.fpsDen/e.fpsNum);else{var s=e.samples[0],i=e.samples[a.length-1];r=Math.floor((i.dts-s.dts)/(a.length-1))}var n=a.pop();if(this._videoLastSample&&a.unshift(this._videoLastSample),this._videoLastSample=n,a.length){if(void 0===this._videoNextDts){var o=a[0];this._videoNextDts=o.dts}var u=a.length,c=0,l=a[0],d=this._videoNextDts-l.dts;if(Math.abs(d)>200){var f;if(Math.abs(l.dts-this._lastVideoExceptionChunkFirstDtsDot)>5e3)this._lastVideoExceptionChunkFirstDtsDot=l.dts,e.warnings.push({type:x.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts,firstSampleDts:l.dts,nextSampleDts:null===(f=a[1])||void 0===f?void 0:f.dts,sampleDuration:d});this._videoTimestampBreak>=5?(this._videoNextDts=l.dts,this._videoTimestampBreak=0):(l.dts+=d,l.pts+=d)}for(var h=0;h<u;h++){var p=a[h].dts,v=a[h+1];((c=h<u-1?v.dts-p:n?n.dts-p:r)>1e3||c<0)&&(this._videoTimestampBreak++,Math.abs(p-this._lastVideoExceptionLargeGapDot)>5e3&&(this._lastVideoExceptionLargeGapDot=p,e.warnings.push({type:x.LARGE_VIDEO_GAP,time:p/e.timescale,dts:p,originDts:a[h].originDts,nextDts:this._videoNextDts,sampleDuration:c,refSampleDuration:r})),c=r),a[h].duration=c,this._videoNextDts+=c}}}}},{key:"_fixAudio",value:function(e){var t=this,a=e.samples;a.length&&(a.forEach((function(e){e.dts=e.pts-=t._baseDts})),this._doFixAudioInternal(e,a,1e3))}},{key:"_calculateBaseDts",value:function(e,t){var a=e.samples,r=t.samples;if(!a.length&&!r.length)return!1;var s=1/0,i=1/0;a.length&&(e.baseDts=s=a[0].pts),r.length&&(t.baseDts=i=r[0].dts),this._baseDts=Math.min(s,i);var n=i-s;return Number.isFinite(n)&&Math.abs(n)>500&&t.warnings.push({type:x.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){if(this._baseDtsInited&&this._videoTimestampBreak&&this._audioTimestampBreak){if(!this._calculateBaseDts(this.audioTrack,this.videoTrack))return;this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts),this._videoLastSample=null,this._videoTimestampBreak=0,this._audioTimestampBreak=0}}},{key:"_doFixAudioInternal",value:function(e,t,a){e.sampleDuration||(e.sampleDuration=e.codecType===_.AAC?Z.getFrameDuration(e.timescale,a):this._getG711Duration(e));var r=e.sampleDuration,s=e.codecType===_.AAC?1024:r*e.timescale/1e3;if(void 0===this._audioNextPts){var i=t[0];this._audioNextPts=i.pts}for(var n=0;n<t.length;n++){var o=this._audioNextPts,u=t[n],c=u.pts-o;if(0===n&&this._audioTimestampBreak>=5&&(o=this._audioNextPts=u.dts,c=0,this._audioTimestampBreak=0),!this._audioTimestampBreak&&c>=3*r&&c<=J&&!z){var l=this._getSilentFrame(e)||t[0].data.subarray(),d=Math.floor(c/r);Math.abs(u.pts-this._lastAudioExceptionGapDot)>$&&(this._lastAudioExceptionGapDot=u.pts,e.warnings.push({type:x.AUDIO_FILLED,pts:u.pts,originPts:u.originPts,count:d,nextPts:o,refSampleDuration:r}));for(var f=0;f<d;f++){var h=new A(Math.floor(this._audioNextPts+r)-Math.floor(this._audioNextPts),l,s);h.originPts=Math.floor(this._baseDts+o),t.splice(n,0,h),this._audioNextPts+=r,n++}n--}else c<=-3*r&&c>=-1e3?(Math.abs(u.pts-this._lastAudioExceptionOverlapDot)>$&&(this._lastAudioExceptionOverlapDot=u.pts,e.warnings.push({type:x.AUDIO_DROPPED,pts:u.pts,originPts:u.originPts,nextPts:o,refSampleDuration:r})),t.splice(n,1),n--):(Math.abs(c)>J&&(this._audioTimestampBreak++,Math.abs(u.pts-this._lastAudioExceptionLargeGapDot)>$&&(this._lastAudioExceptionLargeGapDot=u.pts,e.warnings.push({type:x.LARGE_AUDIO_GAP,time:u.pts/1e3,pts:u.pts,originPts:u.originPts,nextPts:o,sampleDuration:c,refSampleDuration:r}))),u.dts=u.pts=o,u.duration=s,this._audioNextPts+=r)}}},{key:"_getG711Duration",value:function(e){var t=e.sampleSize,a=e.channelCount,r=e.sampleRate,s=e.samples[0];if(s)return 2*s.data.byteLength/a/(t/8)/r*1e3}},{key:"_getSilentFrame",value:function(e){return e.codecType===_.AAC?Z.getSilentFrame(e.codec,e.channelCount):new Uint8Array(8*e.sampleDuration*e.channelCount)}}]),e}(),te=function(){function e(){a(this,e)}return s(e,null,[{key:"parse",value:function(t){if(!(t.length<3)){var a={},r=e._parseValue(new DataView(t.buffer,t.byteOffset,t.byteLength)),s=e._parseValue(new DataView(t.buffer,t.byteOffset+r.size,t.byteLength-r.size));return a[r.data]=s.data,a}}},{key:"_parseValue",value:function(t){var a,r=t.byteLength,s=1,i=!1;switch(t.getUint8(0)){case 0:a=t.getFloat64(1),s+=8;break;case 1:a=!!t.getUint8(1),s+=1;break;case 2:var n=e._parseString(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s));a=n.data,s+=n.size;break;case 3:a={};var o=0;for(9==(16777215&t.getUint32(r-4))&&(o=3);s<r-4;){var u=e._parseObject(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s-o)),c=u.size,l=u.data;if(u.isEnd)break;a[l.name]=l.value,s+=c}if(s<=r-3)9===(16777215&t.getUint32(s-1))&&(s+=3);break;case 8:a={},s+=4;var d=0;for(9==(16777215&t.getUint32(r-4))&&(d=3);s<r-8;){var f=e._parseObject(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s-d)),h=f.size,p=f.data;if(f.isEnd)break;a[p.name]=p.value,s+=h}if(s<=r-3)9===(16777215&t.getUint32(s-1))&&(s+=3);break;case 9:a=void 0,s=1,i=!0;break;case 10:a=[];var v=t.getUint32(1);s+=4;for(var y=0;y<v;y++){var m=e._parseValue(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s)),g=m.data,k=m.size;a.push(g),s+=k}break;case 11:var b=t.getFloat64(s)+6e4*t.getInt16(s+8);a=new Date(b),s+=10;break;case 12:var _=t.getUint32(1);s+=4,a="",_>0&&(a=I.decode(new Uint8Array(t.buffer,t.byteOffset+s,_))),s+=_;break;default:s=r}return{data:a,size:s,isEnd:i}}},{key:"_parseString",value:function(e){var t=e.getUint16(0),a="";return t>0&&(a=I.decode(new Uint8Array(e.buffer,e.byteOffset+2,t))),{data:a,size:2+t}}},{key:"_parseObject",value:function(t){if(!(t.byteLength<3)){var a=e._parseString(t),r=e._parseValue(new DataView(t.buffer,t.byteOffset+a.size,t.byteLength-a.size));return{data:{name:a.data,value:r.data},size:a.size+r.size,isEnd:r.isEnd}}}}]),e}(),ae=new U("FlvDemuxer"),re=function(){function e(t,r,s){a(this,e),i(this,"_headerParsed",!1),i(this,"_remainingData",null),i(this,"_gopId",0),i(this,"_needAddMetaBeforeKeyFrameNal",!0),this.videoTrack=t||new w,this.audioTrack=r||new D,this.metadataTrack=s||new B,this._fixer=new ee(this.videoTrack,this.audioTrack,this.metadataTrack)}return s(e,[{key:"demux",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],s=this.audioTrack,i=this.videoTrack,n=this.metadataTrack;if(!a&&r||(this._remainingData=null,this._headerParsed=!1),a?(i.reset(),s.reset(),n.reset()):(i.samples=[],s.samples=[],n.seiSamples=[],n.flvScriptSamples=[],i.warnings=[],s.warnings=[],this._remainingData&&(t=L(this._remainingData,t),this._remainingData=null)),!t.length)return{videoTrack:i,audioTrack:s,metadataTrack:n};var o=0;if(!this._headerParsed){if(!e.probe(t))throw new Error("Invalid flv file");s.present=(4&t[4])>>>2!=0,i.present=0!=(1&t[4]),this._headerParsed=!0,o=G(t,5)+4}for(var u,c,l,d,f,h=t.length;o+15<h&&(u=t[o],!(o+15+(c=t[o+1]<<16|t[o+2]<<8|t[o+3])>h));)l=(t[o+7]<<24>>>0)+(t[o+4]<<16)+(t[o+5]<<8)+t[o+6],o+=11,d=t.subarray(o,o+c),8===u?this._parseAudio(d,l):9===u?this._parseVideo(d,l):18===u?this._parseScript(d,l):ae.warn("Invalid tag type: ".concat(u)),(f=G(t,o+=c))!==11+c&&ae.warn("Invalid PrevTagSize ".concat(f," (").concat(11+c,")")),o+=4;return o<h&&(this._remainingData=t.subarray(o)),s.formatTimescale=i.formatTimescale=i.timescale=n.timescale=1e3,s.timescale=s.sampleRate||0,!s.exist()&&s.hasSample()&&s.reset(),!i.exist()&&i.hasSample()&&i.reset(),{videoTrack:i,audioTrack:s,metadataTrack:n}}},{key:"fix",value:function(e,t,a){return this._fixer.fix(e,t,a),{videoTrack:this.videoTrack,audioTrack:this.audioTrack,metadataTrack:this.metadataTrack}}},{key:"demuxAndFix",value:function(e,t,a,r){return this.demux(e,t,a),this.fix(r,t,a)}},{key:"_parseAudio",value:function(t,a){if(t.length){var r=(240&t[0])>>>4,s=this.audioTrack;if(10!==r&&7!==r&&8!==r)return ae.warn("Unsupported sound format: ".concat(r)),void s.reset();if(10!==r){var i=(12&t[0])>>2,n=(2&t[0])>>1,o=1&t[0];s.sampleRate=e.AUDIO_RATE[i],s.sampleSize=n?16:8,s.channelCount=o+1}10===r?this._parseAac(t,a):this._parseG711(t,a,r)}}},{key:"_parseG711",value:function(e,t,a){var r=this.audioTrack;r.codecType=7===a?_.G711PCMA:_.G711PCMU,r.sampleRate=8e3,r.codec=r.codecType,r.samples.push(new A(t,e.subarray(1)))}},{key:"_parseAac",value:function(e,t){var a=this.audioTrack;if(a.codecType=_.AAC,0===e[1]){var r=Z.parseAudioSpecificConfig(e.subarray(2));r?(a.codec=r.codec,a.channelCount=r.channelCount,a.sampleRate=r.sampleRate,a.config=r.config,a.objectType=r.objectType,a.sampleRateIndex=r.samplingFrequencyIndex):(a.reset(),ae.warn("Cannot parse AudioSpecificConfig",e))}else if(1===e[1]){if(null==t)return;a.samples.push(new A(t,e.subarray(2)))}else ae.warn("Unknown AACPacketType: ".concat(e[1]))}},{key:"_parseVideo",value:function(e,t){var a=this;if(!(e.length<6)){var r=(240&e[0])>>>4,s=15&e[0],i=this.videoTrack;if(7!==s&&12!==s)return i.reset(),void ae.warn("Unsupported codecId: ".concat(s));var n=12===s;i.codecType=n?b.HEVC:b.AVC;var o=e[1],u=(e[2]<<16|e[3]<<8|e[4])<<8>>8;if(0===o){var c=e.subarray(5),l=n?Q.parseHEVCDecoderConfigurationRecord(c):Y.parseAVCDecoderConfigurationRecord(c);if(l){var d=l.hvcC,f=l.sps,h=l.ppsArr,p=l.spsArr,v=l.vpsArr,y=l.nalUnitSize;d&&(i.hvcC=i.hvcC||d),f&&(i.codec=f.codec,i.width=f.width,i.height=f.height,i.sarRatio=f.sarRatio,i.fpsNum=f.fpsNum,i.fpsDen=f.fpsDen),p.length&&(i.sps=p),h.length&&(i.pps=h),v&&v.length&&(i.vps=v),y&&(i.nalUnitSize=y)}else ae.warn("Cannot parse ".concat(n?"HEVC":"AVC","DecoderConfigurationRecord"),e)}else if(1===o){var m=X.parseAvcC(e.subarray(5),i.nalUnitSize);if((m=this._checkAddMetaNalToUnits(n,m,i))&&m.length){var g=new S(t+u,t,m);1===r&&g.setToKeyframe(),i.samples.push(g),m.forEach((function(e){var r=n?e[0]>>>1&63:31&e[0];switch(r){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!n&&5!==r||n&&5===r)break;g.setToKeyframe();break;case 6:case 39:case 40:if(!n&&6!==r||n&&6===r)break;a.metadataTrack.seiSamples.push(new E(X.parseSEI(X.removeEPB(e)),t+u))}})),g.keyframe&&this._gopId++,g.gopId=this._gopId}else ae.warn("Cannot parse NALUs",e)}else 2===o||ae.warn("Unknown AVCPacketType: ".concat(o))}}},{key:"_checkAddMetaNalToUnits",value:function(e,t,a){return e&&this._needAddMetaBeforeKeyFrameNal?t.map((function(e){return e[0]>>>1&63})).includes(32)?(this._needAddMetaBeforeKeyFrameNal=!1,t):(t.unshift(a.pps[0]),t.unshift(a.sps[0]),t.unshift(a.vps[0]),t.filter(Boolean)):(this._needAddMetaBeforeKeyFrameNal=!1,t)}},{key:"_parseScript",value:function(e,t){this.metadataTrack.flvScriptSamples.push(new j(te.parse(e),t))}}],[{key:"probe",value:function(e){return 70===e[0]&&76===e[1]&&86===e[2]&&1===e[3]&&G(e,5)>=9}}]),e}();i(re,"AUDIO_RATE",[5500,11e3,22e3,44e3]);var se=Object.freeze(Object.defineProperty({__proto__:null,FlvDemuxer:re},Symbol.toStringTag,{value:"Module"})),ie=9e4,ne=45e4,oe=9e4,ue=function(){function e(t,r,s){a(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=s,this._baseDts=-1,this._baseDtsInited=!1,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=!1,this._videoTimestampBreak=!1,this._lastAudioExceptionGapDot=0,this._lastAudioExceptionOverlapDot=0,this._lastAudioExceptionLargeGapDot=0}return s(e,[{key:"fix",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=Math.round(9e4*t);var s=this.videoTrack,i=this.audioTrack,n=s.samples,o=i.samples;if(n.length||o.length){var u=n[0],c=o[0],l=0;if(n.length&&o.length&&(l=u.dts-c.pts),this._baseDtsInited||this._calculateBaseDts(this.audioTrack,this.videoTrack),a&&(this._calculateBaseDts(this.audioTrack,this.videoTrack),this._baseDts-=t),!r){this._videoNextDts=l>0?t+l:t,this._audioNextPts=l>0?t:t-l;var d=u?u.dts-this._baseDts-this._videoNextDts:0,f=c?c.pts-this._baseDts-this._audioNextPts:0;Math.abs(d||f)>oe&&(this._calculateBaseDts(this.audioTrack,this.videoTrack),this._baseDts-=t)}if(this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(i),this._fixVideo(s),this.metadataTrack.exist()){var h=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/h}))}s.samples.length&&(s.baseMediaDecodeTime=s.samples[0].dts),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts*i.timescale/9e4)}}},{key:"_fixVideo",value:function(e){var t=this,a=e.samples;if(a.length){if(a.forEach((function(e){e.dts-=t._baseDts,e.pts-=t._baseDts})),void 0===this._videoNextDts){var r=a[0];this._videoNextDts=r.dts}var s,i,n=a.length,o=0,u=a[0],c=a[1],l=this._videoNextDts-u.dts;if(Math.abs(l)>45e3)u.dts+=l,u.pts+=l,e.warnings.push({type:x.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts,firstSampleDts:u.dts,nextSampleDts:null===(s=a[1])||void 0===s?void 0:s.dts,sampleDuration:l}),c&&Math.abs(c.dts-u.dts)>oe&&(this._videoTimestampBreak=!0,a.forEach((function(e,t){0!==t&&(e.dts+=l,e.pts+=l)})));if(e.fpsNum&&e.fpsDen)i=e.timescale*(e.fpsDen/e.fpsNum);else{var d=e.samples[0],f=e.samples[n-1];i=1===n?9e3:Math.floor((f.dts-d.dts)/(n-1))}for(var h=0;h<n;h++){var p=a[h].dts,v=a[h+1];if((o=h<n-1?v.dts-p:a[h-1]?Math.min(p-a[h-1].dts,i):i)>oe||o<0){this._videoTimestampBreak=!0,o=this._audioTimestampBreak?i:Math.max(o,2700);var y=this._audioNextPts||0;v&&v.dts>y&&(o=i),e.warnings.push({type:x.LARGE_VIDEO_GAP,time:p/e.timescale,dts:p,originDts:a[h].originDts,nextDts:this._videoNextDts,sampleDuration:o,refSampleDuration:i})}a[h].duration=o,this._videoNextDts+=o}}}},{key:"_fixAudio",value:function(e){var t=this,a=e.samples;a.length&&(a.forEach((function(e){e.pts-=t._baseDts,e.dts=e.pts})),this._doFixAudioInternal(e,a,9e4))}},{key:"_calculateBaseDts",value:function(e,t){var a=e.samples,r=t.samples;if(!a.length&&!r.length)return!1;var s=1/0,i=1/0;a.length&&(e.baseDts=s=a[0].pts),r.length&&(t.baseDts=i=r[0].dts),this._baseDts=Math.min(s,i);var n=i-s;return Number.isFinite(n)&&Math.abs(n)>45e3&&t.warnings.push({type:x.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){if(this._baseDtsInited&&this._videoTimestampBreak&&this._audioTimestampBreak){if(!this._calculateBaseDts(this.audioTrack,this.videoTrack))return;this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts),this._audioLastSample=null,this._videoLastSample=null,this._videoTimestampBreak=!1,this._audioTimestampBreak=!1}}},{key:"_doFixAudioInternal",value:function(e,t,a){e.sampleDuration||(e.sampleDuration=Z.getFrameDuration(e.timescale,a));var r=e.sampleDuration;if(void 0===this._audioNextPts){var s=t[0];this._audioNextPts=s.pts}for(var i=0;i<t.length;i++){var n=this._audioNextPts,o=t[i],u=o.pts-n;if(!this._audioTimestampBreak&&u>=3*r&&u<=ie&&!z){var c=Z.getSilentFrame(e.codec,e.channelCount)||t[0].data.subarray(),l=Math.floor(u/r);Math.abs(o.pts-this._lastAudioExceptionGapDot)>ne&&(this._lastAudioExceptionGapDot=o.pts),e.warnings.push({type:x.AUDIO_FILLED,pts:o.pts,originPts:o.originPts,count:l,nextPts:n,refSampleDuration:r});for(var d=0;d<l;d++){var f=new A(Math.floor(n),c);f.originPts=Math.floor(this._baseDts+n),t.splice(i,0,f),this._audioNextPts+=r,i++}i--}else u<=-3*r&&u>=-9e4?(Math.abs(o.pts-this._lastAudioExceptionOverlapDot)>ne&&(this._lastAudioExceptionOverlapDot=o.pts,e.warnings.push({type:x.AUDIO_DROPPED,pts:o.pts,originPts:o.originPts,nextPts:n,refSampleDuration:r})),t.splice(i,1),i--):(Math.abs(u)>=ie&&(this._audioTimestampBreak=!0,Math.abs(o.pts-this._lastAudioExceptionLargeGapDot)>ne&&(this._lastAudioExceptionLargeGapDot=o.pts,e.warnings.push({type:x.LARGE_AUDIO_GAP,time:o.pts/1e3,pts:o.pts,originPts:o.originPts,nextPts:n,sampleDuration:u,refSampleDuration:r}))),o.dts=o.pts=n,this._audioNextPts+=r)}}}]),e}(),ce=new U("TsDemuxer"),le=function(){function e(t,r,s){a(this,e),i(this,"_pmtId",-1),i(this,"_remainingPacketData",null),i(this,"_videoPesData",[]),i(this,"_audioPesData",[]),i(this,"_gopId",0),this.videoTrack=t||new w,this.audioTrack=r||new D,this.metadataTrack=s||new B,this._fixer=new ue(this.videoTrack,this.audioTrack,this.metadataTrack)}return s(e,[{key:"demux",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=this.audioTrack,s=this.videoTrack,i=this.metadataTrack;t&&(this._pmtId=-1,s.reset(),r.reset(),i.reset()),!a||t?(this._remainingPacketData=null,this._videoPesData=[],this._audioPesData=[]):(s.samples=[],r.samples=[],i.seiSamples=[],s.warnings=[],r.warnings=[],this._remainingPacketData&&(e=L(this._remainingPacketData,e),this._remainingPacketData=null));var n=e.length,o=n%188;o&&(this._remainingPacketData=e.subarray(n-o),n-=o);for(var u=s.pid,c=r.pid,l=0;l<n;l+=188){if(71!==e[l])throw new Error("TS packet did not start with 0x47");var d=!!(64&e[l+1]),f=((31&e[l+1])<<8)+e[l+2],h=(48&e[l+3])>>4,p=void 0;if(h>1){if((p=l+5+e[l+4])===l+188)continue}else p=l+4;switch(f){case 0:d&&(p+=e[p]+1),this._pmtId=(31&e[p+10])<<8|e[p+11];break;case this._pmtId:d&&(p+=e[p]+1);var v=p+3+((15&e[p+1])<<8|e[p+2])-4,y=(15&e[p+10])<<8|e[p+11];for(p+=12+y;p<v;){var m=(31&e[p+1])<<8|e[p+2];switch(e[p]){case 15:r.pid=c=m;break;case 27:if(-1!==u)break;s.codecType=b.AVC,s.pid=u=m;break;case 36:if(-1!==u)break;s.codecType=b.HEVC,s.pid=u=m;break;default:ce.warn("Unsupported stream. type: ".concat(e[p],", pid: ").concat(m))}p+=5+((15&e[p+3])<<8|e[p+4])}break;case u:d&&this._videoPesData.length&&this._parseVideoData(),this._videoPesData.push(e.subarray(p,l+188));break;case c:d&&this._audioPesData.length&&this._parseAudioData(),this._audioPesData.push(e.subarray(p,l+188));break;case 17:case 8191:break;default:ce.warn("Unknown pid: ".concat(f))}}return this._parseVideoData(),this._parseAudioData(),r.formatTimescale=s.formatTimescale=s.timescale=i.timescale=9e4,r.timescale=r.sampleRate||0,{videoTrack:s,audioTrack:r,metadataTrack:i}}},{key:"fix",value:function(e,t,a){return this._fixer.fix(e,t,a),{videoTrack:this.videoTrack,audioTrack:this.audioTrack,metadataTrack:this.metadataTrack}}},{key:"demuxAndFix",value:function(e,t,a,r){return this.demux(e,t,a),this.fix(r,t,a)}},{key:"_parseVideoData",value:function(){if(this._videoPesData.length){var t=e._parsePES(L.apply(void 0,y(this._videoPesData)));if(t){var a=X.parseAnnexB(t.data);a?this._createVideoSample(a,t.pts,t.dts):ce.warn("Cannot parse avc units",t),this._videoPesData=[]}else ce.warn("Cannot parse video pes",this._videoPesData)}}},{key:"_createVideoSample",value:function(e,t,a){var r=this;if(e.length){var s=this.videoTrack,i=s.codecType===b.HEVC,n=new S(t,a);e.forEach((function(e){var a=i?e[0]>>>1&63:31&e[0];switch(a){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!i&&5!==a||i&&5===a)break;n.setToKeyframe(),r._gopId++;break;case 6:case 39:case 40:if(!i&&6!==a||i&&6===a)break;return void r.metadataTrack.seiSamples.push(new E(X.parseSEI(X.removeEPB(e)),t));case 32:if(!i)break;if(!s.vps.length){var o=Q.parseVPS(X.removeEPB(e),s.hvcC);s.hvcC=s.hvcC||o,s.vps=[e]}break;case 7:case 33:if(!i&&7!==a||i&&7===a)break;if(!s.sps.length){var u=X.removeEPB(e),c=i?Q.parseSPS(u,s.hvcC):Y.parseSPS(u);s.sps=[e],s.hvcC=s.hvcC||c.hvcC,s.codec=c.codec,s.width=c.width,s.height=c.height,s.sarRatio=c.sarRatio,s.fpsNum=c.fpsNum,s.fpsDen=c.fpsDen}break;case 8:case 34:if(!i&&8!==a||i&&8===a)break;s.pps.length||(s.pps=[e])}n.units.push(e)})),n.gopId=this._gopId,this._pushVideoSample(s,n)}}},{key:"_pushVideoSample",value:function(e,t){if(t.units.length)if(null===t.pts||void 0===t.pts){ce.warn("Video sample no pts",t);var a=e.samples[e.samples.length-1];a?(t.pts=a.pts,t.dts=a.dts):ce.warn("Drop video sample",t)}else e.samples.push(t)}},{key:"_parseAudioData",value:function(){if(this._audioPesData.length){var t=e._parsePES(L.apply(void 0,y(this._audioPesData)));t?(this._parseAacData(t),this._audioPesData=[]):ce.warn("Cannot parse audio pes",this._audioPesData)}}},{key:"_parseAacData",value:function(e){var t=this.audioTrack,a=e.pts;if(null==a){if(ce.warn("AAC pes not pts",t),!t.samples.length||!t.sampleRate)return;a=t.samples[t.samples.length-1].pts+Z.getFrameDuration(t.sampleRate)}var r,s=Z.parseADTS(e.data,a);s?(t.codec=s.codec,t.channelCount=s.channelCount,t.sampleRate=s.sampleRate,t.objectType=s.objectType,t.sampleRateIndex=s.samplingFrequencyIndex,t.config=s.config,(r=t.samples).push.apply(r,y(s.frames.map((function(e){return new A(e.pts,e.data)})))),s.skip&&ce.warn("Skip aac adts ".concat(s.skip," bits")),s.remaining&&ce.warn("Remaining aac adts ".concat(s.remaining," bits"))):ce.warn("Cannot parse aac adts",e)}}],[{key:"probe",value:function(e){return!!e.length&&(71===e[0]&&71===e[188]&&71===e[376])}},{key:"_parsePES",value:function(e){var t=e[8];if(!(null==t||e.length<t+9)&&1===(e[0]<<16|e[1]<<8|e[2])){var a=(e[4]<<8)+e[5];if(!(a&&a>e.length-6)){var r,s,i=e[7];return 192&i&&(r=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&i?r-(s=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(r=s):s=r),{data:e.subarray(9+t),pts:r,dts:s}}}}}]),e}(),de=Object.freeze(Object.defineProperty({__proto__:null,TsDemuxer:le},Symbol.toStringTag,{value:"Module"})),fe=function(){function e(){a(this,e)}return s(e,null,[{key:"findBox",value:function(t,a){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=[];if(!t)return s;for(var i=0,n="",o=0;t.length>7;){if(i=G(t),n=String.fromCharCode.apply(null,t.subarray(4,8)),o=8,1===i?(i=q(t,8),o+=8):i||(i=t.length),!a[0]||n===a[0]){var u=t.subarray(0,i);if(!(a.length<2))return e.findBox(u.subarray(o),a.slice(1),r+o);s.push({start:r,size:i,headerSize:o,type:n,data:u})}r+=i,t=t.subarray(i)}return s}},{key:"tfhd",value:function(e){return ye(e,!0,(function(e,t){e.trackId=G(t);var a=4,r=1&e.flags,s=2&e.flags,i=8&e.flags,n=16&e.flags,o=32&e.flags;r&&(a+=4,e.baseDataOffset=G(t,a),a+=4),s&&(e.sampleDescriptionIndex=G(t,a),a+=4),i&&(e.defaultSampleDuration=G(t,a),a+=4),n&&(e.defaultSampleSize=G(t,a),a+=4),o&&(e.defaultSampleFlags=G(t,a))}))}},{key:"sidx",value:function(e){return ye(e,!0,(function(e,t){var a=0;e.reference_ID=G(t,a),a+=4,e.timescale=G(t,a),a+=4,0===e.version?(e.earliest_presentation_time=G(t,a),a+=4,e.first_offset=G(t,a),a+=4):(e.earliest_presentation_time=q(t,a),a+=8,e.first_offset=q(t,a),a+=8),a+=2,e.references=[];var r=F(t,a);a+=2;for(var s=0;s<r;s++){var i={};e.references.push(i);var n=G(t,a);a+=4,i.reference_type=n>>31&1,i.referenced_size=2147483647&n,i.subsegment_duration=G(t,a),n=G(t,a+=4),a+=4,i.starts_with_SAP=n>>31&1,i.SAP_type=n>>28&7,i.SAP_delta_time=268435455&n}}))}},{key:"moov",value:function(t){return ye(t,!1,(function(t,a,r){t.mvhd=e.mvhd(e.findBox(a,["mvhd"],r)[0]),t.trak=e.findBox(a,["trak"],r).map((function(t){return e.trak(t)})),t.pssh=e.pssh(e.findBox(a,["pssh"],r)[0])}))}},{key:"mvhd",value:function(e){return ye(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=G(t,16),e.duration=q(t,20),a+=28):(e.timescale=G(t,8),e.duration=G(t,12),a+=16),e.nextTrackId=G(t,a+76)}))}},{key:"trak",value:function(t){return ye(t,!1,(function(t,a,r){t.tkhd=e.tkhd(e.findBox(a,["tkhd"],r)[0]),t.mdia=e.mdia(e.findBox(a,["mdia"],r)[0])}))}},{key:"tkhd",value:function(e){return ye(e,!0,(function(e,t){var a=0;1===e.version?(e.trackId=G(t,16),e.duration=q(t,24),a+=32):(e.trackId=G(t,8),e.duration=G(t,16),a+=20),e.width=G(t,a+52),e.height=G(t,a+56)}))}},{key:"mdia",value:function(t){return ye(t,!1,(function(t,a,r){t.mdhd=e.mdhd(e.findBox(a,["mdhd"],r)[0]),t.hdlr=e.hdlr(e.findBox(a,["hdlr"],r)[0]),t.minf=e.minf(e.findBox(a,["minf"],r)[0])}))}},{key:"mdhd",value:function(e){return ye(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=G(t,16),e.duration=q(t,20),a+=28):(e.timescale=G(t,8),e.duration=G(t,12),a+=16);var r=F(t,a);e.language=String.fromCharCode(96+(r>>10&31),96+(r>>5&31),96+(31&r))}))}},{key:"hdlr",value:function(e){return ye(e,!0,(function(e,t){0===e.version&&(e.handlerType=String.fromCharCode.apply(null,t.subarray(4,8)))}))}},{key:"minf",value:function(t){return ye(t,!1,(function(t,a,r){t.vmhd=e.vmhd(e.findBox(a,["vmhd"],r)[0]),t.smhd=e.smhd(e.findBox(a,["smhd"],r)[0]),t.stbl=e.stbl(e.findBox(a,["stbl"],r)[0])}))}},{key:"vmhd",value:function(e){return ye(e,!0,(function(e,t){e.graphicsmode=F(t),e.opcolor=[F(t,2),F(t,4),F(t,6)]}))}},{key:"smhd",value:function(e){return ye(e,!0,(function(e,t){e.balance=F(t)}))}},{key:"stbl",value:function(t){return ye(t,!1,(function(t,a,r){var s,i,n;t.stsd=e.stsd(e.findBox(a,["stsd"],r)[0]),t.stts=e.stts(e.findBox(a,["stts"],r)[0]),t.ctts=e.ctts(e.findBox(a,["ctts"],r)[0]),t.stsc=e.stsc(e.findBox(a,["stsc"],r)[0]),t.stsz=e.stsz(e.findBox(a,["stsz"],r)[0]),t.stco=e.stco(e.findBox(a,["stco"],r)[0]),t.stco||(t.co64=e.co64(e.findBox(a,["co64"],r)[0]),t.stco=t.co64);var o=null===(s=t.stsd.entries[0])||void 0===s||null===(i=s.sinf)||void 0===i||null===(n=i.schi)||void 0===n?void 0:n.tenc.default_IV_size;t.stss=e.stss(e.findBox(a,["stss"],r)[0]),t.senc=e.senc(e.findBox(a,["senc"],r)[0],o)}))}},{key:"senc",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8;return ye(e,!0,(function(e,a){var r=0,s=G(a,r);r+=4,e.samples=[];for(var i=0;i<s;i++){for(var n={InitializationVector:[]},o=0;o<t;o++)n.InitializationVector[o]=a[r+o];if(r+=t,2&e.flags){n.subsamples=[];var u=F(a,r);r+=2;for(var c=0;c<u;c++){var l={};l.BytesOfClearData=F(a,r),r+=2,l.BytesOfProtectedData=G(a,r),r+=4,n.subsamples.push(l)}}e.samples.push(n)}}))}},{key:"pssh",value:function(e){return ye(e,!0,(function(e,t){for(var a=[],r=[],s=0,i=0;i<16;i++)r.push(ge(t[s+i]));if(s+=16,e.version>0){var n=G(t,s);s+=4;for(var o=0;o<(""+n).length;o++)for(var u=0;u<16;u++){var c=t[s];s+=1,a.push(ge(c))}}var l=G(t,s);e.data_size=l,s+=4,e.kid=a,e.system_id=r,e.buffer=t}))}},{key:"stsd",value:function(t){return ye(t,!0,(function(t,a,r){t.entryCount=G(a),t.entries=e.findBox(a.subarray(4),[],r+4).map((function(t){switch(t.type){case"avc1":case"avc2":case"avc3":case"avc4":return e.avc1(t);case"hvc1":case"hev1":return e.hvc1(t);case"mp4a":return e.mp4a(t);case"alaw":case"ulaw":return e.alaw(t);case"enca":return ye(t,!1,(function(t,a,r){t.channelCount=F(a,16),t.samplesize=F(a,18),t.sampleRate=G(a,24)/65536,a=a.subarray(28),t.sinf=e.sinf(e.findBox(a,["sinf"],r)[0]),t.esds=e.esds(e.findBox(a,["esds"],r)[0])}));case"encv":return ye(t,!1,(function(t,a,r){t.width=F(a,24),t.height=F(a,26),t.horizresolution=G(a,28),t.vertresolution=G(a,32),a=a.subarray(78),t.sinf=e.sinf(e.findBox(a,["sinf"],r)[0]),t.avcC=e.avcC(e.findBox(a,["avcC"],r)[0]),t.hvcC=e.hvcC(e.findBox(a,["hvcC"],r)[0]),t.pasp=e.pasp(e.findBox(a,["pasp"],r)[0])}))}})).filter(Boolean)}))}},{key:"tenc",value:function(e){return ye(e,!1,(function(e,t){var a=6;e.default_IsEncrypted=t[a],a+=1,e.default_IV_size=t[a],a+=1,e.default_KID=[];for(var r=0;r<16;r++)e.default_KID.push(ge(t[a])),a+=1}))}},{key:"schi",value:function(t){return ye(t,!1,(function(t,a,r){t.tenc=e.tenc(e.findBox(a,["tenc"],r)[0])}))}},{key:"sinf",value:function(t){return ye(t,!1,(function(t,a,r){t.schi=e.schi(e.findBox(a,["schi"],r)[0]),t.frma=e.frma(e.findBox(a,["frma"],r)[0])}))}},{key:"frma",value:function(e){return ye(e,!1,(function(e,t){e.data_format="";for(var a=0;a<4;a++)e.data_format+=String.fromCharCode(t[a])}))}},{key:"avc1",value:function(t){return ye(t,!1,(function(t,a,r){var s=pe(t,a),i=a.subarray(s);r+=s,t.avcC=e.avcC(e.findBox(i,["avcC"],r)[0]),t.pasp=e.pasp(e.findBox(i,["pasp"],r)[0])}))}},{key:"avcC",value:function(e){return ye(e,!1,(function(e,t){e.configurationVersion=t[0],e.AVCProfileIndication=t[1],e.profileCompatibility=t[2],e.AVCLevelIndication=t[3],e.codec=H([t[1],t[2],t[3]]),e.lengthSizeMinusOne=3&t[4],e.spsLength=31&t[5],e.sps=[];for(var a=6,r=0;r<e.spsLength;r++){var s=F(t,a);a+=2,e.sps.push(t.subarray(a,a+s)),a+=s}e.ppsLength=t[a],a+=1,e.pps=[];for(var i=0;i<e.ppsLength;i++){var n=F(t,a);a+=2,e.pps.push(t.subarray(a,a+=n)),a+=n}}))}},{key:"hvc1",value:function(t){return ye(t,!1,(function(t,a,r){var s=pe(t,a),i=a.subarray(s);r+=s,t.hvcC=e.hvcC(e.findBox(i,["hvcC"],r)[0]),t.pasp=e.pasp(e.findBox(i,["pasp"],r)[0])}))}},{key:"hvcC",value:function(e){return ye(e,!1,(function(t,a){t.data=e.data,t.codec="hev1.1.6.L93.B0",t.configurationVersion=a[0];var r=a[1];t.generalProfileSpace=r>>6,t.generalTierFlag=(32&r)>>5,t.generalProfileIdc=31&r,t.generalProfileCompatibility=G(a,2),t.generalConstraintIndicatorFlags=a.subarray(6,12),t.generalLevelIdc=a[12],t.avgFrameRate=F(a,19),t.numOfArrays=a[22],t.vps=[],t.sps=[],t.pps=[];for(var s=23,i=0,n=0,o=0,u=0;u<t.numOfArrays;u++){i=63&a[s],n=F(a,s+1),s+=3;for(var c,l=[],d=0;d<n;d++)o=F(a,s),s+=2,l.push(a.subarray(s,s+o)),s+=o;if(32===i)(c=t.vps).push.apply(c,l);else if(33===i){var f;(f=t.sps).push.apply(f,l)}else if(34===i){var h;(h=t.pps).push.apply(h,l)}}}))}},{key:"pasp",value:function(e){return ye(e,!1,(function(e,t){e.hSpacing=G(t),e.vSpacing=G(t,4)}))}},{key:"mp4a",value:function(t){return ye(t,!1,(function(t,a,r){var s=ve(t,a);t.esds=e.esds(e.findBox(a.subarray(s),["esds"],r+s)[0])}))}},{key:"esds",value:function(e){return ye(e,!0,(function(e,t){e.codec="mp4a.";for(var a=0,r=0,s=0,i=0;t.length;){for(i=t[a=0],r=t[a+1],a+=2;128&r;)s=(127&r)<<7,r=t[a],a+=1;if(s+=127&r,3===i)t=t.subarray(a+3);else{if(4!==i){if(5===i){var n=e.config=t.subarray(a,a+s),o=(248&n[0])>>3;return 31===o&&n.length>=2&&(o=32+((7&n[0])<<3)+((224&n[1])>>5)),e.objectType=o,e.codec+=o.toString(16),void("."===e.codec[e.codec.length-1]&&(e.codec=e.codec.substring(0,e.codec.length-1)))}return void("."===e.codec[e.codec.length-1]&&(e.codec=e.codec.substring(0,e.codec.length-1)))}e.codec+=(t[a].toString(16)+".").padStart(3,"0"),t=t.subarray(a+13)}}}))}},{key:"alaw",value:function(e){return ye(e,!1,(function(e,t){ve(e,t)}))}},{key:"stts",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push({count:G(t,s),delta:G(t,s+4)}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"ctts",value:function(e){return ye(e,!0,(function(e,t){var a=G(t),r=[],s=4;if(1===e.version)for(var i=0;i<a;i++)r.push({count:G(t,s),offset:G(t,s+4)}),s+=8;else for(var n=0;n<a;n++)r.push({count:G(t,s),offset:-(1+~G(t,s+4))}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stsc",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push({firstChunk:G(t,s),samplesPerChunk:G(t,s+4),sampleDescriptionIndex:G(t,s+8)}),s+=12;e.entryCount=a,e.entries=r}))}},{key:"stsz",value:function(e){return ye(e,!0,(function(e,t){var a=G(t),r=G(t,4),s=[];if(!a)for(var i=8,n=0;n<r;n++)s.push(G(t,i)),i+=4;e.sampleSize=a,e.sampleCount=r,e.entrySizes=s}))}},{key:"stco",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push(G(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"co64",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push(q(t,s)),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stss",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push(G(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"moof",value:function(t){return ye(t,!1,(function(t,a,r){t.mfhd=e.mfhd(e.findBox(a,["mfhd"],r)[0]),t.traf=e.findBox(a,["traf"],r).map((function(t){return e.traf(t)}))}))}},{key:"mfhd",value:function(e){return ye(e,!0,(function(e,t){e.sequenceNumber=G(t)}))}},{key:"traf",value:function(t){return ye(t,!1,(function(t,a,r){t.tfhd=e.tfhd(e.findBox(a,["tfhd"],r)[0]),t.tfdt=e.tfdt(e.findBox(a,["tfdt"],r)[0]),t.trun=e.trun(e.findBox(a,["trun"],r)[0])}))}},{key:"trun",value:function(e){return ye(e,!0,(function(e,t){var a=e.version,r=e.flags,s=t.length,i=e.sampleCount=G(t),n=4;if(s>n&&1&r&&(e.dataOffset=-(1+~G(t,n)),n+=4),s>n&&4&r&&(e.firstSampleFlags=G(t,n),n+=4),e.samples=[],s>n)for(var o,u=0;u<i;u++)o={},256&r&&(o.duration=G(t,n),n+=4),512&r&&(o.size=G(t,n),n+=4),1024&r&&(o.flags=G(t,n),n+=4),2048&r&&(o.cts=a?-(1+~G(t,n+4)):G(t,n),n+=4),e.samples.push(o)}))}},{key:"tfdt",value:function(e){return ye(e,!0,(function(e,t){1===e.version?e.baseMediaDecodeTime=q(t):e.baseMediaDecodeTime=G(t)}))}},{key:"probe",value:function(t){return!!e.findBox(t,["ftyp"])}},{key:"parseSampleFlags",value:function(e){return{isLeading:(12&e[0])>>>2,dependsOn:3&e[0],isDependedOn:(192&e[1])>>>6,hasRedundancy:(48&e[1])>>>4,paddingValue:(14&e[1])>>>1,isNonSyncSample:1&e[1],degradationPriority:e[2]<<8|e[3]}}},{key:"moovToTrack",value:function(e,t,a){var r,s,i=e.trak;if(i&&i.length){var n=i.find((function(e){var t,a;return"vide"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)})),o=i.find((function(e){var t,a;return"soun"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)}));if(n&&t){var u,c,l,d,f,h,p,v=t,y=null===(u=n.tkhd)||void 0===u?void 0:u.trackId;null!=y&&(v.id=n.tkhd.trackId),v.tkhdDuration=n.tkhd.duration,v.mvhdDurtion=e.mvhd.duration,v.mvhdTimecale=e.mvhd.timescale,v.timescale=v.formatTimescale=n.mdia.mdhd.timescale,v.duration=n.mdia.mdhd.duration||v.mvhdDurtion/v.mvhdTimecale*v.timescale;var m,g,k,x,w,D,S,A,T=n.mdia.minf.stbl.stsd.entries[0];if(v.width=T.width,v.height=T.height,T.pasp&&(v.sarRatio=[T.pasp.hSpacing,T.pasp.vSpacing]),T.hvcC)v.codecType=b.HEVC,v.codec=T.hvcC.codec,v.vps=T.hvcC.vps,v.sps=T.hvcC.sps,v.pps=T.hvcC.pps,v.hvcC=T.hvcC.data;else{if(!T.avcC)throw new Error("unknown video stsd entry");v.codec=T.avcC.codec,v.sps=T.avcC.sps,v.pps=T.avcC.pps}if(v.present=!0,v.ext={},v.ext.stss=null===(c=n.mdia)||void 0===c||null===(l=c.minf)||void 0===l||null===(d=l.stbl)||void 0===d?void 0:d.stss,v.ext.ctts=null===(f=n.mdia)||void 0===f||null===(h=f.minf)||void 0===h||null===(p=h.stbl)||void 0===p?void 0:p.ctts,T&&"encv"===T.type)v.isVideoEncryption=!0,T.default_KID=null===(m=T.sinf)||void 0===m||null===(g=m.schi)||void 0===g?void 0:g.tenc.default_KID,T.default_IsEncrypted=null===(k=T.sinf)||void 0===k||null===(x=k.schi)||void 0===x?void 0:x.tenc.default_IsEncrypted,T.default_IV_size=null===(w=T.sinf)||void 0===w||null===(D=w.schi)||void 0===D?void 0:D.tenc.default_IV_size,v.videoSenc=n.mdia.minf.stbl.senc&&n.mdia.minf.stbl.senc.samples,T.data_format=null===(S=T.sinf)||void 0===S||null===(A=S.frma)||void 0===A?void 0:A.data_format,v.useEME=e.useEME,v.kidValue=e.kidValue,v.pssh=e.pssh,v.encv=T}if(o&&a){var j,E,B,C,P,U,I,M,O,z=a,R=null===(j=o.tkhd)||void 0===j?void 0:j.trackId;null!=R&&(z.id=o.tkhd.trackId),z.tkhdDuration=o.tkhd.duration,z.mvhdDurtion=e.mvhd.duration,z.mvhdTimecale=e.mvhd.timescale,z.timescale=z.formatTimescale=o.mdia.mdhd.timescale,z.duration=o.mdia.mdhd.duration||z.mvhdDurtion/z.mvhdTimecale*z.timescale;var V,L,N,F,G,q,H,K,W=o.mdia.minf.stbl.stsd.entries[0];switch(z.sampleSize=W.sampleSize,z.sampleRate=W.sampleRate,z.channelCount=W.channelCount,z.present=!0,W.type){case"alaw":z.codecType=z.codec=_.G711PCMA,z.sampleRate=8e3;break;case"ulaw":z.codecType=z.codec=_.G711PCMU,z.sampleRate=8e3;break;default:z.sampleDuration=Z.getFrameDuration(z.sampleRate,z.timescale),z.sampleRateIndex=Z.getRateIndexByRate(z.sampleRate),z.objectType=(null===(r=W.esds)||void 0===r?void 0:r.objectType)||2,W.esds&&(z.config=Array.from(W.esds.config)),z.codec=(null===(s=W.esds)||void 0===s?void 0:s.codec)||"mp4a.40.2"}if(z.sampleDuration=Z.getFrameDuration(z.sampleRate,z.timescale),z.objectType=(null===(E=W.esds)||void 0===E?void 0:E.objectType)||2,W.esds&&(W.esds.config?z.config=Array.from(W.esds.config):console.warn("esds config is null")),z.codec=(null===(B=W.esds)||void 0===B?void 0:B.codec)||"mp4a.40.2",z.sampleRateIndex=Z.getRateIndexByRate(z.sampleRate),z.ext={},z.ext.stss=null===(C=o.mdia)||void 0===C||null===(P=C.minf)||void 0===P||null===(U=P.stbl)||void 0===U?void 0:U.stss,z.ext.ctts=null===(I=o.mdia)||void 0===I||null===(M=I.minf)||void 0===M||null===(O=M.stbl)||void 0===O?void 0:O.ctts,z.present=!0,W&&"enca"===W.type)z.isAudioEncryption=!0,W.data_format=null===(V=W.sinf)||void 0===V||null===(L=V.frma)||void 0===L?void 0:L.data_format,W.default_KID=null===(N=W.sinf)||void 0===N||null===(F=N.schi)||void 0===F?void 0:F.tenc.default_KID,W.default_IsEncrypted=null===(G=W.sinf)||void 0===G||null===(q=G.schi)||void 0===q?void 0:q.tenc.default_IsEncrypted,W.default_IV_size=null===(H=W.sinf)||void 0===H||null===(K=H.schi)||void 0===K?void 0:K.tenc.default_IV_size,z.audioSenc=o.mdia.minf.stbl.senc&&o.mdia.minf.stbl.senc.samples,z.useEME=e.useEME,z.kidValue=e.kidValue,z.enca=W}if(a&&(a.isVideoEncryption=!!t&&t.isVideoEncryption),t&&(t.isAudioEncryption=!!a&&a.isAudioEncryption),null!=t&&t.encv||null!=a&&a.enca){var X,Y,Q=null==t||null===(X=t.encv)||void 0===X?void 0:X.default_KID,J=null==a||null===(Y=a.enca)||void 0===Y?void 0:Y.default_KID,$=Q||J?(Q||J).join(""):null;t&&(t.kid=$),a&&(a.kid=$)}return t&&(t.flags=3841),a&&(a.flags=1793),{videoTrack:t,audioTrack:a}}}},{key:"evaluateDefaultDuration",value:function(e,t,a){var r,s=null==t||null===(r=t.samples)||void 0===r?void 0:r.length;return s?1024*s/t.timescale*e.timescale/a:1024}},{key:"moofToSamples",value:function(t,a,r){var s={};return t.mfhd&&(a&&(a.sequenceNumber=t.mfhd.sequenceNumber),r&&(r.sequenceNumber=t.mfhd.sequenceNumber)),t.traf.forEach((function(t){var i=t.tfhd,n=t.tfdt,o=t.trun;if(i&&o){n&&(a&&a.id===i.trackId&&(a.baseMediaDecodeTime=n.baseMediaDecodeTime),r&&r.id===i.trackId&&(r.baseMediaDecodeTime=n.baseMediaDecodeTime));var u=i.defaultSampleSize||0,c=i.defaultSampleDuration||e.evaluateDefaultDuration(a,r,o.samples.length||o.sampleCount),l=o.dataOffset||0,d=0,f=-1;if(!o.samples.length&&o.sampleCount){s[i.trackId]=[];for(var h=0;h<o.sampleCount;h++)s[i.trackId].push({offset:l,dts:d,duration:c,size:u}),d+=c,l+=u}else s[i.trackId]=o.samples.map((function(e,t){return(e={offset:l,dts:d,pts:d+(e.cts||0),duration:e.duration||c,size:e.size||u,gopId:f,keyframe:0===t||null!==e.flags&&void 0!==e.flags&&(65536&e.flags)>>>0!=65536}).keyframe&&(f++,e.gopId=f),d+=e.duration,l+=e.size,e}))}})),s}},{key:"moovToSamples",value:function(e){var t=e.trak;if(t&&t.length){var a=t.find((function(e){var t,a;return"vide"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)})),r=t.find((function(e){var t,a;return"soun"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)}));if(a||r){var s,i;if(a){var n,o,u=null===(n=a.mdia)||void 0===n||null===(o=n.minf)||void 0===o?void 0:o.stbl;if(!u)return;var c=u.stts,l=u.stsc,d=u.stsz,f=u.stco,h=u.stss,p=u.ctts;if(!(c&&l&&d&&f&&h))return;s=he(c,l,d,f,p,h)}if(r){var v,y,m,g=null===(v=r.mdia)||void 0===v||null===(y=v.minf)||void 0===y?void 0:y.stbl;if(!g)return;var k=null===(m=r.mdia.mdhd)||void 0===m?void 0:m.timescale,b=g.stts,_=g.stsc,x=g.stsz,w=g.stco;if(!(k&&b&&_&&x&&w))return;i=he(b,_,x,w)}return{videoSamples:s,audioSamples:i}}}}}]),e}();function he(e,t,a,r,s,i){var n,o,u,c=[],l=null==s?void 0:s.entries,d=t.entries,f=r.entries,h=a.entrySizes,p=null==i?void 0:i.entries;p&&(n={},p.forEach((function(e){n[e-1]=!0}))),l&&(o=[],l.forEach((function(e){for(var t=e.count,a=e.offset,r=0;r<t;r++)o.push(a)})));var v=-1,y=0,m=0,g=0,k=0,b=0,_=d[0].samplesPerChunk,x=d[1]?d[1].firstChunk-1:1/0;return e.entries.forEach((function(e){for(var t=e.count,r=e.delta,s=0;s<t;s++)u={dts:y,duration:r,size:h[m]||a.sampleSize,offset:f[g]+b,index:m},p&&(u.keyframe=n[m],u.keyframe&&v++,u.gopId=v),o&&m<o.length&&(u.pts=u.dts+o[m]),c.push(u),y+=r,++m<_?b+=u.size:(g++,b=0,g>=x&&(k++,x=d[k+1]?d[k+1].firstChunk-1:1/0),_+=d[k].samplesPerChunk)})),c}function pe(e,t){return e.dataReferenceIndex=F(t,6),e.width=F(t,24),e.height=F(t,26),e.horizresolution=G(t,28),e.vertresolution=G(t,32),e.frameCount=F(t,40),e.depth=F(t,74),78}function ve(e,t){return e.dataReferenceIndex=F(t,6),e.channelCount=F(t,16),e.sampleSize=F(t,18),e.sampleRate=G(t,24)/65536,28}function ye(e,t,a){if(e){if(e.size!==e.data.length)throw new Error("box ".concat(e.type," size !== data.length"));var r={start:e.start,size:e.size,headerSize:e.headerSize,type:e.type};return t&&(r.version=e.data[e.headerSize],r.flags=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<16)+(e[t+1]<<8)+(e[t+2]||0)}(e.data,e.headerSize+1),r.headerSize+=4),a(r,e.data.subarray(r.headerSize),r.start+r.headerSize),r}}var me=function(e,t,a){for(var r=String(a),s=t>>0,i=Math.ceil(s/r.length),n=[],o=String(e);i--;)n.push(r);return n.join("").substring(0,s-o.length)+o},ge=function(){for(var e=[],t=arguments.length,a=new Array(t),r=0;r<t;r++)a[r]=arguments[r];return a.forEach((function(t){e.push(me(Number(t).toString(16),2,0))})),e[0]},ke=function(){function e(t,r,s){a(this,e),this.videoTrack=t||new w,this.audioTrack=r||new D,this.metadataTrack=s||new B}return s(e,[{key:"demux",value:function(e,t){var a=this.videoTrack,r=this.audioTrack,s=a.exist(),i=r.exist();if(a.samples=[],r.samples=[],t){if(!i){var n=fe.findBox(t,["moov"])[0];if(!n)throw new Error("cannot found moov box");fe.moovToTrack(fe.moov(n),null,r)}var o=fe.findBox(t,["moof"])[0];if(o){var u=fe.moofToSamples(fe.moof(o),null,r)[r.id],c=r.baseMediaDecodeTime;if(u){var l=o.start;u.map((function(e){e.offset+=l;var a=t.subarray(e.offset,e.offset+e.size);r.samples.push(new A(e.dts+c,a,e.duration))}))}}}if(e){if(!s&&!i){var d=fe.findBox(e,["moov"])[0];if(!d)throw new Error("cannot found moov box");fe.moovToTrack(fe.moov(d),a,r)}var f=fe.findBox(e,["moof"])[0];if(f){var h,p=fe.moofToSamples(fe.moof(f),a,r),v=a.baseMediaDecodeTime,y=r.baseMediaDecodeTime,m=f.start;Object.keys(p).forEach((function(t){a.id==t?p[t].map((function(t){t.offset+=m;var r=new S((t.pts||t.dts)+v,t.dts+v);r.duration=t.duration,r.gopId=t.gopId,t.keyframe&&r.setToKeyframe();var s=e.subarray(t.offset,t.offset+t.size);r.data=s;for(var i=0,n=s.length-1;i<n;)h=G(s,i),i+=4,r.units.push(s.subarray(i,i+h)),i+=h;a.samples.push(r)})):r.id==t&&p[t].map((function(t){t.offset+=m;var a=e.subarray(t.offset,t.offset+t.size);r.samples.push(new A(t.dts+y,a,t.duration))}))}))}}return{videoTrack:a,audioTrack:r,metadataTrack:this.metadataTrack}}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset(),this.metadataTrack.reset()}}],[{key:"probe",value:function(e){return fe.probe(e)}}]),e}();function be(e){for(var t=0,a=arguments.length,r=new Array(a>1?a-1:0),s=1;s<a;s++)r[s-1]=arguments[s];r.forEach((function(e){t+=e.length}));var i=new e(t),n=0;return r.forEach((function(e){i.set(e,n),n+=e.length})),i}var _e=function(){function e(){a(this,e),this.buffer=new Uint8Array(0)}return s(e,[{key:"write",value:function(){for(var e=this,t=arguments.length,a=new Array(t),r=0;r<t;r++)a[r]=arguments[r];a.forEach((function(t){t?e.buffer=be(Uint8Array,e.buffer,t):window.console.warn(t)}))}}],[{key:"writeUint16",value:function(e){return new Uint8Array([e>>8&255,255&e])}},{key:"writeUint32",value:function(e){return new Uint8Array([e>>24,e>>16&255,e>>8&255,255&e])}}]),e}(),xe=Math.pow(2,32)-1,we=function(){function e(){a(this,e)}return s(e,null,[{key:"box",value:function(e){for(var t=arguments.length,a=new Array(t>1?t-1:0),r=1;r<t;r++)a[r-1]=arguments[r];var s=8+(a=a.filter(Boolean)).reduce((function(e,t){return e+t.byteLength}),0),i=new Uint8Array(s);i[0]=s>>24&255,i[1]=s>>16&255,i[2]=s>>8&255,i[3]=255&s,i.set(e,4);var n=8;return a.forEach((function(e){i.set(e,n),n+=e.byteLength})),i}},{key:"ftyp",value:function(t){return t.find((function(e){return e.type===k.VIDEO&&e.codecType===b.HEVC}))?e.FTYPHEV1:e.FTYPAVC1}},{key:"initSegment",value:function(t){return L(e.ftyp(t),e.moov(t))}},{key:"pssh",value:function(t){var a=new Uint8Array([1,0,0,0].concat([16,119,239,236,192,178,77,2,172,227,60,30,82,226,251,75],[0,0,0,1],W(t.kid),[0,0,0,0]));return e.box(e.types.pssh,a)}},{key:"moov",value:function(t){if(t[0].useEME&&(t[0].encv||t[0].enca)){t[0].pssh||(t[0].pssh={kid:t[0].kid});var a=this.pssh(t[0].pssh);return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale),e.mvex(t)].concat(y(t.map((function(t){return e.trak(t)}))),[a]))}return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale)].concat(y(t.map((function(t){return e.trak(t)}))),[e.mvex(t)]))}},{key:"mvhd",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4,r=e.box(e.types.mvhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a,t>>24&255,t>>16&255,t>>8&255,255&t,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 r}},{key:"trak",value:function(t){return e.box(e.types.trak,e.tkhd(t.id,t.tkhdDuration||0,t.width,t.height),e.mdia(t))}},{key:"tkhd",value:function(t,a){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t>>24&255,t>>16&255,t>>8&255,255&t,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a,0,0,0,0,0,0,0,0,0,0,0,0,1,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]));return i}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.duration,t.timescale),e.hdlr(t.type),e.minf(t))}},{key:"mdhd",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4,r=e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a,t>>24&255,t>>16&255,t>>8&255,255&t,85,196,0,0]));return r}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"minf",value:function(t){return e.box(e.types.minf,t.type===k.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stbl(t))}},{key:"stbl",value:function(t){var a=[];return t&&t.ext&&t.ext.stss&&a.push(e.stss(t.ext.stss.entries)),e.box(e.types.stbl,e.stsd(t),e.STTS,a[0],e.STSC,e.STSZ,e.STCO)}},{key:"stsd",value:function(t){var a;return a="audio"===t.type?t.useEME&&t.enca?e.enca(t):e.mp4a(t):t.useEME&&t.encv?e.encv(t):e.avc1hev1(t),e.box(e.types.stsd,new Uint8Array([0,0,0,0,0,0,0,1]),a)}},{key:"enca",value:function(t){var a=t.enca.channelCount,r=t.enca.sampleRate,s=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,a,0,16,0,0,0,0,r>>8&255,255&r,0,0]),i=e.esds(t.config),n=e.sinf(t.enca);return e.box(e.types.enca,s,i,n)}},{key:"encv",value:function(t){var a,r,s=t.sps.length>0?t.sps[0]:[],i=t.pps.length>0?t.pps[0]:[],n=t.width,o=t.height,u=t.sarRatio[0],c=t.sarRatio[1],l=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,n>>8&255,255&n,o>>8&255,255&o,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]),d=new Uint8Array((a=(r=[1,s[1],s[2],s[3],255,225,s.length>>>8&255,255&s.length]).concat.apply(r,y(s)).concat([1,i.length>>>8&255,255&i.length])).concat.apply(a,y(i))),f=new Uint8Array([0,0,88,57,0,15,200,192,0,4,86,72]),h=e.sinf(t.encv),p=new Uint8Array([u>>24,u>>16&255,u>>8&255,255&u,c>>24,c>>16&255,c>>8&255,255&c]);return e.box(e.types.encv,l,e.box(e.types.avcC,d),e.box(e.types.btrt,f),h,e.box(e.types.pasp,p))}},{key:"schi",value:function(t){var a=new Uint8Array([]),r=e.tenc(t);return e.box(e.types.schi,a,r)}},{key:"tenc",value:function(t){var a=new Uint8Array([0,0,0,0,0,0,255&t.default_IsEncrypted,255&t.default_IV_size].concat(W(t.default_KID)));return e.box(e.types.tenc,a)}},{key:"sinf",value:function(t){var a=new Uint8Array([]),r=new Uint8Array([t.data_format.charCodeAt(0),t.data_format.charCodeAt(1),t.data_format.charCodeAt(2),t.data_format.charCodeAt(3)]),s=new Uint8Array([0,0,0,0,99,101,110,99,0,1,0,0]),i=e.schi(t);return e.box(e.types.sinf,a,e.box(e.types.frma,r),e.box(e.types.schm,s),i)}},{key:"avc1hev1",value:function(t){var a=t.codecType===b.HEVC,r=a?e.types.hvc1:e.types.avc1,s=a?e.hvcC(t):e.avcC(t),i=[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,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,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,0,0,0,0,0,0,24,17,17]),s];return a?i.push(e.box(e.types.fiel,new Uint8Array([1,0]))):t.sarRatio&&t.sarRatio.length>1&&i.push(e.pasp(t.sarRatio)),e.box.apply(e,[r].concat(i))}},{key:"avcC",value:function(t){var a,r,s,i=[],n=[];return t.sps.forEach((function(e){s=e.byteLength,i.push(s>>>8&255),i.push(255&s),i.push.apply(i,y(e))})),t.pps.forEach((function(e){s=e.byteLength,n.push(s>>>8&255),n.push(255&s),n.push.apply(n,y(e))})),e.box(e.types.avcC,new Uint8Array((a=(r=[1,i[3],i[4],i[5],255,224|t.sps.length]).concat.apply(r,i).concat([t.pps.length])).concat.apply(a,n)))}},{key:"hvcC",value:function(t){var a=t.hvcC;if(a instanceof ArrayBuffer||a instanceof Uint8Array)return a;var r,s=t.vps,i=t.sps,n=t.pps;if(a){var o=a.generalProfileCompatibilityFlags,u=a.generalConstraintIndicatorFlags,c=(s.length&&1)+(i.length&&1)+(n.length&&1);r=[1,a.generalProfileSpace<<6|a.generalTierFlag<<5|a.generalProfileIdc,o>>>24,o>>>16,o>>>8,o,u[0],u[1],u[2],u[3],u[4],u[5],a.generalLevelIdc,240,0,252,252|a.chromaFormatIdc,248|a.bitDepthLumaMinus8,248|a.bitDepthChromaMinus8,0,0,a.numTemporalLayers<<3|a.temporalIdNested<<2|3,c];var l=function(e){var t;r.push(e.length>>8,e.length),(t=r).push.apply(t,y(e))};s.length&&(r.push(160,0,s.length),s.forEach(l)),i.length&&(r.push(161,0,i.length),i.forEach(l)),n.length&&(r.push(162,0,n.length),n.forEach(l))}else r=[1,1,96,0,0,0,144,0,0,0,0,0,93,240,0,252,253,248,248,0,0,15,3,160,0,1,0,24,64,1,12,1,255,255,1,96,0,0,3,0,144,0,0,3,0,0,3,0,93,153,152,9,161,0,1,0,45,66,1,1,1,96,0,0,3,0,144,0,0,3,0,0,3,0,93,160,2,128,128,45,22,89,153,164,147,43,154,128,128,128,130,0,0,3,0,2,0,0,3,0,50,16,162,0,1,0,7,68,1,193,114,180,98,64];return e.box(e.types.hvcC,new Uint8Array(r))}},{key:"pasp",value:function(t){var a=v(t,2),r=a[0],s=a[1];return e.box(e.types.pasp,new Uint8Array([r>>24,r>>16&255,r>>8&255,255&r,s>>24,s>>16&255,s>>8&255,255&s]))}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.sampleRate>>8&255,255&t.sampleRate,0,0]),t.config.length?e.esds(t.config):void 0)}},{key:"esds",value:function(t){var a=t.length;return e.box(e.types.esds,new Uint8Array([0,0,0,0,3,23+a,0,0,0,4,15+a,64,21,0,6,0,0,0,218,192,0,0,218,192,5].concat([a]).concat(t).concat([6,1,2])))}},{key:"mvex",value:function(t){return e.box.apply(e,[e.types.mvex].concat(y(t.map((function(t){return e.trex(t.id)})))))}},{key:"trex",value:function(t){return e.box(e.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]))}},{key:"trex1",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,2,0,0,0,0,0,0,1,0,0]))}},{key:"trex2",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,4,0,0,0,0,0,2,0,0,0]))}},{key:"moof",value:function(t){return e.box.apply(e,[e.types.moof,e.mfhd(t[0].samples?t[0].samples[0].gopId:0)].concat(y(t.map((function(t){return e.traf(t)})))))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"traf",value:function(t){var a=e.tfhd(t.id),r=e.tfdt(t,t.baseMediaDecodeTime);if(t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)){if(t.isVideoEncryption){if(t.isVideo){var s=e.saiz(t),i=e.saio(t),n=e.trun1(t),o=e.senc(t);return e.box(e.types.traf,a,r,s,i,n,o)}if(t.isAudioEncryption){var u=e.sbgp(),c=e.saiz(t),l=e.saio(t),d=e.senc(t),f=e.trun1(t);return e.box(e.types.traf,a,r,u,c,l,d,f)}var h=e.sbgp(),p=e.trun1(t);return e.box(e.types.traf,a,r,h,p)}if(t.isVideo){var v=e.trun1(t);return e.box(e.types.traf,a,r,v)}var y=e.sbgp(),m=e.saiz(t),g=e.saio(t),k=e.senc(t),b=e.trun1(t);return e.box(e.types.traf,a,r,y,m,g,k,b)}var _=e.sdtp(t);return e.box(e.types.traf,a,r,_,e.trun(t.samples,_.byteLength+76))}},{key:"sdtp",value:function(t){var a=new _e;return t.samples.forEach((function(e){a.write(new Uint8Array(t.isVideo?[e.keyframe?32:16]:[16]))})),e.box(e.types.sdtp,this.extension(0,0),a.buffer)}},{key:"trun1",value:function(t){var a=new _e,r=_e.writeUint32(t.samples.length),s=null;if(t.isVideo){var i=t.videoSencLength;s=_e.writeUint32(16*t.samples.length+i+149),!t.isVideoEncryption&&t.isAudioEncryption&&(s=_e.writeUint32(16*t.samples.length+92))}else{var n=12*t.samples.length+124;t.isAudioEncryption&&(n=12*t.samples.length+8*t.audioSenc.length+177),s=_e.writeUint32(n)}return t.samples.forEach((function(e){a.write(_e.writeUint32(e.duration)),a.write(_e.writeUint32(e.size)),a.write(_e.writeUint32(e.keyframe?33554432:65536)),t.isVideo&&a.write(_e.writeUint32(e.cts?e.cts:0))})),e.box(e.types.trun,this.extension(0,t.flags),r,s,a.buffer)}},{key:"senc",value:function(t){var a=new _e,r=t.samples.length,s=t.isVideo?16:8,i=t.isVideo?2:0,n=[],o=0;return t.isVideo?(n=t.videoSenc,o=t.videoSencLength):n=t.audioSenc,o=o||s*r,a.write(_e.writeUint32(16+o),e.types.senc,this.extension(0,i)),a.write(_e.writeUint32(r)),n.forEach((function(e){for(var t=0;t<e.InitializationVector.length;t++)a.write(new Uint8Array([e.InitializationVector[t]]));e.subsamples&&e.subsamples.length&&(a.write(_e.writeUint16(e.subsamples.length)),e.subsamples.forEach((function(e){a.write(_e.writeUint16(e.BytesOfClearData)),a.write(_e.writeUint32(e.BytesOfProtectedData))})))})),a.buffer}},{key:"saio",value:function(t){var a=12*t.samples.length+141;!t.isVideo&&t.isAudioEncryption&&(a=149);var r=new Uint8Array([1,0,0,0,0,0,0,1,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a]);return e.box(e.types.saio,r)}},{key:"saiz",value:function(t){var a=t.samples.length,r=new Uint8Array([0,0,0,0,16,a>>24&255,a>>16&255,a>>8&255,255&a]);return e.box(e.types.saiz,r)}},{key:"sbgp",value:function(){var t=new Uint8Array([114,111,108,108,0,0,0,1,0,0,1,25,0,0,0,1]);return e.box(e.types.sbgp,this.extension(0,0),t)}},{key:"extension",value:function(e,t){return new Uint8Array([e,t>>16&255,t>>8&255,255&t])}},{key:"tfhd",value:function(t){return e.box(e.types.tfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"tfdt",value:function(t,a){var r=Math.floor(a/(xe+1)),s=Math.floor(a%(xe+1));return t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)?e.box(e.types.tfdt,new Uint8Array([0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s])):e.box(e.types.tfdt,new Uint8Array([1,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,s>>24,s>>16&255,s>>8&255,255&s]))}},{key:"trun",value:function(t,a){var r=t.length,s=12+16*r;a+=8+s;var i=new Uint8Array(s);i.set([0,0,15,1,r>>>24&255,r>>>16&255,r>>>8&255,255&r,a>>>24&255,a>>>16&255,a>>>8&255,255&a],0);for(var n=0;n<r;n++){var o=t[n],u=o.duration,c=o.size,l=o.flag,d=void 0===l?{}:l,f=o.cts,h=void 0===f?0:f;i.set([u>>>24&255,u>>>16&255,u>>>8&255,255&u,c>>>24&255,c>>>16&255,c>>>8&255,255&c,d.isLeading<<2|(null===d.dependsOn||void 0===d.dependsOn?1:d.dependsOn),d.isDependedOn<<6|d.hasRedundancy<<4|d.paddingValue<<1|(null===d.isNonSyncSample||void 0===d.isNonSyncSample?1:d.isNonSyncSample),61440&d.degradationPriority,15&d.degradationPriority,h>>>24&255,h>>>16&255,h>>>8&255,255&h],12+16*n)}return e.box(e.types.trun,i)}},{key:"moovMP4",value:function(t){return e.box.apply(e,[e.types.moov,e.mvhd(t[0].duration,t[0].timescale)].concat(y(t.map((function(t){return e.trackMP4(t)})))))}},{key:"trackMP4",value:function(t){return e.box(e.types.trak,e.tkhd(t.id,t.duration,t.width,t.height),e.mdiaMP4(t))}},{key:"mdiaMP4",value:function(t){return e.box(e.types.mdia,e.mdhd(t.duration,t.timescale),e.hdlr(t.type),e.minfMP4(t))}},{key:"minfMP4",value:function(t){return e.box(e.types.minf,t.type===k.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stblMP4(t))}},{key:"stblMP4",value:function(t){var a=t.ext,r=[e.stsd(t),e.stts(a.stts),e.stsc(a.stsc),e.stsz(a.stsz),e.stco(a.stco)];return a.stss.length&&r.push(e.stss(a.stss)),a.ctts.length&&r.push(e.ctts(a.ctts)),e.box.apply(e,[e.types.stbl].concat(r))}},{key:"stts",value:function(t){var a=t.length,r=new Uint8Array(8*a),s=0;return t.forEach((function(e){var t=e.value,a=e.count;r.set([a>>24,a>>16&255,a>>8&255,255&a,t>>24,t>>16&255,t>>8&255,255&t],s),s+=8})),e.box(e.types.stts,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stsc",value:function(t){var a=t.length,r=new Uint8Array(12*a),s=0;return t.forEach((function(e){var t=e.firstChunk,a=e.samplesPerChunk,i=e.sampleDescIndex;r.set([t>>24,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],s),s+=12})),e.box(e.types.stsc,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stsz",value:function(t){var a=t.length,r=new Uint8Array(4*a),s=0;return t.forEach((function(e){r.set([e>>24,e>>16&255,e>>8&255,255&e],s),s+=4})),e.box(e.types.stsz,L(new Uint8Array([0,0,0,0,0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stco",value:function(t){var a=t.length,r=new Uint8Array(4*a),s=0;return t.forEach((function(e){r.set([e>>24,e>>16&255,e>>8&255,255&e],s),s+=4})),e.box(e.types.stco,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stss",value:function(t){var a=t.length,r=new Uint8Array(4*a),s=0;return t.forEach((function(e){r.set([e>>24,e>>16&255,e>>8&255,255&e],s),s+=4})),e.box(e.types.stss,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"ctts",value:function(t){var a=t.length,r=new Uint8Array(8*a),s=0;return t.forEach((function(e){var t=e.value,a=e.count;r.set([a>>24,a>>16&255,a>>8&255,255&a,t>>24,t>>16&255,t>>8&255,255&t],s),s+=8})),e.box(e.types.ctts,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"styp",value:function(){return e.box(e.types.styp,new Uint8Array([109,115,100,104,0,0,0,0,109,115,100,104,109,115,105,120]))}},{key:"sidx",value:function(t){var a=t.timescale,r=t.samples[0].duration,s=r*t.samples.length,i=t.samples[0].sampleOffset*r,n=8;t.samples.forEach((function(e){n+=e.size}));var o=0;if(t.isVideo){var u,c=0;t.videoSenc&&(u=t.videoSenc),t.isVideo&&u.forEach((function(e){c+=8,e.subsamples&&e.subsamples.length&&(c+=2,c+=6*e.subsamples.length)})),t.videoSencLength=c,o=n+141+16*t.samples.length+c,t.useEME&&t.isAudioEncryption&&!t.isVideoEncryption&&(o=n+16*t.samples.length+84)}else o=n+116+12*t.samples.length,t.useEME&&t.isAudioEncryption&&(o=n+169+12*t.samples.length+8*t.audioSenc.length);var l=new Uint8Array([0,0,0,0,0,0,0,255&t.id,a>>24&255,a>>16&255,a>>8&255,255&a,i>>24&255,i>>16&255,i>>8&255,255&i,0,0,0,0,0,0,0,1,0,o>>16&255,o>>8&255,255&o,s>>24&255,s>>16&255,s>>8&255,255&s,144,0,0,0]);return e.box(e.types.sidx,l)}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}}]),e}();i(we,"types",["avc1","avcC","hvc1","hvcC","dinf","dref","esds","ftyp","hdlr","mdat","mdhd","mdia","mfhd","minf","moof","moov","mp4a","mvex","mvhd","pasp","stbl","stco","stsc","stsd","stsz","stts","tfdt","tfhd","traf","trak","trex","tkhd","vmhd","smhd","ctts","stss","styp","pssh","sidx","sbgp","saiz","saio","senc","trun","encv","enca","sinf","btrt","frma","tenc","schm","schi","mehd","fiel","sdtp"].reduce((function(e,t){return e[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)],e}),Object.create(null))),i(we,"HDLR_TYPES",{video: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]),audio: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(we,"FTYPAVC1",we.box(we.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))),i(we,"FTYPHEV1",we.box(we.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,104,101,118,49]))),i(we,"DINF",we.box(we.types.dinf,we.box(we.types.dref,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1])))),i(we,"VMHD",we.box(we.types.vmhd,new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))),i(we,"SMHD",we.box(we.types.smhd,new Uint8Array([0,0,0,0,0,0,0,0]))),i(we,"StblTable",new Uint8Array([0,0,0,0,0,0,0,0])),i(we,"STTS",we.box(we.types.stts,we.StblTable)),i(we,"STSC",we.box(we.types.stsc,we.StblTable)),i(we,"STSZ",we.box(we.types.stsz,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]))),i(we,"STCO",we.box(we.types.stco,we.StblTable));var De=function(){function e(t,r){a(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]"),e.disabled=r}return s(e,[{key:"debug",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).debug.apply(t,[this._prefix].concat(r))}}},{key:"log",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).log.apply(t,[this._prefix].concat(r))}}},{key:"warn",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).warn.apply(t,[this._prefix].concat(r))}}},{key:"error",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).error.apply(t,[this._prefix].concat(r))}}},{key:"table",value:function(){var t;e.disabled||(console.group(this._prefix),(t=console).table.apply(t,arguments),console.groupEnd())}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();i(De,"disabled",!0);for(var Se=function(){function e(t,r,s){a(this,e),this.videoTrack=t,this.audioTrack=r;var i=/Chrome\/([^.]+)/.exec(navigator.userAgent);this.forceFirstIDR=i&&Number(i[1])<50,this.log=new De("FMP4Remuxer",!s||!s.openLog||!s.openLog)}return s(e,[{key:"remux",value:function(){var e,t,a,r,s,i=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=this.videoTrack,u=this.audioTrack,c=o.exist(),l=u.exist(),d=[];return i&&(n&&n.initMerge?(c&&d.push(this.videoTrack),l&&d.push(this.audioTrack),a=we.initSegment(d)):(c&&(e=we.initSegment([this.videoTrack])),l&&(t=we.initSegment([this.audioTrack])))),c&&o.hasSample()&&(r=this._remuxVideo()),l&&u.hasSample()&&(s=this._remuxAudio()),o.samples=[],u.samples=[],{initSegment:a,videoInitSegment:e,audioInitSegment:t,videoSegment:r,audioSegment:s}}},{key:"_remuxVideo",value:function(){var e=this.videoTrack;this.forceFirstIDR&&(e.samples[0].flag={dependsOn:2,isNonSyncSample:0});var t=e.samples,a=0;t.forEach((function(e){a+=e.units.reduce((function(e,t){return e+t.byteLength}),0),a+=4*e.units.length}));for(var r,s=new Uint8Array(a),i=new DataView(s.buffer),n=function(e,a,n,o){o=t[e];var u=0;o.units.forEach((function(e){i.setUint32(n,e.byteLength),n+=4,s.set(e,n),n+=e.byteLength,u+=4+e.byteLength})),o.size=u,c=n,r=o},o=0,u=t.length,c=0;o<u;o++)n(o,0,c,r);var l=we.mdat(s);return L(we.moof([e]),l)}},{key:"_remuxAudio",value:function(){var e=this.audioTrack,t=new Uint8Array(e.samples.reduce((function(e,t){return e+t.size}),0));e.samples.reduce((function(e,a){return t.set(a.data,e),e+a.size}),0);var a=we.mdat(t);return L(we.moof([e]),a)}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset()}}]),e}(),Ae=function(){function e(){a(this,e)}return s(e,[{key:"mixIn",value:function(e){return Object.assign(this,e)}},{key:"clone",value:function(){var e=new this.constructor;return Object.assign(e,this),e}}],[{key:"create",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return l(this,t)}}]),e}(),Te=function(e){n(r,e);var t=f(r);function r(){var e,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4*s.length;a(this,r),e=t.call(this);var n=s;if(n instanceof ArrayBuffer&&(n=new Uint8Array(n)),(n instanceof Int8Array||n instanceof Uint8ClampedArray||n instanceof Int16Array||n instanceof Uint16Array||n instanceof Int32Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array)&&(n=new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),n instanceof Uint8Array){for(var o=n.byteLength,u=[],c=0;c<o;c+=1)u[c>>>2]|=n[c]<<24-c%4*8;e.words=u,e.sigBytes=o}else e.words=s,e.sigBytes=i;return e}return s(r,[{key:"toString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:je;return e.stringify(this)}},{key:"concat",value:function(e){var t=this.words,a=e.words,r=this.sigBytes,s=e.sigBytes;if(this.clamp(),r%4)for(var i=0;i<s;i+=1){var n=a[i>>>2]>>>24-i%4*8&255;t[r+i>>>2]|=n<<24-(r+i)%4*8}else for(var o=0;o<s;o+=4)t[r+o>>>2]=a[o>>>2];return this.sigBytes+=s,this}},{key:"clamp",value:function(){var e=this.words,t=this.sigBytes;e[t>>>2]&=4294967295<<32-t%4*8,e.length=Math.ceil(t/4)}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e.words=this.words.slice(0),e}}],[{key:"random",value:function(e){for(var t,a=[],s=function(e){var t=e,a=987654321,r=4294967295;return function(){var e=((a=36969*(65535&a)+(a>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return e/=4294967296,(e+=.5)*(Math.random()>.5?1:-1)}},i=0;i<e;i+=4){var n=s(4294967296*(t||Math.random()));t=987654071*n(),a.push(4294967296*n()|0)}return new r(a,e)}}]),r}(Ae),je={stringify:function(e){for(var t=e.words,a=e.sigBytes,r=[],s=0;s<a;s+=1){var i=t[s>>>2]>>>24-s%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,a=[],r=0;r<t;r+=2)a[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new Te(a,t/2)}},Ee=function(e){for(var t=e.length,a=[],r=0;r<t;r+=1)a[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new Te(a,t)},Be=function(e){return Ee(unescape(encodeURIComponent(e)))},Ce=function(e){n(r,e);var t=f(r);function r(){var e;return a(this,r),(e=t.call(this))._minBufferSize=0,e}return s(r,[{key:"reset",value:function(){this._data=new Te,this._nDataBytes=0}},{key:"_append",value:function(e){var t=e;"string"==typeof t&&(t=Be(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes}},{key:"_process",value:function(e){var t,a=this._data,r=this.blockSize,s=a.words,i=a.sigBytes,n=i/(4*r),o=(n=e?Math.ceil(n):Math.max((0|n)-this._minBufferSize,0))*r,u=Math.min(4*o,i);if(o){for(var c=0;c<o;c+=r)this._doProcessBlock(s,c);t=s.splice(0,o),a.sigBytes-=u}return new Te(t,u)}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e._data=this._data.clone(),e}}]),r}(Ae),Pe=function(e){n(r,e);var t=f(r);function r(e){var s;return a(this,r),(s=t.call(this)).blockSize=16,s.cfg=Object.assign(new Ae,e),s.reset(),s}return s(r,[{key:"reset",value:function(){p(o(r.prototype),"reset",this).call(this),this._doReset()}},{key:"update",value:function(e){return this._append(e),this._process(),this}},{key:"finalize",value:function(e){return e&&this._append(e),this._doFinalize()}}],[{key:"_createHelper",value:function(e){return function(t,a){return new e(a).finalize(t)}}},{key:"_createHmacHelper",value:function(e){return function(t,a){return new Ue(e,a).finalize(t)}}}]),r}(Ce),Ue=function(e){n(r,e);var t=f(r);function r(e,s){var i;a(this,r),i=t.call(this);var n=new e;i._hasher=n;var o=s;"string"==typeof o&&(o=Be(o));var u=n.blockSize,c=4*u;o.sigBytes>c&&(o=n.finalize(s)),o.clamp();var l=o.clone();i._oKey=l;var d=o.clone();i._iKey=d;for(var f=l.words,h=d.words,p=0;p<u;p+=1)f[p]^=1549556828,h[p]^=909522486;return l.sigBytes=c,d.sigBytes=c,i.reset(),i}return s(r,[{key:"reset",value:function(){var e=this._hasher;e.reset(),e.update(this._iKey)}},{key:"update",value:function(e){return this._hasher.update(e),this}},{key:"finalize",value:function(e){var t=this._hasher,a=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(a))}}]),r}(Ae),Ie={stringify:function(e){var t=e.words,a=e.sigBytes,r=this._map;e.clamp();for(var s=[],i=0;i<a;i+=3)for(var n=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,o=0;o<4&&i+.75*o<a;o+=1)s.push(r.charAt(n>>>6*(3-o)&63));var u=r.charAt(64);if(u)for(;s.length%4;)s.push(u);return s.join("")},parse:function(e){var t=e.length,a=this._map,r=this._reverseMap;if(!r){this._reverseMap=[],r=this._reverseMap;for(var s=0;s<a.length;s+=1)r[a.charCodeAt(s)]=s}var i=a.charAt(64);if(i){var n=e.indexOf(i);-1!==n&&(t=n)}return function(e,t,a){for(var r=[],s=0,i=0;i<t;i+=1)if(i%4){var n=a[e.charCodeAt(i-1)]<<i%4*2|a[e.charCodeAt(i)]>>>6-i%4*2;r[s>>>2]|=n<<24-s%4*8,s+=1}return Te.create(r,s)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},Me=[],Oe=0;Oe<64;Oe+=1)Me[Oe]=4294967296*Math.abs(Math.sin(Oe+1))|0;var ze=function(e,t,a,r,s,i,n){var o=e+(t&a|~t&r)+s+n;return(o<<i|o>>>32-i)+t},Re=function(e,t,a,r,s,i,n){var o=e+(t&r|a&~r)+s+n;return(o<<i|o>>>32-i)+t},Ve=function(e,t,a,r,s,i,n){var o=e+(t^a^r)+s+n;return(o<<i|o>>>32-i)+t},Le=function(e,t,a,r,s,i,n){var o=e+(a^(t|~r))+s+n;return(o<<i|o>>>32-i)+t},Ne=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"_doReset",value:function(){this._hash=new Te([1732584193,4023233417,2562383102,271733878])}},{key:"_doProcessBlock",value:function(e,t){for(var a=e,r=0;r<16;r+=1){var s=t+r,i=e[s];a[s]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8)}var n=this._hash.words,o=a[t+0],u=a[t+1],c=a[t+2],l=a[t+3],d=a[t+4],f=a[t+5],h=a[t+6],p=a[t+7],v=a[t+8],y=a[t+9],m=a[t+10],g=a[t+11],k=a[t+12],b=a[t+13],_=a[t+14],x=a[t+15],w=n[0],D=n[1],S=n[2],A=n[3];w=ze(w,D,S,A,o,7,Me[0]),A=ze(A,w,D,S,u,12,Me[1]),S=ze(S,A,w,D,c,17,Me[2]),D=ze(D,S,A,w,l,22,Me[3]),w=ze(w,D,S,A,d,7,Me[4]),A=ze(A,w,D,S,f,12,Me[5]),S=ze(S,A,w,D,h,17,Me[6]),D=ze(D,S,A,w,p,22,Me[7]),w=ze(w,D,S,A,v,7,Me[8]),A=ze(A,w,D,S,y,12,Me[9]),S=ze(S,A,w,D,m,17,Me[10]),D=ze(D,S,A,w,g,22,Me[11]),w=ze(w,D,S,A,k,7,Me[12]),A=ze(A,w,D,S,b,12,Me[13]),S=ze(S,A,w,D,_,17,Me[14]),D=ze(D,S,A,w,x,22,Me[15]),w=Re(w,D,S,A,u,5,Me[16]),A=Re(A,w,D,S,h,9,Me[17]),S=Re(S,A,w,D,g,14,Me[18]),D=Re(D,S,A,w,o,20,Me[19]),w=Re(w,D,S,A,f,5,Me[20]),A=Re(A,w,D,S,m,9,Me[21]),S=Re(S,A,w,D,x,14,Me[22]),D=Re(D,S,A,w,d,20,Me[23]),w=Re(w,D,S,A,y,5,Me[24]),A=Re(A,w,D,S,_,9,Me[25]),S=Re(S,A,w,D,l,14,Me[26]),D=Re(D,S,A,w,v,20,Me[27]),w=Re(w,D,S,A,b,5,Me[28]),A=Re(A,w,D,S,c,9,Me[29]),S=Re(S,A,w,D,p,14,Me[30]),D=Re(D,S,A,w,k,20,Me[31]),w=Ve(w,D,S,A,f,4,Me[32]),A=Ve(A,w,D,S,v,11,Me[33]),S=Ve(S,A,w,D,g,16,Me[34]),D=Ve(D,S,A,w,_,23,Me[35]),w=Ve(w,D,S,A,u,4,Me[36]),A=Ve(A,w,D,S,d,11,Me[37]),S=Ve(S,A,w,D,p,16,Me[38]),D=Ve(D,S,A,w,m,23,Me[39]),w=Ve(w,D,S,A,b,4,Me[40]),A=Ve(A,w,D,S,o,11,Me[41]),S=Ve(S,A,w,D,l,16,Me[42]),D=Ve(D,S,A,w,h,23,Me[43]),w=Ve(w,D,S,A,y,4,Me[44]),A=Ve(A,w,D,S,k,11,Me[45]),S=Ve(S,A,w,D,x,16,Me[46]),D=Ve(D,S,A,w,c,23,Me[47]),w=Le(w,D,S,A,o,6,Me[48]),A=Le(A,w,D,S,p,10,Me[49]),S=Le(S,A,w,D,_,15,Me[50]),D=Le(D,S,A,w,f,21,Me[51]),w=Le(w,D,S,A,k,6,Me[52]),A=Le(A,w,D,S,l,10,Me[53]),S=Le(S,A,w,D,m,15,Me[54]),D=Le(D,S,A,w,u,21,Me[55]),w=Le(w,D,S,A,v,6,Me[56]),A=Le(A,w,D,S,x,10,Me[57]),S=Le(S,A,w,D,h,15,Me[58]),D=Le(D,S,A,w,b,21,Me[59]),w=Le(w,D,S,A,d,6,Me[60]),A=Le(A,w,D,S,g,10,Me[61]),S=Le(S,A,w,D,c,15,Me[62]),D=Le(D,S,A,w,y,21,Me[63]),n[0]=n[0]+w|0,n[1]=n[1]+D|0,n[2]=n[2]+S|0,n[3]=n[3]+A|0}},{key:"_doFinalize",value:function(){var e=this._data,t=e.words,a=8*this._nDataBytes,r=8*e.sigBytes;t[r>>>5]|=128<<24-r%32;var s=Math.floor(a/4294967296),i=a;t[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t[14+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),e.sigBytes=4*(t.length+1),this._process();for(var n=this._hash,o=n.words,u=0;u<4;u+=1){var c=o[u];o[u]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}return n}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e._hash=this._hash.clone(),e}}]),r}(Pe);Pe._createHelper(Ne),Pe._createHmacHelper(Ne);var Fe=function(e){n(r,e);var t=f(r);function r(e){var s;return a(this,r),(s=t.call(this)).cfg=Object.assign(new Ae,{keySize:4,hasher:Ne,iterations:1},e),s}return s(r,[{key:"compute",value:function(e,t){for(var a,r=this.cfg,s=r.hasher.create(),i=Te.create(),n=i.words,o=r.keySize,u=r.iterations;n.length<o;){a&&s.update(a),a=s.update(e).finalize(t),s.reset();for(var c=1;c<u;c+=1)a=s.finalize(a),s.reset();i.concat(a)}return i.sigBytes=4*o,i}}]),r}(Ae),Ge=function(e){n(r,e);var t=f(r);function r(e,s,i){var n;return a(this,r),(n=t.call(this)).cfg=Object.assign(new Ae,i),n._xformMode=e,n._key=s,n.reset(),n}return s(r,[{key:"reset",value:function(){p(o(r.prototype),"reset",this).call(this),this._doReset()}},{key:"process",value:function(e){return this._append(e),this._process()}},{key:"finalize",value:function(e){return e&&this._append(e),this._doFinalize()}}],[{key:"createEncryptor",value:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)}},{key:"createDecryptor",value:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)}},{key:"_createHelper",value:function(e){var t=function(e){return"string"==typeof e?$e:Qe};return{encrypt:function(a,r,s){return t(r).encrypt(e,a,r,s)},decrypt:function(a,r,s){return t(r).decrypt(e,a,r,s)}}}}]),r}(Ce);Ge._ENC_XFORM_MODE=1,Ge._DEC_XFORM_MODE=2,Ge.keySize=4,Ge.ivSize=4;var qe=function(e){n(r,e);var t=f(r);function r(e,s){var i;return a(this,r),(i=t.call(this))._cipher=e,i._iv=s,i}return s(r,null,[{key:"createEncryptor",value:function(e,t){return this.Encryptor.create(e,t)}},{key:"createDecryptor",value:function(e,t){return this.Decryptor.create(e,t)}}]),r}(Ae);function He(e,t,a){var r,s=e,i=this._iv;i?(r=i,this._iv=void 0):r=this._prevBlock;for(var n=0;n<a;n+=1)s[t+n]^=r[n]}var Ke=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(qe);Ke.Encryptor=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"processBlock",value:function(e,t){var a=this._cipher,r=a.blockSize;He.call(this,e,t,r),a.encryptBlock(e,t),this._prevBlock=e.slice(t,t+r)}}]),r}(Ke),Ke.Decryptor=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"processBlock",value:function(e,t){var a=this._cipher,r=a.blockSize,s=e.slice(t,t+r);a.decryptBlock(e,t),He.call(this,e,t,r),this._prevBlock=s}}]),r}(Ke);var We={pad:function(e,t){for(var a=4*t,r=a-e.sigBytes%a,s=r<<24|r<<16|r<<8|r,i=[],n=0;n<r;n+=4)i.push(s);var o=Te.create(i,r);e.concat(o)},unpad:function(e){var t=e,a=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=a}},Xe=function(e){n(r,e);var t=f(r);function r(e,s,i){var n;return a(this,r),(n=t.call(this,e,s,Object.assign({mode:Ke,padding:We},i))).blockSize=4,n}return s(r,[{key:"reset",value:function(){var e;p(o(r.prototype),"reset",this).call(this);var t=this.cfg,a=t.iv,s=t.mode;this._xformMode===this.constructor._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode=e.call(s,this,a&&a.words),this._mode.__creator=e}},{key:"_doProcessBlock",value:function(e,t){this._mode.processBlock(e,t)}},{key:"_doFinalize",value:function(){var e,t=this.cfg.padding;return this._xformMode===this.constructor._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e}}]),r}(Ge),Ye=function(e){n(r,e);var t=f(r);function r(e){var s;return a(this,r),(s=t.call(this)).mixIn(e),s}return s(r,[{key:"toString",value:function(e){return(e||this.formatter).stringify(this)}}]),r}(Ae),Ze={stringify:function(e){var t=e.ciphertext,a=e.salt;return(a?Te.create([1398893684,1701076831]).concat(a).concat(t):t).toString(Ie)},parse:function(e){var t,a=Ie.parse(e),r=a.words;return 1398893684===r[0]&&1701076831===r[1]&&(t=Te.create(r.slice(2,4)),r.splice(0,4),a.sigBytes-=16),Ye.create({ciphertext:a,salt:t})}},Qe=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,null,[{key:"encrypt",value:function(e,t,a,r){var s=Object.assign(new Ae,this.cfg,r),i=e.createEncryptor(a,s),n=i.finalize(t),o=i.cfg;return Ye.create({ciphertext:n,key:a,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:i.blockSize,formatter:s.format})}},{key:"decrypt",value:function(e,t,a,r){var s=t,i=Object.assign(new Ae,this.cfg,r);return s=this._parse(s,i.format),e.createDecryptor(a,i).finalize(s.ciphertext)}},{key:"_parse",value:function(e,t){return"string"==typeof e?t.parse(e,this):e}}]),r}(Ae);Qe.cfg=Object.assign(new Ae,{format:Ze});var Je={execute:function(e,t,a,r){var s=r;s||(s=Te.random(8));var i=Fe.create({keySize:t+a}).compute(e,s),n=Te.create(i.words.slice(t),4*a);return i.sigBytes=4*t,Ye.create({key:i,iv:n,salt:s})}},$e=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,null,[{key:"encrypt",value:function(e,t,a,r){var s=Object.assign(new Ae,this.cfg,r),i=s.kdf.execute(a,e.keySize,e.ivSize);s.iv=i.iv;var n=Qe.encrypt.call(this,e,t,i.key,s);return n.mixIn(i),n}},{key:"decrypt",value:function(e,t,a,r){var s=t,i=Object.assign(new Ae,this.cfg,r);s=this._parse(s,i.format);var n=i.kdf.execute(a,e.keySize,e.ivSize,s.salt);return i.iv=n.iv,Qe.decrypt.call(this,e,s,n.key,i)}}]),r}(Qe);$e.cfg=Object.assign(Qe.cfg,{kdf:Je});for(var et=[],tt=[],at=[],rt=[],st=[],it=[],nt=[],ot=[],ut=[],ct=[],lt=[],dt=0;dt<256;dt+=1)lt[dt]=dt<128?dt<<1:dt<<1^283;for(var ft=0,ht=0,pt=0;pt<256;pt+=1){var vt=ht^ht<<1^ht<<2^ht<<3^ht<<4;vt=vt>>>8^255&vt^99,et[ft]=vt,tt[vt]=ft;var yt=lt[ft],mt=lt[yt],gt=lt[mt],kt=257*lt[vt]^16843008*vt;at[ft]=kt<<24|kt>>>8,rt[ft]=kt<<16|kt>>>16,st[ft]=kt<<8|kt>>>24,it[ft]=kt,kt=16843009*gt^65537*mt^257*yt^16843008*ft,nt[vt]=kt<<24|kt>>>8,ot[vt]=kt<<16|kt>>>16,ut[vt]=kt<<8|kt>>>24,ct[vt]=kt,ft?(ft=yt^lt[lt[lt[gt^yt]]],ht^=lt[lt[ht]]):ft=ht=1}var bt=[0,1,2,4,8,16,32,64,128,27,54],_t=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"_doReset",value:function(){var e;if(!this._nRounds||this._keyPriorReset!==this._key){this._keyPriorReset=this._key;var t=this._keyPriorReset,a=t.words,r=t.sigBytes/4;this._nRounds=r+6;var s=4*(this._nRounds+1);this._keySchedule=[];for(var i=this._keySchedule,n=0;n<s;n+=1)n<r?i[n]=a[n]:(e=i[n-1],n%r?r>6&&n%r==4&&(e=et[e>>>24]<<24|et[e>>>16&255]<<16|et[e>>>8&255]<<8|et[255&e]):(e=et[(e=e<<8|e>>>24)>>>24]<<24|et[e>>>16&255]<<16|et[e>>>8&255]<<8|et[255&e],e^=bt[n/r|0]<<24),i[n]=i[n-r]^e);this._invKeySchedule=[];for(var o=this._invKeySchedule,u=0;u<s;u+=1){var c=s-u;e=u%4?i[c]:i[c-4],o[u]=u<4||c<=4?e:nt[et[e>>>24]]^ot[et[e>>>16&255]]^ut[et[e>>>8&255]]^ct[et[255&e]]}}}},{key:"encryptBlock",value:function(e,t){this._doCryptBlock(e,t,this._keySchedule,at,rt,st,it,et)}},{key:"decryptBlock",value:function(e,t){var a=e,r=a[t+1];a[t+1]=a[t+3],a[t+3]=r,this._doCryptBlock(a,t,this._invKeySchedule,nt,ot,ut,ct,tt),r=a[t+1],a[t+1]=a[t+3],a[t+3]=r}},{key:"_doCryptBlock",value:function(e,t,a,r,s,i,n,o){for(var u=e,c=this._nRounds,l=u[t]^a[0],d=u[t+1]^a[1],f=u[t+2]^a[2],h=u[t+3]^a[3],p=4,v=1;v<c;v+=1){var y=r[l>>>24]^s[d>>>16&255]^i[f>>>8&255]^n[255&h]^a[p];p+=1;var m=r[d>>>24]^s[f>>>16&255]^i[h>>>8&255]^n[255&l]^a[p];p+=1;var g=r[f>>>24]^s[h>>>16&255]^i[l>>>8&255]^n[255&d]^a[p];p+=1;var k=r[h>>>24]^s[l>>>16&255]^i[d>>>8&255]^n[255&f]^a[p];p+=1,l=y,d=m,f=g,h=k}var b=(o[l>>>24]<<24|o[d>>>16&255]<<16|o[f>>>8&255]<<8|o[255&h])^a[p];p+=1;var _=(o[d>>>24]<<24|o[f>>>16&255]<<16|o[h>>>8&255]<<8|o[255&l])^a[p];p+=1;var x=(o[f>>>24]<<24|o[h>>>16&255]<<16|o[l>>>8&255]<<8|o[255&d])^a[p];p+=1;var w=(o[h>>>24]<<24|o[l>>>16&255]<<16|o[d>>>8&255]<<8|o[255&f])^a[p];p+=1,u[t]=b,u[t+1]=_,u[t+2]=x,u[t+3]=w}}]),r}(Xe);_t.keySize=8;var xt=Xe._createHelper(_t),wt=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(qe);wt.Encryptor=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"processBlock",value:function(e,t){var a=e,r=this._cipher,s=r.blockSize,i=this._iv,n=this._counter;i&&(this._counter=i.slice(0),n=this._counter,this._iv=void 0);var o=n.slice(0);r.encryptBlock(o,0),n[s-1]=n[s-1]+1|0;for(var u=0;u<s;u+=1)a[t+u]^=o[u]}}]),r}(wt),wt.Decryptor=wt.Encryptor;var Dt={pad:function(){},unpad:function(){}},St={decryptWordArray:function(e,t,a){var r=je.parse(t),s=je.parse(K(a)),i=Te.create(new Uint8Array(e)),n=xt.decrypt(Ye.create({ciphertext:i}),r,{iv:s,mode:wt,padding:Dt});return St.wordArrayToUint8Array(n)},wordArrayToUint8Array:function(e){for(var t=e.sigBytes,a=e.words,r=new Uint8Array(t),s=0,i=0;s!==t;){var n=a[i++];if(r[s++]=(4278190080&n)>>>24,s===t)break;if(r[s++]=(16711680&n)>>>16,s===t)break;if(r[s++]=(65280&n)>>>8,s===t)break;r[s++]=255&n}return r},decoderAESCTRData:function(e,t){if(e.videoSenc){var a=e.kidValue,r=e.videoSenc;e.samples.forEach((function(t,s){var i=r[s],n=t.data,o=[],u=[],c=i.InitializationVector;if(i.subsamples&&i.subsamples.length)i.subsamples.forEach((function(e){var t=e.BytesOfClearData+e.BytesOfProtectedData,a=n.slice(0,t);o.push(a.slice(0,e.BytesOfClearData)),u.push(a.slice(e.BytesOfClearData)),n=n.slice(t)}));else{var l=t.size;o.push(n.slice(0,0)),u.push(n.slice(0,l)),n=n.slice(l)}var d=new _e;d.write.apply(d,u);var f=St.decryptWordArray(d.buffer,a,c),h=new _e;o.forEach((function(e,t){var a=u[t].length,r=f.slice(0,a);h.write(e),h.write(r),f=f.slice(a)})),e.samples[s].data=h.buffer}))}if(t.audioSenc){var s=t.kidValue,i=t.audioSenc;t.samples.forEach((function(e,a){var r=i[a],n=St.decryptWordArray(e.data,s,r.InitializationVector);t.samples[a].data=n}))}}},At=function(){function e(t,r,s,n){var o=this;a(this,e),i(this,"_videoSamples",[]),i(this,"_audioSamples",[]),i(this,"_lastRemainBuffer",[]),i(this,"_lastRemainBufferStartPos",0),this.videoTrack=new w,this.audioTrack=new D,this.metadataTrack=s||new B,this.log=new De("MP4Demuxer",!n||!n.openLog||!n.openLog),t&&t.forEach((function(e){var t;(t=o._videoSamples).push.apply(t,y(e.frames))})),r&&r.forEach((function(e){var t;(t=o._audioSamples).push.apply(t,y(e.frames))}))}return s(e,[{key:"parseSamples",value:function(e){if(!e)throw new Error("moov is required");if(this.videoTrack.codec||this.audioTrack.codec||(fe.moovToTrack(e,this.videoTrack,this.audioTrack),this.videoSenc=this.videoTrack.videoSenc,this.audioSenc=this.audioTrack.audioSenc),!this._audioSamples.length&&!this._videoSamples.length){var t=fe.moovToSamples(e);if(!t)throw new Error("cannot parse samples from moov box");this._videoSamples=t.videoSamples||[],this._audioSamples=t.audioSamples||[]}}},{key:"demux",value:function(e,t,a,r,s){this.parseSamples(s);var i,n,o,u=this.videoTrack,c=this.audioTrack;if(u.samples=[],c.samples=[],a){for(var l,d=0,f=a[0],h=a[1];f<=h;f++){if(!(i=this._videoSamples[f]))throw new Error("cannot found video frame #".concat(f));o=i.offset-t,n=e.subarray(o,o+i.size),(l=new S(i.pts||i.dts,i.dts)).duration=i.duration,l.gopId=i.gopId,i.keyframe&&l.setToKeyframe();for(var p=0,v=n.length-1;p<v;)d=G(n,p),p+=4,l.units.push(n.subarray(p,p+d)),p+=d;u.samples.push(l)}u.baseMediaDecodeTime=u.samples[0].dts}if(r){for(var y=r[0],m=r[1];y<=m;y++){if(!(i=this._audioSamples[y]))throw new Error("cannot found video frame #".concat(y));o=i.offset-t,n=e.subarray(o,o+i.size),c.samples.push(new A(i.dts,n,i.duration))}c.baseMediaDecodeTime=c.samples[0].dts}return{videoTrack:u,audioTrack:c,metadataTrack:this.metadataTrack}}},{key:"demuxPart",value:function(e,t,a,r,s,i,n){if(this.parseSamples(s),this.videoTrack.useEME=i,this.audioTrack.useEME=i,this._lastRemainBuffer&&this._lastRemainBuffer.byteLength>0&&t>this._lastRemainBufferStartPos&&t<=this._lastRemainBufferStartPos+this._lastRemainBuffer.byteLength)for(var o=0;o<20;)try{var u=this._lastRemainBuffer.subarray(0,t-this._lastRemainBufferStartPos),c=new Uint8Array(e.byteLength+u.byteLength);c.set(u,0),c.set(new Uint8Array(e),u.byteLength),e=c,t-=u.byteLength,this._lastRemainBuffer=null,this._lastRemainBufferStartPos=0;break}catch(j){if(!(o<20))throw new Error("new Uint8Array error:,"+j.errorMessage);o++}var l,d,f,h=this.videoTrack,p=this.audioTrack;h.samples=[],p.samples=[],h.videoSenc=null,p.audioSenc=null;var v=0,y=0;if(this._videoSamples.length>0&&a.length>0){for(var m,g=e.byteLength+t,k=a[0];k<=a[1];k++){if(!(l=this._videoSamples[k]))throw new Error("cannot found video frame #".concat(k));l.offset>=t&&l.offset+l.size<=g&&(v=(f=l.offset-t)+l.size,d=e.subarray(f,v),(m=new S(l.pts||l.dts,l.dts)).duration=l.duration,m.gopId=l.gopId,m.sampleOffset=l.index,l.keyframe&&m.setToKeyframe(),m.data=d,m.size=l.size,h.samples.push(m))}h.samples.length>0&&(h.gopId=h.samples[0].gopId,h.baseMediaDecodeTime=h.samples[0].dts,h.startPts=h.samples[0].pts/h.timescale,h.endPts=h.samples[h.samples.length-1].pts/h.timescale,this.videoSenc&&(h.videoSenc=this.videoSenc.slice(h.samples[0].sampleOffset,h.samples[0].sampleOffset+h.samples.length),h.kidValue=n))}if(this._audioSamples.length>0&&r.length>0){for(var b=r[0];b<=r[1];b++){if(!(l=this._audioSamples[b]))throw new Error("cannot found video frame #".concat(b));l.offset>=t&&l.offset+l.size<=e.byteLength+t&&(y=(f=l.offset-t)+l.size,d=e.subarray(f,y),p.samples.push(new A(l.dts,d,l.duration,l.index)))}p.samples.length>0&&(p.gopId=p.samples[0].gopId||h.gopId,p.baseMediaDecodeTime=p.samples[0].dts,p.startPts=p.samples[0].pts/p.timescale,p.endPts=p.samples[p.samples.length-1].pts/p.timescale,this.audioSenc&&(p.audioSenc=this.audioSenc.slice(p.samples[0].sampleOffset,p.samples[0].sampleOffset+p.samples.length),p.kidValue=n))}this.decoderData(h,p);for(var _=0,x=0;x<h.samples.length;x++)for(var w=0,D=h.samples[x].data,T=D.length-1;w<T;)_=G(D,w),w+=4,h.samples[x].units.push(D.subarray(w,w+_)),w+=_;return this._lastRemainBuffer=e.subarray(Math.max(v,y)),this._lastRemainBuffer.byteLength>0?this._lastRemainBufferStartPos=t+e.byteLength-this._lastRemainBuffer.byteLength:this._lastRemainBufferStartPos=0,{videoTrack:h,audioTrack:p,metadataTrack:this.metadataTrack}}},{key:"reset",value:function(){this._videoSamples=[],this._audioSamples=[],this._lastRemainBuffer=null,this._lastRemainBufferStartPos=0,this.videoTrack.reset(),this.audioTrack.reset(),this.metadataTrack.reset()}},{key:"decoderData",value:function(e,t){e.useEME||t.useEME||St.decoderAESCTRData(e,t)}}],[{key:"probe",value:function(e){return fe.probe(e)}}]),e}(),Tt=function(){function e(t,r){a(this,e),this.videoTrack=t,this.audioTrack=r}return s(e,[{key:"remux",value:function(e,t){this.videoTrack=e||this.videoTrack,this.audioTrack=t||this.audioTrack;var a,r,s=(null==e?void 0:e.exist())&&(null==e?void 0:e.hasSample()),i=(null==t?void 0:t.exist())&&(null==t?void 0:t.hasSample());return s&&i?a=this._remuxMix(e,t):s?a=this._remuxTrack(e):i&&(r=this._remuxTrack(t)),e&&(e.samples=[]),t&&(t.samples=[]),{videoSegment:a,audioSegment:r}}},{key:"_remuxMix",value:function(e,t){var a=we.ftyp([e,t]),r=this._remuxData(e,a.byteLength+8),s=r.mdatData,i=r.chunkOffset,n=this._remuxData(t,i).mdatData,o=we.mdat(L(s,n)),u=we.moovMP4([e,t]);return e.ext=void 0,t.ext=void 0,e.samples=[],t.samples=[],L(a,o,u)}},{key:"_remuxTrack",value:function(e){var t=we.ftyp([e]),a=this._remuxData(e,t.byteLength+8).mdatData,r=we.mdat(a),s=we.moovMP4([e]);return e.ext=void 0,e.samples=[],L(t,r,s)}},{key:"_remuxData",value:function(e,t){var a=e.type===k.VIDEO,r=e.samples,s=0;a?r.forEach((function(e){s+=e.units.reduce((function(e,t){return e+t.byteLength}),0),s+=4*e.units.length})):s=r.reduce((function(e,t){return e+t.size}),0);for(var i,n=new Uint8Array(s),o=new DataView(n.buffer),u=e.ext={stts:[],stsc:[],stsz:[],stco:[],stss:[],ctts:[]},c=0,l=0,d=r.length,f=0;f<d;f++){l+=(i=r[f]).duration;var h=a?0:i.size;a?i.units.forEach((function(e){o.setUint32(c,e.byteLength),c+=4,n.set(e,c),c+=e.byteLength,h+=4+e.byteLength})):(n.set(i.data,c),c+=h),i.size=h,u.stsz.push(h),a&&this._fillCttsSamples(u.ctts,i.cts),this._fillSttsSamples(u.stts,i,r[f+1]),this._fillStcoSamples(u.stco,f,1,t),t+=h,a&&i.keyframe&&u.stss.push(f+1)}return e.duration=l,this._fillStscSamples(u.stsc,d,1),{mdatData:n,chunkOffset:t}}},{key:"_fillSttsSamples",value:function(e,t,a){var r=e[e.length-1];a?r&&r.value===t.duration?r.count++:e.push({value:t.duration,count:1}):r?r.count++:e.push({value:40,count:1})}},{key:"_fillCttsSamples",value:function(e,t){var a=e[e.length-1];a&&a.value===t?a.count++:e.push({value:t,count:1})}},{key:"_fillStcoSamples",value:function(e,t,a,r){t%a||e.push(r)}},{key:"_fillStscSamples",value:function(e,t,a){if(t<=a)e.push({firstChunk:1,samplesPerChunk:t,sampleDescIndex:1});else{var r=Math.floor(t/a),s=t%a;e.push({firstChunk:1,samplesPerChunk:a,sampleDescIndex:1}),s&&e.push({firstChunk:r+1,samplesPerChunk:s,sampleDescIndex:1})}}}]),e}(),jt=Object.freeze(Object.defineProperty({__proto__:null,FMP4Demuxer:ke,FMP4Remuxer:Se,MP4Demuxer:At,MP4Remuxer:Tt,MP4Parser:fe,Crypto:St},Symbol.toStringTag,{value:"Module"}));return t(t(t(t(t({},se),de),jt),C),{},{Logger:U})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.array.map.js"),require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.string.includes.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.number.is-finite.js"),require("core-js/modules/es.number.constructor.js"),require("core-js/modules/es.array.splice.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.typed-array.uint8-array.js"),require("core-js/modules/esnext.typed-array.at.js"),require("core-js/modules/es.typed-array.copy-within.js"),require("core-js/modules/es.typed-array.every.js"),require("core-js/modules/es.typed-array.fill.js"),require("core-js/modules/es.typed-array.filter.js"),require("core-js/modules/es.typed-array.find.js"),require("core-js/modules/es.typed-array.find-index.js"),require("core-js/modules/esnext.typed-array.find-last.js"),require("core-js/modules/esnext.typed-array.find-last-index.js"),require("core-js/modules/es.typed-array.for-each.js"),require("core-js/modules/es.typed-array.includes.js"),require("core-js/modules/es.typed-array.index-of.js"),require("core-js/modules/es.typed-array.iterator.js"),require("core-js/modules/es.typed-array.join.js"),require("core-js/modules/es.typed-array.last-index-of.js"),require("core-js/modules/es.typed-array.map.js"),require("core-js/modules/es.typed-array.reduce.js"),require("core-js/modules/es.typed-array.reduce-right.js"),require("core-js/modules/es.typed-array.reverse.js"),require("core-js/modules/es.typed-array.set.js"),require("core-js/modules/es.typed-array.slice.js"),require("core-js/modules/es.typed-array.some.js"),require("core-js/modules/es.typed-array.sort.js"),require("core-js/modules/es.typed-array.subarray.js"),require("core-js/modules/es.typed-array.to-locale-string.js"),require("core-js/modules/es.typed-array.to-string.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.array.join.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.regexp.test.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.regexp.flags.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.string.pad-start.js"),require("core-js/modules/es.array.find.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/es.array-buffer.constructor.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.typed-array.int8-array.js"),require("core-js/modules/es.typed-array.uint8-clamped-array.js"),require("core-js/modules/es.typed-array.int16-array.js"),require("core-js/modules/es.typed-array.uint16-array.js"),require("core-js/modules/es.typed-array.int32-array.js"),require("core-js/modules/es.typed-array.uint32-array.js"),require("core-js/modules/es.typed-array.float32-array.js"),require("core-js/modules/es.typed-array.float64-array.js")):"function"==typeof define&&define.amd?define(["core-js/modules/es.array.concat.js","core-js/modules/es.object.to-string.js","core-js/modules/web.dom-collections.for-each.js","core-js/modules/es.array.map.js","core-js/modules/es.array.includes.js","core-js/modules/es.string.includes.js","core-js/modules/es.array.filter.js","core-js/modules/es.number.is-finite.js","core-js/modules/es.number.constructor.js","core-js/modules/es.array.splice.js","core-js/modules/es.array.iterator.js","core-js/modules/es.typed-array.uint8-array.js","core-js/modules/esnext.typed-array.at.js","core-js/modules/es.typed-array.copy-within.js","core-js/modules/es.typed-array.every.js","core-js/modules/es.typed-array.fill.js","core-js/modules/es.typed-array.filter.js","core-js/modules/es.typed-array.find.js","core-js/modules/es.typed-array.find-index.js","core-js/modules/esnext.typed-array.find-last.js","core-js/modules/esnext.typed-array.find-last-index.js","core-js/modules/es.typed-array.for-each.js","core-js/modules/es.typed-array.includes.js","core-js/modules/es.typed-array.index-of.js","core-js/modules/es.typed-array.iterator.js","core-js/modules/es.typed-array.join.js","core-js/modules/es.typed-array.last-index-of.js","core-js/modules/es.typed-array.map.js","core-js/modules/es.typed-array.reduce.js","core-js/modules/es.typed-array.reduce-right.js","core-js/modules/es.typed-array.reverse.js","core-js/modules/es.typed-array.set.js","core-js/modules/es.typed-array.slice.js","core-js/modules/es.typed-array.some.js","core-js/modules/es.typed-array.sort.js","core-js/modules/es.typed-array.subarray.js","core-js/modules/es.typed-array.to-locale-string.js","core-js/modules/es.typed-array.to-string.js","core-js/modules/es.regexp.to-string.js","core-js/modules/es.array.slice.js","core-js/modules/es.function.name.js","core-js/modules/es.array.join.js","core-js/modules/es.regexp.exec.js","core-js/modules/es.regexp.test.js","core-js/modules/es.object.keys.js","core-js/modules/es.regexp.flags.js","core-js/modules/web.dom-collections.iterator.js","core-js/modules/es.string.pad-start.js","core-js/modules/es.array.find.js","core-js/modules/es.array.from.js","core-js/modules/es.string.iterator.js","core-js/modules/es.array-buffer.constructor.js","core-js/modules/es.object.assign.js","core-js/modules/es.typed-array.int8-array.js","core-js/modules/es.typed-array.uint8-clamped-array.js","core-js/modules/es.typed-array.int16-array.js","core-js/modules/es.typed-array.uint16-array.js","core-js/modules/es.typed-array.int32-array.js","core-js/modules/es.typed-array.uint32-array.js","core-js/modules/es.typed-array.float32-array.js","core-js/modules/es.typed-array.float64-array.js"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).XGPlayerTransmuxer=t()}(this,(function(){"use strict";function e(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function t(t){for(var a=1;a<arguments.length;a++){var r=null!=arguments[a]?arguments[a]:{};a%2?e(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e,t,a){return t&&r(e.prototype,t),a&&r(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function l(e,t,a){return(l=c()?Reflect.construct.bind():function(e,t,a){var r=[null];r.push.apply(r,t);var s=new(Function.bind.apply(e,r));return a&&u(s,a.prototype),s}).apply(null,arguments)}function d(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function f(e){var t=c();return function(){var a,r=o(e);if(t){var s=o(this).constructor;a=Reflect.construct(r,arguments,s)}else a=r.apply(this,arguments);return d(this,a)}}function h(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}function p(){return p="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,a){var r=h(e,t);if(r){var s=Object.getOwnPropertyDescriptor(r,t);return s.get?s.get.call(arguments.length<3?e:a):s.value}},p.apply(this,arguments)}function v(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==a)return;var r,s,i=[],n=!0,o=!1;try{for(a=a.call(e);!(n=(r=a.next()).done)&&(i.push(r.value),!t||i.length!==t);n=!0);}catch(u){o=!0,s=u}finally{try{n||null==a.return||a.return()}finally{if(o)throw s}}return i}(e,t)||m(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e){return function(e){if(Array.isArray(e))return g(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||m(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){if(e){if("string"==typeof e)return g(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,r=new Array(t);a<t;a++)r[a]=e[a];return r}var k={VIDEO:"video",AUDIO:"audio",METADATA:"metadata"},b={AVC:"avc",HEVC:"hevc"},_={AAC:"aac",G711PCMA:"g7110a",G711PCMU:"g7110m"},x={LARGE_AV_SHIFT:"LARGE_AV_SHIFT",LARGE_VIDEO_GAP:"LARGE_VIDEO_GAP",LARGE_VIDEO_GAP_BETWEEN_CHUNK:"LARGE_VIDEO_GAP_BETWEEN_CHUNK",LARGE_AUDIO_GAP:"LARGE_AUDIO_GAP",AUDIO_FILLED:"AUDIO_FILLED",AUDIO_DROPPED:"AUDIO_DROPPED"},w=function(){function e(){a(this,e),i(this,"id",1),i(this,"type",k.VIDEO),i(this,"codecType",b.AVC),i(this,"pid",-1),i(this,"hvcC",void 0),i(this,"codec",""),i(this,"timescale",0),i(this,"formatTimescale",0),i(this,"sequenceNumber",0),i(this,"baseMediaDecodeTime",0),i(this,"baseDts",0),i(this,"duration",0),i(this,"warnings",[]),i(this,"samples",[]),i(this,"pps",[]),i(this,"sps",[]),i(this,"vps",[]),i(this,"fpsNum",0),i(this,"fpsDen",0),i(this,"sarRatio",[]),i(this,"width",0),i(this,"height",0),i(this,"nalUnitSize",4),i(this,"present",!1),i(this,"isVideoEncryption",!1),i(this,"isAudioEncryption",!1),i(this,"isVideo",!0),i(this,"kid",null),i(this,"pssh",null),i(this,"ext",void 0)}return s(e,[{key:"reset",value:function(){this.sequenceNumber=this.width=this.height=this.fpsDen=this.fpsNum=this.duration=this.baseMediaDecodeTime=this.timescale=0,this.codec="",this.present=!1,this.pid=-1,this.pps=[],this.sps=[],this.vps=[],this.sarRatio=[],this.samples=[],this.warnings=[],this.hvcC=null}},{key:"exist",value:function(){return!!(this.pps.length&&this.sps.length&&this.codec)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isVideoEncryption}}]),e}(),D=function(){function e(){a(this,e),i(this,"id",2),i(this,"type",k.AUDIO),i(this,"codecType",_.AAC),i(this,"pid",-1),i(this,"codec",""),i(this,"sequenceNumber",0),i(this,"sampleDuration",0),i(this,"timescale",0),i(this,"formatTimescale",0),i(this,"baseMediaDecodeTime",0),i(this,"duration",0),i(this,"warnings",[]),i(this,"samples",[]),i(this,"baseDts",0),i(this,"sampleSize",16),i(this,"sampleRate",0),i(this,"channelCount",0),i(this,"objectType",0),i(this,"sampleRateIndex",0),i(this,"config",[]),i(this,"present",!1),i(this,"isVideoEncryption",!1),i(this,"isAudioEncryption",!1),i(this,"kid",null),i(this,"ext",void 0)}return s(e,[{key:"reset",value:function(){this.sequenceNumber=0,this.timescale=0,this.sampleDuration=0,this.sampleRate=0,this.channelCount=0,this.baseMediaDecodeTime=0,this.present=!1,this.pid=-1,this.codec="",this.samples=[],this.config=[],this.warnings=[]}},{key:"exist",value:function(){return!!(this.sampleRate&&this.channelCount&&this.codec&&this.codecType===_.AAC)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isAudioEncryption}}]),e}(),S=function(){function e(t,r,s){a(this,e),i(this,"flag",{}),i(this,"keyframe",!1),i(this,"gopId",0),i(this,"duration",0),i(this,"size",0),i(this,"units",[]),i(this,"chromaFormat",420),this.originPts=this.pts=t,this.originDts=this.dts=r,s&&(this.units=s)}return s(e,[{key:"cts",get:function(){return this.pts-this.dts}},{key:"setToKeyframe",value:function(){this.keyframe=!0,this.flag.dependsOn=2,this.flag.isNonSyncSample=0}}]),e}(),A=s((function e(t,r,s,n){a(this,e),i(this,"duration",1024),i(this,"flag",{dependsOn:2,isNonSyncSample:0}),i(this,"keyframe",!0),this.originPts=this.pts=this.dts=t,this.data=r,this.size=r.byteLength,this.sampleOffset=n,s&&(this.duration=s)})),T=s((function e(t,r){a(this,e),i(this,"time",0),this.data=t,this.originPts=this.pts=r})),j=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(T),E=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(T),B=function(){function e(){a(this,e),i(this,"id",3),i(this,"type",k.METADATA),i(this,"timescale",0),i(this,"flvScriptSamples",[]),i(this,"seiSamples",[])}return s(e,[{key:"exist",value:function(){return!(!this.flvScriptSamples.length&&!this.seiSamples.length||!this.timescale)}},{key:"reset",value:function(){this.timescale=0,this.flvScriptSamples=[],this.seiSamples=[]}},{key:"hasSample",value:function(){return!(!this.flvScriptSamples.length&&!this.seiSamples.length)}}]),e}(),C=Object.freeze(Object.defineProperty({__proto__:null,VideoTrack:w,AudioTrack:D,VideoSample:S,AudioSample:A,FlvScriptSample:j,SeiSample:E,MetadataTrack:B,TrackType:k,VideoCodecType:b,AudioCodecType:_,WarningType:x},Symbol.toStringTag,{value:"Module"})),P=function(){function e(t){if(a(this,e),i(this,"_bytesAvailable",void 0),i(this,"_bitsAvailable",0),i(this,"_word",0),!t)throw new Error("ExpGolomb data params is required");this._data=t,this._bytesAvailable=t.byteLength,this._bytesAvailable&&this._loadWord()}return s(e,[{key:"_loadWord",value:function(){var e=this._data.byteLength-this._bytesAvailable,t=Math.min(4,this._bytesAvailable);if(0===t)throw new Error("No bytes available");var a=new Uint8Array(4);a.set(this._data.subarray(e,e+t)),this._word=new DataView(a.buffer).getUint32(0),this._bitsAvailable=8*t,this._bytesAvailable-=t}},{key:"skipBits",value:function(e){if(this._bitsAvailable>e)this._word<<=e,this._bitsAvailable-=e;else{e-=this._bitsAvailable;var t=Math.floor(e/8);e-=8*t,this._bytesAvailable-=t,this._loadWord(),this._word<<=e,this._bitsAvailable-=e}}},{key:"readBits",value:function(e){if(e>32)throw new Error("Cannot read more than 32 bits");var t=Math.min(this._bitsAvailable,e),a=this._word>>>32-t;return this._bitsAvailable-=t,this._bitsAvailable>0?this._word<<=t:this._bytesAvailable>0&&this._loadWord(),(t=e-t)>0&&this._bitsAvailable?a<<t|this.readBits(t):a}},{key:"skipLZ",value:function(){var e;for(e=0;e<this._bitsAvailable;++e)if(0!=(this._word&2147483648>>>e))return this._word<<=e,this._bitsAvailable-=e,e;return this._loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBool",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"skipScalingList",value:function(e){for(var t=8,a=8,r=0;r<e;r++)0!==a&&(a=(t+this.readEG()+256)%256),t=0===a?t:a}}]),e}(),U=function(){function e(t){a(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]")}return s(e,[{key:"warn",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).warn.apply(t,[this._prefix].concat(r))}}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();i(U,"disabled",!0);var I=function(){function e(){a(this,e)}return s(e,null,[{key:"decode",value:function(t){for(var a=[],r=t,s=0,i=t.length;s<i;)if(r[s]<128)a.push(String.fromCharCode(r[s])),++s;else{if(r[s]<192);else if(r[s]<224){if(e._checkContinuation(r,s,1)){var n=(31&r[s])<<6|63&r[s+1];if(n>=128){a.push(String.fromCharCode(65535&n)),s+=2;continue}}}else if(r[s]<240){if(e._checkContinuation(r,s,2)){var o=(15&r[s])<<12|(63&r[s+1])<<6|63&r[s+2];if(o>=2048&&55296!=(63488&o)){a.push(String.fromCharCode(65535&o)),s+=3;continue}}}else if(r[s]<248&&e._checkContinuation(r,s,3)){var u=(7&r[s])<<18|(63&r[s+1])<<12|(63&r[s+2])<<6|63&r[s+3];if(u>65536&&u<1114112){u-=65536,a.push(String.fromCharCode(u>>>10|55296)),a.push(String.fromCharCode(1023&u|56320)),s+=4;continue}}a.push(String.fromCharCode(65533)),++s}return a.join("")}},{key:"_checkContinuation",value:function(e,t,a){var r=e;if(t+a<r.length){for(;a--;)if(128!=(192&r[++t]))return!1;return!0}return!1}}]),e}(),M="undefined"!=typeof window,O=M&&navigator.userAgent.toLocaleLowerCase(),z=M&&/^((?!chrome|android).)*safari/.test(O),R=M&&O.includes("firefox"),V=M&&O.includes("android");function L(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];t=t.filter(Boolean);var r=new Uint8Array(t.reduce((function(e,t){return e+t.byteLength}),0)),s=0;return t.forEach((function(e){r.set(e,s),s+=e.byteLength})),r}var N=Math.pow(2,32);function F(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<8)+(e[t+1]||0)}function G(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+(e[t+3]||0)}function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return G(e,t)*N+G(e,t+4)}function H(e){for(var t,a="avc1.",r=0;r<3;r++)(t=e[r].toString(16)).length<2&&(t="0".concat(t)),a+=t;return a}function K(e){var t="";if(e.forEach((function(e){t+=function(e){return("0"+Number(e).toString(16)).slice(-2).toUpperCase()}(e)})),t.length<=32)for(var a=32-t.length,r=0;r<a;r++)t+="0";return t}function W(e){if(!Array.isArray(e)){for(var t=[],a="",r=0;r<e.length;r++)r%2&&(a=e[r-1]+e[r],t.push(parseInt(a,16)),a="");return t}return e.map((function(e){return parseInt(e,16)}))}var X=function(){function e(){a(this,e)}return s(e,null,[{key:"parseAnnexB",value:function(e){for(var t=e.length,a=2,r=0;null!==e[a]&&void 0!==e[a]&&1!==e[a];)a++;if((r=++a+2)>=t)return[];for(var s=[];r<t;)switch(e[r]){case 0:if(0!==e[r-1]){r+=2;break}if(0!==e[r-2]){r++;break}a!==r-2&&s.push(e.subarray(a,r-2));do{r++}while(1!==e[r]&&r<t);r=(a=r+1)+2;break;case 1:if(0!==e[r-1]||0!==e[r-2]){r+=3;break}a!==r-2&&s.push(e.subarray(a,r-2)),r=(a=r+1)+2;break;default:r+=3}return a<t&&s.push(e.subarray(a)),s}},{key:"parseAvcC",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(!(e.length<4)){for(var a,r=e.length,s=[],i=0;i+t<r;)if(a=G(e,i),3===t&&(a>>>=8),i+=t,a){if(i+a>r)break;s.push(e.subarray(i,i+a)),i+=a}return s}}},{key:"parseSEI",value:function(e,t){for(var a=e.length,r=t?2:1,s=0,i=0,n="";255===e[r];)s+=255,r++;for(s+=e[r++];255===e[r];)i+=255,r++;if(i+=e[r++],5===s&&a>r+16)for(var o=0;o<16;o++)n+=e[r].toString(16),r++;return{payload:e.subarray(r),type:s,size:i,uuid:n}}},{key:"removeEPB",value:function(e){for(var t=e.byteLength,a=[],r=1;r<t-2;)0===e[r]&&0===e[r+1]&&3===e[r+2]?(a.push(r+2),r+=2):r++;if(!a.length)return e;var s=t-a.length,i=new Uint8Array(s),n=0;for(r=0;r<s;n++,r++)n===a[0]&&(n++,a.shift()),i[r]=e[n];return i}}]),e}(),Y=function(){function e(){a(this,e)}return s(e,null,[{key:"parseAVCDecoderConfigurationRecord",value:function(t){if(!(t.length<7)){for(var a,r,s=1+(3&t[4]),i=[],n=[],o=6,u=31&t[5],c=0;c<u;c++)if(r=t[o]<<8|t[o+1],o+=2,r){var l=t.subarray(o,o+r);o+=r,i.push(l),a||(a=e.parseSPS(X.removeEPB(l)))}var d,f=t[o];o++;for(var h=0;h<f;h++)d=t[o]<<8|t[o+1],o+=2,d&&(n.push(t.subarray(o,o+d)),o+=d);return{sps:a,spsArr:i,ppsArr:n,nalUnitSize:s}}}},{key:"parseSPS",value:function(e){var t=new P(e);t.readUByte();var a=t.readUByte(),r=t.readUByte(),s=t.readUByte();t.skipUEG();var i=420;if(100===a||110===a||122===a||244===a||44===a||83===a||86===a||118===a||128===a||138===a||144===a){var n=t.readUEG();if(n<=3&&(i=[0,420,422,444][n]),3===n&&t.skipBits(1),t.skipUEG(),t.skipUEG(),t.skipBits(1),t.readBool())for(var o=3!==n?8:12,u=0;u<o;u++)t.readBool()&&(u<6?t.skipScalingList(16):t.skipScalingList(64))}t.skipUEG();var c=t.readUEG();if(0===c)t.readUEG();else if(1===c){t.skipBits(1),t.skipUEG(),t.skipUEG();for(var l=t.readUEG(),d=0;d<l;d++)t.skipUEG()}t.skipUEG(),t.skipBits(1);var f=t.readUEG(),h=t.readUEG(),p=t.readBits(1);0===p&&t.skipBits(1),t.skipBits(1);var v,y,m,g,k,b=0,_=0,x=0,w=0;if(t.readBool()&&(b=t.readUEG(),_=t.readUEG(),x=t.readUEG(),w=t.readUEG()),t.readBool()){if(t.readBool())switch(t.readUByte()){case 1:v=[1,1];break;case 2:v=[12,11];break;case 3:v=[10,11];break;case 4:v=[16,11];break;case 5:v=[40,33];break;case 6:v=[24,11];break;case 7:v=[20,11];break;case 8:v=[32,11];break;case 9:v=[80,33];break;case 10:v=[18,11];break;case 11:v=[15,11];break;case 12:v=[64,33];break;case 13:v=[160,99];break;case 14:v=[4,3];break;case 15:v=[3,2];break;case 16:v=[2,1];break;case 255:v=[t.readUByte()<<8|t.readUByte(),t.readUByte()<<8|t.readUByte()]}if(t.readBool()&&t.readBool(),t.readBool()&&(t.readBits(4),t.readBool()&&t.readBits(24)),t.readBool()&&(t.readUEG(),t.readUEG()),t.readBool()){var D=t.readBits(32),S=t.readBits(32);y=t.readBool(),k=(m=S)/(g=2*D)}}return{codec:H(e.subarray(1,4)),profileIdc:a,profileCompatibility:r,levelIdc:s,chromaFormat:i,width:Math.ceil(16*(f+1)-2*(b+_)),height:(2-p)*(h+1)*16-(p?2:4)*(x+w),sarRatio:v,fpsNum:m,fpsDen:g,fps:k,fixedFrame:y}}}]),e}(),Z=function(){function e(){a(this,e)}return s(e,null,[{key:"getRateIndexByRate",value:function(t){return e.FREQ.indexOf(t)}},{key:"parseADTS",value:function(t,a){for(var r=t.length,s=0;s+2<r&&(255!==t[s]||240!=(246&t[s+1]));)s++;if(!(s>=r)){var i=s,n=[],o=(60&t[s+2])>>>2,u=e.FREQ[o];if(!u)throw new Error("Invalid sampling index: ".concat(o));for(var c,l,d=1+((192&t[s+2])>>>6),f=(1&t[s+2])<<2|(192&t[s+3])>>>6,h=e._getConfig(o,f,d),p=h.config,v=h.codec,y=0,m=e.getFrameDuration(u);s+7<r;)if(255===t[s]&&240==(246&t[s+1])){if(r-s<(l=(3&t[s+3])<<11|t[s+4]<<3|(224&t[s+5])>>5))break;c=2*(1&~t[s+1]),n.push({pts:a+y*m,data:t.subarray(s+7+c,s+l)}),y++,s+=l}else s++;return{skip:i,remaining:s>=r?void 0:t.subarray(s),frames:n,samplingFrequencyIndex:o,sampleRate:u,objectType:d,channelCount:f,codec:v,config:p,originCodec:"mp4a.40.".concat(d)}}}},{key:"parseAudioSpecificConfig",value:function(t){if(t.length){var a=t[0]>>>3,r=(7&t[0])<<1|t[1]>>>7,s=(120&t[1])>>>3,i=e.FREQ[r];if(i){var n=e._getConfig(r,s,a);return{samplingFrequencyIndex:r,sampleRate:i,objectType:a,channelCount:s,config:n.config,codec:n.codec,originCodec:"mp4a.40.".concat(a)}}}}},{key:"getFrameDuration",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return 1024*t/e}},{key:"_getConfig",value:function(e,t,a){var r,s,i=[];return R?e>=6?(r=5,s=e-3):(r=2,s=e):V?(r=2,s=e):(r=2===a||5===a?a:5,s=e,e>=6?s=e-3:1===t&&(r=2,s=e)),i[0]=r<<3,i[0]|=(14&e)>>1,i[1]=(1&e)<<7,i[1]|=t<<3,5===r&&(i[1]|=(14&s)>>1,i[2]=(1&s)<<7,i[2]|=8,i[3]=0),{config:i,codec:"mp4a.40.".concat(r)}}},{key:"getSilentFrame",value:function(e,t){if("mp4a.40.2"===e){if(1===t)return new Uint8Array([0,200,0,128,35,128]);if(2===t)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224])}else{if(1===t)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}}}]),e}();i(Z,"FREQ",[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]);var Q=function(){function e(){a(this,e)}return s(e,null,[{key:"parseHEVCDecoderConfigurationRecord",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(t.length<23)){a=a||{};for(var r,s,i,n,o,u=1+(3&t[21]),c=[],l=[],d=[],f=23,h=t[22],p=0;p<h;p++){i=63&t[f],n=t[f+1]<<8|t[f+2],f+=3;for(var v=0;v<n;v++)if(o=t[f]<<8|t[f+1],f+=2,o){switch(i){case 32:var y=t.subarray(f,f+o);r||(r=e.parseVPS(X.removeEPB(y),a)),d.push(y);break;case 33:var m=t.subarray(f,f+o);s||(s=e.parseSPS(X.removeEPB(m),a)),c.push(m);break;case 34:l.push(t.subarray(f,f+o))}f+=o}}return{hvcC:a,sps:s,spsArr:c,ppsArr:l,vpsArr:d,nalUnitSize:u}}}},{key:"parseVPS",value:function(t,a){a=a||{};var r=new P(t);r.readUByte(),r.readUByte(),r.readBits(12);var s=r.readBits(3);return a.numTemporalLayers=Math.max(a.numTemporalLayers||0,s+1),r.readBits(17),e._parseProfileTierLevel(r,s,a),a}},{key:"parseSPS",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a=a||{};var r=new P(t);r.readUByte(),r.readUByte(),r.readBits(4);var s=r.readBits(3);a.numTemporalLayers=Math.max(s+1,a.numTemporalLayers||0),a.temporalIdNested=r.readBits(1),e._parseProfileTierLevel(r,s,a),r.readUEG();var i=a.chromaFormatIdc=r.readUEG(),n=420;i<=3&&(n=[0,420,422,444][i]);var o=0;3===i&&(o=r.readBits(1));var u,c,l,d,f=r.readUEG(),h=r.readUEG(),p=r.readBits(1);if(1===p&&(u=r.readUEG(),c=r.readUEG(),l=r.readUEG(),d=r.readUEG()),a.bitDepthLumaMinus8=r.readUEG(),a.bitDepthChromaMinus8=r.readUEG(),1===p){var v=1!==i&&2!==i||0!==o?1:2,y=1===i&&0===o?2:1;f-=v*(c+u),h-=y*(d+l)}return{codec:"hev1.1.6.L93.B0",width:f,height:h,chromaFormat:n,hvcC:a}}},{key:"_parseProfileTierLevel",value:function(e,t,a){var r=a.generalTierFlag||0;a.generalProfileSpace=e.readBits(2),a.generalTierFlag=Math.max(e.readBits(1),r),a.generalProfileIdc=Math.max(e.readBits(5),a.generalProfileIdc||0),a.generalProfileCompatibilityFlags=e.readBits(32),a.generalConstraintIndicatorFlags=[e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8)];var s=e.readBits(8);r<a.generalTierFlag?a.generalLevelIdc=s:a.generalLevelIdc=Math.max(s,a.generalLevelIdc||0);for(var i=[],n=[],o=0;o<t;o++)i[o]=e.readBits(1),n[o]=e.readBits(1);t>0&&e.readBits(2*(8-t));for(var u=0;u<t;u++)0!==i[u]&&(e.readBits(2),e.readBits(1),e.readBits(5),e.readBits(16),e.readBits(16),e.readBits(4),e.readBits(16),e.readBits(16),e.readBits(12)),0!==n[u]&&e.readBits(8)}}]),e}(),J=1e3,$=5e3,ee=function(){function e(t,r,s){a(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=s,this._baseDts=-1,this._baseDtsInited=!1,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=0,this._videoTimestampBreak=0,this._lastAudioExceptionGapDot=-1/0,this._lastAudioExceptionOverlapDot=-1/0,this._lastAudioExceptionLargeGapDot=-1/0,this._lastVideoExceptionLargeGapDot=-1/0,this._lastVideoExceptionChunkFirstDtsDot=-1/0}return s(e,[{key:"fix",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=Math.round(1e3*t);var s=this.videoTrack,i=this.audioTrack;if(!a&&r||(this._videoLastSample=null,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=0,this._videoTimestampBreak=0,this._lastAudioExceptionGapDot=-1/0,this._lastAudioExceptionOverlapDot=-1/0,this._lastAudioExceptionLargeGapDot=-1/0,this._lastVideoExceptionLargeGapDot=-1/0,this._lastVideoExceptionChunkFirstDtsDot=-1/0),a&&!r&&(this._baseDtsInited=!1),this._baseDtsInited||this._calculateBaseDts(i,s),this._baseDtsInited){if(!r&&t&&(this._audioNextPts=this._videoNextDts=t),this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(i),this._fixVideo(s),this.metadataTrack.exist()){var n=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/n})),this.metadataTrack.flvScriptSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/n}))}s.samples.length&&(s.baseMediaDecodeTime=s.samples[0].dts),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts*i.timescale/1e3)}}},{key:"_fixVideo",value:function(e){var t=this,a=e.samples;if(a.length){var r;if(a.forEach((function(e){e.dts-=t._baseDts,e.pts-=t._baseDts})),e.fpsNum&&e.fpsDen)r=e.timescale*(e.fpsDen/e.fpsNum);else{var s=e.samples[0],i=e.samples[a.length-1];r=Math.floor((i.dts-s.dts)/(a.length-1))}var n=a.pop();if(this._videoLastSample&&a.unshift(this._videoLastSample),this._videoLastSample=n,a.length){if(void 0===this._videoNextDts){var o=a[0];this._videoNextDts=o.dts}var u=a.length,c=0,l=a[0],d=this._videoNextDts-l.dts;if(Math.abs(d)>200){var f;if(Math.abs(l.dts-this._lastVideoExceptionChunkFirstDtsDot)>5e3)this._lastVideoExceptionChunkFirstDtsDot=l.dts,e.warnings.push({type:x.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts,firstSampleDts:l.dts,nextSampleDts:null===(f=a[1])||void 0===f?void 0:f.dts,sampleDuration:d});this._videoTimestampBreak>=5?(this._videoNextDts=l.dts,this._videoTimestampBreak=0):(l.dts+=d,l.pts+=d)}for(var h=0;h<u;h++){var p=a[h].dts,v=a[h+1];((c=h<u-1?v.dts-p:n?n.dts-p:r)>1e3||c<0)&&(this._videoTimestampBreak++,Math.abs(p-this._lastVideoExceptionLargeGapDot)>5e3&&(this._lastVideoExceptionLargeGapDot=p,e.warnings.push({type:x.LARGE_VIDEO_GAP,time:p/e.timescale,dts:p,originDts:a[h].originDts,nextDts:this._videoNextDts,sampleDuration:c,refSampleDuration:r})),c=r),a[h].duration=c,this._videoNextDts+=c}}}}},{key:"_fixAudio",value:function(e){var t=this,a=e.samples;a.length&&(a.forEach((function(e){e.dts=e.pts-=t._baseDts})),this._doFixAudioInternal(e,a,1e3))}},{key:"_calculateBaseDts",value:function(e,t){var a=e.samples,r=t.samples;if(!a.length&&!r.length)return!1;var s=1/0,i=1/0;a.length&&(e.baseDts=s=a[0].pts),r.length&&(t.baseDts=i=r[0].dts),this._baseDts=Math.min(s,i);var n=i-s;return Number.isFinite(n)&&Math.abs(n)>500&&t.warnings.push({type:x.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){if(this._baseDtsInited&&this._videoTimestampBreak&&this._audioTimestampBreak){if(!this._calculateBaseDts(this.audioTrack,this.videoTrack))return;this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts),this._videoLastSample=null,this._videoTimestampBreak=0,this._audioTimestampBreak=0}}},{key:"_doFixAudioInternal",value:function(e,t,a){e.sampleDuration||(e.sampleDuration=e.codecType===_.AAC?Z.getFrameDuration(e.timescale,a):this._getG711Duration(e));var r=e.sampleDuration,s=e.codecType===_.AAC?1024:r*e.timescale/1e3;if(void 0===this._audioNextPts){var i=t[0];this._audioNextPts=i.pts}for(var n=0;n<t.length;n++){var o=this._audioNextPts,u=t[n],c=u.pts-o;if(0===n&&this._audioTimestampBreak>=5&&(o=this._audioNextPts=u.dts,c=0,this._audioTimestampBreak=0),!this._audioTimestampBreak&&c>=3*r&&c<=J&&!z){var l=this._getSilentFrame(e)||t[0].data.subarray(),d=Math.floor(c/r);Math.abs(u.pts-this._lastAudioExceptionGapDot)>$&&(this._lastAudioExceptionGapDot=u.pts,e.warnings.push({type:x.AUDIO_FILLED,pts:u.pts,originPts:u.originPts,count:d,nextPts:o,refSampleDuration:r}));for(var f=0;f<d;f++){var h=new A(Math.floor(this._audioNextPts+r)-Math.floor(this._audioNextPts),l,s);h.originPts=Math.floor(this._baseDts+o),t.splice(n,0,h),this._audioNextPts+=r,n++}n--}else c<=-3*r&&c>=-1e3?(Math.abs(u.pts-this._lastAudioExceptionOverlapDot)>$&&(this._lastAudioExceptionOverlapDot=u.pts,e.warnings.push({type:x.AUDIO_DROPPED,pts:u.pts,originPts:u.originPts,nextPts:o,refSampleDuration:r})),t.splice(n,1),n--):(Math.abs(c)>J&&(this._audioTimestampBreak++,Math.abs(u.pts-this._lastAudioExceptionLargeGapDot)>$&&(this._lastAudioExceptionLargeGapDot=u.pts,e.warnings.push({type:x.LARGE_AUDIO_GAP,time:u.pts/1e3,pts:u.pts,originPts:u.originPts,nextPts:o,sampleDuration:c,refSampleDuration:r}))),u.dts=u.pts=o,u.duration=s,this._audioNextPts+=r)}}},{key:"_getG711Duration",value:function(e){var t=e.sampleSize,a=e.channelCount,r=e.sampleRate,s=e.samples[0];if(s)return 2*s.data.byteLength/a/(t/8)/r*1e3}},{key:"_getSilentFrame",value:function(e){return e.codecType===_.AAC?Z.getSilentFrame(e.codec,e.channelCount):new Uint8Array(8*e.sampleDuration*e.channelCount)}}]),e}(),te=function(){function e(){a(this,e)}return s(e,null,[{key:"parse",value:function(t){if(!(t.length<3)){var a={},r=e._parseValue(new DataView(t.buffer,t.byteOffset,t.byteLength)),s=e._parseValue(new DataView(t.buffer,t.byteOffset+r.size,t.byteLength-r.size));return a[r.data]=s.data,a}}},{key:"_parseValue",value:function(t){var a,r=t.byteLength,s=1,i=!1;switch(t.getUint8(0)){case 0:a=t.getFloat64(1),s+=8;break;case 1:a=!!t.getUint8(1),s+=1;break;case 2:var n=e._parseString(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s));a=n.data,s+=n.size;break;case 3:a={};var o=0;for(9==(16777215&t.getUint32(r-4))&&(o=3);s<r-4;){var u=e._parseObject(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s-o)),c=u.size,l=u.data;if(u.isEnd)break;a[l.name]=l.value,s+=c}if(s<=r-3)9===(16777215&t.getUint32(s-1))&&(s+=3);break;case 8:a={},s+=4;var d=0;for(9==(16777215&t.getUint32(r-4))&&(d=3);s<r-8;){var f=e._parseObject(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s-d)),h=f.size,p=f.data;if(f.isEnd)break;a[p.name]=p.value,s+=h}if(s<=r-3)9===(16777215&t.getUint32(s-1))&&(s+=3);break;case 9:a=void 0,s=1,i=!0;break;case 10:a=[];var v=t.getUint32(1);s+=4;for(var y=0;y<v;y++){var m=e._parseValue(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s)),g=m.data,k=m.size;a.push(g),s+=k}break;case 11:var b=t.getFloat64(s)+6e4*t.getInt16(s+8);a=new Date(b),s+=10;break;case 12:var _=t.getUint32(1);s+=4,a="",_>0&&(a=I.decode(new Uint8Array(t.buffer,t.byteOffset+s,_))),s+=_;break;default:s=r}return{data:a,size:s,isEnd:i}}},{key:"_parseString",value:function(e){var t=e.getUint16(0),a="";return t>0&&(a=I.decode(new Uint8Array(e.buffer,e.byteOffset+2,t))),{data:a,size:2+t}}},{key:"_parseObject",value:function(t){if(!(t.byteLength<3)){var a=e._parseString(t),r=e._parseValue(new DataView(t.buffer,t.byteOffset+a.size,t.byteLength-a.size));return{data:{name:a.data,value:r.data},size:a.size+r.size,isEnd:r.isEnd}}}}]),e}(),ae=new U("FlvDemuxer"),re=function(){function e(t,r,s){a(this,e),i(this,"_headerParsed",!1),i(this,"_remainingData",null),i(this,"_gopId",0),i(this,"_needAddMetaBeforeKeyFrameNal",!0),this.videoTrack=t||new w,this.audioTrack=r||new D,this.metadataTrack=s||new B,this._fixer=new ee(this.videoTrack,this.audioTrack,this.metadataTrack)}return s(e,[{key:"demux",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],s=this.audioTrack,i=this.videoTrack,n=this.metadataTrack;if(!a&&r||(this._remainingData=null,this._headerParsed=!1),a?(i.reset(),s.reset(),n.reset()):(i.samples=[],s.samples=[],n.seiSamples=[],n.flvScriptSamples=[],i.warnings=[],s.warnings=[],this._remainingData&&(t=L(this._remainingData,t),this._remainingData=null)),!t.length)return{videoTrack:i,audioTrack:s,metadataTrack:n};var o=0;if(!this._headerParsed){if(!e.probe(t))throw new Error("Invalid flv file");s.present=(4&t[4])>>>2!=0,i.present=0!=(1&t[4]),this._headerParsed=!0,o=G(t,5)+4}for(var u,c,l,d,f,h=t.length;o+15<h&&(u=t[o],!(o+15+(c=t[o+1]<<16|t[o+2]<<8|t[o+3])>h));)l=(t[o+7]<<24>>>0)+(t[o+4]<<16)+(t[o+5]<<8)+t[o+6],o+=11,d=t.subarray(o,o+c),8===u?this._parseAudio(d,l):9===u?this._parseVideo(d,l):18===u?this._parseScript(d,l):ae.warn("Invalid tag type: ".concat(u)),(f=G(t,o+=c))!==11+c&&ae.warn("Invalid PrevTagSize ".concat(f," (").concat(11+c,")")),o+=4;return o<h&&(this._remainingData=t.subarray(o)),s.formatTimescale=i.formatTimescale=i.timescale=n.timescale=1e3,s.timescale=s.sampleRate||0,!s.exist()&&s.hasSample()&&s.reset(),!i.exist()&&i.hasSample()&&i.reset(),{videoTrack:i,audioTrack:s,metadataTrack:n}}},{key:"fix",value:function(e,t,a){return this._fixer.fix(e,t,a),{videoTrack:this.videoTrack,audioTrack:this.audioTrack,metadataTrack:this.metadataTrack}}},{key:"demuxAndFix",value:function(e,t,a,r){return this.demux(e,t,a),this.fix(r,t,a)}},{key:"_parseAudio",value:function(t,a){if(t.length){var r=(240&t[0])>>>4,s=this.audioTrack;if(10!==r&&7!==r&&8!==r)return ae.warn("Unsupported sound format: ".concat(r)),void s.reset();if(10!==r){var i=(12&t[0])>>2,n=(2&t[0])>>1,o=1&t[0];s.sampleRate=e.AUDIO_RATE[i],s.sampleSize=n?16:8,s.channelCount=o+1}10===r?this._parseAac(t,a):this._parseG711(t,a,r)}}},{key:"_parseG711",value:function(e,t,a){var r=this.audioTrack;r.codecType=7===a?_.G711PCMA:_.G711PCMU,r.sampleRate=8e3,r.codec=r.codecType,r.samples.push(new A(t,e.subarray(1)))}},{key:"_parseAac",value:function(e,t){var a=this.audioTrack;if(a.codecType=_.AAC,0===e[1]){var r=Z.parseAudioSpecificConfig(e.subarray(2));r?(a.codec=r.codec,a.channelCount=r.channelCount,a.sampleRate=r.sampleRate,a.config=r.config,a.objectType=r.objectType,a.sampleRateIndex=r.samplingFrequencyIndex):(a.reset(),ae.warn("Cannot parse AudioSpecificConfig",e))}else if(1===e[1]){if(null==t)return;a.samples.push(new A(t,e.subarray(2)))}else ae.warn("Unknown AACPacketType: ".concat(e[1]))}},{key:"_parseVideo",value:function(e,t){var a=this;if(!(e.length<6)){var r=(240&e[0])>>>4,s=15&e[0],i=this.videoTrack;if(7!==s&&12!==s)return i.reset(),void ae.warn("Unsupported codecId: ".concat(s));var n=12===s;i.codecType=n?b.HEVC:b.AVC;var o=e[1],u=(e[2]<<16|e[3]<<8|e[4])<<8>>8;if(0===o){var c=e.subarray(5),l=n?Q.parseHEVCDecoderConfigurationRecord(c):Y.parseAVCDecoderConfigurationRecord(c);if(l){var d=l.hvcC,f=l.sps,h=l.ppsArr,p=l.spsArr,v=l.vpsArr,y=l.nalUnitSize;d&&(i.hvcC=i.hvcC||d),f&&(i.codec=f.codec,i.width=f.width,i.height=f.height,i.sarRatio=f.sarRatio,i.fpsNum=f.fpsNum,i.fpsDen=f.fpsDen),p.length&&(i.sps=p),h.length&&(i.pps=h),v&&v.length&&(i.vps=v),y&&(i.nalUnitSize=y)}else ae.warn("Cannot parse ".concat(n?"HEVC":"AVC","DecoderConfigurationRecord"),e)}else if(1===o){var m=X.parseAvcC(e.subarray(5),i.nalUnitSize);if((m=this._checkAddMetaNalToUnits(n,m,i))&&m.length){var g=new S(t+u,t,m);1===r&&g.setToKeyframe(),i.samples.push(g),m.forEach((function(e){var r=n?e[0]>>>1&63:31&e[0];switch(r){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!n&&5!==r||n&&5===r)break;g.setToKeyframe();break;case 6:case 39:case 40:if(!n&&6!==r||n&&6===r)break;a.metadataTrack.seiSamples.push(new E(X.parseSEI(X.removeEPB(e),n),t+u))}})),g.keyframe&&this._gopId++,g.gopId=this._gopId}else ae.warn("Cannot parse NALUs",e)}else 2===o||ae.warn("Unknown AVCPacketType: ".concat(o))}}},{key:"_checkAddMetaNalToUnits",value:function(e,t,a){return e&&this._needAddMetaBeforeKeyFrameNal?t.map((function(e){return e[0]>>>1&63})).includes(32)?(this._needAddMetaBeforeKeyFrameNal=!1,t):(t.unshift(a.pps[0]),t.unshift(a.sps[0]),t.unshift(a.vps[0]),t.filter(Boolean)):(this._needAddMetaBeforeKeyFrameNal=!1,t)}},{key:"_parseScript",value:function(e,t){this.metadataTrack.flvScriptSamples.push(new j(te.parse(e),t))}}],[{key:"probe",value:function(e){return 70===e[0]&&76===e[1]&&86===e[2]&&1===e[3]&&G(e,5)>=9}}]),e}();i(re,"AUDIO_RATE",[5500,11e3,22e3,44e3]);var se=Object.freeze(Object.defineProperty({__proto__:null,FlvDemuxer:re},Symbol.toStringTag,{value:"Module"})),ie=9e4,ne=45e4,oe=9e4,ue=function(){function e(t,r,s){a(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=s,this._baseDts=-1,this._baseDtsInited=!1,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=!1,this._videoTimestampBreak=!1,this._lastAudioExceptionGapDot=0,this._lastAudioExceptionOverlapDot=0,this._lastAudioExceptionLargeGapDot=0}return s(e,[{key:"fix",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=Math.round(9e4*t);var s=this.videoTrack,i=this.audioTrack,n=s.samples,o=i.samples;if(n.length||o.length){var u=n[0],c=o[0],l=0;if(n.length&&o.length&&(l=u.dts-c.pts),this._baseDtsInited||this._calculateBaseDts(this.audioTrack,this.videoTrack),a&&(this._calculateBaseDts(this.audioTrack,this.videoTrack),this._baseDts-=t),!r){this._videoNextDts=l>0?t+l:t,this._audioNextPts=l>0?t:t-l;var d=u?u.dts-this._baseDts-this._videoNextDts:0,f=c?c.pts-this._baseDts-this._audioNextPts:0;Math.abs(d||f)>oe&&(this._calculateBaseDts(this.audioTrack,this.videoTrack),this._baseDts-=t)}if(this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(i),this._fixVideo(s),this.metadataTrack.exist()){var h=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/h}))}s.samples.length&&(s.baseMediaDecodeTime=s.samples[0].dts),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts*i.timescale/9e4)}}},{key:"_fixVideo",value:function(e){var t=this,a=e.samples;if(a.length){if(a.forEach((function(e){e.dts-=t._baseDts,e.pts-=t._baseDts})),void 0===this._videoNextDts){var r=a[0];this._videoNextDts=r.dts}var s,i,n=a.length,o=0,u=a[0],c=a[1],l=this._videoNextDts-u.dts;if(Math.abs(l)>45e3)u.dts+=l,u.pts+=l,e.warnings.push({type:x.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts,firstSampleDts:u.dts,nextSampleDts:null===(s=a[1])||void 0===s?void 0:s.dts,sampleDuration:l}),c&&Math.abs(c.dts-u.dts)>oe&&(this._videoTimestampBreak=!0,a.forEach((function(e,t){0!==t&&(e.dts+=l,e.pts+=l)})));if(e.fpsNum&&e.fpsDen)i=e.timescale*(e.fpsDen/e.fpsNum);else{var d=e.samples[0],f=e.samples[n-1];i=1===n?9e3:Math.floor((f.dts-d.dts)/(n-1))}for(var h=0;h<n;h++){var p=a[h].dts,v=a[h+1];if((o=h<n-1?v.dts-p:a[h-1]?Math.min(p-a[h-1].dts,i):i)>oe||o<0){this._videoTimestampBreak=!0,o=this._audioTimestampBreak?i:Math.max(o,2700);var y=this._audioNextPts||0;v&&v.dts>y&&(o=i),e.warnings.push({type:x.LARGE_VIDEO_GAP,time:p/e.timescale,dts:p,originDts:a[h].originDts,nextDts:this._videoNextDts,sampleDuration:o,refSampleDuration:i})}a[h].duration=o,this._videoNextDts+=o}}}},{key:"_fixAudio",value:function(e){var t=this,a=e.samples;a.length&&(a.forEach((function(e){e.pts-=t._baseDts,e.dts=e.pts})),this._doFixAudioInternal(e,a,9e4))}},{key:"_calculateBaseDts",value:function(e,t){var a=e.samples,r=t.samples;if(!a.length&&!r.length)return!1;var s=1/0,i=1/0;a.length&&(e.baseDts=s=a[0].pts),r.length&&(t.baseDts=i=r[0].dts),this._baseDts=Math.min(s,i);var n=i-s;return Number.isFinite(n)&&Math.abs(n)>45e3&&t.warnings.push({type:x.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){if(this._baseDtsInited&&this._videoTimestampBreak&&this._audioTimestampBreak){if(!this._calculateBaseDts(this.audioTrack,this.videoTrack))return;this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts),this._audioLastSample=null,this._videoLastSample=null,this._videoTimestampBreak=!1,this._audioTimestampBreak=!1}}},{key:"_doFixAudioInternal",value:function(e,t,a){e.sampleDuration||(e.sampleDuration=Z.getFrameDuration(e.timescale,a));var r=e.sampleDuration;if(void 0===this._audioNextPts){var s=t[0];this._audioNextPts=s.pts}for(var i=0;i<t.length;i++){var n=this._audioNextPts,o=t[i],u=o.pts-n;if(!this._audioTimestampBreak&&u>=3*r&&u<=ie&&!z){var c=Z.getSilentFrame(e.codec,e.channelCount)||t[0].data.subarray(),l=Math.floor(u/r);Math.abs(o.pts-this._lastAudioExceptionGapDot)>ne&&(this._lastAudioExceptionGapDot=o.pts),e.warnings.push({type:x.AUDIO_FILLED,pts:o.pts,originPts:o.originPts,count:l,nextPts:n,refSampleDuration:r});for(var d=0;d<l;d++){var f=new A(Math.floor(n),c);f.originPts=Math.floor(this._baseDts+n),t.splice(i,0,f),this._audioNextPts+=r,i++}i--}else u<=-3*r&&u>=-9e4?(Math.abs(o.pts-this._lastAudioExceptionOverlapDot)>ne&&(this._lastAudioExceptionOverlapDot=o.pts,e.warnings.push({type:x.AUDIO_DROPPED,pts:o.pts,originPts:o.originPts,nextPts:n,refSampleDuration:r})),t.splice(i,1),i--):(Math.abs(u)>=ie&&(this._audioTimestampBreak=!0,Math.abs(o.pts-this._lastAudioExceptionLargeGapDot)>ne&&(this._lastAudioExceptionLargeGapDot=o.pts,e.warnings.push({type:x.LARGE_AUDIO_GAP,time:o.pts/1e3,pts:o.pts,originPts:o.originPts,nextPts:n,sampleDuration:u,refSampleDuration:r}))),o.dts=o.pts=n,this._audioNextPts+=r)}}}]),e}(),ce=new U("TsDemuxer"),le=function(){function e(t,r,s){a(this,e),i(this,"_pmtId",-1),i(this,"_remainingPacketData",null),i(this,"_videoPesData",[]),i(this,"_audioPesData",[]),i(this,"_gopId",0),this.videoTrack=t||new w,this.audioTrack=r||new D,this.metadataTrack=s||new B,this._fixer=new ue(this.videoTrack,this.audioTrack,this.metadataTrack)}return s(e,[{key:"demux",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=this.audioTrack,s=this.videoTrack,i=this.metadataTrack;t&&(this._pmtId=-1,s.reset(),r.reset(),i.reset()),!a||t?(this._remainingPacketData=null,this._videoPesData=[],this._audioPesData=[]):(s.samples=[],r.samples=[],i.seiSamples=[],s.warnings=[],r.warnings=[],this._remainingPacketData&&(e=L(this._remainingPacketData,e),this._remainingPacketData=null));var n=e.length,o=n%188;o&&(this._remainingPacketData=e.subarray(n-o),n-=o);for(var u=s.pid,c=r.pid,l=0;l<n;l+=188){if(71!==e[l])throw new Error("TS packet did not start with 0x47");var d=!!(64&e[l+1]),f=((31&e[l+1])<<8)+e[l+2],h=(48&e[l+3])>>4,p=void 0;if(h>1){if((p=l+5+e[l+4])===l+188)continue}else p=l+4;switch(f){case 0:d&&(p+=e[p]+1),this._pmtId=(31&e[p+10])<<8|e[p+11];break;case this._pmtId:d&&(p+=e[p]+1);var v=p+3+((15&e[p+1])<<8|e[p+2])-4,y=(15&e[p+10])<<8|e[p+11];for(p+=12+y;p<v;){var m=(31&e[p+1])<<8|e[p+2];switch(e[p]){case 15:r.pid=c=m;break;case 27:if(-1!==u)break;s.codecType=b.AVC,s.pid=u=m;break;case 36:if(-1!==u)break;s.codecType=b.HEVC,s.pid=u=m;break;default:ce.warn("Unsupported stream. type: ".concat(e[p],", pid: ").concat(m))}p+=5+((15&e[p+3])<<8|e[p+4])}break;case u:d&&this._videoPesData.length&&this._parseVideoData(),this._videoPesData.push(e.subarray(p,l+188));break;case c:d&&this._audioPesData.length&&this._parseAudioData(),this._audioPesData.push(e.subarray(p,l+188));break;case 17:case 8191:break;default:ce.warn("Unknown pid: ".concat(f))}}return this._parseVideoData(),this._parseAudioData(),r.formatTimescale=s.formatTimescale=s.timescale=i.timescale=9e4,r.timescale=r.sampleRate||0,{videoTrack:s,audioTrack:r,metadataTrack:i}}},{key:"fix",value:function(e,t,a){return this._fixer.fix(e,t,a),{videoTrack:this.videoTrack,audioTrack:this.audioTrack,metadataTrack:this.metadataTrack}}},{key:"demuxAndFix",value:function(e,t,a,r){return this.demux(e,t,a),this.fix(r,t,a)}},{key:"_parseVideoData",value:function(){if(this._videoPesData.length){var t=e._parsePES(L.apply(void 0,y(this._videoPesData)));if(t){var a=X.parseAnnexB(t.data);a?this._createVideoSample(a,t.pts,t.dts):ce.warn("Cannot parse avc units",t),this._videoPesData=[]}else ce.warn("Cannot parse video pes",this._videoPesData)}}},{key:"_createVideoSample",value:function(e,t,a){var r=this;if(e.length){var s=this.videoTrack,i=s.codecType===b.HEVC,n=new S(t,a);e.forEach((function(e){var a=i?e[0]>>>1&63:31&e[0];switch(a){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!i&&5!==a||i&&5===a)break;n.setToKeyframe(),r._gopId++;break;case 6:case 39:case 40:if(!i&&6!==a||i&&6===a)break;return void r.metadataTrack.seiSamples.push(new E(X.parseSEI(X.removeEPB(e),i),t));case 32:if(!i)break;if(!s.vps.length){var o=Q.parseVPS(X.removeEPB(e),s.hvcC);s.hvcC=s.hvcC||o,s.vps=[e]}break;case 7:case 33:if(!i&&7!==a||i&&7===a)break;if(!s.sps.length){var u=X.removeEPB(e),c=i?Q.parseSPS(u,s.hvcC):Y.parseSPS(u);s.sps=[e],s.hvcC=s.hvcC||c.hvcC,s.codec=c.codec,s.width=c.width,s.height=c.height,s.sarRatio=c.sarRatio,s.fpsNum=c.fpsNum,s.fpsDen=c.fpsDen}break;case 8:case 34:if(!i&&8!==a||i&&8===a)break;s.pps.length||(s.pps=[e])}n.units.push(e)})),n.gopId=this._gopId,this._pushVideoSample(s,n)}}},{key:"_pushVideoSample",value:function(e,t){if(t.units.length)if(null===t.pts||void 0===t.pts){ce.warn("Video sample no pts",t);var a=e.samples[e.samples.length-1];a?(t.pts=a.pts,t.dts=a.dts):ce.warn("Drop video sample",t)}else e.samples.push(t)}},{key:"_parseAudioData",value:function(){if(this._audioPesData.length){var t=e._parsePES(L.apply(void 0,y(this._audioPesData)));t?(this._parseAacData(t),this._audioPesData=[]):ce.warn("Cannot parse audio pes",this._audioPesData)}}},{key:"_parseAacData",value:function(e){var t=this.audioTrack,a=e.pts;if(null==a){if(ce.warn("AAC pes not pts",t),!t.samples.length||!t.sampleRate)return;a=t.samples[t.samples.length-1].pts+Z.getFrameDuration(t.sampleRate)}var r,s=Z.parseADTS(e.data,a);s?(t.codec=s.codec,t.channelCount=s.channelCount,t.sampleRate=s.sampleRate,t.objectType=s.objectType,t.sampleRateIndex=s.samplingFrequencyIndex,t.config=s.config,(r=t.samples).push.apply(r,y(s.frames.map((function(e){return new A(e.pts,e.data)})))),s.skip&&ce.warn("Skip aac adts ".concat(s.skip," bits")),s.remaining&&ce.warn("Remaining aac adts ".concat(s.remaining," bits"))):ce.warn("Cannot parse aac adts",e)}}],[{key:"probe",value:function(e){return!!e.length&&(71===e[0]&&71===e[188]&&71===e[376])}},{key:"_parsePES",value:function(e){var t=e[8];if(!(null==t||e.length<t+9)&&1===(e[0]<<16|e[1]<<8|e[2])){var a=(e[4]<<8)+e[5];if(!(a&&a>e.length-6)){var r,s,i=e[7];return 192&i&&(r=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&i?r-(s=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(r=s):s=r),{data:e.subarray(9+t),pts:r,dts:s}}}}}]),e}(),de=Object.freeze(Object.defineProperty({__proto__:null,TsDemuxer:le},Symbol.toStringTag,{value:"Module"})),fe=function(){function e(){a(this,e)}return s(e,null,[{key:"findBox",value:function(t,a){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=[];if(!t)return s;for(var i=0,n="",o=0;t.length>7;){if(i=G(t),n=String.fromCharCode.apply(null,t.subarray(4,8)),o=8,1===i?(i=q(t,8),o+=8):i||(i=t.length),!a[0]||n===a[0]){var u=t.subarray(0,i);if(!(a.length<2))return e.findBox(u.subarray(o),a.slice(1),r+o);s.push({start:r,size:i,headerSize:o,type:n,data:u})}r+=i,t=t.subarray(i)}return s}},{key:"tfhd",value:function(e){return ye(e,!0,(function(e,t){e.trackId=G(t);var a=4,r=1&e.flags,s=2&e.flags,i=8&e.flags,n=16&e.flags,o=32&e.flags;r&&(a+=4,e.baseDataOffset=G(t,a),a+=4),s&&(e.sampleDescriptionIndex=G(t,a),a+=4),i&&(e.defaultSampleDuration=G(t,a),a+=4),n&&(e.defaultSampleSize=G(t,a),a+=4),o&&(e.defaultSampleFlags=G(t,a))}))}},{key:"sidx",value:function(e){return ye(e,!0,(function(e,t){var a=0;e.reference_ID=G(t,a),a+=4,e.timescale=G(t,a),a+=4,0===e.version?(e.earliest_presentation_time=G(t,a),a+=4,e.first_offset=G(t,a),a+=4):(e.earliest_presentation_time=q(t,a),a+=8,e.first_offset=q(t,a),a+=8),a+=2,e.references=[];var r=F(t,a);a+=2;for(var s=0;s<r;s++){var i={};e.references.push(i);var n=G(t,a);a+=4,i.reference_type=n>>31&1,i.referenced_size=2147483647&n,i.subsegment_duration=G(t,a),n=G(t,a+=4),a+=4,i.starts_with_SAP=n>>31&1,i.SAP_type=n>>28&7,i.SAP_delta_time=268435455&n}}))}},{key:"moov",value:function(t){return ye(t,!1,(function(t,a,r){t.mvhd=e.mvhd(e.findBox(a,["mvhd"],r)[0]),t.trak=e.findBox(a,["trak"],r).map((function(t){return e.trak(t)})),t.pssh=e.pssh(e.findBox(a,["pssh"],r)[0])}))}},{key:"mvhd",value:function(e){return ye(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=G(t,16),e.duration=q(t,20),a+=28):(e.timescale=G(t,8),e.duration=G(t,12),a+=16),e.nextTrackId=G(t,a+76)}))}},{key:"trak",value:function(t){return ye(t,!1,(function(t,a,r){t.tkhd=e.tkhd(e.findBox(a,["tkhd"],r)[0]),t.mdia=e.mdia(e.findBox(a,["mdia"],r)[0])}))}},{key:"tkhd",value:function(e){return ye(e,!0,(function(e,t){var a=0;1===e.version?(e.trackId=G(t,16),e.duration=q(t,24),a+=32):(e.trackId=G(t,8),e.duration=G(t,16),a+=20),e.width=G(t,a+52),e.height=G(t,a+56)}))}},{key:"mdia",value:function(t){return ye(t,!1,(function(t,a,r){t.mdhd=e.mdhd(e.findBox(a,["mdhd"],r)[0]),t.hdlr=e.hdlr(e.findBox(a,["hdlr"],r)[0]),t.minf=e.minf(e.findBox(a,["minf"],r)[0])}))}},{key:"mdhd",value:function(e){return ye(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=G(t,16),e.duration=q(t,20),a+=28):(e.timescale=G(t,8),e.duration=G(t,12),a+=16);var r=F(t,a);e.language=String.fromCharCode(96+(r>>10&31),96+(r>>5&31),96+(31&r))}))}},{key:"hdlr",value:function(e){return ye(e,!0,(function(e,t){0===e.version&&(e.handlerType=String.fromCharCode.apply(null,t.subarray(4,8)))}))}},{key:"minf",value:function(t){return ye(t,!1,(function(t,a,r){t.vmhd=e.vmhd(e.findBox(a,["vmhd"],r)[0]),t.smhd=e.smhd(e.findBox(a,["smhd"],r)[0]),t.stbl=e.stbl(e.findBox(a,["stbl"],r)[0])}))}},{key:"vmhd",value:function(e){return ye(e,!0,(function(e,t){e.graphicsmode=F(t),e.opcolor=[F(t,2),F(t,4),F(t,6)]}))}},{key:"smhd",value:function(e){return ye(e,!0,(function(e,t){e.balance=F(t)}))}},{key:"stbl",value:function(t){return ye(t,!1,(function(t,a,r){var s,i,n;t.stsd=e.stsd(e.findBox(a,["stsd"],r)[0]),t.stts=e.stts(e.findBox(a,["stts"],r)[0]),t.ctts=e.ctts(e.findBox(a,["ctts"],r)[0]),t.stsc=e.stsc(e.findBox(a,["stsc"],r)[0]),t.stsz=e.stsz(e.findBox(a,["stsz"],r)[0]),t.stco=e.stco(e.findBox(a,["stco"],r)[0]),t.stco||(t.co64=e.co64(e.findBox(a,["co64"],r)[0]),t.stco=t.co64);var o=null===(s=t.stsd.entries[0])||void 0===s||null===(i=s.sinf)||void 0===i||null===(n=i.schi)||void 0===n?void 0:n.tenc.default_IV_size;t.stss=e.stss(e.findBox(a,["stss"],r)[0]),t.senc=e.senc(e.findBox(a,["senc"],r)[0],o)}))}},{key:"senc",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8;return ye(e,!0,(function(e,a){var r=0,s=G(a,r);r+=4,e.samples=[];for(var i=0;i<s;i++){for(var n={InitializationVector:[]},o=0;o<t;o++)n.InitializationVector[o]=a[r+o];if(r+=t,2&e.flags){n.subsamples=[];var u=F(a,r);r+=2;for(var c=0;c<u;c++){var l={};l.BytesOfClearData=F(a,r),r+=2,l.BytesOfProtectedData=G(a,r),r+=4,n.subsamples.push(l)}}e.samples.push(n)}}))}},{key:"pssh",value:function(e){return ye(e,!0,(function(e,t){for(var a=[],r=[],s=0,i=0;i<16;i++)r.push(ge(t[s+i]));if(s+=16,e.version>0){var n=G(t,s);s+=4;for(var o=0;o<(""+n).length;o++)for(var u=0;u<16;u++){var c=t[s];s+=1,a.push(ge(c))}}var l=G(t,s);e.data_size=l,s+=4,e.kid=a,e.system_id=r,e.buffer=t}))}},{key:"stsd",value:function(t){return ye(t,!0,(function(t,a,r){t.entryCount=G(a),t.entries=e.findBox(a.subarray(4),[],r+4).map((function(t){switch(t.type){case"avc1":case"avc2":case"avc3":case"avc4":return e.avc1(t);case"hvc1":case"hev1":return e.hvc1(t);case"mp4a":return e.mp4a(t);case"alaw":case"ulaw":return e.alaw(t);case"enca":return ye(t,!1,(function(t,a,r){t.channelCount=F(a,16),t.samplesize=F(a,18),t.sampleRate=G(a,24)/65536,a=a.subarray(28),t.sinf=e.sinf(e.findBox(a,["sinf"],r)[0]),t.esds=e.esds(e.findBox(a,["esds"],r)[0])}));case"encv":return ye(t,!1,(function(t,a,r){t.width=F(a,24),t.height=F(a,26),t.horizresolution=G(a,28),t.vertresolution=G(a,32),a=a.subarray(78),t.sinf=e.sinf(e.findBox(a,["sinf"],r)[0]),t.avcC=e.avcC(e.findBox(a,["avcC"],r)[0]),t.hvcC=e.hvcC(e.findBox(a,["hvcC"],r)[0]),t.pasp=e.pasp(e.findBox(a,["pasp"],r)[0])}))}})).filter(Boolean)}))}},{key:"tenc",value:function(e){return ye(e,!1,(function(e,t){var a=6;e.default_IsEncrypted=t[a],a+=1,e.default_IV_size=t[a],a+=1,e.default_KID=[];for(var r=0;r<16;r++)e.default_KID.push(ge(t[a])),a+=1}))}},{key:"schi",value:function(t){return ye(t,!1,(function(t,a,r){t.tenc=e.tenc(e.findBox(a,["tenc"],r)[0])}))}},{key:"sinf",value:function(t){return ye(t,!1,(function(t,a,r){t.schi=e.schi(e.findBox(a,["schi"],r)[0]),t.frma=e.frma(e.findBox(a,["frma"],r)[0])}))}},{key:"frma",value:function(e){return ye(e,!1,(function(e,t){e.data_format="";for(var a=0;a<4;a++)e.data_format+=String.fromCharCode(t[a])}))}},{key:"avc1",value:function(t){return ye(t,!1,(function(t,a,r){var s=pe(t,a),i=a.subarray(s);r+=s,t.avcC=e.avcC(e.findBox(i,["avcC"],r)[0]),t.pasp=e.pasp(e.findBox(i,["pasp"],r)[0])}))}},{key:"avcC",value:function(e){return ye(e,!1,(function(e,t){e.configurationVersion=t[0],e.AVCProfileIndication=t[1],e.profileCompatibility=t[2],e.AVCLevelIndication=t[3],e.codec=H([t[1],t[2],t[3]]),e.lengthSizeMinusOne=3&t[4],e.spsLength=31&t[5],e.sps=[];for(var a=6,r=0;r<e.spsLength;r++){var s=F(t,a);a+=2,e.sps.push(t.subarray(a,a+s)),a+=s}e.ppsLength=t[a],a+=1,e.pps=[];for(var i=0;i<e.ppsLength;i++){var n=F(t,a);a+=2,e.pps.push(t.subarray(a,a+=n)),a+=n}}))}},{key:"hvc1",value:function(t){return ye(t,!1,(function(t,a,r){var s=pe(t,a),i=a.subarray(s);r+=s,t.hvcC=e.hvcC(e.findBox(i,["hvcC"],r)[0]),t.pasp=e.pasp(e.findBox(i,["pasp"],r)[0])}))}},{key:"hvcC",value:function(e){return ye(e,!1,(function(t,a){t.data=e.data,t.codec="hev1.1.6.L93.B0",t.configurationVersion=a[0];var r=a[1];t.generalProfileSpace=r>>6,t.generalTierFlag=(32&r)>>5,t.generalProfileIdc=31&r,t.generalProfileCompatibility=G(a,2),t.generalConstraintIndicatorFlags=a.subarray(6,12),t.generalLevelIdc=a[12],t.avgFrameRate=F(a,19),t.numOfArrays=a[22],t.vps=[],t.sps=[],t.pps=[];for(var s=23,i=0,n=0,o=0,u=0;u<t.numOfArrays;u++){i=63&a[s],n=F(a,s+1),s+=3;for(var c,l=[],d=0;d<n;d++)o=F(a,s),s+=2,l.push(a.subarray(s,s+o)),s+=o;if(32===i)(c=t.vps).push.apply(c,l);else if(33===i){var f;(f=t.sps).push.apply(f,l)}else if(34===i){var h;(h=t.pps).push.apply(h,l)}}}))}},{key:"pasp",value:function(e){return ye(e,!1,(function(e,t){e.hSpacing=G(t),e.vSpacing=G(t,4)}))}},{key:"mp4a",value:function(t){return ye(t,!1,(function(t,a,r){var s=ve(t,a);t.esds=e.esds(e.findBox(a.subarray(s),["esds"],r+s)[0])}))}},{key:"esds",value:function(e){return ye(e,!0,(function(e,t){e.codec="mp4a.";for(var a=0,r=0,s=0,i=0;t.length;){for(i=t[a=0],r=t[a+1],a+=2;128&r;)s=(127&r)<<7,r=t[a],a+=1;if(s+=127&r,3===i)t=t.subarray(a+3);else{if(4!==i){if(5===i){var n=e.config=t.subarray(a,a+s),o=(248&n[0])>>3;return 31===o&&n.length>=2&&(o=32+((7&n[0])<<3)+((224&n[1])>>5)),e.objectType=o,e.codec+=o.toString(16),void("."===e.codec[e.codec.length-1]&&(e.codec=e.codec.substring(0,e.codec.length-1)))}return void("."===e.codec[e.codec.length-1]&&(e.codec=e.codec.substring(0,e.codec.length-1)))}e.codec+=(t[a].toString(16)+".").padStart(3,"0"),t=t.subarray(a+13)}}}))}},{key:"alaw",value:function(e){return ye(e,!1,(function(e,t){ve(e,t)}))}},{key:"stts",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push({count:G(t,s),delta:G(t,s+4)}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"ctts",value:function(e){return ye(e,!0,(function(e,t){var a=G(t),r=[],s=4;if(1===e.version)for(var i=0;i<a;i++)r.push({count:G(t,s),offset:G(t,s+4)}),s+=8;else for(var n=0;n<a;n++)r.push({count:G(t,s),offset:-(1+~G(t,s+4))}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stsc",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push({firstChunk:G(t,s),samplesPerChunk:G(t,s+4),sampleDescriptionIndex:G(t,s+8)}),s+=12;e.entryCount=a,e.entries=r}))}},{key:"stsz",value:function(e){return ye(e,!0,(function(e,t){var a=G(t),r=G(t,4),s=[];if(!a)for(var i=8,n=0;n<r;n++)s.push(G(t,i)),i+=4;e.sampleSize=a,e.sampleCount=r,e.entrySizes=s}))}},{key:"stco",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push(G(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"co64",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push(q(t,s)),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stss",value:function(e){return ye(e,!0,(function(e,t){for(var a=G(t),r=[],s=4,i=0;i<a;i++)r.push(G(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"moof",value:function(t){return ye(t,!1,(function(t,a,r){t.mfhd=e.mfhd(e.findBox(a,["mfhd"],r)[0]),t.traf=e.findBox(a,["traf"],r).map((function(t){return e.traf(t)}))}))}},{key:"mfhd",value:function(e){return ye(e,!0,(function(e,t){e.sequenceNumber=G(t)}))}},{key:"traf",value:function(t){return ye(t,!1,(function(t,a,r){t.tfhd=e.tfhd(e.findBox(a,["tfhd"],r)[0]),t.tfdt=e.tfdt(e.findBox(a,["tfdt"],r)[0]),t.trun=e.trun(e.findBox(a,["trun"],r)[0])}))}},{key:"trun",value:function(e){return ye(e,!0,(function(e,t){var a=e.version,r=e.flags,s=t.length,i=e.sampleCount=G(t),n=4;if(s>n&&1&r&&(e.dataOffset=-(1+~G(t,n)),n+=4),s>n&&4&r&&(e.firstSampleFlags=G(t,n),n+=4),e.samples=[],s>n)for(var o,u=0;u<i;u++)o={},256&r&&(o.duration=G(t,n),n+=4),512&r&&(o.size=G(t,n),n+=4),1024&r&&(o.flags=G(t,n),n+=4),2048&r&&(o.cts=a?-(1+~G(t,n+4)):G(t,n),n+=4),e.samples.push(o)}))}},{key:"tfdt",value:function(e){return ye(e,!0,(function(e,t){1===e.version?e.baseMediaDecodeTime=q(t):e.baseMediaDecodeTime=G(t)}))}},{key:"probe",value:function(t){return!!e.findBox(t,["ftyp"])}},{key:"parseSampleFlags",value:function(e){return{isLeading:(12&e[0])>>>2,dependsOn:3&e[0],isDependedOn:(192&e[1])>>>6,hasRedundancy:(48&e[1])>>>4,paddingValue:(14&e[1])>>>1,isNonSyncSample:1&e[1],degradationPriority:e[2]<<8|e[3]}}},{key:"moovToTrack",value:function(e,t,a){var r,s,i=e.trak;if(i&&i.length){var n=i.find((function(e){var t,a;return"vide"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)})),o=i.find((function(e){var t,a;return"soun"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)}));if(n&&t){var u,c,l,d,f,h,p,v=t,y=null===(u=n.tkhd)||void 0===u?void 0:u.trackId;null!=y&&(v.id=n.tkhd.trackId),v.tkhdDuration=n.tkhd.duration,v.mvhdDurtion=e.mvhd.duration,v.mvhdTimecale=e.mvhd.timescale,v.timescale=v.formatTimescale=n.mdia.mdhd.timescale,v.duration=n.mdia.mdhd.duration||v.mvhdDurtion/v.mvhdTimecale*v.timescale;var m,g,k,x,w,D,S,A,T=n.mdia.minf.stbl.stsd.entries[0];if(v.width=T.width,v.height=T.height,T.pasp&&(v.sarRatio=[T.pasp.hSpacing,T.pasp.vSpacing]),T.hvcC)v.codecType=b.HEVC,v.codec=T.hvcC.codec,v.vps=T.hvcC.vps,v.sps=T.hvcC.sps,v.pps=T.hvcC.pps,v.hvcC=T.hvcC.data;else{if(!T.avcC)throw new Error("unknown video stsd entry");v.codec=T.avcC.codec,v.sps=T.avcC.sps,v.pps=T.avcC.pps}if(v.present=!0,v.ext={},v.ext.stss=null===(c=n.mdia)||void 0===c||null===(l=c.minf)||void 0===l||null===(d=l.stbl)||void 0===d?void 0:d.stss,v.ext.ctts=null===(f=n.mdia)||void 0===f||null===(h=f.minf)||void 0===h||null===(p=h.stbl)||void 0===p?void 0:p.ctts,T&&"encv"===T.type)v.isVideoEncryption=!0,T.default_KID=null===(m=T.sinf)||void 0===m||null===(g=m.schi)||void 0===g?void 0:g.tenc.default_KID,T.default_IsEncrypted=null===(k=T.sinf)||void 0===k||null===(x=k.schi)||void 0===x?void 0:x.tenc.default_IsEncrypted,T.default_IV_size=null===(w=T.sinf)||void 0===w||null===(D=w.schi)||void 0===D?void 0:D.tenc.default_IV_size,v.videoSenc=n.mdia.minf.stbl.senc&&n.mdia.minf.stbl.senc.samples,T.data_format=null===(S=T.sinf)||void 0===S||null===(A=S.frma)||void 0===A?void 0:A.data_format,v.useEME=e.useEME,v.kidValue=e.kidValue,v.pssh=e.pssh,v.encv=T}if(o&&a){var j,E,B,C,P,U,I,M,O,z=a,R=null===(j=o.tkhd)||void 0===j?void 0:j.trackId;null!=R&&(z.id=o.tkhd.trackId),z.tkhdDuration=o.tkhd.duration,z.mvhdDurtion=e.mvhd.duration,z.mvhdTimecale=e.mvhd.timescale,z.timescale=z.formatTimescale=o.mdia.mdhd.timescale,z.duration=o.mdia.mdhd.duration||z.mvhdDurtion/z.mvhdTimecale*z.timescale;var V,L,N,F,G,q,H,K,W=o.mdia.minf.stbl.stsd.entries[0];switch(z.sampleSize=W.sampleSize,z.sampleRate=W.sampleRate,z.channelCount=W.channelCount,z.present=!0,W.type){case"alaw":z.codecType=z.codec=_.G711PCMA,z.sampleRate=8e3;break;case"ulaw":z.codecType=z.codec=_.G711PCMU,z.sampleRate=8e3;break;default:z.sampleDuration=Z.getFrameDuration(z.sampleRate,z.timescale),z.sampleRateIndex=Z.getRateIndexByRate(z.sampleRate),z.objectType=(null===(r=W.esds)||void 0===r?void 0:r.objectType)||2,W.esds&&(z.config=Array.from(W.esds.config)),z.codec=(null===(s=W.esds)||void 0===s?void 0:s.codec)||"mp4a.40.2"}if(z.sampleDuration=Z.getFrameDuration(z.sampleRate,z.timescale),z.objectType=(null===(E=W.esds)||void 0===E?void 0:E.objectType)||2,W.esds&&(W.esds.config?z.config=Array.from(W.esds.config):console.warn("esds config is null")),z.codec=(null===(B=W.esds)||void 0===B?void 0:B.codec)||"mp4a.40.2",z.sampleRateIndex=Z.getRateIndexByRate(z.sampleRate),z.ext={},z.ext.stss=null===(C=o.mdia)||void 0===C||null===(P=C.minf)||void 0===P||null===(U=P.stbl)||void 0===U?void 0:U.stss,z.ext.ctts=null===(I=o.mdia)||void 0===I||null===(M=I.minf)||void 0===M||null===(O=M.stbl)||void 0===O?void 0:O.ctts,z.present=!0,W&&"enca"===W.type)z.isAudioEncryption=!0,W.data_format=null===(V=W.sinf)||void 0===V||null===(L=V.frma)||void 0===L?void 0:L.data_format,W.default_KID=null===(N=W.sinf)||void 0===N||null===(F=N.schi)||void 0===F?void 0:F.tenc.default_KID,W.default_IsEncrypted=null===(G=W.sinf)||void 0===G||null===(q=G.schi)||void 0===q?void 0:q.tenc.default_IsEncrypted,W.default_IV_size=null===(H=W.sinf)||void 0===H||null===(K=H.schi)||void 0===K?void 0:K.tenc.default_IV_size,z.audioSenc=o.mdia.minf.stbl.senc&&o.mdia.minf.stbl.senc.samples,z.useEME=e.useEME,z.kidValue=e.kidValue,z.enca=W}if(a&&(a.isVideoEncryption=!!t&&t.isVideoEncryption),t&&(t.isAudioEncryption=!!a&&a.isAudioEncryption),null!=t&&t.encv||null!=a&&a.enca){var X,Y,Q=null==t||null===(X=t.encv)||void 0===X?void 0:X.default_KID,J=null==a||null===(Y=a.enca)||void 0===Y?void 0:Y.default_KID,$=Q||J?(Q||J).join(""):null;t&&(t.kid=$),a&&(a.kid=$)}return t&&(t.flags=3841),a&&(a.flags=1793),{videoTrack:t,audioTrack:a}}}},{key:"evaluateDefaultDuration",value:function(e,t,a){var r,s=null==t||null===(r=t.samples)||void 0===r?void 0:r.length;return s?1024*s/t.timescale*e.timescale/a:1024}},{key:"moofToSamples",value:function(t,a,r){var s={};return t.mfhd&&(a&&(a.sequenceNumber=t.mfhd.sequenceNumber),r&&(r.sequenceNumber=t.mfhd.sequenceNumber)),t.traf.forEach((function(t){var i=t.tfhd,n=t.tfdt,o=t.trun;if(i&&o){n&&(a&&a.id===i.trackId&&(a.baseMediaDecodeTime=n.baseMediaDecodeTime),r&&r.id===i.trackId&&(r.baseMediaDecodeTime=n.baseMediaDecodeTime));var u=i.defaultSampleSize||0,c=i.defaultSampleDuration||e.evaluateDefaultDuration(a,r,o.samples.length||o.sampleCount),l=o.dataOffset||0,d=0,f=-1;if(!o.samples.length&&o.sampleCount){s[i.trackId]=[];for(var h=0;h<o.sampleCount;h++)s[i.trackId].push({offset:l,dts:d,duration:c,size:u}),d+=c,l+=u}else s[i.trackId]=o.samples.map((function(e,t){return(e={offset:l,dts:d,pts:d+(e.cts||0),duration:e.duration||c,size:e.size||u,gopId:f,keyframe:0===t||null!==e.flags&&void 0!==e.flags&&(65536&e.flags)>>>0!=65536}).keyframe&&(f++,e.gopId=f),d+=e.duration,l+=e.size,e}))}})),s}},{key:"moovToSamples",value:function(e){var t=e.trak;if(t&&t.length){var a=t.find((function(e){var t,a;return"vide"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)})),r=t.find((function(e){var t,a;return"soun"===(null===(t=e.mdia)||void 0===t||null===(a=t.hdlr)||void 0===a?void 0:a.handlerType)}));if(a||r){var s,i;if(a){var n,o,u=null===(n=a.mdia)||void 0===n||null===(o=n.minf)||void 0===o?void 0:o.stbl;if(!u)return;var c=u.stts,l=u.stsc,d=u.stsz,f=u.stco,h=u.stss,p=u.ctts;if(!(c&&l&&d&&f&&h))return;s=he(c,l,d,f,p,h)}if(r){var v,y,m,g=null===(v=r.mdia)||void 0===v||null===(y=v.minf)||void 0===y?void 0:y.stbl;if(!g)return;var k=null===(m=r.mdia.mdhd)||void 0===m?void 0:m.timescale,b=g.stts,_=g.stsc,x=g.stsz,w=g.stco;if(!(k&&b&&_&&x&&w))return;i=he(b,_,x,w)}return{videoSamples:s,audioSamples:i}}}}}]),e}();function he(e,t,a,r,s,i){var n,o,u,c=[],l=null==s?void 0:s.entries,d=t.entries,f=r.entries,h=a.entrySizes,p=null==i?void 0:i.entries;p&&(n={},p.forEach((function(e){n[e-1]=!0}))),l&&(o=[],l.forEach((function(e){for(var t=e.count,a=e.offset,r=0;r<t;r++)o.push(a)})));var v=-1,y=0,m=0,g=0,k=0,b=0,_=d[0].samplesPerChunk,x=d[1]?d[1].firstChunk-1:1/0;return e.entries.forEach((function(e){for(var t=e.count,r=e.delta,s=0;s<t;s++)u={dts:y,duration:r,size:h[m]||a.sampleSize,offset:f[g]+b,index:m},p&&(u.keyframe=n[m],u.keyframe&&v++,u.gopId=v),o&&m<o.length&&(u.pts=u.dts+o[m]),c.push(u),y+=r,++m<_?b+=u.size:(g++,b=0,g>=x&&(k++,x=d[k+1]?d[k+1].firstChunk-1:1/0),_+=d[k].samplesPerChunk)})),c}function pe(e,t){return e.dataReferenceIndex=F(t,6),e.width=F(t,24),e.height=F(t,26),e.horizresolution=G(t,28),e.vertresolution=G(t,32),e.frameCount=F(t,40),e.depth=F(t,74),78}function ve(e,t){return e.dataReferenceIndex=F(t,6),e.channelCount=F(t,16),e.sampleSize=F(t,18),e.sampleRate=G(t,24)/65536,28}function ye(e,t,a){if(e){if(e.size!==e.data.length)throw new Error("box ".concat(e.type," size !== data.length"));var r={start:e.start,size:e.size,headerSize:e.headerSize,type:e.type};return t&&(r.version=e.data[e.headerSize],r.flags=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<16)+(e[t+1]<<8)+(e[t+2]||0)}(e.data,e.headerSize+1),r.headerSize+=4),a(r,e.data.subarray(r.headerSize),r.start+r.headerSize),r}}var me=function(e,t,a){for(var r=String(a),s=t>>0,i=Math.ceil(s/r.length),n=[],o=String(e);i--;)n.push(r);return n.join("").substring(0,s-o.length)+o},ge=function(){for(var e=[],t=arguments.length,a=new Array(t),r=0;r<t;r++)a[r]=arguments[r];return a.forEach((function(t){e.push(me(Number(t).toString(16),2,0))})),e[0]},ke=function(){function e(t,r,s){a(this,e),this.videoTrack=t||new w,this.audioTrack=r||new D,this.metadataTrack=s||new B}return s(e,[{key:"demux",value:function(e,t){var a=this.videoTrack,r=this.audioTrack,s=a.exist(),i=r.exist();if(a.samples=[],r.samples=[],t){if(!i){var n=fe.findBox(t,["moov"])[0];if(!n)throw new Error("cannot found moov box");fe.moovToTrack(fe.moov(n),null,r)}var o=fe.findBox(t,["moof"])[0];if(o){var u=fe.moofToSamples(fe.moof(o),null,r)[r.id],c=r.baseMediaDecodeTime;if(u){var l=o.start;u.map((function(e){e.offset+=l;var a=t.subarray(e.offset,e.offset+e.size);r.samples.push(new A(e.dts+c,a,e.duration))}))}}}if(e){if(!s&&!i){var d=fe.findBox(e,["moov"])[0];if(!d)throw new Error("cannot found moov box");fe.moovToTrack(fe.moov(d),a,r)}var f=fe.findBox(e,["moof"])[0];if(f){var h,p=fe.moofToSamples(fe.moof(f),a,r),v=a.baseMediaDecodeTime,y=r.baseMediaDecodeTime,m=f.start;Object.keys(p).forEach((function(t){a.id==t?p[t].map((function(t){t.offset+=m;var r=new S((t.pts||t.dts)+v,t.dts+v);r.duration=t.duration,r.gopId=t.gopId,t.keyframe&&r.setToKeyframe();var s=e.subarray(t.offset,t.offset+t.size);r.data=s;for(var i=0,n=s.length-1;i<n;)h=G(s,i),i+=4,r.units.push(s.subarray(i,i+h)),i+=h;a.samples.push(r)})):r.id==t&&p[t].map((function(t){t.offset+=m;var a=e.subarray(t.offset,t.offset+t.size);r.samples.push(new A(t.dts+y,a,t.duration))}))}))}}return{videoTrack:a,audioTrack:r,metadataTrack:this.metadataTrack}}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset(),this.metadataTrack.reset()}}],[{key:"probe",value:function(e){return fe.probe(e)}}]),e}();function be(e){for(var t=0,a=arguments.length,r=new Array(a>1?a-1:0),s=1;s<a;s++)r[s-1]=arguments[s];r.forEach((function(e){t+=e.length}));var i=new e(t),n=0;return r.forEach((function(e){i.set(e,n),n+=e.length})),i}var _e=function(){function e(){a(this,e),this.buffer=new Uint8Array(0)}return s(e,[{key:"write",value:function(){for(var e=this,t=arguments.length,a=new Array(t),r=0;r<t;r++)a[r]=arguments[r];a.forEach((function(t){t?e.buffer=be(Uint8Array,e.buffer,t):window.console.warn(t)}))}}],[{key:"writeUint16",value:function(e){return new Uint8Array([e>>8&255,255&e])}},{key:"writeUint32",value:function(e){return new Uint8Array([e>>24,e>>16&255,e>>8&255,255&e])}}]),e}(),xe=Math.pow(2,32)-1,we=function(){function e(){a(this,e)}return s(e,null,[{key:"box",value:function(e){for(var t=arguments.length,a=new Array(t>1?t-1:0),r=1;r<t;r++)a[r-1]=arguments[r];var s=8+(a=a.filter(Boolean)).reduce((function(e,t){return e+t.byteLength}),0),i=new Uint8Array(s);i[0]=s>>24&255,i[1]=s>>16&255,i[2]=s>>8&255,i[3]=255&s,i.set(e,4);var n=8;return a.forEach((function(e){i.set(e,n),n+=e.byteLength})),i}},{key:"ftyp",value:function(t){return t.find((function(e){return e.type===k.VIDEO&&e.codecType===b.HEVC}))?e.FTYPHEV1:e.FTYPAVC1}},{key:"initSegment",value:function(t){return L(e.ftyp(t),e.moov(t))}},{key:"pssh",value:function(t){var a=new Uint8Array([1,0,0,0].concat([16,119,239,236,192,178,77,2,172,227,60,30,82,226,251,75],[0,0,0,1],W(t.kid),[0,0,0,0]));return e.box(e.types.pssh,a)}},{key:"moov",value:function(t){if(t[0].useEME&&(t[0].encv||t[0].enca)){t[0].pssh||(t[0].pssh={kid:t[0].kid});var a=this.pssh(t[0].pssh);return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale),e.mvex(t)].concat(y(t.map((function(t){return e.trak(t)}))),[a]))}return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale)].concat(y(t.map((function(t){return e.trak(t)}))),[e.mvex(t)]))}},{key:"mvhd",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4,r=e.box(e.types.mvhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a,t>>24&255,t>>16&255,t>>8&255,255&t,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 r}},{key:"trak",value:function(t){return e.box(e.types.trak,e.tkhd(t.id,t.tkhdDuration||0,t.width,t.height),e.mdia(t))}},{key:"tkhd",value:function(t,a){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t>>24&255,t>>16&255,t>>8&255,255&t,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a,0,0,0,0,0,0,0,0,0,0,0,0,1,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]));return i}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.duration,t.timescale),e.hdlr(t.type),e.minf(t))}},{key:"mdhd",value:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4,r=e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a,t>>24&255,t>>16&255,t>>8&255,255&t,85,196,0,0]));return r}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"minf",value:function(t){return e.box(e.types.minf,t.type===k.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stbl(t))}},{key:"stbl",value:function(t){var a=[];return t&&t.ext&&t.ext.stss&&a.push(e.stss(t.ext.stss.entries)),e.box(e.types.stbl,e.stsd(t),e.STTS,a[0],e.STSC,e.STSZ,e.STCO)}},{key:"stsd",value:function(t){var a;return a="audio"===t.type?t.useEME&&t.enca?e.enca(t):e.mp4a(t):t.useEME&&t.encv?e.encv(t):e.avc1hev1(t),e.box(e.types.stsd,new Uint8Array([0,0,0,0,0,0,0,1]),a)}},{key:"enca",value:function(t){var a=t.enca.channelCount,r=t.enca.sampleRate,s=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,a,0,16,0,0,0,0,r>>8&255,255&r,0,0]),i=e.esds(t.config),n=e.sinf(t.enca);return e.box(e.types.enca,s,i,n)}},{key:"encv",value:function(t){var a,r,s=t.sps.length>0?t.sps[0]:[],i=t.pps.length>0?t.pps[0]:[],n=t.width,o=t.height,u=t.sarRatio[0],c=t.sarRatio[1],l=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,n>>8&255,255&n,o>>8&255,255&o,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]),d=new Uint8Array((a=(r=[1,s[1],s[2],s[3],255,225,s.length>>>8&255,255&s.length]).concat.apply(r,y(s)).concat([1,i.length>>>8&255,255&i.length])).concat.apply(a,y(i))),f=new Uint8Array([0,0,88,57,0,15,200,192,0,4,86,72]),h=e.sinf(t.encv),p=new Uint8Array([u>>24,u>>16&255,u>>8&255,255&u,c>>24,c>>16&255,c>>8&255,255&c]);return e.box(e.types.encv,l,e.box(e.types.avcC,d),e.box(e.types.btrt,f),h,e.box(e.types.pasp,p))}},{key:"schi",value:function(t){var a=new Uint8Array([]),r=e.tenc(t);return e.box(e.types.schi,a,r)}},{key:"tenc",value:function(t){var a=new Uint8Array([0,0,0,0,0,0,255&t.default_IsEncrypted,255&t.default_IV_size].concat(W(t.default_KID)));return e.box(e.types.tenc,a)}},{key:"sinf",value:function(t){var a=new Uint8Array([]),r=new Uint8Array([t.data_format.charCodeAt(0),t.data_format.charCodeAt(1),t.data_format.charCodeAt(2),t.data_format.charCodeAt(3)]),s=new Uint8Array([0,0,0,0,99,101,110,99,0,1,0,0]),i=e.schi(t);return e.box(e.types.sinf,a,e.box(e.types.frma,r),e.box(e.types.schm,s),i)}},{key:"avc1hev1",value:function(t){var a=t.codecType===b.HEVC,r=a?e.types.hvc1:e.types.avc1,s=a?e.hvcC(t):e.avcC(t),i=[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,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,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,0,0,0,0,0,0,24,17,17]),s];return a?i.push(e.box(e.types.fiel,new Uint8Array([1,0]))):t.sarRatio&&t.sarRatio.length>1&&i.push(e.pasp(t.sarRatio)),e.box.apply(e,[r].concat(i))}},{key:"avcC",value:function(t){var a,r,s,i=[],n=[];return t.sps.forEach((function(e){s=e.byteLength,i.push(s>>>8&255),i.push(255&s),i.push.apply(i,y(e))})),t.pps.forEach((function(e){s=e.byteLength,n.push(s>>>8&255),n.push(255&s),n.push.apply(n,y(e))})),e.box(e.types.avcC,new Uint8Array((a=(r=[1,i[3],i[4],i[5],255,224|t.sps.length]).concat.apply(r,i).concat([t.pps.length])).concat.apply(a,n)))}},{key:"hvcC",value:function(t){var a=t.hvcC;if(a instanceof ArrayBuffer||a instanceof Uint8Array)return a;var r,s=t.vps,i=t.sps,n=t.pps;if(a){var o=a.generalProfileCompatibilityFlags,u=a.generalConstraintIndicatorFlags,c=(s.length&&1)+(i.length&&1)+(n.length&&1);r=[1,a.generalProfileSpace<<6|a.generalTierFlag<<5|a.generalProfileIdc,o>>>24,o>>>16,o>>>8,o,u[0],u[1],u[2],u[3],u[4],u[5],a.generalLevelIdc,240,0,252,252|a.chromaFormatIdc,248|a.bitDepthLumaMinus8,248|a.bitDepthChromaMinus8,0,0,a.numTemporalLayers<<3|a.temporalIdNested<<2|3,c];var l=function(e){var t;r.push(e.length>>8,e.length),(t=r).push.apply(t,y(e))};s.length&&(r.push(160,0,s.length),s.forEach(l)),i.length&&(r.push(161,0,i.length),i.forEach(l)),n.length&&(r.push(162,0,n.length),n.forEach(l))}else r=[1,1,96,0,0,0,144,0,0,0,0,0,93,240,0,252,253,248,248,0,0,15,3,160,0,1,0,24,64,1,12,1,255,255,1,96,0,0,3,0,144,0,0,3,0,0,3,0,93,153,152,9,161,0,1,0,45,66,1,1,1,96,0,0,3,0,144,0,0,3,0,0,3,0,93,160,2,128,128,45,22,89,153,164,147,43,154,128,128,128,130,0,0,3,0,2,0,0,3,0,50,16,162,0,1,0,7,68,1,193,114,180,98,64];return e.box(e.types.hvcC,new Uint8Array(r))}},{key:"pasp",value:function(t){var a=v(t,2),r=a[0],s=a[1];return e.box(e.types.pasp,new Uint8Array([r>>24,r>>16&255,r>>8&255,255&r,s>>24,s>>16&255,s>>8&255,255&s]))}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.sampleRate>>8&255,255&t.sampleRate,0,0]),t.config.length?e.esds(t.config):void 0)}},{key:"esds",value:function(t){var a=t.length;return e.box(e.types.esds,new Uint8Array([0,0,0,0,3,23+a,0,0,0,4,15+a,64,21,0,6,0,0,0,218,192,0,0,218,192,5].concat([a]).concat(t).concat([6,1,2])))}},{key:"mvex",value:function(t){return e.box.apply(e,[e.types.mvex].concat(y(t.map((function(t){return e.trex(t.id)})))))}},{key:"trex",value:function(t){return e.box(e.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]))}},{key:"trex1",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,2,0,0,0,0,0,0,1,0,0]))}},{key:"trex2",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,4,0,0,0,0,0,2,0,0,0]))}},{key:"moof",value:function(t){return e.box.apply(e,[e.types.moof,e.mfhd(t[0].samples?t[0].samples[0].gopId:0)].concat(y(t.map((function(t){return e.traf(t)})))))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"traf",value:function(t){var a=e.tfhd(t.id),r=e.tfdt(t,t.baseMediaDecodeTime);if(t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)){if(t.isVideoEncryption){if(t.isVideo){var s=e.saiz(t),i=e.saio(t),n=e.trun1(t),o=e.senc(t);return e.box(e.types.traf,a,r,s,i,n,o)}if(t.isAudioEncryption){var u=e.sbgp(),c=e.saiz(t),l=e.saio(t),d=e.senc(t),f=e.trun1(t);return e.box(e.types.traf,a,r,u,c,l,d,f)}var h=e.sbgp(),p=e.trun1(t);return e.box(e.types.traf,a,r,h,p)}if(t.isVideo){var v=e.trun1(t);return e.box(e.types.traf,a,r,v)}var y=e.sbgp(),m=e.saiz(t),g=e.saio(t),k=e.senc(t),b=e.trun1(t);return e.box(e.types.traf,a,r,y,m,g,k,b)}var _=e.sdtp(t);return e.box(e.types.traf,a,r,_,e.trun(t.samples,_.byteLength+76))}},{key:"sdtp",value:function(t){var a=new _e;return t.samples.forEach((function(e){a.write(new Uint8Array(t.isVideo?[e.keyframe?32:16]:[16]))})),e.box(e.types.sdtp,this.extension(0,0),a.buffer)}},{key:"trun1",value:function(t){var a=new _e,r=_e.writeUint32(t.samples.length),s=null;if(t.isVideo){var i=t.videoSencLength;s=_e.writeUint32(16*t.samples.length+i+149),!t.isVideoEncryption&&t.isAudioEncryption&&(s=_e.writeUint32(16*t.samples.length+92))}else{var n=12*t.samples.length+124;t.isAudioEncryption&&(n=12*t.samples.length+8*t.audioSenc.length+177),s=_e.writeUint32(n)}return t.samples.forEach((function(e){a.write(_e.writeUint32(e.duration)),a.write(_e.writeUint32(e.size)),a.write(_e.writeUint32(e.keyframe?33554432:65536)),t.isVideo&&a.write(_e.writeUint32(e.cts?e.cts:0))})),e.box(e.types.trun,this.extension(0,t.flags),r,s,a.buffer)}},{key:"senc",value:function(t){var a=new _e,r=t.samples.length,s=t.isVideo?16:8,i=t.isVideo?2:0,n=[],o=0;return t.isVideo?(n=t.videoSenc,o=t.videoSencLength):n=t.audioSenc,o=o||s*r,a.write(_e.writeUint32(16+o),e.types.senc,this.extension(0,i)),a.write(_e.writeUint32(r)),n.forEach((function(e){for(var t=0;t<e.InitializationVector.length;t++)a.write(new Uint8Array([e.InitializationVector[t]]));e.subsamples&&e.subsamples.length&&(a.write(_e.writeUint16(e.subsamples.length)),e.subsamples.forEach((function(e){a.write(_e.writeUint16(e.BytesOfClearData)),a.write(_e.writeUint32(e.BytesOfProtectedData))})))})),a.buffer}},{key:"saio",value:function(t){var a=12*t.samples.length+141;!t.isVideo&&t.isAudioEncryption&&(a=149);var r=new Uint8Array([1,0,0,0,0,0,0,1,0,0,0,0,a>>24&255,a>>16&255,a>>8&255,255&a]);return e.box(e.types.saio,r)}},{key:"saiz",value:function(t){var a=t.samples.length,r=new Uint8Array([0,0,0,0,16,a>>24&255,a>>16&255,a>>8&255,255&a]);return e.box(e.types.saiz,r)}},{key:"sbgp",value:function(){var t=new Uint8Array([114,111,108,108,0,0,0,1,0,0,1,25,0,0,0,1]);return e.box(e.types.sbgp,this.extension(0,0),t)}},{key:"extension",value:function(e,t){return new Uint8Array([e,t>>16&255,t>>8&255,255&t])}},{key:"tfhd",value:function(t){return e.box(e.types.tfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"tfdt",value:function(t,a){var r=Math.floor(a/(xe+1)),s=Math.floor(a%(xe+1));return t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)?e.box(e.types.tfdt,new Uint8Array([0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s])):e.box(e.types.tfdt,new Uint8Array([1,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,s>>24,s>>16&255,s>>8&255,255&s]))}},{key:"trun",value:function(t,a){var r=t.length,s=12+16*r;a+=8+s;var i=new Uint8Array(s);i.set([0,0,15,1,r>>>24&255,r>>>16&255,r>>>8&255,255&r,a>>>24&255,a>>>16&255,a>>>8&255,255&a],0);for(var n=0;n<r;n++){var o=t[n],u=o.duration,c=o.size,l=o.flag,d=void 0===l?{}:l,f=o.cts,h=void 0===f?0:f;i.set([u>>>24&255,u>>>16&255,u>>>8&255,255&u,c>>>24&255,c>>>16&255,c>>>8&255,255&c,d.isLeading<<2|(null===d.dependsOn||void 0===d.dependsOn?1:d.dependsOn),d.isDependedOn<<6|d.hasRedundancy<<4|d.paddingValue<<1|(null===d.isNonSyncSample||void 0===d.isNonSyncSample?1:d.isNonSyncSample),61440&d.degradationPriority,15&d.degradationPriority,h>>>24&255,h>>>16&255,h>>>8&255,255&h],12+16*n)}return e.box(e.types.trun,i)}},{key:"moovMP4",value:function(t){return e.box.apply(e,[e.types.moov,e.mvhd(t[0].duration,t[0].timescale)].concat(y(t.map((function(t){return e.trackMP4(t)})))))}},{key:"trackMP4",value:function(t){return e.box(e.types.trak,e.tkhd(t.id,t.duration,t.width,t.height),e.mdiaMP4(t))}},{key:"mdiaMP4",value:function(t){return e.box(e.types.mdia,e.mdhd(t.duration,t.timescale),e.hdlr(t.type),e.minfMP4(t))}},{key:"minfMP4",value:function(t){return e.box(e.types.minf,t.type===k.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stblMP4(t))}},{key:"stblMP4",value:function(t){var a=t.ext,r=[e.stsd(t),e.stts(a.stts),e.stsc(a.stsc),e.stsz(a.stsz),e.stco(a.stco)];return a.stss.length&&r.push(e.stss(a.stss)),a.ctts.length&&r.push(e.ctts(a.ctts)),e.box.apply(e,[e.types.stbl].concat(r))}},{key:"stts",value:function(t){var a=t.length,r=new Uint8Array(8*a),s=0;return t.forEach((function(e){var t=e.value,a=e.count;r.set([a>>24,a>>16&255,a>>8&255,255&a,t>>24,t>>16&255,t>>8&255,255&t],s),s+=8})),e.box(e.types.stts,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stsc",value:function(t){var a=t.length,r=new Uint8Array(12*a),s=0;return t.forEach((function(e){var t=e.firstChunk,a=e.samplesPerChunk,i=e.sampleDescIndex;r.set([t>>24,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],s),s+=12})),e.box(e.types.stsc,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stsz",value:function(t){var a=t.length,r=new Uint8Array(4*a),s=0;return t.forEach((function(e){r.set([e>>24,e>>16&255,e>>8&255,255&e],s),s+=4})),e.box(e.types.stsz,L(new Uint8Array([0,0,0,0,0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stco",value:function(t){var a=t.length,r=new Uint8Array(4*a),s=0;return t.forEach((function(e){r.set([e>>24,e>>16&255,e>>8&255,255&e],s),s+=4})),e.box(e.types.stco,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"stss",value:function(t){var a=t.length,r=new Uint8Array(4*a),s=0;return t.forEach((function(e){r.set([e>>24,e>>16&255,e>>8&255,255&e],s),s+=4})),e.box(e.types.stss,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"ctts",value:function(t){var a=t.length,r=new Uint8Array(8*a),s=0;return t.forEach((function(e){var t=e.value,a=e.count;r.set([a>>24,a>>16&255,a>>8&255,255&a,t>>24,t>>16&255,t>>8&255,255&t],s),s+=8})),e.box(e.types.ctts,L(new Uint8Array([0,0,0,0,a>>24,a>>16&255,a>>8&255,255&a]),r))}},{key:"styp",value:function(){return e.box(e.types.styp,new Uint8Array([109,115,100,104,0,0,0,0,109,115,100,104,109,115,105,120]))}},{key:"sidx",value:function(t){var a=t.timescale,r=t.samples[0].duration,s=r*t.samples.length,i=t.samples[0].sampleOffset*r,n=8;t.samples.forEach((function(e){n+=e.size}));var o=0;if(t.isVideo){var u,c=0;t.videoSenc&&(u=t.videoSenc),t.isVideo&&u.forEach((function(e){c+=8,e.subsamples&&e.subsamples.length&&(c+=2,c+=6*e.subsamples.length)})),t.videoSencLength=c,o=n+141+16*t.samples.length+c,t.useEME&&t.isAudioEncryption&&!t.isVideoEncryption&&(o=n+16*t.samples.length+84)}else o=n+116+12*t.samples.length,t.useEME&&t.isAudioEncryption&&(o=n+169+12*t.samples.length+8*t.audioSenc.length);var l=new Uint8Array([0,0,0,0,0,0,0,255&t.id,a>>24&255,a>>16&255,a>>8&255,255&a,i>>24&255,i>>16&255,i>>8&255,255&i,0,0,0,0,0,0,0,1,0,o>>16&255,o>>8&255,255&o,s>>24&255,s>>16&255,s>>8&255,255&s,144,0,0,0]);return e.box(e.types.sidx,l)}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}}]),e}();i(we,"types",["avc1","avcC","hvc1","hvcC","dinf","dref","esds","ftyp","hdlr","mdat","mdhd","mdia","mfhd","minf","moof","moov","mp4a","mvex","mvhd","pasp","stbl","stco","stsc","stsd","stsz","stts","tfdt","tfhd","traf","trak","trex","tkhd","vmhd","smhd","ctts","stss","styp","pssh","sidx","sbgp","saiz","saio","senc","trun","encv","enca","sinf","btrt","frma","tenc","schm","schi","mehd","fiel","sdtp"].reduce((function(e,t){return e[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)],e}),Object.create(null))),i(we,"HDLR_TYPES",{video: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]),audio: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(we,"FTYPAVC1",we.box(we.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))),i(we,"FTYPHEV1",we.box(we.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,104,101,118,49]))),i(we,"DINF",we.box(we.types.dinf,we.box(we.types.dref,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1])))),i(we,"VMHD",we.box(we.types.vmhd,new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))),i(we,"SMHD",we.box(we.types.smhd,new Uint8Array([0,0,0,0,0,0,0,0]))),i(we,"StblTable",new Uint8Array([0,0,0,0,0,0,0,0])),i(we,"STTS",we.box(we.types.stts,we.StblTable)),i(we,"STSC",we.box(we.types.stsc,we.StblTable)),i(we,"STSZ",we.box(we.types.stsz,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]))),i(we,"STCO",we.box(we.types.stco,we.StblTable));var De=function(){function e(t,r){a(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]"),e.disabled=r}return s(e,[{key:"debug",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).debug.apply(t,[this._prefix].concat(r))}}},{key:"log",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).log.apply(t,[this._prefix].concat(r))}}},{key:"warn",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).warn.apply(t,[this._prefix].concat(r))}}},{key:"error",value:function(){var t;if(!e.disabled){for(var a=arguments.length,r=new Array(a),s=0;s<a;s++)r[s]=arguments[s];(t=console).error.apply(t,[this._prefix].concat(r))}}},{key:"table",value:function(){var t;e.disabled||(console.group(this._prefix),(t=console).table.apply(t,arguments),console.groupEnd())}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();i(De,"disabled",!0);for(var Se=function(){function e(t,r,s){a(this,e),this.videoTrack=t,this.audioTrack=r;var i=/Chrome\/([^.]+)/.exec(navigator.userAgent);this.forceFirstIDR=i&&Number(i[1])<50,this.log=new De("FMP4Remuxer",!s||!s.openLog||!s.openLog)}return s(e,[{key:"remux",value:function(){var e,t,a,r,s,i=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=this.videoTrack,u=this.audioTrack,c=o.exist(),l=u.exist(),d=[];return i&&(n&&n.initMerge?(c&&d.push(this.videoTrack),l&&d.push(this.audioTrack),a=we.initSegment(d)):(c&&(e=we.initSegment([this.videoTrack])),l&&(t=we.initSegment([this.audioTrack])))),c&&o.hasSample()&&(r=this._remuxVideo()),l&&u.hasSample()&&(s=this._remuxAudio()),o.samples=[],u.samples=[],{initSegment:a,videoInitSegment:e,audioInitSegment:t,videoSegment:r,audioSegment:s}}},{key:"_remuxVideo",value:function(){var e=this.videoTrack;this.forceFirstIDR&&(e.samples[0].flag={dependsOn:2,isNonSyncSample:0});var t=e.samples,a=0;t.forEach((function(e){a+=e.units.reduce((function(e,t){return e+t.byteLength}),0),a+=4*e.units.length}));for(var r,s=new Uint8Array(a),i=new DataView(s.buffer),n=function(e,a,n,o){o=t[e];var u=0;o.units.forEach((function(e){i.setUint32(n,e.byteLength),n+=4,s.set(e,n),n+=e.byteLength,u+=4+e.byteLength})),o.size=u,c=n,r=o},o=0,u=t.length,c=0;o<u;o++)n(o,0,c,r);var l=we.mdat(s);return L(we.moof([e]),l)}},{key:"_remuxAudio",value:function(){var e=this.audioTrack,t=new Uint8Array(e.samples.reduce((function(e,t){return e+t.size}),0));e.samples.reduce((function(e,a){return t.set(a.data,e),e+a.size}),0);var a=we.mdat(t);return L(we.moof([e]),a)}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset()}}]),e}(),Ae=function(){function e(){a(this,e)}return s(e,[{key:"mixIn",value:function(e){return Object.assign(this,e)}},{key:"clone",value:function(){var e=new this.constructor;return Object.assign(e,this),e}}],[{key:"create",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return l(this,t)}}]),e}(),Te=function(e){n(r,e);var t=f(r);function r(){var e,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4*s.length;a(this,r),e=t.call(this);var n=s;if(n instanceof ArrayBuffer&&(n=new Uint8Array(n)),(n instanceof Int8Array||n instanceof Uint8ClampedArray||n instanceof Int16Array||n instanceof Uint16Array||n instanceof Int32Array||n instanceof Uint32Array||n instanceof Float32Array||n instanceof Float64Array)&&(n=new Uint8Array(n.buffer,n.byteOffset,n.byteLength)),n instanceof Uint8Array){for(var o=n.byteLength,u=[],c=0;c<o;c+=1)u[c>>>2]|=n[c]<<24-c%4*8;e.words=u,e.sigBytes=o}else e.words=s,e.sigBytes=i;return e}return s(r,[{key:"toString",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:je;return e.stringify(this)}},{key:"concat",value:function(e){var t=this.words,a=e.words,r=this.sigBytes,s=e.sigBytes;if(this.clamp(),r%4)for(var i=0;i<s;i+=1){var n=a[i>>>2]>>>24-i%4*8&255;t[r+i>>>2]|=n<<24-(r+i)%4*8}else for(var o=0;o<s;o+=4)t[r+o>>>2]=a[o>>>2];return this.sigBytes+=s,this}},{key:"clamp",value:function(){var e=this.words,t=this.sigBytes;e[t>>>2]&=4294967295<<32-t%4*8,e.length=Math.ceil(t/4)}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e.words=this.words.slice(0),e}}],[{key:"random",value:function(e){for(var t,a=[],s=function(e){var t=e,a=987654321,r=4294967295;return function(){var e=((a=36969*(65535&a)+(a>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return e/=4294967296,(e+=.5)*(Math.random()>.5?1:-1)}},i=0;i<e;i+=4){var n=s(4294967296*(t||Math.random()));t=987654071*n(),a.push(4294967296*n()|0)}return new r(a,e)}}]),r}(Ae),je={stringify:function(e){for(var t=e.words,a=e.sigBytes,r=[],s=0;s<a;s+=1){var i=t[s>>>2]>>>24-s%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,a=[],r=0;r<t;r+=2)a[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new Te(a,t/2)}},Ee=function(e){for(var t=e.length,a=[],r=0;r<t;r+=1)a[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new Te(a,t)},Be=function(e){return Ee(unescape(encodeURIComponent(e)))},Ce=function(e){n(r,e);var t=f(r);function r(){var e;return a(this,r),(e=t.call(this))._minBufferSize=0,e}return s(r,[{key:"reset",value:function(){this._data=new Te,this._nDataBytes=0}},{key:"_append",value:function(e){var t=e;"string"==typeof t&&(t=Be(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes}},{key:"_process",value:function(e){var t,a=this._data,r=this.blockSize,s=a.words,i=a.sigBytes,n=i/(4*r),o=(n=e?Math.ceil(n):Math.max((0|n)-this._minBufferSize,0))*r,u=Math.min(4*o,i);if(o){for(var c=0;c<o;c+=r)this._doProcessBlock(s,c);t=s.splice(0,o),a.sigBytes-=u}return new Te(t,u)}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e._data=this._data.clone(),e}}]),r}(Ae),Pe=function(e){n(r,e);var t=f(r);function r(e){var s;return a(this,r),(s=t.call(this)).blockSize=16,s.cfg=Object.assign(new Ae,e),s.reset(),s}return s(r,[{key:"reset",value:function(){p(o(r.prototype),"reset",this).call(this),this._doReset()}},{key:"update",value:function(e){return this._append(e),this._process(),this}},{key:"finalize",value:function(e){return e&&this._append(e),this._doFinalize()}}],[{key:"_createHelper",value:function(e){return function(t,a){return new e(a).finalize(t)}}},{key:"_createHmacHelper",value:function(e){return function(t,a){return new Ue(e,a).finalize(t)}}}]),r}(Ce),Ue=function(e){n(r,e);var t=f(r);function r(e,s){var i;a(this,r),i=t.call(this);var n=new e;i._hasher=n;var o=s;"string"==typeof o&&(o=Be(o));var u=n.blockSize,c=4*u;o.sigBytes>c&&(o=n.finalize(s)),o.clamp();var l=o.clone();i._oKey=l;var d=o.clone();i._iKey=d;for(var f=l.words,h=d.words,p=0;p<u;p+=1)f[p]^=1549556828,h[p]^=909522486;return l.sigBytes=c,d.sigBytes=c,i.reset(),i}return s(r,[{key:"reset",value:function(){var e=this._hasher;e.reset(),e.update(this._iKey)}},{key:"update",value:function(e){return this._hasher.update(e),this}},{key:"finalize",value:function(e){var t=this._hasher,a=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(a))}}]),r}(Ae),Ie={stringify:function(e){var t=e.words,a=e.sigBytes,r=this._map;e.clamp();for(var s=[],i=0;i<a;i+=3)for(var n=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,o=0;o<4&&i+.75*o<a;o+=1)s.push(r.charAt(n>>>6*(3-o)&63));var u=r.charAt(64);if(u)for(;s.length%4;)s.push(u);return s.join("")},parse:function(e){var t=e.length,a=this._map,r=this._reverseMap;if(!r){this._reverseMap=[],r=this._reverseMap;for(var s=0;s<a.length;s+=1)r[a.charCodeAt(s)]=s}var i=a.charAt(64);if(i){var n=e.indexOf(i);-1!==n&&(t=n)}return function(e,t,a){for(var r=[],s=0,i=0;i<t;i+=1)if(i%4){var n=a[e.charCodeAt(i-1)]<<i%4*2|a[e.charCodeAt(i)]>>>6-i%4*2;r[s>>>2]|=n<<24-s%4*8,s+=1}return Te.create(r,s)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},Me=[],Oe=0;Oe<64;Oe+=1)Me[Oe]=4294967296*Math.abs(Math.sin(Oe+1))|0;var ze=function(e,t,a,r,s,i,n){var o=e+(t&a|~t&r)+s+n;return(o<<i|o>>>32-i)+t},Re=function(e,t,a,r,s,i,n){var o=e+(t&r|a&~r)+s+n;return(o<<i|o>>>32-i)+t},Ve=function(e,t,a,r,s,i,n){var o=e+(t^a^r)+s+n;return(o<<i|o>>>32-i)+t},Le=function(e,t,a,r,s,i,n){var o=e+(a^(t|~r))+s+n;return(o<<i|o>>>32-i)+t},Ne=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"_doReset",value:function(){this._hash=new Te([1732584193,4023233417,2562383102,271733878])}},{key:"_doProcessBlock",value:function(e,t){for(var a=e,r=0;r<16;r+=1){var s=t+r,i=e[s];a[s]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8)}var n=this._hash.words,o=a[t+0],u=a[t+1],c=a[t+2],l=a[t+3],d=a[t+4],f=a[t+5],h=a[t+6],p=a[t+7],v=a[t+8],y=a[t+9],m=a[t+10],g=a[t+11],k=a[t+12],b=a[t+13],_=a[t+14],x=a[t+15],w=n[0],D=n[1],S=n[2],A=n[3];w=ze(w,D,S,A,o,7,Me[0]),A=ze(A,w,D,S,u,12,Me[1]),S=ze(S,A,w,D,c,17,Me[2]),D=ze(D,S,A,w,l,22,Me[3]),w=ze(w,D,S,A,d,7,Me[4]),A=ze(A,w,D,S,f,12,Me[5]),S=ze(S,A,w,D,h,17,Me[6]),D=ze(D,S,A,w,p,22,Me[7]),w=ze(w,D,S,A,v,7,Me[8]),A=ze(A,w,D,S,y,12,Me[9]),S=ze(S,A,w,D,m,17,Me[10]),D=ze(D,S,A,w,g,22,Me[11]),w=ze(w,D,S,A,k,7,Me[12]),A=ze(A,w,D,S,b,12,Me[13]),S=ze(S,A,w,D,_,17,Me[14]),D=ze(D,S,A,w,x,22,Me[15]),w=Re(w,D,S,A,u,5,Me[16]),A=Re(A,w,D,S,h,9,Me[17]),S=Re(S,A,w,D,g,14,Me[18]),D=Re(D,S,A,w,o,20,Me[19]),w=Re(w,D,S,A,f,5,Me[20]),A=Re(A,w,D,S,m,9,Me[21]),S=Re(S,A,w,D,x,14,Me[22]),D=Re(D,S,A,w,d,20,Me[23]),w=Re(w,D,S,A,y,5,Me[24]),A=Re(A,w,D,S,_,9,Me[25]),S=Re(S,A,w,D,l,14,Me[26]),D=Re(D,S,A,w,v,20,Me[27]),w=Re(w,D,S,A,b,5,Me[28]),A=Re(A,w,D,S,c,9,Me[29]),S=Re(S,A,w,D,p,14,Me[30]),D=Re(D,S,A,w,k,20,Me[31]),w=Ve(w,D,S,A,f,4,Me[32]),A=Ve(A,w,D,S,v,11,Me[33]),S=Ve(S,A,w,D,g,16,Me[34]),D=Ve(D,S,A,w,_,23,Me[35]),w=Ve(w,D,S,A,u,4,Me[36]),A=Ve(A,w,D,S,d,11,Me[37]),S=Ve(S,A,w,D,p,16,Me[38]),D=Ve(D,S,A,w,m,23,Me[39]),w=Ve(w,D,S,A,b,4,Me[40]),A=Ve(A,w,D,S,o,11,Me[41]),S=Ve(S,A,w,D,l,16,Me[42]),D=Ve(D,S,A,w,h,23,Me[43]),w=Ve(w,D,S,A,y,4,Me[44]),A=Ve(A,w,D,S,k,11,Me[45]),S=Ve(S,A,w,D,x,16,Me[46]),D=Ve(D,S,A,w,c,23,Me[47]),w=Le(w,D,S,A,o,6,Me[48]),A=Le(A,w,D,S,p,10,Me[49]),S=Le(S,A,w,D,_,15,Me[50]),D=Le(D,S,A,w,f,21,Me[51]),w=Le(w,D,S,A,k,6,Me[52]),A=Le(A,w,D,S,l,10,Me[53]),S=Le(S,A,w,D,m,15,Me[54]),D=Le(D,S,A,w,u,21,Me[55]),w=Le(w,D,S,A,v,6,Me[56]),A=Le(A,w,D,S,x,10,Me[57]),S=Le(S,A,w,D,h,15,Me[58]),D=Le(D,S,A,w,b,21,Me[59]),w=Le(w,D,S,A,d,6,Me[60]),A=Le(A,w,D,S,g,10,Me[61]),S=Le(S,A,w,D,c,15,Me[62]),D=Le(D,S,A,w,y,21,Me[63]),n[0]=n[0]+w|0,n[1]=n[1]+D|0,n[2]=n[2]+S|0,n[3]=n[3]+A|0}},{key:"_doFinalize",value:function(){var e=this._data,t=e.words,a=8*this._nDataBytes,r=8*e.sigBytes;t[r>>>5]|=128<<24-r%32;var s=Math.floor(a/4294967296),i=a;t[15+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t[14+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),e.sigBytes=4*(t.length+1),this._process();for(var n=this._hash,o=n.words,u=0;u<4;u+=1){var c=o[u];o[u]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}return n}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e._hash=this._hash.clone(),e}}]),r}(Pe);Pe._createHelper(Ne),Pe._createHmacHelper(Ne);var Fe=function(e){n(r,e);var t=f(r);function r(e){var s;return a(this,r),(s=t.call(this)).cfg=Object.assign(new Ae,{keySize:4,hasher:Ne,iterations:1},e),s}return s(r,[{key:"compute",value:function(e,t){for(var a,r=this.cfg,s=r.hasher.create(),i=Te.create(),n=i.words,o=r.keySize,u=r.iterations;n.length<o;){a&&s.update(a),a=s.update(e).finalize(t),s.reset();for(var c=1;c<u;c+=1)a=s.finalize(a),s.reset();i.concat(a)}return i.sigBytes=4*o,i}}]),r}(Ae),Ge=function(e){n(r,e);var t=f(r);function r(e,s,i){var n;return a(this,r),(n=t.call(this)).cfg=Object.assign(new Ae,i),n._xformMode=e,n._key=s,n.reset(),n}return s(r,[{key:"reset",value:function(){p(o(r.prototype),"reset",this).call(this),this._doReset()}},{key:"process",value:function(e){return this._append(e),this._process()}},{key:"finalize",value:function(e){return e&&this._append(e),this._doFinalize()}}],[{key:"createEncryptor",value:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)}},{key:"createDecryptor",value:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)}},{key:"_createHelper",value:function(e){var t=function(e){return"string"==typeof e?$e:Qe};return{encrypt:function(a,r,s){return t(r).encrypt(e,a,r,s)},decrypt:function(a,r,s){return t(r).decrypt(e,a,r,s)}}}}]),r}(Ce);Ge._ENC_XFORM_MODE=1,Ge._DEC_XFORM_MODE=2,Ge.keySize=4,Ge.ivSize=4;var qe=function(e){n(r,e);var t=f(r);function r(e,s){var i;return a(this,r),(i=t.call(this))._cipher=e,i._iv=s,i}return s(r,null,[{key:"createEncryptor",value:function(e,t){return this.Encryptor.create(e,t)}},{key:"createDecryptor",value:function(e,t){return this.Decryptor.create(e,t)}}]),r}(Ae);function He(e,t,a){var r,s=e,i=this._iv;i?(r=i,this._iv=void 0):r=this._prevBlock;for(var n=0;n<a;n+=1)s[t+n]^=r[n]}var Ke=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(qe);Ke.Encryptor=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"processBlock",value:function(e,t){var a=this._cipher,r=a.blockSize;He.call(this,e,t,r),a.encryptBlock(e,t),this._prevBlock=e.slice(t,t+r)}}]),r}(Ke),Ke.Decryptor=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"processBlock",value:function(e,t){var a=this._cipher,r=a.blockSize,s=e.slice(t,t+r);a.decryptBlock(e,t),He.call(this,e,t,r),this._prevBlock=s}}]),r}(Ke);var We={pad:function(e,t){for(var a=4*t,r=a-e.sigBytes%a,s=r<<24|r<<16|r<<8|r,i=[],n=0;n<r;n+=4)i.push(s);var o=Te.create(i,r);e.concat(o)},unpad:function(e){var t=e,a=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=a}},Xe=function(e){n(r,e);var t=f(r);function r(e,s,i){var n;return a(this,r),(n=t.call(this,e,s,Object.assign({mode:Ke,padding:We},i))).blockSize=4,n}return s(r,[{key:"reset",value:function(){var e;p(o(r.prototype),"reset",this).call(this);var t=this.cfg,a=t.iv,s=t.mode;this._xformMode===this.constructor._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode=e.call(s,this,a&&a.words),this._mode.__creator=e}},{key:"_doProcessBlock",value:function(e,t){this._mode.processBlock(e,t)}},{key:"_doFinalize",value:function(){var e,t=this.cfg.padding;return this._xformMode===this.constructor._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e}}]),r}(Ge),Ye=function(e){n(r,e);var t=f(r);function r(e){var s;return a(this,r),(s=t.call(this)).mixIn(e),s}return s(r,[{key:"toString",value:function(e){return(e||this.formatter).stringify(this)}}]),r}(Ae),Ze={stringify:function(e){var t=e.ciphertext,a=e.salt;return(a?Te.create([1398893684,1701076831]).concat(a).concat(t):t).toString(Ie)},parse:function(e){var t,a=Ie.parse(e),r=a.words;return 1398893684===r[0]&&1701076831===r[1]&&(t=Te.create(r.slice(2,4)),r.splice(0,4),a.sigBytes-=16),Ye.create({ciphertext:a,salt:t})}},Qe=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,null,[{key:"encrypt",value:function(e,t,a,r){var s=Object.assign(new Ae,this.cfg,r),i=e.createEncryptor(a,s),n=i.finalize(t),o=i.cfg;return Ye.create({ciphertext:n,key:a,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:i.blockSize,formatter:s.format})}},{key:"decrypt",value:function(e,t,a,r){var s=t,i=Object.assign(new Ae,this.cfg,r);return s=this._parse(s,i.format),e.createDecryptor(a,i).finalize(s.ciphertext)}},{key:"_parse",value:function(e,t){return"string"==typeof e?t.parse(e,this):e}}]),r}(Ae);Qe.cfg=Object.assign(new Ae,{format:Ze});var Je={execute:function(e,t,a,r){var s=r;s||(s=Te.random(8));var i=Fe.create({keySize:t+a}).compute(e,s),n=Te.create(i.words.slice(t),4*a);return i.sigBytes=4*t,Ye.create({key:i,iv:n,salt:s})}},$e=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,null,[{key:"encrypt",value:function(e,t,a,r){var s=Object.assign(new Ae,this.cfg,r),i=s.kdf.execute(a,e.keySize,e.ivSize);s.iv=i.iv;var n=Qe.encrypt.call(this,e,t,i.key,s);return n.mixIn(i),n}},{key:"decrypt",value:function(e,t,a,r){var s=t,i=Object.assign(new Ae,this.cfg,r);s=this._parse(s,i.format);var n=i.kdf.execute(a,e.keySize,e.ivSize,s.salt);return i.iv=n.iv,Qe.decrypt.call(this,e,s,n.key,i)}}]),r}(Qe);$e.cfg=Object.assign(Qe.cfg,{kdf:Je});for(var et=[],tt=[],at=[],rt=[],st=[],it=[],nt=[],ot=[],ut=[],ct=[],lt=[],dt=0;dt<256;dt+=1)lt[dt]=dt<128?dt<<1:dt<<1^283;for(var ft=0,ht=0,pt=0;pt<256;pt+=1){var vt=ht^ht<<1^ht<<2^ht<<3^ht<<4;vt=vt>>>8^255&vt^99,et[ft]=vt,tt[vt]=ft;var yt=lt[ft],mt=lt[yt],gt=lt[mt],kt=257*lt[vt]^16843008*vt;at[ft]=kt<<24|kt>>>8,rt[ft]=kt<<16|kt>>>16,st[ft]=kt<<8|kt>>>24,it[ft]=kt,kt=16843009*gt^65537*mt^257*yt^16843008*ft,nt[vt]=kt<<24|kt>>>8,ot[vt]=kt<<16|kt>>>16,ut[vt]=kt<<8|kt>>>24,ct[vt]=kt,ft?(ft=yt^lt[lt[lt[gt^yt]]],ht^=lt[lt[ht]]):ft=ht=1}var bt=[0,1,2,4,8,16,32,64,128,27,54],_t=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"_doReset",value:function(){var e;if(!this._nRounds||this._keyPriorReset!==this._key){this._keyPriorReset=this._key;var t=this._keyPriorReset,a=t.words,r=t.sigBytes/4;this._nRounds=r+6;var s=4*(this._nRounds+1);this._keySchedule=[];for(var i=this._keySchedule,n=0;n<s;n+=1)n<r?i[n]=a[n]:(e=i[n-1],n%r?r>6&&n%r==4&&(e=et[e>>>24]<<24|et[e>>>16&255]<<16|et[e>>>8&255]<<8|et[255&e]):(e=et[(e=e<<8|e>>>24)>>>24]<<24|et[e>>>16&255]<<16|et[e>>>8&255]<<8|et[255&e],e^=bt[n/r|0]<<24),i[n]=i[n-r]^e);this._invKeySchedule=[];for(var o=this._invKeySchedule,u=0;u<s;u+=1){var c=s-u;e=u%4?i[c]:i[c-4],o[u]=u<4||c<=4?e:nt[et[e>>>24]]^ot[et[e>>>16&255]]^ut[et[e>>>8&255]]^ct[et[255&e]]}}}},{key:"encryptBlock",value:function(e,t){this._doCryptBlock(e,t,this._keySchedule,at,rt,st,it,et)}},{key:"decryptBlock",value:function(e,t){var a=e,r=a[t+1];a[t+1]=a[t+3],a[t+3]=r,this._doCryptBlock(a,t,this._invKeySchedule,nt,ot,ut,ct,tt),r=a[t+1],a[t+1]=a[t+3],a[t+3]=r}},{key:"_doCryptBlock",value:function(e,t,a,r,s,i,n,o){for(var u=e,c=this._nRounds,l=u[t]^a[0],d=u[t+1]^a[1],f=u[t+2]^a[2],h=u[t+3]^a[3],p=4,v=1;v<c;v+=1){var y=r[l>>>24]^s[d>>>16&255]^i[f>>>8&255]^n[255&h]^a[p];p+=1;var m=r[d>>>24]^s[f>>>16&255]^i[h>>>8&255]^n[255&l]^a[p];p+=1;var g=r[f>>>24]^s[h>>>16&255]^i[l>>>8&255]^n[255&d]^a[p];p+=1;var k=r[h>>>24]^s[l>>>16&255]^i[d>>>8&255]^n[255&f]^a[p];p+=1,l=y,d=m,f=g,h=k}var b=(o[l>>>24]<<24|o[d>>>16&255]<<16|o[f>>>8&255]<<8|o[255&h])^a[p];p+=1;var _=(o[d>>>24]<<24|o[f>>>16&255]<<16|o[h>>>8&255]<<8|o[255&l])^a[p];p+=1;var x=(o[f>>>24]<<24|o[h>>>16&255]<<16|o[l>>>8&255]<<8|o[255&d])^a[p];p+=1;var w=(o[h>>>24]<<24|o[l>>>16&255]<<16|o[d>>>8&255]<<8|o[255&f])^a[p];p+=1,u[t]=b,u[t+1]=_,u[t+2]=x,u[t+3]=w}}]),r}(Xe);_t.keySize=8;var xt=Xe._createHelper(_t),wt=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(qe);wt.Encryptor=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r,[{key:"processBlock",value:function(e,t){var a=e,r=this._cipher,s=r.blockSize,i=this._iv,n=this._counter;i&&(this._counter=i.slice(0),n=this._counter,this._iv=void 0);var o=n.slice(0);r.encryptBlock(o,0),n[s-1]=n[s-1]+1|0;for(var u=0;u<s;u+=1)a[t+u]^=o[u]}}]),r}(wt),wt.Decryptor=wt.Encryptor;var Dt={pad:function(){},unpad:function(){}},St={decryptWordArray:function(e,t,a){var r=je.parse(t),s=je.parse(K(a)),i=Te.create(new Uint8Array(e)),n=xt.decrypt(Ye.create({ciphertext:i}),r,{iv:s,mode:wt,padding:Dt});return St.wordArrayToUint8Array(n)},wordArrayToUint8Array:function(e){for(var t=e.sigBytes,a=e.words,r=new Uint8Array(t),s=0,i=0;s!==t;){var n=a[i++];if(r[s++]=(4278190080&n)>>>24,s===t)break;if(r[s++]=(16711680&n)>>>16,s===t)break;if(r[s++]=(65280&n)>>>8,s===t)break;r[s++]=255&n}return r},decoderAESCTRData:function(e,t){if(e.videoSenc){var a=e.kidValue,r=e.videoSenc;e.samples.forEach((function(t,s){var i=r[s],n=t.data,o=[],u=[],c=i.InitializationVector;if(i.subsamples&&i.subsamples.length)i.subsamples.forEach((function(e){var t=e.BytesOfClearData+e.BytesOfProtectedData,a=n.slice(0,t);o.push(a.slice(0,e.BytesOfClearData)),u.push(a.slice(e.BytesOfClearData)),n=n.slice(t)}));else{var l=t.size;o.push(n.slice(0,0)),u.push(n.slice(0,l)),n=n.slice(l)}var d=new _e;d.write.apply(d,u);var f=St.decryptWordArray(d.buffer,a,c),h=new _e;o.forEach((function(e,t){var a=u[t].length,r=f.slice(0,a);h.write(e),h.write(r),f=f.slice(a)})),e.samples[s].data=h.buffer}))}if(t.audioSenc){var s=t.kidValue,i=t.audioSenc;t.samples.forEach((function(e,a){var r=i[a],n=St.decryptWordArray(e.data,s,r.InitializationVector);t.samples[a].data=n}))}}},At=function(){function e(t,r,s,n){var o=this;a(this,e),i(this,"_videoSamples",[]),i(this,"_audioSamples",[]),i(this,"_lastRemainBuffer",[]),i(this,"_lastRemainBufferStartPos",0),this.videoTrack=new w,this.audioTrack=new D,this.metadataTrack=s||new B,this.log=new De("MP4Demuxer",!n||!n.openLog||!n.openLog),t&&t.forEach((function(e){var t;(t=o._videoSamples).push.apply(t,y(e.frames))})),r&&r.forEach((function(e){var t;(t=o._audioSamples).push.apply(t,y(e.frames))}))}return s(e,[{key:"parseSamples",value:function(e){if(!e)throw new Error("moov is required");if(this.videoTrack.codec||this.audioTrack.codec||(fe.moovToTrack(e,this.videoTrack,this.audioTrack),this.videoSenc=this.videoTrack.videoSenc,this.audioSenc=this.audioTrack.audioSenc),!this._audioSamples.length&&!this._videoSamples.length){var t=fe.moovToSamples(e);if(!t)throw new Error("cannot parse samples from moov box");this._videoSamples=t.videoSamples||[],this._audioSamples=t.audioSamples||[]}}},{key:"demux",value:function(e,t,a,r,s){this.parseSamples(s);var i,n,o,u=this.videoTrack,c=this.audioTrack;if(u.samples=[],c.samples=[],a){for(var l,d=0,f=a[0],h=a[1];f<=h;f++){if(!(i=this._videoSamples[f]))throw new Error("cannot found video frame #".concat(f));o=i.offset-t,n=e.subarray(o,o+i.size),(l=new S(i.pts||i.dts,i.dts)).duration=i.duration,l.gopId=i.gopId,i.keyframe&&l.setToKeyframe();for(var p=0,v=n.length-1;p<v;)d=G(n,p),p+=4,l.units.push(n.subarray(p,p+d)),p+=d;u.samples.push(l)}u.baseMediaDecodeTime=u.samples[0].dts}if(r){for(var y=r[0],m=r[1];y<=m;y++){if(!(i=this._audioSamples[y]))throw new Error("cannot found video frame #".concat(y));o=i.offset-t,n=e.subarray(o,o+i.size),c.samples.push(new A(i.dts,n,i.duration))}c.baseMediaDecodeTime=c.samples[0].dts}return{videoTrack:u,audioTrack:c,metadataTrack:this.metadataTrack}}},{key:"demuxPart",value:function(e,t,a,r,s,i,n){if(this.parseSamples(s),this.videoTrack.useEME=i,this.audioTrack.useEME=i,this._lastRemainBuffer&&this._lastRemainBuffer.byteLength>0&&t>this._lastRemainBufferStartPos&&t<=this._lastRemainBufferStartPos+this._lastRemainBuffer.byteLength)for(var o=0;o<20;)try{var u=this._lastRemainBuffer.subarray(0,t-this._lastRemainBufferStartPos),c=new Uint8Array(e.byteLength+u.byteLength);c.set(u,0),c.set(new Uint8Array(e),u.byteLength),e=c,t-=u.byteLength,this._lastRemainBuffer=null,this._lastRemainBufferStartPos=0;break}catch(j){if(!(o<20))throw new Error("new Uint8Array error:,"+j.errorMessage);o++}var l,d,f,h=this.videoTrack,p=this.audioTrack;h.samples=[],p.samples=[],h.videoSenc=null,p.audioSenc=null;var v=0,y=0;if(this._videoSamples.length>0&&a.length>0){for(var m,g=e.byteLength+t,k=a[0];k<=a[1];k++){if(!(l=this._videoSamples[k]))throw new Error("cannot found video frame #".concat(k));l.offset>=t&&l.offset+l.size<=g&&(v=(f=l.offset-t)+l.size,d=e.subarray(f,v),(m=new S(l.pts||l.dts,l.dts)).duration=l.duration,m.gopId=l.gopId,m.sampleOffset=l.index,l.keyframe&&m.setToKeyframe(),m.data=d,m.size=l.size,h.samples.push(m))}h.samples.length>0&&(h.gopId=h.samples[0].gopId,h.baseMediaDecodeTime=h.samples[0].dts,h.startPts=h.samples[0].pts/h.timescale,h.endPts=h.samples[h.samples.length-1].pts/h.timescale,this.videoSenc&&(h.videoSenc=this.videoSenc.slice(h.samples[0].sampleOffset,h.samples[0].sampleOffset+h.samples.length),h.kidValue=n))}if(this._audioSamples.length>0&&r.length>0){for(var b=r[0];b<=r[1];b++){if(!(l=this._audioSamples[b]))throw new Error("cannot found video frame #".concat(b));l.offset>=t&&l.offset+l.size<=e.byteLength+t&&(y=(f=l.offset-t)+l.size,d=e.subarray(f,y),p.samples.push(new A(l.dts,d,l.duration,l.index)))}p.samples.length>0&&(p.gopId=p.samples[0].gopId||h.gopId,p.baseMediaDecodeTime=p.samples[0].dts,p.startPts=p.samples[0].pts/p.timescale,p.endPts=p.samples[p.samples.length-1].pts/p.timescale,this.audioSenc&&(p.audioSenc=this.audioSenc.slice(p.samples[0].sampleOffset,p.samples[0].sampleOffset+p.samples.length),p.kidValue=n))}this.decoderData(h,p);for(var _=0,x=0;x<h.samples.length;x++)for(var w=0,D=h.samples[x].data,T=D.length-1;w<T;)_=G(D,w),w+=4,h.samples[x].units.push(D.subarray(w,w+_)),w+=_;return this._lastRemainBuffer=e.subarray(Math.max(v,y)),this._lastRemainBuffer.byteLength>0?this._lastRemainBufferStartPos=t+e.byteLength-this._lastRemainBuffer.byteLength:this._lastRemainBufferStartPos=0,{videoTrack:h,audioTrack:p,metadataTrack:this.metadataTrack}}},{key:"reset",value:function(){this._videoSamples=[],this._audioSamples=[],this._lastRemainBuffer=null,this._lastRemainBufferStartPos=0,this.videoTrack.reset(),this.audioTrack.reset(),this.metadataTrack.reset()}},{key:"decoderData",value:function(e,t){e.useEME||t.useEME||St.decoderAESCTRData(e,t)}}],[{key:"probe",value:function(e){return fe.probe(e)}}]),e}(),Tt=function(){function e(t,r){a(this,e),this.videoTrack=t,this.audioTrack=r}return s(e,[{key:"remux",value:function(e,t){this.videoTrack=e||this.videoTrack,this.audioTrack=t||this.audioTrack;var a,r,s=(null==e?void 0:e.exist())&&(null==e?void 0:e.hasSample()),i=(null==t?void 0:t.exist())&&(null==t?void 0:t.hasSample());return s&&i?a=this._remuxMix(e,t):s?a=this._remuxTrack(e):i&&(r=this._remuxTrack(t)),e&&(e.samples=[]),t&&(t.samples=[]),{videoSegment:a,audioSegment:r}}},{key:"_remuxMix",value:function(e,t){var a=we.ftyp([e,t]),r=this._remuxData(e,a.byteLength+8),s=r.mdatData,i=r.chunkOffset,n=this._remuxData(t,i).mdatData,o=we.mdat(L(s,n)),u=we.moovMP4([e,t]);return e.ext=void 0,t.ext=void 0,e.samples=[],t.samples=[],L(a,o,u)}},{key:"_remuxTrack",value:function(e){var t=we.ftyp([e]),a=this._remuxData(e,t.byteLength+8).mdatData,r=we.mdat(a),s=we.moovMP4([e]);return e.ext=void 0,e.samples=[],L(t,r,s)}},{key:"_remuxData",value:function(e,t){var a=e.type===k.VIDEO,r=e.samples,s=0;a?r.forEach((function(e){s+=e.units.reduce((function(e,t){return e+t.byteLength}),0),s+=4*e.units.length})):s=r.reduce((function(e,t){return e+t.size}),0);for(var i,n=new Uint8Array(s),o=new DataView(n.buffer),u=e.ext={stts:[],stsc:[],stsz:[],stco:[],stss:[],ctts:[]},c=0,l=0,d=r.length,f=0;f<d;f++){l+=(i=r[f]).duration;var h=a?0:i.size;a?i.units.forEach((function(e){o.setUint32(c,e.byteLength),c+=4,n.set(e,c),c+=e.byteLength,h+=4+e.byteLength})):(n.set(i.data,c),c+=h),i.size=h,u.stsz.push(h),a&&this._fillCttsSamples(u.ctts,i.cts),this._fillSttsSamples(u.stts,i,r[f+1]),this._fillStcoSamples(u.stco,f,1,t),t+=h,a&&i.keyframe&&u.stss.push(f+1)}return e.duration=l,this._fillStscSamples(u.stsc,d,1),{mdatData:n,chunkOffset:t}}},{key:"_fillSttsSamples",value:function(e,t,a){var r=e[e.length-1];a?r&&r.value===t.duration?r.count++:e.push({value:t.duration,count:1}):r?r.count++:e.push({value:40,count:1})}},{key:"_fillCttsSamples",value:function(e,t){var a=e[e.length-1];a&&a.value===t?a.count++:e.push({value:t,count:1})}},{key:"_fillStcoSamples",value:function(e,t,a,r){t%a||e.push(r)}},{key:"_fillStscSamples",value:function(e,t,a){if(t<=a)e.push({firstChunk:1,samplesPerChunk:t,sampleDescIndex:1});else{var r=Math.floor(t/a),s=t%a;e.push({firstChunk:1,samplesPerChunk:a,sampleDescIndex:1}),s&&e.push({firstChunk:r+1,samplesPerChunk:s,sampleDescIndex:1})}}}]),e}(),jt=Object.freeze(Object.defineProperty({__proto__:null,FMP4Demuxer:ke,FMP4Remuxer:Se,MP4Demuxer:At,MP4Remuxer:Tt,MP4Parser:fe,Crypto:St},Symbol.toStringTag,{value:"Module"}));return t(t(t(t(t({},se),de),jt),C),{},{Logger:U})}));
2
2
  //# sourceMappingURL=index.min.js.map