xgplayer-transmuxer 3.0.21 → 3.0.22-rc.1

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.regexp.exec.js"),require("core-js/modules/es.regexp.test.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.math.hypot.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.array.join.js"),require("core-js/modules/es.string.from-code-point.js"),require("core-js/modules/es.string.match.js"),require("core-js/modules/es.array.sort.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.regexp.exec.js","core-js/modules/es.regexp.test.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.math.hypot.js","core-js/modules/es.function.name.js","core-js/modules/es.array.join.js","core-js/modules/es.string.from-code-point.js","core-js/modules/es.string.match.js","core-js/modules/es.array.sort.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,k(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=k(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){var r,s,i,n,o=[],u=!0,c=!1;try{if(i=(a=a.call(e)).next,0===t){if(Object(a)!==a)return;u=!1}else for(;!(u=(r=i.call(a)).done)&&(o.push(r.value),o.length!==t);u=!0);}catch(l){c=!0,s=l}finally{try{if(!u&&null!=a.return&&(n=a.return(),Object(n)!==n))return}finally{if(c)throw s}}return o}}(e,t)||y(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 m(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)||y(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 y(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}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var a=e[Symbol.toPrimitive];if(void 0!==a){var r=a.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var b={VIDEO:"video",AUDIO:"audio",METADATA:"metadata"},_={AV1:"av1",AVC:"avc",HEVC:"hevc"},x={AAC:"aac",G711PCMA:"g7110a",G711PCMU:"g7110m",OPUS:"opus",MP3:"mp3"},w={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"},D=function(){function e(){a(this,e),i(this,"id",1),i(this,"type",b.VIDEO),i(this,"codecType",_.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,"lastKeyFrameDts",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:"firstDts",get:function(){return this.samples.length?this.samples[0].dts:null}},{key:"firstPts",get:function(){return this.samples.length?this.samples[0].pts:null}},{key:"samplesDuration",get:function(){if(this.samples.length>0){var e=this.samples[0],t=this.samples[this.samples.length-1];return t.dts-e.dts+t.duration}return 0}},{key:"exist",value:function(){return!!/av01/.test(this.codec)||!!(this.pps.length&&this.sps.length&&this.codec)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isVideoEncryption}}]),e}(),S=function(){function e(){a(this,e),i(this,"id",2),i(this,"type",b.AUDIO),i(this,"codecType",x.AAC),i(this,"pid",-1),i(this,"codec",""),i(this,"container",""),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.container||this.codecType!==x.AAC&&this.codecType!==x.G711PCMA&&this.codecType!==x.G711PCMU&&this.codecType!==x.OPUS&&this.codecType!==x.MP3)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isAudioEncryption}},{key:"firstDts",get:function(){return this.samples.length?this.samples[0].dts:null}},{key:"firstPts",get:function(){return this.samples.length?this.samples[0].pts:null}},{key:"samplesDuration",get:function(){if(this.samples.length>0){var e=this.samples[0],t=this.samples[this.samples.length-1];return t.dts-e.dts+t.duration}return 0}}]),e}(),T=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)})),j=s((function e(t,r){a(this,e),i(this,"time",0),this.data=t,this.originPts=this.pts=r})),E=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(j),B=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(j),C=function(){function e(){a(this,e),i(this,"id",3),i(this,"type",b.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}(),P=Object.freeze(Object.defineProperty({__proto__:null,VideoTrack:D,AudioTrack:S,VideoSample:T,AudioSample:A,FlvScriptSample:E,SeiSample:B,MetadataTrack:C,TrackType:b,VideoCodecType:_,AudioCodecType:x,WarningType:w},Symbol.toStringTag,{value:"Module"})),U=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:"bitsAvailable",get:function(){return this._bitsAvailable}},{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}(),I=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(I,"disabled",!0);var M=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}(),O="undefined"!=typeof window,R=O&&navigator.userAgent.toLocaleLowerCase(),z=O&&/^((?!chrome|android).)*safari/.test(R),L=O&&R.includes("firefox"),V=O&&R.includes("android");function F(){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 G=Math.pow(2,32);function N(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<8)+(e[t+1]||0)}function q(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 H(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return q(e,t)*G+q(e,t+4)}function K(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 W(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 X(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)}))}function Y(e,t){return Number(e+"."+t)}var 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,m=0,y=e.getFrameDuration(u);s+7<r;)if(255===t[s]&&240==(246&t[s+1])){if(!(l=(3&t[s+3])<<11|t[s+4]<<3|(224&t[s+5])>>5)||r-s<l)break;c=2*(1&~t[s+1]),n.push({pts:a+m*y,data:t.subarray(s+7+c,s+l)}),m++,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 L?e>=6?(r=5,s=e-3):(r=2,s=e):V?(r=2,s=e):(r=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:"parseAnnexB",value:function(e){var t=e.byteLength-1,a=0;do{if(0!==e[t])break;a++,t--}while(t>0);a>=3&&(e=e.subarray(0,t+1));for(var r=e.length,s=2,i=0;null!==e[s]&&void 0!==e[s]&&1!==e[s];)s++;if((i=++s+2)>=r)return[];for(var n=[];i<r;)switch(e[i]){case 0:if(0!==e[i-1]){i+=2;break}if(0!==e[i-2]){i++;break}if(i<r-1&&1!==e[i+1]){i++;break}s!==i-2&&n.push(e.subarray(s,i-2));do{i++}while(1!==e[i]&&i<r);i=(s=i+1)+2;break;case 1:if(0!==e[i-1]||0!==e[i-2]){i+=3;break}s!==i-2&&n.push(e.subarray(s,i-2)),i=(s=i+1)+2;break;default:i+=3}return s<r&&n.push(e.subarray(s)),n}},{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=q(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,r+i),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}(),J=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(Q.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 U(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,m,y,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);m=t.readBool(),k=(y=S)/(g=2*D)}}return{codec:K(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:y,fpsDen:g,fps:k,fixedFrame:m}}}]),e}(),$=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 m=t.subarray(f,f+o);r||(r=e.parseVPS(Q.removeEPB(m),a)),d.push(m);break;case 33:var y=t.subarray(f,f+o);s||(s=e.parseSPS(Q.removeEPB(y),a)),c.push(y);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 U(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 U(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,m=1===i&&0===o?2:1;f-=v*(c+u),h-=m*(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);var i=[],n=[];if(t>e.bitsAvailable)throw new Error("maxSubLayersMinus inavlid size ".concat(t));for(var 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}(),ee=function(){function e(){a(this,e)}return s(e,null,[{key:"getFrameDuration",value:function(e){return 20}},{key:"parseHeaderPackets",value:function(e){if(e.length){for(var t=new DataView(e.buffer,e.byteOffset,e.byteLength),a="",r=0;r<8;r++)a+=String.fromCodePoint(e[r]);if("OpusHead"!==a)throw new Error("Invalid Opus MagicSignature");var s=e[9];console.log("Pre-skip",e[10],e[11]);var i=t.getUint32(12,!0),n=t.getInt16(16,!0);if(i){return{outputGain:n,sampleRate:i,channelCount:s,config:new Uint8Array(e.buffer,e.byteOffset+8,e.byteLength-8),codec:"opus",originCodec:"opus"}}}}}]),e}(),te=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],ae=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],re=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],se=[0,1,1,4],ie=null,ne=function(){function e(){a(this,e)}return s(e,null,[{key:"isHeader",value:function(e,t){return t+1<e.length&&255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}},{key:"appendFrame",value:function(t,a,r,s,i){if(!(r+24>a.length)){var n=e.parseHeader(a,r);if(n&&r+n.frameLength<=a.length){var o=s+i*(9e4*n.samplesPerFrame/n.sampleRate),u={data:a.subarray(r,r+n.frameLength),pts:o,dts:o};return u.size=u.data.byteLength,t.config=[],t.channelCount=n.channelCount,t.sampleRate=n.sampleRate,L?t.codec="mp3":t.container="audio/mpeg",t.samples.push(u),{length:n.frameLength}}}}},{key:"parseHeader",value:function(e,t){var a=e[t+1]>>3&3,r=e[t+1]>>1&3,s=e[t+2]>>4&15,i=e[t+2]>>2&3;if(1!==a&&0!==s&&15!==s&&3!==i){var n=e[t+2]>>1&1,o=e[t+3]>>6,u=1e3*te[14*(3===a?3-r:3===r?3:4)+s-1],c=ae[3*(3===a?0:2===a?1:2)+i],l=3===o?1:2,d=re[a][r],f=se[r],h=8*d*f,p=Math.floor(d*u/c+n)*f;if(null===ie){var v=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);ie=v?parseInt(v[1]):0}return!!ie&&ie<=87&&2===r&&u>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:c,channelCount:l,frameLength:p,samplesPerFrame:h}}}}]),e}(),oe=1e3,ue=5e3,ce=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._lastVideoDuration=0,this._keyFrameInNextChunk=!1,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;!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),!r&&t&&(this._audioNextPts=this._videoNextDts=t);var n=this._baseDtsInited&&(this._videoTimestampBreak||!this.videoTrack.exist())&&(this._audioTimestampBreak||!this.audioTrack.exist());if(n&&this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(i),this._keyFrameInNextChunk=!1,this._fixVideo(s),this.metadataTrack.exist()){var o=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/o})),this.metadataTrack.flvScriptSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/o}))}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.keyframe&&(t._keyFrameInNextChunk=!0)})),e.fpsNum&&e.fpsDen)r=e.timescale*(e.fpsDen/e.fpsNum);else if(e.length>1){var s=e.samples[0],i=e.samples[a.length-1];r=Math.floor((i.dts-s.dts)/(a.length-1))}else r=this._lastVideoDuration||40;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:w.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,this.audioTrack.exist()||(this._videoTimestampBreak=1))}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:w.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,this._lastVideoDuration=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:w.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){this._calculateBaseDts(this.audioTrack,this.videoTrack)&&(this.audioTrack.exist()?this.videoTrack.exist()?this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts):this._baseDts-=this._audioNextPts:this._baseDts-=this._videoNextDts,this._videoTimestampBreak=0,this._audioTimestampBreak=0)}},{key:"_doFixAudioInternal",value:function(e,t,a){if(!e.sampleDuration)switch(e.codecType){case x.AAC:e.sampleDuration=Z.getFrameDuration(e.timescale,a);break;case x.OPUS:e.sampleDuration=ee.getFrameDuration(e.samples,a);break;case x.G711PCMA:case x.G711PCMU:e.sampleDuration=this._getG711Duration(e);break;default:console.error("can't fix audio codecType:",e.codecType)}var r=e.sampleDuration,s=e.codecType===x.OPUS?20:e.codecType===x.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&&this._keyFrameInNextChunk&&(o=this._audioNextPts=u.dts,c=0,this._audioTimestampBreak=0),!this._audioTimestampBreak&&c>=3*r&&c<=oe&&!z){var l=this._getSilentFrame(e)||t[0].data.subarray(),d=Math.floor(c/r);Math.abs(u.pts-this._lastAudioExceptionGapDot)>ue&&(this._lastAudioExceptionGapDot=u.pts,e.warnings.push({type:w.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 if(c<=-3*r&&c>=-1e3)Math.abs(u.pts-this._lastAudioExceptionOverlapDot)>ue&&(this._lastAudioExceptionOverlapDot=u.pts,e.warnings.push({type:w.AUDIO_DROPPED,pts:u.pts,originPts:u.originPts,nextPts:o,refSampleDuration:r})),t.splice(n,1),n--;else{if(Math.abs(c)>oe&&(this._audioTimestampBreak++,Math.abs(u.pts-this._lastAudioExceptionLargeGapDot)>ue&&(this._lastAudioExceptionLargeGapDot=u.pts,e.warnings.push({type:w.LARGE_AUDIO_GAP,time:u.pts/1e3,pts:u.pts,originPts:u.originPts,nextPts:o,sampleDuration:c,refSampleDuration:r}))),e.codecType===x.OPUS){var p=t[t.length-1];p&&(p.duration=u.pts-p.pts)}else 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===x.AAC?Z.getSilentFrame(e.codec,e.channelCount):new Uint8Array(8*e.sampleDuration*e.channelCount)}}]),e}(),le=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 m=0;m<v;m++){var y=e._parseValue(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s)),g=y.data,k=y.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=M.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=M.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}(),de=7,fe=8,he=10,pe=13,ve=new I("FlvDemuxer"),me=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 D,this.audioTrack=r||new S,this.metadataTrack=s||new C,this._fixer=new ce(this.videoTrack,this.audioTrack,this.metadataTrack)}return s(e,[{key:"demux",value:function(t){var a,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3?arguments[3]:void 0,n=this.audioTrack,o=this.videoTrack,u=this.metadataTrack;if(!r&&s||(this._remainingData=null),r&&(this._headerParsed=!1),r?(o.reset(),n.reset(),u.reset()):(o.samples=[],n.samples=[],u.seiSamples=[],u.flvScriptSamples=[],o.warnings=[],n.warnings=[],this._remainingData&&(t=F(this._remainingData,t),this._remainingData=null)),!t.length)return{videoTrack:o,audioTrack:n,metadataTrack:u};var c=0;if(!this._headerParsed){if(!e.probe(t))throw new Error("Invalid flv file");n.present=(4&t[4])>>>2!=0,o.present=0!=(1&t[4]),this._headerParsed=!0,c=q(t,5)+4}for(var l,d,f,h,p,v=t.length;c+15<v&&(l=t[c],!(c+15+(d=t[c+1]<<16|t[c+2]<<8|t[c+3])>v));)f=(t[c+7]<<24>>>0)+(t[c+4]<<16)+(t[c+5]<<8)+t[c+6],c+=11,h=t.subarray(c,c+d),8===l?this._parseAudio(h,f):9===l?(i&&(this.seamlessLoadingSwitching=!0),this._parseVideo(h,f)):18===l?this._parseScript(h,f):ve.warn("Invalid tag type: ".concat(l)),(p=q(t,c+=d))!==11+d&&ve.warn("Invalid PrevTagSize ".concat(p," (").concat(11+d,")")),c+=4;c<v&&(this._remainingData=t.subarray(c)),n.formatTimescale=o.formatTimescale=o.timescale=u.timescale=1e3,n.timescale=n.codecType===x.OPUS?1e3:n.sampleRate||0,!n.exist()&&n.hasSample()&&n.reset(),!o.exist()&&o.hasSample()&&o.reset();var m=u.flvScriptSamples[u.flvScriptSamples.length-1],y=null==m||null===(a=m.data)||void 0===a?void 0:a.onMetaData;return y&&(null!=o&&o.exist()&&(y.hasOwnProperty("duration")&&(o.duration=1e3*y.duration),y.hasOwnProperty("width")&&y.hasOwnProperty("height")&&(o.width=y.width,o.height=y.height)),null!=n&&n.exist()&&y.hasOwnProperty("duration")&&(n.duration=1e3*y.duration)),{videoTrack:o,audioTrack:n,metadataTrack:u}}},{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,s){return this.demux(e,t,a,s),this.fix(r,t,a)}},{key:"_parseAudio",value:function(t,a){if(t.length){var r=(240&t[0])>>>4,s=this.audioTrack;if(r!==he&&r!==de&&r!==fe&&r!==pe)return ve.warn("Unsupported sound format: ".concat(r)),void s.reset();if(r!==he&&r!==pe){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}switch(r){case de:case fe:this._parseG711(t,a,r);break;case he:this._parseAac(t,a);break;case pe:this._parseOpus(t,a)}}}},{key:"_parseOpus",value:function(e,t){var a=this.audioTrack,r=e[1];switch(a.codecType=x.OPUS,r){case 0:var s=ee.parseHeaderPackets(e.subarray(2));s?(a.codec=s.codec,a.channelCount=s.channelCount,a.sampleRate=s.sampleRate,a.config=s.config,a.sampleDuration=ee.getFrameDuration([],a.timescale)):(a.reset(),ve.warn("Cannot parse AudioSpecificConfig",e));break;case 1:if(null==t)return;var i=new A(t,e.subarray(2),a.sampleDuration);a.samples.push(i);break;default:ve.warn("Unknown OpusPacketType: ".concat(r))}}},{key:"_parseG711",value:function(e,t,a){var r=this.audioTrack,s=e.subarray(1);if(!(s.byteLength<1)){var i=new A(t,s);r.codecType=7===a?x.G711PCMA:x.G711PCMU,r.sampleRate=8e3,r.codec=r.codecType,r.samples.push(i)}}},{key:"_parseAac",value:function(e,t){var a=this.audioTrack;if(a.codecType=x.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(),ve.warn("Cannot parse AudioSpecificConfig",e))}else if(1===e[1]){if(null==t)return;a.samples.push(new A(t,e.subarray(2)))}else ve.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 ve.warn("Unsupported codecId: ".concat(s));var n=12===s;i.codecType=n?_.HEVC:_.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?$.parseHEVCDecoderConfigurationRecord(c):J.parseAVCDecoderConfigurationRecord(c);if(l){var d=l.hvcC,f=l.sps,h=l.ppsArr,p=l.spsArr,v=l.vpsArr,m=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),m&&(i.nalUnitSize=m)}else ve.warn("Cannot parse ".concat(n?"HEVC":"AVC","DecoderConfigurationRecord"),e)}else if(1===o){var y=Q.parseAvcC(e.subarray(5),i.nalUnitSize);if((y=this._checkAddMetaNalToUnits(n,y,i))&&y.length){var g=new T(t+u,t,y);if(this.seamlessLoadingSwitching&&t<i.lastKeyFrameDts)return;this.seamlessLoadingSwitching=!1,1===r&&(g.setToKeyframe(),i.lastKeyFrameDts=t),i.samples.push(g),y.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 B(Q.parseSEI(Q.removeEPB(e),n),t+u))}})),g.keyframe&&this._gopId++,g.gopId=this._gopId}else ve.warn("Cannot parse NALUs",e)}else 2===o||ve.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 E(le.parse(e),t))}}],[{key:"probe",value:function(e){return 70===e[0]&&76===e[1]&&86===e[2]&&1===e[3]&&q(e,5)>=9}}]),e}();i(me,"AUDIO_RATE",[5500,11e3,22e3,44e3]);var ye=Object.freeze(Object.defineProperty({__proto__:null,FlvDemuxer:me},Symbol.toStringTag,{value:"Module"})),ge=9e4,ke=45e4,be=9e4,_e=function(){function e(t,r,s,i){a(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=s,this._baseDts=-1,this._baseVideoDts=-1,this._baseAudioDts=-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,this._needForceFixLargeGap=null==i?void 0:i.forceFixLargeGap,this._largeGapThreshold=(null==i?void 0:i.largeGapThreshold)||45e4}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,this._baseAudioDts-=t,this._baseVideoDts-=t),!r){this._videoNextDts=l>0?t+l:t,this._audioNextPts=l>0?t:t-l,this._needForceFixLargeGap&&(this._videoNextDts=0,this._audioNextPts=0);var d=u?u.dts-this._baseDts-this._videoNextDts:0,f=c?c.pts-this._baseDts-this._audioNextPts:0;Math.abs(d||f)>be&&(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._needForceFixLargeGap?t._baseVideoDts:t._baseDts,e.pts-=t._needForceFixLargeGap?t._baseVideoDts: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)if(e.warnings.push({type:w.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts/90,firstSampleDts:u.dts/90,nextSampleDts:((null===(s=a[1])||void 0===s?void 0:s.dts)||0)/90,sampleDuration:l/90}),u.dts+=l,u.pts+=l,c&&Math.abs(c.dts-u.dts)>be)this._videoTimestampBreak=!0,a.forEach((function(e,t){0!==t&&(e.dts+=l,e.pts+=l)}));else for(var d=1;d<n-1;d++){var f,h=null===(f=a[d])||void 0===f?void 0:f.dts,p=a[d-1].dts;h&&h-p<0&&(a[d].dts+=l,a[d].pts+=l)}if(e.fpsNum&&e.fpsDen&&(i=e.timescale*(e.fpsDen/e.fpsNum)),i<900&&(i=0),!i){var v=e.samples[0],m=e.samples[1];i=1===n?9e3:Math.floor(m.dts-v.dts)}for(var y=0;y<n;y++){var g=a[y].dts,k=a[y+1];if((o=y<n-1?k.dts-g:a[y-1]?Math.min(g-a[y-1].dts,i):i)>be||o<0){this._videoTimestampBreak=!0,o=this._audioTimestampBreak?i:Math.max(o,2700);var b=this._audioNextPts||0;k&&k.dts>b&&(o=i),e.warnings.push({type:w.LARGE_VIDEO_GAP,time:g/e.timescale,dts:g,originDts:a[y].originDts,nextDts:this._videoNextDts,sampleDuration:o,refSampleDuration:i})}a[y].duration=o,this._videoNextDts+=o}}}},{key:"_fixAudio",value:function(e){var t=this,a=e.samples;if(a.length)if(e.codecType!==x.MP3)a.forEach((function(e){e.pts-=t._needForceFixLargeGap?t._baseAudioDts:t._baseDts,e.dts=e.pts})),this._doFixAudioInternal(e,a,9e4);else{this.lastAudioSample&&a.unshift(this.lastAudioSample);for(var r=0;r<a.length;r++){var s=a[r];if(!a[r+1])break;s.duration=a[r+1].pts-s.pts,s.pts-=this._baseDts,s.dts=s.pts}this.lastAudioSample=a.pop()}}},{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,this._baseAudioDts=s),r.length&&(t.baseDts=i=r[0].dts,this._baseVideoDts=i),this._baseDts=Math.min(s,i);var n=i-s,o=!1;return Number.isFinite(n)&&Math.abs(n)>45e3&&t.warnings.push({type:w.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),Number.isFinite(n)&&Math.abs(n)>this._largeGapThreshold*ge&&(o=!0),this._baseDtsInited||(o&&this._needForceFixLargeGap?this._needForceFixLargeGap=!0:this._needForceFixLargeGap=!1),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<=ge&&!z){var c=Z.getSilentFrame(e.codec,e.channelCount)||t[0].data.subarray(),l=Math.floor(u/r);Math.abs(o.pts-this._lastAudioExceptionGapDot)>ke&&(this._lastAudioExceptionGapDot=o.pts),e.warnings.push({type:w.AUDIO_FILLED,pts:o.pts/90,originPts:o.originPts,count:l,nextPts:n/90,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)>ke&&(this._lastAudioExceptionOverlapDot=o.pts,e.warnings.push({type:w.AUDIO_DROPPED,pts:o.pts/90,originPts:o.originPts,nextPts:n/90,refSampleDuration:r})),t.splice(i,1),i--):(Math.abs(u)>=ge&&(this._audioTimestampBreak=!0,Math.abs(o.pts-this._lastAudioExceptionLargeGapDot)>ke&&(this._lastAudioExceptionLargeGapDot=o.pts,e.warnings.push({type:w.LARGE_AUDIO_GAP,time:o.pts/1e3,pts:o.pts/90,originPts:o.originPts,nextPts:n/90,sampleDuration:u,refSampleDuration:r}))),o.dts=o.pts=n,this._audioNextPts+=r)}}}]),e}(),xe=new I("TsDemuxer"),we=function(){function e(t,r,s){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};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 D,this.audioTrack=r||new S,this.metadataTrack=s||new C,this._fixer=new _e(this.videoTrack,this.audioTrack,this.metadataTrack,n)}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=F(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,m=(15&e[p+10])<<8|e[p+11];for(p+=12+m;p<v;){var y=(31&e[p+1])<<8|e[p+2];switch(e[p]){case 15:r.pid=c=y;break;case 3:case 4:-1===r.pid&&(r.pid=c=y,r.codecType=x.MP3);break;case 27:if(-1!==u)break;s.codecType=_.AVC,s.pid=u=y;break;case 36:if(-1!==u)break;s.codecType=_.HEVC,s.pid=u=y;break;default:xe.warn("Unsupported stream. type: ".concat(e[p],", pid: ").concat(y))}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:xe.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(F.apply(void 0,m(this._videoPesData)));if(t){var a=Q.parseAnnexB(t.data);a?this._createVideoSample(a,t.pts,t.dts):xe.warn("Cannot parse avc units",t),this._videoPesData=[]}else xe.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===_.HEVC,n=new T(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 B(Q.parseSEI(Q.removeEPB(e),i),t));case 32:if(!i)break;if(!s.vps.length){var o=$.parseVPS(Q.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=Q.removeEPB(e),c=i?$.parseSPS(u,s.hvcC):J.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]);break;case 9:case 35:break;case 38:if(i){for(var l=!1,d=2;d<e.byteLength;d++)if(255===e[d]){l=!0;break}if(!l)return}}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){xe.warn("Video sample no pts",t);var a=e.samples[e.samples.length-1];a?(t.pts=a.pts,t.dts=a.dts):xe.warn("Drop video sample",t)}else e.samples.push(t)}},{key:"_parseAudioData",value:function(){if(this._audioPesData.length){var t=e._parsePES(F.apply(void 0,m(this._audioPesData)));if(t){switch(this.audioTrack.codecType){case x.AAC:this._parseAacData(t);break;case x.MP3:this._parseMPEG(t)}this._audioPesData=[]}else xe.warn("Cannot parse audio pes",this._audioPesData)}}},{key:"_parseAacData",value:function(e){var t=this.audioTrack,a=e.pts;if(null==a){if(xe.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,m(s.frames.map((function(e){return new A(e.pts,e.data)})))),s.skip&&xe.warn("Skip aac adts ".concat(s.skip," bits")),s.remaining&&xe.warn("Remaining aac adts ".concat(s.remaining," bits"))):xe.warn("Cannot parse aac adts",e)}},{key:"_parseMPEG",value:function(e){var t=e.data,a=t.length,r=0,s=0,i=e.pts;if(void 0!==i)for(;s<a;)if(ne.isHeader(t,s)){var n=ne.appendFrame(this.audioTrack,t,s,i,r);if(!n)break;s+=n.length,r++}else s++;else xe.warn("[tsdemuxer]: MPEG PES unknown PTS")}}],[{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:we},Symbol.toStringTag,{value:"Module"})),Se=function(){function e(t,r,s){a(this,e),this.dv=new DataView(t),this.start=this.offset=r||this.dv.byteOffset,this.end=s?this.start+s:this.start+this.dv.byteLength}return s(e,[{key:"buffer",get:function(){return this.dv.buffer}},{key:"unreadLength",get:function(){return Math.max(this.end-this.offset,0)}},{key:"size",get:function(){return this.end-this.start}},{key:"readFloat",value:function(e){var t=0;switch(e){case 4:t=this.dv.getFloat32(this.offset);break;case 8:t=this.dv.getFloat64(this.offset);break;default:throw new Error("read ".concat(e,"-byte float is not supported"))}return this.offset+=e,t}},{key:"back",value:function(e){this.offset-=e}},{key:"skip",value:function(e){this.offset+=e}},{key:"readInt",value:function(e){var t=this.offset;switch(this.offset+=e,e){case 1:return this.dv.getInt8(t);case 2:return this.dv.getInt16(t);case 4:return this.dv.getInt32(t);default:throw new Error("read ".concat(e,"-byte integers is not supported"))}}},{key:"read",value:function(e){var t=this.offset;switch(this.offset+=e,e){case 1:return this.dv.getUint8(t);case 2:return this.dv.getUint16(t);case 3:return(this.dv.getUint16(t)<<8)+this.dv.getUint8(t+2);case 4:return this.dv.getUint32(t);default:return this.back(e-4),this.read(e-4)+this.dv.getUint32(t)*Math.pow(256,e-4)}}},{key:"write",value:function(e,t){var a=this.offset;switch(this.offset+=e,e){case 1:return this.dv.setUint8(a,t);case 2:return this.dv.setUint16(a,t);case 3:return this.dv.setUint8(a,t>>>16),this.dv.setUint16(a+1,65535&t);case 4:return this.dv.setUint32(a,t);default:throw new Error("write ".concat(e,"-byte integers is not supported"))}}},{key:"readToBuffer",value:function(e){var t;return t=this.offset||e?this.dv.buffer.slice(this.offset,e?this.offset+e:this.end):this.dv.buffer,this.offset+=t.byteLength,t}},{key:"readToUint8",value:function(e){var t=new Uint8Array(this.dv.buffer,this.offset,e||this.unreadLength);return this.offset+=t.byteLength,t}},{key:"readString",value:function(e){for(var t=0,a="";t<e;t++)a+=String.fromCharCode(this.dv.getUint8(this.offset)),this.offset++;return a}}],[{key:"fromUint8",value:function(t){return new e(t.buffer,t.byteOffset,t.byteLength)}},{key:"concatUint8s",value:function(e){var t=new Uint8Array(e.reduce((function(e,t){return e+t.byteLength}),0)),a=0;return e.forEach((function(e){t.set(e,a),a+=e.byteLength})),t}},{key:"concatUint8",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return this.concatUint8s(t)}}]),e}(),Te=function(){function e(t,r){a(this,e),this.offset=0,this.val=t,this.size=r}return s(e,[{key:"skip",value:function(e){this.offset+=e}},{key:"read",value:function(e){var t=this.size-this.offset-e;if(t>=0){var a=0,r=0;if(this.offset+=e,this.size>31){for(;r<e;r++)a+=Math.pow(2,r);return this.val/Math.pow(2,t)&a}for(;r<e;r++)a+=1<<r;return this.val>>>t&a}throw new Error("the number of the read operation exceeds the total length limit of bits")}}],[{key:"fromByte",value:function(t,a){return new e(t.read(a),a<<3)}}]),e}(),Ae=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=q(t),n=String.fromCharCode.apply(null,t.subarray(4,8)),o=8,1===i?(i=H(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 Ce(e,!0,(function(e,t){e.trackId=q(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=q(t,a),a+=4),s&&(e.sampleDescriptionIndex=q(t,a),a+=4),i&&(e.defaultSampleDuration=q(t,a),a+=4),n&&(e.defaultSampleSize=q(t,a),a+=4),o&&(e.defaultSampleFlags=q(t,a))}))}},{key:"sidx",value:function(e){return Ce(e,!0,(function(e,t){var a=0;e.reference_ID=q(t,a),a+=4,e.timescale=q(t,a),a+=4,0===e.version?(e.earliest_presentation_time=q(t,a),a+=4,e.first_offset=q(t,a),a+=4):(e.earliest_presentation_time=H(t,a),a+=8,e.first_offset=H(t,a),a+=8),a+=2,e.references=[];var r=N(t,a);a+=2;for(var s=0;s<r;s++){var i={};e.references.push(i);var n=q(t,a);a+=4,i.reference_type=n>>31&1,i.referenced_size=2147483647&n,i.subsegment_duration=q(t,a),n=q(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 Ce(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 Ce(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=q(t,16),e.duration=H(t,20),a+=28):(e.timescale=q(t,8),e.duration=q(t,12),a+=16),e.nextTrackId=q(t,a+76)}))}},{key:"trak",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){var a=Se.fromUint8(t);1===e.version?(a.read(8),a.read(8),e.trackId=a.read(4),a.read(4),e.duration=a.read(8)):(a.read(4),a.read(4),e.trackId=a.read(4),a.read(4),e.duration=a.read(4)),a.skip(16),e.matrix=[];for(var r=0;r<36;r++)e.matrix.push(a.read(1));a.back(36);for(var s,i=[],n=0;n<3;n++)i.push(Y(a.readInt(2),a.readInt(2))),i.push(Y(a.readInt(2),a.readInt(2))),s=a.readInt(4),i.push(Y(s>>30,1073741823&s));e.rotation=function(e){if(e.length<5)return 0;var t=Math.hypot(e[0],e[3]),a=Math.hypot(e[1],e[4]);return 0===t||0===a?0:180*Math.atan2(e[1]/a,e[0]/t)/Math.PI}(i),e.width=a.read(4),e.height=a.read(4)}))}},{key:"mdia",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=q(t,16),e.duration=H(t,20),a+=28):(e.timescale=q(t,8),e.duration=q(t,12),a+=16);var r=N(t,a);e.language=String.fromCharCode(96+(r>>10&31),96+(r>>5&31),96+(31&r))}))}},{key:"hdlr",value:function(e){return Ce(e,!0,(function(e,t){0===e.version&&(e.handlerType=String.fromCharCode.apply(null,t.subarray(4,8)))}))}},{key:"minf",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){e.graphicsmode=N(t),e.opcolor=[N(t,2),N(t,4),N(t,6)]}))}},{key:"smhd",value:function(e){return Ce(e,!0,(function(e,t){e.balance=N(t)}))}},{key:"stbl",value:function(t){return Ce(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 Ce(e,!0,(function(e,a){var r=0,s=q(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=N(a,r);r+=2;for(var c=0;c<u;c++){var l={};l.BytesOfClearData=N(a,r),r+=2,l.BytesOfProtectedData=q(a,r),r+=4,n.subsamples.push(l)}}e.samples.push(n)}}))}},{key:"pssh",value:function(e){return Ce(e,!0,(function(e,t){for(var a=[],r=[],s=0,i=0;i<16;i++)r.push(Ue(t[s+i]));if(s+=16,e.version>0){var n=q(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(Ue(c))}}var l=q(t,s);e.data_size=l,s+=4,e.kid=a,e.system_id=r,e.buffer=t}))}},{key:"stsd",value:function(t){return Ce(t,!0,(function(t,a,r){t.entryCount=q(a),t.entries=e.findBox(a.subarray(4),[],r+4).map((function(t){switch(t.type){case"av01":return e.av01(t);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 Ce(t,!1,(function(t,a,r){t.channelCount=N(a,16),t.samplesize=N(a,18),t.sampleRate=q(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 Ce(t,!1,(function(t,a,r){t.width=N(a,24),t.height=N(a,26),t.horizresolution=q(a,28),t.vertresolution=q(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 Ce(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(Ue(t[a])),a+=1}))}},{key:"schi",value:function(t){return Ce(t,!1,(function(t,a,r){t.tenc=e.tenc(e.findBox(a,["tenc"],r)[0])}))}},{key:"sinf",value:function(t){return Ce(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 Ce(e,!1,(function(e,t){e.data_format="";for(var a=0;a<4;a++)e.data_format+=String.fromCharCode(t[a])}))}},{key:"colr",value:function(e){return Ce(e,!1,(function(t,a){var r=Se.fromUint8(a);t.data=e.data,t.colorType=r.readString(4),"nclx"===t.colorType?(t.colorPrimaries=r.read(2),t.transferCharacteristics=r.read(2),t.matrixCoefficients=r.read(2),t.fullRangeFlag=r.read(1)>>7):"rICC"!==t.colorType&&"prof"!==t.colorType||(t.iccProfile=a.readToUint8())}))}},{key:"av01",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Ee(t,a),i=a.subarray(s);r+=s,t.av1C=e.av1C(e.findBox(i,["av1C"],r)[0]),t.colr=e.colr(e.findBox(i,["colr"],r)[0])}))}},{key:"av1C",value:function(e){return Ce(e,!1,(function(t,a){t.data=e.data;var r,s=Se.fromUint8(a),i=Te.fromByte(s,4);t.marker=i.read(1),t.version=i.read(7),t.seqProfile=i.read(3),t.seqLevelIdx0=i.read(5),t.seqTier0=i.read(1),t.highBitdepth=i.read(1),t.twelveBit=i.read(1),t.monochrome=i.read(1),t.chromaSubsamplingX=i.read(1),t.chromaSubsamplingY=i.read(1),t.chromaSamplePosition=i.read(2),t.reserved=i.read(3),t.initialPresentationDelayPresent=i.read(1),t.initialPresentationDelayPresent?t.initialPresentationDelayMinusOne=i.read(4):t.initialPresentationDelayMinusOne=0,t.configOBUs=s.readToUint8(),2===t.seqLevelIdx0&&1===t.highBitdepth?r=1===t.twelveBit?"12":"10":t.seqProfile<=2&&(r=1===t.highBitdepth?"10":"08"),t.codec=["av01",t.seqProfile,(t.seqLevelIdx0<10?"0"+t.seqLevelIdx0:t.seqLevelIdx0)+(t.seqTier0?"H":"M"),r].join(".")}))}},{key:"avc1",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Ee(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 Ce(e,!1,(function(t,a){t.data=e.data,t.configurationVersion=a[0],t.AVCProfileIndication=a[1],t.profileCompatibility=a[2],t.AVCLevelIndication=a[3],t.codec=K([a[1],a[2],a[3]]),t.lengthSizeMinusOne=3&a[4],t.spsLength=31&a[5],t.sps=[];for(var r=6,s=0;s<t.spsLength;s++){var i=N(a,r);r+=2,t.sps.push(a.subarray(r,r+i)),r+=i}t.ppsLength=a[r],r+=1,t.pps=[];for(var n=0;n<t.ppsLength;n++){var o=N(a,r);r+=2,t.pps.push(a.subarray(r,r+=o)),r+=o}}))}},{key:"hvc1",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Ee(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 Ce(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=q(a,2),t.generalConstraintIndicatorFlags=a.subarray(6,12),t.generalLevelIdc=a[12],t.avgFrameRate=N(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=N(a,s+1),s+=3;for(var c,l=[],d=0;d<n;d++)o=N(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 Ce(e,!1,(function(e,t){e.hSpacing=q(t),e.vSpacing=q(t,4)}))}},{key:"mp4a",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Be(t,a);t.esds=e.esds(e.findBox(a.subarray(s),["esds"],r+s)[0])}))}},{key:"esds",value:function(e){return Ce(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 Ce(e,!1,(function(e,t){Be(e,t)}))}},{key:"stts",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push({count:q(t,s),delta:q(t,s+4)}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"ctts",value:function(e){return Ce(e,!0,(function(e,t){var a=q(t),r=[],s=4;if(1===e.version)for(var i=0;i<a;i++)r.push({count:q(t,s),offset:q(t,s+4)}),s+=8;else for(var n=0;n<a;n++)r.push({count:q(t,s),offset:-(1+~q(t,s+4))}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stsc",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push({firstChunk:q(t,s),samplesPerChunk:q(t,s+4),sampleDescriptionIndex:q(t,s+8)}),s+=12;e.entryCount=a,e.entries=r}))}},{key:"stsz",value:function(e){return Ce(e,!0,(function(e,t){var a=q(t),r=q(t,4),s=[];if(!a)for(var i=8,n=0;n<r;n++)s.push(q(t,i)),i+=4;e.sampleSize=a,e.sampleCount=r,e.entrySizes=s}))}},{key:"stco",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push(q(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"co64",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push(H(t,s)),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stss",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push(q(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"moof",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){e.sequenceNumber=q(t)}))}},{key:"traf",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){var a=e.version,r=e.flags,s=t.length,i=e.sampleCount=q(t),n=4;if(s>n&&1&r&&(e.dataOffset=-(1+~q(t,n)),n+=4),s>n&&4&r&&(e.firstSampleFlags=q(t,n),n+=4),e.samples=[],s>n)for(var o,u=0;u<i;u++)o={},256&r&&(o.duration=q(t,n),n+=4),512&r&&(o.size=q(t,n),n+=4),1024&r&&(o.flags=q(t,n),n+=4),2048&r&&(o.cts=a?-(1+~q(t,n+4)):q(t,n),n+=4),e.samples.push(o)}))}},{key:"tfdt",value:function(e){return Ce(e,!0,(function(e,t){1===e.version?e.baseMediaDecodeTime=H(t):e.baseMediaDecodeTime=q(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,m=null===(u=n.tkhd)||void 0===u?void 0:u.trackId;null!=m&&(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,v.rotation=n.tkhd.rotation,v.matrix=n.tkhd.matrix;var y,g,k,b,w,D,S,T,A=n.mdia.minf.stbl.stsd.entries[0];if(v.width=A.width,v.height=A.height,A.pasp&&(v.sarRatio=[A.pasp.hSpacing,A.pasp.vSpacing]),A.av1C)v.codecType=_.AV1,v.codec=A.av1C.codec,v.av1C=A.av1C.data,v.colr=A.colr.data;else if(A.hvcC)v.codecType=_.HEVC,v.codec=A.hvcC.codec,v.vps=A.hvcC.vps,v.sps=A.hvcC.sps,v.pps=A.hvcC.pps,v.hvcC=A.hvcC.data;else{if(!A.avcC)throw new Error("unknown video stsd entry");v.codec=A.avcC.codec,v.sps=A.avcC.sps,v.pps=A.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,A&&"encv"===A.type)v.isVideoEncryption=!0,A.default_KID=null===(y=A.sinf)||void 0===y||null===(g=y.schi)||void 0===g?void 0:g.tenc.default_KID,A.default_IsEncrypted=null===(k=A.sinf)||void 0===k||null===(b=k.schi)||void 0===b?void 0:b.tenc.default_IsEncrypted,A.default_IV_size=null===(w=A.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,A.data_format=null===(S=A.sinf)||void 0===S||null===(T=S.frma)||void 0===T?void 0:T.data_format,v.useEME=e.useEME,v.kidValue=e.kidValue,v.pssh=e.pssh,v.encv=A}if(o&&a){var j,E,B,C,P,U,I,M,O,R=a,z=null===(j=o.tkhd)||void 0===j?void 0:j.trackId;null!=z&&(R.id=o.tkhd.trackId),R.tkhdDuration=o.tkhd.duration,R.mvhdDurtion=e.mvhd.duration,R.mvhdTimecale=e.mvhd.timescale,R.timescale=R.formatTimescale=o.mdia.mdhd.timescale,R.duration=o.mdia.mdhd.duration||R.mvhdDurtion/R.mvhdTimecale*R.timescale;var L,V,F,G,N,q,H,K,W=o.mdia.minf.stbl.stsd.entries[0];switch(R.sampleSize=W.sampleSize,R.sampleRate=W.sampleRate,R.channelCount=W.channelCount,R.present=!0,W.type){case"alaw":R.codecType=R.codec=x.G711PCMA,R.sampleRate=8e3;break;case"ulaw":R.codecType=R.codec=x.G711PCMU,R.sampleRate=8e3;break;default:R.sampleDuration=Z.getFrameDuration(R.sampleRate,R.timescale),R.sampleRateIndex=Z.getRateIndexByRate(R.sampleRate),R.objectType=(null===(r=W.esds)||void 0===r?void 0:r.objectType)||2,W.esds&&(R.config=Array.from(W.esds.config)),R.codec=(null===(s=W.esds)||void 0===s?void 0:s.codec)||"mp4a.40.2"}if(R.sampleDuration=Z.getFrameDuration(R.sampleRate,R.timescale),R.objectType=(null===(E=W.esds)||void 0===E?void 0:E.objectType)||2,W.esds&&(W.esds.config?R.config=Array.from(W.esds.config):console.warn("esds config is null")),R.codec=(null===(B=W.esds)||void 0===B?void 0:B.codec)||"mp4a.40.2",R.sampleRateIndex=Z.getRateIndexByRate(R.sampleRate),R.ext={},R.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,R.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,R.present=!0,W&&"enca"===W.type)R.isAudioEncryption=!0,W.data_format=null===(L=W.sinf)||void 0===L||null===(V=L.frma)||void 0===V?void 0:V.data_format,W.default_KID=null===(F=W.sinf)||void 0===F||null===(G=F.schi)||void 0===G?void 0:G.tenc.default_KID,W.default_IsEncrypted=null===(N=W.sinf)||void 0===N||null===(q=N.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,R.audioSenc=o.mdia.minf.stbl.senc&&o.mdia.minf.stbl.senc.samples,R.useEME=e.useEME,R.kidValue=e.kidValue,R.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=je(c,l,d,f,p,h)}if(r){var v,m,y,g=null===(v=r.mdia)||void 0===v||null===(m=v.minf)||void 0===m?void 0:m.stbl;if(!g)return;var k=null===(y=r.mdia.mdhd)||void 0===y?void 0:y.timescale,b=g.stts,_=g.stsc,x=g.stsz,w=g.stco;if(!(k&&b&&_&&x&&w))return;i=je(b,_,x,w)}return{videoSamples:s,audioSamples:i}}}}}]),e}();function je(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,m=0,y=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:m,duration:r,size:h[y]||a.sampleSize,offset:f[g]+b,index:y},p&&(u.keyframe=n[y],u.keyframe&&v++,u.gopId=v),o&&y<o.length&&(u.pts=u.dts+o[y]),c.push(u),m+=r,++y<_?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 Ee(e,t){return e.dataReferenceIndex=N(t,6),e.width=N(t,24),e.height=N(t,26),e.horizresolution=q(t,28),e.vertresolution=q(t,32),e.frameCount=N(t,40),e.depth=N(t,74),78}function Be(e,t){return e.dataReferenceIndex=N(t,6),e.channelCount=N(t,16),e.sampleSize=N(t,18),e.sampleRate=q(t,24)/65536,28}function Ce(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 Pe=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},Ue=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(Pe(Number(t).toString(16),2,0))})),e[0]},Ie=function(){function e(t,r,s){a(this,e),i(this,"__loadedMoofWraps",[]),i(this,"__lastRemainData",null),i(this,"__lastRemainDataStart",0),i(this,"__nextMoofStart",-1),this.videoTrack=t||new D,this.audioTrack=r||new S,this.metadataTrack=s||new C}return s(e,[{key:"demuxPart",value:function(e,t,a){var r=this,s=this.videoTrack,i=this.audioTrack,n=s.exist(),o=i.exist(),u=/av01/.test(s.codec);s.samples=[],i.samples=[];var c=e,l=t;if(this.__lastRemainData){var d=this.__lastRemainDataStart+this.__lastRemainData.byteLength;if(t<=d&&t>this.__lastRemainDataStart&&t+e.byteLength>d){var f=e.subarray(this.__lastRemainData.byteLength+this.__lastRemainDataStart-t);c=F(this.__lastRemainData,f),l=this.__lastRemainDataStart,this.__lastRemainData=null}else this.__lastRemainData=null,this.__lastRemainDataStart=0,this.__nextMoofStart=-1}if(!a){var h=Ae.findBox(c,["moov"])[0];if(!h)throw new Error("cannot found moov box");a=Ae.moov(h)}if(c){var p=l+c.byteLength;n||o||Ae.moovToTrack(a,s,i);var v=[];this.__nextMoofStart<0?Ae.findBox(c,["moof"],l).forEach((function(e){return v.push(e)})):this.__nextMoofStart>=l&&this.__nextMoofStart<=p-8&&Ae.findBox(c.subarray(this.__nextMoofStart-l),["moof"],this.__nextMoofStart).forEach((function(e){return v.push(e)})),v.filter((function(e){return e.size<=e.data.length})).forEach((function(e){var t=Ae.moof(e);r.__nextMoofStart=t.start+Math.max.apply(Math,m(t.traf.map((function(e){return e.trun.samples.reduce((function(e,t){return e+t.size}),e.trun.dataOffset||0)})))),r.__loadedMoofWraps.push({start:t.start,nextMoofStart:r.__nextMoofStart,moof:t}),r.__loadedMoofWraps.sort((function(e,t){return e.start-t.start}))}));var g,k=function(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=y(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,n=!0,o=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return n=e.done,e},e:function(e){o=!0,i=e},f:function(){try{n||null==a.return||a.return()}finally{if(o)throw i}}}}(this.__loadedMoofWraps);try{var b=function(){var e=g.value;if(e.start>p||e.nextMoofStart<l)return"continue";var t,a=e.start,n=Ae.moofToSamples(e.moof,s,i),o=s.baseMediaDecodeTime,d=i.baseMediaDecodeTime;Object.keys(n).forEach((function(e){s.id==e?n[e].some((function(e){var i=e.offset+=a;if(!(i<l)){if(i+e.size>p)return!0;var n=new T((e.pts||e.dts)+o,e.dts+o);n.duration=e.duration,n.gopId=e.gopId,e.keyframe&&n.setToKeyframe();var d=c.subarray(i-l,i-l+e.size);if(n.data=d,!u)for(var f=0,h=d.length-1;f<h;)t=q(d,f),f+=4,n.units.push(d.subarray(f,f+t)),f+=t;r.__lastRemainDataStart=i+e.size,s.samples.push(n)}})):i.id==e&&n[e].some((function(e){var t=e.offset+a;if(!(t<l)){if(t+e.size>p)return!0;var s=c.subarray(t-l,t-l+e.size);i.samples.push(new A(e.dts+d,s,e.duration)),r.__lastRemainDataStart=t+e.size}}))}))};for(k.s();!(g=k.n()).done;)b()}catch(_){k.e(_)}finally{k.f()}}return this.__lastRemainDataStart>l&&this.__lastRemainDataStart<c.byteLength+l?this.__lastRemainData=c.subarray(this.__lastRemainDataStart-l):(this.__lastRemainData=c,this.__lastRemainDataStart=l),s.samples.length&&(s.baseMediaDecodeTime=s.samples[0].pts),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts),{videoTrack:s,audioTrack:i,metadataTrack:this.metadataTrack}}},{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=Ae.findBox(t,["moov"])[0];if(!n)throw new Error("cannot found moov box");Ae.moovToTrack(Ae.moov(n),null,r)}var o=Ae.findBox(t,["moof"])[0];if(o){var u=Ae.moofToSamples(Ae.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=Ae.findBox(e,["moov"])[0];if(!d)throw new Error("cannot found moov box");Ae.moovToTrack(Ae.moov(d),a,r)}var f=Ae.findBox(e,["moof"])[0];if(f){var h,p=Ae.moofToSamples(Ae.moof(f),a,r),v=a.baseMediaDecodeTime,m=r.baseMediaDecodeTime,y=f.start;Object.keys(p).forEach((function(t){a.id==t?p[t].map((function(t){t.offset+=y;var r=new T((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=q(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+=y;var a=e.subarray(t.offset,t.offset+t.size);r.samples.push(new A(t.dts+m,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 Ae.probe(e)}}]),e}();function Me(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 Oe=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=Me(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}(),Re=Math.pow(2,32)-1,ze=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===b.VIDEO&&e.codecType===_.HEVC}))?e.FTYPHEV1:e.FTYPAVC1}},{key:"initSegment",value:function(t){return F(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],X(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(m(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(m(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===b.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):t.codecType===x.OPUS?e.opus(t):e.mp4a(t):t.useEME&&t.encv?e.encv(t):t.av1C?e.av01(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,m(s)).concat([1,i.length>>>8&255,255&i.length])).concat.apply(a,m(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(X(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:"av01",value:function(t){return e.box(e.types.av01,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]),t.av1C,t.colr)}},{key:"avc1hev1",value:function(t){var a=t.codecType===_.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,m(e))})),t.pps.forEach((function(e){s=e.byteLength,n.push(s>>>8&255),n.push(255&s),n.push.apply(n,m(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,m(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:"opus",value:function(t){var a=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]),r=t.config.length?e.dOps(t):[];return e.box(e.types.Opus,a,r)}},{key:"dOps",value:function(t){if(t.config)return t.config[4]=t.sampleRate>>>24&255,t.config[5]=t.sampleRate>>>16&255,t.config[6]=t.sampleRate>>>8&255,t.config[7]=255&t.sampleRate,e.box(e.types.dOps,t.config)}},{key:"mvex",value:function(t){return e.box.apply(e,[e.types.mvex].concat(m(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(m(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),s=0;if(t.isVideo&&t.videoSenc&&t.videoSenc.forEach((function(e){s+=8,e.subsamples&&e.subsamples.length&&(s+=2,s+=6*e.subsamples.length)})),t.videoSencLength=s,t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)){if(t.isVideoEncryption){if(t.isVideo){var i=e.saiz(t),n=e.saio(t),o=e.trun1(t),u=e.senc(t);return e.box(e.types.traf,a,r,i,n,o,u)}if(t.isAudioEncryption){var c=e.sbgp(),l=e.saiz(t),d=e.saio(t),f=e.senc(t),h=e.trun1(t);return e.box(e.types.traf,a,r,c,l,d,f,h)}var p=e.sbgp(),v=e.trun1(t);return e.box(e.types.traf,a,r,p,v)}if(t.isVideo){var m=e.trun1(t);return e.box(e.types.traf,a,r,m)}var y=e.sbgp(),g=e.saiz(t),k=e.saio(t),b=e.senc(t),_=e.trun1(t);return e.box(e.types.traf,a,r,y,g,k,b,_)}var x=e.sdtp(t);return e.box(e.types.traf,a,r,x,e.trun(t.samples,x.byteLength+76))}},{key:"sdtp",value:function(t){var a=new Oe;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 Oe,r=Oe.writeUint32(t.samples.length),s=null;if(t.isVideo){var i=t.videoSencLength;s=Oe.writeUint32(16*t.samples.length+i+149),!t.isVideoEncryption&&t.isAudioEncryption&&(s=Oe.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=Oe.writeUint32(n)}return t.samples.forEach((function(e){a.write(Oe.writeUint32(e.duration)),a.write(Oe.writeUint32(e.size)),a.write(Oe.writeUint32(e.keyframe?33554432:65536)),t.isVideo&&a.write(Oe.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 Oe,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(Oe.writeUint32(16+o),e.types.senc,this.extension(0,i)),a.write(Oe.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(Oe.writeUint16(e.subsamples.length)),e.subsamples.forEach((function(e){a.write(Oe.writeUint16(e.BytesOfClearData)),a.write(Oe.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/(Re+1)),s=Math.floor(a%(Re+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(m(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===b.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,F(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,F(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,F(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,F(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,F(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,F(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(ze,"types",["Opus","dOps","av01","av1C","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(ze,"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(ze,"FTYPAVC1",ze.box(ze.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))),i(ze,"FTYPHEV1",ze.box(ze.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,104,101,118,49]))),i(ze,"DINF",ze.box(ze.types.dinf,ze.box(ze.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(ze,"VMHD",ze.box(ze.types.vmhd,new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))),i(ze,"SMHD",ze.box(ze.types.smhd,new Uint8Array([0,0,0,0,0,0,0,0]))),i(ze,"StblTable",new Uint8Array([0,0,0,0,0,0,0,0])),i(ze,"STTS",ze.box(ze.types.stts,ze.StblTable)),i(ze,"STSC",ze.box(ze.types.stsc,ze.StblTable)),i(ze,"STSZ",ze.box(ze.types.stsz,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]))),i(ze,"STCO",ze.box(ze.types.stco,ze.StblTable));var Le=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(Le,"disabled",!0);for(var Ve=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 Le("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=ze.initSegment(d)):(c&&(e=ze.initSegment([this.videoTrack])),l&&(t=ze.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=/av01/.test(e.codec),r=0;a?t.forEach((function(e){r+=e.data.byteLength})):t.forEach((function(e){r+=e.units.reduce((function(e,t){return e+t.byteLength}),0),r+=4*e.units.length}));var s=new Uint8Array(r);if(a)for(var i,n=0,o=t.length,u=0;n<o;n++)i=t[n],s.set(i.data,u),i.size=i.data.byteLength,u+=i.size;else for(var c,l=new DataView(s.buffer),d=function(e,a){a=t[f];var r=0;a.units.forEach((function(t){l.setUint32(e,t.byteLength),e+=4,s.set(t,e),e+=t.byteLength,r+=4+t.byteLength})),a.size=r,p=e,c=a},f=0,h=t.length,p=0;f<h;f++)d(p,c);var v=ze.mdat(s);return F(ze.moof([e]),v)}},{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=ze.mdat(t);return F(ze.moof([e]),a)}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset()}}]),e}(),Fe=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}(),Ge=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]:Ne;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}(Fe),Ne={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 Ge(a,t/2)}},qe=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 Ge(a,t)},He=function(e){return qe(unescape(encodeURIComponent(e)))},Ke=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 Ge,this._nDataBytes=0}},{key:"_append",value:function(e){var t=e;"string"==typeof t&&(t=He(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 Ge(t,u)}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e._data=this._data.clone(),e}}]),r}(Fe),We=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 Fe,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 Xe(e,a).finalize(t)}}}]),r}(Ke),Xe=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=He(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}(Fe),Ye={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 Ge.create(r,s)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},Ze=[],Qe=0;Qe<64;Qe+=1)Ze[Qe]=4294967296*Math.abs(Math.sin(Qe+1))|0;var Je=function(e,t,a,r,s,i,n){var o=e+(t&a|~t&r)+s+n;return(o<<i|o>>>32-i)+t},$e=function(e,t,a,r,s,i,n){var o=e+(t&r|a&~r)+s+n;return(o<<i|o>>>32-i)+t},et=function(e,t,a,r,s,i,n){var o=e+(t^a^r)+s+n;return(o<<i|o>>>32-i)+t},tt=function(e,t,a,r,s,i,n){var o=e+(a^(t|~r))+s+n;return(o<<i|o>>>32-i)+t},at=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 Ge([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],m=a[t+9],y=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],T=n[3];w=Je(w,D,S,T,o,7,Ze[0]),T=Je(T,w,D,S,u,12,Ze[1]),S=Je(S,T,w,D,c,17,Ze[2]),D=Je(D,S,T,w,l,22,Ze[3]),w=Je(w,D,S,T,d,7,Ze[4]),T=Je(T,w,D,S,f,12,Ze[5]),S=Je(S,T,w,D,h,17,Ze[6]),D=Je(D,S,T,w,p,22,Ze[7]),w=Je(w,D,S,T,v,7,Ze[8]),T=Je(T,w,D,S,m,12,Ze[9]),S=Je(S,T,w,D,y,17,Ze[10]),D=Je(D,S,T,w,g,22,Ze[11]),w=Je(w,D,S,T,k,7,Ze[12]),T=Je(T,w,D,S,b,12,Ze[13]),S=Je(S,T,w,D,_,17,Ze[14]),D=Je(D,S,T,w,x,22,Ze[15]),w=$e(w,D,S,T,u,5,Ze[16]),T=$e(T,w,D,S,h,9,Ze[17]),S=$e(S,T,w,D,g,14,Ze[18]),D=$e(D,S,T,w,o,20,Ze[19]),w=$e(w,D,S,T,f,5,Ze[20]),T=$e(T,w,D,S,y,9,Ze[21]),S=$e(S,T,w,D,x,14,Ze[22]),D=$e(D,S,T,w,d,20,Ze[23]),w=$e(w,D,S,T,m,5,Ze[24]),T=$e(T,w,D,S,_,9,Ze[25]),S=$e(S,T,w,D,l,14,Ze[26]),D=$e(D,S,T,w,v,20,Ze[27]),w=$e(w,D,S,T,b,5,Ze[28]),T=$e(T,w,D,S,c,9,Ze[29]),S=$e(S,T,w,D,p,14,Ze[30]),D=$e(D,S,T,w,k,20,Ze[31]),w=et(w,D,S,T,f,4,Ze[32]),T=et(T,w,D,S,v,11,Ze[33]),S=et(S,T,w,D,g,16,Ze[34]),D=et(D,S,T,w,_,23,Ze[35]),w=et(w,D,S,T,u,4,Ze[36]),T=et(T,w,D,S,d,11,Ze[37]),S=et(S,T,w,D,p,16,Ze[38]),D=et(D,S,T,w,y,23,Ze[39]),w=et(w,D,S,T,b,4,Ze[40]),T=et(T,w,D,S,o,11,Ze[41]),S=et(S,T,w,D,l,16,Ze[42]),D=et(D,S,T,w,h,23,Ze[43]),w=et(w,D,S,T,m,4,Ze[44]),T=et(T,w,D,S,k,11,Ze[45]),S=et(S,T,w,D,x,16,Ze[46]),D=et(D,S,T,w,c,23,Ze[47]),w=tt(w,D,S,T,o,6,Ze[48]),T=tt(T,w,D,S,p,10,Ze[49]),S=tt(S,T,w,D,_,15,Ze[50]),D=tt(D,S,T,w,f,21,Ze[51]),w=tt(w,D,S,T,k,6,Ze[52]),T=tt(T,w,D,S,l,10,Ze[53]),S=tt(S,T,w,D,y,15,Ze[54]),D=tt(D,S,T,w,u,21,Ze[55]),w=tt(w,D,S,T,v,6,Ze[56]),T=tt(T,w,D,S,x,10,Ze[57]),S=tt(S,T,w,D,h,15,Ze[58]),D=tt(D,S,T,w,b,21,Ze[59]),w=tt(w,D,S,T,d,6,Ze[60]),T=tt(T,w,D,S,g,10,Ze[61]),S=tt(S,T,w,D,c,15,Ze[62]),D=tt(D,S,T,w,m,21,Ze[63]),n[0]=n[0]+w|0,n[1]=n[1]+D|0,n[2]=n[2]+S|0,n[3]=n[3]+T|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}(We);We._createHelper(at),We._createHmacHelper(at);var rt=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 Fe,{keySize:4,hasher:at,iterations:1},e),s}return s(r,[{key:"compute",value:function(e,t){for(var a,r=this.cfg,s=r.hasher.create(),i=Ge.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}(Fe),st=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 Fe,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?pt:ft};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}(Ke);st._ENC_XFORM_MODE=1,st._DEC_XFORM_MODE=2,st.keySize=4,st.ivSize=4;var it=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}(Fe);function nt(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 ot=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(it);ot.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;nt.call(this,e,t,r),a.encryptBlock(e,t),this._prevBlock=e.slice(t,t+r)}}]),r}(ot),ot.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),nt.call(this,e,t,r),this._prevBlock=s}}]),r}(ot);var ut={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=Ge.create(i,r);e.concat(o)},unpad:function(e){var t=e,a=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=a}},ct=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:ot,padding:ut},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}(st),lt=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}(Fe),dt={stringify:function(e){var t=e.ciphertext,a=e.salt;return(a?Ge.create([1398893684,1701076831]).concat(a).concat(t):t).toString(Ye)},parse:function(e){var t,a=Ye.parse(e),r=a.words;return 1398893684===r[0]&&1701076831===r[1]&&(t=Ge.create(r.slice(2,4)),r.splice(0,4),a.sigBytes-=16),lt.create({ciphertext:a,salt:t})}},ft=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 Fe,this.cfg,r),i=e.createEncryptor(a,s),n=i.finalize(t),o=i.cfg;return lt.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 Fe,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}(Fe);ft.cfg=Object.assign(new Fe,{format:dt});var ht={execute:function(e,t,a,r){var s=r;s||(s=Ge.random(8));var i=rt.create({keySize:t+a}).compute(e,s),n=Ge.create(i.words.slice(t),4*a);return i.sigBytes=4*t,lt.create({key:i,iv:n,salt:s})}},pt=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 Fe,this.cfg,r),i=s.kdf.execute(a,e.keySize,e.ivSize);s.iv=i.iv;var n=ft.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 Fe,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,ft.decrypt.call(this,e,s,n.key,i)}}]),r}(ft);pt.cfg=Object.assign(ft.cfg,{kdf:ht});for(var vt=[],mt=[],yt=[],gt=[],kt=[],bt=[],_t=[],xt=[],wt=[],Dt=[],St=[],Tt=0;Tt<256;Tt+=1)St[Tt]=Tt<128?Tt<<1:Tt<<1^283;for(var At=0,jt=0,Et=0;Et<256;Et+=1){var Bt=jt^jt<<1^jt<<2^jt<<3^jt<<4;Bt=Bt>>>8^255&Bt^99,vt[At]=Bt,mt[Bt]=At;var Ct=St[At],Pt=St[Ct],Ut=St[Pt],It=257*St[Bt]^16843008*Bt;yt[At]=It<<24|It>>>8,gt[At]=It<<16|It>>>16,kt[At]=It<<8|It>>>24,bt[At]=It,It=16843009*Ut^65537*Pt^257*Ct^16843008*At,_t[Bt]=It<<24|It>>>8,xt[Bt]=It<<16|It>>>16,wt[Bt]=It<<8|It>>>24,Dt[Bt]=It,At?(At=Ct^St[St[St[Ut^Ct]]],jt^=St[St[jt]]):At=jt=1}var Mt=[0,1,2,4,8,16,32,64,128,27,54],Ot=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=vt[e>>>24]<<24|vt[e>>>16&255]<<16|vt[e>>>8&255]<<8|vt[255&e]):(e=vt[(e=e<<8|e>>>24)>>>24]<<24|vt[e>>>16&255]<<16|vt[e>>>8&255]<<8|vt[255&e],e^=Mt[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:_t[vt[e>>>24]]^xt[vt[e>>>16&255]]^wt[vt[e>>>8&255]]^Dt[vt[255&e]]}}}},{key:"encryptBlock",value:function(e,t){this._doCryptBlock(e,t,this._keySchedule,yt,gt,kt,bt,vt)}},{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,_t,xt,wt,Dt,mt),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 m=r[l>>>24]^s[d>>>16&255]^i[f>>>8&255]^n[255&h]^a[p];p+=1;var y=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=m,d=y,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}(ct);Ot.keySize=8;var Rt=ct._createHelper(Ot),zt=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(it);zt.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}(zt),zt.Decryptor=zt.Encryptor;var Lt={pad:function(){},unpad:function(){}},Vt={decryptWordArray:function(e,t,a){var r=Ne.parse(t),s=Ne.parse(W(a)),i=Ge.create(new Uint8Array(e)),n=Rt.decrypt(lt.create({ciphertext:i}),r,{iv:s,mode:zt,padding:Lt});return Vt.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,a){if(e.videoSenc){var r=e.kidValue,s=e.videoSenc;e.samples.forEach((function(t,i){var n=s[i],o=t.data,u=[],c=[],l=n.InitializationVector;if(n.subsamples&&n.subsamples.length)n.subsamples.forEach((function(e){var t=e.BytesOfClearData+e.BytesOfProtectedData,a=o.slice(0,t);u.push(a.slice(0,e.BytesOfClearData)),c.push(a.slice(e.BytesOfClearData)),o=o.slice(t)}));else{var d=t.size;u.push(o.slice(0,0)),c.push(o.slice(0,d)),o=o.slice(d)}var f=new Oe;f.write.apply(f,c);var h=a?a(f.buffer,r,l):Vt.decryptWordArray(f.buffer,r,l),p=new Oe;u.forEach((function(e,t){var a=c[t].length,r=h.slice(0,a);p.write(e),p.write(r),h=h.slice(a)})),e.samples[i].data=p.buffer}))}if(t.audioSenc){var i=t.kidValue,n=t.audioSenc;t.samples.forEach((function(e,r){var s=n[r],o=a?a(e.data,i,s.InitializationVector):Vt.decryptWordArray(e.data,i,s.InitializationVector);t.samples[r].data=o}))}}},Ft=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 D,this.audioTrack=new S,this.metadataTrack=s||new C,this.log=new Le("MP4Demuxer",!n||!n.openLog||!n.openLog),t&&t.forEach((function(e){var t;(t=o._videoSamples).push.apply(t,m(e.frames))})),r&&r.forEach((function(e){var t;(t=o._audioSamples).push.apply(t,m(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||(Ae.moovToTrack(e,this.videoTrack,this.audioTrack),this.videoSenc=this.videoTrack.videoSenc,this.audioSenc=this.audioTrack.audioSenc),!this._audioSamples.length&&!this._videoSamples.length){var t=Ae.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 T(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=q(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 m=r[0],y=r[1];m<=y;m++){if(!(i=this._audioSamples[m]))throw new Error("cannot found video frame #".concat(m));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,o){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 u=0;u<20;)try{var c=this._lastRemainBuffer.subarray(0,t-this._lastRemainBufferStartPos),l=new Uint8Array(e.byteLength+c.byteLength);l.set(c,0),l.set(new Uint8Array(e),c.byteLength),e=l,t-=c.byteLength,this._lastRemainBuffer=null,this._lastRemainBufferStartPos=0;break}catch(E){if(!(u<20))throw new Error("new Uint8Array error:,"+E.errorMessage);u++}var d,f,h,p=this.videoTrack,v=this.audioTrack;p.samples=[],v.samples=[],p.videoSenc=null,v.audioSenc=null;var m=0,y=0;if(this._videoSamples.length>0&&a.length>0){for(var g,k=e.byteLength+t,b=a[0];b<=a[1];b++){if(!(d=this._videoSamples[b]))throw new Error("cannot found video frame #".concat(b));d.offset>=t&&d.offset+d.size<=k&&(m=(h=d.offset-t)+d.size,f=e.subarray(h,m),(g=new T(d.pts||d.dts,d.dts)).duration=d.duration,g.gopId=d.gopId,g.sampleOffset=d.index,d.keyframe&&g.setToKeyframe(),g.data=f,g.size=d.size,p.samples.push(g))}p.samples.length>0&&(p.gopId=p.samples[0].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.videoSenc&&(p.videoSenc=this.videoSenc.slice(p.samples[0].sampleOffset,p.samples[0].sampleOffset+p.samples.length),p.kidValue=n))}if(this._audioSamples.length>0&&r.length>0){for(var _=r[0];_<=r[1];_++){if(!(d=this._audioSamples[_]))throw new Error("cannot found video frame #".concat(_));d.offset>=t&&d.offset+d.size<=e.byteLength+t&&(y=(h=d.offset-t)+d.size,f=e.subarray(h,y),v.samples.push(new A(d.dts,f,d.duration,d.index)))}v.samples.length>0&&(v.gopId=v.samples[0].gopId||p.gopId,v.baseMediaDecodeTime=v.samples[0].dts,v.startPts=v.samples[0].pts/v.timescale,v.endPts=v.samples[v.samples.length-1].pts/v.timescale,this.audioSenc&&(v.audioSenc=this.audioSenc.slice(v.samples[0].sampleOffset,v.samples[0].sampleOffset+v.samples.length),v.kidValue=n))}this.decoderData(p,v,o);for(var x=0,w=0;w<p.samples.length;w++)for(var D=0,S=p.samples[w].data,j=S.length-1;D<j;)x=q(S,D),D+=4,p.samples[w].units.push(S.subarray(D,D+x)),D+=x;return this._lastRemainBuffer=e.subarray(Math.max(m,y)),this._lastRemainBuffer.byteLength>0?this._lastRemainBufferStartPos=t+e.byteLength-this._lastRemainBuffer.byteLength:this._lastRemainBufferStartPos=0,{videoTrack:p,audioTrack:v,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,a){e.useEME||t.useEME||Vt.decoderAESCTRData(e,t,a)}}],[{key:"probe",value:function(e){return Ae.probe(e)}}]),e}(),Gt=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=ze.ftyp([e,t]),r=this._remuxData(e,a.byteLength+8),s=r.mdatData,i=r.chunkOffset,n=this._remuxData(t,i).mdatData,o=ze.mdat(F(s,n)),u=ze.moovMP4([e,t]);return e.ext=void 0,t.ext=void 0,e.samples=[],t.samples=[],F(a,o,u)}},{key:"_remuxTrack",value:function(e){var t=ze.ftyp([e]),a=this._remuxData(e,t.byteLength+8).mdatData,r=ze.mdat(a),s=ze.moovMP4([e]);return e.ext=void 0,e.samples=[],F(t,r,s)}},{key:"_remuxData",value:function(e,t){var a=this,r=e.type===b.VIDEO,s=e.samples,i=0;r?s.forEach((function(e){i+=e.units.reduce((function(e,t){return e+t.byteLength}),0),i+=4*e.units.length})):i=s.reduce((function(e,t){return e+t.size}),0);for(var n,o=new Uint8Array(i),u=new DataView(o.buffer),c=e.ext={stts:[],stsc:[],stsz:[],stco:[],stss:[],ctts:[]},l=0,d=0,f=s.length,h=function(){n=s[p],d+=n.duration;var e=r?0:n.size;r?n.units.forEach((function(t){u.setUint32(l,t.byteLength),l+=4,o.set(t,l),l+=t.byteLength,e+=4+t.byteLength})):(o.set(n.data,l),l+=e),n.size=e,c.stsz.push(e),r&&a._fillCttsSamples(c.ctts,n.cts),a._fillSttsSamples(c.stts,n,s[p+1]),a._fillStcoSamples(c.stco,p,1,t),t+=e,r&&n.keyframe&&c.stss.push(p+1)},p=0;p<f;p++)h();return e.duration=d,this._fillStscSamples(c.stsc,f,1),{mdatData:o,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}(),Nt=Object.freeze(Object.defineProperty({__proto__:null,FMP4Demuxer:Ie,FMP4Remuxer:Ve,MP4Demuxer:Ft,MP4Remuxer:Gt,MP4Parser:Ae,Crypto:Vt},Symbol.toStringTag,{value:"Module"}));return t(t(t(t(t({},ye),De),Nt),P),{},{Logger:I})}));
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.regexp.exec.js"),require("core-js/modules/es.regexp.test.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.math.hypot.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.array.join.js"),require("core-js/modules/es.string.from-code-point.js"),require("core-js/modules/es.string.match.js"),require("core-js/modules/es.array.sort.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.regexp.exec.js","core-js/modules/es.regexp.test.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.math.hypot.js","core-js/modules/es.function.name.js","core-js/modules/es.array.join.js","core-js/modules/es.string.from-code-point.js","core-js/modules/es.string.match.js","core-js/modules/es.array.sort.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,k(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=k(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){var r,s,i,n,o=[],u=!0,c=!1;try{if(i=(a=a.call(e)).next,0===t){if(Object(a)!==a)return;u=!1}else for(;!(u=(r=i.call(a)).done)&&(o.push(r.value),o.length!==t);u=!0);}catch(l){c=!0,s=l}finally{try{if(!u&&null!=a.return&&(n=a.return(),Object(n)!==n))return}finally{if(c)throw s}}return o}}(e,t)||y(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 m(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)||y(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 y(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}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var a=e[Symbol.toPrimitive];if(void 0!==a){var r=a.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var b={VIDEO:"video",AUDIO:"audio",METADATA:"metadata"},_={AV1:"av1",AVC:"avc",HEVC:"hevc"},x={AAC:"aac",G711PCMA:"g7110a",G711PCMU:"g7110m",OPUS:"opus",MP3:"mp3"},w={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"},D=function(){function e(){a(this,e),i(this,"id",1),i(this,"type",b.VIDEO),i(this,"codecType",_.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,"lastKeyFrameDts",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:"firstDts",get:function(){return this.samples.length?this.samples[0].dts:null}},{key:"firstPts",get:function(){return this.samples.length?this.samples[0].pts:null}},{key:"samplesDuration",get:function(){if(this.samples.length>0){var e=this.samples[0],t=this.samples[this.samples.length-1];return t.dts-e.dts+t.duration}return 0}},{key:"exist",value:function(){return!!/av01/.test(this.codec)||!!(this.pps.length&&this.sps.length&&this.codec)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isVideoEncryption}}]),e}(),S=function(){function e(){a(this,e),i(this,"id",2),i(this,"type",b.AUDIO),i(this,"codecType",x.AAC),i(this,"pid",-1),i(this,"codec",""),i(this,"container",""),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.container||this.codecType!==x.AAC&&this.codecType!==x.G711PCMA&&this.codecType!==x.G711PCMU&&this.codecType!==x.OPUS&&this.codecType!==x.MP3)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isAudioEncryption}},{key:"firstDts",get:function(){return this.samples.length?this.samples[0].dts:null}},{key:"firstPts",get:function(){return this.samples.length?this.samples[0].pts:null}},{key:"samplesDuration",get:function(){if(this.samples.length>0){var e=this.samples[0],t=this.samples[this.samples.length-1];return t.dts-e.dts+t.duration}return 0}}]),e}(),T=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)})),j=s((function e(t,r){a(this,e),i(this,"time",0),this.data=t,this.originPts=this.pts=r})),E=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(j),B=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(j),C=function(){function e(){a(this,e),i(this,"id",3),i(this,"type",b.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}(),P=Object.freeze(Object.defineProperty({__proto__:null,VideoTrack:D,AudioTrack:S,VideoSample:T,AudioSample:A,FlvScriptSample:E,SeiSample:B,MetadataTrack:C,TrackType:b,VideoCodecType:_,AudioCodecType:x,WarningType:w},Symbol.toStringTag,{value:"Module"})),U=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:"bitsAvailable",get:function(){return this._bitsAvailable}},{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}(),I=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(I,"disabled",!0);var M=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}(),O="undefined"!=typeof window,R=O&&navigator.userAgent.toLocaleLowerCase(),z=O&&/^((?!chrome|android).)*safari/.test(R),L=O&&R.includes("firefox"),V=O&&R.includes("android");function F(){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 G=Math.pow(2,32);function N(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<8)+(e[t+1]||0)}function q(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 H(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return q(e,t)*G+q(e,t+4)}function K(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 W(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 X(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)}))}function Y(e,t){return Number(e+"."+t)}var 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,m=0,y=e.getFrameDuration(u);s+7<r;)if(255===t[s]&&240==(246&t[s+1])){if(!(l=(3&t[s+3])<<11|t[s+4]<<3|(224&t[s+5])>>5)||r-s<l)break;c=2*(1&~t[s+1]),n.push({pts:a+m*y,data:t.subarray(s+7+c,s+l)}),m++,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 L?e>=6?(r=5,s=e-3):(r=2,s=e):V?(r=2,s=e):(r=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:"parseAnnexB",value:function(e){var t=e.byteLength-1,a=0;do{if(0!==e[t])break;a++,t--}while(t>0);a>=3&&(e=e.subarray(0,t+1));for(var r=e.length,s=2,i=0;null!==e[s]&&void 0!==e[s]&&1!==e[s];)s++;if((i=++s+2)>=r)return[];for(var n=[];i<r;)switch(e[i]){case 0:if(0!==e[i-1]){i+=2;break}if(0!==e[i-2]){i++;break}if(i<r-1&&1!==e[i+1]){i++;break}s!==i-2&&n.push(e.subarray(s,i-2));do{i++}while(1!==e[i]&&i<r);i=(s=i+1)+2;break;case 1:if(0!==e[i-1]||0!==e[i-2]){i+=3;break}s!==i-2&&n.push(e.subarray(s,i-2)),i=(s=i+1)+2;break;default:i+=3}return s<r&&n.push(e.subarray(s)),n}},{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=q(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,r+i),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}(),J=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(Q.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 U(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,m,y,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);m=t.readBool(),k=(y=S)/(g=2*D)}}return{codec:K(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:y,fpsDen:g,fps:k,fixedFrame:m}}}]),e}(),$=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 m=t.subarray(f,f+o);r||(r=e.parseVPS(Q.removeEPB(m),a)),d.push(m);break;case 33:var y=t.subarray(f,f+o);s||(s=e.parseSPS(Q.removeEPB(y),a)),c.push(y);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 U(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 U(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,m=1===i&&0===o?2:1;f-=v*(c+u),h-=m*(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);var i=[],n=[];if(t>e.bitsAvailable)throw new Error("maxSubLayersMinus inavlid size ".concat(t));for(var 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}(),ee=function(){function e(){a(this,e)}return s(e,null,[{key:"getFrameDuration",value:function(e){return 20}},{key:"parseHeaderPackets",value:function(e){if(e.length){for(var t=new DataView(e.buffer,e.byteOffset,e.byteLength),a="",r=0;r<8;r++)a+=String.fromCodePoint(e[r]);if("OpusHead"!==a)throw new Error("Invalid Opus MagicSignature");var s=e[9];console.log("Pre-skip",e[10],e[11]);var i=t.getUint32(12,!0),n=t.getInt16(16,!0);if(i){return{outputGain:n,sampleRate:i,channelCount:s,config:new Uint8Array(e.buffer,e.byteOffset+8,e.byteLength-8),codec:"opus",originCodec:"opus"}}}}}]),e}(),te=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],ae=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],re=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],se=[0,1,1,4],ie=null,ne=function(){function e(){a(this,e)}return s(e,null,[{key:"isHeader",value:function(e,t){return t+1<e.length&&255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}},{key:"appendFrame",value:function(t,a,r,s,i){if(!(r+24>a.length)){var n=e.parseHeader(a,r);if(n&&r+n.frameLength<=a.length){var o=s+i*(9e4*n.samplesPerFrame/n.sampleRate),u={data:a.subarray(r,r+n.frameLength),pts:o,dts:o};return u.size=u.data.byteLength,t.config=[],t.channelCount=n.channelCount,t.sampleRate=n.sampleRate,L?t.codec="mp3":t.container="audio/mpeg",t.samples.push(u),{length:n.frameLength}}}}},{key:"parseHeader",value:function(e,t){var a=e[t+1]>>3&3,r=e[t+1]>>1&3,s=e[t+2]>>4&15,i=e[t+2]>>2&3;if(1!==a&&0!==s&&15!==s&&3!==i){var n=e[t+2]>>1&1,o=e[t+3]>>6,u=1e3*te[14*(3===a?3-r:3===r?3:4)+s-1],c=ae[3*(3===a?0:2===a?1:2)+i],l=3===o?1:2,d=re[a][r],f=se[r],h=8*d*f,p=Math.floor(d*u/c+n)*f;if(null===ie){var v=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);ie=v?parseInt(v[1]):0}return!!ie&&ie<=87&&2===r&&u>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:c,channelCount:l,frameLength:p,samplesPerFrame:h}}}}]),e}(),oe=1e3,ue=5e3,ce=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._lastVideoDuration=0,this._keyFrameInNextChunk=!1,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;!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),!r&&t&&(this._audioNextPts=this._videoNextDts=t);var n=this._baseDtsInited&&(this._videoTimestampBreak||!this.videoTrack.exist())&&(this._audioTimestampBreak||!this.audioTrack.exist());if(n&&this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(i),this._keyFrameInNextChunk=!1,this._fixVideo(s),this.metadataTrack.exist()){var o=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/o})),this.metadataTrack.flvScriptSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/o}))}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.keyframe&&(t._keyFrameInNextChunk=!0)})),e.fpsNum&&e.fpsDen)r=e.timescale*(e.fpsDen/e.fpsNum);else if(e.length>1){var s=e.samples[0],i=e.samples[a.length-1];r=Math.floor((i.dts-s.dts)/(a.length-1))}else r=this._lastVideoDuration||40;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:w.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,this.audioTrack.exist()||(this._videoTimestampBreak=1))}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:w.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,this._lastVideoDuration=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:w.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){this._calculateBaseDts(this.audioTrack,this.videoTrack)&&(this.audioTrack.exist()?this.videoTrack.exist()?this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts):this._baseDts-=this._audioNextPts:this._baseDts-=this._videoNextDts,this._videoTimestampBreak=0,this._audioTimestampBreak=0)}},{key:"_doFixAudioInternal",value:function(e,t,a){if(!e.sampleDuration)switch(e.codecType){case x.AAC:e.sampleDuration=Z.getFrameDuration(e.timescale,a);break;case x.OPUS:e.sampleDuration=ee.getFrameDuration(e.samples,a);break;case x.G711PCMA:case x.G711PCMU:e.sampleDuration=this._getG711Duration(e);break;default:console.error("can't fix audio codecType:",e.codecType)}var r=e.sampleDuration,s=e.codecType===x.OPUS?20:e.codecType===x.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&&this._keyFrameInNextChunk&&(o=this._audioNextPts=u.dts,c=0,this._audioTimestampBreak=0),!this._audioTimestampBreak&&c>=3*r&&c<=oe&&!z){var l=this._getSilentFrame(e)||t[0].data.subarray(),d=Math.floor(c/r);Math.abs(u.pts-this._lastAudioExceptionGapDot)>ue&&(this._lastAudioExceptionGapDot=u.pts,e.warnings.push({type:w.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 if(c<=-3*r&&c>=-1e3)Math.abs(u.pts-this._lastAudioExceptionOverlapDot)>ue&&(this._lastAudioExceptionOverlapDot=u.pts,e.warnings.push({type:w.AUDIO_DROPPED,pts:u.pts,originPts:u.originPts,nextPts:o,refSampleDuration:r})),t.splice(n,1),n--;else{if(Math.abs(c)>oe&&(this._audioTimestampBreak++,Math.abs(u.pts-this._lastAudioExceptionLargeGapDot)>ue&&(this._lastAudioExceptionLargeGapDot=u.pts,e.warnings.push({type:w.LARGE_AUDIO_GAP,time:u.pts/1e3,pts:u.pts,originPts:u.originPts,nextPts:o,sampleDuration:c,refSampleDuration:r}))),e.codecType===x.OPUS){var p=t[t.length-1];p&&(p.duration=u.pts-p.pts)}else 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===x.AAC?Z.getSilentFrame(e.codec,e.channelCount):new Uint8Array(8*e.sampleDuration*e.channelCount)}}]),e}(),le=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 m=0;m<v;m++){var y=e._parseValue(new DataView(t.buffer,t.byteOffset+s,t.byteLength-s)),g=y.data,k=y.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=M.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=M.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}(),de=7,fe=8,he=10,pe=13,ve=new I("FlvDemuxer"),me=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 D,this.audioTrack=r||new S,this.metadataTrack=s||new C,this._fixer=new ce(this.videoTrack,this.audioTrack,this.metadataTrack)}return s(e,[{key:"demux",value:function(t){var a,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3?arguments[3]:void 0,n=this.audioTrack,o=this.videoTrack,u=this.metadataTrack;if(!r&&s||(this._remainingData=null),r&&(this._headerParsed=!1),r?(o.reset(),n.reset(),u.reset()):(o.samples=[],n.samples=[],u.seiSamples=[],u.flvScriptSamples=[],o.warnings=[],n.warnings=[],this._remainingData&&(t=F(this._remainingData,t),this._remainingData=null)),!t.length)return{videoTrack:o,audioTrack:n,metadataTrack:u};var c=0;if(!this._headerParsed){if(!e.probe(t))throw new Error("Invalid flv file");n.present=(4&t[4])>>>2!=0,o.present=0!=(1&t[4]),this._headerParsed=!0,c=q(t,5)+4}for(var l,d,f,h,p,v=t.length;c+15<v&&(l=t[c],!(c+15+(d=t[c+1]<<16|t[c+2]<<8|t[c+3])>v));)f=(t[c+7]<<24>>>0)+(t[c+4]<<16)+(t[c+5]<<8)+t[c+6],c+=11,h=t.subarray(c,c+d),8===l?this._parseAudio(h,f):9===l?(i&&(this.seamlessLoadingSwitching=!0),this._parseVideo(h,f)):18===l?this._parseScript(h,f):ve.warn("Invalid tag type: ".concat(l)),(p=q(t,c+=d))!==11+d&&ve.warn("Invalid PrevTagSize ".concat(p," (").concat(11+d,")")),c+=4;c<v&&(this._remainingData=t.subarray(c)),n.formatTimescale=o.formatTimescale=o.timescale=u.timescale=1e3,n.timescale=n.codecType===x.OPUS?1e3:n.sampleRate||0,!n.exist()&&n.hasSample()&&n.reset(),!o.exist()&&o.hasSample()&&o.reset();var m=u.flvScriptSamples[u.flvScriptSamples.length-1],y=null==m||null===(a=m.data)||void 0===a?void 0:a.onMetaData;return y&&(null!=o&&o.exist()&&(y.hasOwnProperty("duration")&&(o.duration=1e3*y.duration),y.hasOwnProperty("width")&&y.hasOwnProperty("height")&&(o.width=y.width,o.height=y.height)),null!=n&&n.exist()&&y.hasOwnProperty("duration")&&(n.duration=1e3*y.duration)),{videoTrack:o,audioTrack:n,metadataTrack:u}}},{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,s){return this.demux(e,t,a,s),this.fix(r,t,a)}},{key:"_parseAudio",value:function(t,a){if(t.length){var r=(240&t[0])>>>4,s=this.audioTrack;if(r!==he&&r!==de&&r!==fe&&r!==pe)return ve.warn("Unsupported sound format: ".concat(r)),void s.reset();if(r!==he&&r!==pe){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}switch(r){case de:case fe:this._parseG711(t,a,r);break;case he:this._parseAac(t,a);break;case pe:this._parseOpus(t,a)}}}},{key:"_parseOpus",value:function(e,t){var a=this.audioTrack,r=e[1];switch(a.codecType=x.OPUS,r){case 0:var s=ee.parseHeaderPackets(e.subarray(2));s?(a.codec=s.codec,a.channelCount=s.channelCount,a.sampleRate=s.sampleRate,a.config=s.config,a.sampleDuration=ee.getFrameDuration([],a.timescale)):(a.reset(),ve.warn("Cannot parse AudioSpecificConfig",e));break;case 1:if(null==t)return;var i=new A(t,e.subarray(2),a.sampleDuration);a.samples.push(i);break;default:ve.warn("Unknown OpusPacketType: ".concat(r))}}},{key:"_parseG711",value:function(e,t,a){var r=this.audioTrack,s=e.subarray(1);if(!(s.byteLength<1)){var i=new A(t,s);r.codecType=7===a?x.G711PCMA:x.G711PCMU,r.sampleRate=8e3,r.codec=r.codecType,r.samples.push(i)}}},{key:"_parseAac",value:function(e,t){var a=this.audioTrack;if(a.codecType=x.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(),ve.warn("Cannot parse AudioSpecificConfig",e))}else if(1===e[1]){if(null==t)return;a.samples.push(new A(t,e.subarray(2)))}else ve.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 ve.warn("Unsupported codecId: ".concat(s));var n=12===s;i.codecType=n?_.HEVC:_.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?$.parseHEVCDecoderConfigurationRecord(c):J.parseAVCDecoderConfigurationRecord(c);if(l){var d=l.hvcC,f=l.sps,h=l.ppsArr,p=l.spsArr,v=l.vpsArr,m=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),m&&(i.nalUnitSize=m)}else ve.warn("Cannot parse ".concat(n?"HEVC":"AVC","DecoderConfigurationRecord"),e)}else if(1===o){var y=Q.parseAvcC(e.subarray(5),i.nalUnitSize);if((y=this._checkAddMetaNalToUnits(n,y,i))&&y.length){var g=new T(t+u,t,y);if(this.seamlessLoadingSwitching&&t<i.lastKeyFrameDts)return;this.seamlessLoadingSwitching=!1,1===r&&(g.setToKeyframe(),i.lastKeyFrameDts=t),i.samples.push(g),y.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 B(Q.parseSEI(Q.removeEPB(e),n),t+u))}})),g.keyframe&&this._gopId++,g.gopId=this._gopId}else ve.warn("Cannot parse NALUs",e)}else 2===o||ve.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 E(le.parse(e),t))}}],[{key:"probe",value:function(e){return 70===e[0]&&76===e[1]&&86===e[2]&&1===e[3]&&q(e,5)>=9}}]),e}();i(me,"AUDIO_RATE",[5500,11e3,22e3,44e3]);var ye=Object.freeze(Object.defineProperty({__proto__:null,FlvDemuxer:me},Symbol.toStringTag,{value:"Module"})),ge=9e4,ke=45e4,be=9e4,_e=function(){function e(t,r,s,i){a(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=s,this._baseDts=-1,this._baseVideoDts=-1,this._baseAudioDts=-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,this._needForceFixLargeGap=null==i?void 0:i.forceFixLargeGap,this._largeGapThreshold=(null==i?void 0:i.largeGapThreshold)||45e4}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,this._baseAudioDts-=t,this._baseVideoDts-=t),!r){this._videoNextDts=l>0?t+l:t,this._audioNextPts=l>0?t:t-l,this._needForceFixLargeGap&&(this._videoNextDts=0,this._audioNextPts=0);var d=u?u.dts-this._baseDts-this._videoNextDts:0,f=c?c.pts-this._baseDts-this._audioNextPts:0;Math.abs(d||f)>be&&(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._needForceFixLargeGap?t._baseVideoDts:t._baseDts,e.pts-=t._needForceFixLargeGap?t._baseVideoDts: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)if(e.warnings.push({type:w.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts/90,firstSampleDts:u.dts/90,nextSampleDts:((null===(s=a[1])||void 0===s?void 0:s.dts)||0)/90,sampleDuration:l/90}),u.dts+=l,u.pts+=l,c&&Math.abs(c.dts-u.dts)>be)this._videoTimestampBreak=!0,a.forEach((function(e,t){0!==t&&(e.dts+=l,e.pts+=l)}));else for(var d=1;d<n-1;d++){var f,h=null===(f=a[d])||void 0===f?void 0:f.dts,p=a[d-1].dts;h&&h-p<0&&(a[d].dts+=l,a[d].pts+=l)}if(e.fpsNum&&e.fpsDen&&(i=e.timescale*(e.fpsDen/e.fpsNum)),i<900&&(i=0),!i){var v=e.samples[0],m=e.samples[1];i=1===n?9e3:Math.floor(m.dts-v.dts)}for(var y=0;y<n;y++){var g=a[y].dts,k=a[y+1];if((o=y<n-1?k.dts-g:a[y-1]?Math.min(g-a[y-1].dts,i):i)>be||o<0){this._videoTimestampBreak=!0,o=this._audioTimestampBreak?i:Math.max(o,2700);var b=this._audioNextPts||0;k&&k.dts>b&&(o=i),e.warnings.push({type:w.LARGE_VIDEO_GAP,time:g/e.timescale,dts:g,originDts:a[y].originDts,nextDts:this._videoNextDts,sampleDuration:o,refSampleDuration:i})}a[y].duration=o,this._videoNextDts+=o}}}},{key:"_fixAudio",value:function(e){var t=this,a=e.samples;if(a.length)if(e.codecType!==x.MP3)a.forEach((function(e){e.pts-=t._needForceFixLargeGap?t._baseAudioDts:t._baseDts,e.dts=e.pts})),this._doFixAudioInternal(e,a,9e4);else{this.lastAudioSample&&a.unshift(this.lastAudioSample);for(var r=0;r<a.length;r++){var s=a[r];if(!a[r+1])break;s.duration=a[r+1].pts-s.pts,s.pts-=this._baseDts,s.dts=s.pts}this.lastAudioSample=a.pop()}}},{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,this._baseAudioDts=s),r.length&&(t.baseDts=i=r[0].dts,this._baseVideoDts=i),this._baseDts=Math.min(s,i);var n=i-s,o=!1;return Number.isFinite(n)&&Math.abs(n)>45e3&&t.warnings.push({type:w.LARGE_AV_SHIFT,videoBaseDts:i,audioBasePts:s,baseDts:this._baseDts,delta:n}),Number.isFinite(n)&&Math.abs(n)>this._largeGapThreshold*ge&&(o=!0),this._baseDtsInited||(o&&this._needForceFixLargeGap?this._needForceFixLargeGap=!0:this._needForceFixLargeGap=!1),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<=ge&&!z){var c=Z.getSilentFrame(e.codec,e.channelCount)||t[0].data.subarray(),l=Math.floor(u/r);Math.abs(o.pts-this._lastAudioExceptionGapDot)>ke&&(this._lastAudioExceptionGapDot=o.pts),e.warnings.push({type:w.AUDIO_FILLED,pts:o.pts/90,originPts:o.originPts,count:l,nextPts:n/90,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)>ke&&(this._lastAudioExceptionOverlapDot=o.pts,e.warnings.push({type:w.AUDIO_DROPPED,pts:o.pts/90,originPts:o.originPts,nextPts:n/90,refSampleDuration:r})),t.splice(i,1),i--):(Math.abs(u)>=ge&&(this._audioTimestampBreak=!0,Math.abs(o.pts-this._lastAudioExceptionLargeGapDot)>ke&&(this._lastAudioExceptionLargeGapDot=o.pts,e.warnings.push({type:w.LARGE_AUDIO_GAP,time:o.pts/1e3,pts:o.pts/90,originPts:o.originPts,nextPts:n/90,sampleDuration:u,refSampleDuration:r}))),o.dts=o.pts=n,this._audioNextPts+=r)}}}]),e}(),xe=new I("TsDemuxer"),we=function(){function e(t,r,s){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};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 D,this.audioTrack=r||new S,this.metadataTrack=s||new C,this._fixer=new _e(this.videoTrack,this.audioTrack,this.metadataTrack,n)}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=F(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,m=(15&e[p+10])<<8|e[p+11];for(p+=12+m;p<v;){var y=(31&e[p+1])<<8|e[p+2];switch(e[p]){case 15:r.pid=c=y;break;case 3:case 4:-1===r.pid&&(r.pid=c=y,r.codecType=x.MP3);break;case 27:if(-1!==u)break;s.codecType=_.AVC,s.pid=u=y;break;case 36:if(-1!==u)break;s.codecType=_.HEVC,s.pid=u=y;break;default:xe.warn("Unsupported stream. type: ".concat(e[p],", pid: ").concat(y))}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:xe.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(F.apply(void 0,m(this._videoPesData)));if(t){var a=Q.parseAnnexB(t.data);a?this._createVideoSample(a,t.pts,t.dts):xe.warn("Cannot parse avc units",t),this._videoPesData=[]}else xe.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===_.HEVC,n=new T(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 B(Q.parseSEI(Q.removeEPB(e),i),t));case 32:if(!i)break;if(!s.vps.length){var o=$.parseVPS(Q.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=Q.removeEPB(e),c=i?$.parseSPS(u,s.hvcC):J.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]);break;case 9:case 35:break;case 38:if(i){for(var l=!1,d=2;d<e.byteLength;d++)if(255===e[d]){l=!0;break}if(!l)return}}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){xe.warn("Video sample no pts",t);var a=e.samples[e.samples.length-1];a?(t.pts=a.pts,t.dts=a.dts):xe.warn("Drop video sample",t)}else e.samples.push(t)}},{key:"_parseAudioData",value:function(){if(this._audioPesData.length){var t=e._parsePES(F.apply(void 0,m(this._audioPesData)));if(t){switch(this.audioTrack.codecType){case x.AAC:this._parseAacData(t);break;case x.MP3:this._parseMPEG(t)}this._audioPesData=[]}else xe.warn("Cannot parse audio pes",this._audioPesData)}}},{key:"_parseAacData",value:function(e){var t=this.audioTrack,a=e.pts;if(null==a){if(xe.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,m(s.frames.map((function(e){return new A(e.pts,e.data)})))),s.skip&&xe.warn("Skip aac adts ".concat(s.skip," bits")),s.remaining&&xe.warn("Remaining aac adts ".concat(s.remaining," bits"))):xe.warn("Cannot parse aac adts",e)}},{key:"_parseMPEG",value:function(e){var t=e.data,a=t.length,r=0,s=0,i=e.pts;if(void 0!==i)for(;s<a;)if(ne.isHeader(t,s)){var n=ne.appendFrame(this.audioTrack,t,s,i,r);if(!n)break;s+=n.length,r++}else s++;else xe.warn("[tsdemuxer]: MPEG PES unknown PTS")}}],[{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:we},Symbol.toStringTag,{value:"Module"})),Se=function(){function e(t,r,s){a(this,e),this.dv=new DataView(t),this.start=this.offset=r||this.dv.byteOffset,this.end=s?this.start+s:this.start+this.dv.byteLength}return s(e,[{key:"buffer",get:function(){return this.dv.buffer}},{key:"unreadLength",get:function(){return Math.max(this.end-this.offset,0)}},{key:"size",get:function(){return this.end-this.start}},{key:"readFloat",value:function(e){var t=0;switch(e){case 4:t=this.dv.getFloat32(this.offset);break;case 8:t=this.dv.getFloat64(this.offset);break;default:throw new Error("read ".concat(e,"-byte float is not supported"))}return this.offset+=e,t}},{key:"back",value:function(e){this.offset-=e}},{key:"skip",value:function(e){this.offset+=e}},{key:"readInt",value:function(e){var t=this.offset;switch(this.offset+=e,e){case 1:return this.dv.getInt8(t);case 2:return this.dv.getInt16(t);case 4:return this.dv.getInt32(t);default:throw new Error("read ".concat(e,"-byte integers is not supported"))}}},{key:"read",value:function(e){var t=this.offset;switch(this.offset+=e,e){case 1:return this.dv.getUint8(t);case 2:return this.dv.getUint16(t);case 3:return(this.dv.getUint16(t)<<8)+this.dv.getUint8(t+2);case 4:return this.dv.getUint32(t);default:return this.back(e-4),this.read(e-4)+this.dv.getUint32(t)*Math.pow(256,e-4)}}},{key:"write",value:function(e,t){var a=this.offset;switch(this.offset+=e,e){case 1:return this.dv.setUint8(a,t);case 2:return this.dv.setUint16(a,t);case 3:return this.dv.setUint8(a,t>>>16),this.dv.setUint16(a+1,65535&t);case 4:return this.dv.setUint32(a,t);default:throw new Error("write ".concat(e,"-byte integers is not supported"))}}},{key:"readToBuffer",value:function(e){var t;return t=this.offset||e?this.dv.buffer.slice(this.offset,e?this.offset+e:this.end):this.dv.buffer,this.offset+=t.byteLength,t}},{key:"readToUint8",value:function(e){var t=new Uint8Array(this.dv.buffer,this.offset,e||this.unreadLength);return this.offset+=t.byteLength,t}},{key:"readString",value:function(e){for(var t=0,a="";t<e;t++)a+=String.fromCharCode(this.dv.getUint8(this.offset)),this.offset++;return a}}],[{key:"fromUint8",value:function(t){return new e(t.buffer,t.byteOffset,t.byteLength)}},{key:"concatUint8s",value:function(e){var t=new Uint8Array(e.reduce((function(e,t){return e+t.byteLength}),0)),a=0;return e.forEach((function(e){t.set(e,a),a+=e.byteLength})),t}},{key:"concatUint8",value:function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];return this.concatUint8s(t)}}]),e}(),Te=function(){function e(t,r){a(this,e),this.offset=0,this.val=t,this.size=r}return s(e,[{key:"skip",value:function(e){this.offset+=e}},{key:"read",value:function(e){var t=this.size-this.offset-e;if(t>=0){var a=0,r=0;if(this.offset+=e,this.size>31){for(;r<e;r++)a+=Math.pow(2,r);return this.val/Math.pow(2,t)&a}for(;r<e;r++)a+=1<<r;return this.val>>>t&a}throw new Error("the number of the read operation exceeds the total length limit of bits")}}],[{key:"fromByte",value:function(t,a){return new e(t.read(a),a<<3)}}]),e}(),Ae=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=q(t),n=String.fromCharCode.apply(null,t.subarray(4,8)),o=8,1===i?(i=H(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 Ce(e,!0,(function(e,t){e.trackId=q(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=q(t,a),a+=4),s&&(e.sampleDescriptionIndex=q(t,a),a+=4),i&&(e.defaultSampleDuration=q(t,a),a+=4),n&&(e.defaultSampleSize=q(t,a),a+=4),o&&(e.defaultSampleFlags=q(t,a))}))}},{key:"sidx",value:function(e){return Ce(e,!0,(function(e,t){var a=0;e.reference_ID=q(t,a),a+=4,e.timescale=q(t,a),a+=4,0===e.version?(e.earliest_presentation_time=q(t,a),a+=4,e.first_offset=q(t,a),a+=4):(e.earliest_presentation_time=H(t,a),a+=8,e.first_offset=H(t,a),a+=8),a+=2,e.references=[];var r=N(t,a);a+=2;for(var s=0;s<r;s++){var i={};e.references.push(i);var n=q(t,a);a+=4,i.reference_type=n>>31&1,i.referenced_size=2147483647&n,i.subsegment_duration=q(t,a),n=q(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 Ce(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 Ce(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=q(t,16),e.duration=H(t,20),a+=28):(e.timescale=q(t,8),e.duration=q(t,12),a+=16),e.nextTrackId=q(t,a+76)}))}},{key:"trak",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){var a=Se.fromUint8(t);1===e.version?(a.read(8),a.read(8),e.trackId=a.read(4),a.read(4),e.duration=a.read(8)):(a.read(4),a.read(4),e.trackId=a.read(4),a.read(4),e.duration=a.read(4)),a.skip(16),e.matrix=[];for(var r=0;r<36;r++)e.matrix.push(a.read(1));a.back(36);for(var s,i=[],n=0;n<3;n++)i.push(Y(a.readInt(2),a.readInt(2))),i.push(Y(a.readInt(2),a.readInt(2))),s=a.readInt(4),i.push(Y(s>>30,1073741823&s));e.rotation=function(e){if(e.length<5)return 0;var t=Math.hypot(e[0],e[3]),a=Math.hypot(e[1],e[4]);return 0===t||0===a?0:180*Math.atan2(e[1]/a,e[0]/t)/Math.PI}(i),e.width=a.read(4),e.height=a.read(4)}))}},{key:"mdia",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){var a=0;1===e.version?(e.timescale=q(t,16),e.duration=H(t,20),a+=28):(e.timescale=q(t,8),e.duration=q(t,12),a+=16);var r=N(t,a);e.language=String.fromCharCode(96+(r>>10&31),96+(r>>5&31),96+(31&r))}))}},{key:"hdlr",value:function(e){return Ce(e,!0,(function(e,t){0===e.version&&(e.handlerType=String.fromCharCode.apply(null,t.subarray(4,8)))}))}},{key:"minf",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){e.graphicsmode=N(t),e.opcolor=[N(t,2),N(t,4),N(t,6)]}))}},{key:"smhd",value:function(e){return Ce(e,!0,(function(e,t){e.balance=N(t)}))}},{key:"stbl",value:function(t){return Ce(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 Ce(e,!0,(function(e,a){var r=0,s=q(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=N(a,r);r+=2;for(var c=0;c<u;c++){var l={};l.BytesOfClearData=N(a,r),r+=2,l.BytesOfProtectedData=q(a,r),r+=4,n.subsamples.push(l)}}e.samples.push(n)}}))}},{key:"pssh",value:function(e){return Ce(e,!0,(function(e,t){for(var a=[],r=[],s=0,i=0;i<16;i++)r.push(Ue(t[s+i]));if(s+=16,e.version>0){var n=q(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(Ue(c))}}var l=q(t,s);e.data_size=l,s+=4,e.kid=a,e.system_id=r,e.buffer=t}))}},{key:"stsd",value:function(t){return Ce(t,!0,(function(t,a,r){t.entryCount=q(a),t.entries=e.findBox(a.subarray(4),[],r+4).map((function(t){switch(t.type){case"av01":return e.av01(t);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 Ce(t,!1,(function(t,a,r){t.channelCount=N(a,16),t.samplesize=N(a,18),t.sampleRate=q(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 Ce(t,!1,(function(t,a,r){t.width=N(a,24),t.height=N(a,26),t.horizresolution=q(a,28),t.vertresolution=q(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 Ce(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(Ue(t[a])),a+=1}))}},{key:"schi",value:function(t){return Ce(t,!1,(function(t,a,r){t.tenc=e.tenc(e.findBox(a,["tenc"],r)[0])}))}},{key:"sinf",value:function(t){return Ce(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 Ce(e,!1,(function(e,t){e.data_format="";for(var a=0;a<4;a++)e.data_format+=String.fromCharCode(t[a])}))}},{key:"colr",value:function(e){return Ce(e,!1,(function(t,a){var r=Se.fromUint8(a);t.data=e.data,t.colorType=r.readString(4),"nclx"===t.colorType?(t.colorPrimaries=r.read(2),t.transferCharacteristics=r.read(2),t.matrixCoefficients=r.read(2),t.fullRangeFlag=r.read(1)>>7):"rICC"!==t.colorType&&"prof"!==t.colorType||(t.iccProfile=a.readToUint8())}))}},{key:"av01",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Ee(t,a),i=a.subarray(s);r+=s,t.av1C=e.av1C(e.findBox(i,["av1C"],r)[0]),t.colr=e.colr(e.findBox(i,["colr"],r)[0])}))}},{key:"av1C",value:function(e){return Ce(e,!1,(function(t,a){t.data=e.data;var r,s=Se.fromUint8(a),i=Te.fromByte(s,4);t.marker=i.read(1),t.version=i.read(7),t.seqProfile=i.read(3),t.seqLevelIdx0=i.read(5),t.seqTier0=i.read(1),t.highBitdepth=i.read(1),t.twelveBit=i.read(1),t.monochrome=i.read(1),t.chromaSubsamplingX=i.read(1),t.chromaSubsamplingY=i.read(1),t.chromaSamplePosition=i.read(2),t.reserved=i.read(3),t.initialPresentationDelayPresent=i.read(1),t.initialPresentationDelayPresent?t.initialPresentationDelayMinusOne=i.read(4):t.initialPresentationDelayMinusOne=0,t.configOBUs=s.readToUint8(),2===t.seqLevelIdx0&&1===t.highBitdepth?r=1===t.twelveBit?"12":"10":t.seqProfile<=2&&(r=1===t.highBitdepth?"10":"08"),t.codec=["av01",t.seqProfile,(t.seqLevelIdx0<10?"0"+t.seqLevelIdx0:t.seqLevelIdx0)+(t.seqTier0?"H":"M"),r].join(".")}))}},{key:"avc1",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Ee(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 Ce(e,!1,(function(t,a){t.data=e.data,t.configurationVersion=a[0],t.AVCProfileIndication=a[1],t.profileCompatibility=a[2],t.AVCLevelIndication=a[3],t.codec=K([a[1],a[2],a[3]]),t.lengthSizeMinusOne=3&a[4],t.spsLength=31&a[5],t.sps=[];for(var r=6,s=0;s<t.spsLength;s++){var i=N(a,r);r+=2,t.sps.push(a.subarray(r,r+i)),r+=i}t.ppsLength=a[r],r+=1,t.pps=[];for(var n=0;n<t.ppsLength;n++){var o=N(a,r);r+=2,t.pps.push(a.subarray(r,r+=o)),r+=o}}))}},{key:"hvc1",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Ee(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 Ce(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=q(a,2),t.generalConstraintIndicatorFlags=a.subarray(6,12),t.generalLevelIdc=a[12],t.avgFrameRate=N(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=N(a,s+1),s+=3;for(var c,l=[],d=0;d<n;d++)o=N(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 Ce(e,!1,(function(e,t){e.hSpacing=q(t),e.vSpacing=q(t,4)}))}},{key:"mp4a",value:function(t){return Ce(t,!1,(function(t,a,r){var s=Be(t,a);t.esds=e.esds(e.findBox(a.subarray(s),["esds"],r+s)[0])}))}},{key:"esds",value:function(e){return Ce(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 Ce(e,!1,(function(e,t){Be(e,t)}))}},{key:"stts",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push({count:q(t,s),delta:q(t,s+4)}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"ctts",value:function(e){return Ce(e,!0,(function(e,t){var a=q(t),r=[],s=4;if(1===e.version)for(var i=0;i<a;i++)r.push({count:q(t,s),offset:q(t,s+4)}),s+=8;else for(var n=0;n<a;n++)r.push({count:q(t,s),offset:-(1+~q(t,s+4))}),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stsc",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push({firstChunk:q(t,s),samplesPerChunk:q(t,s+4),sampleDescriptionIndex:q(t,s+8)}),s+=12;e.entryCount=a,e.entries=r}))}},{key:"stsz",value:function(e){return Ce(e,!0,(function(e,t){var a=q(t),r=q(t,4),s=[];if(!a)for(var i=8,n=0;n<r;n++)s.push(q(t,i)),i+=4;e.sampleSize=a,e.sampleCount=r,e.entrySizes=s}))}},{key:"stco",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push(q(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"co64",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push(H(t,s)),s+=8;e.entryCount=a,e.entries=r}))}},{key:"stss",value:function(e){return Ce(e,!0,(function(e,t){for(var a=q(t),r=[],s=4,i=0;i<a;i++)r.push(q(t,s)),s+=4;e.entryCount=a,e.entries=r}))}},{key:"moof",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){e.sequenceNumber=q(t)}))}},{key:"traf",value:function(t){return Ce(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 Ce(e,!0,(function(e,t){var a=e.version,r=e.flags,s=t.length,i=e.sampleCount=q(t),n=4;if(s>n&&1&r&&(e.dataOffset=-(1+~q(t,n)),n+=4),s>n&&4&r&&(e.firstSampleFlags=q(t,n),n+=4),e.samples=[],s>n)for(var o,u=0;u<i;u++)o={},256&r&&(o.duration=q(t,n),n+=4),512&r&&(o.size=q(t,n),n+=4),1024&r&&(o.flags=q(t,n),n+=4),2048&r&&(o.cts=a?-(1+~q(t,n+4)):q(t,n),n+=4),e.samples.push(o)}))}},{key:"tfdt",value:function(e){return Ce(e,!0,(function(e,t){1===e.version?e.baseMediaDecodeTime=H(t):e.baseMediaDecodeTime=q(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,m=null===(u=n.tkhd)||void 0===u?void 0:u.trackId;null!=m&&(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,v.rotation=n.tkhd.rotation,v.matrix=n.tkhd.matrix;var y,g,k,b,w,D,S,T,A=n.mdia.minf.stbl.stsd.entries[0];if(v.width=A.width,v.height=A.height,A.pasp&&(v.sarRatio=[A.pasp.hSpacing,A.pasp.vSpacing]),A.av1C)v.codecType=_.AV1,v.codec=A.av1C.codec,v.av1C=A.av1C.data,A.colr&&(v.colr=A.colr.data);else if(A.hvcC)v.codecType=_.HEVC,v.codec=A.hvcC.codec,v.vps=A.hvcC.vps,v.sps=A.hvcC.sps,v.pps=A.hvcC.pps,v.hvcC=A.hvcC.data;else{if(!A.avcC)throw new Error("unknown video stsd entry");v.codec=A.avcC.codec,v.sps=A.avcC.sps,v.pps=A.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,A&&"encv"===A.type)v.isVideoEncryption=!0,A.default_KID=null===(y=A.sinf)||void 0===y||null===(g=y.schi)||void 0===g?void 0:g.tenc.default_KID,A.default_IsEncrypted=null===(k=A.sinf)||void 0===k||null===(b=k.schi)||void 0===b?void 0:b.tenc.default_IsEncrypted,A.default_IV_size=null===(w=A.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,A.data_format=null===(S=A.sinf)||void 0===S||null===(T=S.frma)||void 0===T?void 0:T.data_format,v.useEME=e.useEME,v.kidValue=e.kidValue,v.pssh=e.pssh,v.encv=A}if(o&&a){var j,E,B,C,P,U,I,M,O,R=a,z=null===(j=o.tkhd)||void 0===j?void 0:j.trackId;null!=z&&(R.id=o.tkhd.trackId),R.tkhdDuration=o.tkhd.duration,R.mvhdDurtion=e.mvhd.duration,R.mvhdTimecale=e.mvhd.timescale,R.timescale=R.formatTimescale=o.mdia.mdhd.timescale,R.duration=o.mdia.mdhd.duration||R.mvhdDurtion/R.mvhdTimecale*R.timescale;var L,V,F,G,N,q,H,K,W=o.mdia.minf.stbl.stsd.entries[0];switch(R.sampleSize=W.sampleSize,R.sampleRate=W.sampleRate,R.channelCount=W.channelCount,R.present=!0,W.type){case"alaw":R.codecType=R.codec=x.G711PCMA,R.sampleRate=8e3;break;case"ulaw":R.codecType=R.codec=x.G711PCMU,R.sampleRate=8e3;break;default:R.sampleDuration=Z.getFrameDuration(R.sampleRate,R.timescale),R.sampleRateIndex=Z.getRateIndexByRate(R.sampleRate),R.objectType=(null===(r=W.esds)||void 0===r?void 0:r.objectType)||2,W.esds&&(R.config=Array.from(W.esds.config)),R.codec=(null===(s=W.esds)||void 0===s?void 0:s.codec)||"mp4a.40.2"}if(R.sampleDuration=Z.getFrameDuration(R.sampleRate,R.timescale),R.objectType=(null===(E=W.esds)||void 0===E?void 0:E.objectType)||2,W.esds&&(W.esds.config?R.config=Array.from(W.esds.config):console.warn("esds config is null")),R.codec=(null===(B=W.esds)||void 0===B?void 0:B.codec)||"mp4a.40.2",R.sampleRateIndex=Z.getRateIndexByRate(R.sampleRate),R.ext={},R.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,R.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,R.present=!0,W&&"enca"===W.type)R.isAudioEncryption=!0,W.data_format=null===(L=W.sinf)||void 0===L||null===(V=L.frma)||void 0===V?void 0:V.data_format,W.default_KID=null===(F=W.sinf)||void 0===F||null===(G=F.schi)||void 0===G?void 0:G.tenc.default_KID,W.default_IsEncrypted=null===(N=W.sinf)||void 0===N||null===(q=N.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,R.audioSenc=o.mdia.minf.stbl.senc&&o.mdia.minf.stbl.senc.samples,R.useEME=e.useEME,R.kidValue=e.kidValue,R.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=je(c,l,d,f,p,h)}if(r){var v,m,y,g=null===(v=r.mdia)||void 0===v||null===(m=v.minf)||void 0===m?void 0:m.stbl;if(!g)return;var k=null===(y=r.mdia.mdhd)||void 0===y?void 0:y.timescale,b=g.stts,_=g.stsc,x=g.stsz,w=g.stco;if(!(k&&b&&_&&x&&w))return;i=je(b,_,x,w)}return{videoSamples:s,audioSamples:i}}}}}]),e}();function je(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,m=0,y=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:m,duration:r,size:h[y]||a.sampleSize,offset:f[g]+b,index:y},p&&(u.keyframe=n[y],u.keyframe&&v++,u.gopId=v),o&&y<o.length&&(u.pts=u.dts+o[y]),c.push(u),m+=r,++y<_?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 Ee(e,t){return e.dataReferenceIndex=N(t,6),e.width=N(t,24),e.height=N(t,26),e.horizresolution=q(t,28),e.vertresolution=q(t,32),e.frameCount=N(t,40),e.depth=N(t,74),78}function Be(e,t){return e.dataReferenceIndex=N(t,6),e.channelCount=N(t,16),e.sampleSize=N(t,18),e.sampleRate=q(t,24)/65536,28}function Ce(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 Pe=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},Ue=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(Pe(Number(t).toString(16),2,0))})),e[0]},Ie=function(){function e(t,r,s){a(this,e),i(this,"__loadedMoofWraps",[]),i(this,"__lastRemainData",null),i(this,"__lastRemainDataStart",0),i(this,"__nextMoofStart",-1),this.videoTrack=t||new D,this.audioTrack=r||new S,this.metadataTrack=s||new C}return s(e,[{key:"demuxPart",value:function(e,t,a){var r=this,s=this.videoTrack,i=this.audioTrack,n=s.exist(),o=i.exist(),u=/av01/.test(s.codec);s.samples=[],i.samples=[];var c=e,l=t;if(this.__lastRemainData){var d=this.__lastRemainDataStart+this.__lastRemainData.byteLength;if(t<=d&&t>this.__lastRemainDataStart&&t+e.byteLength>d){var f=e.subarray(this.__lastRemainData.byteLength+this.__lastRemainDataStart-t);c=F(this.__lastRemainData,f),l=this.__lastRemainDataStart,this.__lastRemainData=null}else this.__lastRemainData=null,this.__lastRemainDataStart=0,this.__nextMoofStart=-1}if(!a){var h=Ae.findBox(c,["moov"])[0];if(!h)throw new Error("cannot found moov box");a=Ae.moov(h)}if(c){var p=l+c.byteLength;n||o||Ae.moovToTrack(a,s,i);var v=[];this.__nextMoofStart<0?Ae.findBox(c,["moof"],l).forEach((function(e){return v.push(e)})):this.__nextMoofStart>=l&&this.__nextMoofStart<=p-8&&Ae.findBox(c.subarray(this.__nextMoofStart-l),["moof"],this.__nextMoofStart).forEach((function(e){return v.push(e)})),v.filter((function(e){return e.size<=e.data.length})).forEach((function(e){var t=Ae.moof(e);r.__nextMoofStart=t.start+Math.max.apply(Math,m(t.traf.map((function(e){return e.trun.samples.reduce((function(e,t){return e+t.size}),e.trun.dataOffset||0)})))),r.__loadedMoofWraps.push({start:t.start,nextMoofStart:r.__nextMoofStart,moof:t}),r.__loadedMoofWraps.sort((function(e,t){return e.start-t.start}))}));var g,k=function(e,t){var a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!a){if(Array.isArray(e)||(a=y(e))||t&&e&&"number"==typeof e.length){a&&(e=a);var r=0,s=function(){};return{s:s,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:s}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,n=!0,o=!1;return{s:function(){a=a.call(e)},n:function(){var e=a.next();return n=e.done,e},e:function(e){o=!0,i=e},f:function(){try{n||null==a.return||a.return()}finally{if(o)throw i}}}}(this.__loadedMoofWraps);try{var b=function(){var e=g.value;if(e.start>p||e.nextMoofStart<l)return"continue";var t,a=e.start,n=Ae.moofToSamples(e.moof,s,i),o=s.baseMediaDecodeTime,d=i.baseMediaDecodeTime;Object.keys(n).forEach((function(e){s.id==e?n[e].some((function(e){var i=e.offset+=a;if(!(i<l)){if(i+e.size>p)return!0;var n=new T((e.pts||e.dts)+o,e.dts+o);n.duration=e.duration,n.gopId=e.gopId,e.keyframe&&n.setToKeyframe();var d=c.subarray(i-l,i-l+e.size);if(n.data=d,!u)for(var f=0,h=d.length-1;f<h;)t=q(d,f),f+=4,n.units.push(d.subarray(f,f+t)),f+=t;r.__lastRemainDataStart=i+e.size,s.samples.push(n)}})):i.id==e&&n[e].some((function(e){var t=e.offset+a;if(!(t<l)){if(t+e.size>p)return!0;var s=c.subarray(t-l,t-l+e.size);i.samples.push(new A(e.dts+d,s,e.duration)),r.__lastRemainDataStart=t+e.size}}))}))};for(k.s();!(g=k.n()).done;)b()}catch(_){k.e(_)}finally{k.f()}}return this.__lastRemainDataStart>l&&this.__lastRemainDataStart<c.byteLength+l?this.__lastRemainData=c.subarray(this.__lastRemainDataStart-l):(this.__lastRemainData=c,this.__lastRemainDataStart=l),s.samples.length&&(s.baseMediaDecodeTime=s.samples[0].pts),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts),{videoTrack:s,audioTrack:i,metadataTrack:this.metadataTrack}}},{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=Ae.findBox(t,["moov"])[0];if(!n)throw new Error("cannot found moov box");Ae.moovToTrack(Ae.moov(n),null,r)}var o=Ae.findBox(t,["moof"])[0];if(o){var u=Ae.moofToSamples(Ae.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=Ae.findBox(e,["moov"])[0];if(!d)throw new Error("cannot found moov box");Ae.moovToTrack(Ae.moov(d),a,r)}var f=Ae.findBox(e,["moof"])[0];if(f){var h,p=Ae.moofToSamples(Ae.moof(f),a,r),v=a.baseMediaDecodeTime,m=r.baseMediaDecodeTime,y=f.start;Object.keys(p).forEach((function(t){a.id==t?p[t].map((function(t){t.offset+=y;var r=new T((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=q(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+=y;var a=e.subarray(t.offset,t.offset+t.size);r.samples.push(new A(t.dts+m,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 Ae.probe(e)}}]),e}();function Me(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 Oe=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=Me(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}(),Re=Math.pow(2,32)-1,ze=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===b.VIDEO&&e.codecType===_.HEVC}))?e.FTYPHEV1:e.FTYPAVC1}},{key:"initSegment",value:function(t){return F(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],X(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(m(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(m(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===b.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):t.codecType===x.OPUS?e.opus(t):e.mp4a(t):t.useEME&&t.encv?e.encv(t):t.av1C?e.av01(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,m(s)).concat([1,i.length>>>8&255,255&i.length])).concat.apply(a,m(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(X(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:"av01",value:function(t){return e.box(e.types.av01,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]),t.av1C,t.colr)}},{key:"avc1hev1",value:function(t){var a=t.codecType===_.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,m(e))})),t.pps.forEach((function(e){s=e.byteLength,n.push(s>>>8&255),n.push(255&s),n.push.apply(n,m(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,m(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:"opus",value:function(t){var a=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]),r=t.config.length?e.dOps(t):[];return e.box(e.types.Opus,a,r)}},{key:"dOps",value:function(t){if(t.config)return t.config[4]=t.sampleRate>>>24&255,t.config[5]=t.sampleRate>>>16&255,t.config[6]=t.sampleRate>>>8&255,t.config[7]=255&t.sampleRate,e.box(e.types.dOps,t.config)}},{key:"mvex",value:function(t){return e.box.apply(e,[e.types.mvex].concat(m(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(m(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),s=0;if(t.isVideo&&t.videoSenc&&t.videoSenc.forEach((function(e){s+=8,e.subsamples&&e.subsamples.length&&(s+=2,s+=6*e.subsamples.length)})),t.videoSencLength=s,t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)){if(t.isVideoEncryption){if(t.isVideo){var i=e.saiz(t),n=e.saio(t),o=e.trun1(t),u=e.senc(t);return e.box(e.types.traf,a,r,i,n,o,u)}if(t.isAudioEncryption){var c=e.sbgp(),l=e.saiz(t),d=e.saio(t),f=e.senc(t),h=e.trun1(t);return e.box(e.types.traf,a,r,c,l,d,f,h)}var p=e.sbgp(),v=e.trun1(t);return e.box(e.types.traf,a,r,p,v)}if(t.isVideo){var m=e.trun1(t);return e.box(e.types.traf,a,r,m)}var y=e.sbgp(),g=e.saiz(t),k=e.saio(t),b=e.senc(t),_=e.trun1(t);return e.box(e.types.traf,a,r,y,g,k,b,_)}var x=e.sdtp(t);return e.box(e.types.traf,a,r,x,e.trun(t.samples,x.byteLength+76))}},{key:"sdtp",value:function(t){var a=new Oe;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 Oe,r=Oe.writeUint32(t.samples.length),s=null;if(t.isVideo){var i=t.videoSencLength;s=Oe.writeUint32(16*t.samples.length+i+149),!t.isVideoEncryption&&t.isAudioEncryption&&(s=Oe.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=Oe.writeUint32(n)}return t.samples.forEach((function(e){a.write(Oe.writeUint32(e.duration)),a.write(Oe.writeUint32(e.size)),a.write(Oe.writeUint32(e.keyframe?33554432:65536)),t.isVideo&&a.write(Oe.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 Oe,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(Oe.writeUint32(16+o),e.types.senc,this.extension(0,i)),a.write(Oe.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(Oe.writeUint16(e.subsamples.length)),e.subsamples.forEach((function(e){a.write(Oe.writeUint16(e.BytesOfClearData)),a.write(Oe.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/(Re+1)),s=Math.floor(a%(Re+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(m(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===b.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,F(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,F(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,F(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,F(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,F(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,F(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(ze,"types",["Opus","dOps","av01","av1C","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(ze,"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(ze,"FTYPAVC1",ze.box(ze.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))),i(ze,"FTYPHEV1",ze.box(ze.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,104,101,118,49]))),i(ze,"DINF",ze.box(ze.types.dinf,ze.box(ze.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(ze,"VMHD",ze.box(ze.types.vmhd,new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))),i(ze,"SMHD",ze.box(ze.types.smhd,new Uint8Array([0,0,0,0,0,0,0,0]))),i(ze,"StblTable",new Uint8Array([0,0,0,0,0,0,0,0])),i(ze,"STTS",ze.box(ze.types.stts,ze.StblTable)),i(ze,"STSC",ze.box(ze.types.stsc,ze.StblTable)),i(ze,"STSZ",ze.box(ze.types.stsz,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]))),i(ze,"STCO",ze.box(ze.types.stco,ze.StblTable));var Le=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(Le,"disabled",!0);for(var Ve=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 Le("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=ze.initSegment(d)):(c&&(e=ze.initSegment([this.videoTrack])),l&&(t=ze.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=/av01/.test(e.codec),r=0;a?t.forEach((function(e){r+=e.data.byteLength})):t.forEach((function(e){r+=e.units.reduce((function(e,t){return e+t.byteLength}),0),r+=4*e.units.length}));var s=new Uint8Array(r);if(a)for(var i,n=0,o=t.length,u=0;n<o;n++)i=t[n],s.set(i.data,u),i.size=i.data.byteLength,u+=i.size;else for(var c,l=new DataView(s.buffer),d=function(e,a){a=t[f];var r=0;a.units.forEach((function(t){l.setUint32(e,t.byteLength),e+=4,s.set(t,e),e+=t.byteLength,r+=4+t.byteLength})),a.size=r,p=e,c=a},f=0,h=t.length,p=0;f<h;f++)d(p,c);var v=ze.mdat(s);return F(ze.moof([e]),v)}},{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=ze.mdat(t);return F(ze.moof([e]),a)}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset()}}]),e}(),Fe=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}(),Ge=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]:Ne;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}(Fe),Ne={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 Ge(a,t/2)}},qe=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 Ge(a,t)},He=function(e){return qe(unescape(encodeURIComponent(e)))},Ke=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 Ge,this._nDataBytes=0}},{key:"_append",value:function(e){var t=e;"string"==typeof t&&(t=He(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 Ge(t,u)}},{key:"clone",value:function(){var e=p(o(r.prototype),"clone",this).call(this);return e._data=this._data.clone(),e}}]),r}(Fe),We=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 Fe,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 Xe(e,a).finalize(t)}}}]),r}(Ke),Xe=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=He(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}(Fe),Ye={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 Ge.create(r,s)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},Ze=[],Qe=0;Qe<64;Qe+=1)Ze[Qe]=4294967296*Math.abs(Math.sin(Qe+1))|0;var Je=function(e,t,a,r,s,i,n){var o=e+(t&a|~t&r)+s+n;return(o<<i|o>>>32-i)+t},$e=function(e,t,a,r,s,i,n){var o=e+(t&r|a&~r)+s+n;return(o<<i|o>>>32-i)+t},et=function(e,t,a,r,s,i,n){var o=e+(t^a^r)+s+n;return(o<<i|o>>>32-i)+t},tt=function(e,t,a,r,s,i,n){var o=e+(a^(t|~r))+s+n;return(o<<i|o>>>32-i)+t},at=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 Ge([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],m=a[t+9],y=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],T=n[3];w=Je(w,D,S,T,o,7,Ze[0]),T=Je(T,w,D,S,u,12,Ze[1]),S=Je(S,T,w,D,c,17,Ze[2]),D=Je(D,S,T,w,l,22,Ze[3]),w=Je(w,D,S,T,d,7,Ze[4]),T=Je(T,w,D,S,f,12,Ze[5]),S=Je(S,T,w,D,h,17,Ze[6]),D=Je(D,S,T,w,p,22,Ze[7]),w=Je(w,D,S,T,v,7,Ze[8]),T=Je(T,w,D,S,m,12,Ze[9]),S=Je(S,T,w,D,y,17,Ze[10]),D=Je(D,S,T,w,g,22,Ze[11]),w=Je(w,D,S,T,k,7,Ze[12]),T=Je(T,w,D,S,b,12,Ze[13]),S=Je(S,T,w,D,_,17,Ze[14]),D=Je(D,S,T,w,x,22,Ze[15]),w=$e(w,D,S,T,u,5,Ze[16]),T=$e(T,w,D,S,h,9,Ze[17]),S=$e(S,T,w,D,g,14,Ze[18]),D=$e(D,S,T,w,o,20,Ze[19]),w=$e(w,D,S,T,f,5,Ze[20]),T=$e(T,w,D,S,y,9,Ze[21]),S=$e(S,T,w,D,x,14,Ze[22]),D=$e(D,S,T,w,d,20,Ze[23]),w=$e(w,D,S,T,m,5,Ze[24]),T=$e(T,w,D,S,_,9,Ze[25]),S=$e(S,T,w,D,l,14,Ze[26]),D=$e(D,S,T,w,v,20,Ze[27]),w=$e(w,D,S,T,b,5,Ze[28]),T=$e(T,w,D,S,c,9,Ze[29]),S=$e(S,T,w,D,p,14,Ze[30]),D=$e(D,S,T,w,k,20,Ze[31]),w=et(w,D,S,T,f,4,Ze[32]),T=et(T,w,D,S,v,11,Ze[33]),S=et(S,T,w,D,g,16,Ze[34]),D=et(D,S,T,w,_,23,Ze[35]),w=et(w,D,S,T,u,4,Ze[36]),T=et(T,w,D,S,d,11,Ze[37]),S=et(S,T,w,D,p,16,Ze[38]),D=et(D,S,T,w,y,23,Ze[39]),w=et(w,D,S,T,b,4,Ze[40]),T=et(T,w,D,S,o,11,Ze[41]),S=et(S,T,w,D,l,16,Ze[42]),D=et(D,S,T,w,h,23,Ze[43]),w=et(w,D,S,T,m,4,Ze[44]),T=et(T,w,D,S,k,11,Ze[45]),S=et(S,T,w,D,x,16,Ze[46]),D=et(D,S,T,w,c,23,Ze[47]),w=tt(w,D,S,T,o,6,Ze[48]),T=tt(T,w,D,S,p,10,Ze[49]),S=tt(S,T,w,D,_,15,Ze[50]),D=tt(D,S,T,w,f,21,Ze[51]),w=tt(w,D,S,T,k,6,Ze[52]),T=tt(T,w,D,S,l,10,Ze[53]),S=tt(S,T,w,D,y,15,Ze[54]),D=tt(D,S,T,w,u,21,Ze[55]),w=tt(w,D,S,T,v,6,Ze[56]),T=tt(T,w,D,S,x,10,Ze[57]),S=tt(S,T,w,D,h,15,Ze[58]),D=tt(D,S,T,w,b,21,Ze[59]),w=tt(w,D,S,T,d,6,Ze[60]),T=tt(T,w,D,S,g,10,Ze[61]),S=tt(S,T,w,D,c,15,Ze[62]),D=tt(D,S,T,w,m,21,Ze[63]),n[0]=n[0]+w|0,n[1]=n[1]+D|0,n[2]=n[2]+S|0,n[3]=n[3]+T|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}(We);We._createHelper(at),We._createHmacHelper(at);var rt=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 Fe,{keySize:4,hasher:at,iterations:1},e),s}return s(r,[{key:"compute",value:function(e,t){for(var a,r=this.cfg,s=r.hasher.create(),i=Ge.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}(Fe),st=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 Fe,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?pt:ft};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}(Ke);st._ENC_XFORM_MODE=1,st._DEC_XFORM_MODE=2,st.keySize=4,st.ivSize=4;var it=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}(Fe);function nt(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 ot=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(it);ot.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;nt.call(this,e,t,r),a.encryptBlock(e,t),this._prevBlock=e.slice(t,t+r)}}]),r}(ot),ot.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),nt.call(this,e,t,r),this._prevBlock=s}}]),r}(ot);var ut={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=Ge.create(i,r);e.concat(o)},unpad:function(e){var t=e,a=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=a}},ct=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:ot,padding:ut},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}(st),lt=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}(Fe),dt={stringify:function(e){var t=e.ciphertext,a=e.salt;return(a?Ge.create([1398893684,1701076831]).concat(a).concat(t):t).toString(Ye)},parse:function(e){var t,a=Ye.parse(e),r=a.words;return 1398893684===r[0]&&1701076831===r[1]&&(t=Ge.create(r.slice(2,4)),r.splice(0,4),a.sigBytes-=16),lt.create({ciphertext:a,salt:t})}},ft=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 Fe,this.cfg,r),i=e.createEncryptor(a,s),n=i.finalize(t),o=i.cfg;return lt.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 Fe,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}(Fe);ft.cfg=Object.assign(new Fe,{format:dt});var ht={execute:function(e,t,a,r){var s=r;s||(s=Ge.random(8));var i=rt.create({keySize:t+a}).compute(e,s),n=Ge.create(i.words.slice(t),4*a);return i.sigBytes=4*t,lt.create({key:i,iv:n,salt:s})}},pt=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 Fe,this.cfg,r),i=s.kdf.execute(a,e.keySize,e.ivSize);s.iv=i.iv;var n=ft.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 Fe,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,ft.decrypt.call(this,e,s,n.key,i)}}]),r}(ft);pt.cfg=Object.assign(ft.cfg,{kdf:ht});for(var vt=[],mt=[],yt=[],gt=[],kt=[],bt=[],_t=[],xt=[],wt=[],Dt=[],St=[],Tt=0;Tt<256;Tt+=1)St[Tt]=Tt<128?Tt<<1:Tt<<1^283;for(var At=0,jt=0,Et=0;Et<256;Et+=1){var Bt=jt^jt<<1^jt<<2^jt<<3^jt<<4;Bt=Bt>>>8^255&Bt^99,vt[At]=Bt,mt[Bt]=At;var Ct=St[At],Pt=St[Ct],Ut=St[Pt],It=257*St[Bt]^16843008*Bt;yt[At]=It<<24|It>>>8,gt[At]=It<<16|It>>>16,kt[At]=It<<8|It>>>24,bt[At]=It,It=16843009*Ut^65537*Pt^257*Ct^16843008*At,_t[Bt]=It<<24|It>>>8,xt[Bt]=It<<16|It>>>16,wt[Bt]=It<<8|It>>>24,Dt[Bt]=It,At?(At=Ct^St[St[St[Ut^Ct]]],jt^=St[St[jt]]):At=jt=1}var Mt=[0,1,2,4,8,16,32,64,128,27,54],Ot=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=vt[e>>>24]<<24|vt[e>>>16&255]<<16|vt[e>>>8&255]<<8|vt[255&e]):(e=vt[(e=e<<8|e>>>24)>>>24]<<24|vt[e>>>16&255]<<16|vt[e>>>8&255]<<8|vt[255&e],e^=Mt[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:_t[vt[e>>>24]]^xt[vt[e>>>16&255]]^wt[vt[e>>>8&255]]^Dt[vt[255&e]]}}}},{key:"encryptBlock",value:function(e,t){this._doCryptBlock(e,t,this._keySchedule,yt,gt,kt,bt,vt)}},{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,_t,xt,wt,Dt,mt),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 m=r[l>>>24]^s[d>>>16&255]^i[f>>>8&255]^n[255&h]^a[p];p+=1;var y=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=m,d=y,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}(ct);Ot.keySize=8;var Rt=ct._createHelper(Ot),zt=function(e){n(r,e);var t=f(r);function r(){return a(this,r),t.apply(this,arguments)}return s(r)}(it);zt.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}(zt),zt.Decryptor=zt.Encryptor;var Lt={pad:function(){},unpad:function(){}},Vt={decryptWordArray:function(e,t,a){var r=Ne.parse(t),s=Ne.parse(W(a)),i=Ge.create(new Uint8Array(e)),n=Rt.decrypt(lt.create({ciphertext:i}),r,{iv:s,mode:zt,padding:Lt});return Vt.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,a){if(e.videoSenc){var r=e.kidValue,s=e.videoSenc;e.samples.forEach((function(t,i){var n=s[i],o=t.data,u=[],c=[],l=n.InitializationVector;if(n.subsamples&&n.subsamples.length)n.subsamples.forEach((function(e){var t=e.BytesOfClearData+e.BytesOfProtectedData,a=o.slice(0,t);u.push(a.slice(0,e.BytesOfClearData)),c.push(a.slice(e.BytesOfClearData)),o=o.slice(t)}));else{var d=t.size;u.push(o.slice(0,0)),c.push(o.slice(0,d)),o=o.slice(d)}var f=new Oe;f.write.apply(f,c);var h=a?a(f.buffer,r,l):Vt.decryptWordArray(f.buffer,r,l),p=new Oe;u.forEach((function(e,t){var a=c[t].length,r=h.slice(0,a);p.write(e),p.write(r),h=h.slice(a)})),e.samples[i].data=p.buffer}))}if(t.audioSenc){var i=t.kidValue,n=t.audioSenc;t.samples.forEach((function(e,r){var s=n[r],o=a?a(e.data,i,s.InitializationVector):Vt.decryptWordArray(e.data,i,s.InitializationVector);t.samples[r].data=o}))}}},Ft=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 D,this.audioTrack=new S,this.metadataTrack=s||new C,this.log=new Le("MP4Demuxer",!n||!n.openLog||!n.openLog),t&&t.forEach((function(e){var t;(t=o._videoSamples).push.apply(t,m(e.frames))})),r&&r.forEach((function(e){var t;(t=o._audioSamples).push.apply(t,m(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||(Ae.moovToTrack(e,this.videoTrack,this.audioTrack),this.videoSenc=this.videoTrack.videoSenc,this.audioSenc=this.audioTrack.audioSenc),!this._audioSamples.length&&!this._videoSamples.length){var t=Ae.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 T(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=q(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 m=r[0],y=r[1];m<=y;m++){if(!(i=this._audioSamples[m]))throw new Error("cannot found video frame #".concat(m));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,o){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 u=0;u<20;)try{var c=this._lastRemainBuffer.subarray(0,t-this._lastRemainBufferStartPos),l=new Uint8Array(e.byteLength+c.byteLength);l.set(c,0),l.set(new Uint8Array(e),c.byteLength),e=l,t-=c.byteLength,this._lastRemainBuffer=null,this._lastRemainBufferStartPos=0;break}catch(E){if(!(u<20))throw new Error("new Uint8Array error:,"+E.errorMessage);u++}var d,f,h,p=this.videoTrack,v=this.audioTrack;p.samples=[],v.samples=[],p.videoSenc=null,v.audioSenc=null;var m=0,y=0;if(this._videoSamples.length>0&&a.length>0){for(var g,k=e.byteLength+t,b=a[0];b<=a[1];b++){if(!(d=this._videoSamples[b]))throw new Error("cannot found video frame #".concat(b));d.offset>=t&&d.offset+d.size<=k&&(m=(h=d.offset-t)+d.size,f=e.subarray(h,m),(g=new T(d.pts||d.dts,d.dts)).duration=d.duration,g.gopId=d.gopId,g.sampleOffset=d.index,d.keyframe&&g.setToKeyframe(),g.data=f,g.size=d.size,p.samples.push(g))}p.samples.length>0&&(p.gopId=p.samples[0].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.videoSenc&&(p.videoSenc=this.videoSenc.slice(p.samples[0].sampleOffset,p.samples[0].sampleOffset+p.samples.length),p.kidValue=n))}if(this._audioSamples.length>0&&r.length>0){for(var _=r[0];_<=r[1];_++){if(!(d=this._audioSamples[_]))throw new Error("cannot found video frame #".concat(_));d.offset>=t&&d.offset+d.size<=e.byteLength+t&&(y=(h=d.offset-t)+d.size,f=e.subarray(h,y),v.samples.push(new A(d.dts,f,d.duration,d.index)))}v.samples.length>0&&(v.gopId=v.samples[0].gopId||p.gopId,v.baseMediaDecodeTime=v.samples[0].dts,v.startPts=v.samples[0].pts/v.timescale,v.endPts=v.samples[v.samples.length-1].pts/v.timescale,this.audioSenc&&(v.audioSenc=this.audioSenc.slice(v.samples[0].sampleOffset,v.samples[0].sampleOffset+v.samples.length),v.kidValue=n))}this.decoderData(p,v,o);for(var x=0,w=0;w<p.samples.length;w++)for(var D=0,S=p.samples[w].data,j=S.length-1;D<j;)x=q(S,D),D+=4,p.samples[w].units.push(S.subarray(D,D+x)),D+=x;return this._lastRemainBuffer=e.subarray(Math.max(m,y)),this._lastRemainBuffer.byteLength>0?this._lastRemainBufferStartPos=t+e.byteLength-this._lastRemainBuffer.byteLength:this._lastRemainBufferStartPos=0,{videoTrack:p,audioTrack:v,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,a){e.useEME||t.useEME||Vt.decoderAESCTRData(e,t,a)}}],[{key:"probe",value:function(e){return Ae.probe(e)}}]),e}(),Gt=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=ze.ftyp([e,t]),r=this._remuxData(e,a.byteLength+8),s=r.mdatData,i=r.chunkOffset,n=this._remuxData(t,i).mdatData,o=ze.mdat(F(s,n)),u=ze.moovMP4([e,t]);return e.ext=void 0,t.ext=void 0,e.samples=[],t.samples=[],F(a,o,u)}},{key:"_remuxTrack",value:function(e){var t=ze.ftyp([e]),a=this._remuxData(e,t.byteLength+8).mdatData,r=ze.mdat(a),s=ze.moovMP4([e]);return e.ext=void 0,e.samples=[],F(t,r,s)}},{key:"_remuxData",value:function(e,t){var a=this,r=e.type===b.VIDEO,s=e.samples,i=0;r?s.forEach((function(e){i+=e.units.reduce((function(e,t){return e+t.byteLength}),0),i+=4*e.units.length})):i=s.reduce((function(e,t){return e+t.size}),0);for(var n,o=new Uint8Array(i),u=new DataView(o.buffer),c=e.ext={stts:[],stsc:[],stsz:[],stco:[],stss:[],ctts:[]},l=0,d=0,f=s.length,h=function(){n=s[p],d+=n.duration;var e=r?0:n.size;r?n.units.forEach((function(t){u.setUint32(l,t.byteLength),l+=4,o.set(t,l),l+=t.byteLength,e+=4+t.byteLength})):(o.set(n.data,l),l+=e),n.size=e,c.stsz.push(e),r&&a._fillCttsSamples(c.ctts,n.cts),a._fillSttsSamples(c.stts,n,s[p+1]),a._fillStcoSamples(c.stco,p,1,t),t+=e,r&&n.keyframe&&c.stss.push(p+1)},p=0;p<f;p++)h();return e.duration=d,this._fillStscSamples(c.stsc,f,1),{mdatData:o,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}(),Nt=Object.freeze(Object.defineProperty({__proto__:null,FMP4Demuxer:Ie,FMP4Remuxer:Ve,MP4Demuxer:Ft,MP4Remuxer:Gt,MP4Parser:Ae,Crypto:Vt},Symbol.toStringTag,{value:"Module"}));return t(t(t(t(t({},ye),De),Nt),P),{},{Logger:I})}));
2
2
  //# sourceMappingURL=index.min.js.map