@byteplus/veplayer 1.18.0-rc.9 → 1.18.0
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/index.d.ts +161 -0
- package/index.min.js +2 -2
- package/lite.cjs +2 -2
- package/lite.esm.mjs +2 -2
- package/lite.min.js +2 -2
- package/package.json +1 -1
- package/plugin/modules/DashAbralgo.mjs +1 -1
- package/plugin/modules/XGVideo.mjs +1 -1
- package/plugin/modules/danmuMask.mjs +1 -1
- package/plugin/modules/danmujs.mjs +1 -1
- package/plugin/modules/dash.mjs +1 -1
- package/plugin/modules/flv.mjs +1 -1
- package/plugin/modules/hls.mjs +1 -1
- package/plugin/modules/hlsEncrypt.mjs +1 -1
- package/plugin/modules/hlsjs.mjs +1 -1
- package/plugin/modules/hlsjsPro.mjs +1 -1
- package/plugin/modules/mp4Encrypt.mjs +1 -1
- package/plugin/modules/preloader.mjs +1 -1
- package/plugin/modules/streamprobe.mjs +1 -1
- package/plugin/modules/vestrategy.mjs +1 -1
- package/plugin/modules/vestrategy_adapt_range.mjs +1 -1
- package/plugin/modules/vestrategy_h265.mjs +1 -1
- package/plugin/modules/vestrategy_preload.mjs +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// @byteplus/veplayer@1.18.0
|
|
1
|
+
// @byteplus/veplayer@1.18.0 Built @9/1/2026, 4:36:00 PM
|
|
2
2
|
function _iterableToArrayLimit$1(e,t){var i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var n,r,o,a,s=[],A=!0,u=!1;try{if(o=(i=i.call(e)).next,0===t){if(Object(i)!==i)return;A=!1}else for(;!(A=(n=o.call(i)).done)&&(s.push(n.value),s.length!==t);A=!0);}catch(e){u=!0,r=e}finally{try{if(!A&&null!=i.return&&(a=i.return(),Object(a)!==a))return}finally{if(u)throw r}}return s}}function ownKeys(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function _objectSpread2(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(i),!0).forEach((function(t){_defineProperty$2(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):ownKeys(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function _regeneratorRuntime$1(){_regeneratorRuntime$1=function(){return e};var e={},t=Object.prototype,i=t.hasOwnProperty,n=Object.defineProperty||function(e,t,i){e[t]=i.value},r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",s=r.toStringTag||"@@toStringTag";function A(e,t,i){return Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{A({},"")}catch(e){A=function(e,t,i){return e[t]=i}}function u(e,t,i,r){var o=t&&t.prototype instanceof l?t:l,a=Object.create(o.prototype),s=new D(r||[]);return n(a,"_invoke",{value:g(e,i,s)}),a}function c(e,t,i){try{return{type:"normal",arg:e.call(t,i)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function l(){}function h(){}function _(){}var f={};A(f,o,(function(){return this}));var m=Object.getPrototypeOf,p=m&&m(m(k([])));p&&p!==t&&i.call(p,o)&&(f=p);var v=_.prototype=l.prototype=Object.create(f);function E(e){["next","throw","return"].forEach((function(t){A(e,t,(function(e){return this._invoke(t,e)}))}))}function y(e,t){function r(n,o,a,s){var A=c(e[n],e,o);if("throw"!==A.type){var u=A.arg,d=u.value;return d&&"object"==typeof d&&i.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(A.arg)}var o;n(this,"_invoke",{value:function(e,i){function n(){return new t((function(t,n){r(e,i,t,n)}))}return o=o?o.then(n,n):n()}})}function g(e,t,i){var n="suspendedStart";return function(r,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===r)throw o;return{value:void 0,done:!0}}for(i.method=r,i.arg=o;;){var a=i.delegate;if(a){var s=b(a,i);if(s){if(s===d)continue;return s}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if("suspendedStart"===n)throw n="completed",i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);n="executing";var A=c(e,t,i);if("normal"===A.type){if(n=i.done?"completed":"suspendedYield",A.arg===d)continue;return{value:A.arg,done:i.done}}"throw"===A.type&&(n="completed",i.method="throw",i.arg=A.arg)}}}function b(e,t){var i=t.method,n=e.iterator[i];if(void 0===n)return t.delegate=null,"throw"===i&&e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method)||"return"!==i&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+i+"' method")),d;var r=c(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,d;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function k(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function t(){for(;++n<e.length;)if(i.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return r.next=r}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=_,n(v,"constructor",{value:_,configurable:!0}),n(_,"constructor",{value:h,configurable:!0}),h.displayName=A(_,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,_):(e.__proto__=_,A(e,s,"GeneratorFunction")),e.prototype=Object.create(v),e},e.awrap=function(e){return{__await:e}},E(y.prototype),A(y.prototype,a,(function(){return this})),e.AsyncIterator=y,e.async=function(t,i,n,r,o){void 0===o&&(o=Promise);var a=new y(u(t,i,n,r),o);return e.isGeneratorFunction(i)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(v),A(v,s,"Generator"),A(v,o,(function(){return this})),A(v,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),i=[];for(var n in t)i.push(n);return i.reverse(),function e(){for(;i.length;){var n=i.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=k,D.prototype={constructor:D,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(R),!e)for(var t in this)"t"===t.charAt(0)&&i.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(i,n){return a.type="throw",a.arg=e,t.next=i,n&&(t.method="next",t.arg=void 0),!!n}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=i.call(o,"catchLoc"),A=i.call(o,"finallyLoc");if(s&&A){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!A)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),R(i),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var n=i.completion;if("throw"===n.type){var r=n.arg;R(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,i){return this.delegate={iterator:k(e),resultName:t,nextLoc:i},"next"===this.method&&(this.arg=void 0),d}},e}function asyncGeneratorStep$1(e,t,i,n,r,o,a){try{var s=e[o](a),A=s.value}catch(e){return void i(e)}s.done?t(A):Promise.resolve(A).then(n,r)}function _asyncToGenerator$1(e){return function(){var t=this,i=arguments;return new Promise((function(n,r){var o=e.apply(t,i);function a(e){asyncGeneratorStep$1(o,n,r,a,s,"next",e)}function s(e){asyncGeneratorStep$1(o,n,r,a,s,"throw",e)}a(void 0)}))}}function _classCallCheck$2(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$2(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey$2(n.key),n)}}function _createClass$2(e,t,i){return t&&_defineProperties$2(e.prototype,t),i&&_defineProperties$2(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty$2(e,t,i){return(t=_toPropertyKey$2(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _inherits$1(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&&_setPrototypeOf$1(e,t)}function _getPrototypeOf$1(e){return(_getPrototypeOf$1=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf$1(e,t){return(_setPrototypeOf$1=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct$1(){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 _assertThisInitialized$1(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn$1(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 _assertThisInitialized$1(e)}function _createSuper$1(e){var t=_isNativeReflectConstruct$1();return function(){var i,n=_getPrototypeOf$1(e);if(t){var r=_getPrototypeOf$1(this).constructor;i=Reflect.construct(n,arguments,r)}else i=n.apply(this,arguments);return _possibleConstructorReturn$1(this,i)}}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf$1(e)););return e}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,i){var n=_superPropBase(e,t);if(n){var r=Object.getOwnPropertyDescriptor(n,t);return r.get?r.get.call(arguments.length<3?e:i):r.value}},_get.apply(this,arguments)}function _slicedToArray$1(e,t){return _arrayWithHoles$1(e)||_iterableToArrayLimit$1(e,t)||_unsupportedIterableToArray$1(e,t)||_nonIterableRest$1()}function _toConsumableArray$1(e){return _arrayWithoutHoles$1(e)||_iterableToArray$1(e)||_unsupportedIterableToArray$1(e)||_nonIterableSpread$1()}function _arrayWithoutHoles$1(e){if(Array.isArray(e))return _arrayLikeToArray$1(e)}function _arrayWithHoles$1(e){if(Array.isArray(e))return e}function _iterableToArray$1(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray$1(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$1(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?_arrayLikeToArray$1(e,t):void 0}}function _arrayLikeToArray$1(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function _nonIterableSpread$1(){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 _nonIterableRest$1(){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 _toPrimitive$2(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey$2(e){var t=_toPrimitive$2(e,"string");return"symbol"==typeof t?t:String(t)}var EleName="xg-video",simdCanused=!1;try{simdCanused=WebAssembly&&WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]))}catch(e){}var decodeCapacity={preloadDecoder:!1,reuseWasmDecoder:!0,reuseMseForAudio:!1,preciseSeek:0,h264WithWebcodec:!1,lowDecodeThreshold:100,wasmFallbackToAsm:!1,audioWithMse:!0,canUseThreadMode:!1,disabledWhenErrorOccur:!0,disabledDuration:43200,evaluateVVCount:0,disabledByLowdecodePrecent:.5,maxDecodeOnceWasm:simdCanused?6:8,maxDecodeOnceFirstTime:8,maxDecodeOnceWebcodec:20,maxDecoderThreads:navigator.hardwareConcurrency>=6?6:navigator.hardwareConcurrency};function getEleName(){return EleName}function setEleName(e){EleName=e}function setDecodeCapacity(e){decodeCapacity=Object.assign({},decodeCapacity,e)}function getDecodeCapacaity(){return decodeCapacity}function getDecoderUrls(){var e="undefined"!=typeof customElements&&customElements.get(EleName);return e?{H264_DECODER_URL:e.h264Url,ASM_H264_DECODER_URL:e.h264AsmUrl,H265_DECODER_URL:e.h265Url,H265_THREAD_DECODER_URL:e.h265ThreadUrl,H265_SIMD_DECODER_URL:e.h265SimdUrl,ASM_H265_DECODER_URL:e.h265AsmUrl,H266_DECODER_URL:e.h266Url,H266_SIMD_DECODER_URL:e.h266SimdUrl,H266_THREAD_DECODER_URL:e.h266PthreadUrl,H266_SIMD_THREAD_DECODER_URL:e.h266SimdPthreadUrl}:{}}function simdSupported(){if("undefined"==typeof customElements)return!1;var e=customElements.get(EleName);return simdCanused&&Boolean(null==e?void 0:e.h265SimdUrl)}function threadSupported(){if("undefined"==typeof customElements)return!1;var e=customElements.get(EleName);return"undefined"!=typeof SharedArrayBuffer&&Boolean(null==e?void 0:e.h265ThreadUrl)}var _softDecodeSupport=!1;try{var _localStorage,_localStorage$getItem;_softDecodeSupport="1"===(null===(_localStorage=localStorage)||void 0===_localStorage||null===(_localStorage$getItem=_localStorage.getItem)||void 0===_localStorage$getItem?void 0:_localStorage$getItem.call(_localStorage,"_sds"))}catch(e){}function softDecodeSupported(){if("undefined"==typeof customElements)return!1;if(_softDecodeSupport)return!0;var e=!1,t=!1;try{var i=new(window.AudioContext||window.webkitAudioContext);i.close(),i=null,e=!0}catch(e){}try{for(var n=document.createElement("canvas"),r=["webgl","experimental-webgl","moz-webgl","webkit-3d"],o=0;o<r.length;o++){var a=n.getContext(r[o]);if(a){a=null,n=null,t=!0;break}}_softDecodeSupport=e&&t&&"undefined"!=typeof WebAssembly,localStorage.setItem("_sds",_softDecodeSupport?1:0)}catch(e){}return _softDecodeSupport}function getDeviceCapacity(){return{simd:simdCanused,thread:threadSupported(),nbCpu:navigator.hardwareConcurrency}}var vv=0,lowdecodeVV=0,lowdecodePercent=0,disabledHevc=!1;function updateVV(){vv++}function getVV(){return vv}function updateLowdecodeVV(){lowdecodeVV++}function getLowdecodeVV(){return lowdecodeVV}function getLowdecodePercent(){return lowdecodePercent}function _getDisabledByEvaluateVV(){return!!disabledHevc||0!==getDecodeCapacaity().evaluateVVCount&&(vv===getDecodeCapacaity().evaluateVVCount&&(lowdecodePercent=lowdecodeVV/vv),lowdecodePercent>=getDecodeCapacaity().disabledByLowdecodePrecent&&(disabledHevc=!0),disabledHevc)}function persistenceDisabledStatus(e){localStorage.setItem("xgv_dis",e),2===e&&localStorage.setItem("xgv_dist",(new Date).getTime())}function getDisabledStatus(){if(!0===_getDisabledByEvaluateVV())return!0;var e=localStorage.getItem("xgv_dis");if(!e)return!1;if("1"===e)return!0;if("2"===e){var t=localStorage.getItem("xgv_dist")||0;if(t=Number(t),((new Date).getTime()-t)/1e3<getDecodeCapacaity().disabledDuration)return!0;cleanDisabledStatus()}}function cleanDisabledStatus(){localStorage.removeItem("xgv_dist"),localStorage.removeItem("xgv_dis")}var AnalyseDots={FIRST_DATA:1,AUDIO_MSE_OPEN_START:2,AUDIO_MSE_OPEND:3,AUDIO_FIRSTTIME_APPENDED:4,AUDIO_READY:5,WASM_WORKER_INIT:6,WASM_WORKER_READY:7,FIRST_FRAME_TODECODE:8,VIDEO_READY:9,FIRST_FRAME:10,WAITIGN:11,SEEKING:12,SEEKED:13},AnalyseDotsFlat=Object.entries(AnalyseDots),Analyse=function(){function e(){_classCallCheck$2(this,e),_defineProperty$2(this,"_dot",[]),_defineProperty$2(this,"_currentLowDecodeCount",0)}return _createClass$2(e,[{key:"getBootStats",value:function(){var e,t=(null===(e=this._dot[0])||void 0===e?void 0:e.dot)||0;return this._dot.map((function(e){return{action:AnalyseDotsFlat.filter((function(t){return t[1]===e.action}))[0][1],dot:parseInt(e.dot-t)}}))}},{key:"getStats",value:function(e){var t,i=this.getBootStats();return{bootStats:i,bitrate:Math.abs(e.bitrate/1e3),decodeFps:e.decodeFps,fps:e.fps,playbackRate:e.playbackRate,firstframe:null===(t=i.filter((function(e){return 10===e.action}))[0])||void 0===t?void 0:t.dot,width:e.videoWidth,height:e.videoHeight,decoderMode:e.decoderMode,vv:getVV(),lowdecodeVV:getLowdecodeVV(),h265FailureRate:Number((100*getLowdecodePercent()).toFixed(2)),currentLowDecodeCount:this._currentLowDecodeCount}}},{key:"seekElapses",value:function(){for(var e=this.getBootStats(),t=[],i=0,n=0,r=e.length;n<r;n++){var o=e[n];o.action===AnalyseDots.SEEKING&&(i=o.dot),o.action===AnalyseDots.SEEKED&&t.push(o.dot-i)}return t}},{key:"addFirstData",value:function(){this._dot.push({action:AnalyseDots.FIRST_DATA,dot:this._getTimestap()})}},{key:"addAudioBoundMedia",value:function(){this._dot.push({action:AnalyseDots.AUDIO_BOUND_MEDIA,dot:this._getTimestap()})}},{key:"addAudioMseOpenStart",value:function(){this._dot.push({action:AnalyseDots.AUDIO_MSE_OPEN_START,dot:this._getTimestap()})}},{key:"addAudioMseOpend",value:function(){this._dot.push({action:AnalyseDots.AUDIO_MSE_OPEND,dot:this._getTimestap()})}},{key:"addAudioFirstTimeAppended",value:function(){this._dot.push({action:AnalyseDots.AUDIO_FIRSTTIME_APPENDED,dot:this._getTimestap()})}},{key:"addAudioReady",value:function(){this._dot.push({action:AnalyseDots.AUDIO_READY,dot:this._getTimestap()})}},{key:"addWasmInit",value:function(){this._dot.push({action:AnalyseDots.WASM_WORKER_INIT,dot:this._getTimestap()})}},{key:"addWasmReady",value:function(){this._dot.push({action:AnalyseDots.WASM_WORKER_READY,dot:this._getTimestap()})}},{key:"addFirstFrameToDecode",value:function(){this._dot.push({action:AnalyseDots.FIRST_FRAME_TODECODE,dot:this._getTimestap()})}},{key:"addVideoReady",value:function(){this._dot.push({action:AnalyseDots.VIDEO_READY,dot:this._getTimestap()})}},{key:"addFirstframe",value:function(){this._dot.push({action:AnalyseDots.FIRST_FRAME,dot:this._getTimestap()})}},{key:"addWaiting",value:function(){this._dot.push({action:AnalyseDots.WAITIGN,dot:this._getTimestap()})}},{key:"addSeeking",value:function(){this._dot.push({action:AnalyseDots.SEEKING,dot:this._getTimestap()})}},{key:"addSeeked",value:function(){this._dot.push({action:AnalyseDots.SEEKED,dot:this._getTimestap()})}},{key:"_getTimestap",value:function(){return performance.now()}},{key:"increaseLowDecodeCount",value:function(){this._currentLowDecodeCount++}},{key:"reset",value:function(){this._currentLowDecodeCount=0,this._dot=[]}}]),e}(),DevLogger=function(){function e(){var t=this;_classCallCheck$2(this,e);try{var i=/xgd=(\d)/.exec(document.cookie)||Boolean(localStorage.getItem("playerlog"));this._status=Boolean(i),this._level=i&&i[1]}catch(e){this._status=!1}["group","groupEnd","log","warn","error"].forEach((function(e){t[e]=function(i,n,r,o,a,s,A,u,c,d){var l;if(t._status){var h=i,_=[n,r,o,a,s,A,u,c,d].filter((function(e){return void 0!==e}));(l=console)[e].apply(l,["["+(new Date).toISOString()+"]["+h+"]"].concat(_toConsumableArray$1(_)))}}}))}return _createClass$2(e,[{key:"enable",get:function(){return this._status}},{key:"long",get:function(){return"2"===this._level}}]),e}(),logger=new DevLogger;function debounce(e,t){var i=Date.now(),n=null,r=!0;return function(){for(var o=arguments.length,a=new Array(o),s=0;s<o;s++)a[s]=arguments[s];var A=Date.now();r&&(i=Date.now(),r=!1,e.apply(void 0,a)),A-i>t?(i=A,e.apply(void 0,a)):(n&&window.clearTimeout(n),n=setTimeout((function(){e.apply(void 0,a)}),t))}}function getAvcc(e,t){if(e&&t){var i=new Uint8Array(e.byteLength+t.byteLength+11);i[0]=1,i[1]=e[1],i[2]=e[2],i[3]=e[3],i[4]=255,i[5]=225;var n=6;return i.set(new Uint8Array([e.byteLength>>>8&255,255&e.byteLength]),n),n+=2,i.set(e,n),i[n+=e.byteLength]=1,n++,i.set(new Uint8Array([t.byteLength>>>8&255,255&t.byteLength]),n),n+=2,i.set(t,n),i}}function promiseDelayed(){var e,t,i=new Promise((function(i,n){e=i,t=n}));return i.resolve=e,i.reject=t,i}var encodedJs$4="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHNoaW1JbXBvcnRTY3JpcHRzKHNyYyl7cmV0dXJuIGZldGNoKHNyYykudGhlbigoZnVuY3Rpb24oZSl7aWYoIWUub2spdGhyb3cgbmV3IEVycm9yKCJkZWNvZGVyIHVybCByZXR1cm5lZCAiK2Uuc3RhdHVzKyI6ICIrc3JjKTtyZXR1cm4gZS50ZXh0KCl9KSkudGhlbigoZnVuY3Rpb24odGV4dCl7c2VsZi5leHBvcnRzPXt9LGV2YWwodGV4dCksc2VsZi5tPWV4cG9ydHMubX0pKX1mdW5jdGlvbiBpc0ltcG9ydFNjcmlwdHNNb2R1bGVFcnJvcihlKXt2YXIgdD1lJiZlLm1lc3NhZ2U/ZS5tZXNzYWdlOiIiO3JldHVybi9pbXBvcnRTY3JpcHRzL2kudGVzdCh0KSYmL21vZHVsZS9pLnRlc3QodCl9dmFyIE1BWF9TVFJFQU1fQlVGRkVSX0xFTkdUSD01MjQyODgwLEJBVENIX0RFQ09ERV9TSVpFPTgsaW5pdFRzPTAsRW5hYmxlTG9nPSExLERlY29kZXI9ZnVuY3Rpb24oZSl7dGhpcy5pbml0ZWQ9ITEsdGhpcy5pbmZvSWQ9MCx0aGlzLnNlbGY9ZSx0aGlzLm1ldGE9ZS5tZXRhLHRoaXMudHM9MCx0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Z1bmN0aW9uKGUpe3ZhciB0PWUuZGF0YTtpZigiaW5pdCI9PT10Lm1zZ3x8InByZWxvYWQiPT09dC5tc2d8fGRlY29kZXIpc3dpdGNoKHQubXNnKXtjYXNlInByZWxvYWQiOmluaXQodC51cmwpLEJBVENIX0RFQ09ERV9TSVpFPXQuYmF0Y2hEZWNvZGVDb3VudDticmVhaztjYXNlImluaXQiOnNlbGYubWV0YT10Lm1ldGEsQkFUQ0hfREVDT0RFX1NJWkU9dC5iYXRjaERlY29kZUNvdW50LHQuZW5hYmxlTG9nJiYoRW5hYmxlTG9nPSEwKSxpbml0KHQudXJsKTticmVhaztjYXNlInVwZGF0ZW1ldGEiOnNlbGYubWV0YT10Lm1ldGEsZGVjb2Rlci51cGRhdGVNZXRhKHQubWV0YSk7YnJlYWs7Y2FzZSJpbml0RGVjb2RlciI6ZGVjb2Rlci5mcmFtZUxlbnNPZmZzZXQmJmRlY29kZXIuYmF0Y2hEZWNvZGUoITApLGRlY29kZXIuZmx1c2goKSxkZWNvZGVyLmRlY29kZSh0LmRhdGEpO2JyZWFrO2Nhc2UiZGVjb2RlIjpkZWNvZGVyLnN0b3JlQnVmZmVyKHQuZGF0YSx0LmluZm8pO2JyZWFrO2Nhc2UiZmx1c2giOmRlY29kZXIuZmx1c2goKTticmVhaztjYXNlImZpbmlzaF9mbGFnIjpzZWxmLnBvc3RNZXNzYWdlKHttc2c6IkJBVENIX0ZJTklTSF9GTEFHIn0pO2JyZWFrO2Nhc2UiZGVzdG9yeSI6ZGVjb2Rlci5kZXN0cm95KCl9fX0pKCk7Cg==",blob$4="undefined"!=typeof window&&window.Blob&&new Blob([atob(encodedJs$4)],{type:"text/javascript;charset=utf-8"});function WorkerWrapper$4(){var e=blob$4&&(window.URL||window.webkitURL).createObjectURL(blob$4);try{return e?new Worker(e,{}):new Worker("data:application/javascript;base64,"+encodedJs$4,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}var encodedJs$3="KGZ1bmN0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1bmN0aW9uKGUpe3NlbGYucG9zdE1lc3NhZ2Uoe21zZzoiSU5JVF9GQUlMRUQiLGxvZzplLm1lc3NhZ2V9KX0pKX1zZWxmLm9ubWVzc2FnZT1mdW5jdGlvbihlKXt2YXIgdD1lLmRhdGE7aWYodC5tc2cpe2lmKCJpbml0IiE9PXQubXNnJiYicHJlbG9hZCIhPT10Lm1zZyYmIWRlY29kZXIpcmV0dXJuO3N3aXRjaCh0Lm1zZyl7Y2FzZSJwcmVsb2FkIjppbml0KHQudXJsKTticmVhaztjYXNlImluaXQiOnNlbGYubWV0YT10Lm1ldGEsdC5lbmFibGVMb2cmJihFbmFibGVMb2c9ITApLGluaXQodC51cmwpO2JyZWFrO2Nhc2UidXBkYXRlbWV0YSI6c2VsZi5tZXRhPXQubWV0YSxkZWNvZGVyLnVwZGF0ZU1ldGEodC5tZXRhKTticmVhaztjYXNlImluaXREZWNvZGVyIjpkZWNvZGVyLmRlY29kZSh0LmRhdGEpO2JyZWFrO2Nhc2UiZGVjb2RlIjpkZWNvZGVyLmRlY29kZSh0LmRhdGEsdC5pbmZvKTticmVhaztjYXNlImZsdXNoIjpkZWNvZGVyLmZsdXNoKCk7YnJlYWs7Y2FzZSJmaW5pc2hfZmxhZyI6c2VsZi5wb3N0TWVzc2FnZSh7bXNnOiJCQVRDSF9GSU5JU0hfRkxBRyJ9KTticmVhaztjYXNlImRlc3RvcnkiOmRlY29kZXIuZGVzdHJveSgpfX1lbHNlIHNlbGYucG9zdE1lc3NhZ2Uoe21zZzoiRVJST1I6aW52YWxpZCBtZXNzYWdlIn0pfX0pKCk7Cg==",blob$3="undefined"!=typeof window&&window.Blob&&new Blob([atob(encodedJs$3)],{type:"text/javascript;charset=utf-8"});function WorkerWrapper$3(){var e=blob$3&&(window.URL||window.webkitURL).createObjectURL(blob$3);try{return e?new Worker(e,{}):new Worker("data:application/javascript;base64,"+encodedJs$3,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}var encodedJ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0pKX1zZWxmLm9ubWVzc2FnZT1mdW5jdGlvbihlKXt2YXIgdD1lLmRhdGE7aWYoImluaXQiPT09dC5tc2d8fCJwcmVsb2FkIj09PXQubXNnfHxkZWNvZGVyKXN3aXRjaCh0Lm1zZyl7Y2FzZSJwcmVsb2FkIjppbml0KHQudXJsLHttYXhUaHJlYWRzOnQubWF4VGhyZWFkc30pLEJBVENIX0RFQ09ERV9TSVpFPXQuYmF0Y2hEZWNvZGVDb3VudDticmVhaztjYXNlImluaXQiOnNlbGYubWV0YT10Lm1ldGEsQkFUQ0hfREVDT0RFX1NJWkU9dC5iYXRjaERlY29kZUNvdW50LHQuZW5hYmxlTG9nJiYoRW5hYmxlTG9nPSEwKSxpbml0KHQudXJsLHttYXhUaHJlYWRzOnQubWF4VGhyZWFkc30pO2JyZWFrO2Nhc2UidXBkYXRlbWV0YSI6c2VsZi5tZXRhPXQubWV0YSxkZWNvZGVyLnVwZGF0ZU1ldGEodC5tZXRhKTticmVhaztjYXNlImluaXREZWNvZGVyIjpkZWNvZGVyLmZyYW1lTGVuc09mZnNldCYmZGVjb2Rlci5iYXRjaERlY29kZSghMCksZGVjb2Rlci5mbHVzaCgpLGRlY29kZXIuZGVjb2RlKHQuZGF0YSk7YnJlYWs7Y2FzZSJkZWNvZGUiOmRlY29kZXIuc3RvcmVCdWZmZXIodC5kYXRhLHQuaW5mbyk7YnJlYWs7Y2FzZSJmbHVzaCI6ZGVjb2Rlci5mbHVzaCghIXQuZHJvcENhY2hlKTticmVhaztjYXNlImZpbmlzaF9mbGFnIjpzZWxmLnBvc3RNZXNzYWdlKHttc2c6IkJBVENIX0ZJTklTSF9GTEFHIn0pO2JyZWFrO2Nhc2UiZGVzdG9yeSI6ZGVjb2Rlci5kZXN0cm95KCl9fX0pKCk7Cg==",blob$2="undefined"!=typeof window&&window.Blob&&new Blob([atob(encodedJs$2)],{type:"text/javascript;charset=utf-8"});function WorkerWrapper$2(){var e=blob$2&&(window.URL||window.webkitURL).createObjectURL(blob$2);try{return e?new Worker(e,{}):new Worker("data:application/javascript;base64,"+encodedJs$2,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}var encodedJs$1="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHNoaW1JbXBvcnRTY3JpcHRzKHNyYyl7cmV0dXJuIGZldGNoKHNyYykudGhlbigoZnVuY3Rpb24oZSl7aWYoIWUub2spdGhyb3cgbmV3IEVycm9yKCJkZWNvZGVyIHVybCByZXR1cm5lZCAiK2Uuc3RhdHVzKyI6ICIrc3JjKTtyZXR1cm4gZS50ZXh0KCl9KSkudGhlbigoZnVuY3Rpb24odGV4dCl7c2VsZi5leHBvcnRzPXt9LGV2YWwodGV4dCksc2VsZi5tPWV4cG9ydHMubX0pKX1mdW5jdGlvbiBpc0ltcG9ydFNjcmlwdHNNb2R1bGVFcnJvcihlKXt2YXIgdD1lJiZlLm1lc3NhZ2U/ZS5tZXNzYWdlOiIiO3JldHVybi9pbXBvcnRTY3JpcHRzL2kudGVzdCh0KSYmL21vZHVsZS9pLnRlc3QodCl9dmFyIE1BWF9TVFJFQU1fQlVGRkVSX0xFTkdUSD0xMDQ4NTc2LGluaXRUcz0wLERlY29kZXI9ZnVuY3Rpb24oZSl7dGhpcy5pbml0ZWQ9ITEsdGhpcy5zZWxmPWUsdGhpcy5tZXRhPWUubWV0YSx0aGlzLmluZm9saXN0PVtdLGUucGFyX2Jyb2Fkd2F5T25Ccm9hZHdheUluaXRlZD10aGlzLmJyb2Fkd2F5T25Ccm9hZHdheUluaXRlZC5iaW5kKHRoaXMpLGUucGFyX2Jyb2Fkd2F5T25QaWN0dXJlRGVjb2RlZD10aGlzLmJyb2Fkd2F5T25QaWN0dXJlRGVjb2RlZC5iaW5kKHRoaXMpfSxkZWNvZGVyO2Z1bmN0aW9uIG9uUG9zdFJ1bigpeyhkZWNvZGVyPW5ldyBEZWNvZGVyKHRoaXMpKS5pbml0KCl9RGVjb2Rlci5w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1ldGEpO2JyZWFrO2Nhc2UiaW5pdERlY29kZXIiOmRlY29kZXIuZGVjb2RlKHQuZGF0YSk7YnJlYWs7Y2FzZSJkZWNvZGUiOmRlY29kZXIuZGVjb2RlKHQuZGF0YSx0LmluZm8pO2JyZWFrO2Nhc2UiZmluaXNoX2ZsYWciOnNlbGYucG9zdE1lc3NhZ2Uoe21zZzoiQkFUQ0hfRklOSVNIX0ZMQUcifSk7YnJlYWs7Y2FzZSJkZXN0b3J5IjpkZWNvZGVyLmRlc3Ryb3koKX19fSkoKTsK",blob$1="undefined"!=typeof window&&window.Blob&&new Blob([atob(encodedJs$1)],{type:"text/javascript;charset=utf-8"});function WorkerWrapper$1(){var e=blob$1&&(window.URL||window.webkitURL).createObjectURL(blob$1);try{return e?new Worker(e,{}):new Worker("data:application/javascript;base64,"+encodedJs$1,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}var ele,DecoderCache=function(){function e(){_classCallCheck$2(this,e),_defineProperty$2(this,"_queue",[]),_defineProperty$2(this,"_pendingDecoder",null),_defineProperty$2(this,"TAG","DecoderCache")}return _createClass$2(e,[{key:"genDecoder",value:function(e){return this._initDecoder(e)}},{key:"_initDecoder",value:function(e){var t=this,i=getDecodeCapacaity(),n=i.preloadDecoder,r=i.maxDecodeOnceWasm;e=e||n;var o,a,s=getDecoderUrls(),A=s.H264_DECODER_URL,u=s.H265_SIMD_DECODER_URL,c=s.H265_DECODER_URL,d=s.H265_THREAD_DECODER_URL,l=s.H266_DECODER_URL,h=s.H266_SIMD_DECODER_URL,_=s.H266_THREAD_DECODER_URL,f=s.H266_SIMD_THREAD_DECODER_URL,m=simdSupported(),p=threadSupported()&&getDecodeCapacaity().canUseThreadMode;switch(e){case"h266":o=new WorkerWrapper$2,a=m&&p?f:m?h:p?_:l;break;case"h265":simdSupported()?(o=new WorkerWrapper$3,a=u):p?(o=new WorkerWrapper$4,a=d):(o=new WorkerWrapper$3,a=c);break;case"h264":o=new WorkerWrapper$1,a=A}if(!o)return Promise.resolve();var v=promiseDelayed();o.postMessage({msg:"preload",batchDecodeCount:r,url:a,maxThreads:getDecodeCapacaity().maxDecoderThreads}),this._pendingDecoder=o,o.id=Date.now()+parseInt(1e3*Math.random()),o.codecType=e,o.isHevc="h265"===e,o.using=!1,o.ready=!1,logger.log(this.TAG,"start init decoder worker, id=".concat(o.id,", codecType=").concat(o.codecType,", url=").concat(a));var E=function e(i){t._pendingDecoder=null;var n=i.data.msg;switch("DECODER_READY"!==n&&"INIT_FAILED"!==n||(o.removeEventListener("message",e),o.removeEventListener("error",y)),n){case"DECODER_READY":logger.log(t.TAG,"decoder worker inited!, id=",o.id,"cost:",i.data.cost),o.ready=!0,o.using||t._queue.push(o),v.resolve();break;case"INIT_FAILED":logger.log(t.TAG,"decoder worker init failed!",i.data.log),v.reject(i.data.log)}},y=function e(t){o.removeEventListener("message",E),o.removeEventListener("error",e),v.reject(null==t?void 0:t.message)};return o.addEventListener("message",E),o.addEventListener("error",y),v}},{key:"cacheDecoder",value:function(e){e.using=!1,e.ready=!0,e.id||(e.id=Date.now()+parseInt(1e3*Math.random())),this._queue.push(e),logger.log(this.TAG,"cache decoder, id=",e.id);var t=getDecodeCapacaity().preloadDecoder;if("h265"===t||"h266"===t){var i=this._queue.filter((function(e){return!e.using&&"h265"===e.codecType})),n=this._queue.filter((function(e){return!e.using&&"h266"===e.codecType}));1===i.length&&this.genDecoder("h265"),1===n.length&&this.genDecoder("h266")}}},{key:"getCachedDecoder",value:function(e){var t,i=this._queue.findIndex((function(t){return!t.using&&t.codecType===e}));if(-1!==i&&(t=this._queue.splice(i,1)[0]),!t&&this._pendingDecoder&&this._pendingDecoder.codecType===e&&(t=this._pendingDecoder,this._pendingDecoder=null),t)return t.using=!0,logger.warn(this.TAG,"get cached decoder, id=".concat(t.id,", ready=").concat(t.ready)),t}}]),e}(),decoderCache=new DecoderCache,VIDEO_EVENTS={WAITING:0,CANPLAY:1,PLAY:2,PLAYING:3,PAUSE:4,SEEKING:5,SEEKED:6,LOADEDDATA:7,LOADEDMETADATA:8,TIMEUPDATE:9,DURATION_CHANGE:10,VOLUME_CHANGE:11,PROGRESS:12,ERROR:13,ENDED:14,RESIZE:15,LOADSTART:16,DECODE_FPS:17,LOW_DECODE:18,LARGE_AV_GAP:19,FIRST_FRAME:20},VIDEO_EVENTS_ARR=["waiting","canplay","play","playing","pause","seeking","seeked","loadeddata","loadedmetadata","timeupdate","durationchange","volumechange","progress","error","ended","resize","loadstart","decodefps","lowdecode","largeavgap","firstframe"],Events={AUDIO:{AUDIO_READY:"audio_ready",AUDIO_NOT_ALLOWED_AUTOPLAY:"audio_not_allowed_autoplay",AUDIO_WAITING:"audio_waiting",AUDIO_SYNC_DTS:"audio_sync_dts"},VIDEO:{VIDEO_DECODER_INIT:"video_decode_init",VIDEO_READY:"video_ready",VIDEO_WAITING:"video_waiting",AUTO_RUN:"auto_run",DECODE_LOW_FPS:"decode_low_fps",UPDATE_VIDEO_FILLTYPE:"update_video_filltype",UPDATE_VIDEO_COVER_POSITION:"update_video_cover_position"},TIMELINE:{PLAY_EVENT:"play_event",SET_METADATA:"set_metadata",APPEND_CHUNKS:"append_chunks",START_RENDER:"start_render",DO_PLAY:"do_play",DO_PAUSE:"do_pause",DO_SEEK:"do_seek",SET_PLAYBACKRATE:"set_playbackrate",SYNC_DTS:"sync_dts",RESET_BASE_DTS:"reset_base_dts",UPDATE_VOLUME:"update_volume",SINGLE_TRACK:"single_track",DESTROY:"destroy",READY:"ready",UPDATE_GL_OPTIONS:"update_gl_options",SET_VIDEO_DURATION:"set_video_duration",SET_PLAY_MODE:"set_play_mode",UPDATE_CAPABILITY_LEVEL:"update_capability_level",INNER_DEGRADE:"inner_degrade",ADJUST_SEEK_TIME:"adjust_seek_time",CHASE_FRAME:"chase_frame",END_OF_STREAM:"end_of_stream",UPDATE_SEGMENT_END:"update_segment_end"},VIDEO_EVENTS:VIDEO_EVENTS,DECODE_EVENTS:{INIT:"init",READY:"decoderready",REMUX:"remux",INIT_FAILED:"initfailed",DATAREADY:"dataReady",PLAY_FAILED:"playfailed",FRAGMENT_END:"fragmentEnd",APPEND_VIDEO:"appendVideo",FIRST_FRAME:"firstFrame",DECODED:"decoded",RENDE_END:"rendeEnd",CHASE_VIDEO_FRAME:"chaseVideoFrame",CHASE_VIDEO_FRAME_END:"chaseVideoFrameEnd",CHASE_AUDIO_FRAME:"chaseAudioFrame",INIT_SEGMENT:"initSegment",MEDIA_SEGMENT:"mediaSegment",FRAME_MAX_COUNY:"frameMaxCount",FRAME_MIN_COUNY:"frameMinCount"}};function initBgSilenceAudio(){if(!document.querySelector("#hackAudioPP")){var e=document.createElement("div");e.innerHTML="<audio id='hackAudioPP'></audio>",document.body.appendChild(e);var t=e.children.item(0);t.controls=!1,t.preload="auto",t.innerHTML="<source src=".concat("data:audio/mpeg;base64,//uQxAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAACcQCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA//////////////////////////////////////////////////////////////////8AAABhTEFNRTMuMTAwA8MAAAAAAAAAABQgJAUHQQAB9AAAAnGMHkkIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//sQxAADgnABGiAAQBCqgCRMAAgEAH///////////////7+n/9FTuQsQH//////2NG0jWUGlio5gLQTOtIoeR2WX////X4s9Atb/JRVCbBUpeRUq//////////////////9RUi0f2jn/+xDECgPCjAEQAABN4AAANIAAAAQVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVQ==",' type="audio/mpeg"></source>'),t.muted=!0,t.loop=!0,t.play().catch((function(){}))}}function playSlienceAudio(){var e=ele||(ele=document.querySelector("#hackAudioPP"));e?!1===e.paused&&!1===e.muted||(e.muted=!1,e.play().catch((function(e){console.log("bgAudio: ",e.message)}))):initBgSilenceAudio()}function pauseSlienceAudio(){var e=ele||(ele=document.querySelector("#hackAudioPP"));e&&e.pause()}var webm="data:video/webm;base64,GkXfowEAAAAAAAAfQoaBAUL3gQFC8oEEQvOBCEKChHdlYm1Ch4EEQoWBAhhTgGcBAAAAAAAVkhFNm3RALE27i1OrhBVJqWZTrIHfTbuMU6uEFlSua1OsggEwTbuMU6uEHFO7a1OsghV17AEAAAAAAACkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmAQAAAAAAAEUq17GDD0JATYCNTGF2ZjU1LjMzLjEwMFdBjUxhdmY1NS4zMy4xMDBzpJBlrrXf3DCDVB8KcgbMpcr+RImIQJBgAAAAAAAWVK5rAQAAAAAAD++uAQAAAAAAADLXgQFzxYEBnIEAIrWcg3VuZIaFVl9WUDiDgQEj44OEAmJaAOABAAAAAAAABrCBsLqBkK4BAAAAAAAPq9eBAnPFgQKcgQAitZyDdW5khohBX1ZPUkJJU4OBAuEBAAAAAAAAEZ+BArWIQOdwAAAAAABiZIEgY6JPbwIeVgF2b3JiaXMAAAAAA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wAAAAIAAAABAAAADQAAAAEAAAABAAAADgAAAAIAAAABAAAADwAAAAEAAAABAAAAEAAAAAIAAAABAAAAEQAAAAEAAAABAAAAEgAAAAIAAAABAAAAFAAAAAEAAAABAAAAFQAAAAIAAAABAAAAFgAAAAEAAAABAAAAFwAAAAIAAAABAAAAGAAAAAEAAAABAAAAGQAAAAIAAAABAAAAGgAAAAEAAAABAAAAGwAAAAIAAAABAAAAHQAAAAEAAAABAAAAHgAAAAIAAAABAAAAHwAAAAQAAAABAAAA4HN0c3oAAAAAAAAAAAAAADMAAAAaAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAAAJAAAACQAAAAkAAACMc3RjbwAAAAAAAAAfAAAALAAAA1UAAANyAAADhgAAA6IAAAO+AAAD0QAAA+0AAAQAAAAEHAAABC8AAARLAAAEZwAABHoAAASWAAAEqQAABMUAAATYAAAE9AAABRAAAAUjAAAFPwAABVIAAAVuAAAFgQAABZ0AAAWwAAAFzAAABegAAAX7AAAGFwAAAGJ1ZHRhAAAAWm1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAALWlsc3QAAAAlqXRvbwAAAB1kYXRhAAAAAQAAAABMYXZmNTUuMzMuMTAw",oldIOS=function(){return"undefined"!=typeof navigator&&parseFloat(String((/CPU.*OS ([0-9_]{3,4})[0-9_]{0,1}|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent)||[0,""])[1]).replace("undefined","3_2").replace("_",".").replace("_",""))<10&&!window.MSStream},nativeWakeLock=function(){return"wakeLock"in navigator},NoSleep=function(){function e(){var t=this;_classCallCheck$2(this,e),this.enabled=!1,nativeWakeLock()?(this._wakeLock=null,this.handleVisibilityChange=function(){null!==t._wakeLock&&t.visible&&t.enable()},document.addEventListener("visibilitychange",this.handleVisibilityChange),document.addEventListener("fullscreenchange",this.handleVisibilityChange)):oldIOS()?this.noSleepTimer=null:(this.noSleepVideo=document.createElement("video"),this.noSleepVideo.setAttribute("playsinline",""),this._addSourceToVideo(this.noSleepVideo,"mp4",mp4),this._addSourceToVideo(this.noSleepVideo,"webm",webm),this.noSleepVideo.addEventListener("loadedmetadata",(function(){t.noSleepVideo&&(t.noSleepVideo.duration<=1?t.noSleepVideo.setAttribute("loop",""):(t.onTimeupdate=function(){t.noSleepVideo.currentTime>.5&&(t.noSleepVideo.currentTime=Math.random())},t.noSleepVideo.addEventListener("timeupdate",t.onTimeupdate)))})))}return _createClass$2(e,[{key:"_addSourceToVideo",value:function(e,t,i){var n=document.createElement("source");n.src=i,n.type="video/".concat(t),e.appendChild(n)}},{key:"visible",get:function(){return"visible"===document.visibilityState}},{key:"isEnabled",get:function(){return this.enabled}},{key:"enable",value:function(){var e,t=this;if(nativeWakeLock()&&this.visible)return navigator.wakeLock.request("screen").then((function(e){t._wakeLock=e,t.enabled=!0,t._wakeLock.addEventListener("release",(function(){}))})).catch((function(){t.enabled=!1}));if(oldIOS())return this.disable(),console.warn("\n NoSleep enabled for older iOS devices. This can interrupt\n active or long-running network requests from completing successfully.\n See https://github.com/richtr/NoSleep.js/issues/15 for more details.\n "),this.noSleepTimer=window.setInterval((function(){document.hidden||(window.location.href=window.location.href.split("#")[0],window.setTimeout(window.stop,0))}),15e3),this.enabled=!0,Promise.resolve();if(null!==(e=this.noSleepVideo)&&void 0!==e&&e.paused){var i=this.noSleepVideo.play();return i&&i.then((function(e){return t.enabled=!0,e})).catch((function(e){console.log("noSleep: ",e.message),t.enabled=!1}))}}},{key:"disable",value:function(){nativeWakeLock()?(this._wakeLock&&this._wakeLock.release(),this._wakeLock=null):oldIOS()?this.noSleepTimer&&(console.warn("\n NoSleep now disabled for older iOS devices.\n "),window.clearInterval(this.noSleepTimer),this.noSleepTimer=null):this.noSleepVideo.pause(),this.enabled=!1}},{key:"toPlay",value:function(){if(this.noSleepVideo&&this.noSleepVideo.paused){var e=performance.now();this.lastTs||(this.lastTs=e),e-this.lastTs>1e4&&(this.enable(),this.lastTs=e)}}},{key:"destroy",value:function(){this.disable(),this.handleVisibilityChange&&(document.removeEventListener("visibilitychange",this.handleVisibilityChange),document.removeEventListener("fullscreenchange",this.handleVisibilityChange)),this.onTimeupdate&&this.noSleepVideo.removeEventListener("timeupdate",this.onTimeupdate),this.noSleepVideo=null}}]),e}();function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var eventemitter3={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,i="~";function n(){}function r(e,t,i){this.fn=e,this.context=t,this.once=i||!1}function o(e,t,n,o,a){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new r(n,o||e,a),A=i?i+t:t;return e._events[A]?e._events[A].fn?e._events[A]=[e._events[A],s]:e._events[A].push(s):(e._events[A]=s,e._eventsCount++),e}function a(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function s(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(i=!1)),s.prototype.eventNames=function(){var e,n,r=[];if(0===this._eventsCount)return r;for(n in e=this._events)t.call(e,n)&&r.push(i?n.slice(1):n);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},s.prototype.listeners=function(e){var t=i?i+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,o=n.length,a=new Array(o);r<o;r++)a[r]=n[r].fn;return a},s.prototype.listenerCount=function(e){var t=i?i+e:e,n=this._events[t];return n?n.fn?1:n.length:0},s.prototype.emit=function(e,t,n,r,o,a){var s=i?i+e:e;if(!this._events[s])return!1;var A,u,c=this._events[s],d=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),d){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,o),!0;case 6:return c.fn.call(c.context,t,n,r,o,a),!0}for(u=1,A=new Array(d-1);u<d;u++)A[u-1]=arguments[u];c.fn.apply(c.context,A)}else{var l,h=c.length;for(u=0;u<h;u++)switch(c[u].once&&this.removeListener(e,c[u].fn,void 0,!0),d){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,t);break;case 3:c[u].fn.call(c[u].context,t,n);break;case 4:c[u].fn.call(c[u].context,t,n,r);break;default:if(!A)for(l=1,A=new Array(d-1);l<d;l++)A[l-1]=arguments[l];c[u].fn.apply(c[u].context,A)}}return!0},s.prototype.on=function(e,t,i){return o(this,e,t,i,!1)},s.prototype.once=function(e,t,i){return o(this,e,t,i,!0)},s.prototype.removeListener=function(e,t,n,r){var o=i?i+e:e;if(!this._events[o])return this;if(!t)return a(this,o),this;var s=this._events[o];if(s.fn)s.fn!==t||r&&!s.once||n&&s.context!==n||a(this,o);else{for(var A=0,u=[],c=s.length;A<c;A++)(s[A].fn!==t||r&&!s[A].once||n&&s[A].context!==n)&&u.push(s[A]);u.length?this._events[o]=1===u.length?u[0]:u:a(this,o)}return this},s.prototype.removeAllListeners=function(e){var t;return e?(t=i?i+e:e,this._events[t]&&a(this,t)):(this._events=new n,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=i,s.EventEmitter=s,e.exports=s}(eventemitter3);var eventemitter3Exports=eventemitter3.exports,EventEmitter=getDefaultExportFromCjs(eventemitter3Exports);function _iterableToArrayLimit(e,t){var i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var n,r,o,a,s=[],A=!0,u=!1;try{if(o=(i=i.call(e)).next,0===t){if(Object(i)!==i)return;A=!1}else for(;!(A=(n=o.call(i)).done)&&(s.push(n.value),s.length!==t);A=!0);}catch(e){u=!0,r=e}finally{try{if(!A&&null!=i.return&&(a=i.return(),Object(a)!==a))return}finally{if(u)throw r}}return s}}function _classCallCheck$1(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$1(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey$1(n.key),n)}}function _createClass$1(e,t,i){return t&&_defineProperties$1(e.prototype,t),i&&_defineProperties$1(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty$1(e,t,i){return(t=_toPropertyKey$1(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function _nonIterableSpread(){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 _nonIterableRest(){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 _toPrimitive$1(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey$1(e){var t=_toPrimitive$1(e,"string");return"symbol"==typeof t?t:String(t)}var TrackType={VIDEO:"video",AUDIO:"audio",METADATA:"metadata"},VideoCodecType={AV1:"av1",AVC:"avc",HEVC:"hevc"},AudioCodecType={AAC:"aac",G711PCMA:"g7110a",G711PCMU:"g7110m",OPUS:"opus"};function concatUint8Array(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];t=t.filter(Boolean);var n=new Uint8Array(t.reduce((function(e,t){return e+t.byteLength}),0)),r=0;return t.forEach((function(e){n.set(e,r),r+=e.byteLength})),n}function parse(e){if(!Array.isArray(e)){for(var t=[],i="",n=0;n<e.length;n++)n%2&&(i=e[n-1]+e[n],t.push(parseInt(i,16)),i="");return t}return e.map((function(e){return parseInt(e,16)}))}function Concat(e){for(var t=0,i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];n.forEach((function(e){t+=e.length}));var o=new e(t),a=0;return n.forEach((function(e){o.set(e,a),a+=e.length})),o}var Buffer$1=function(){function e(){_classCallCheck$1(this,e),this.buffer=new Uint8Array(0)}return _createClass$1(e,[{key:"write",value:function(){for(var e=this,t=arguments.length,i=new Array(t),n=0;n<t;n++)i[n]=arguments[n];i.forEach((function(t){t?e.buffer=Concat(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}(),UINT32_MAX=Math.pow(2,32)-1,MP4=function(){function e(){_classCallCheck$1(this,e)}return _createClass$1(e,null,[{key:"box",value:function(e){for(var t=arguments.length,i=new Array(t>1?t-1:0),n=1;n<t;n++)i[n-1]=arguments[n];var r=8+(i=i.filter(Boolean)).reduce((function(e,t){return e+t.byteLength}),0),o=new Uint8Array(r);o[0]=r>>24&255,o[1]=r>>16&255,o[2]=r>>8&255,o[3]=255&r,o.set(e,4);var a=8;return i.forEach((function(e){o.set(e,a),a+=e.byteLength})),o}},{key:"ftyp",value:function(t){return t.find((function(e){return e.type===TrackType.VIDEO&&e.codecType===VideoCodecType.HEVC}))?e.FTYPHEV1:e.FTYPAVC1}},{key:"initSegment",value:function(t){return concatUint8Array(e.ftyp(t),e.moov(t))}},{key:"pssh",value:function(t){var i=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],parse(t.kid),[0,0,0,0]));return e.box(e.types.pssh,i)}},{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 i=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(_toConsumableArray(t.map((function(t){return e.trak(t)}))),[i]))}return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale)].concat(_toConsumableArray(t.map((function(t){return e.trak(t)}))),[e.mvex(t)]))}},{key:"mvhd",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return e.box(e.types.mvhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,i>>24&255,i>>16&255,i>>8&255,255&i,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]))}},{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,i){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return 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,i>>24&255,i>>16&255,i>>8&255,255&i,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,n>>8&255,255&n,0,0,r>>8&255,255&r,0,0]))}},{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 i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,i>>24&255,i>>16&255,i>>8&255,255&i,t>>24&255,t>>16&255,t>>8&255,255&t,85,196,0,0]))}},{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===TrackType.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stbl(t))}},{key:"stbl",value:function(t){var i=[];return t&&t.ext&&t.ext.stss&&i.push(e.stss(t.ext.stss.entries)),e.box(e.types.stbl,e.stsd(t),e.STTS,i[0],e.STSC,e.STSZ,e.STCO)}},{key:"stsd",value:function(t){var i;return i="audio"===t.type?t.useEME&&t.enca?e.enca(t):t.codecType===AudioCodecType.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]),i)}},{key:"enca",value:function(t){var i=t.enca.channelCount,n=t.enca.sampleRate,r=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,i,0,16,0,0,0,0,n>>8&255,255&n,0,0]),o=e.esds(t.config),a=e.sinf(t.enca);return e.box(e.types.enca,r,o,a)}},{key:"encv",value:function(t){var i,n,r=t.sps.length>0?t.sps[0]:[],o=t.pps.length>0?t.pps[0]:[],a=t.width,s=t.height,A=t.sarRatio[0],u=t.sarRatio[1],c=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,a>>8&255,255&a,s>>8&255,255&s,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((i=(n=[1,r[1],r[2],r[3],255,225,r.length>>>8&255,255&r.length]).concat.apply(n,_toConsumableArray(r)).concat([1,o.length>>>8&255,255&o.length])).concat.apply(i,_toConsumableArray(o))),l=new Uint8Array([0,0,88,57,0,15,200,192,0,4,86,72]),h=e.sinf(t.encv),_=new Uint8Array([A>>24,A>>16&255,A>>8&255,255&A,u>>24,u>>16&255,u>>8&255,255&u]);return e.box(e.types.encv,c,e.box(e.types.avcC,d),e.box(e.types.btrt,l),h,e.box(e.types.pasp,_))}},{key:"schi",value:function(t){var i=new Uint8Array([]),n=e.tenc(t);return e.box(e.types.schi,i,n)}},{key:"tenc",value:function(t){var i=new Uint8Array([0,0,0,0,0,0,255&t.default_IsEncrypted,255&t.default_IV_size].concat(parse(t.default_KID)));return e.box(e.types.tenc,i)}},{key:"sinf",value:function(t){var i=new Uint8Array([]),n=new Uint8Array([t.data_format.charCodeAt(0),t.data_format.charCodeAt(1),t.data_format.charCodeAt(2),t.data_format.charCodeAt(3)]),r=new Uint8Array([0,0,0,0,99,101,110,99,0,1,0,0]),o=e.schi(t);return e.box(e.types.sinf,i,e.box(e.types.frma,n),e.box(e.types.schm,r),o)}},{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 i=t.codecType===VideoCodecType.HEVC,n=i?e.types.hvc1:e.types.avc1,r=i?e.hvcC(t):e.avcC(t),o=[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]),r];return i?o.push(e.box(e.types.fiel,new Uint8Array([1,0]))):t.sarRatio&&t.sarRatio.length>1&&o.push(e.pasp(t.sarRatio)),e.box.apply(e,[n].concat(o))}},{key:"avcC",value:function(t){var i,n,r,o=[],a=[];return t.sps.forEach((function(e){r=e.byteLength,o.push(r>>>8&255),o.push(255&r),o.push.apply(o,_toConsumableArray(e))})),t.pps.forEach((function(e){r=e.byteLength,a.push(r>>>8&255),a.push(255&r),a.push.apply(a,_toConsumableArray(e))})),e.box(e.types.avcC,new Uint8Array((i=(n=[1,o[3],o[4],o[5],255,224|t.sps.length]).concat.apply(n,o).concat([t.pps.length])).concat.apply(i,a)))}},{key:"hvcC",value:function(t){var i=t.hvcC;if(i instanceof ArrayBuffer||i instanceof Uint8Array)return i;var n,r=t.vps,o=t.sps,a=t.pps;if(i){var s=i.generalProfileCompatibilityFlags,A=i.generalConstraintIndicatorFlags,u=(r.length&&1)+(o.length&&1)+(a.length&&1);n=[1,i.generalProfileSpace<<6|i.generalTierFlag<<5|i.generalProfileIdc,s>>>24,s>>>16,s>>>8,s,A[0],A[1],A[2],A[3],A[4],A[5],i.generalLevelIdc,240,0,252,252|i.chromaFormatIdc,248|i.bitDepthLumaMinus8,248|i.bitDepthChromaMinus8,0,0,i.numTemporalLayers<<3|i.temporalIdNested<<2|3,u];var c=function(e){var t;n.push(e.length>>8,e.length),(t=n).push.apply(t,_toConsumableArray(e))};r.length&&(n.push(160,0,r.length),r.forEach(c)),o.length&&(n.push(161,0,o.length),o.forEach(c)),a.length&&(n.push(162,0,a.length),a.forEach(c))}else n=[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(n))}},{key:"pasp",value:function(t){var i=_slicedToArray(t,2),n=i[0],r=i[1];return e.box(e.types.pasp,new Uint8Array([n>>24,n>>16&255,n>>8&255,255&n,r>>24,r>>16&255,r>>8&255,255&r]))}},{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 i=t.length;return e.box(e.types.esds,new Uint8Array([0,0,0,0,3,23+i,0,0,0,4,15+i,64,21,0,6,0,0,0,218,192,0,0,218,192,5].concat([i]).concat(t).concat([6,1,2])))}},{key:"opus",value:function(t){var i=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]),n=t.config.length?e.dOps(t):[];return e.box(e.types.Opus,i,n)}},{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(_toConsumableArray(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(_toConsumableArray(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 i=e.tfhd(t.id),n=e.tfdt(t,t.baseMediaDecodeTime),r=0;if(t.isVideo&&t.videoSenc&&t.videoSenc.forEach((function(e){r+=8,e.subsamples&&e.subsamples.length&&(r+=2,r+=6*e.subsamples.length)})),t.videoSencLength=r,t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)){if(t.isVideoEncryption){if(t.isVideo){var o=e.saiz(t),a=e.saio(t),s=e.trun1(t),A=e.senc(t);return e.box(e.types.traf,i,n,o,a,s,A)}if(t.isAudioEncryption){var u=e.sbgp(),c=e.saiz(t),d=e.saio(t),l=e.senc(t),h=e.trun1(t);return e.box(e.types.traf,i,n,u,c,d,l,h)}var _=e.sbgp(),f=e.trun1(t);return e.box(e.types.traf,i,n,_,f)}if(t.isVideo){var m=e.trun1(t);return e.box(e.types.traf,i,n,m)}var p=e.sbgp(),v=e.saiz(t),E=e.saio(t),y=e.senc(t),g=e.trun1(t);return e.box(e.types.traf,i,n,p,v,E,y,g)}var b=e.sdtp(t);return e.box(e.types.traf,i,n,b,e.trun(t.samples,b.byteLength+76))}},{key:"sdtp",value:function(t){var i=new Buffer$1;return t.samples.forEach((function(e){i.write(new Uint8Array(t.isVideo?[e.keyframe?32:16]:[16]))})),e.box(e.types.sdtp,this.extension(0,0),i.buffer)}},{key:"trun1",value:function(t){var i=new Buffer$1,n=Buffer$1.writeUint32(t.samples.length),r=null;if(t.isVideo){var o=t.videoSencLength;r=Buffer$1.writeUint32(16*t.samples.length+o+149),!t.isVideoEncryption&&t.isAudioEncryption&&(r=Buffer$1.writeUint32(16*t.samples.length+92))}else{var a=12*t.samples.length+124;t.isAudioEncryption&&(a=12*t.samples.length+8*t.audioSenc.length+177),r=Buffer$1.writeUint32(a)}return t.samples.forEach((function(e){i.write(Buffer$1.writeUint32(e.duration)),i.write(Buffer$1.writeUint32(e.size)),i.write(Buffer$1.writeUint32(e.keyframe?33554432:65536)),t.isVideo&&i.write(Buffer$1.writeUint32(e.cts?e.cts:0))})),e.box(e.types.trun,this.extension(0,t.flags),n,r,i.buffer)}},{key:"senc",value:function(t){var i=new Buffer$1,n=t.samples.length,r=t.isVideo?16:8,o=t.isVideo?2:0,a=[],s=0;return t.isVideo?(a=t.videoSenc,s=t.videoSencLength):a=t.audioSenc,s=s||r*n,i.write(Buffer$1.writeUint32(16+s),e.types.senc,this.extension(0,o)),i.write(Buffer$1.writeUint32(n)),a.forEach((function(e){for(var t=0;t<e.InitializationVector.length;t++)i.write(new Uint8Array([e.InitializationVector[t]]));e.subsamples&&e.subsamples.length&&(i.write(Buffer$1.writeUint16(e.subsamples.length)),e.subsamples.forEach((function(e){i.write(Buffer$1.writeUint16(e.BytesOfClearData)),i.write(Buffer$1.writeUint32(e.BytesOfProtectedData))})))})),i.buffer}},{key:"saio",value:function(t){var i=12*t.samples.length+141;!t.isVideo&&t.isAudioEncryption&&(i=149);var n=new Uint8Array([1,0,0,0,0,0,0,1,0,0,0,0,i>>24&255,i>>16&255,i>>8&255,255&i]);return e.box(e.types.saio,n)}},{key:"saiz",value:function(t){var i=t.samples.length,n=new Uint8Array([0,0,0,0,16,i>>24&255,i>>16&255,i>>8&255,255&i]);return e.box(e.types.saiz,n)}},{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,i){var n=Math.floor(i/(UINT32_MAX+1)),r=Math.floor(i%(UINT32_MAX+1));return t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)?e.box(e.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])):e.box(e.types.tfdt,new Uint8Array([1,0,0,0,n>>24,n>>16&255,n>>8&255,255&n,r>>24,r>>16&255,r>>8&255,255&r]))}},{key:"trun",value:function(t,i){var n=t.length,r=12+16*n;i+=8+r;var o=new Uint8Array(r);o.set([0,0,15,1,n>>>24&255,n>>>16&255,n>>>8&255,255&n,i>>>24&255,i>>>16&255,i>>>8&255,255&i],0);for(var a=0;a<n;a++){var s=t[a],A=s.duration,u=s.size,c=s.flag,d=void 0===c?{}:c,l=s.cts,h=void 0===l?0:l;o.set([A>>>24&255,A>>>16&255,A>>>8&255,255&A,u>>>24&255,u>>>16&255,u>>>8&255,255&u,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*a)}return e.box(e.types.trun,o)}},{key:"moovMP4",value:function(t){return e.box.apply(e,[e.types.moov,e.mvhd(t[0].duration,t[0].timescale)].concat(_toConsumableArray(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===TrackType.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stblMP4(t))}},{key:"stblMP4",value:function(t){var i=t.ext,n=[e.stsd(t),e.stts(i.stts),e.stsc(i.stsc),e.stsz(i.stsz),e.stco(i.stco)];return i.stss.length&&n.push(e.stss(i.stss)),i.ctts.length&&n.push(e.ctts(i.ctts)),e.box.apply(e,[e.types.stbl].concat(n))}},{key:"stts",value:function(t){var i=t.length,n=new Uint8Array(8*i),r=0;return t.forEach((function(e){var t=e.value,i=e.count;n.set([i>>24,i>>16&255,i>>8&255,255&i,t>>24,t>>16&255,t>>8&255,255&t],r),r+=8})),e.box(e.types.stts,concatUint8Array(new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i]),n))}},{key:"stsc",value:function(t){var i=t.length,n=new Uint8Array(12*i),r=0;return t.forEach((function(e){var t=e.firstChunk,i=e.samplesPerChunk,o=e.sampleDescIndex;n.set([t>>24,t>>16&255,t>>8&255,255&t,i>>24,i>>16&255,i>>8&255,255&i,o>>24,o>>16&255,o>>8&255,255&o],r),r+=12})),e.box(e.types.stsc,concatUint8Array(new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i]),n))}},{key:"stsz",value:function(t){var i=t.length,n=new Uint8Array(4*i),r=0;return t.forEach((function(e){n.set([e>>24,e>>16&255,e>>8&255,255&e],r),r+=4})),e.box(e.types.stsz,concatUint8Array(new Uint8Array([0,0,0,0,0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i]),n))}},{key:"stco",value:function(t){var i=t.length,n=new Uint8Array(4*i),r=0;return t.forEach((function(e){n.set([e>>24,e>>16&255,e>>8&255,255&e],r),r+=4})),e.box(e.types.stco,concatUint8Array(new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i]),n))}},{key:"stss",value:function(t){var i=t.length,n=new Uint8Array(4*i),r=0;return t.forEach((function(e){n.set([e>>24,e>>16&255,e>>8&255,255&e],r),r+=4})),e.box(e.types.stss,concatUint8Array(new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i]),n))}},{key:"ctts",value:function(t){var i=t.length,n=new Uint8Array(8*i),r=0;return t.forEach((function(e){var t=e.value,i=e.count;n.set([i>>24,i>>16&255,i>>8&255,255&i,t>>24,t>>16&255,t>>8&255,255&t],r),r+=8})),e.box(e.types.ctts,concatUint8Array(new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i]),n))}},{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 i=t.timescale,n=t.samples[0].duration,r=n*t.samples.length,o=t.samples[0].sampleOffset*n,a=8;t.samples.forEach((function(e){a+=e.size}));var s=0;if(t.isVideo){var A,u=0;t.videoSenc&&(A=t.videoSenc),t.isVideo&&A.forEach((function(e){u+=8,e.subsamples&&e.subsamples.length&&(u+=2,u+=6*e.subsamples.length)})),t.videoSencLength=u,s=a+141+16*t.samples.length+u,t.useEME&&t.isAudioEncryption&&!t.isVideoEncryption&&(s=a+16*t.samples.length+84)}else s=a+116+12*t.samples.length,t.useEME&&t.isAudioEncryption&&(s=a+169+12*t.samples.length+8*t.audioSenc.length);var c=new Uint8Array([0,0,0,0,0,0,0,255&t.id,i>>24&255,i>>16&255,i>>8&255,255&i,o>>24&255,o>>16&255,o>>8&255,255&o,0,0,0,0,0,0,0,1,0,s>>16&255,s>>8&255,255&s,r>>24&255,r>>16&255,r>>8&255,255&r,144,0,0,0]);return e.box(e.types.sidx,c)}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}}]),e}();_defineProperty$1(MP4,"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))),_defineProperty$1(MP4,"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])}),_defineProperty$1(MP4,"FTYPAVC1",MP4.box(MP4.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))),_defineProperty$1(MP4,"FTYPHEV1",MP4.box(MP4.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,104,101,118,49]))),_defineProperty$1(MP4,"DINF",MP4.box(MP4.types.dinf,MP4.box(MP4.types.dref,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1])))),_defineProperty$1(MP4,"VMHD",MP4.box(MP4.types.vmhd,new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))),_defineProperty$1(MP4,"SMHD",MP4.box(MP4.types.smhd,new Uint8Array([0,0,0,0,0,0,0,0]))),_defineProperty$1(MP4,"StblTable",new Uint8Array([0,0,0,0,0,0,0,0])),_defineProperty$1(MP4,"STTS",MP4.box(MP4.types.stts,MP4.StblTable)),_defineProperty$1(MP4,"STSC",MP4.box(MP4.types.stsc,MP4.StblTable)),_defineProperty$1(MP4,"STSZ",MP4.box(MP4.types.stsz,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]))),_defineProperty$1(MP4,"STCO",MP4.box(MP4.types.stco,MP4.StblTable));var Logger$1=function(){function e(t,i){_classCallCheck$1(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]"),e.disabled=i}return _createClass$1(e,[{key:"debug",value:function(){var t;if(!e.disabled){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];(t=console).debug.apply(t,[this._prefix].concat(n))}}},{key:"log",value:function(){var t;if(!e.disabled){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];(t=console).log.apply(t,[this._prefix].concat(n))}}},{key:"warn",value:function(){var t;if(!e.disabled){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];(t=console).warn.apply(t,[this._prefix].concat(n))}}},{key:"error",value:function(){var t;if(!e.disabled){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];(t=console).error.apply(t,[this._prefix].concat(n))}}},{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}();_defineProperty$1(Logger$1,"disabled",!0);var FMP4Remuxer=function(){function e(t,i,n){_classCallCheck$1(this,e),this.videoTrack=t,this.audioTrack=i;var r=/Chrome\/([^.]+)/.exec(navigator.userAgent);this.forceFirstIDR=r&&Number(r[1])<50,this.log=new Logger$1("FMP4Remuxer",!n||!n.openLog||!n.openLog)}return _createClass$1(e,[{key:"remux",value:function(){var e,t,i,n,r,o=arguments.length>0&&void 0!==arguments[0]&&arguments[0],a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=this.videoTrack,A=this.audioTrack,u=s.exist(),c=A.exist(),d=[];return o&&(a&&a.initMerge?(u&&d.push(this.videoTrack),c&&d.push(this.audioTrack),i=MP4.initSegment(d)):(u&&(e=MP4.initSegment([this.videoTrack])),c&&(t=MP4.initSegment([this.audioTrack])))),u&&s.hasSample()&&(n=this._remuxVideo()),c&&A.hasSample()&&(r=this._remuxAudio()),s.samples=[],A.samples=[],{initSegment:i,videoInitSegment:e,audioInitSegment:t,videoSegment:n,audioSegment:r}}},{key:"_remuxVideo",value:function(){var e=this.videoTrack;this.forceFirstIDR&&(e.samples[0].flag={dependsOn:2,isNonSyncSample:0});var t=e.samples,i=/av01/.test(e.codec),n=0;i?t.forEach((function(e){n+=e.data.byteLength})):t.forEach((function(e){n+=e.units.reduce((function(e,t){return e+t.byteLength}),0),n+=4*e.units.length}));var r=new Uint8Array(n);if(i)for(var o,a=0,s=t.length,A=0;a<s;a++)o=t[a],r.set(o.data,A),o.size=o.data.byteLength,A+=o.size;else for(var u,c=new DataView(r.buffer),d=function(e,i){i=t[l];var n=0;i.units.forEach((function(t){c.setUint32(e,t.byteLength),e+=4,r.set(t,e),e+=t.byteLength,n+=4+t.byteLength})),i.size=n,_=e,u=i},l=0,h=t.length,_=0;l<h;l++)d(_,u);var f=MP4.mdat(r);return concatUint8Array(MP4.moof([e]),f)}},{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,i){return t.set(i.data,e),e+i.size}),0);var i=MP4.mdat(t);return concatUint8Array(MP4.moof([e]),i)}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset()}}]),e}(),MP4Remuxer=function(){function e(t,i){_classCallCheck$1(this,e),this.videoTrack=t,this.audioTrack=i}return _createClass$1(e,[{key:"remux",value:function(e,t){this.videoTrack=e||this.videoTrack,this.audioTrack=t||this.audioTrack;var i,n,r=(null==e?void 0:e.exist())&&(null==e?void 0:e.hasSample()),o=(null==t?void 0:t.exist())&&(null==t?void 0:t.hasSample());return r&&o?i=this._remuxMix(e,t):r?i=this._remuxTrack(e):o&&(n=this._remuxTrack(t)),e&&(e.samples=[]),t&&(t.samples=[]),{videoSegment:i,audioSegment:n}}},{key:"_remuxMix",value:function(e,t){var i=MP4.ftyp([e,t]),n=this._remuxData(e,i.byteLength+8),r=n.mdatData,o=n.chunkOffset,a=this._remuxData(t,o).mdatData,s=MP4.mdat(concatUint8Array(r,a)),A=MP4.moovMP4([e,t]);return e.ext=void 0,t.ext=void 0,e.samples=[],t.samples=[],concatUint8Array(i,s,A)}},{key:"_remuxTrack",value:function(e){var t=MP4.ftyp([e]),i=this._remuxData(e,t.byteLength+8).mdatData,n=MP4.mdat(i),r=MP4.moovMP4([e]);return e.ext=void 0,e.samples=[],concatUint8Array(t,n,r)}},{key:"_remuxData",value:function(e,t){var i=this,n=e.type===TrackType.VIDEO,r=e.samples,o=0;n?r.forEach((function(e){o+=e.units.reduce((function(e,t){return e+t.byteLength}),0),o+=4*e.units.length})):o=r.reduce((function(e,t){return e+t.size}),0);for(var a,s=new Uint8Array(o),A=new DataView(s.buffer),u=e.ext={stts:[],stsc:[],stsz:[],stco:[],stss:[],ctts:[]},c=0,d=0,l=r.length,h=function(){a=r[_],d+=a.duration;var e=n?0:a.size;n?a.units.forEach((function(t){A.setUint32(c,t.byteLength),c+=4,s.set(t,c),c+=t.byteLength,e+=4+t.byteLength})):(s.set(a.data,c),c+=e),a.size=e,u.stsz.push(e),n&&i._fillCttsSamples(u.ctts,a.cts),i._fillSttsSamples(u.stts,a,r[_+1]),i._fillStcoSamples(u.stco,_,1,t),t+=e,n&&a.keyframe&&u.stss.push(_+1)},_=0;_<l;_++)h();return e.duration=d,this._fillStscSamples(u.stsc,l,1),{mdatData:s,chunkOffset:t}}},{key:"_fillSttsSamples",value:function(e,t,i){var n=e[e.length-1];i?n&&n.value===t.duration?n.count++:e.push({value:t.duration,count:1}):n?n.count++:e.push({value:40,count:1})}},{key:"_fillCttsSamples",value:function(e,t){var i=e[e.length-1];i&&i.value===t?i.count++:e.push({value:t,count:1})}},{key:"_fillStcoSamples",value:function(e,t,i,n){t%i||e.push(n)}},{key:"_fillStscSamples",value:function(e,t,i){if(t<=i)e.push({firstChunk:1,samplesPerChunk:t,sampleDescIndex:1});else{var n=Math.floor(t/i),r=t%i;e.push({firstChunk:1,samplesPerChunk:i,sampleDescIndex:1}),r&&e.push({firstChunk:n+1,samplesPerChunk:r,sampleDescIndex:1})}}}]),e}(),Alaw2lpcm=[-5504,-5248,-6016,-5760,-4480,-4224,-4992,-4736,-7552,-7296,-8064,-7808,-6528,-6272,-7040,-6784,-2752,-2624,-3008,-2880,-2240,-2112,-2496,-2368,-3776,-3648,-4032,-3904,-3264,-3136,-3520,-3392,-22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,-30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,-11008,-10496,-12032,-11520,-8960,-8448,-9984,-9472,-15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,-344,-328,-376,-360,-280,-264,-312,-296,-472,-456,-504,-488,-408,-392,-440,-424,-88,-72,-120,-104,-24,-8,-56,-40,-216,-200,-248,-232,-152,-136,-184,-168,-1376,-1312,-1504,-1440,-1120,-1056,-1248,-1184,-1888,-1824,-2016,-1952,-1632,-1568,-1760,-1696,-688,-656,-752,-720,-560,-528,-624,-592,-944,-912,-1008,-976,-816,-784,-880,-848,5504,5248,6016,5760,4480,4224,4992,4736,7552,7296,8064,7808,6528,6272,7040,6784,2752,2624,3008,2880,2240,2112,2496,2368,3776,3648,4032,3904,3264,3136,3520,3392,22016,20992,24064,23040,17920,16896,19968,18944,30208,29184,32256,31232,26112,25088,28160,27136,11008,10496,12032,11520,8960,8448,9984,9472,15104,14592,16128,15616,13056,12544,14080,13568,344,328,376,360,280,264,312,296,472,456,504,488,408,392,440,424,88,72,120,104,24,8,56,40,216,200,248,232,152,136,184,168,1376,1312,1504,1440,1120,1056,1248,1184,1888,1824,2016,1952,1632,1568,1760,1696,688,656,752,720,560,528,624,592,944,912,1008,976,816,784,880,848],Ulaw2lpcm=[-32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,-23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,-15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,-11900,-11388,-10876,-10364,-9852,-9340,-8828,-8316,-7932,-7676,-7420,-7164,-6908,-6652,-6396,-6140,-5884,-5628,-5372,-5116,-4860,-4604,-4348,-4092,-3900,-3772,-3644,-3516,-3388,-3260,-3132,-3004,-2876,-2748,-2620,-2492,-2364,-2236,-2108,-1980,-1884,-1820,-1756,-1692,-1628,-1564,-1500,-1436,-1372,-1308,-1244,-1180,-1116,-1052,-988,-924,-876,-844,-812,-780,-748,-716,-684,-652,-620,-588,-556,-524,-492,-460,-428,-396,-372,-356,-340,-324,-308,-292,-276,-260,-244,-228,-212,-196,-180,-164,-148,-132,-120,-112,-104,-96,-88,-80,-72,-64,-56,-48,-40,-32,-24,-16,-8,0,32124,31100,30076,29052,28028,27004,25980,24956,23932,22908,21884,20860,19836,18812,17788,16764,15996,15484,14972,14460,13948,13436,12924,12412,11900,11388,10876,10364,9852,9340,8828,8316,7932,7676,7420,7164,6908,6652,6396,6140,5884,5628,5372,5116,4860,4604,4348,4092,3900,3772,3644,3516,3388,3260,3132,3004,2876,2748,2620,2492,2364,2236,2108,1980,1884,1820,1756,1692,1628,1564,1500,1436,1372,1308,1244,1180,1116,1052,988,924,876,844,812,780,748,716,684,652,620,588,556,524,492,460,428,396,372,356,340,324,308,292,276,260,244,228,212,196,180,164,148,132,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,0],silenceFrame=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]);function _doubleCheckSampleRateIndex(e,t){var i=(7&e[0])<<1|e[1]>>>7;return i!==t?i:t}function _constructAdtsHeader(e,t){var i=e.sampleRateIndex,n=e.channelCount;i=_doubleCheckSampleRateIndex(e.config,i);var r=new Uint8Array(7);r[0]=255,r[1]=240,r[1]=1|r[1],r[2]=64,r[2]=r[2]|60&i<<2,r[2]=r[2]|1&n>>2,r[3]=192&n<<6;var o=t.byteLength+7;return r[3]=r[3]|3&o>>11,r[4]=255&o>>3,r[5]=224&o<<5,r[5]=31|r[5],r[6]=252,r}function packageAACToAdts(e,t){var i=new Uint8Array(t.data.byteLength+7),n=_constructAdtsHeader(e,t.data);return i.set(n),i.set(t.data,7),i}function concatAdts(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=0,n=0,r=e.length;n<r;n++)t&&n%t==0||(i+=e[n].byteLength);for(var o=new Uint8Array(i),a=0,s=0,A=e.length;s<A;s++)t&&s%t==0||(o.set(e[s],a),a+=e[s].byteLength);return o}function _decodeAlaw(e){for(var t=new Uint8Array(2*e.length),i=0,n=0;i<e.length;){var r=Alaw2lpcm[e[i]];if(void 0===r)throw new Error("can not decode g711 alaw data!");t[n]=255&r,t[n+1]=r>>8,i+=1,n+=2}return t}function _decodeUlaw(e){for(var t=new Uint8Array(2*e.length),i=0,n=0;i<e.length;){var r=Ulaw2lpcm[e[i]];if(void 0===r)throw new Error("can not decode g711 ulaw data!");t[n]=255&r,t[n+1]=r>>8,i+=1,n+=2}return t}function decodeG711(e,t){if("g7110a"===t)return _decodeAlaw(e);if("g7110m"===t)return _decodeUlaw(e);throw new Error("no supported format=".concat(t," for g711"))}function _getSampleCount(e,t,i){return e/t/i}function _uint16ToFloat32(e){return e>=32768?-(65536-e)/32768:e/32767}function createAudioBufferFromPcm(e,t,i,n,r){for(var o=_getSampleCount(t.byteLength,i,r),a=e.createBuffer(i,o,n),s=new DataView(t),A=0;A<i;A++)for(var u=a.getChannelData(A),c=void 0,d=0;d<o;d++)c=s.getUint16(d*(2*i)+2*A,!0),u[d]=_uint16ToFloat32(c);return{audioBuffer:a,duration:o/n}}function checkRefillFrame(e){var t=e[0].dts,i=e.filter((function(e){return e.dts===t})).length;if(!(i<=1))for(var n=0;n<i;n++)e[n].data=silenceFrame}var AudioHelper={decodeG711:decodeG711,createAudioBufferFromPcm:createAudioBufferFromPcm,packageAACToAdts:packageAACToAdts,concatAdts:concatAdts,checkRefillFrame:checkRefillFrame},TOLERANCE$2=.5,AudioTimeRange=function(){function e(t){_classCallCheck$2(this,e),this.TAG="AudioTimeRange",this._parent=t,this._buffers=[],this._duration=0,this._baseDts=0,this._lastBuffer=null}return _createClass$2(e,[{key:"isLive",get:function(){return this._parent.isLive}},{key:"duration",get:function(){return this._duration},set:function(e){this._duration=e}},{key:"buffered",get:function(){var e=this;if(this.isLive)return{length:this._duration?1:0,start:function(){return 0},end:function(){return e._duration}};var t=this._mergeBufferRanges();return{length:t.length,start:function(e){var i=t[e];return i?i.start:0},end:function(e){var i=t[e];return i?i.end:1/0}}}},{key:"resetDts",value:function(e){this._baseDts=e}},{key:"_transitionSamples",value:function(e){for(var t=e.numberOfChannels,i=e.length,n=512,r=0;r<t;r++){for(var o=e.getChannelData(r),a=0;a<n;a++)o[a]=o[a]*a/n;for(var s=i-n;s<i;s++)o[s]=o[s]*(i-s)/n}}},{key:"append",value:function(e,t,i,n){-1===this._baseDts&&(this._baseDts=i),this._transitionSamples(e);var r=(i-this._baseDts)/1e3,o=r+t,a={start:r,end:o,startDts:i,source:e,duration:t,delay:n};if(logger.log(this.TAG,"add new buffer range, startDts:".concat(i,", [").concat(a.start," , ").concat(a.end,"]")),!this._buffers.filter((function(e){return e.start===r})).length)return this._buffers.push(a),this.isLive&&(this._duration=o),a.start;console.error("音频重复")}},{key:"deletePassed",value:function(e){return this._buffers=this._buffers.filter((function(t){return t.start>=e})),this._buffers[0]}},{key:"canSeek",value:function(e){var t=this._buffers[this._buffers.length-1];return!!t&&!(t.start<e)}},{key:"_mergeBufferRanges",value:function(){var e=this._buffers.slice().sort((function(e,t){return e.start>t.start?1:-1})),t=e.length,i=[];if(!t)return i;for(var n={start:e[0].start,end:e[0].end},r=1;r<t;r++){var o=e[r];Math.abs(n.end-o.start)<TOLERANCE$2?n.end=o.end:(i.push(n),n={start:o.start,end:o.end})}return i.push(n),i}},{key:"getBuffer",value:function(e){if(this.isLive)return this._buffers.shift();var t=this._buffers.filter((function(t){return t.start<e+TOLERANCE$2&&t.end>e+TOLERANCE$2}))[0];return logger.log(this.TAG,"get audio buffer , currentTime:".concat(e," ,buffer:[").concat(t&&t.start," , ").concat(t&&t.end,"]")),0!==e||t?t:this._buffers[0]}},{key:"hasBuffer",value:function(){var e;return Boolean(null===(e=this._buffers)||void 0===e?void 0:e.length)}}]),e}(),BaseRender=function(e){_inherits$1(i,EventEmitter);var t=_createSuper$1(i);function i(e,n){var r;return _classCallCheck$2(this,i),(r=t.call(this))._config=e,r._parent=n,r._meta=null,r._ready=!1,r._isLive=!0,r._innerDegrade=!1,r._singleTrack=-1,r}return _createClass$2(i,[{key:"analyse",get:function(){return this._parent.analyse}},{key:"isLive",get:function(){return this._isLive}},{key:"innerDegrade",get:function(){return this._innerDegrade}},{key:"noAudio",get:function(){return 1===this._singleTrack||2===this._singleTrack}},{key:"noVideo",get:function(){return 3===this._singleTrack}},{key:"duration",get:function(){return this._timeRange.duration},set:function(e){this._timeRange&&(this._timeRange.duration=e)}},{key:"_bindEvents",value:function(){var e=this;this._parent.on(Events.TIMELINE.APPEND_CHUNKS,this._appendChunk.bind(this)),this._parent.on(Events.TIMELINE.RESET_BASE_DTS,this._resetDts.bind(this)),this._parent.on(Events.TIMELINE.START_RENDER,this._startRender.bind(this)),this._parent.on(Events.TIMELINE.DO_PLAY,this._doPlay.bind(this)),this._parent.on(Events.TIMELINE.DO_PAUSE,this._doPause.bind(this)),this._parent.on(Events.TIMELINE.DO_SEEK,this._doSeek.bind(this)),this._parent.on(Events.TIMELINE.DESTROY,this._destroy.bind(this)),this._parent.on(Events.TIMELINE.CHASE_FRAME,this._doChaseFrame.bind(this)),this._parent.on(Events.TIMELINE.SINGLE_TRACK,(function(t){e._singleTrack=t})),this._parent.on(Events.TIMELINE.SET_PLAY_MODE,(function(t){e._isLive="LIVE"===t})),this._parent.on(Events.TIMELINE.INNER_DEGRADE,(function(){e._innerDegrade=!0})),this._parent.on(Events.TIMELINE.SET_VIDEO_DURATION,(function(t){e.duration=t}))}}]),i}(),MEDIA_ERR_DECODE$1=3,ERROR_MSG={INIT_AUDIO_ERR:"create new AudioContext error",DECODE_ERR:"audio data decode error"},AudioRender=function(e){_inherits$1(r,BaseRender);var t,i,n=_createSuper$1(r);function r(e,t){var i;return _classCallCheck$2(this,r),_defineProperty$2(_assertThisInitialized$1(i=n.call(this,e,t)),"doPause",i._doPause),i.TAG="AudioRender",i._timeRange=new AudioTimeRange(_assertThisInitialized$1(i)),i._lastTimeLineTime=0,i._sampleQueue=[],i._source=null,i._audioCanAutoplay=!0,i._lastBuffer=null,i._inDecoding=!1,i._endOfStream=!1,i._delay=0,i._isSourceBufferEnd=-1,i._onSourceBufferEnded=i._onSourceBufferEnded.bind(_assertThisInitialized$1(i)),i._initAudioCtx(e.volume||.6),i._bindEvents(),i}return _createClass$2(r,[{key:"baseDts",get:function(){return this._timeRange._baseDts}},{key:"currentTime",get:function(){return this._audioCtx?this._lastTimeLineTime+this._audioCtx.currentTime:0}},{key:"preloadTime",get:function(){return this.isLive?1:0}},{key:"timescale",get:function(){return 1e3}},{key:"buffered",get:function(){return this._timeRange.buffered}},{key:"ctxState",get:function(){return this._audioCtx.state}},{key:"audioCanAutoplay",get:function(){return this._audioCanAutoplay}},{key:"resume",value:function(){if(this._audioCtx&&"suspended"===this._audioCtx.state)return this._audioCtx.resume().catch((function(e){}))}},{key:"canSeek",value:function(e){return this._timeRange.canSeek(e)}},{key:"_assembleErr",value:function(e){var t=new Error(e);return t.code=MEDIA_ERR_DECODE$1,t}},{key:"_emitTimelineEvents",value:function(e,t,i){var n,r;null===(n=this._parent)||void 0===n||null===(r=n.emit)||void 0===r||r.call(n,e,t,i)}},{key:"_initAudioCtx",value:function(e){var t=this;logger.log(this.TAG,"init audioCtx");var i=window.AudioContext||window.webkitAudioContext;return this._audioCtx=new i,this._audioCtx?(this._gainNode=this._audioCtx.createGain(),this._gainNode.gain.value=e,this._gainNode.connect(this._audioCtx.destination),this._audioCanAutoplay="running"===this._audioCtx.state,logger.log(this.TAG,"webAudio state:",this._audioCtx.state),initBgSilenceAudio(),this._bindAudioCtxEvent(),this._audioCtx.suspend()):(logger.warn(this.TAG,"create webaudio error!"),void setTimeout((function(){t._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,t._assembleErr(ERROR_MSG.INIT_AUDIO_ERR))})))}},{key:"_bindAudioCtxEvent",value:function(){var e=this;this._onStateChange=function(){e._audioCtx&&"running"===e._audioCtx.state&&e._ready&&e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PLAYING)},this._audioCtx.addEventListener("statechange",this._onStateChange)}},{key:"_bindEvents",value:function(){var e=this;_get(_getPrototypeOf$1(r.prototype),"_bindEvents",this).call(this),this._parent.on(Events.DECODE_EVENTS.CHASE_AUDIO_FRAME,this._doChaseFrame.bind(this)),this._parent.on(Events.TIMELINE.UPDATE_VOLUME,(function(t){e._gainNode&&(e._gainNode.gain.value=Number.isFinite(t)?t:1,e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.VOLUME_CHANGE))})),this._parent.on(Events.TIMELINE.END_OF_STREAM,(function(){var t;e._endOfStream=!0,e.noAudio||null!==(t=e._timeRange)&&void 0!==t&&t.hasBuffer()||null==e||e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ENDED)}))}},{key:"_appendChunk",value:function(e,t){if(!this.noAudio){this._meta||(this._meta=t,logger.warn(this.TAG,"audio set metadata",this._meta));var i=t.samples;if(i.length){this._sampleQueue=this._sampleQueue.concat(i),t.samples=[];var n=this._meta.codecType;if(this._inDecoding)return;switch(n){case AudioCodecType.AAC:this._decodeAACWrapper();break;case AudioCodecType.G711PCMA:case AudioCodecType.G711PCMU:this._decodeG711();break;default:logger.warn(this.TAG,"unsupported codec type:",n)}}}}},{key:"_resetDts",value:function(e,t){"video"!==t&&this._timeRange.resetDts(e)}},{key:"_doPlay",value:function(){this.noAudio||this._parent.seeking||(this._source||!this.currentTime?this.resume():this._startRender())}},{key:"_doPause",value:function(){this.noAudio||this._audioCtx.suspend()}},{key:"_clearSource",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this._source){if(this._source.removeEventListener("ended",this._onSourceBufferEnded),e)try{this._source.stop()}catch(e){}try{this._source.disconnect()}catch(e){}this._source=null}}},{key:"_reInitAudioCtx",value:function(e){var t=this;if(this._lastTimeLineTime=e,this._lastBuffer=null,this._lastAudioBufferInfo=null,this._delay=0,!this._ready||!this._audioCtx.currentTime)return Promise.resolve();var i=this._gainNode.gain.value;return this._audioCtx.close().then((function(){return t._audioCtx.removeEventListener("statechange",t._onStateChange),t._audioCtx=null,t._clearSource(),t._initAudioCtx(i)}))}},{key:"_doSeek",value:function(e){var t=this;this._reInitAudioCtx(e).then((function(){t._getAudioBuffer(!0)})).catch((function(e){}))}},{key:"_doChaseFrame",value:function(e){var t=this,i=e.position,n=this._timeRange.deletePassed(i);n&&(logger.log(this.TAG,"_doChaseFrame","startTime:",n.start,"buffeLength:",this.buffered.end(0)-n.start),this._reInitAudioCtx(n.start).then((function(){t._startRender(),t._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.TIMEUPDATE)})).catch((function(e){})))}},{key:"_decodeAACWrapper",value:(i=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,i,n,r,o,a,s,A,u,c;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this._sampleQueue.length,i=this._sampleQueue[0],n=this._sampleQueue[t-1],!((r=(n.dts-i.dts)/this.timescale)<1)){e.next=6;break}return e.abrupt("return");case 6:for(o=parseInt(r/3-1)||1,a=parseInt(t/o),s=[],A=0;A<o;A++)A<o-1?s.push(this._sampleQueue.slice(A*a,(A+1)*a)):s.push(this._sampleQueue.slice(A*a));return this._sampleQueue=[],this._inDecoding=!0,e.prev=12,e.next=15,this._decodeCycle(s);case 15:this._isLive||(u=this._timeRange._buffers,(c=u[u.length-1])&&this._emitTimelineEvents(Events.TIMELINE.UPDATE_SEGMENT_END,c.end)),e.next=21;break;case 18:e.prev=18,e.t0=e.catch(12),this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,this._assembleErr("ERROR_MSG.DECODE_ERR:".concat(e.t0&&e.t0.message)));case 21:this._inDecoding=!1;case 22:case"end":return e.stop()}}),e,this,[[12,18]])}))),function(){return i.apply(this,arguments)})},{key:"_decodeCycle",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var i;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=t.shift()){e.next=3;break}return e.abrupt("return");case 3:return e.next=5,this._decodeAAC(i);case 5:return e.next=7,this._decodeCycle(t);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"_decodeAAC",value:function(e){var t=this,i=e[0],n=0;AudioHelper.checkRefillFrame(e);var r=e.map((function(e){return AudioHelper.packageAACToAdts(t._meta,e)})),o=AudioHelper.concatAdts(r,0);return new Promise((function(e,r){var a=t._audioCtx.decodeAudioData(o.buffer,(function(r){if(t._timeRange){if(t._lastAudioBufferInfo&&t.isLive){var o=t._lastAudioBufferInfo,a=o.dts+o.duration;(n=i.dts-a)>1&&(t._timeRange._duration+=n/1e3,logger.log(t.TAG,"_decodeAAC","audio data dts is not continue, last end dts:",a,",now start Dts:",i.dts,"delay:",n))}t._lastAudioBufferInfo={duration:Math.floor(1e3*r.duration),dts:i.dts};var s=t._timeRange.append(r,r.duration,i.dts,n/1e3);if(!t._ready){var A=Math.abs(s+r.duration-t.currentTime)<.5;(t.isLive||!A)&&(t._ready=!0,logger.log(t.TAG,"_decodeAAC","set ready true start=",s),t.emit(Events.AUDIO.AUDIO_READY,s))}t._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PROGRESS),t._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.DURATION_CHANGE),e()}}),r);a.catch&&a.catch(r)}))}},{key:"_decodeG711",value:function(){var e=this._sampleQueue.length,t=this._sampleQueue[0];if(!((this._sampleQueue[e-1].dts-t.dts)/this.timescale<.5)){var i=this._sampleQueue.reduce((function(e,t){return e+=t.data.byteLength}),0),n=new Uint8Array(i),r=0,o=0;this._sampleQueue.forEach((function(e,t){0===t&&(r=e.dts),n.set(e.data,o),o+=e.data.byteLength})),this._sampleQueue=[];try{var a=this._meta,s=a.codecType,A=a.channelCount,u=a.sampleSize,c=a.sampleRate,d=AudioHelper.decodeG711(n,s),l=AudioHelper.createAudioBufferFromPcm(this._audioCtx,d.buffer,A,c,u/8),h=l.audioBuffer,_=l.duration,f=this._timeRange.append(h,_,r,0);this._ready||(this._ready=!0,logger.log(this.TAG,"_decodeG711","set ready true"),this.emit(Events.AUDIO.AUDIO_READY,f)),this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PROGRESS),this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.DURATION_CHANGE)}catch(e){this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,this._assembleErr("ERROR_MSG.DECODE_ERR:".concat(e&&e.message)))}}}},{key:"_onSourceBufferEnded",value:function(){this._isSourceBufferEnd=!0,logger.long&&logger.log(this.TAG,"source play end! currentTime:".concat(this.currentTime," , duration:").concat(this.duration)),this._startRender()}},{key:"_ajustSeekTime",value:function(e){var t=this._timeRange.getBuffer(e,0);t&&(logger.log(this.TAG,"ajust seek time to:",t.start),this._lastTimeLineTime=t.start)}},{key:"_getAudioBuffer",value:function(e){var t=this;if(this._timeRange){var i=this._timeRange.getBuffer(this._lastBuffer?this._lastBuffer.end:this.currentTime,0);return i?e?(this._ajustSeekTime(i.start),void this.emit(Events.AUDIO.AUDIO_READY)):i:(this._endOfStream||!this._isLive)&&this.currentTime-this.duration>-.5?(this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.TIMEUPDATE),void this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ENDED)):(this._ready=!1,this._audioCtx.suspend(),this.emit(Events.AUDIO.AUDIO_WAITING),void(e&&(this._onAudioReady||(this._onAudioReady=function(e){t._ajustSeekTime(e)}),this.removeListener(Events.AUDIO.AUDIO_READY,this._onAudioReady),this.once(Events.AUDIO.AUDIO_READY,this._onAudioReady))))}}},{key:"_startRender",value:function(e){if(!this.noAudio)if(!this._source||this._isSourceBufferEnd){if("video"===e&&this.isLive&&this._ready&&!this._isSourceBufferEnd)return console.log(this.TAG,"_startRender, audio currentTime",this.currentTime,"from:",e,"_isSourceBufferEnd:",this._isSourceBufferEnd,"ready:",this._ready),void this._doPlay();var t=this._getAudioBuffer();if(t){"suspended"===this._audioCtx.state&&(this._audioCtx.resume().catch((function(e){})),playSlienceAudio()),this._lastBuffer=t,this._clearSource();var i=this._audioCtx.createBufferSource();i.buffer=t.source,i.loop=!1,this._source=i,i.addEventListener("ended",this._onSourceBufferEnded),i.connect(this._gainNode),t.delay&&t.delay>.001&&(this._delay+=t.delay),this.startDts=t.startDts;try{this._isSourceBufferEnd=!1,i.start()}catch(e){}t.startDts&&this._emitTimelineEvents(Events.TIMELINE.SYNC_DTS,t.startDts)}}else this.resume()}},{key:"_destroy",value:function(){logger.log(this.TAG,"destroy audio..."),this._clearSource(!0),this._audioCtx&&"closed"!==this.ctxState&&this._audioCtx.close(),this._audioCtx=null,this._sampleQueue=null,this._timeRange=null,this._parent=null,this.removeAllListeners()}}]),r}();function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var e={},t=Object.prototype,i=t.hasOwnProperty,n=Object.defineProperty||function(e,t,i){e[t]=i.value},r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",s=r.toStringTag||"@@toStringTag";function A(e,t,i){return Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{A({},"")}catch(e){A=function(e,t,i){return e[t]=i}}function u(e,t,i,r){var o=t&&t.prototype instanceof l?t:l,a=Object.create(o.prototype),s=new D(r||[]);return n(a,"_invoke",{value:g(e,i,s)}),a}function c(e,t,i){try{return{type:"normal",arg:e.call(t,i)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function l(){}function h(){}function _(){}var f={};A(f,o,(function(){return this}));var m=Object.getPrototypeOf,p=m&&m(m(k([])));p&&p!==t&&i.call(p,o)&&(f=p);var v=_.prototype=l.prototype=Object.create(f);function E(e){["next","throw","return"].forEach((function(t){A(e,t,(function(e){return this._invoke(t,e)}))}))}function y(e,t){function r(n,o,a,s){var A=c(e[n],e,o);if("throw"!==A.type){var u=A.arg,d=u.value;return d&&"object"==typeof d&&i.call(d,"__await")?t.resolve(d.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(d).then((function(e){u.value=e,a(u)}),(function(e){return r("throw",e,a,s)}))}s(A.arg)}var o;n(this,"_invoke",{value:function(e,i){function n(){return new t((function(t,n){r(e,i,t,n)}))}return o=o?o.then(n,n):n()}})}function g(e,t,i){var n="suspendedStart";return function(r,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===r)throw o;return{value:void 0,done:!0}}for(i.method=r,i.arg=o;;){var a=i.delegate;if(a){var s=b(a,i);if(s){if(s===d)continue;return s}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if("suspendedStart"===n)throw n="completed",i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);n="executing";var A=c(e,t,i);if("normal"===A.type){if(n=i.done?"completed":"suspendedYield",A.arg===d)continue;return{value:A.arg,done:i.done}}"throw"===A.type&&(n="completed",i.method="throw",i.arg=A.arg)}}}function b(e,t){var i=t.method,n=e.iterator[i];if(void 0===n)return t.delegate=null,"throw"===i&&e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method)||"return"!==i&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+i+"' method")),d;var r=c(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,d;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function R(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function k(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,r=function t(){for(;++n<e.length;)if(i.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return r.next=r}}return{next:S}}function S(){return{value:void 0,done:!0}}return h.prototype=_,n(v,"constructor",{value:_,configurable:!0}),n(_,"constructor",{value:h,configurable:!0}),h.displayName=A(_,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,_):(e.__proto__=_,A(e,s,"GeneratorFunction")),e.prototype=Object.create(v),e},e.awrap=function(e){return{__await:e}},E(y.prototype),A(y.prototype,a,(function(){return this})),e.AsyncIterator=y,e.async=function(t,i,n,r,o){void 0===o&&(o=Promise);var a=new y(u(t,i,n,r),o);return e.isGeneratorFunction(i)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(v),A(v,s,"Generator"),A(v,o,(function(){return this})),A(v,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),i=[];for(var n in t)i.push(n);return i.reverse(),function e(){for(;i.length;){var n=i.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=k,D.prototype={constructor:D,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(R),!e)for(var t in this)"t"===t.charAt(0)&&i.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(i,n){return a.type="throw",a.arg=e,t.next=i,n&&(t.method="next",t.arg=void 0),!!n}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=i.call(o,"catchLoc"),A=i.call(o,"finallyLoc");if(s&&A){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!A)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),R(i),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var n=i.completion;if("throw"===n.type){var r=n.arg;R(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,i){return this.delegate={iterator:k(e),resultName:t,nextLoc:i},"next"===this.method&&(this.arg=void 0),d}},e}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function asyncGeneratorStep(e,t,i,n,r,o,a){try{var s=e[o](a),A=s.value}catch(e){return void i(e)}s.done?t(A):Promise.resolve(A).then(n,r)}function _asyncToGenerator(e){return function(){var t=this,i=arguments;return new Promise((function(n,r){var o=e.apply(t,i);function a(e){asyncGeneratorStep(o,n,r,a,s,"next",e)}function s(e){asyncGeneratorStep(o,n,r,a,s,"throw",e)}a(void 0)}))}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n)}}function _createClass(e,t,i){return t&&_defineProperties(e.prototype,t),i&&_defineProperties(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _inherits(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&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct(){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 _construct(e,t,i){return(_construct=_isNativeReflectConstruct()?Reflect.construct.bind():function(e,t,i){var n=[null];n.push.apply(n,t);var r=new(Function.bind.apply(e,n));return i&&_setPrototypeOf(r,i.prototype),r}).apply(null,arguments)}function _isNativeFunction(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function _wrapNativeSuper(e){var t="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(e){if(null===e||!_isNativeFunction(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return _construct(e,arguments,_getPrototypeOf(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(i,e)},_wrapNativeSuper(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(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 _assertThisInitialized(e)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var i,n=_getPrototypeOf(e);if(t){var r=_getPrototypeOf(this).constructor;i=Reflect.construct(n,arguments,r)}else i=n.apply(this,arguments);return _possibleConstructorReturn(this,i)}}function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:String(t)}var _ERR_CODE,Buffer=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"start",value:function(e){return e&&e.length?1===e.length&&e.end(0)-e.start(0)<1e-6||1===e.length&&e.start(0)<0?0:e.start(0):0}},{key:"end",value:function(e){return e&&e.length?1===e.length&&e.end(0)-e.start(0)<1e-6?0:e.end(e.length-1):0}},{key:"get",value:function(e){if(e)try{return e.buffered}catch(e){}}},{key:"buffers",value:function(e,t){if(!e||!e.length)return[];for(var i=[],n=0,r=e.length;n<r;n++){var o=i.length;if(o&&t){var a=i[o-1],s=a[1];if(e.start(n)-s<=t){var A=e.end(n);A>s&&(a[1]=A)}else i.push([e.start(n),e.end(n)])}else i.push([e.start(n),e.end(n)])}return i}},{key:"totalLength",value:function(e){return e&&e.length?e.reduce((function(e,t){return e+(t[1]-t[0])}),0):0}},{key:"info",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!t||!t.length)return{start:0,end:0,buffers:[]};for(var r=0,o=0,a=0,s=0,A=0,u=0,c=0,d=e.buffers(t,n),l=0,h=d.length;l<h;l++){var _=d[l];if(i+n>=_[0]&&i<=_[1])r=_[0],o=_[1],a=l;else{if(i+n<_[0]){s=_[0],A=_[1];break}i+n>_[1]&&(u=_[0],c=_[1])}}return{start:r,end:o,index:a,buffers:d,nextStart:s,nextEnd:A,prevStart:u,prevEnd:c,currentTime:i,behind:i-r,remaining:o?o-i:0,length:e.totalLength&&e.totalLength(d)}}},{key:"isBuffered",value:function(t,i){if(t){var n=e.get(t);if(null!=n&&n.length)for(var r=0;r<n.length;r++)if(i>=n.start(r)&&i<=n.end(r))return!0}return!1}}]),e}(),isBrowser="undefined"!=typeof window,ERR={MANIFEST:"manifest",NETWORK:"network",NETWORK_TIMEOUT:"network_timeout",NETWORK_FORBIDDEN:"network_forbidden",NETWORK_NOTFOUND:"network_notfound",NETWROK_RANGE_NOT_SATISFIABLE:"network_range_not_satisfiable",DEMUX:"demux",REMUX:"remux",MEDIA:"media",DRM:"drm",OTHER:"other",RUNTIME:"runtime",SUB_TYPES:{FLV:"FLV",HLS:"HLS",MP4:"MP4",FMP4:"FMP4",MSE_ADD_SB:"MSE_ADD_SB",MSE_APPEND_BUFFER:"MSE_APPEND_BUFFER",MSE_OTHER:"MSE_OTHER",MSE_FULL:"MSE_FULL",MSE_CHANGE_TYPE:"MSE_CHANGE_TYPE",OPTION:"OPTION",DASH:"DASH",LICENSE:"LICENSE",CUSTOM_LICENSE:"CUSTOM_LICENSE",MSE_HIJACK:"MSE_HIJACK",EME_HIJACK:"EME_HIJACK",SIDX:"SIDX",NO_CANPLAY_ERROR:"NO_CANPLAY_ERROR",BUFFERBREAK_ERROR:"BUFFERBREAK_ERROR",WAITING_TIMEOUT_ERROR:"WAITING_TIMEOUT_ERROR",MEDIA_ERR_ABORTED:"MEDIA_ERR_ABORTED",MEDIA_ERR_NETWORK:"MEDIA_ERR_NETWORK",MEDIA_ERR_DECODE:"MEDIA_ERR_DECODE",MEDIA_ERR_SRC_NOT_SUPPORTED:"MEDIA_ERR_SRC_NOT_SUPPORTED",MEDIA_ERR_CODEC_NOT_SUPPORTED:"MEDIA_ERR_CODEC_NOT_SUPPORTED",MEDIA_ERR_URL_EMPTY:"MEDIA_ERR_URL_EMPTY"}},ERR_CODE=(_defineProperty(_ERR_CODE={},ERR.MANIFEST,{HLS:1100,DASH:1200}),_defineProperty(_ERR_CODE,ERR.NETWORK,2100),_defineProperty(_ERR_CODE,ERR.NETWORK_TIMEOUT,2101),_defineProperty(_ERR_CODE,ERR.NETWORK_FORBIDDEN,2103),_defineProperty(_ERR_CODE,ERR.NETWORK_NOTFOUND,2104),_defineProperty(_ERR_CODE,ERR.NETWROK_RANGE_NOT_SATISFIABLE,2116),_defineProperty(_ERR_CODE,ERR.DEMUX,{FLV:3100,HLS:3200,MP4:3300,FMP4:3400,SIDX:3410}),_defineProperty(_ERR_CODE,ERR.REMUX,{FMP4:4100,MP4:4200}),_defineProperty(_ERR_CODE,ERR.MEDIA,{MEDIA_ERR_ABORTED:5101,MEDIA_ERR_NETWORK:5102,MEDIA_ERR_DECODE:5103,MEDIA_ERR_SRC_NOT_SUPPORTED:5104,MEDIA_ERR_CODEC_NOT_SUPPORTED:5105,MEDIA_ERR_URL_EMPTY:5106,MSE_ADD_SB:5200,MSE_APPEND_BUFFER:5201,MSE_OTHER:5202,MSE_FULL:5203,MSE_HIJACK:5204,MSE_CHANGE_TYPE:5205,EME_HIJACK:5301}),_defineProperty(_ERR_CODE,ERR.DRM,{LICENSE:7100,CUSTOM_LICENSE:7200}),_defineProperty(_ERR_CODE,ERR.OTHER,8e3),_defineProperty(_ERR_CODE,ERR.RUNTIME,{NO_CANPLAY_ERROR:9001,BUFFERBREAK_ERROR:9002,WAITING_TIMEOUT_ERROR:9003}),_ERR_CODE),StreamingError=function(e){_inherits(i,_wrapNativeSuper(Error));var t=_createSuper(i);function i(e,n,r,o,a){var s;return _classCallCheck(this,i),(s=t.call(this,a||(null==r?void 0:r.message))).errorType=e===ERR.NETWORK_TIMEOUT?ERR.NETWORK:e,s.originError=r,s.ext=o,s.errorCode=ERR_CODE[e][n]||ERR_CODE[e],s.errorMessage=s.message,s.errorCode||(s.errorType=ERR.OTHER,s.errorCode=ERR_CODE[s.errorType]),s}return _createClass(i,null,[{key:"create",value:function(e,t,n,r,o){return e instanceof i?e:(e instanceof Error&&(n=e,e=""),e||(e=ERR.OTHER),new i(e,t,n,r,o))}},{key:"network",value:function(e){var t;return new i(null!=e&&e.isTimeout?ERR.NETWORK_TIMEOUT:ERR.NETWORK,null,e instanceof Error?e:null,{url:null==e?void 0:e.url,response:null==e?void 0:e.response,httpCode:null==e||null===(t=e.response)||void 0===t?void 0:t.status})}}]),i}(),LogCacheLevel={DEBUG:1,LOG:2,WARN:3,ERROR:4},LOG_MAX_SIZE=204800,SIMPLE_TYPE=["Boolean","Number","String","Undefined","Null","Date","Object"],Logger=function(){function e(t,i){_classCallCheck(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]"),this.logCacheLevel=(null==i?void 0:i.logCacheLevel)||3,this.logMaxSize=(null==i?void 0:i.logMaxSize)||LOG_MAX_SIZE,this.logSize=0,this.logTextArray=[]}return _createClass(e,[{key:"debug",value:function(){for(var t,i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];this.logCache.apply(this,[LogCacheLevel.DEBUG].concat(n)),e.disabled||(t=console).debug.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"log",value:function(){for(var t,i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];this.logCache.apply(this,[LogCacheLevel.LOG].concat(n)),e.disabled||(t=console).log.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"warn",value:function(){for(var t,i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];this.logCache.apply(this,[LogCacheLevel.WARN].concat(n)),e.disabled||(t=console).warn.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"error",value:function(){for(var t,i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];this.logCache.apply(this,[LogCacheLevel.ERROR].concat(n)),e.disabled||(t=console).error.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"logCache",value:function(e){if(!(e<this.logCacheLevel)){var t="";try{for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];var o=n.map((function(e){return logable(e)}));t="[".concat(nowTime$1(),"]")+this._prefix+JSON.stringify(o)}catch(e){return}if(e>=this.logCacheLevel&&(this.logSize+=t.length,this.logTextArray.push(t)),this.logSize>this.logMaxSize){var a=this.logTextArray.shift();this.logSize-=a.length}}}},{key:"getLogCache",value:function(){var e=this.logTextArray.join("\n");return this.reset(),e}},{key:"reset",value:function(){this.logTextArray=[],this.logSize=0}},{key:"table",value:function(){var t;e.disabled||(console.group(this._prefix),(t=console).table.apply(t,arguments),console.groupEnd())}},{key:"setLogLevel",value:function(e){this.logCacheLevel=e}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();function nowTime$1(){return(new Date).toLocaleString()}function reduceDepth(e){if("object"!==_typeof(e))return e;var t=Object.prototype.toString.call(e).slice(8,-1);switch(t){case"Array":case"Uint8Array":case"ArrayBuffer":return t+"["+e.length+"]";case"Object":return"{}";default:return t}}function logable(e,t,i){i||(i=1),t||(t=2);var n={};if(!e||"object"!==_typeof(e))return e;var r=Object.prototype.toString.call(e).slice(8,-1);if(!SIMPLE_TYPE.includes(r))return r;if(!(i>t)){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i===t?n[o]=reduceDepth(e[o]):"object"===_typeof(e[o])?n[o]=logable(e[o],t,i+1):n[o]=e[o]);return n}}function createPublicPromise(){var e,t,i=new Promise((function(i,n){e=i,t=n}));return i.used=!1,i.resolve=function(){return i.used=!0,e.apply(void 0,arguments)},i.reject=function(){return i.used=!0,t.apply(void 0,arguments)},i}function nowTime(){try{return parseInt(performance.now(),10)}catch(e){return(new Date).getTime()}}_defineProperty(Logger,"disabled",!0);var SafeJSON={stringify:function(e){try{return JSON.stringify(e)}catch(e){return""}},parse:function(e){try{return JSON.parse(e)}catch(e){return}}};function getMediaSource(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];try{return isBrowser?e&&"undefined"!=typeof ManagedMediaSource?ManagedMediaSource:window.MediaSource:null}catch(e){}}function isMMS(e){return/ManagedMediaSource/gi.test(Object.prototype.toString.call(e))}function getTimeRanges(e){var t=[];if(e instanceof TimeRanges)for(var i=0;i<e.length;i++)t.push({start:e.start(i),end:e.end(i)});return t}var OP_NAME={APPEND:"appendBuffer",REMOVE:"removeBuffer",UPDATE_DURATION:"updateDuration"},MSE=function(){function e(t,i){var n=this;_classCallCheck(this,e),_defineProperty(this,"media",null),_defineProperty(this,"mediaSource",null),_defineProperty(this,"_openPromise",createPublicPromise()),_defineProperty(this,"_queue",Object.create(null)),_defineProperty(this,"_sourceBuffer",Object.create(null)),_defineProperty(this,"_mseFullFlag",{}),_defineProperty(this,"_st",0),_defineProperty(this,"_opst",0),_defineProperty(this,"_logger",null),_defineProperty(this,"_config",null),_defineProperty(this,"_url",null),_defineProperty(this,"_onStartStreaming",(function(){n._logger.debug("startstreaming")})),_defineProperty(this,"_onEndStreaming",(function(){n._logger.debug("endstreaming")})),_defineProperty(this,"_onSBUpdateEnd",(function(e){var t=n._queue[e];if(t){var i=t[0];if((null==i?void 0:i.opName)!==OP_NAME.UPDATE_DURATION&&t.shift(),i){var r,o,a=nowTime()-n._opst;n._logger.debug("UpdateEnd(".concat(e,"/").concat(i.opName,")"),SafeJSON.stringify(getTimeRanges(null===(r=n._sourceBuffer[e])||void 0===r?void 0:r.buffered)),a,i.context),i.promise.resolve({name:i.opName,context:i.context,costtime:a});var s=null===(o=i.context)||void 0===o?void 0:o.callback;s&&"function"==typeof s&&s(i.context),n._startQueue(e)}}})),_defineProperty(this,"_onSBUpdateError",(function(e,t){var i=n._queue[e];if(i){var r=i[0];r&&(n._logger.error("UpdateError",e,r.opName,r.context),r.promise.reject(new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_APPEND_BUFFER,t)))}})),this._config=Object.assign(e.getDefaultConfig(),i),t&&this.bindMedia(t),this._logger=new Logger("MSE"),this._config.openLog&&Logger.enable()}var t,i,n;return _createClass(e,[{key:"isOpened",get:function(){var e;return"open"===(null===(e=this.mediaSource)||void 0===e?void 0:e.readyState)}},{key:"hasOpTasks",get:function(){var e=this,t=!1;return Object.keys(this._queue).forEach((function(i){var n=e._queue[i];Array.isArray(n)&&(t||(t=n.length>0))})),t}},{key:"url",get:function(){return this._url}},{key:"duration",get:function(){var e;return(null===(e=this.mediaSource)||void 0===e?void 0:e.duration)||-1}},{key:"isEnded",get:function(){return!!this.mediaSource&&"ended"===this.mediaSource.readyState}},{key:"streaming",get:function(){return!isMMS(this.mediaSource)||this.mediaSource.streaming}},{key:"isFull",value:function(t){return t?this._mseFullFlag[t]:this._mseFullFlag[e.VIDEO]}},{key:"updateDuration",value:function(e){var t=this,i=this.mediaSource&&this.mediaSource.duration>e;if(this.mediaSource&&this.mediaSource.duration>e){var n=0;if(Object.keys(this._sourceBuffer).forEach((function(e){try{n=Math.max(t.bufferEnd(e)||0,n)}catch(e){}})),e<n)return Promise.resolve()}return this._enqueueBlockingOp((function(){t.isEnded?t._logger.debug("setDuration but ended"):t.mediaSource&&(t.mediaSource.duration=e,t._logger.debug("setDuration",e))}),OP_NAME.UPDATE_DURATION,{isReduceDuration:i})}},{key:"open",value:function(){var e=this;if(this._openPromise.used&&!this.isOpened&&this.mediaSource){var t=this.mediaSource;t.addEventListener("sourceopen",(function i(){var n=nowTime()-e._st;e._logger.debug("sourceopen",n),t.removeEventListener("sourceopen",i),e._openPromise.resolve({costtime:n})})),this._openPromise=createPublicPromise()}return this._openPromise}},{key:"bindMedia",value:(n=_asyncToGenerator(_regeneratorRuntime().mark((function e(t){var i,n,r,o,a=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.mediaSource&&!this.media){e.next=3;break}return e.next=3,this.unbindMedia();case 3:if(i=getMediaSource(this._config.preferMMS),t&&i){e.next=6;break}throw new Error("Param media or MediaSource does not exist");case 6:return this.media=t,n=this.mediaSource=new i,r=isMMS(n),this._st=nowTime(),o=function e(){var i=nowTime()-a._st;a._logger.debug("sourceopen"),n.removeEventListener("sourceopen",e),URL.revokeObjectURL(t.src),a._openPromise.resolve({costtime:i})},n.addEventListener("sourceopen",o),r&&(n.addEventListener("startstreaming",this._onStartStreaming),n.addEventListener("endstreaming",this._onEndStreaming)),this._url=URL.createObjectURL(n),t.src=this._url,t.disableRemotePlayback=r,e.abrupt("return",this._openPromise);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"unbindMedia",value:(i=_asyncToGenerator(_regeneratorRuntime().mark((function e(){var t,i,n,r=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._openPromise.used||this._openPromise.resolve(),t=this.mediaSource){if(Object.keys(this._queue).forEach((function(e){var t=r._queue[e];t&&t.forEach((function(e){var t,i;return null===(t=e.promise)||void 0===t||null===(i=t.resolve)||void 0===i?void 0:i.call(t)}))})),i=!!this.media&&this.media.readyState>=1,n="open"===t.readyState,i&&n)try{t.endOfStream()}catch(e){}Object.keys(this._sourceBuffer).forEach((function(e){try{t.removeSourceBuffer(r._sourceBuffer[e])}catch(e){}})),isMMS(t)&&(t.removeEventListener("startstreaming",this._onStartStreaming),t.removeEventListener("endstreaming",this._onEndStreaming))}if(this.media){this.media.disableRemotePlayback=!1,this.media.removeAttribute("src");try{this.media.load()}catch(e){}this.media=null}this.mediaSource=null,this._openPromise=createPublicPromise(),this._queue=Object.create(null),this._sourceBuffer=Object.create(null);case 8:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"createSource",value:function(e,t){if(!this._sourceBuffer[e]&&this.mediaSource){var i;try{i=this._sourceBuffer[e]=this.mediaSource.addSourceBuffer(t)}catch(e){throw new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_ADD_SB,e)}i.mimeType=t,i.addEventListener("updateend",this._onSBUpdateEnd.bind(this,e)),i.addEventListener("error",this._onSBUpdateError.bind(this,e))}}},{key:"changeType",value:function(e,t){var i=this,n=this._sourceBuffer[e];return this.mediaSource&&n&&n.mimeType!==t?"function"!=typeof n.changeType?Promise.reject(new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_CHANGE_TYPE,new Error("changeType is not a function"))):this._enqueueOp(e,(function(){try{n.changeType(t)}catch(e){throw new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_CHANGE_TYPE,e)}n.mimeType=t,i._onSBUpdateEnd(e)}),"changeType",{mimeType:t}):Promise.resolve()}},{key:"createOrChangeSource",value:function(e,t){return this.createSource(e,t),this.changeType(e,t)}},{key:"append",value:function(e,t,i){var n=this;return t&&t.byteLength&&this._sourceBuffer[e]?this._enqueueOp(e,(function(){var r;n.mediaSource&&!n.media.error&&(n._logger.debug("MSE APPEND START",i),n._opst=nowTime(),null===(r=n._sourceBuffer[e])||void 0===r||r.appendBuffer(t))}),OP_NAME.APPEND,i):Promise.resolve()}},{key:"remove",value:function(e,t,i,n){var r=this,o=!1;return this._mseFullFlag[e]&&(o=!0),this._enqueueOp(e,(function(){if(r.mediaSource&&!r.media.error){var o=r._sourceBuffer[e];t>=i||!o?r._onSBUpdateEnd(e):(r._opst=nowTime(),r._logger.debug("MSE REMOVE START",e,t,i,n),o.remove(t,i))}}),OP_NAME.REMOVE,n,o)}},{key:"clearBuffer",value:function(e,t){var i,n=this;return Object.keys(this._sourceBuffer).forEach((function(r){i=n.remove(r,e,t)})),i||Promise.resolve()}},{key:"clearAllBuffer",value:function(){var e,t=this;return Object.keys(this._sourceBuffer).forEach((function(i){var n=t._sourceBuffer[i];e=t.remove(i,0,Buffer.end(Buffer.get(n)))})),e}},{key:"clearOpQueues",value:function(e,t){var i;this._logger.debug("MSE clearOpQueue START");var n=this._queue[e];if(t&&n)this._queue[e]=[];else if(n&&n[e]&&!(n.length<5)){var r=[];n.forEach((function(e){e.context&&e.context.isinit&&r.push(e)})),this._queue[e]=n.slice(0,2),r.length>0&&(i=this._queue[e]).push.apply(i,r)}}},{key:"endOfStream",value:function(e){var t=this;return this.mediaSource&&"open"===this.mediaSource.readyState?this._enqueueBlockingOp((function(){var i=t.mediaSource;i&&"open"===i.readyState&&(t._logger.debug("MSE endOfStream START"),e?i.endOfStream(e):i.endOfStream())}),"endOfStream"):Promise.resolve()}},{key:"setLiveSeekableRange",value:function(e,t){var i=this.mediaSource;e<0||t<e||null==i||!i.setLiveSeekableRange||"open"!==i.readyState||i.setLiveSeekableRange(e,t)}},{key:"getSourceBuffer",value:function(e){return this._sourceBuffer[e]}},{key:"buffered",value:function(e){return Buffer.get(this._sourceBuffer[e])}},{key:"bufferStart",value:function(e){return Buffer.start(this.buffered(e))}},{key:"bufferEnd",value:function(e){return Buffer.end(this.buffered(e))}},{key:"_enqueueOp",value:function(e,t,i,n,r){var o=this;if(!this.mediaSource)return Promise.resolve();var a=this._queue[e]=this._queue[e]||[],s={exec:t,promise:createPublicPromise(),opName:i,context:n};return r?(a.splice(0,0,s),this._mseFullFlag[e]=!1,this._startQueue(e)):a.push(s),this.isOpened||this.isEnded?1===a.length&&this._startQueue(e):this._openPromise.then((function(){1===a.length&&o._startQueue(e)})),s.promise}},{key:"_enqueueBlockingOp",value:(t=_asyncToGenerator(_regeneratorRuntime().mark((function e(t,i,n){var r,o,a=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mediaSource){e.next=2;break}return e.abrupt("return",Promise.resolve());case 2:if((r=Object.keys(this._sourceBuffer)).length){e.next=5;break}return e.abrupt("return",t());case 5:return o=[],r.forEach((function(e){var t=a._queue[e],r=createPublicPromise();o.push(r),t.push({exec:function(){r.resolve()},promise:r,opName:i,context:n}),1===t.length&&a._startQueue(e)})),e.abrupt("return",Promise.all(o).then((function(){try{return t()}finally{r.forEach((function(e){var t=a._queue[e],i=a._sourceBuffer[e];null==t||t.shift(),i&&i.updating||a._startQueue(e)}))}})));case 8:case"end":return e.stop()}}),e,this)}))),function(e,i,n){return t.apply(this,arguments)})},{key:"_startQueue",value:function(e){var t=this._queue[e];if(t){var i=t[0];if(i&&!this._mseFullFlag[e])try{i.exec()}catch(n){n&&n.message&&n.message.indexOf("SourceBuffer is full")>=0?(this._mseFullFlag[e]=!0,i.context&&"object"===_typeof(i.context)&&(i.context.isFull=!0),this._logger.error("[MSE error], context,",i.context," ,name,",i.opName,",err,SourceBuffer is full"),i.promise.reject(new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_FULL,n))):(this._logger.error(n),i.promise.reject(n.constructor===StreamingError?n:new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_OTHER,n)),t.shift(),this._startQueue(e))}}}},{key:"setTimeoffset",value:function(e,t,i){var n=this;return this._enqueueOp(e,(function(){t<0&&(t+=.001),n._sourceBuffer[e].timestampOffset=t,n._onSBUpdateEnd(e)}),"setTimeoffset",i)}},{key:"abort",value:function(e,t){var i=this;return this.isOpened?this._enqueueOp(e,(function(){i._sourceBuffer[e].abort(),i._onSBUpdateEnd(e)}),"abort",t):Promise.resolve()}}],[{key:"isSupported",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:'video/mp4; codecs="avc1.42E01E,mp4a.40.2"',t=getMediaSource();if(!t)return!1;try{return t.isTypeSupported(e)}catch(t){return this._logger.error(e,t),!1}}},{key:"isMMSOnly",value:function(){return"undefined"!=typeof ManagedMediaSource&&"undefined"==typeof MediaSource}},{key:"getDefaultConfig",value:function(){return{openLog:!1,preferMMS:!1}}}]),e}();_defineProperty(MSE,"VIDEO","video"),_defineProperty(MSE,"AUDIO","audio");var AUDIO_ERROR_SUBCODE=3,CODEC_MAP={"mp4a.40.5":1,"mp4a.40.2":2},JUMP_GAP_STEP=.05,MediaCache=function(){function e(){_classCallCheck$2(this,e),_defineProperty$2(this,"_queue",[]),"undefined"!=typeof document&&(this._tempMedia=document.createElement("video"))}return _createClass$2(e,[{key:"tempMedia",get:function(){return this._tempMedia}},{key:"hasCached",get:function(){return-1!==this._queue.findIndex((function(e){return 1===e.codec}))&&-1!==this._queue.findIndex((function(e){return 2===e.codec}))}},{key:"getCachedMedia",value:function(e){var t=this._queue.findIndex((function(t){return t.codec===e}));return-1!==t?this._queue.splice(t,1)[0]:null}},{key:"cacheMedia",value:function(e){var t=e.codec,i=e.media,n=e.mse,r=CODEC_MAP[t];if(this._queue=this._queue.filter((function(e){var t;return e.mse&&!e.mse.isOpened&&e.mse.unbindMedia(),null===(t=e.mse)||void 0===t?void 0:t.isOpened})),!t||this._queue.filter((function(e){return e.codec===r})).length>2)return null==n||n.endOfStream(),void(null==n||n.unbindMedia());this._queue.push({codec:r,media:i,mse:n})}}]),e}(),mediaCache=new MediaCache,AudioMseRender=function(e){_inherits$1(o,BaseRender);var t,i,n,r=_createSuper$1(o);function o(e,t){var i;return _classCallCheck$2(this,o),_defineProperty$2(_assertThisInitialized$1(i=r.call(this,e,t)),"_media",void 0),_defineProperty$2(_assertThisInitialized$1(i),"_isTempMedia",!1),_defineProperty$2(_assertThisInitialized$1(i),"_mse",void 0),_defineProperty$2(_assertThisInitialized$1(i),"_remuxer",null),_defineProperty$2(_assertThisInitialized$1(i),"_codec",""),_defineProperty$2(_assertThisInitialized$1(i),"_sourceCreated",!1),_defineProperty$2(_assertThisInitialized$1(i),"_needInitSegment",!0),_defineProperty$2(_assertThisInitialized$1(i),"_seekNoSideEffect",!1),_defineProperty$2(_assertThisInitialized$1(i),"_startRendered",!1),_defineProperty$2(_assertThisInitialized$1(i),"_firstTimeAppendedBuffer",!1),_defineProperty$2(_assertThisInitialized$1(i),"_sampleQueue",[]),_defineProperty$2(_assertThisInitialized$1(i),"_inProcessing",!1),_defineProperty$2(_assertThisInitialized$1(i),"_duration",0),_defineProperty$2(_assertThisInitialized$1(i),"_mediaCache",mediaCache),_defineProperty$2(_assertThisInitialized$1(i),"_resetDts",(function(){})),_defineProperty$2(_assertThisInitialized$1(i),"_onCanplay",(function(){i._ready||(i._ready=!0,i.emit(Events.AUDIO.AUDIO_READY))})),_defineProperty$2(_assertThisInitialized$1(i),"_onPlaying",(function(){i._parent.ready&&(i._audioCanAutoplay=!0,i._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PLAYING))})),_defineProperty$2(_assertThisInitialized$1(i),"_onWaiting",(function(){if(!i._seekNoSideEffect){try{for(var e,t=i._media.buffered,n=i._media.currentTime,r=0,o=0,a=t.length;o<a;o++)t.start(o)<n&&t.end(o)>n&&(r=t.end(o)-n);if(Math.abs(r)>.5)return;if(Math.abs(i._media.duration-i._media.currentTime)<.3)return i._reuseMse||i._mse.endOfStream(),void(null===(e=_assertThisInitialized$1(i))||void 0===e||e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ENDED))}catch(e){}i._ready=!1,i.emit(Events.AUDIO.AUDIO_WAITING)}})),_defineProperty$2(_assertThisInitialized$1(i),"_onSeeked",(function(){i._seekNoSideEffect||i._isLive?i._seekNoSideEffect=!1:(logger.log(i.TAG,"seeked"),i._ready||(i._media.pause(),i._ready=!0,i.emit(Events.AUDIO.AUDIO_READY)))})),_defineProperty$2(_assertThisInitialized$1(i),"_onProgress",(function(){if(i._media.readyState<=1){var e=i._getBufferGap();e>0&&e<1&&(i._media.currentTime+=e+JUMP_GAP_STEP,logger.warn(i.TAG,"progress, gap=",e))}i._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PROGRESS),i._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.DURATION_CHANGE)})),_defineProperty$2(_assertThisInitialized$1(i),"_onEnded",(function(){var e;logger.log(i.TAG,"ended!"),null===(e=_assertThisInitialized$1(i))||void 0===e||e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ENDED)})),_defineProperty$2(_assertThisInitialized$1(i),"_onOnceProgress",(function(){if(i._media.buffered.length){var e=i._media.buffered.start(0);e&&(i._media.currentTime=e+JUMP_GAP_STEP,logger.log(i.TAG,"start gap:",e)),i._media.removeEventListener("progress",i._onOnceProgress)}})),_defineProperty$2(_assertThisInitialized$1(i),"_onError",(function(){var e;i._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,i._assembleErr("audio error: ".concat(null===(e=i._media.error)||void 0===e?void 0:e.message),AUDIO_ERROR_SUBCODE))})),_defineProperty$2(_assertThisInitialized$1(i),"_appendChunk",(function(e,t){if(!i.noAudio&&t.samples.length){if(i._codec||(2!==t.objectType&&5!==t.objectType?i._codec="mp4a.40.5":i._codec=t.codec,i._isTempMedia&&i._switchMedia(i._codec)),t.samples.forEach((function(e){e.baseMediaDecodeTime=t.baseMediaDecodeTime,i._sampleQueue.push(e)})),t.samples=[],!i._meta)return i._meta=_objectSpread2(_objectSpread2({},t),{},{exist:function(){return!0},hasSample:function(){return!0},samples:[]}),logger.warn(i.TAG,"audio set metadata",i._meta),void i._doAppendWrapper();i._meta.sampleRate!==t.sampleRate&&(logger.warn(i.TAG,"discontinue: ".concat(i._meta.sampleRate," -> ").concat(t.sampleRate)),i._needInitSegment=!0,Object.keys(t).forEach((function(e){i._meta[e]=t[e]}))),!i._inProcessing&&i._sampleQueue.length&&i._doAppendWrapper()}})),_defineProperty$2(_assertThisInitialized$1(i),"_doAppend",function(){var e=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var n,r,o;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i._remuxer||(i._remuxer=new FMP4Remuxer({samples:[],exist:function(){return!1}},t)),n=t.samples,i._sourceCreated){e.next=12;break}return i.analyse.addAudioMseOpenStart(),e.next=6,i._mse.open();case 6:i._sourceCreated=!0,logger.log(i.TAG,"video/mp4;codecs=".concat(i._codec)),i._mse.createSource(t.type,"video/mp4;codecs=".concat(i._codec)),i.analyse.addAudioMseOpend(),logger.log(i.TAG,"sb created!"),i._checkAutoPlay();case 12:if(r=i._remuxer.remux(i._needInitSegment),!i._needInitSegment||r.audioInitSegment){e.next=15;break}return e.abrupt("return");case 15:return i._needInitSegment=!1,o=[],r.audioInitSegment&&o.push(i._mse.append(t.type,r.audioInitSegment)),r.audioSegment&&o.push(i._mse.append(t.type,r.audioSegment)),e.abrupt("return",Promise.all(o).then((function(){return n[n.length-1].dts/1e3})).then((function(){i._firstTimeAppendedBuffer||(i._firstTimeAppendedBuffer=!0,i.analyse.addAudioFirstTimeAppended())})));case 20:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),_defineProperty$2(_assertThisInitialized$1(i),"_doPlay",(function(){i._media.play().catch((function(){}))})),_defineProperty$2(_assertThisInitialized$1(i),"_doPause",(function(){i._media.pause()})),_defineProperty$2(_assertThisInitialized$1(i),"_doSeek",(function(e){i._ready=!1,i._media.currentTime=e})),_defineProperty$2(_assertThisInitialized$1(i),"_doChaseFrame",(function(e){var t=e.position;i._seekNoSideEffect=!0,i._media.currentTime=t})),_defineProperty$2(_assertThisInitialized$1(i),"_startRender",(function(){logger.log(i.TAG,"start render"),i._startRendered=!0,i._media.play().catch((function(){}))})),i.TAG="AudioMseRender",i._reuseMse=getDecodeCapacaity().reuseMseForAudio,i._initMedia(),i}return _createClass$2(o,[{key:"isMse",get:function(){return!0}},{key:"media",get:function(){return this._media}},{key:"currentTime",get:function(){return this._media.currentTime}},{key:"buffered",get:function(){return this._media.buffered}},{key:"duration",get:function(){return Number.isNaN(this._media.duration)?1/0:this._media.duration},set:function(e){this._duration=e,this._updateDuration(e)}},{key:"audioCanAutoplay",get:function(){return this._audioCanAutoplay||this.noAudio}},{key:"_initMedia",value:function(){if(!this._reuseMse||!mediaCache.hasCached)return logger.log(this.TAG,"init media and mse directly"),this._media=document.createElement("video"),this._media.autoplay=!0,this._mse=new MSE,this._bindEvents(),this._bindMediaEvents(),void this._mse.bindMedia(this._media);logger.log(this.TAG,"bind media temporary"),this._media=mediaCache.tempMedia,this._bindEvents(),this._isTempMedia=!0}},{key:"_switchMedia",value:function(e){var t=this._media,i=mediaCache.getCachedMedia(CODEC_MAP[e]);i?(logger.warn(this.TAG,"switch to cached media for audio play! codec=".concat(e)),this._media=i.media,this._mse=i.mse,this._bindMediaEvents(),this._updateDuration(this._duration),this._media.currentTime=JUMP_GAP_STEP,this._sourceCreated=!0,this._audioCanAutoplay=!0,this.analyse.addAudioMseOpend()):this._initMedia(),this._media.volume=t.volume,this._media.playbackRate=t.playbackRate,this._isTempMedia=!1}},{key:"_getBufferGap",value:function(){for(var e=this.buffered,t=0,i=e.length;t<i;t++)if(!(e.end(t)<this.currentTime))return e.start(t)-this.currentTime;return 0}},{key:"canSeek",value:function(){return!0}},{key:"resume",value:function(){return this._media.play()}},{key:"pause",value:function(){return this._media.pause()}},{key:"seekNoSideEffect",value:function(e){this._doChaseFrame(e)}},{key:"dump",value:function(){}},{key:"_emitTimelineEvents",value:function(e,t,i){var n,r;null===(n=this._parent)||void 0===n||null===(r=n.emit)||void 0===r||r.call(n,e,t,i)}},{key:"_assembleErr",value:function(e,t){var i=new Error(e);return i.code=3,i.subCode=t,i}},{key:"_bindEvents",value:function(){var e=this;_get(_getPrototypeOf$1(o.prototype),"_bindEvents",this).call(this),this._parent.on(Events.DECODE_EVENTS.CHASE_AUDIO_FRAME,this._doChaseFrame),this._parent.on(Events.TIMELINE.UPDATE_VOLUME,(function(t){e._media.volume=t,e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.VOLUME_CHANGE)})),this._parent.on(Events.TIMELINE.END_OF_STREAM,(function(){var t;e.reuseMseForAudio||!e._media.readyState?null==e||e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ENDED):null===(t=e._mse)||void 0===t||t.endOfStream()})),this._parent.on(Events.TIMELINE.SET_PLAYBACKRATE,(function(t){logger.log(e.TAG,"change playbackrate, ",t),e._media.playbackRate=t}))}},{key:"_bindMediaEvents",value:function(){this._media.addEventListener("canplay",this._onCanplay),this._media.addEventListener("playing",this._onPlaying),this._media.addEventListener("waiting",this._onWaiting),this._media.addEventListener("seeked",this._onSeeked),this._media.addEventListener("progress",this._onProgress),this._media.addEventListener("ended",this._onEnded),this._media.addEventListener("progress",this._onOnceProgress),this._media.addEventListener("error",this._onError)}},{key:"_updateDuration",value:(n=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._mse){e.next=7;break}if(this._mse.isOpened){e.next=4;break}return e.next=4,this._mse.open();case 4:return e.next=6,this._mse.updateDuration(t);case 6:logger.log(this.TAG,"update duration",t);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"_doAppendWrapper",value:(i=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._meta.samples=this._sampleQueue.slice(),this._meta.baseMediaDecodeTime=this._meta.samples[0].baseMediaDecodeTime,this._sampleQueue=[],e.prev=3,this._inProcessing=!0,e.next=7,this._doAppend(this._meta);case 7:if(t=e.sent,this.isLive&&this._emitTimelineEvents(Events.TIMELINE.UPDATE_SEGMENT_END,t),this._inProcessing=!1,!this._sampleQueue.length){e.next=13;break}return e.next=13,this._doAppendWrapper();case 13:e.next=18;break;case 15:e.prev=15,e.t0=e.catch(3),this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,this._assembleErr("audio error: ".concat(null===e.t0||void 0===e.t0?void 0:e.t0.message),AUDIO_ERROR_SUBCODE));case 18:case"end":return e.stop()}}),e,this,[[3,15]])}))),function(){return i.apply(this,arguments)})},{key:"_checkAutoPlay",value:function(){var e=this;this._media.addEventListener("canplay",(function t(){var i=e._media.volume;e._media.volume=Math.min(i,.1);var n=e._media.play();(n=n.then?n:Promise.reject()).then((function(){logger.log(e.TAG,"auto play by checkAutoPlay!"),e._audioCanAutoplay=!0})).catch((function(){logger.warn(e.TAG,"can’t auto play!"),e._audioCanAutoplay=!1,e.emit(Events.AUDIO.AUDIO_NOT_ALLOWED_AUTOPLAY)})).finally((function(){e._media.volume=i,e._startRendered||(e._media.pause(),logger.log(e.TAG,"auto paused by checkAutoPlay!")),e._media.removeEventListener("canplay",t)}))}))}},{key:"_destroy",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,i,n;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(logger.log(this.TAG,"destroy audio render"),this._remuxer=null,this.removeAllListeners(),this._media.removeEventListener("canplay",this._onCanplay),this._media.removeEventListener("playing",this._onPlaying),this._media.removeEventListener("waiting",this._onWaiting),this._media.removeEventListener("seeked",this._onSeeked),this._media.removeEventListener("progress",this._onProgress),this._media.removeEventListener("ended",this._onEnded),this._media.removeEventListener("progress",this._onOnceProgress),this._media.removeEventListener("error",this._onError),this._reuseMse){e.next=17;break}return this._media.readyState&&(null===(i=this._mse)||void 0===i||i.endOfStream()),e.next=15,null===(t=this._mse)||void 0===t?void 0:t.unbindMedia();case 15:e.next=20;break;case 17:null===(n=this._mse)||void 0===n||n.clearAllBuffer(),mediaCache.cacheMedia({codec:this._codec,media:this._media,mse:this._mse}),logger.log(this.TAG,"cache media for audio play, codec=",this._codec);case 20:this._meta&&(this._meta.duration=0),this._mse=null,this._media=null;case 23:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}],[{key:"isSupported",value:function(){return getDecodeCapacaity().audioWithMse&&Boolean(window.MediaSource)&&window.MediaSource.isTypeSupported('video/mp4; codecs="mp4a.40.5"')}}]),o}(),TOLERANCE$1=.1,MAX_TOLERANCE=1,VideoTimeRange=function(){function e(t){_classCallCheck$2(this,e),this.TAG="VideoTimeRange",this._parent=t,this._baseDts=0,this._lastDuration=0,this._duration=0,this._bitrate=0,this._totalSize=0,this._buffers=[],this._currentFrameQueue=[],this._frameIndexInQueue=0,this._delayEstimateList=[],this._keyframeQueue=[]}return _createClass$2(e,[{key:"isLive",get:function(){return this._parent.isLive}},{key:"baseDts",get:function(){return this._baseDts}},{key:"duration",get:function(){return this._duration},set:function(e){this._duration=e}},{key:"buffered",get:function(){var e=this;if(this.isLive)return{length:this._duration?1:0,start:function(){return 0},end:function(){return e._duration}};var t=this._mergeBufferRanges();return{length:t.length,start:function(e){var i=t[e];return i?i.start:0},end:function(e){var i=t[e];return i?i.end:1/0}}}},{key:"bufferStart",get:function(){var e;return(null===(e=this._buffers[0])||void 0===e?void 0:e.start)||0}},{key:"frameLength",get:function(){return this._currentFrameQueue.length}},{key:"keyFrameLength",get:function(){return this._keyframeQueue.length}},{key:"totalSize",get:function(){return this._totalSize}},{key:"bitrate",get:function(){return this._bitrate},set:function(e){this._bitrate=e}},{key:"lastDuration",get:function(){return this._lastDuration}},{key:"frames",get:function(){return this._currentFrameQueue}},{key:"getCurrentTime",value:function(e){return this._lastDuration+(e-this._baseDts)/1e3}},{key:"resetDts",value:function(e){this._baseDts=e}},{key:"_mergeBufferRanges",value:function(){var e=this._buffers.sort((function(e,t){return e.start>t.start?1:-1})),t=e.length,i=[];if(!t)return i;for(var n={start:e[0].start,end:e[0].end},r=1;r<t;r++){var o=e[r];Math.abs(n.end-o.start)<TOLERANCE$1?n.end=o.end:(i.push(n),n={start:o.start,end:o.end})}return i.push(n),i}},{key:"_caclBaseDts",value:function(e){-1===this._baseDts&&e&&(this._baseDts=e.dts,logger.log(this.TAG,"set baseDts: ",this._baseDts,"frame len:",this._currentFrameQueue.length))}},{key:"_updateDuration",value:function(e){for(var t=e.length,i=e[t-1],n=0;n<t;n++){var r=e[n];if(r&&r.options&&r.options.meta){var o=e[n-1]||this._currentFrameQueue[this._currentFrameQueue.length-1];o?this._lastDuration+=(o.dts-this._baseDts)/1e3:this._lastDuration=this._duration,logger.log(this.TAG,"updateBaseDts,record lastDuration:",this._lastDuration),this._baseDts=r.dts;break}}i&&(this._duration=(i.dts-this._baseDts)/1e3+this._lastDuration)}},{key:"_estimateBitRate",value:function(e){var t=e.length;if(t<=2){if(this._delayEstimateList=this._delayEstimateList.concat(e),(t=this._delayEstimateList.length)<=30)return;e=this._delayEstimateList,this._delayEstimateList=[]}for(var i=0,n=0;n<t;n++){var r=e[n];i+=r.data?r.data.length:r.units.reduce((function(e,t){return e+t.byteLength}),0)}this._totalSize+=i;var o=i/(e[t-1].dts-e[0].dts);this._bitrate=parseInt(8e3*o)}},{key:"_beforeAppendVodBuffer",value:function(e){var t=this;if(e.length){for(var i=[],n=[],r=0,o=e.length;r<o;r++)e[r].keyframe&&(i.push(n),n=[]),n.push(e[r]);n.length&&i.push(n),i.forEach((function(e){return t._appendVodBuffer(e)}))}}},{key:"_appendVodBuffer",value:function(e){if(e.length){var t=e[0],i=e[e.length-1],n=(t.dts-this._baseDts)/1e3,r=(i.dts-this._baseDts)/1e3;logger.enable&&logger.log(this.TAG,"add new buffer range [".concat(n," , ").concat(r,"]")),this._buffers.filter((function(e){return n>=e.start&&r<=e.end})).length||(this._buffers.push({start:n,end:r,duartion:r-n,frames:e.slice()}),this._buffers.sort((function(e,t){return e.start>t.start?1:-1})),this._afterAppendVodBuffer())}}},{key:"_afterAppendVodBuffer",value:function(){if(this._buffers.filter((function(e){var t;return!(null!==(t=e.frames[0])&&void 0!==t&&t.keyframe)})).length){for(var e=this._buffers,t=this._buffers.length,i=[],n=this._buffers[0],r=1;r<t;r++){var o;null!==(o=e[r].frames[0])&&void 0!==o&&o.keyframe?(i.push(n),n=e[r]):(n.frames=n.frames.concat(e[r].frames),n.end=e[r].end,n.duartion=n.end-n.start)}i.push(n),this._buffers=i}}},{key:"_recordKeyframes",value:function(e){var t=this;e.forEach((function(e){if(e.keyframe){var i=(e.dts-t._baseDts)/1e3;t._keyframeQueue.push({position:i,frame:e})}})),this._keyframeQueue=this._keyframeQueue.sort((function(e,t){return e.position>t.position?1:-1})),this.isLive&&this._keyframeQueue.length>40&&this._keyframeQueue.splice(0,20)}},{key:"toAnnexBNalu",value:function(e){e.forEach((function(e){var t=e.units;if(t){var i=t.reduce((function(e,t){return e+4+t.byteLength}),0),n=new Uint8Array(i),r=0;t.forEach((function(e){n.set([0,0,0,1],r),r+=4,n.set(e,r),r+=e.byteLength})),e.units=null,e.data=n}}))}},{key:"append",value:function(e,t,i){i&&this.toAnnexBNalu(e),this._caclBaseDts(e[0]),t&&this._updateDuration(e),this._estimateBitRate(e),this._recordKeyframes(e),this.isLive?this._currentFrameQueue=this._currentFrameQueue.concat(e):this._beforeAppendVodBuffer(e)}},{key:"updateSegmentEnd",value:function(e){var t=this._buffers[this._buffers.length-1];t&&(Math.abs(t.end-e)<.5||(t.end=e,t.duartion=e-t.start,logger.log(this.TAG,"video data lack, reset end:",e)))}},{key:"getFrame",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(this.isLive)return this._currentFrameQueue.shift();if(!(e=this._currentFrameQueue[this._frameIndexInQueue])){if(!(e=this._currentFrameQueue[--this._frameIndexInQueue]))return;if(!this.switchBuffer((e.dts-this._baseDts)/1e3,this._frameIndexInQueue++,t))return;return this.getFrame(++t)}return this._frameIndexInQueue++,e}},{key:"getFramesForPreciseSeek",value:function(e){return this._currentFrameQueue.filter((function(t){return t.dts<=e}))}},{key:"updateFrameIndexForPreciseSeek",value:function(e){this._frameIndexInQueue=e}},{key:"switchBuffer",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(!((arguments.length>2&&void 0!==arguments[2]?arguments[2]:0)>=20)){e=e||this.bufferStart;var i=this._buffers.filter((function(t){return t.start<e+TOLERANCE$1&&t.end>=e+TOLERANCE$1}))[0];if(!i){var n=this._buffers.find((function(t){return t.start>=e}));return n&&n.start-e<MAX_TOLERANCE?(this._currentFrameQueue=n.frames.slice(0),this._frameIndexInQueue=0,n):void 0}return i.frames[0].dts>=e?(this._currentFrameQueue=i.frames.slice(0),this._frameIndexInQueue=0,logger.log(this.TAG,"switch video buffer, time:".concat(e," , buffer:[").concat(i.start," , ").concat(i.end,"], index=0")),i):i.frames.length>t?(this._currentFrameQueue=i.frames.slice(0),logger.log(this.TAG,"switch video buffer, in the same gop and more frame got, time:".concat(e," , buffer:[").concat(i.start," , ").concat(i.end,"], index=").concat(t)),i):void logger.log(this.TAG,"switch video buffer, in the same gop and no more frame got, time:".concat(e," , buffer:[").concat(i.start," , ").concat(i.end,"], index=").concat(t))}}},{key:"getSeekStartPosition",value:function(e){var t,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;if(this._keyframeQueue.forEach((function(i){i.position<=e&&(t=i)})),t)return e-t.position<i?t:void 0}},{key:"nextFrame",value:function(){return this._currentFrameQueue[0]}},{key:"deletePassed",value:function(e){this._currentFrameQueue=this._currentFrameQueue.filter((function(t){return t.dts>=e}))}},{key:"getDtsOfTime",value:function(e){var t=e-this._lastDuration;return this._baseDts+1e3*t}},{key:"clean",value:function(){this._currentFrameQueue=[]}},{key:"destroy",value:function(){this._currentFrameQueue=[],this._buffers=[]}}]),e}();function _checkClose(e){var t;(null===(t=e.buffer)||void 0===t?void 0:t.close)&&e.buffer.close()}var FrameQueue=function(){function e(t){_classCallCheck$2(this,e),this.TAG="FrameQueue",this._parent=t,this._lastGopId=0,this._frames=[]}return _createClass$2(e,[{key:"currentTimeDts",get:function(){return this._parent.preciseVideoDts}},{key:"length",get:function(){return this._frames.length}},{key:"frames",get:function(){return this._frames}},{key:"append",value:function(e){e.info?this._frames.push(e):_checkClose(e)}},{key:"appendVodFrame",value:function(e){this._frames.push(e)}},{key:"nextFrame",value:function(){var e=this._frames.length;return 1===this._parent.noAudio&&e>3&&(this._frames=this._frames.slice(e-2)),this._frames[0]}},{key:"shift",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this._frames.shift();return this.deletePassed(e),t}},{key:"deletePassed",value:function(e){this._frames=this._frames.filter((function(t){return!!(t.info&&t.info.dts>e)||(_checkClose(t),!1)}))}},{key:"empty",value:function(){this._frames.forEach((function(e){return _checkClose(e)})),this._frames=[]}},{key:"destroy",value:function(){this.empty(),this._lastGopId=0}}]),e}(),FrameRenderCache=function(){function e(){_classCallCheck$2(this,e),_defineProperty$2(this,"_queue",[]),_defineProperty$2(this,"TAG","FrameRenderCache")}return _createClass$2(e,[{key:"cacheCvs",value:function(e){this._queue.push(e),logger.log(this.TAG,"cache canvas!")}},{key:"getCachedCvs",value:function(){var e=this._queue.pop();return e&&logger.log(this.TAG,"get cached canvas!"),e}}]),e}(),frameRenderCache=new FrameRenderCache,FrameRender=function(){function e(t,i){_classCallCheck$2(this,e),this.TAG="FrameRender",this.configs=Object.assign({},t),this.parent=i,this.canvas=this.configs.canvas,this.canvas.glInstance=this,this.meta=Object.assign({},this.configs.meta),this.frameRenderCache=frameRenderCache,this._initMeta(),this._initContextGL(),this.contextGL&&(this._initProgram(),this._initBuffers(),this._initTextures())}return _createClass$2(e,[{key:"_initMeta",value:function(){this.chroma=this.meta.chromaFormat,this.height=this.meta.height,this.width=this.meta.width,this.canvas.width===this.meta.width&&this.canvas.height===this.meta.height||(this.canvas.width=this.meta.width,this.canvas.height=this.meta.height,this.parent.emitResizeEvent())}},{key:"_initContextGL",value:function(){if("2d"!==this.configs.type){for(var e=this.canvas,t=null,i=["webgl","experimental-webgl","moz-webgl","webkit-3d"],n=0;!t&&n<i.length;){var r=i[n];try{t=e.getContext(r,this.configs.glCtxOptions),logger.log("FrameRender","use=",r,this.configs.glCtxOptions);break}catch(e){t=null}t&&"function"==typeof t.getParameter||(t=null),++n}this.contextGL=t}else this.ctx=this.canvas.getContext("2d")}},{key:"_initProgram",value:function(){var e=this.contextGL,t=["attribute vec4 vertexPos;","attribute vec4 texturePos;","attribute vec4 uTexturePos;","attribute vec4 vTexturePos;","varying vec2 textureCoord;","varying vec2 uTextureCoord;","varying vec2 vTextureCoord;","void main()","{"," gl_Position = vertexPos;"," textureCoord = texturePos.xy;"," uTextureCoord = uTexturePos.xy;"," vTextureCoord = vTexturePos.xy;","}"].join("\n"),i=["precision highp float;","varying highp vec2 textureCoord;","varying highp vec2 uTextureCoord;","varying highp vec2 vTextureCoord;","uniform sampler2D ySampler;","uniform sampler2D uSampler;","uniform sampler2D vSampler;","uniform mat4 YUV2RGB;","void main(void) {"," highp float y = texture2D(ySampler, textureCoord).r;"," highp float u = texture2D(uSampler, uTextureCoord).r;"," highp float v = texture2D(vSampler, vTextureCoord).r;"," gl_FragColor = vec4(y, u, v, 1) * YUV2RGB;","}"].join("\n"),n=e.createShader(e.VERTEX_SHADER);e.shaderSource(n,t),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS)||console.log("Vertex shader failed to compile: "+e.getShaderInfoLog(n));var r=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(r,i),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)||console.log("Fragment shader failed to compile: "+e.getShaderInfoLog(r));var o=e.createProgram();e.attachShader(o,n),e.attachShader(o,r),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)||console.log("Program failed to compile: "+e.getProgramInfoLog(o)),e.useProgram(o);var a=e.getUniformLocation(o,"YUV2RGB");e.uniformMatrix4fv(a,!1,[1.16438,0,1.59603,-.87079,1.16438,-.39176,-.81297,.52959,1.16438,2.01723,0,-1.08139,0,0,0,1]),this.shaderProgram=o}},{key:"_initBuffers",value:function(){var e=this.contextGL,t=this.shaderProgram,i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,new Float32Array([1,1,-1,1,1,-1,-1,-1]),e.STATIC_DRAW);var n=e.getAttribLocation(t,"vertexPos");e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0);var r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),e.STATIC_DRAW);var o=e.getAttribLocation(t,"texturePos");e.enableVertexAttribArray(o),e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0),this.texturePosBuffer=r;var a=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,a),e.bufferData(e.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),e.STATIC_DRAW);var s=e.getAttribLocation(t,"uTexturePos");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),this.uTexturePosBuffer=a;var A=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,A),e.bufferData(e.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),e.STATIC_DRAW);var u=e.getAttribLocation(t,"vTexturePos");e.enableVertexAttribArray(u),e.vertexAttribPointer(u,2,e.FLOAT,!1,0,0),this.vTexturePosBuffer=A}},{key:"_initTextures",value:function(){var e=this.contextGL,t=this.shaderProgram,i=this._initTexture(),n=e.getUniformLocation(t,"ySampler");e.uniform1i(n,0),this.yTextureRef=i;var r=this._initTexture(),o=e.getUniformLocation(t,"uSampler");e.uniform1i(o,1),this.uTextureRef=r;var a=this._initTexture(),s=e.getUniformLocation(t,"vSampler");e.uniform1i(s,2),this.vTextureRef=a,e.pixelStorei(e.UNPACK_ALIGNMENT,1)}},{key:"_initTexture",value:function(){var e=this.contextGL,t=e.createTexture();return e.bindTexture(e.TEXTURE_2D,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(e.TEXTURE_2D,null),t}},{key:"_drawPictureGL",value:function(e,t,i,n,r){var o=n*i,a=r*i/2;444!==this.chroma&&422!==this.chroma||(a*=2);var s={yData:(e=new Uint8Array(e)).subarray(0,o),uData:e.subarray(o,o+a),vData:e.subarray(o+a,o+a+a)};this._drawPictureGL420(s,t,i,n,r)}},{key:"_drawPictureGL420",value:function(e,t,i,n,r){var o=this.contextGL,a=this.texturePosBuffer,s=this.uTexturePosBuffer,A=this.vTexturePosBuffer,u=this.yTextureRef,c=this.uTextureRef,d=this.vTextureRef,l=e.yData,h=e.uData,_=e.vData,f=n,m=i,p=r,v=i/2;422!==this.chroma&&444!==this.chroma||(v=i);var E=r,y=v,g=this.canvas.width/this.width,b=this.canvas.height/this.height,T=0,R=0,D=this.canvas.width,k=this.canvas.height;g<b?(k=this.height*this.canvas.width/this.width,R=parseInt((this.canvas.height-this.height*this.canvas.width/this.width)/2)):(D=this.width*this.canvas.height/this.height,T=parseInt((this.canvas.width-this.width*this.canvas.height/this.height)/2)),o.viewport(T,R,D,k);var S=new Float32Array([1,0,0,0,1,1,0,1]);o.bindBuffer(o.ARRAY_BUFFER,a),o.bufferData(o.ARRAY_BUFFER,S,o.DYNAMIC_DRAW);var I=new Float32Array([1,0,0,0,1,1,0,1]);o.bindBuffer(o.ARRAY_BUFFER,s),o.bufferData(o.ARRAY_BUFFER,I,o.DYNAMIC_DRAW);var C=new Float32Array([1,0,0,0,1,1,0,1]);o.bindBuffer(o.ARRAY_BUFFER,A),o.bufferData(o.ARRAY_BUFFER,C,o.DYNAMIC_DRAW),o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,u),o.texImage2D(o.TEXTURE_2D,0,o.LUMINANCE,f,m,0,o.LUMINANCE,o.UNSIGNED_BYTE,l),o.activeTexture(o.TEXTURE1),o.bindTexture(o.TEXTURE_2D,c),o.texImage2D(o.TEXTURE_2D,0,o.LUMINANCE,p,v,0,o.LUMINANCE,o.UNSIGNED_BYTE,h),o.activeTexture(o.TEXTURE2),o.bindTexture(o.TEXTURE_2D,d),o.texImage2D(o.TEXTURE_2D,0,o.LUMINANCE,E,y,0,o.LUMINANCE,o.UNSIGNED_BYTE,_),o.drawArrays(o.TRIANGLE_STRIP,0,4)}},{key:"_drawPicture2d",value:function(e){if(e&&this.canvas){this.ctx||(this.ctx=this.canvas.getContext("2d"));var t=e.displayWidth||e.width,i=e.displayHeight||e.height;this.canvas.height===i&&this.canvas.width===t||(this.canvas.height=i,this.canvas.width=t);try{this.ctx.drawImage(e.dom||e,0,0,t,i)}catch(t){console.error(this.TAG,"_drawPicture2d",e,e.dom,t,t.message)}}}},{key:"_resize",value:function(e,t){this.width===e&&this.height===t||(this.width=e,this.height=t,this.canvas.width=e,this.canvas.height=t,this.parent.emitResizeEvent())}},{key:"render",value:function(e,t,i,n,r){this._resize(t,i),this.contextGL?this._drawPictureGL(e,t,i,n,r):this._drawPicture2d(e)}},{key:"resetMeta",value:function(e){this.meta=Object.assign({},e)}},{key:"updateBind",value:function(e,t){this.parent=e,this.resetMeta(t)}},{key:"destroy",value:function(e){this.parent=null,this.canvas.style.display="none",e&&(this.contextGL&&this.contextGL.clear(this.contextGL.DEPTH_BUFFER_BIT|this.contextGL.COLOR_BUFFER_BIT),frameRenderCache.cacheCvs(this.canvas))}}]),e}(),MAX_QUEUE_LENGTH=5,DecodeEstimate=function(){function e(t){_classCallCheck$2(this,e),_defineProperty$2(this,"_lowDecodeThreshold",getDecodeCapacaity().lowDecodeThreshold/MAX_QUEUE_LENGTH),this.TAG="DecodeEstimate",this._needEstimate=!0,this._parent=t,this._lastDecodeDot=0,this._lastDecodeCost=0,this._lastFrameDts=0,this._dtsDeltas=[],this._decodeCosts=[],this._lowDecodeQueue=[],this._fps=0,this._decodeFps=0,this._gopLength=0,this._webcodec=!1}return _createClass$2(e,[{key:"fps",get:function(){return this._fps}},{key:"decodeFps",get:function(){return this._decodeFps}},{key:"decodeCost",get:function(){return this._lastDecodeCost}},{key:"gopLength",get:function(){return this._gopLength}},{key:"webcodec",set:function(e){this._webcodec=e}},{key:"updateGopCount",value:function(){this._gopLength++}},{key:"needEstimateFps",value:function(){this._needEstimate=!0}},{key:"addDecodeInfo",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{dts:0};this._estimateDecodeFps(e),this._estimateFps(e)}},{key:"resetDecodeDot",value:function(e){this._lastDecodeDot=e||0}},{key:"reset",value:function(){this._decodeCosts=[],this._lowDecodeQueue=[]}},{key:"_estimateFps",value:function(e){if(this._needEstimate)if(this._lastFrameDts){var t=e.dts-this._lastFrameDts;if(this._lastFrameDts=e.dts,!(Math.abs(t)>200)){this._dtsDeltas.push(t);var i=this._dtsDeltas.length;i<MAX_QUEUE_LENGTH||(this._fps=Math.ceil(1e3/this._avg(this._dtsDeltas,i)),logger.log(this.TAG,"estimate fps:",this._fps),this._needEstimate=!1)}}else this._lastFrameDts=e.dts}},{key:"_estimateDecodeFps",value:function(e){if(this._lastDecodeDot){var t=performance.now(),i=t-this._lastDecodeDot;this._lastDecodeDot=t,e.cost=i,this._lastDecodeCost=i,this._decodeCosts.push(i);var n=this._decodeCosts.length;if(!(n<MAX_QUEUE_LENGTH)){var r=this._avg(this._decodeCosts,n);this._decodeFps=Math.floor(1e3/r),this._decodeCosts=[],this._lowDecodeDetect()}}else this._lastDecodeDot=performance.now()}},{key:"_avg",value:function(e,t){var i=e.reduce((function(e,t){return e+=t}),0);return Math.floor(i/t)||1}},{key:"_lowDecodeDetect",value:function(){this._decodeFps?(this._decodeFps<this._fps*this._parent.playbackRate+(this.webcodec?0:3)?this._lowDecodeQueue.push(this._decodeFps):this._lowDecodeQueue.pop(),this._lowDecodeQueue.length>this._lowDecodeThreshold&&(this._lowDecodeQueue=[],logger.log(this.TAG,"解码效率过低,应该降级"),this._parent.emit(Events.VIDEO.DECODE_LOW_FPS))):this._parent.emit(Events.VIDEO.DECODE_LOW_FPS)}}]),e}(),shell="\n var timer;\n\n function initTimer (interval) {\n destroy()\n clearInterval(timer);\n timer = setInterval(() => {\n self.postMessage({type: 'NEXT_TICK'});\n }, interval)\n }\n\n function destroy () {\n clearInterval(timer);\n }\n\n self.onmessage = function (e) {\n var {type,interval} = e.data;\n switch (type) {\n case 'START':\n initTimer(interval);\n break;\n case 'DESTROY':\n destroy();\n break;\n }\n }\n",timerWorkerCache=[],TickTimer=function(){function e(t){var i=this;_classCallCheck$2(this,e),_defineProperty$2(this,"_doTask",(function(){var e;null===(e=i._task)||void 0===e||e.call(i)})),this._task=t;var n=new Blob([shell],{type:"application/javascript"});this._worker=timerWorkerCache.pop()||new Worker(URL.createObjectURL(n)),this._bindEvent()}return _createClass$2(e,[{key:"_bindEvent",value:function(){this._worker.addEventListener("message",this._doTask)}},{key:"start",value:function(e){(e=parseInt(e))<10&&(e=10),e>60?e=60:e>25&&(e=25),this._worker.postMessage({type:"START",interval:e})}},{key:"stop",value:function(){this._worker.postMessage({type:"DESTROY"})}},{key:"destroy",value:function(){this._worker&&(this._worker.postMessage({type:"DESTROY"}),this._worker.removeEventListener("message",this._doTask),timerWorkerCache.push(this._worker),logger.log("TickTimer","unbind timer event"),this._worker=null,this._task=null)}}]),e}(),HAVE_NOTHING=0,HAVE_METADATA=1,HAVE_CURRENT_DATA=2,HAVE_FUTURE_DATA=3,HAVE_ENOUGH_DATA=4,MEDIA_ERR_DECODE=3,VideoBaseRender=function(e){_inherits$1(i,BaseRender);var t=_createSuper$1(i);function i(e,n){var r;return _classCallCheck$2(this,i),(r=t.call(this,e,n))._timeRange=new VideoTimeRange(_assertThisInitialized$1(r)),r._decodeEstimate=new DecodeEstimate(_assertThisInitialized$1(r)),r._frameQueue=new FrameQueue(_assertThisInitialized$1(r)),r._lastTimeupdate=0,r._renderCost=0,r._canAutoPlay=!0,r._videoDecode=!1,r._inSeeking=!1,r._frameRender=null,r._configuration=null,r._render=r._render.bind(_assertThisInitialized$1(r)),r._tickTimer=new TickTimer(r._render),r._initCanvas(e),r._bindEvents(),r}return _createClass$2(i,[{key:"canAutoPlay",get:function(){return this._canAutoPlay}},{key:"canvas",get:function(){return this._canvas}},{key:"timescale",get:function(){return 1e3}},{key:"fps",get:function(){return this._decodeEstimate.fps||this._meta&&this._meta.fpsNum/this._meta.fpsDen||24}},{key:"decodeFps",get:function(){return this._decodeEstimate.decodeFps}},{key:"decodeCost",get:function(){return this._decodeEstimate.decodeCost}},{key:"renderCost",get:function(){return this._renderCost}},{key:"totalSize",get:function(){return this._timeRange.totalSize}},{key:"bitrate",get:function(){return this._timeRange.bitrate},set:function(e){this._timeRange.bitrate=e}},{key:"gopLength",get:function(){return this._decodeEstimate.gopLength}},{key:"is540p",get:function(){return this._canvas.height<720}},{key:"buffered",get:function(){return this._timeRange.buffered}},{key:"inSeeking",get:function(){return this._inSeeking}},{key:"interval",get:function(){return Math.floor(1e3/this.fps/this.playbackRate)}},{key:"playbackRate",get:function(){return this._playbackRate||1}},{key:"baseDts",get:function(){return this._timeRange.baseDts}},{key:"currentTime",get:function(){return this._timeRange.getCurrentTime(this.preciseVideoDts)}},{key:"timelinePosition",get:function(){return this._parent.timelinePosition}},{key:"lastTimelinePosition",get:function(){return this._lastTimelinePosition||0},set:function(e){this._lastTimelinePosition=e}},{key:"audioSyncDts",get:function(){return this._audioDts||this.baseDts},set:function(e){this._audioDts=e}},{key:"preciseVideoDts",get:function(){return this.audioSyncDts+Math.floor(1e3*(this.timelinePosition-this.lastTimelinePosition))}},{key:"readyState",get:function(){var e=this._frameQueue.length||(this.currentTime?1:0);return e?e>=8?HAVE_ENOUGH_DATA:e>=4?HAVE_FUTURE_DATA:e>=2?HAVE_CURRENT_DATA:HAVE_METADATA:HAVE_NOTHING}},{key:"isHevc",get:function(){return Boolean("hev1.1.6.L93.B0"===(this._meta||{}).codec)}},{key:"isVvc",get:function(){return/^bvc2\./.test((this._meta||{}).codec)}},{key:"videoDecode",get:function(){return this._videoDecode}},{key:"decoderMode",get:function(){var e;return null===(e=this._decodeController)||void 0===e?void 0:e.decoderMode}},{key:"configuration",get:function(){var e,t;return this._configuration||(this._configuration=this._meta.configuration||getAvcc(null===(e=this._meta)||void 0===e?void 0:e.sps[0],null===(t=this._meta)||void 0===t?void 0:t.pps[0])),this._configuration},set:function(e){this._configuration=e.configuration||getAvcc(e.sps[0],e.pps[0])}},{key:"setSeekingStatus",value:function(e){e!==this._inSeeking&&(logger.warn(this.TAG,"seeking status ->",e),this._inSeeking=e)}},{key:"getDtsOfTime",value:function(e){return this._timeRange.getDtsOfTime(e)}},{key:"updateReady",value:function(){this._whenReady()}},{key:"forceRender",value:function(){this._render(!0)}},{key:"getSeekStartPosition",value:function(e,t){return this._timeRange.getSeekStartPosition(e,t)}},{key:"canSeek",value:function(){throw new Error("need override by children")}},{key:"emitResizeEvent",value:function(){null==this||this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.RESIZE)}},{key:"_assembleErr",value:function(e,t){var i=new Error(e);return i.code=MEDIA_ERR_DECODE,i.subCode=t,i}},{key:"_emitTimelineEvents",value:function(e,t,i){var n;null===(n=this._parent)||void 0===n||n.emit(e,t,i)}},{key:"_initCanvas",value:function(e){e.canvas?this._canvas=e.canvas:this._canvas=frameRenderCache.getCachedCvs()||document.createElement("canvas"),this._canvas.style.margin="auto",this._canvas.style.position="absolute",this._canvas.style.pointerEvents="none"}},{key:"_bindEvents",value:function(){var e=this;_get(_getPrototypeOf$1(i.prototype),"_bindEvents",this).call(this);var t=function(t){var i=t.width,n=t.height,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,a=e._canvas,s=a.width,A=a.height,u=n*s/A,c=i*A/s,d=i-u,l=n-c,h=d*r+"px",_=l*o+"px";e._canvas.style.left=h,e._canvas.style.top=_,logger.warn(e.TAG,"cvsWidth=".concat(s,", cvsHeight=").concat(A,", scaleCvsWidth=").concat(u,", scaleCvsHeight=").concat(c)),logger.warn(e.TAG,"cover position: deltaX=".concat(d,", deltaY=").concat(l,", width=").concat(i,", height=").concat(n,", pX=").concat(h,", pY=").concat(_))};this._parent.on(Events.VIDEO.UPDATE_VIDEO_FILLTYPE,(function(i,n){var r=n.width,o=n.height,a=e._canvas,s=a.width,A=a.height,u=!r||r/o>s/A;if(logger.warn(e.TAG,"UPDATE_VIDEO_FILLTYPE isGapX =",u,"type =",i,s,A,r,o),e._canvas.style.maxWidth="initial",e._canvas.style.maxHeight="initial","cover"===i)return u?(e._canvas.style.left=0,e._canvas.style.top=0,e._canvas.style.height="auto",e._canvas.style.width="100%",void t({width:r,height:o},0,.5)):(e._canvas.style.left=0,e._canvas.style.top=0,e._canvas.style.width="auto",e._canvas.style.height="100%",void t({width:r,height:o},.5,0));if("fill"===i)return e._canvas.style.width="100%",void(e._canvas.style.height="100%");(e._canvas.style.top=0,e._canvas.style.bottom=0,e._canvas.style.left=0,e._canvas.style.right=0,e._canvas.style.maxWidth="100%",e._canvas.style.maxHeight="100%",e._canvas.style.width="initial",e._canvas.style.height="initial",s<r&&A<o)&&(s/r>A/o?e._canvas.style.width="100%":e._canvas.style.height="100%")})),this._parent.on(Events.VIDEO.UPDATE_VIDEO_COVER_POSITION,t),this._parent.on(Events.TIMELINE.SYNC_DTS,(function(t){var i,n=e._frameQueue.nextFrame(),r=n&&n.info&&n.info.dts;if(e.lastTimelinePosition=e.timelinePosition,e.noAudio){var o=e._timeRange.nextFrame();t=t||r||o&&o.dts||0}if(e.audioSyncDts=t,r&&r-t>500&&e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.LARGE_AV_GAP,{aDts:t,vDts:r,frameLength:e._frameQueue.length,currentTime:e._parent.currentTime,duration:e._parent.duration}),logger.log(e.TAG,"audio current buffer play finish, next buffer dts=",t,"currentTime:",e._parent.currentTime,"preciseVideoDts:",e.preciseVideoDts,"next video frame dts:",r,"frame length:",e._frameQueue.length),!(e._isLive||null!==(i=e._parent)&&void 0!==i&&i.seeking)){var a=e._timeRange.nextFrame();if(a){var s=(a.dts-a.baseDts)/1e3;e._parent.currentTime-s>1&&(logger.warn(e.TAG,"丢帧!"),e.ajustSeekTime(e._parent.currentTime))}}})),this._parent.on(Events.TIMELINE.UPDATE_GL_OPTIONS,(function(t){e._config.glCtxOptions=t})),this._parent.on(Events.TIMELINE.UPDATE_SEGMENT_END,this._updateSegmentEnd.bind(this)),this.on(Events.VIDEO.AUTO_RUN,this._startRender.bind(this)),this._parent.on(Events.TIMELINE.SET_PLAYBACKRATE,(function(t){e._playbackRate=t,e._startRender()}))}},{key:"ajustSeekTime",value:function(){throw new Error("need override by children")}},{key:"_resetDts",value:function(e,t){"audio"!==t&&this._timeRange.resetDts(e)}},{key:"_setMetadata",value:function(e,t){if("audio"!==e){logger.warn(this.TAG,"video set metadata"),this._meta=t;var i=t&&t.frameRate&&t.frameRate.fps;i?logger.log(this.TAG,"detect fps:",i):logger.warn(this.TAG,"no detect fps,start estimate"),this._initDecoder()}}},{key:"_initDecoder",value:function(){throw new Error("need override by children")}},{key:"_whenDecoderReady",value:function(){throw new Error("need override by children")}},{key:"_appendChunk",value:function(){throw new Error("need override by children")}},{key:"_startDecode",value:function(){throw new Error("need override by children")}},{key:"_receiveFrame",value:function(e,t){if(this._parent&&this._timeRange){var i=e.info||{};if(this._decodeEstimate.addDecodeInfo(i),!this._isLive&&((i.output||i.keyframe)&&this.setSeekingStatus(!1),this.inSeeking))return logger.log(this.TAG,"drop frame",e.info),void _checkClose(e);this._isLive?this._frameQueue.append(e):this._frameQueue.appendVodFrame(e),t&&t(),this._ready||this.readyState>=HAVE_METADATA&&this._whenReady()}}},{key:"_startRender",value:function(){logger.log(this.TAG,"start render"),this._tickTimer.start(this.interval)}},{key:"_render",value:function(){throw new Error("need override by children")}},{key:"_updateSegmentEnd",value:function(){throw new Error("need override by children")}},{key:"_whenReady",value:function(){this._ready=!0,this.emit(Events.VIDEO.VIDEO_READY),this.noAudio&&this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PLAYING)}},{key:"_doPlay",value:function(){this._tickTimer.start()}},{key:"_doPause",value:function(){this._tickTimer.stop()}},{key:"_doSeek",value:function(){this._ready=!1,this._frameQueue.destroy()}},{key:"_doChaseFrame",value:function(){throw new Error("need override by children")}},{key:"destroy",value:function(e){var t,i,n,r;null===(t=this._tickTimer)||void 0===t||t.destroy(),null===(i=this._timeRange)||void 0===i||i.destroy(),null===(n=this._frameQueue)||void 0===n||n.destroy(),null===(r=this._frameRender)||void 0===r||r.destroy(e),this._tickTimer=null,this._canvas=null,this._timeRange=null,this._frameQueue=null,this._frameRender=null,this._decodeEstimate=null,this._parent=null,this.removeAllListeners()}}]),i}(),DEFAULT_PLAYBACKRATE=2,CANVAS_COUNT=45,FRAME_DURATION=25,MAX_VIDEO_HEIGHT=720,MAX_FPS=30,MIN_FPS=15,VideoDecoder=function(e){_inherits$1(i,EventEmitter);var t=_createSuper$1(i);function i(e){var n;return _classCallCheck$2(this,i),(n=t.call(this)).TAG="VideoDecoder",n._video=n._createVideo(),n._IsInDecoding=!1,n._fps=0,n._framId=null,n._screenShotNum=0,n._allPicNum=0,n._currentBlob=null,n._basePTS=0,n._totleTime=0,n._isVideoONRun=!0,n.firstEmit=!1,n.ptsArray=[],n._currentCanvasHeight=0,n._canvasList=[],n._realFrameDuration=FRAME_DURATION,n._maxVideoHeight=e.maxVideoHeight||MAX_VIDEO_HEIGHT,n._minFPSTime=0,n._maxFPSTime=0,n._playFailed=!1,n._isPhoneSafari=!1,n._createCanvasList(),n._bindEvents(),n}return _createClass$2(i,[{key:"_createCanvasList",value:function(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d",{alpha:!1});for(var e=0;e<CANVAS_COUNT;e++){var t=this._createCanvas(),i=t.dom,n=t.ctx;this._canvasList.push({dom:i,ctx:n})}}},{key:"_createCanvas",value:function(){var e=document.createElement("canvas"),t=e.getContext("2d");return{dom:e,ctx:t}}},{key:"_createVideo",value:function(){var e=document.createElement("video");return e.setAttribute("muted",!0),e.setAttribute("autoplay",!0),e.setAttribute("controls",!0),e.setAttribute("webkit-playsinline",!0),e.setAttribute("playsinline",!0),e.setAttribute("x5-video-player-type","h5"),e.setAttribute("x5-video-player-type","h5-page"),e.style.position="absolute",e}},{key:"_initVideo",value:function(e,t){if(e.blobUrl&&void 0!==e.dts){var i=e.blobUrl;this._currentBlob=i,this._basePTS=e.dts,this._currentDuration=e.duration;try{logger.log(this.TAG,"_initVideo, basePTS:",e.dts),this._setVideoSrc(i,t),this._video.paused&&this._videoPlay("_initVideo")}catch(e){console.error(this.TAG,"_initVideo, load error",e)}}else console.error(this.TAG,"_initVideo","input info is error, blobUrl:",e.blobUrl,"dts:",e.dts)}},{key:"_setVideoSrc",value:function(e){try{var t=this._video;t.src=e,t.load(),t.playbackRate=DEFAULT_PLAYBACKRATE}catch(e){console.error(this.TAG,"_setVideoSrc",e)}}},{key:"_videoPlay",value:function(e){var t=this,i=this._video;if(logger.log(this.TAG,"_videoPlay, video is pause:",i.paused,e),i&&i.paused){var n=i.play();void 0!==n&&n.then((function(){t._playFailed=!1,logger.log(t.TAG,"_videoPlay success")})).catch((function(e){console.error(t.TAG,"_videoPlay failed,",e.message),t._playFailed=!0,t.emit(Events.DECODE_EVENTS.PLAY_FAILED,t.firstEmit)}))}}},{key:"_removeEvents",value:function(){var e=this._video;e.removeEventListener("playing",this._onPlaying.bind(this)),e.removeEventListener("ended",this._onEnded.bind(this)),e.removeEventListener("error",this._onError.bind(this)),e.removeEventListener("loadeddata",this._onLoadeddata.bind(this)),e.removeEventListener("timeupdate",this._onTimeUpdate.bind(this))}},{key:"_bindEvents",value:function(){var e=this,t=this._video;t?(document.addEventListener("visibilitychange",this._onVisibilityChange.bind(this)),t.addEventListener("playing",this._onPlaying.bind(this)),t.addEventListener("ended",this._onEnded.bind(this)),t.addEventListener("error",this._onError.bind(this)),t.addEventListener("loadeddata",this._onLoadeddata.bind(this)),t.addEventListener("timeupdate",this._onTimeUpdate.bind(this)),t.addEventListener("pause",(function(){logger.log("on pause, currentTime, duration:",e._vCurrentTime,e._vDuration)})),this.on("outputresolutionchange",this._onChange.bind(this)),this.on("fpsreduce",(function(t){e._adaptFrameDuration(t)}))):console.error(this.TAG,"_bindEvents")}},{key:"_onTimeUpdate",value:function(){this._lastCurrentTime=this._vCurrentTime}},{key:"_onVisibilityChange",value:function(){this._isVideoONRun="visible"===document.visibilityState}},{key:"_onChange",value:function(e,t){this._width=e,this._height=t}},{key:"_onPlaying",value:function(){this._IsInDecoding&&(console.warn(this.TAG,"_onPlaying","last video not correct end"),this._framId&&(window.cancelAnimationFrame(this._framId),this._framId=null)),logger.log(this.TAG,"_onPlaying, video duration:",this._vDuration,"currentTime:",this._vCurrentTime,"_lastPts:",this._lastPts),this._isInDecoding=!0,this._lastCurrentTime=this._vCurrentTime,this.ptsArray=[],this.playingTime||(this.playingTime=!0),this._getFrame()}},{key:"_onEnded",value:function(e,t){logger.log(this.TAG,"_onEnded","current fmp4 duration is:",this._vDuration,"_isInDecoding:",this._isInDecoding,"_lastPts:",this._lastPts,"_realFrameDuration:",this._realFrameDuration,"from:",t),this._isInDecoding&&(this._isInDecoding=!1,this._lastMp4Duration=Math.min(this._vDuration,this._vCurrentTime),this._framId&&(logger.log(this.TAG,"_onEnded","cancelAnimationFrame"),window.cancelAnimationFrame(this._framId),this._framId=null),this._decodeFPS=parseInt(this._screenShotNum/(this._vDuration/1e3)),this.emit("fps",this._screenShotNum,this._totleTime,this._vDuration,this._metaFPS,{height:this._currentCanvasHeight,relHeight:this._video.videoHeight}),logger.log("_timePerFrame",this._totleTime/this._screenShotNum),this._timePerFrame=this._totleTime/this._screenShotNum,this._screenShotNum=0,this._allPicNum=0,this._totleTime=0,this._currentBlob&&(URL.revokeObjectURL(this._currentBlob),this._currentBlob=null,this._basePTS=0),this.emit(Events.DECODE_EVENTS.FRAGMENT_END,this._decodeFPS,this._video.duration))}},{key:"_onError",value:function(){this._isInDecoding=!1;var e=this._video;console.error("video error:",e.error.code,e.error.message),this.emit("error",e.error,this.firstEmit)}},{key:"_onLoadeddata",value:function(){var e=this,t=this._video;t.currentTime=.001,this.firstEmit||(this._playFailed?(t.style.visibility="hidden",this.emit(Events.DECODE_EVENTS.APPEND_VIDEO,t),setTimeout((function(){logger.log(e.TAG,"onloadeddata, setTimeout firstEmit:",e.firstEmit),e._getFirstFrame()}),40)):(logger.log(this.TAG,"onloadeddata, firstEmit:",this.firstEmit),this._getFirstFrame()))}},{key:"_getFirstFrame",value:function(){this.firstTime=Date.now();var e=this._vCurrentTime,t=this._basePTS+e,i=this._getImageData(t).imageData;this.firstEmit=!0,this.emit(Events.DECODE_EVENTS.FIRST_FRAME,i,t)}},{key:"_getFrame",value:function(){var e=this._video,t=e.videoWidth,i=e.videoHeight;if(this._allPicNum++,this._isInDecoding){if(t||i){var n=this._vCurrentTime,r=this._basePTS+n;if(this.ptsArray.push(r),this._lastCurrentTime&&this._lastCurrentTime===this._vDuration&&(logger.log(this.TAG,"_getFrame, video ended, lastCurrentTime",this._lastCurrentTime,"duration:",this._vDuration,"isInDecoding:",this._isInDecoding),this._onEnded(null,"getFrame")),this._lastPts&&r<=this._lastPts)return void(this._framId=window.requestAnimationFrame(this._getFrame.bind(this)));if(this._lastPts&&r-this._lastPts<this._realFrameDuration)return void(this._framId=window.requestAnimationFrame(this._getFrame.bind(this)));this._screenShotNum++;var o,a=null,s=Date.now();try{a=(o=this._getImageData(r)).imageData}catch(e){console.error(e,o,this._canvasList.length)}this._lastPts=r;var A=Date.now()-s;return this._totleTime+=A,this.emit(Events.DECODE_EVENTS.DECODED,a,r),void(this._framId=window.requestAnimationFrame(this._getFrame.bind(this)))}this._framId=window.requestAnimationFrame(this._getFrame.bind(this))}else this._framId&&(window.cancelAnimationFrame(this._framId),this._framId=null)}},{key:"_getImageData",value:function(){var e,t=this._video,i=t.videoWidth,n=t.videoHeight,r=i,o=n;this._width&&this._height&&(r=this._width,o=this._height),o>this._maxVideoHeight&&(o=this._maxVideoHeight,r=parseInt(o*(i/n))),(e=this._canvasList.shift())||(console.warn(this.TAG,"_getImageData, _canvansList length is 0"),e=this._createCanvas()),e.width=r,e.height=o;var a=e.dom,s=e.ctx;if(this._currentCanvasHeight=o,!a)return{imageData:e};a.width!==r&&(a.width=r,a.height=o);try{n&&i&&r&&o&&s.drawImage(t,0,0,i,n,0,0,r,o)}catch(e){console.error(this.TAG,"_getImageData, drawImage:",e)}return{imageData:e}}},{key:"_adaptFrameDuration",value:function(e){e<MIN_FPS?this._minFPSTime++:this._minFPSTime=0,e>MAX_FPS?this._maxFPSTime++:this._maxFPSTime=0,this._minFPSTime>0&&this._decodeFPS<MIN_FPS&&(this._realFrameDuration-=this._timePerFrame,this._realFrameDuration<15&&(this._realFrameDuration=15),this._minFPSTime=0),this._maxFPSTime>0&&this._decodeFPS>MAX_FPS&&(this._realFrameDuration+=this._timePerFrame,this._maxFPSTime=0)}},{key:"_vDuration",get:function(){return parseInt(1e3*this._video.duration)}},{key:"_vCurrentTime",get:function(){return parseInt(1e3*this._video.currentTime)}},{key:"_reset",value:function(){this._isInDecoding=!1,this._lastPts=0,this._screenShotNum=0,this._allPicNum=0,this._totleTime=0}},{key:"reStartDecode",value:function(){this._video.pause(),this._reset();var e=this._currentBlob,t=this._basePTS;this._framId&&(window.cancelAnimationFrame(this._framId),this._framId=null),this._initVideo({blobUrl:e,dts:t})}},{key:"doSeek",value:function(e){if(this._isInDecoding){if(e<=0)return;var t=this._vCurrentTime/1e3+e>=this._vDuration/1e3?this._vDuration/1e3:this._vCurrentTime/1e3+1;console.error("doSeek",t),this._video.currentTime=t}}},{key:"pause",value:function(){this._isInDecoding&&this._video.pause()}},{key:"play",value:function(){if(this._isInDecoding&&this._video.paused)return logger.log("video play",this._vCurrentTime),this._video.play()}},{key:"startDecode",value:function(e,t,i){this._initVideo(e,i),this._metaFPS=t}},{key:"stopDecode",value:function(){this._video.paused||(this._video.pause(),this._reset())}},{key:"canPlayType",value:function(e){return this._video.canPlayType(e)}},{key:"destroy",value:function(){this._isInDecoding=!1,window.cancelAnimationFrame(this._framId),this._video.pause(),this._removeEvents()}},{key:"videoWidth",get:function(){return this._video?this._video.videoWidth:0}},{key:"videoHeight",get:function(){return this._video?this._video.videoHeight:0}}]),i}(),MAX_FRAMESIZE=40,MIN_FRAMESIZE=25,DEFAULT_FPS=20,LEVELS=[{base:720,level:1},{base:540,level:2},{base:360,level:3},{base:280,level:4}],VideoDecoderController=function(e){_inherits$1(i,EventEmitter);var t=_createSuper$1(i);function i(e,n){var r;return _classCallCheck$2(this,i),(r=t.call(this)).TAG="VideoDecoderController",r._decoder=new VideoDecoder(e),r._remux=new MP4Remuxer,r._bindEvents(),r._isInit=!1,r._isDataReady=!1,r._ready=!1,r._blobURLList=[],r._isInDecoding=!1,r._mediaSegmentReady=!1,r._parent=n,r._isDecodePause=!1,r._playSuccess=!0,r._isVideoOnRun=!0,r._startDts=0,r._fDuration=0,r._minFPSTime=0,r._lastPts=0,r._frameLengthPerFragment=0,r._gopBufferLength=0,r._maxGopDuration=0,r._minGopDuration=0,r._currentLevel=-1,r._endLevel=e.endLevel||2,r.currentFragmentDuration=0,r._handleKeyFrameVideo=r._handleKeyFrameVideo.bind(_assertThisInitialized$1(r)),r}return _createClass$2(i,[{key:"_bindEvents",value:function(){var e=this;document.addEventListener("visibilitychange",this._onVisibilityChange.bind(this)),this._decoder.on(Events.DECODE_EVENTS.APPEND_VIDEO,this._onAppendVideo.bind(this)),this._decoder.on(Events.DECODE_EVENTS.PLAY_FAILED,this._onPlayFailed.bind(this)),this._decoder.on("error",this._onError.bind(this)),this._decoder.on(Events.DECODE_EVENTS.DECODED,this._onDecoded.bind(this)),this._decoder.on(Events.DECODE_EVENTS.FIRST_FRAME,this._onFirstFrame.bind(this)),this._decoder.on(Events.DECODE_EVENTS.FRAGMENT_END,this._onFragmentEnd.bind(this)),this._decoder.on("fps",(function(){for(var t=arguments.length,i=new Array(t),n=0;n<t;n++)i[n]=arguments[n];var r=[e._metaFPS].concat(i,[e._frameLengthPerFragment]);e.emit.apply(e,["fps"].concat(_toConsumableArray$1(r)))})),this.on("keyFrame",this._handleKeyFrameVideo)}},{key:"_onRemuxed",value:function(e){var t={blobUrl:this._createBlobURL(e),dts:this.currentFragmentDts,duration:this.currentFragmentDuration,frameDuration:Math.floor(1e3/this._metaFPS)};this._recordGopDuration(this.currentFragmentDuration),this._pushBlob(t),logger.log(this.TAG,"_onRemuxed","maxgopduration:",this._maxGopDuration,"_gopBufferLength:",this._gopBufferLength),!this._isDataReady&&this._gopBufferLength>=this._maxGopDuration&&this._checkDataReady()}},{key:"_onPlayFailed",value:function(e){this._isInDecoding=!1,this._parent.emit(Events.DECODE_EVENTS.PLAY_FAILED,e)}},{key:"_onAppendVideo",value:function(e){this._parent.emit(Events.DECODE_EVENTS.APPEND_VIDEO,e)}},{key:"_onVisibilityChange",value:function(){this._isVideoOnRun="visible"===document.visibilityState}},{key:"_onDecoded",value:function(e,t){this._frameLengthPerFragment++;var i=this._buildFrameInfo(e,t);this._parent.emit(Events.DECODE_EVENTS.DECODED,i),this._lastPts=t}},{key:"_onFirstFrame",value:function(e,t){var i=this._buildFrameInfo(e,t);this._parent.emit(Events.DECODE_EVENTS.FIRST_FRAME,i)}},{key:"_onFragmentEnd",value:function(e){var t=this;logger.log(this.TAG,"_onFragmentEnd ,_isDecodePause:",this._isDecodePause,"decodeFPS:",e),e&&this._reduceResolution(e),this._isInDecoding=!1,this._inDecodeId=-1,this._currentInfo=null,this._frameLengthPerFragment=0,this._getBlobLength()&&!this._isDecodePause?this.startDecode():this.loadNextHandle=setInterval((function(){t._getBlobLength()&&!t._isDecodePause&&t._isVideoOnRun&&!t._isInDecoding&&(logger.log(t.TAG,"_onFragmentEnd, setInterval start next mp4 decode"),t.startDecode(),clearInterval(t.loadNextHandle))}))}},{key:"_onError",value:function(e,t){this._isInDecoding=!1,this._parent.emit("error",e,t)}},{key:"_checkReady",value:function(){this._isDataReady&&this._isInit&&(this.ready=!0,logger.log(this.TAG,"checkReady trigger ready"),this._parent.emit(Events.DECODE_EVENTS.READY))}},{key:"_checkDataReady",value:function(){this._isDataReady=!0,this._checkReady()}},{key:"_reduceResolution",value:function(e){if(logger.log(this.TAG,"_reduceResolution","currentLevel:",this._currentLevel,"endLevel:",this._endLevel),this._videoHeight>720&&(logger.log(this.TAG,"_reduceResolution","trigger DECODE_LOW_FPS"),this._parent.emit(Events.VIDEO.DECODE_LOW_FPS)),e&&e<DEFAULT_FPS?(this._minFPSTime++,this._decoder.emit("fpsreduce",e)):this._minFPSTime=0,this._currentLevel>=this._endLevel)return logger.log(this.TAG,"_reduceResolution","trigger DECODE_LOW_FPS",this._currentLevel,this._endLevel),void this._parent.emit(Events.VIDEO.DECODE_LOW_FPS);if(this._minFPSTime>2){var t,i=this._videoWidth,n=this._videoHeight;if(t=this._findLevel(n,this._currentLevel)){if(this._currentLevel=t.level,4===this._currentLevel)return logger.log(this.TAG,"_reduceResolution","trigger DECODE_LOW_FPS, _currentLevel: ",this._currentLevel),void this._parent.emit(Events.VIDEO.DECODE_LOW_FPS);this.width=t.base*(i/n),this.height=t.base,this._decoder.emit("outputresolutionchange",this.width,this.height)}this._minFPSTime=0}}},{key:"_findLevel",value:function(e,t){return LEVELS.find((function(i){return i.base<e&&i.level>t}))}},{key:"_buildFrameInfo",value:function(e,t){try{var i=e.width,n=e.height;return{msg:"DECODED",width:i,height:n,buffer:e,yLinesize:i,uvLinesize:i/2,info:{baseDts:void 0,dts:t,gopId:0,isGop:void 0,key:!1,pts:t},type:"rgb"}}catch(e){logger.log(this.TAG,e)}}},{key:"_pushBlob",value:function(e){logger.log("push blob",e.dts,e.duration),e&&e.duration&&(this._gopBufferLength+=e.duration),this._blobURLList.push(e)}},{key:"_shiftBlob",value:function(){var e=this._blobURLList.shift();return e&&e.duration&&(this._gopBufferLength-=e.duration),e}},{key:"_filterBlob",value:function(e){var t=this;this._blobURLList=this._blobURLList.filter((function(i){return i.dts<e&&(URL.revokeObjectURL(i.blobUrl),i.duration&&(t._gopBufferLength-=i.duration)),i.dts>=e}))}},{key:"_emptyBlobList",value:function(){this._blobURLList=[],this._gopBufferLength=0}},{key:"_getBlobLength",value:function(){return this._blobURLList.length}},{key:"_handleKeyFrameVideo",value:function(){try{var e=this._parent._timeRange.frames||[];if(this._parent._timeRange.clean(),!e.length)return;var t=e[0].dts,i=e[e.length-1].dts,n=t-this.endDts;logger.log(this.TAG,"_handleKeyFrameVideo","startDts:",t,"endDts:",i,"samples length:",e.length),this.endDts&&n>Math.floor(1e3/this._metaFPS)+1&&logger.log(this.TAG,"_handleKeyFrame, keyFrame dts:",t,"sample length:",e.length,"endDts:",i,"delay:",n);var r=i-t;if(this._fDuration||(this._fDuration=r),r<1500)return void logger.log(this.TAG,"_handleKeyFrame gopDuration :",r,"sample length:",e.length,"gopStartDts:",t,"gopEndDts:",i);if(this.firstDts||(this.firstDts=e[0].dts),this.currentFragmentDts=e[0].dts,this.currentFragmentDuration=this._getFragmentDuration(e),this.endDts=i,this.currentFragmentDts<this._startDts)return console.warn(this.TAG,"_handleKeyFrameVideo","currentFragmentDts < this._startDts",this.currentFragmentDts,this._startDts),void(e=[]);this.startRemux(e),e=[]}catch(e){console.error(this.TAG,"_handleKeyFrameVideo",e)}}},{key:"_getFragmentDuration",value:function(e){var t=0,i=0;return e[0].keyframe||console.error(this.TAG,"_getFragmentDuration","gop firstFrame is not keyframe"),e.forEach((function(n,r){n.keyframe&&r&&(t+=e[r-1].dts-e[i].dts,i=r)})),t+=e[e.length-1].dts-e[i].dts}},{key:"_createBlobURL",value:function(e){if(e){var t=new window.Blob([e.buffer],{type:"video/mp4"});return window.URL.createObjectURL(t)}}},{key:"_recordGopDuration",value:function(e){var t=e;this._minGopDuration||(this._minGopDuration=t),t>this._maxGopDuration&&(this._maxGopDuration=t),t<this._minGopDuration&&(this._minGopDuration=t)}},{key:"checkMaxFrames",value:function(e){"number"==typeof e&&(this._isDecodePause=e>MAX_FRAMESIZE,this._playSuccess&&this._isDecodePause&&this._decoder.pause())}},{key:"checkMinFrames",value:function(e){var t=this;if("number"==typeof e&&(this._isDecodePause=!(e<MIN_FRAMESIZE),!this._isDecodePause)){var i=this._decoder.play();void 0!==i?i.then((function(){t._playSuccess=!0})).catch((function(){t._playSuccess=!1})):setTimeout((function(){t._playSuccess=!0}),20)}}},{key:"frameRendend",value:function(e){if(e.dom){if(e.dom.width=0,e.dom.height=0,this._decoder._canvasList.length>MAX_FRAMESIZE)return;this._decoder._canvasList.push(e)}else logger.error(this.TAG,"_onRendend","imageObj. is error",e)}},{key:"checkValidBlob",value:function(e){this._filterBlob(e)}},{key:"chaseVideoFrame",value:function(e){logger.log(this.TAG,e,e.frame.dts,this.currentFragmentDts);var t=e.frame.dts;if(this._startDts=t,t===this.currentFragmentDts){if(logger.log(this.TAG,"_onChaseFrame","_inDecodeId:",this._inDecodeId,"currentFragmentDts:",this.currentFragmentDts),this._inDecodeId>0&&this._inDecodeId<t)return logger.log(this.TAG,"_onChaseFrame, _inDecodeId > 0 && _inDecodeId < startDts, _inDecodeId:",this._inDecodeId,"startDts:",t),this.stopDecode(),this._filterBlob(t),void this.startDecode();if(this._inDecodeId===t)return logger.log(this.TAG,"_onChaseFrame, _inDecodeId === startDts, startDts:",t),this.stopDecode(),void this.reStrartDecode(this._currentInfo);-1===this._inDecodeId&&(logger.log(this.TAG,"_onChaseFrame","_inDecodeId==-1"),this.startDecode())}t>this.currentFragmentDts&&(logger.log(this.TAG,"_onChaseFrame, startDts > currentFragmentDts, startDts:",t,"currentFragmentDts:",this.currentFragmentDts),this.stopDecode(),this._emptyBlobList()),t<this.currentFragmentDts&&(logger.log(this.TAG,"_onChaseFrame, startDts < currentFragmentDts, startDts:",t,"currentFragmentDts:",this.currentFragmentDts),t>this._inDecodeId&&(this._filterBlob(t),this.stopDecode(),this.startDecode()))}},{key:"init",value:function(e){this._isInit||(this._metaFPS=e.fpsNum/e.fpsDen||25,this._videoWidth=e.width,this._videoHeight=e.height,this._width=this._videoWidth,this._height=this._videoHeight,this._frameDuration=parseInt(1e3/this._metaFPS),this._isInit=!0,logger.log("".concat(this.TAG," has inited")),this._isInit=!0,this._checkReady())}},{key:"reStrartDecode",value:function(e){if(e)try{logger.log(this.TAG,"reStrartDecode"),this._isInDecoding=!0,this._inDecodeId=e.dts,this._currentInfo=e,this._decoder.startDecode(e,this._metaFPS,this._startTime),this._startTime=0}catch(e){console.error("load error",e)}}},{key:"stopDecode",value:function(){this._isInDecoding=!1,this._inDecodeId=-1,this._currentInfo=null,this._frameLengthPerFragment=0,this._decoder.stopDecode()}},{key:"startDecode",value:function(){if(this._isInDecoding)logger.log(this.TAG,"startDecode","this decoder is in decoding");else{var e=this._getBlobLength();if(this._decoder&&e){logger.log(this.TAG,"startDecode","blob url length:",e);var t=this._shiftBlob()||{};try{logger.log(this.TAG,"startDecode",t.dts,t.duration),this._isInDecoding=!0,this._inDecodeId=t.dts,this._currentInfo=t,this._decoder.startDecode(t,this._metaFPS)}catch(e){console.error(this.TAG,"startDecode","load error",e)}}}}},{key:"canSeek",value:function(e){var t=e.frame.dts;return!!(this.currentFragmentDts>=t&&this._isInDecoding)&&(this._inDecodeId!==t&&this._inDecodeId<t)}},{key:"startRemux",value:function(e){if(logger.log("startRemux samples length:",e.length),e.length){var t=this._parent._meta;t.samples=e;var i=this._remux.remux(t).videoSegment;this._onRemuxed(i)}else console.error("frame length is 0")}},{key:"canPlayType",value:function(e){if(this._decoder)try{return this._decoder.canPlayType('video/mp4;codecs="'+e.codec+'"')}catch(e){console.error(e)}}},{key:"destroy",value:function(){this._blobURLList=[],this._decoder.destroy()}},{key:"empty",value:function(){if(logger.log("empty"),this._decoder){var e=this._decoder._canvasList;return logger.log(this.TAG,"empty >>>>>>>>>>>>>>>>>>length:",e.length),e.forEach((function(e){e.dom&&(logger.log("clear >>>>>>>>>>>>>>>>>>"),e.dom.width=0,e.dom.height=0,e.dom=null)})),e.length}}},{key:"isIDLE",get:function(){return logger.log(this.TAG,"isIDEL","blob length:",this._getBlobLength(),"_isInDecoding:",this._isInDecoding,"isVideoOnRun:",this._isVideoOnRun,"_isDecodePause",this._isDecodePause),!this._getBlobLength()&&!this._isInDecoding&&this._isVideoOnRun}},{key:"ready",get:function(){return this._ready},set:function(e){this._ready=e}},{key:"remux",get:function(){return this._remux}},{key:"isInit",get:function(){return this._isInit}}]),i}(),VideoRenderFromVideo=function(e){_inherits$1(i,VideoBaseRender);var t=_createSuper$1(i);function i(e,n){var r;return _classCallCheck$2(this,i),(r=t.call(this,e,n)).TAG="VideoRenderFromVideo",r._videoDecodeController=new VideoDecoderController(e,_assertThisInitialized$1(r)),r._canAutoPlay=!0,r._videoDecode=e.videoDecode,r._chaseToFrame=null,r}return _createClass$2(i,[{key:"videoDecode",get:function(){return this._videoDecode},set:function(e){this._videoDecode=e}},{key:"_bindEvents",value:function(){var e=this;_get(_getPrototypeOf$1(i.prototype),"_bindEvents",this).call(this),this.on("keyFrame",this._onKeyFrame.bind(this)),this.on(Events.DECODE_EVENTS.READY,this._onReady.bind(this)),this.on(Events.DECODE_EVENTS.DECODED,this._onDecoded.bind(this)),this.on(Events.DECODE_EVENTS.PLAY_FAILED,this._onPlayFailed.bind(this)),this.on("error",this._onError.bind(this)),this.on(Events.DECODE_EVENTS.APPEND_VIDEO,this._onAppendVideo.bind(this)),this.on(Events.DECODE_EVENTS.FIRST_FRAME,this._onFirstFrame.bind(this)),this._parent.on(Events.DECODE_EVENTS.CHASE_VIDEO_FRAME,this._onChaseVideoFrame.bind(this)),this._parent.on(Events.TIMELINE.SYNC_DTS,this._onTimeLineSyncDTS.bind(this)),window.addEventListener("unload",(function(){e._empty()}))}},{key:"_onTimeLineSyncDTS",value:function(e){this._videoDecodeController.checkValidBlob(e)}},{key:"_onChaseVideoFrame",value:function(e){this._doChaseVideoFrame(e)}},{key:"_onAppendVideo",value:function(e){try{this._parent._parent.appendChild(e)}catch(e){cosole.error(this.TAG,"onAppendVideo",e)}}},{key:"_onKeyFrame",value:function(){logger.log(this.TAG,"_onKeyFrame, keyframe"),this._videoDecodeController.emit("keyFrame")}},{key:"_onError",value:function(e,t){console.error(this.TAG,"decoder error",e,t),t||this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,this._assembleErr(e&&e.message))}},{key:"_onReady",value:function(){if(!this._frameRender){var e=Object.assign(this._config,{meta:this._meta,canvas:this._canvas,type:"2d"});try{this._frameRender=new FrameRender(e,this)}catch(e){this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,this._assembleErr(e&&e.message))}}this._startDecode()}},{key:"_onFirstFrame",value:function(e){logger.log(this.TAG,"onFirstFrame"),this._receiveFrame(e),this._firstFrame=!0}},{key:"_onDecoded",value:function(e){var t=this;if(this._inChaseFrame){if(this.chaseFrameAfter++,1===this.chaseFrameAfter&&this._chaseToFrame){if(this._parent.emit(Events.DECODE_EVENTS.CHASE_VIDEO_FRAME_END,this._chaseToFrame),this._frameQueue.length)this._frameQueue.frames.forEach((function(e){t._videoDecodeController.frameRendend(e.buffer)}));this._frameQueue.empty(),this._videoDecodeController.checkMinFrames(this._frameQueue.length),this._timeRange.deletePassed(this._chaseToFrame.frame.dts),this._inChaseFrame=!1,this._chaseToFrame=null,console.warn(this.TAG,"onDecoded","_inChaseFrame end")}}else this.chaseFrameAfter=0;this._receiveFrame(e)}},{key:"_onPlayFailed",value:function(e){console.warn(this.TAG,"onPlayFailed, this._ready:",this._ready,",firstEmit:",e,",frame length:",this._frameQueue.length),this._ready||e||this._whenReady(),this._canAutoPlay=!1}},{key:"canSeek",value:function(e){return this._videoDecodeController.canSeek(e)}},{key:"_initDecoder",value:function(){this._isInit||(logger.log(this.TAG,"_initDecoder"),this._videoDecodeController.isInit||this._videoDecodeController.init(this._meta),this._isInit=!0)}},{key:"_receiveFrame",value:function(e){_get(_getPrototypeOf$1(i.prototype),"_receiveFrame",this).call(this,e),this._videoDecodeController.checkMaxFrames(this._frameQueue._frames.length)}},{key:"_setMetadata",value:function(e){logger.warn(this.TAG,"video set metadata",e),this._meta=e;var t=e.fpsNum/e.fpsDen;t?logger.log(this.TAG,"detect fps:",t):logger.warn(this.TAG,"no detect fps,start estimate"),this._initDecoder(e)}},{key:"_doChaseVideoFrame",value:function(e){this._inChaseFrame=!0,this._chaseToFrame=e,this._videoDecodeController.chaseVideoFrame(e)}},{key:"_appendChunk",value:function(e){this._meta||this._setMetadata(e);for(var t=e.samples.slice(),i=t.length,n=0;n<i;n++){var r=t.shift();r.keyframe&&this.emit("keyFrame"),this._timeRange.append([r],this.noAudio,!1)}}},{key:"_startDecode",value:function(){this._videoDecodeController.startDecode()}},{key:"_checkToDecode",value:function(){this._startDecode()}},{key:"_startRender",value:function(){logger.log(this.TAG,"_startRender interval",this.interval),this._tickTimer.start(this.interval)}},{key:"_render",value:function(e){var t=this,i=this._frameQueue.nextFrame(),n=this.preciseVideoDts;if(i&&this._timeRange){var r=i.info;if(!r)return this._frameQueue.shift(),void console.error("not info");this._renderDts=r.dts;var o=r.dts-n;if(o<-150){this.lastPrecise;var a=this._frameQueue.frames,s=this._getDeleteFrames(a,n),A=s.deleteFrames,u=s.useFrames;return a.splice(0),u.forEach((function(e){a.push(e)})),A.forEach((function(e){t._videoDecodeController.frameRendend(e.buffer)})),this._videoDecodeController.emit("renderDelay",o,this._frameQueue._frames.length),void this._videoDecodeController.checkMinFrames(this._frameQueue.length)}if(!(!e&&o>30&&o<6e4)){Math.abs(this._lastTimeupdate-r.dts)>250&&(this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.TIMEUPDATE),this._lastTimeupdate=r.dts),logger.long&&logger.log(this.TAG,"render delay:".concat(o," , timelinePosition:").concat(n," , dts:").concat(r.dts," , cost:").concat(r.cost," , gopID:").concat(r.gopId," , rest:").concat(this._frameQueue.length,", buffer frame:").concat(this._timeRange.frameLength));var c=performance.now();this._frameRender.render(i.buffer,i.width,i.height,i.yLinesize,i.uvLinesize),this.hasFirstFrame||e||(this.hasFirstFrame=!0,this._parent.emit(Events.TIMELINE.PLAY_EVENT,"firstframe")),this._videoDecodeController.frameRendend(i.buffer),this._frameQueue.shift(),this._videoDecodeController.checkMinFrames(this._frameQueue.length),this._videoDecodeController.emit("renderDelay",o,this._frameQueue._frames.length),this._renderCost=performance.now()-c,e||(this.lastTime&&(this.lastPrecise,Date.now(),this.lastTime),this.lastFrameinfo=r.dts,this.lastPrecise=n,this.lastTime=Date.now(),this.lastAudioTime=this._parent.audioRender.currentTime)}}else{if(this._videoDecodeController.checkMinFrames(this._frameQueue._frames.length),this._parent._paused)return;if(!this._firstFrame)return void logger.log(this.TAG,"_render","not first frame return");var d=this._videoDecodeController;if(logger.log(this.TAG,",lack frame, _inDecoding:",this._videoDecodeController._isInDecoding,this._videoDecodeController._isDecodePause,",_frameQueue.length:",this._frameQueue.length),!this._frameQueue.length&&d.isIDLE){this._ready=!1;var l=this._parent.audioRender;console.warn(this.TAG,"trigger video waiting vdecode, preciseVideoDts:",n,l.currentTime,l.duration,l.buffered.end(0),l.baseDts),this.emit(Events.VIDEO.VIDEO_WAITING)}this._checkToDecode()}}},{key:"_updateSegmentEnd",value:function(){}},{key:"_destroy",value:function(e){this._empty(),_get(_getPrototypeOf$1(i.prototype),"destroy",this).call(this,e),this._videoDecodeController.destroy()}},{key:"_doPause",value:function(){logger.log(this.TAG,">>>>>>>>doPause"),this._tickTimer.stop()}},{key:"_getDeleteFrames",value:function(e,t){var i=[],n=[];return e.forEach((function(e){e.info&&e.info.dts>t?n.push(e):e.info&&e.info.dts<=t&&i.push(e)})),{deleteFrames:i,useFrames:n}}},{key:"_empty",value:function(){this._videoDecodeController&&(this._videoDecodeController.empty(),this._frameQueue.frames.forEach((function(e){e.buffer&&e.buffer.dom&&(e.buffer.dom.width=0,e.buffer.dom.height=0,e.buffer.dom=null)})))}}]),i}(),DecodeController=function(e){_inherits$1(i,EventEmitter);var t=_createSuper$1(i);function i(e){var n;return _classCallCheck$2(this,i),_defineProperty$2(_assertThisInitialized$1(n=t.call(this)),"_parent",null),_defineProperty$2(_assertThisInitialized$1(n),"_decoderReady",!1),_defineProperty$2(_assertThisInitialized$1(n),"_inDecoding",!1),_defineProperty$2(_assertThisInitialized$1(n),"_toDecodeFirstframe",!0),_defineProperty$2(_assertThisInitialized$1(n),"_id",(new Date).getMilliseconds()),_defineProperty$2(_assertThisInitialized$1(n),"_workerErrorCallback",null),_defineProperty$2(_assertThisInitialized$1(n),"_workerMessageCallback",null),_defineProperty$2(_assertThisInitialized$1(n),"_decoderWorker",null),n._parent=e,n}return _createClass$2(i,[{key:"analyse",get:function(){return this._parent.analyse}},{key:"inDecoding",get:function(){return this._inDecoding}},{key:"decoderMode",get:function(){return this._decoderMode}},{key:"decoderReady",get:function(){return this._decoderReady}},{key:"needToDecode",get:function(){return this._inDecoding?0:this._continueDecodeThreshold}},{key:"maxDecodeOnce",get:function(){return this._maxDecodeOnce}},{key:"meta",get:function(){var e;return null===(e=this._parent)||void 0===e?void 0:e._meta},set:function(e){this._parent&&(this._parent._meta=e)}},{key:"init",value:function(e,t){this._workerMessageCallback=e,this._workerErrorCallback=t,this._initWorker()}},{key:"_initWorker",value:function(){throw new Error("need override by children")}},{key:"checkToDecode",value:function(e){this.webcodec?e<=this.needToDecode&&this.doDecode():!this._inDecoding&&e<=this.needToDecode&&this.doDecode()}},{key:"doDecode",value:function(){var e=this,t=this._getFramesToDecode();t&&t.length&&this.meta&&(this._toDecodeFirstframe&&(this._toDecodeFirstframe=!1,this.analyse.addFirstFrameToDecode()),this._avccpushed||this._initDecoderWithConfiguration(this._decoderWorker,this.meta),logger.enable&&logger.log(this.TAG,"doDecode ".concat(t.length," frames")),t.forEach((function(t){e._doDecodeInternal(t)})),this._inDecoding=!0,this._decoderWorker.postMessage({msg:"finish_flag"}))}},{key:"preciseSeek",value:function(e){var t,i,n,r,o=this,a=1e3*e,s=null===(t=this._parent)||void 0===t||null===(i=t._timeRange)||void 0===i?void 0:i.getFramesForPreciseSeek(a),A=s.length;A<this.maxDecodeOnce?this.doDecode():(null===(n=this._parent)||void 0===n||null===(r=n._timeRange)||void 0===r||r.updateFrameIndexForPreciseSeek(A),logger.enable&&logger.log(this.TAG,"doDecode ".concat(s.length," frames for precise seek")),s.forEach((function(e,t){o._doDecodeInternal(e,!0,t>=A-6)})),this._inDecoding=!0,this._decoderWorker.postMessage({msg:"finish_flag"}))}},{key:"_getFramesToDecode",value:function(){var e=this._parent,t=e._timeRange,i=e._decodeEstimate;if(this._decoderReady&&t){var n=t.frameLength;if(n){var r=this._toDecodeFirstframe?getDecodeCapacaity().maxDecodeOnceFirstTime:this.maxDecodeOnce;1===n&&i.resetDecodeDot(performance.now());for(var o=[];r>0;){var a=t&&t.getFrame();if(!a)break;o.push(a),a.gopId&&a.gopId-1==0&&i.updateGopCount(),r--}return o}}}},{key:"_doDecodeInternal",value:function(e,t,i){null!=e&&e.meta&&(this.meta=e.meta,logger.warn(this.TAG,"detect metadata! flush decoder"),this._initDecoderWithConfiguration(this.__decoderWorker,e.meta));var n={dts:e.dts,pts:e.pts||e.dts+e.cts,keyframe:e.keyframe,gopId:e.gopId,id:this._id,originPts:e.originPts};t&&(n.preciseSeek=!0,n.output=i);var r=e.data.slice();this._decoderWorker.postMessage({msg:"decode",data:r,info:n},[r.buffer])}},{key:"_initDecoderWithConfiguration",value:function(){throw new Error("need override by children")}},{key:"flushDecoder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this._decoderWorker.postMessage({msg:"flush",dropCache:e})}},{key:"destroy",value:function(){throw new Error("need override by children")}}]),i}(),encodedJs="IWZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO3ZhciBlPW51bGwsdD1bXSxzPTAsYT0hMTtzZWxmLmFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLChmdW5jdGlvbihvKXtzd2l0Y2goby5kYXRhLm1zZyl7Y2FzZSJjb25maWd1cmF0aW9uIjplPW5ldyBzZWxmLlZpZGVvRGVjb2Rlcih7b3V0cHV0OmZ1bmN0aW9uKG8pe2E9ITAscyYmY2xlYXJUaW1lb3V0KHMpO3ZhciBuPXQuc2hpZnQoKTtuP3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6IkRFQ09ERUQiLHdpZHRoOm8uZGlzcGxheVd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hVmlldyhuZXcgQXJyYXlCdWZmZXIoNCkpO2Muc2V0VWludDMyKDAsZCwhMSksbi5zZXQobmV3IFVpbnQ4QXJyYXkoYy5idWZmZXIpLDApLGkua2V5ZnJhbWUmJmUuZmx1c2goKTt2YXIgcj1uZXcgc2VsZi5FbmNvZGVkVmlkZW9DaHVuayh7dHlwZTppLmtleWZyYW1lPyJrZXkiOiJkZWx0YSIsdGltZXN0YW1wOmkucHRzLGRhdGE6bn0pO2UuZGVjb2RlKHIpO2JyZWFrO2Nhc2UiZGVzdHJveSI6ZSYmKGUuZmx1c2goKSxlLmNsb3NlKCkpLGNsZWFyVGltZW91dChzKTticmVhaztjYXNlImNoZWNrRGVjb2RlIjpzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJDSEVDS19UT19ERUNPREUiLGRhdGE6MD09PU1hdGguYWJzKGUuZGVjb2RlUXVldWVTaXplLXQubGVuZ3RoKX0pfX0pKX0oKTsK",blob="undefined"!=typeof window&&window.Blob&&new Blob([atob(encodedJs)],{type:"text/javascript;charset=utf-8"});function WorkerWrapper(){var e=blob&&(window.URL||window.webkitURL).createObjectURL(blob);try{return e?new Worker(e,{}):new Worker("data:application/javascript;base64,"+encodedJs,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}var MAX_DECODE_ONCE_DEFAULT$1=getDecodeCapacaity().maxDecodeOnceWebcodec,WebCodecDecodeController=function(e){_inherits$1(i,DecodeController);var t=_createSuper$1(i);function i(){var e;_classCallCheck$2(this,i);for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return _defineProperty$2(_assertThisInitialized$1(e=t.call.apply(t,[this].concat(r))),"TAG","WebCodecController"),_defineProperty$2(_assertThisInitialized$1(e),"_decoderMode",5),_defineProperty$2(_assertThisInitialized$1(e),"_maxDecodeOnce",MAX_DECODE_ONCE_DEFAULT$1),_defineProperty$2(_assertThisInitialized$1(e),"_continueDecodeThreshold",MAX_DECODE_ONCE_DEFAULT$1/2),_defineProperty$2(_assertThisInitialized$1(e),"_avccpushed",!1),e}return _createClass$2(i,[{key:"webcodec",get:function(){return!0}},{key:"needToDecode",get:function(){return this._inDecoding?(this._checkToDecode(),0):this._continueDecodeThreshold}},{key:"_initWorker",value:function(){var e=this;logger.log(this.TAG,"start init webcodec worker");var t=new WorkerWrapper;t.onMessage=function(t){var i,n;switch(t.data.type){case"DECODER_READY":logger.log(e.TAG,"webcodec worker ready "),e._decoderReady=!0,e._workerMessageCallback({type:"DECODER_READY"});break;case"DECODED":if(e._inDecoding=!0,(null===(i=t.data)||void 0===i||null===(n=i.info)||void 0===n?void 0:n.id)!==e._id)return;e._workerMessageCallback({type:"RECEIVE_FRAME",data:t.data});break;case"BATCH_FINISH_FLAG":if(e._inDecoding=!1,!e._workerMessageCallback)return;e._workerMessageCallback({type:"BATCH_FINISH"});break;case"CHECK_TO_DECODE":e._inDecoding=t.data.data;break;case"FAILED":e._whenError(t.data.message)}},t.onError=function(t){try{var i,n,r=null===(i=e._parent)||void 0===i||null===(n=i._parent)||void 0===n?void 0:n._parent;r&&r.removeChild(r.querySelector("canvas"))}catch(e){}e._whenError(t.message)},t.addEventListener("message",t.onMessage),t.addEventListener("error",t.onError),this._decoderWorker=t,this._initDecoderWithConfiguration(t,this._parent.configuration)}},{key:"_whenError",value:function(e){i.canUse=!1,this._workerErrorCallback(e)}},{key:"_initDecoderWithConfiguration",value:function(e,t){e.postMessage({msg:"configuration",data:{codec:this._parent._meta.codec,codedHeight:this._parent._meta.height,codedWidth:this._parent._meta.width,description:t}}),this._avccpushed=!0}},{key:"_checkToDecode",value:function(){this._decoderWorker.postMessage({msg:"checkDecode"})}},{key:"destroy",value:function(){var e=this._decoderWorker;e.removeEventListener("message",e.onMessage),e.removeEventListener("error",e.onError),e.postMessage({msg:"destroy"}),e.terminate(),this._decoderWorker=null}}],[{key:"isSupported",value:function(){return getDecodeCapacaity().h264WithWebcodec&&!!window.VideoDecoder&&!1!==i.canUse}}]),i}(),MAX_DECODE_ONCE_DEFAULT=getDecodeCapacaity().maxDecodeOnceWasm,WasmDecodeController=function(e){_inherits$1(i,DecodeController);var t=_createSuper$1(i);function i(){var e;_classCallCheck$2(this,i);for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return _defineProperty$2(_assertThisInitialized$1(e=t.call.apply(t,[this].concat(r))),"TAG","WasmController"),_defineProperty$2(_assertThisInitialized$1(e),"_avccpushed",!1),_defineProperty$2(_assertThisInitialized$1(e),"_maxDecodeOnce",MAX_DECODE_ONCE_DEFAULT),_defineProperty$2(_assertThisInitialized$1(e),"_continueDecodeThreshold",MAX_DECODE_ONCE_DEFAULT/2),_defineProperty$2(_assertThisInitialized$1(e),"_wasmInitCost",0),_defineProperty$2(_assertThisInitialized$1(e),"_threadSupported",threadSupported()&&getDecodeCapacaity().canUseThreadMode),_defineProperty$2(_assertThisInitialized$1(e),"_simdSuppported",simdSupported()),_defineProperty$2(_assertThisInitialized$1(e),"_decoderMode",window.WebAssembly?3:4),e}return _createClass$2(i,[{key:"wasmInitCost",get:function(){var e;return null===(e=this._decoderWorker)||void 0===e?void 0:e._wasmInitCost}},{key:"isHevc",get:function(){var e;return null===(e=this._parent)||void 0===e?void 0:e.isHevc}},{key:"isVvc",get:function(){var e;return null===(e=this._parent)||void 0===e?void 0:e.isVvc}},{key:"_selectDecodeWorker",value:function(){this.analyse.addWasmInit();var e,t=getDecoderUrls(),i=t.H264_DECODER_URL,n=t.H265_DECODER_URL,r=t.H265_THREAD_DECODER_URL,o=t.H265_SIMD_DECODER_URL,a=t.ASM_H264_DECODER_URL,s=t.ASM_H265_DECODER_URL,A=t.H266_DECODER_URL,u=t.H266_SIMD_DECODER_URL,c=t.H266_THREAD_DECODER_URL,d=t.H266_SIMD_THREAD_DECODER_URL;if(logger.log(this.TAG,"start init wasm worker:",performance.now(),", codec:",this.isVvc?"vvc":this.isHevc?"hevc":"avc",", decoderMode:",this._decoderMode),this.isHevc)return(e=1===this._decoderMode?r:2===this._decoderMode?o:3===this._decoderMode?n:s)?{decoder:1===this._decoderMode?new WorkerWrapper$4:new WorkerWrapper$3,url:e}:void this._workerErrorCallback("no found decoder url, decodeMode:".concat(this._decoderMode));if(this.isVvc){switch(this._decoderMode){case 0:e=d;break;case 1:e=c;break;case 2:e=u;break;default:e=A}return e?{decoder:new WorkerWrapper$2,url:e}:void this._workerErrorCallback("no found decoder url, decodeMode:".concat(this._decoderMode))}return(e=4===this._decoderMode?a:i)?{decoder:new WorkerWrapper$1,url:e}:void this._workerErrorCallback("no found decoder url, decodeMode:".concat(this._decoderMode))}},{key:"_initWorker",value:function(){this.isHevc?(this._threadSupported&&(this._decoderMode=1),this._simdSuppported&&(this._decoderMode=2)):this.isVvc&&(this._threadSupported&&this._simdSuppported?this._decoderMode=0:this._threadSupported?this._decoderMode=1:this._simdSuppported&&(this._decoderMode=2)),this._initDecodeWorkerInternal()}},{key:"_initDecodeWorkerInternal",value:function(){var e=decoderCache.getCachedDecoder(this.isVvc?"h266":this.isHevc?"h265":"h264");if(e)return logger.warn(this.TAG,"select ".concat(e.codecType," decoder from cache")),this.analyse.addWasmInit(),this._avccpushed=!1,this._bindWorkerEvent(e),this._decoderWorker=e,void(e.ready&&(this._decoderReady=!0,this._initDecoderWithConfiguration(e,this.meta),this._workerMessageCallback({type:"DECODER_READY",data:e}),logger.log(this.TAG,"decoder ready!")));var t=this._selectDecodeWorker()||{},i=t.decoder,n=t.url;i&&(this._avccpushed=!1,this._bindWorkerEvent(i),i.isHevc=this.isHevc,i.postMessage({msg:"init",meta:this.meta,batchDecodeCount:MAX_DECODE_ONCE_DEFAULT,url:n,enableLog:logger.enable,maxThreads:getDecodeCapacaity().maxDecoderThreads}),this._decoderWorker=i)}},{key:"_bindWorkerEvent",value:function(e){var t=this,i=function(i,n){logger.log(t.TAG,"worker failed: ",i,n),t._terminateWorker(e),t._decoderWorker=null,!1===getDecodeCapacaity().wasmFallbackToAsm||4===t._decoderMode?t._workerErrorCallback(i):(t._decoderMode=1===t._decoderMode||2===t._decoderMode?3:4,t._initDecodeWorkerInternal())};e._onMessage=function(n){var r,o;switch(n.data.msg){case"DECODER_READY":if(logger.log(t.TAG,"wasm worker ready!","cost:",n.data.cost),t._decoderReady=!0,e._wasmInitCost=parseInt(n.data.cost),!t.meta)return;t._avccpushed||t._initDecoderWithConfiguration(e,t.meta),t.emit(Events.VIDEO.VIDEO_DECODER_INIT,e),t._workerMessageCallback({type:"DECODER_READY",data:e});break;case"DECODED":if(t._inDecoding=!0,(null===(r=n.data)||void 0===r||null===(o=r.info)||void 0===o?void 0:o.id)!==t._id)return;t._workerMessageCallback({type:"RECEIVE_FRAME",data:n.data});break;case"BATCH_FINISH_FLAG":if(t._inDecoding=!1,!t._workerMessageCallback)return;t._workerMessageCallback({type:"BATCH_FINISH"});break;case"INIT_FAILED":i(n.data.log,1)}},e._onError=function(e){i(e.message,2)},e.addEventListener("message",e._onMessage),e.addEventListener("error",e._onError)}},{key:"_initDecoderWithConfiguration",value:function(e,t){logger.log(this.TAG,"init decoder with configuration"),this._avccpushed=!0,e.postMessage({msg:"updatemeta",meta:t});var i=t.rawVps?[t.rawVps]:t.vps,n=t.rawSps?[t.rawSps]:t.sps,r=t.rawPps?[t.rawPps]:t.pps,o=[].concat(_toConsumableArray$1(i),_toConsumableArray$1(n),_toConsumableArray$1(r)).filter(Boolean),a=o.reduce((function(e,t){return e+(t.byteLength+4)}),0),s=new Uint8Array(a),A=0;o.forEach((function(e){s.set([0,0,0,1],A),A+=4,s.set(e,A),A+=e.byteLength})),e.postMessage({msg:"initDecoder",data:s})}},{key:"destroy",value:function(){if(this._decoderWorker)return getDecodeCapacaity().reuseWasmDecoder?(this._offWorkerBind(this._decoderWorker),void decoderCache.cacheDecoder(this._decoderWorker)):void this._terminateWorker(this._decoderWorker)}},{key:"_offWorkerBind",value:function(e){e.removeEventListener("message",e._onMessage),e.removeEventListener("error",e._onError),e.postMessage({msg:"flush",dropCache:!0}),e._onMessage=null,e._onError=null,logger.log(this.TAG,"flush decoder and unbind worker event")}},{key:"_terminateWorker",value:function(e){this._offWorkerBind(e),e.postMessage({msg:"destroy"}),e.terminate(),logger.log(this.TAG,"destroy decoder worker")}}]),i}(),DECODER_ERROR_SUBCODE=1,WEBGL_ERROR_SUBCODE=2,VideoRenderWithDecoder=function(e){_inherits$1(i,VideoBaseRender);var t=_createSuper$1(i);function i(){var e;_classCallCheck$2(this,i);for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return _defineProperty$2(_assertThisInitialized$1(e=t.call.apply(t,[this].concat(r))),"TAG","VideoRenderWithDecoder"),_defineProperty$2(_assertThisInitialized$1(e),"_hideRenderFlag",0),_defineProperty$2(_assertThisInitialized$1(e),"_recentMeta",null),_defineProperty$2(_assertThisInitialized$1(e),"_inChaseFrame",!1),_defineProperty$2(_assertThisInitialized$1(e),"_decoderErrorCallback",(function(t){e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,e._assembleErr(t,DECODER_ERROR_SUBCODE))})),_defineProperty$2(_assertThisInitialized$1(e),"_decoderMessageCallback",(function(t){var i,n,r,o=t.type,a=t.data;switch(o){case"DECODER_READY":if(e.analyse.addWasmReady(),!e._frameRender){var s=Object.assign(e._config,{meta:e._meta,canvas:e._canvas,type:e._decodeController.webcodec?"2d":""});try{e._canvas.glInstance?(e._frameRender=e._canvas.glInstance,e._frameRender.updateBind(_assertThisInitialized$1(e),e._meta),logger.warn(e.TAG,"reuse canvas and context")):(e._frameRender=new FrameRender(s,_assertThisInitialized$1(e)),logger.log(e.TAG,"create frameRender with config",s))}catch(t){e._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,e._assembleErr(t&&t.message,WEBGL_ERROR_SUBCODE))}}e._startDecode();break;case"RECEIVE_FRAME":if(e._inChaseFrame&&(null===(i=e._decodeController)||void 0===i||!i.webcodec))return;e._receiveFrame(a);break;case"BATCH_FINISH":null===(n=_assertThisInitialized$1(e))||void 0===n||n._decodeEstimate.resetDecodeDot(),e._inChaseFrame&&(e._inChaseFrame=!1,e._frameQueue.empty()),e._ready||e.inSeeking||null===(r=e._decodeController)||void 0===r||!r.decoderReady||e._startDecode()}})),e}return _createClass$2(i,[{key:"wasmInitCost",get:function(){var e;return null===(e=this._decodeController)||void 0===e?void 0:e.wasmInitCost}},{key:"hevcThread",get:function(){return 1===this.decodeMode}},{key:"lowlatency",get:function(){return this._parent.lowlatency}},{key:"nextFrameTime",get:function(){var e=this._frameQueue.nextFrame();return(e&&e.info&&e.info.dts||0)/1e3}},{key:"ajustSeekTime",value:function(e,t){var i;logger.log(this.TAG,"ajust seek time: ",e),this._frameQueue.empty(),null===(i=this._decodeController)||void 0===i||i.flushDecoder(!0),this._switchVideoBuffer(e,t)}},{key:"canSeek",value:function(){return!0}},{key:"_appendChunk",value:function(e){var t;if(!this.noVideo&&this._timeRange){if(this._meta){if(this._recentMeta.width!==e.width||this._recentMeta.height!==e.height){logger.warn(this.TAG,"metadata changed! width: ".concat(this._recentMeta.width," -> ").concat(e.width,", height: ").concat(this._recentMeta.height," -> ").concat(e.height));var i=e.samples[0];i&&(this._recentMeta=i.meta=Object.assign({},e,{samples:null}))}}else{this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.LOADEDMETADATA),this._recentMeta=this._meta=Object.assign({},e,{samples:null}),logger.warn(this.TAG,"video set metadata",this._meta,"configuration:",this.configuration);var n=e.fpsNum/e.fpsDen;n?logger.log(this.TAG,"detect fps:",n):logger.warn(this.TAG,"no detect fps,start estimate"),this._selectDecoder(),this._initDecoder()}if(this._timeRange.append(e.samples,this._isLive&&this.noAudio,!this.videoDecode),e.samples=[],!this.inSeeking){var r;if(this.isLive||this._timeRange.frameLength||this._switchVideoBuffer(this._parent.currentTime),!this._ready&&null!==(t=this._decodeController)&&void 0!==t&&t.decoderReady)!this.noAudio&&null!==(r=this._decodeController)&&void 0!==r&&r.inDecoding||this._startDecode();this.noAudio&&this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.DURATION_CHANGE)}}}},{key:"_selectDecoder",value:function(){if(!this.isHevc&&!this.isVvc&&WebCodecDecodeController.isSupported())return this._decodeController=new WebCodecDecodeController(this),void(this._decodeEstimate.webcodec=!0);this._decodeController=new WasmDecodeController(this)}},{key:"_initDecoder",value:function(){var e;null===(e=this._decodeController)||void 0===e||e.init(this._decoderMessageCallback,this._decoderErrorCallback)}},{key:"_startDecode",value:function(){var e;null===(e=this._decodeController)||void 0===e||e.doDecode()}},{key:"_switchVideoBuffer",value:function(e,t){var i=this._timeRange.switchBuffer(e);if(i){var n;if(this.noAudio&&this._parent.emit(Events.TIMELINE.SYNC_DTS,this.getDtsOfTime(i.start)),t)return void(null===(n=this._decodeController)||void 0===n||n.preciseSeek(e));this._startDecode(t)}}},{key:"_checkToDecode",value:function(){var e;this.inSeeking||null===(e=this._decodeController)||void 0===e||e.checkToDecode(this._frameQueue.length)}},{key:"_render",value:function(e){var t;if(!this.noVideo){var i=this._frameQueue&&this._frameQueue.nextFrame();if(i){var n=i.info;if(!n)return this._frameQueue.shift(),void console.error("not info");this._renderDts=n.dts;var r=n.dts-this.preciseVideoDts;if(!(!e&&r>0&&r<6e4)){this._frameQueue.shift(this.preciseVideoDts),Math.abs(this._lastTimeupdate-n.dts)>250&&(this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.TIMEUPDATE,{pts:n.originPts}),this._lastTimeupdate=n.dts),logger.long&&logger.log(this.TAG,"render delay:".concat(r," , timelinePosition:").concat(this.preciseVideoDts," , dts:").concat(n.dts," , cost:").concat(n.cost," , gopID:").concat(n.gopId," , rest:").concat(this._frameQueue.length,", buffer frame:").concat(this._timeRange.frameLength));var o=performance.now();this._hideRenderFlag++,("visible"===document.visibilityState||this._hideRenderFlag%15)&&this._frameRender.render(i.buffer,i.width,i.height,i.yLinesize,i.uvLinesize),null!==(t=this._decodeController)&&void 0!==t&&t.webcodec&&i.buffer.close(),this._renderCost=performance.now()-o,this._checkToDecode()}}else{var a;if(logger.log(this.TAG,"lack frame, ","inDecoding:",null===(a=this._decodeController)||void 0===a?void 0:a.inDecoding),this._checkToDecode(),this.noAudio){var s;if(!this.isLive&&Math.abs(this.currentTime-this.duration)<.5)return null==this||this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.TIMEUPDATE),null==this||this._emitTimelineEvents(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ENDED),void(null===(s=this._timeRange)||void 0===s||s.clean());this._timeRange.frameLength||(this._ready=!1,this.emit(Events.VIDEO.VIDEO_WAITING))}}}}},{key:"_updateSegmentEnd",value:function(e){var t;null===(t=this._timeRange)||void 0===t||t.updateSegmentEnd(e)}},{key:"_doChaseFrame",value:function(e){var t=e.frame;this._inChaseFrame=!0,this._timeRange.deletePassed(t.dts),this._frameQueue.empty(),this.noAudio&&this._parent.emit(Events.TIMELINE.SYNC_DTS,t.dts)}},{key:"_destroy",value:function(e){var t;logger.log(this.TAG,"destroy video render"),_get(_getPrototypeOf$1(i.prototype),"destroy",this).call(this,e),null===(t=this._decodeController)||void 0===t||t.destroy(),this._decodeController=null}}]),i}(),TOLERANCE=.1,TimeLine=function(e){_inherits$1(i,EventEmitter);var t=_createSuper$1(i);function i(e,n){var r;return _classCallCheck$2(this,i),(r=t.call(this)).TAG="TimeLine",r._parent=n,r._seeking=!1,r.audioRender=AudioMseRender.isSupported()?new AudioMseRender(e,_assertThisInitialized$1(r)):new AudioRender(e,_assertThisInitialized$1(r)),r.videoRender=r._getController(n.videoDecode,e),r._readyStatus={audio:!1,video:!1},r._paused=!0,r._switchToMultiWorker=!1,r._lowdecodeEmited=!1,r._startPlayed=!1,r._emitReady=!1,r._lastSeekTime=1e-4,r._singleTrack=-1,r._bindEvent(),r._decodeVideo=e.video,r}return _createClass$2(i,[{key:"renderReady",get:function(){return this._emitReady}},{key:"analyse",get:function(){return this._parent.analyse}},{key:"ready",get:function(){return this._readyStatus.video&&this._readyStatus.audio}},{key:"played",get:function(){var e=this;return{length:this.currentTime?1:0,start:function(){return 0},end:function(){return e.currentTime}}}},{key:"noAudio",get:function(){return 1===this._singleTrack||2===this._singleTrack}},{key:"isLive",get:function(){return this._parent.live}},{key:"seeking",get:function(){return this._seeking}},{key:"decodeFps",get:function(){return this.videoRender.decodeFps}},{key:"decodeCost",get:function(){return this.videoRender.decodeCost}},{key:"renderCost",get:function(){return this.videoRender.renderCost}},{key:"wasmInitCost",get:function(){return this.videoRender.wasmInitCost}},{key:"fps",get:function(){return this.videoRender.fps}},{key:"totalSize",get:function(){return this.videoRender.totalSize}},{key:"bitrate",get:function(){return this.videoRender.bitrate}},{key:"gopLength",get:function(){return this.videoRender.gopLength}},{key:"currentTime",get:function(){return this.noAudio?this.paused?this.videoRender.nextFrameTime:this.videoRender.currentTime:this.audioRender.currentTime}},{key:"timelinePosition",get:function(){return this.noAudio?performance.now()/1e3:this.audioRender.currentTime}},{key:"canvas",get:function(){return this.videoRender.canvas}},{key:"readyState",get:function(){return this.videoRender.readyState}},{key:"buffered",get:function(){var e=this;return this.noAudio?this.videoRender.buffered:this.isLive?this.audioRender.buffered:{length:this.audioRender.buffered.length,start:function(t){return Math.max(e.audioRender.buffered.start(t),e.videoRender.buffered.start(t))},end:function(t){return Math.min(e.audioRender.buffered.end(t),e.videoRender.buffered.end(t))}}}},{key:"duration",get:function(){return this.noAudio?this.videoRender.duration:this.isLive?this.audioRender.duration:Math.min(this.audioRender.duration,this.videoRender.duration)}},{key:"paused",get:function(){return this._paused},set:function(e){this._paused=e}},{key:"lowlatency",get:function(){return this._parent.lowlatency}},{key:"decoderMode",get:function(){return this.videoRender.decoderMode}},{key:"currentAudioCanAutoplay",get:function(){return this.audioRender.audioCanAutoplay}},{key:"_getController",value:function(e,t){return e?new VideoRenderFromVideo(t,this):new VideoRenderWithDecoder(t,this)}},{key:"_checkInBuffer",value:function(){for(var e=this.buffered,t=0,i=e.length;t<i;t++)if(e.start(t)<=this.currentTime+TOLERANCE&&e.end(t)>=this.currentTime)return!0;return!1}},{key:"_resetReadyStatus",value:function(){this._readyStatus.audio=!1,this._readyStatus.video=!1}},{key:"_bindEvent",value:function(){var e=this;this.on(Events.DECODE_EVENTS.REMUX,(function(t){e.videoRender.setRemux(t)})),this.on(Events.DECODE_EVENTS.CHASE_VIDEO_FRAME_END,(function(t){e.emit(Events.DECODE_EVENTS.CHASE_AUDIO_FRAME,t)})),this.audioRender.on(Events.AUDIO.AUDIO_READY,(function(){logger.log(e.TAG,"audio ready! seeking=",e._seeking),e._seeking&&setTimeout((function(){try{var t=e.videoRender.getSeekStartPosition(e.currentTime,1/0);if(e.audioRender.isMse&&t)return getDecodeCapacaity().preciseSeek>e.duration&&e.currentTime>TOLERANCE?(e.audioRender.seekNoSideEffect({position:e.currentTime+TOLERANCE}),void e.videoRender.ajustSeekTime(e.currentTime,!0)):(e.audioRender.seekNoSideEffect({position:t.position+TOLERANCE}),void e.videoRender.ajustSeekTime(t.position));e.videoRender.ajustSeekTime(e.currentTime)}catch(e){}}),10),e._readyStatus.video&&e._startRender(),e._readyStatus.audio=!0,e._startPlayed||e.analyse.addAudioReady()})),this.audioRender.on(Events.AUDIO.AUDIO_NOT_ALLOWED_AUTOPLAY,(function(){e._emitReady&&e.pause()})),this.audioRender.on(Events.AUDIO.AUDIO_WAITING,(function(){!e.noAudio&&e.currentTime&&(logger.warn(e.TAG,"lack data, audio waiting,currentTime:",e.currentTime),e.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.TIMEUPDATE),e.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.WAITING),e.emit(Events.TIMELINE.DO_PAUSE),e._readyStatus.audio=!1)})),this.videoRender.on(Events.VIDEO.VIDEO_WAITING,(function(){logger.warn(e.TAG,"lack data, video waiting"),e.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.WAITING),e.emit(Events.TIMELINE.DO_PAUSE),e._readyStatus.video=!1})),this.videoRender.on(Events.VIDEO.VIDEO_READY,(function(){logger.log(e.TAG,"video ready!"),e._startPlayed||e.analyse.addVideoReady(),e._readyStatus.audio&&e._startRender("video"),e._readyStatus.video=!0})),this.videoRender.on(Events.VIDEO.DECODE_LOW_FPS,(function(){e.currentTime<2||(e.analyse.increaseLowDecodeCount(),e._lowdecodeEmited||(updateLowdecodeVV(),e._lowdecodeEmited=!0),e.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.LOW_DECODE))})),this.on(Events.TIMELINE.SINGLE_TRACK,(function(t){e._singleTrack=t,1!==t&&2!==t||(e._readyStatus.audio=!0),3===t&&(e._readyStatus.video=!0),e.emit(Events.TIMELINE.SYNC_DTS,0)})),this.on(Events.TIMELINE.DESTROY,(function(){e.removeAllListeners(),e.videoRender=null,e.audioRender=null})),this.on(Events.TIMELINE.DO_PLAY,(function(){e.emit(Events.TIMELINE.START_RENDER),e._paused=!1,e._lastSeekTime=1e-4,e.noAudio&&e.emit(Events.TIMELINE.SYNC_DTS,0)}))}},{key:"_startRender",value:function(e){!this._parent.error&&this.videoRender&&(this.noAudio&&this.emit(Events.TIMELINE.SYNC_DTS,0),this.videoRender.forceRender(),this._startPlayed||(this.analyse.addFirstframe(),this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.LOADEDDATA),this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.FIRST_FRAME),this._startPlayed=!0),logger.log(this.TAG,"emit canplay"),this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.CANPLAY),!this.isLive&&this._paused&&this._seeking||(this._parent.autoplay?(logger.warn(this.TAG,"startRender: time=",this.currentTime,"paused:",this.paused,"seeking:",this.seeking),this.emit(Events.TIMELINE.START_RENDER,e)):(this._parent.autoplay=!0,this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PAUSE))),this.emit(Events.TIMELINE.READY),this._emitReady=!0,this._seeking&&this._checkInBuffer()&&(logger.log(this.TAG,"set seeking = false"),this._seeking=!1,this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.SEEKED),logger.groupEnd()))}},{key:"_checkHlsTracks",value:function(e){if(!(null==e?void 0:e.samples[0])){if(!this.buffered.length){var t=new Error("lack video sample");t.code=3,this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,t)}return!1}return!0}},{key:"appendBuffer",value:function(e,t){this.emit(Events.TIMELINE.APPEND_CHUNKS,e,t),this.noAudio&&this._seeking&&this.videoRender.ajustSeekTime(this.currentTime)}},{key:"play",value:function(){var e=this;return new Promise((function(t,i){var n=e.currentAudioCanAutoplay;e.noAudio?n=!0:e.audioRender&&e.audioRender.resume().then((function(){logger.log(e.TAG,"audio render resumed, pause status: ".concat(e._paused,", audioCanAutoplay:").concat(e.currentAudioCanAutoplay)),e._paused?e.emit(Events.TIMELINE.DO_PAUSE):n=!0})).catch((function(){logger.warn(e.TAG,"audio render resume failed")})),setTimeout((function(){return logger.log(e.TAG,"play() timer done, resumed=".concat(n,", paused=").concat(e.paused)),n?e.videoRender&&!e.videoRender.canAutoPlay?(console.warn("video render an't autoplay"),e.pause(),void i({name:"NotAllowedError"})):(e.emit(Events.TIMELINE.DO_PLAY),e._paused=!1,void t()):e.paused?void 0:(logger.log(e.TAG,"audioCtx can't autoplay"),e.pause(),void i({name:"NotAllowedError"}))}),e.audioRender.isMse?10:60)}))}},{key:"pause",value:function(){this._paused||!this.ready&&!this._seeking||(this.emit(Events.TIMELINE.DO_PAUSE),this._paused=!0,this.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.PAUSE))}},{key:"seek",value:function(e){var t=this;if(this._seeking&&logger.groupEnd(),this.isLive){if(this.currentTime<TOLERANCE||!this.currentAudioCanAutoplay||this.paused)return;var i=this.videoRender.getSeekStartPosition(e,this._parent.preloadTime+1);if(i){if(i.position<this.currentTime)return;var n=this.audioRender.canSeek(i.position),r=this.videoRender.canSeek(i);if(!n||!r)return void logger.log(this.TAG,"seek, !!!!!!!!!can not seek, audioCanSeek:",n,"videoCanSeek:",r);logger.warn(this.TAG,"seek, chase frame to time: ",i.position,"currentTime:",this.currentTime,"duration:",this.duration),this.videoRender.videoDecode?(this.audioRender.doPause(),i.position=i.position-1.5,this.emit(Events.DECODE_EVENTS.CHASE_VIDEO_FRAME,i)):this.emit(Events.TIMELINE.CHASE_FRAME,i)}}else this._lastSeekTime!==e&&(e&&Math.abs(this._lastSeekTime-e)<=.2||(this._lastSeekTime=e,e>=this.duration&&(e=this.duration-1),e<0&&(e=0),logger.group(this.TAG,"start seek to:".concat(e,", set seeking status=true")),this._seeking=!0,this.videoRender.setSeekingStatus(!0),this.noAudio?(this.emit(Events.TIMELINE.SYNC_DTS,this.videoRender.getDtsOfTime(e)),this.videoRender.ajustSeekTime(e)):this._resetReadyStatus(),this.emit(Events.TIMELINE.DO_SEEK,e),new Promise((function(e){t.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.SEEKING),e()}))))}}]),i}(),VIDEO_DECODE_MODE_VALUE="7",SINGLE_TRACK_TYPE={LOW_LATENCY:1,NO_AUDIO:2,NO_VIDEO:3},Parent="undefined"!=typeof HTMLElement?HTMLElement:function(){},XGVideo=function(e){_inherits$1(i,Parent);var t=_createSuper$1(i);function i(){var e;return _classCallCheck$2(this,i),(e=t.call(this)).TAG="XGVideo",e._proxyProps(),e._isLive=!0,e._vMeta=null,e._aMeta=null,e._resizeObserver=null,e._eventsBackup=[],e._hevc="h265"===getDecodeCapacaity().preloadDecoder,e._hevc||(e._degradeVideo=document.createElement("video")),e._debounceSeek=debounce(e._seek.bind(_assertThisInitialized$1(e)),300),e._onTouchEnd=e._onTouchEnd.bind(_assertThisInitialized$1(e)),e.analyse=new Analyse,e}return _createClass$2(i,[{key:"_proxyProps",value:function(){var e=this;Object.getOwnPropertyNames(i.prototype).forEach((function(t){if(/^__/.test(t)){var i=t.replace("__","");Object.defineProperty(e,i,{get:function(){try{return this[t]}catch(e){}return 0},set:function(e){try{this[t]=e}catch(e){}}})}}))}},{key:"addEventListener",value:function(e,t,n){_get(_getPrototypeOf$1(i.prototype),"addEventListener",this).call(this,e,t,n),this._degradeVideo&&this._eventsBackup.push([e,t,n])}},{key:"removeEventListener",value:function(e,t,n){_get(_getPrototypeOf$1(i.prototype),"removeEventListener",this).call(this,e,t,n),this._degradeVideo&&(this._eventsBackup=this._eventsBackup.filter((function(i){return!(i.eventName===e&&i.handler===t&&i.capture===n)})))}},{key:"setAttribute",value:function(e,t){var n;_get(_getPrototypeOf$1(i.prototype),"setAttribute",this).call(this,e,t),"src"!==e&&(null===(n=this._degradeVideo)||void 0===n||n.setAttribute(e,t))}},{key:"canPlayType",value:function(e){if(""===e||"application/octet-stream"===e)return"";var t=_slicedToArray$1(e.split(/;(?: )?codecs=/i),2),i=t[0],n=t[1],r=_slicedToArray$1(i.split("/"),2),o=r[0];r[1];var a=(null==n?void 0:n.replace(/"/g,"").split(","))||[];if("video"===o&&"video/mp4"===i){var s=/^avc1\./i,A=/^(hev1|hvc1)\./i,u=/^bvc2\./i;return a.some((function(e){return s.test(e)}))||(a.some((function(e){return A.test(e)}))||a.some((function(e){return u.test(e)})))?"probably":n?"":"maybe"}return"audio"===o&&"audio/mpeg"===i?"maybe":""}},{key:"_init",value:function(){this.analyse.reset(),this.timeline=new TimeLine({volume:this.volume,canvas:this.querySelector("canvas"),videoContext:this.videoContext,videoDecode:this.videoDecode,maxVideoHeight:this.getAttribute("maxVideoHeight"),endLevel:parseInt(this.getAttribute("endLevel"))},this),logger.log(this.TAG,"timeline init"),this._noSleep=new NoSleep,this._logFirstFrame=!1,this._playRequest=null,this._degradeVideoUserGestured=!1,this._bindEvents(),this._vMeta&&!this.videoDecode&&this.setVideoMeta(this._vMeta),this._glCtxOptions&&(this.glCtxOptions=this._glCtxOptions),this.timeline&&(this.innerDegrade&&this.timeline.emit(Events.TIMELINE.INNER_DEGRADE),this.timeline.emit(Events.TIMELINE.SET_PLAY_MODE,this._isLive?"LIVE":"VOD"),this.timeline.emit(Events.TIMELINE.SET_PLAYBACKRATE,this.playbackRate),this.muted=this.muted)}},{key:"_bindEvents",value:function(){var e=this;this.timeline.on(Events.TIMELINE.PLAY_EVENT,(function(t,i){var n;t===VIDEO_EVENTS.LOADEDDATA&&(e.querySelector("canvas")||(logger.log(e.TAG,"_bindEvents, appendChild canvas"),e.appendChild(e.canvas)),e.canvas.style.display="block",null===(n=e.timeline)||void 0===n||n.emit(Events.TIMELINE.SET_PLAYBACKRATE,e.playbackRate));if(t!==VIDEO_EVENTS.LOADEDMETADATA&&t!==VIDEO_EVENTS.RESIZE||Promise.resolve().then((function(){e.updateVideoPostion()})),t===VIDEO_EVENTS.ERROR){if(logger.warn(e.TAG,"detect error:",null==i?void 0:i.message),e.pause(),e._disabled(!0),e.innerDegrade||5===e.decoderMode)return e.degradeInfo={decodeFps:e.decodeFps,bitrate:e.bitrate,wasmInitCost:e.wasmInitCost,fps:e.fps,url:e.src,msg:null==i?void 0:i.message,decoderMode:e.decoderMode},void e._innerDispatchEvent("lowdecode");e._err=i}if(t===VIDEO_EVENTS.LOW_DECODE)return e._disabled(),e.degradeInfo={decodeFps:e.decodeFps,bitrate:e.bitrate,wasmInitCost:e.wasmInitCost,fps:e.fps,url:e.src,decoderMode:e.decoderMode},void e._innerDispatchEvent(VIDEO_EVENTS_ARR[t],e.degradeInfo);if(t===VIDEO_EVENTS.LARGE_AV_GAP&&(e.unsyncInfo=i),t===VIDEO_EVENTS.ENDED){if(e.paused)return;e.pause()}t===VIDEO_EVENTS.PROGRESS&&e._noSleep.toPlay(),t===VIDEO_EVENTS.WAITING&&e.analyse.addWaiting(),t===VIDEO_EVENTS.SEEKING&&e.analyse.addSeeking(),t===VIDEO_EVENTS.SEEKED&&e.analyse.addSeeked(),e._innerDispatchEvent(VIDEO_EVENTS_ARR[t],i)}))}},{key:"_disabled",value:function(e){(this.innerDegrade||e)&&(e?getDecodeCapacaity().disabledWhenErrorOccur&&persistenceDisabledStatus(1):getDecodeCapacaity().evaluateVVCount||(this.decodeFps/this.fps<=.6&&this.bitrate<2e6?persistenceDisabledStatus(1):persistenceDisabledStatus(2)))}},{key:"degrade",value:function(e){var t=this;Boolean(this.querySelector("canvas"))?this.replaceChild(this._degradeVideo,this.canvas):this.appendChild(this._degradeVideo),this._eventsBackup.forEach((function(e){var n,r=_slicedToArray$1(e,3),o=r[0],a=r[1],s=r[2];_get(_getPrototypeOf$1(i.prototype),"removeEventListener",t).call(t,o,a,s),null===(n=t._degradeVideo)||void 0===n||n.addEventListener(o,a,s)})),this._eventsBackup=[],this.destroy(),e&&(this._degradeVideo.muted=!1,this._degradeVideo.src=e,this._degradeVideo.load())}},{key:"disconnectedCallback",value:function(){logger.log(this.TAG,"video disconnected"),document.removeEventListener("touchend",this._onTouchEnd,!0),this.destroy(!0),this._resizeObserver&&this._resizeObserver.disconnect(this)}},{key:"connectedCallback",value:function(){var e=this;logger.log(this.TAG,"video connected to document",performance.now()),this.timeline||this._init(),this.style.width="100%",this.style.height="100%",this.style.position="absolute",this.style.left="0px",this.style.top="0px",document.addEventListener("touchend",this._onTouchEnd,!0),ResizeObserver&&(this._resizeObserver=new ResizeObserver((function(t){var i;null!==(i=e.timeline)&&void 0!==i&&i.ready&&e.updateVideoPostion()})),this._resizeObserver.observe(this))}},{key:"_onTouchEnd",value:function(){playSlienceAudio(),this._degradeVideoInteract(),this._noSleep&&this._noSleep.enable()}},{key:"_degradeVideoInteract",value:function(){var e=this;if(this._degradeVideo&&(1===this.innerDegrade||3===this.innerDegrade)){if(this._degradeVideoUserGestured)return;var t=this._degradeVideo.play();t&&t.then((function(){e._degradeVideo.pause(),e._degradeVideoUserGestured=!0})).catch((function(e){console.log("degrade video: ",e.message)}))}}},{key:"play",value:function(e){var t=this;if(this.timeline){logger.log(this.TAG,"play() called, ready:".concat(this.timeline.ready,", paused:").concat(this.timeline.paused,", force:").concat(e)),this._degradeVideoInteract();var i=0;if(this.timeline.ready&&this.timeline.paused||e){if(e=e||this._isLive,this._playRequest=null,!e)return this.timeline.emit(Events.TIMELINE.DO_PLAY),this._innerDispatchEvent("play"),Promise.resolve();this.destroy(),this._init(),i=setTimeout((function(){try{t._innerDispatchEvent("waiting")}catch(e){}}),300)}return this._playRequest||!this.timeline.ready||this.timeline.paused?(logger.log(this.TAG,"request play!"),this._playRequest=this._playRequest||new Promise((function(e,n){t.timeline._paused=!1,t._innerDispatchEvent("play"),t._noSleep.enable();var r=function(){logger.log(t.TAG,"timeline emit ready"),clearTimeout(i),t.timeline.play().then(e).catch(n).finally((function(){t._playRequest=null}))};t.timeline.renderReady?r():t.timeline.once(Events.TIMELINE.READY,r)})),this.autoplay=!0,this._playRequest):Promise.resolve()}}},{key:"pause",value:function(){this._playRequest=null,this.timeline&&this.timeline.pause();try{this._noSleep.disable(),pauseSlienceAudio()}catch(e){}}},{key:"load",value:function(){}},{key:"appendBuffer",value:function(e,t){if(this.timeline&&!this._err){if(!this._logFirstFrame){var i=e&&e.samples[0],n=t&&t.samples[0];if(!i&&!n)return;if(i||n){var r=(null==e?void 0:e.duration)/((null==e?void 0:e.formatTimescale)||1/0),o=(null==t?void 0:t.duration)/((null==t?void 0:t.formatTimescale)||1/0);logger.warn(this.TAG,"video firstDts:".concat(i&&i.dts," , audio firstDts:").concat(n&&n.dts," videoTrack.duration=").concat(r,", audioTrack.duration=").concat(o)),this._logFirstFrame=!0,(r||o)&&(this.setPlayMode("VOD"),this.timeline.emit(Events.TIMELINE.SET_PLAY_MODE,this._isLive?"LIVE":"VOD"),this.duration=Math.min(r||o,o||r)),this.analyse.addFirstData()}this.lowlatency&&(logger.warn(this.TAG,"single track! type=",SINGLE_TRACK_TYPE.LOW_LATENCY),this.timeline.emit(Events.TIMELINE.SINGLE_TRACK,SINGLE_TRACK_TYPE.LOW_LATENCY)),t.exist()||(logger.warn(this.TAG,"single track! type=",SINGLE_TRACK_TYPE.NO_AUDIO),this.timeline.emit(Events.TIMELINE.SINGLE_TRACK,SINGLE_TRACK_TYPE.NO_AUDIO)),e.exist()||(logger.warn(this.TAG,"single track! type=",SINGLE_TRACK_TYPE.NO_VIDEO),this.timeline.emit(Events.TIMELINE.SINGLE_TRACK,SINGLE_TRACK_TYPE.NO_VIDEO))}e.formatTimescale&&e.samples.forEach((function(t){t.dts=Math.floor(t.dts/e.formatTimescale*1e3),t.pts=Math.floor(t.pts/e.formatTimescale*1e3)})),t.formatTimescale&&t.samples.forEach((function(e){e.dts=Math.floor(e.dts/t.formatTimescale*1e3),e.pts=Math.floor(e.pts/t.formatTimescale*1e3)})),this.timeline.appendBuffer(e,t)}}},{key:"setAudioMeta",value:function(e){this._aMeta=e,this.timeline.emit(Events.TIMELINE.SET_METADATA,"audio",e)}},{key:"setVideoMeta",value:function(e){!this._isLive&&this._vMeta||(this.timeline.emit(Events.TIMELINE.SET_METADATA,"video",e),this._vMeta=e)}},{key:"setDecodeMode",value:function(e){this.setAttribute("decodeMode",e)}},{key:"setPlayMode",value:function(e){this._isLive="LIVE"===e}},{key:"endOfStream",value:function(){var e;this.currentTime&&(null===(e=this.timeline)||void 0===e||e.emit(Events.TIMELINE.END_OF_STREAM))}},{key:"updateVideoPostion",value:function(){var e;null===(e=this.timeline)||void 0===e||e.emit(Events.VIDEO.UPDATE_VIDEO_FILLTYPE,this.xgfillType,this.containerLayout)}},{key:"_innerDispatchEvent",value:function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}},{key:"destroy",value:function(e){this.timeline&&(this._noSleep.destroy(),logger.log(this.TAG,"call destroy"),this.timeline.emit(Events.TIMELINE.DESTROY,e),this.querySelector("video")&&this.removeChild(this.querySelector("video")),this.timeline=null,this._err=null,this._noSleep=null,this._eventsBackup=[])}},{key:"updateObjectPosition",value:function(e,t){this.timeline.emit(Events.VIDEO.UPDATE_VIDEO_COVER_POSITION,this.containerLayout,e,t),this._degradeVideo&&(this._degradeVideo.style.objectPosition="".concat(100*e,"% ").concat(100*t,"%"))}},{key:"setVideoDecode",value:function(){logger.log(this.TAG,"set videoDecode",this.videoDecode),this.videoDecode&&this.timeline&&this.timeline.videoRender&&(this.timeline.videoRender.videoDecode=this.videoDecode)}},{key:"live",get:function(){return this._isLive}},{key:"lowlatency",get:function(){return"true"===this.getAttribute("lowlatency")},set:function(e){this.setAttribute("lowlatency",e)}},{key:"autoplay",get:function(){return"true"===this.getAttribute("autoplay")},set:function(e){this.setAttribute("autoplay",e)}},{key:"__canvas",get:function(){return this.timeline.canvas}},{key:"__ended",get:function(){return Math.abs(this.currentTime-this.duration)<.5}},{key:"__width",get:function(){return this.getAttribute("width")||this.videoWidth},set:function(e){var t="number"==typeof e?"".concat(e,"px"):e;this.setAttribute("width",t),this.canvas.width=e}},{key:"__height",get:function(){return this.getAttribute("height")},set:function(e){var t="number"==typeof e?"".concat(e,"px"):e;this.setAttribute("height",t),this.canvas.height=e}},{key:"__videoWidth",get:function(){return this.canvas.width}},{key:"__videoHeight",get:function(){return this.canvas.height}},{key:"__volume",get:function(){return Number(this.getAttribute("volume"))},set:function(e){e<=0&&(e=0),e>=1&&(e=1),this.setAttribute("volume",e),this.muted||this.timeline.emit(Events.TIMELINE.UPDATE_VOLUME,e)}},{key:"__muted",get:function(){return"true"===this.getAttribute("muted")},set:function(e){this.setAttribute("muted",e),this._degradeVideoInteract(),this._noSleep.enable(),this.timeline.emit(Events.TIMELINE.UPDATE_VOLUME,e?0:this.volume)}},{key:"__currentTime",get:function(){if(!this.timeline)return 0;var e=this.timeline.currentTime,t=this.timeline.duration;return Math.min(e,t)},set:function(e){this._debounceSeek(e)}},{key:"_seek",value:function(e){this.timeline&&(this.buffered.length||this.play(),this.paused&&!this._isLive&&0===e&&this.play(),this.timeline.seek(Number(e)))}},{key:"__duration",get:function(){return this._isLive?1/0:this.timeline.duration},set:function(e){this.timeline.emit(Events.TIMELINE.SET_VIDEO_DURATION,e),this._innerDispatchEvent("durationchange")}},{key:"__seeking",get:function(){return this.timeline.seeking}},{key:"__paused",get:function(){return this.timeline.paused}},{key:"__fps",get:function(){return this.timeline.fps}},{key:"__decodeFps",get:function(){return this.timeline.decodeFps}},{key:"__decodeCost",get:function(){return parseInt(this.timeline.decodeCost)}},{key:"__renderCost",get:function(){return this.timeline.renderCost}},{key:"__wasmInitCost",get:function(){return this.timeline.wasmInitCost}},{key:"__totalSize",get:function(){return this.timeline.totalSize}},{key:"__bitrate",get:function(){return this.timeline.bitrate}},{key:"__gopLength",get:function(){return this.timeline.gopLength}},{key:"__readyState",get:function(){return this.timeline.readyState}},{key:"__buffered",get:function(){return this.timeline.buffered}},{key:"__decoderMode",get:function(){return this.timeline.decoderMode}},{key:"src",get:function(){return this.getAttribute("src")||""},set:function(e){logger.log(this.TAG,"set src ",e),this.setAttribute("src",e),this._vMeta=null,this.play(!0),this.timeline||this._init(),this._innerDispatchEvent("loadstart"),updateVV()}},{key:"currentSrc",get:function(){return this.getAttribute("src")||""}},{key:"playbackRate",get:function(){return parseFloat(this.getAttribute("playbackrate")||1)},set:function(e){var t;this.setAttribute("playbackrate",e),null===(t=this.timeline)||void 0===t||t.emit(Events.TIMELINE.SET_PLAYBACKRATE,e)}},{key:"networkState",get:function(){return 1}},{key:"preloadTime",get:function(){var e=this.getAttribute("preloadtime");if(e){var t=Number.parseFloat(e);if(t>0&&!Number.isNaN(t))return t}return 1/0},set:function(e){e&&Number(e)>0&&this.setAttribute("preloadtime",e)}},{key:"innerDegrade",get:function(){var e=this.getAttribute("innerdegrade");return parseInt(e)}},{key:"__glCtxOptions",set:function(e){this._glCtxOptions=e,this.timeline.emit(Events.TIMELINE.UPDATE_GL_OPTIONS,e)}},{key:"__error",get:function(){return this._err},set:function(e){this.timeline.emit(Events.TIMELINE.PLAY_EVENT,VIDEO_EVENTS.ERROR,e)}},{key:"degradeVideo",get:function(){return this._degradeVideo}},{key:"degradeInfo",get:function(){return this._deradeInfo},set:function(e){this._deradeInfo=e}},{key:"unsyncInfo",get:function(){return this._unsyncInfo},set:function(e){this._unsyncInfo=e}},{key:"xgfillType",get:function(){return this.parentNode.getAttribute("data-xgfill")}},{key:"containerLayout",get:function(){var e=this.parentNode;return{width:e.clientWidth,height:e.clientHeight}}},{key:"videoDecode",get:function(){return this.getAttribute("decodeMode")===VIDEO_DECODE_MODE_VALUE}},{key:"audioMedia",get:function(){var e,t;return null===(e=this.timeline)||void 0===e||null===(t=e.audioRender)||void 0===t?void 0:t.media}},{key:"getStats",value:function(){return this.analyse.getStats(this)}},{key:"getSeekElapses",value:function(){return this.analyse.seekElapses()}},{key:"dump",value:function(){var e=this.buffered;return console.log(e),new Array(e.length).fill(0).map((function(t,i){return[e.start(i),e.end(i)]}))}}],[{key:"version",get:function(){return"0.2.5-rc.3"}},{key:"init",value:function(e){var t=e.h264Url,n=e.h264AsmUrl,r=e.h265AsmUrl,o=e.h265Url,a=e.h265ThreadUrl,s=e.h265SimdUrl,A=e.h266Url,u=e.h266SimdUrl,c=e.h266PthreadUrl,d=e.h266SimdPthreadUrl;i.h264Url=t,i.h265Url=o,i.h265AsmUrl=r,i.h264AsmUrl=n,i.h265ThreadUrl=a,i.h265SimdUrl=s,i.h266Url=A,i.h266SimdUrl=u,i.h266PthreadUrl=c,i.h266SimdPthreadUrl=d}},{key:"getDecodeCapacity",value:function(){return getDecodeCapacaity()}},{key:"getDeviceCapacity",value:function(){return getDeviceCapacity()}},{key:"setDecodeCapacity",value:function(e){setDecodeCapacity(e),e.preloadDecoder&&decoderCache.genDecoder().catch((function(){}))}},{key:"genDecoder",value:function(e){return decoderCache.genDecoder(e)}},{key:"cleanDisabled",value:function(){cleanDisabledStatus()}},{key:"isSupported",value:function(){return!!softDecodeSupported()&&!1===getDisabledStatus()}}]),i}();_defineProperty$2(XGVideo,"decoderCache",decoderCache);var H264_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/decoder/1.1.1/h264/decoder.js",ASM_H264_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/decoder/1.1.1/h264/decoder_asm.js",H265_SIMD_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/codec/high/decoder_1656041798666.js",H265_THREAD_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/codec/main/decoder.js",H265_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/codec/base/decoder.js",ASM_H265_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/codec/high/decoder_asm.js",H266_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/decoder/vvc/decoder_20250716143203.js",H266_SIMD_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/decoder/vvc/decoder_simd_20250716143203.js",H266_PTHREAD_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/decoder/vvc/decoder_pthread_20250716143203.js",H266_SIMD_PTHREAD_DECODER_URL="https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/decoder/vvc/decoder_simd_pthread_20250716143203.js";XGVideo.init({h264Url:H264_DECODER_URL,h264AsmUrl:ASM_H264_DECODER_URL,h265Url:H265_DECODER_URL,h265SimdUrl:H265_SIMD_DECODER_URL,h265ThreadUrl:H265_THREAD_DECODER_URL,h265AsmUrl:ASM_H265_DECODER_URL,h266Url:H266_DECODER_URL,h266SimdUrl:H266_SIMD_DECODER_URL,h266PthreadUrl:H266_PTHREAD_DECODER_URL,h266SimdPthreadUrl:H266_SIMD_PTHREAD_DECODER_URL}),XGVideo.setEleName=function(e){setEleName(e);var t=function(e){_inherits$1(i,XGVideo);var t=_createSuper$1(i);function i(){return _classCallCheck$2(this,i),t.apply(this,arguments)}return _createClass$2(i)}();customElements.get(getEleName())||customElements.define(getEleName(),t)};try{customElements.get(getEleName())||customElements.define(getEleName(),XGVideo)}catch(e){}export{XGVideo as default};
|