mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
8 lines
293 KiB
JavaScript
8 lines
293 KiB
JavaScript
|
||
/*!
|
||
* artplayer-proxy-webav.js v1.0.0
|
||
* Github: https://github.com/zhw2590582/ArtPlayer
|
||
* (c) 2017-2025 Harvey Zack
|
||
* Released under the MIT License.
|
||
*/
|
||
!function(t,e,r,n,s,a,o,l){var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},c="function"==typeof u[n]&&u[n],h=c.i||{},f=c.cache||{},d="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(e,r){if(!f[e]){if(!t[e]){if(s[e])return s[e];var a="function"==typeof u[n]&&u[n];if(!r&&a)return a(e,!0);if(c)return c(e,!0);if(d&&"string"==typeof e)return d(e);var o=Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}h.resolve=function(r){var n=t[e][1][r];return null!=n?n:r},h.cache={};var l=f[e]=new p.Module(e);t[e][0].call(l.exports,h,l,l.exports,u)}return f[e].exports;function h(t){var e=h.resolve(t);return!1===e?{}:p(e)}}p.isParcelRequire=!0,p.Module=function(t){this.id=t,this.bundle=p,this.require=d,this.exports={}},p.modules=t,p.cache=f,p.parent=c,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=h,p.register=function(e,r){t[e]=[function(t,e){e.exports=r},{}]},Object.defineProperty(p,"root",{get:function(){return u[n]}}),u[n]=p;for(var _=0;_<e.length;_++)p(e[_]);if(r){var m=p(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=m:"function"==typeof define&&define.amd&&define(function(){return m})}}({"8nMKB":[function(t,e,r,n){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"default",function(){return u});var a=t("@swc/helpers/cjs/_async_to_generator.cjs"),o=t("@swc/helpers/cjs/_ts_generator.cjs"),l=t("@webav/av-cliper");function u(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e){var r,n,s=e.option,u=e.constructor.utils,c=u.createElement,h=u.def,f=c("canvas"),d=f.getContext("2d"),p=null,_=null,m=null,y=null,g=0,v={playing:!1,duration:0,videoWidth:0,videoHeight:0,currentTime:0,playbackRate:1,paused:!0,ended:!1,readyState:0,buffered:0,muted:s.muted,volume:s.volume,autoplay:s.autoplay};function b(){m&&(clearInterval(m),m=null),_&&(_.stop(),_=null)}function w(){if(n){var t=v.muted?0:v.volume;n.gain.setValueAtTime(t,r.currentTime)}}function S(){return(S=(0,a._)(function(){var t,s,l,u;function c(){return h.apply(this,arguments)}function h(){return(h=(0,a._)(function(){var a,c,h,f,m,g,w,S;return(0,o._)(this,function(o){switch(o.label){case 0:if(!v.playing)return[2];return h=(c=performance.now())-u,u=c,null!==y?(t=1e6*y,y=null,l=!0):t+=1e3*h*v.playbackRate,v.currentTime=t/1e6,[4,p.tick(Math.round(t))];case 1:if(m=(f=o.sent()).state,g=f.video,w=f.audio,e.emit("video:timeupdate",{type:"timeupdate"}),"done"===m)return b(),v.ended=!0,v.playing=!1,v.paused=!0,e.emit("video:ended",{type:"ended"}),[2];return g&&"success"===m&&(d.clearRect(0,0,v.videoWidth,v.videoHeight),d.drawImage(g,0,0,v.videoWidth,v.videoHeight),g.close()),l?l=!1:(null==w||null==(a=w[0])?void 0:a.length)&&((S=r.createBuffer(2,w[0].length,48e3)).copyToChannel(w[0],0),S.copyToChannel(w[1],1),(_=r.createBufferSource()).buffer=S,_.connect(n),_.playbackRate.setValueAtTime(v.playbackRate,r.currentTime),s=Math.max(r.currentTime,s),_.start(s),s+=S.duration/v.playbackRate),[2]}})})).apply(this,arguments)}return(0,o._)(this,function(e){return r||(n=(r=new AudioContext).createGain()).connect(r.destination),t=1e6*v.currentTime,s=0,l=!0,u=performance.now(),b(),w(),v.playing=!0,v.paused=!1,m=setInterval(c,1e3/60),[2]})})).apply(this,arguments)}function x(t){return U.apply(this,arguments)}function U(){return(U=(0,a._)(function(t){var e;return(0,o._)(this,function(r){switch(r.label){case 0:return[4,p.tick(1e6*t)];case 1:return(e=r.sent().video)&&(d.clearRect(0,0,f.width,f.height),d.drawImage(e,0,0,f.width,f.height),e.close()),[2]}})})).apply(this,arguments)}function E(){var t,r=null==(t=e.template)?void 0:t.$player;if(r&&!s.autoSize){var n=f.videoWidth/f.videoHeight,a=r.clientWidth,o=r.clientHeight,l=0,u=0;a/o>n?l=(a-o*n)/2:u=(o-a/n)/2,Object.assign(f.style,{padding:"".concat(u,"px ").concat(l,"px")})}}function k(){return(k=(0,a._)(function(){var r,n,a;return(0,o._)(this,function(o){switch(o.label){case 0:return[4,l.Combinator.isSupported()];case 1:if(!o.sent())throw e.notice.show="WebAV is not supported",Error("WebAV is not supported");b(),Object.assign(v,{playing:!1,duration:0,videoWidth:0,videoHeight:0,currentTime:0,playbackRate:1,paused:!0,ended:!1,readyState:0,buffered:0,muted:s.muted,volume:s.volume,autoplay:s.autoplay}),p&&(p.destroy(),e.emit("video:abort",{type:"abort"}),e.emit("video:emptied",{type:"emptied"})),o.label=2;case 2:return o.trys.push([2,5,,6]),[4,Promise.resolve()];case 3:return o.sent(),v.readyState=1,e.emit("video:loadstart",{type:"loadstart"}),[4,fetch(s.url)];case 4:if(!(r=o.sent()).body)throw Error("No response body");return p=new(0,l.MP4Clip)(r.body,t),[3,6];case 5:throw n=o.sent(),v.readyState=0,e.emit("video:error",n),n;case 6:return[4,p.ready];case 7:return Object.assign(v,{readyState:4,duration:Math.round((a=o.sent()).duration/1e6),videoWidth:a.width,videoHeight:a.height}),f.width=v.videoWidth,f.height=v.videoHeight,[4,x(.1)];case 8:return o.sent(),E(),e.emit("video:loadedmetadata",{type:"loadedmetadata"}),e.emit("video:durationchange",{type:"durationchange"}),e.emit("video:loadeddata",{type:"loadeddata"}),e.emit("video:canplay",{type:"canplay"}),e.emit("video:canplaythrough",{type:"canplaythrough"}),[2]}})})).apply(this,arguments)}return h(f,"duration",{get:function(){return v.duration}}),h(f,"videoWidth",{get:function(){return v.videoWidth}}),h(f,"videoHeight",{get:function(){return v.videoHeight}}),h(f,"volume",{get:function(){return v.volume},set:function(t){v.volume=Math.max(0,Math.min(1,t)),w(),e.emit("video:volumechange",{type:"volumechange"})}}),h(f,"currentTime",{get:function(){return v.currentTime},set:function(t){if(!(v.readyState<4)){var r=Math.max(0,Math.min(t,v.duration)),n=performance.now();n-g>16&&(g=n,y=r,v.currentTime=r,v.playing||x(r),e.emit("video:timeupdate",{type:"timeupdate"}))}}}),h(f,"autoplay",{get:function(){return v.autoplay},set:function(t){v.autoplay=t,t&&v.readyState>=4&&f.play()}}),h(f,"src",{get:function(){return s.url},set:function(t){s.url=t,(function(){return k.apply(this,arguments)})().then(function(){s.autoplay&&f.play()})}}),h(f,"playbackRate",{get:function(){return v.playbackRate},set:function(t){v.playbackRate=Math.max(.25,Math.min(2,t)),_&&_.playbackRate.setValueAtTime(v.playbackRate,r.currentTime),e.emit("video:ratechange",{type:"ratechange"})}}),h(f,"playing",{get:function(){return v.playing}}),h(f,"paused",{get:function(){return v.paused}}),h(f,"ended",{get:function(){return v.ended}}),h(f,"readyState",{get:function(){return v.readyState}}),h(f,"muted",{get:function(){return v.muted},set:function(t){v.muted=t,w(),e.emit("video:volumechange",{type:"volumechange"})}}),h(f,"buffered",{get:function(){return{start:function(){return 0},end:function(){return v.buffered},length:1}}}),h(f,"play",{value:(0,a._)(function(){return(0,o._)(this,function(t){switch(t.label){case 0:if(v.readyState<4)return[2,!1];return[4,function(){return S.apply(this,arguments)}()];case 1:return t.sent(),e.emit("video:play",{type:"play"}),e.emit("video:playing",{type:"playing"}),[2,!0]}})})}),h(f,"pause",{value:function(){b(),v.playing=!1,v.paused=!0,e.emit("video:pause",{type:"pause"})}}),e.on("destroy",function(){b(),p&&p.destroy()}),e.on("resize",E),f}}"undefined"!=typeof window&&(window.artplayerProxyWebAV=u)},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@webav/av-cliper":"3j1bs","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],cZn0e:[function(t,e,r,n){"use strict";function s(t,e,r,n,s,a,o){try{var l=t[a](o),u=l.value}catch(t){r(t);return}l.done?e(u):Promise.resolve(u).then(n,s)}r._=function(t){return function(){var e=this,r=arguments;return new Promise(function(n,a){var o=t.apply(e,r);function l(t){s(o,n,a,l,u,"next",t)}function u(t){s(o,n,a,l,u,"throw",t)}l(void 0)})}}},{}],eltGh:[function(t,e,r,n){"use strict";r._=t("eb260df52bffddd").__generator},{eb260df52bffddd:"6yrAu"}],"6yrAu":[function(t,e,r,n){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"__extends",function(){return l}),s.export(r,"__assign",function(){return u}),s.export(r,"__rest",function(){return c}),s.export(r,"__decorate",function(){return h}),s.export(r,"__param",function(){return f}),s.export(r,"__esDecorate",function(){return d}),s.export(r,"__runInitializers",function(){return p}),s.export(r,"__propKey",function(){return _}),s.export(r,"__setFunctionName",function(){return m}),s.export(r,"__metadata",function(){return y}),s.export(r,"__awaiter",function(){return g}),s.export(r,"__generator",function(){return v}),s.export(r,"__createBinding",function(){return b}),s.export(r,"__exportStar",function(){return w}),s.export(r,"__values",function(){return S}),s.export(r,"__read",function(){return x}),s.export(r,"__spread",function(){return U}),s.export(r,"__spreadArrays",function(){return E}),s.export(r,"__spreadArray",function(){return k}),s.export(r,"__await",function(){return A}),s.export(r,"__asyncGenerator",function(){return T}),s.export(r,"__asyncDelegator",function(){return C}),s.export(r,"__asyncValues",function(){return I}),s.export(r,"__makeTemplateObject",function(){return B}),s.export(r,"__importStar",function(){return P}),s.export(r,"__importDefault",function(){return L}),s.export(r,"__classPrivateFieldGet",function(){return R}),s.export(r,"__classPrivateFieldSet",function(){return M}),s.export(r,"__classPrivateFieldIn",function(){return O}),s.export(r,"__addDisposableResource",function(){return D}),s.export(r,"__disposeResources",function(){return N}),s.export(r,"__rewriteRelativeImportExtension",function(){return G});var a=t("@swc/helpers/cjs/_type_of.cjs"),o=function(t,e){return(o=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])})(t,e)};function l(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var u=function(){return(u=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var s in e=arguments[r])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)};function c(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&0>e.indexOf(n)&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)0>e.indexOf(n[s])&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]]);return r}function h(t,e,r,n){var s,o=arguments.length,l=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if(("undefined"==typeof Reflect?"undefined":(0,a._)(Reflect))==="object"&&"function"==typeof Reflect.decorate)l=Reflect.decorate(t,e,r,n);else for(var u=t.length-1;u>=0;u--)(s=t[u])&&(l=(o<3?s(l):o>3?s(e,r,l):s(e,r))||l);return o>3&&l&&Object.defineProperty(e,r,l),l}function f(t,e){return function(r,n){e(r,n,t)}}function d(t,e,r,n,s,o){function l(t){if(void 0!==t&&"function"!=typeof t)throw TypeError("Function expected");return t}for(var u,c=n.kind,h="getter"===c?"get":"setter"===c?"set":"value",f=!e&&t?n.static?t:t.prototype:null,d=e||(f?Object.getOwnPropertyDescriptor(f,n.name):{}),p=!1,_=r.length-1;_>=0;_--){var m={};for(var y in n)m[y]="access"===y?{}:n[y];for(var y in n.access)m.access[y]=n.access[y];m.addInitializer=function(t){if(p)throw TypeError("Cannot add initializers after decoration has completed");o.push(l(t||null))};var g=(0,r[_])("accessor"===c?{get:d.get,set:d.set}:d[h],m);if("accessor"===c){if(void 0===g)continue;if(null===g||(void 0===g?"undefined":(0,a._)(g))!=="object")throw TypeError("Object expected");(u=l(g.get))&&(d.get=u),(u=l(g.set))&&(d.set=u),(u=l(g.init))&&s.unshift(u)}else(u=l(g))&&("field"===c?s.unshift(u):d[h]=u)}f&&Object.defineProperty(f,n.name,d),p=!0}function p(t,e,r){for(var n=arguments.length>2,s=0;s<e.length;s++)r=n?e[s].call(t,r):e[s].call(t);return n?r:void 0}function _(t){return(void 0===t?"undefined":(0,a._)(t))==="symbol"?t:"".concat(t)}function m(t,e,r){return(void 0===e?"undefined":(0,a._)(e))==="symbol"&&(e=e.description?"[".concat(e.description,"]"):""),Object.defineProperty(t,"name",{configurable:!0,value:r?"".concat(r," ",e):e})}function y(t,e){if(("undefined"==typeof Reflect?"undefined":(0,a._)(Reflect))==="object"&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function g(t,e,r,n){return new(r||(r=Promise))(function(s,a){function o(t){try{u(n.next(t))}catch(t){a(t)}}function l(t){try{u(n.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?s(t.value):((e=t.value)instanceof r?e:new r(function(t){t(e)})).then(o,l)}u((n=n.apply(t,e||[])).next())})}function v(t,e){var r,n,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=l(0),o.throw=l(1),o.return=l(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(l){return function(u){var c=[l,u];if(r)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(s=2&c[0]?n.return:c[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,c[1])).done)return s;switch(n=0,s&&(c=[2&c[0],s.value]),c[0]){case 0:case 1:s=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(s=(s=a.trys).length>0&&s[s.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!s||c[1]>s[0]&&c[1]<s[3])){a.label=c[1];break}if(6===c[0]&&a.label<s[1]){a.label=s[1],s=c;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(c);break}s[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],n=0}finally{r=s=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var b=Object.create?function(t,e,r,n){void 0===n&&(n=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,s)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]};function w(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||b(e,t,r)}function S(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function x(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,a=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(s)throw s.error}}return o}function U(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(x(arguments[e]));return t}function E(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],o=0,l=a.length;o<l;o++,s++)n[s]=a[o];return n}function k(t,e,r){if(r||2==arguments.length)for(var n,s=0,a=e.length;s<a;s++)!n&&s in e||(n||(n=Array.prototype.slice.call(e,0,s)),n[s]=e[s]);return t.concat(n||Array.prototype.slice.call(e))}function A(t){return this instanceof A?(this.v=t,this):new A(t)}function T(t,e,r){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var n,s=r.apply(t,e||[]),a=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),o("next"),o("throw"),o("return",function(t){return function(e){return Promise.resolve(e).then(t,c)}}),n[Symbol.asyncIterator]=function(){return this},n;function o(t,e){s[t]&&(n[t]=function(e){return new Promise(function(r,n){a.push([t,e,r,n])>1||l(t,e)})},e&&(n[t]=e(n[t])))}function l(t,e){try{var r;(r=s[t](e)).value instanceof A?Promise.resolve(r.value.v).then(u,c):h(a[0][2],r)}catch(t){h(a[0][3],t)}}function u(t){l("next",t)}function c(t){l("throw",t)}function h(t,e){t(e),a.shift(),a.length&&l(a[0][0],a[0][1])}}function C(t){var e,r;return e={},n("next"),n("throw",function(t){throw t}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(n,s){e[n]=t[n]?function(e){return(r=!r)?{value:A(t[n](e)),done:!1}:s?s(e):e}:s}}function I(t){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=S(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise(function(n,s){var a,o,l;a=n,o=s,l=(e=t[r](e)).done,Promise.resolve(e.value).then(function(t){a({value:t,done:l})},o)})}}}function B(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}var z=Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e},F=function(t){return(F=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e})(t)};function P(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=F(t),n=0;n<r.length;n++)"default"!==r[n]&&b(e,t,r[n]);return z(e,t),e}function L(t){return t&&t.__esModule?t:{default:t}}function R(t,e,r,n){if("a"===r&&!n)throw TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(t):n?n.value:e.get(t)}function M(t,e,r,n,s){if("m"===n)throw TypeError("Private method is not writable");if("a"===n&&!s)throw TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?s.call(t,r):s?s.value=r:e.set(t,r),r}function O(t,e){if(null===e||(void 0===e?"undefined":(0,a._)(e))!=="object"&&"function"!=typeof e)throw TypeError("Cannot use 'in' operator on non-object");return"function"==typeof t?e===t:t.has(e)}function D(t,e,r){if(null!=e){var n,s;if((void 0===e?"undefined":(0,a._)(e))!=="object"&&"function"!=typeof e)throw TypeError("Object expected.");if(r){if(!Symbol.asyncDispose)throw TypeError("Symbol.asyncDispose is not defined.");n=e[Symbol.asyncDispose]}if(void 0===n){if(!Symbol.dispose)throw TypeError("Symbol.dispose is not defined.");n=e[Symbol.dispose],r&&(s=n)}if("function"!=typeof n)throw TypeError("Object not disposable.");s&&(n=function(){try{s.call(this)}catch(t){return Promise.reject(t)}}),t.stack.push({value:e,dispose:n,async:r})}else r&&t.stack.push({async:!0});return e}var j="function"==typeof SuppressedError?SuppressedError:function(t,e,r){var n=Error(r);return n.name="SuppressedError",n.error=t,n.suppressed=e,n};function N(t){function e(e){t.error=t.hasError?new j(e,t.error,"An error was suppressed during disposal."):e,t.hasError=!0}var r,n=0;return function s(){for(;r=t.stack.pop();)try{if(!r.async&&1===n)return n=0,t.stack.push(r),Promise.resolve().then(s);if(r.dispose){var a=r.dispose.call(r.value);if(r.async)return n|=2,Promise.resolve(a).then(s,function(t){return e(t),s()})}else n|=1}catch(t){e(t)}if(1===n)return t.hasError?Promise.reject(t.error):Promise.resolve();if(t.hasError)throw t.error}()}function G(t,e){return"string"==typeof t&&/^\.\.?\//.test(t)?t.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(t,r,n,s,a){return r?e?".jsx":".js":!n||s&&a?n+s+"."+a.toLowerCase()+"js":t}):t}r.default={__extends:l,__assign:u,__rest:c,__decorate:h,__param:f,__esDecorate:d,__runInitializers:p,__propKey:_,__setFunctionName:m,__metadata:y,__awaiter:g,__generator:v,__createBinding:b,__exportStar:w,__values:S,__read:x,__spread:U,__spreadArrays:E,__spreadArray:k,__await:A,__asyncGenerator:T,__asyncDelegator:C,__asyncValues:I,__makeTemplateObject:B,__importStar:P,__importDefault:L,__classPrivateFieldGet:R,__classPrivateFieldSet:M,__classPrivateFieldIn:O,__addDisposableResource:D,__disposeResources:N,__rewriteRelativeImportExtension:G}},{"@swc/helpers/cjs/_type_of.cjs":"iXhRw","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],iXhRw:[function(t,e,r,n){"use strict";r._=function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}},{}],qpMMf:[function(t,e,r,n){r.interopDefault=function(t){return t&&t.__esModule?t:{default:t}},r.defineInteropFlag=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.exportAll=function(t,e){return Object.keys(t).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}),e},r.export=function(t,e,r){Object.defineProperty(t,e,{enumerable:!0,get:r})}},{}],"3j1bs":[function(t,e,r,n){var s,a,o,l,u,c,h,f,d,p,_,m,y,g,v,b,w,S,x,U,E,k,A,T,C,I,B,z,F,P,L,R,M,O,D,j,N,G,W,Y,H,V,Z,X,K,Q,J,q,$,tt,te,tr,ti,tn,ts,ta,to,tl,tu,tc,th,tf,td,tp,t_,tm,ty,tg,tv,tb,tw,tS,tx,tU,tE,tk,tA,tT,tC,tI,tB,tz,tF,tP,tL,tR,tM,tO,tD,tj,tN,tG,tW,tY,tH,tV,tZ,tX,tK,tQ,tJ,tq,t$,t0,t1,t2,t3,t4,t6,t8=t("@parcel/transformer-js/src/esmodule-helpers.js");t8.defineInteropFlag(r),t8.export(r,"AudioClip",function(){return e6}),t8.export(r,"Combinator",function(){return rx}),t8.export(r,"EmbedSubtitlesClip",function(){return rt}),t8.export(r,"ImgClip",function(){return e3}),t8.export(r,"Log",function(){return ep.Log}),t8.export(r,"MP4Clip",function(){return eW}),t8.export(r,"MediaStreamClip",function(){return e9}),t8.export(r,"OffscreenSprite",function(){return ry}),t8.export(r,"Rect",function(){return rp}),t8.export(r,"VisibleSprite",function(){return rv}),t8.export(r,"createChromakey",function(){return rf}),t8.export(r,"fastConcatMP4",function(){return ri}),t8.export(r,"fixFMP4Duration",function(){return ra}),t8.export(r,"mixinMP4AndAudio",function(){return rl}),t8.export(r,"renderTxt2ImgBitmap",function(){return eE});var t5=t("@swc/helpers/cjs/_async_to_generator.cjs"),t9=t("@swc/helpers/cjs/_call_super.cjs"),t7=t("@swc/helpers/cjs/_class_call_check.cjs"),et=t("@swc/helpers/cjs/_create_class.cjs"),ee=t("@swc/helpers/cjs/_define_property.cjs"),er=t("@swc/helpers/cjs/_get.cjs"),ei=t("@swc/helpers/cjs/_get_prototype_of.cjs"),en=t("@swc/helpers/cjs/_inherits.cjs"),es=t("@swc/helpers/cjs/_object_spread.cjs"),ea=t("@swc/helpers/cjs/_object_spread_props.cjs"),eo=t("@swc/helpers/cjs/_sliced_to_array.cjs"),el=t("@swc/helpers/cjs/_to_consumable_array.cjs"),eu=t("@swc/helpers/cjs/_type_of.cjs"),ec=t("@swc/helpers/cjs/_ts_generator.cjs"),eh=t("@swc/helpers/cjs/_ts_values.cjs"),ef=t("@webav/mp4box.js"),ed=t8.interopDefault(ef),ep=t("@webav/internal-utils"),e_=t("wave-resampler"),em=t("opfs-tools"),ey=Object.defineProperty,eg=function(t){throw TypeError(t)},ev=function(t,e,r){var n;return n=(void 0===e?"undefined":(0,eu._)(e))!="symbol"?e+"":e,n in t?ey(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r},eb=function(t,e,r){return e.has(t)||eg("Cannot "+r)},ew=function(t,e,r){return eb(t,e,"read from private field"),r?r.call(t):e.get(t)},eS=function(t,e,r){return e.has(t)?eg("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r)},ex=function(t,e,r,n){return eb(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r},eU=function(t,e,r){return eb(t,e,"access private method"),r};function eE(t,e){return ek.apply(this,arguments)}function ek(){return(ek=(0,t5._)(function(t,e){var r,n,s;return(0,ec._)(this,function(a){switch(a.label){case 0:var o,l,u,c,h,f;return(o=document.createElement("pre")).style.cssText="margin: 0; ".concat(e,"; visibility: hidden; position: fixed;"),o.textContent=t,document.body.appendChild(o),u=(l=o.getBoundingClientRect()).width,c=l.height,o.remove(),o.style.visibility="visible",(h=new Image).width=u,h.height=c,f='\n <svg xmlns="http://www.w3.org/2000/svg" width="'.concat(u,'" height="').concat(c,'">\n<foreignObject width="100%" height="100%">\n<div xmlns="http://www.w3.org/1999/xhtml">').concat(o.outerHTML,"</div>\n</foreignObject>\n</svg>\n ").replace(/\t/g,"").replace(/#/g,"%23"),h.src="data:image/svg+xml;charset=utf-8,".concat(f),r=h,[4,new Promise(function(t){r.onload=t})];case 1:return a.sent(),null==(s=(n=new OffscreenCanvas(r.width,r.height)).getContext("2d"))||s.drawImage(r,0,0,r.width,r.height),[4,createImageBitmap(n)];case 2:return[2,a.sent()]}})})).apply(this,arguments)}function eA(t){var e=new Float32Array(t.map(function(t){return t.length}).reduce(function(t,e){return t+e})),r=0,n=!0,s=!1,a=void 0;try{for(var o,l=t[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=o.value;e.set(u,r),r+=u.length}}catch(t){s=!0,a=t}finally{try{n||null==l.return||l.return()}finally{if(s)throw a}}return e}function eT(t){if("f32-planar"===t.format){for(var e=[],r=0;r<t.numberOfChannels;r+=1){var n=new ArrayBuffer(t.allocationSize({planeIndex:r}));t.copyTo(n,{planeIndex:r}),e.push(new Float32Array(n))}return e}if("f32"===t.format){var s=new ArrayBuffer(t.allocationSize({planeIndex:0}));return t.copyTo(s,{planeIndex:0}),function(t,e){for(var r=t.length/e,n=Array.from({length:e},function(){return new Float32Array(r)}),s=0;s<r;s++)for(var a=0;a<e;a++)n[a][s]=t[s*e+a];return n}(new Float32Array(s),t.numberOfChannels)}if("s16"===t.format){var a=new ArrayBuffer(t.allocationSize({planeIndex:0}));return t.copyTo(a,{planeIndex:0}),function(t,e){for(var r=t.length/e,n=Array.from({length:e},function(){return new Float32Array(r)}),s=0;s<r;s++)for(var a=0;a<e;a++){var o=t[s*e+a];n[a][s]=o/32768}return n}(new Int16Array(a),t.numberOfChannels)}throw Error("Unsupported audio data format")}function eC(t){return Array(t.numberOfChannels).fill(0).map(function(e,r){return t.getChannelData(r)})}function eI(){return(eI=(0,t5._)(function(t,e){var r,n,s,a,o,l,u;return(0,ec._)(this,function(c){switch(c.label){case 0:return[4,Promise.all([(n=new ImageDecoder({type:e,data:t})).completed,n.tracks.ready])];case 1:c.sent(),a=null!=(s=null==(r=n.tracks.selectedTrack)?void 0:r.frameCount)?s:1,o=[],l=0,c.label=2;case 2:if(!(l<a))return[3,5];return u=o.push,[4,n.decode({frameIndex:l})];case 3:u.apply(o,[c.sent().image]),c.label=4;case 4:return l+=1,[3,2];case 5:return[2,o]}})})).apply(this,arguments)}function eB(t){for(var e=(l=Math).max.apply(l,(0,el._)(t.map(function(t){var e,r;return null!=(r=null==(e=t[0])?void 0:e.length)?r:0}))),r=new Float32Array(2*e),n=0;n<e;n++){for(var s=0,a=0,o=0;o<t.length;o++){var l,u,c,h,f,d=null!=(h=null==(u=t[o][0])?void 0:u[n])?h:0,p=null!=(f=null==(c=t[o][1])?void 0:c[n])?f:d;s+=d,a+=p}r[n]=s,r[n+e]=a}return r}function ez(){return(ez=(0,t5._)(function(t,e,r){var n,s,a,o,l,u,c;return(0,ec._)(this,function(h){switch(h.label){case 0:if(s=t.length,a=Array(r.chanCount).fill(0).map(function(){return new Float32Array(0)}),0===s||0===(o=(n=Math).max.apply(n,(0,el._)(t.map(function(t){return t.length})))))return[2,a];if(null==globalThis.OfflineAudioContext)return[2,t.map(function(t){return new Float32Array(e_.resample(t,e,r.rate,{method:"sinc",LPF:!1}))})];return u=(l=new globalThis.OfflineAudioContext(r.chanCount,o*r.rate/e,r.rate)).createBufferSource(),c=l.createBuffer(s,o,e),t.forEach(function(t,e){return c.copyToChannel(t,e)}),u.buffer=c,u.connect(l.destination),u.start(),[4,l.startRendering()];case 1:return[2,eC.apply(void 0,[h.sent()])]}})})).apply(this,arguments)}function eF(t){return new Promise(function(e){var r=(0,ep.workerTimer)(function(){r(),e()},t)})}function eP(t,e,r){for(var n=r-e,s=new Float32Array(n),a=0;a<n;)s[a]=t[(e+a)%t.length],a+=1;return s}function eL(t,e){for(var r=Math.floor(t.length/e),n=new Float32Array(r),s=0;s<r;s++){var a=s*e,o=Math.floor(a),l=a-o;o+1<t.length?n[s]=t[o]*(1-l)+t[o+1]*l:n[s]=t[o]}return n}var eR={sampleRate:48e3,channelCount:2,codec:"mp4a.40.2"};function eM(t,e){var r=e.videoTracks[0],n={};if(null!=r){var s=function(t){var e=!0,r=!1,n=void 0;try{for(var s,a=t.mdia.minf.stbl.stsd.entries[Symbol.iterator]();!(e=(s=a.next()).done);e=!0){var o,l,u,c=s.value,h=null!=(u=null!=(l=null!=(o=c.avcC)?o:c.hvcC)?l:c.av1C)?u:c.vpcC;if(null!=h){var f=new ed.default.DataStream(void 0,0,ed.default.DataStream.BIG_ENDIAN);return h.write(f),new Uint8Array(f.buffer.slice(8))}}}catch(t){r=!0,n=t}finally{try{e||null==a.return||a.return()}finally{if(r)throw n}}throw Error("avcC, hvcC, av1C or VPX not found")}(t.getTrackById(r.id)).buffer,a=r.codec.startsWith("avc1")?{descKey:"avcDecoderConfigRecord",type:"avc1"}:r.codec.startsWith("hvc1")?{descKey:"hevcDecoderConfigRecord",type:"hvc1"}:{descKey:"",type:""},o=a.descKey,l=a.type;""!==o&&(n.videoTrackConf=(0,ee._)({timescale:r.timescale,duration:r.duration,width:r.video.width,height:r.video.height,brands:e.brands,type:l},o,s)),n.videoDecoderConf={codec:r.codec,codedHeight:r.video.height,codedWidth:r.video.width,description:s}}var u=e.audioTracks[0];if(null!=u){var c=eO(t);n.audioTrackConf={timescale:u.timescale,samplerate:u.audio.sample_rate,channel_count:u.audio.channel_count,hdlr:"soun",type:u.codec.startsWith("mp4a")?"mp4a":u.codec,description:eO(t)},n.audioDecoderConf=(0,es._)({codec:u.codec.startsWith("mp4a")?eR.codec:u.codec,numberOfChannels:u.audio.channel_count,sampleRate:u.audio.sample_rate},null==c?{}:function(t){var e,r=null==(e=t.esd.descs[0])?void 0:e.descs[0];if(null==r)return{};var n=(0,eo._)(r.data,2),s=n[0],a=n[1];return{sampleRate:[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][((7&s)<<1)+(a>>7)],numberOfChannels:(127&a)>>3}}(c))}return n}function eO(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"mp4a",n=null==(e=t.moov)?void 0:e.traks.map(function(t){return t.mdia.minf.stbl.stsd.entries}).flat().find(function(t){return t.type===r});return null==n?void 0:n.esds}function eD(){return(eD=(0,t5._)(function(t,e,r){var n;function s(){return(s=(0,t5._)(function(){var e,r,s,a;return(0,ec._)(this,function(o){switch(o.label){case 0:e=0,r=0x1e00000,o.label=1;case 1:return[4,t.read(r,{at:e})];case 2:if(0===(s=o.sent()).byteLength||(s.fileStart=e,null==(a=n.appendBuffer(s))))return[3,4];e=a,o.label=3;case 3:return[3,1];case 4:return n.stop(),[2]}})})).apply(this,arguments)}return(0,ec._)(this,function(t){switch(t.label){case 0:return(n=ed.default.createFile(!1)).onReady=function(t){e({mp4boxFile:n,info:t});var r,s,a=null==(r=t.videoTracks[0])?void 0:r.id;null!=a&&n.setExtractionOptions(a,"video",{nbSamples:100});var o=null==(s=t.audioTracks[0])?void 0:s.id;null!=o&&n.setExtractionOptions(o,"audio",{nbSamples:100}),n.start()},n.onSamples=r,[4,function(){return s.apply(this,arguments)}()];case 1:return t.sent(),[2]}})})).apply(this,arguments)}var ej=0;function eN(t){return"file"===t.kind&&t.createReader instanceof Function}var eG=function(){"use strict";function t(e){var r,n,s,a=this,w=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,t7._)(this,t);var S=this;if(eS(this,o,ej++),eS(this,l,ep.Log.create("MP4Clip id:".concat(ew(this,o),","))),ev(this,"ready"),eS(this,u,!1),eS(this,c,{duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0}),eS(this,h),eS(this,f,[]),eS(this,d,1),eS(this,p,[]),eS(this,_,[]),eS(this,m,null),eS(this,y,null),eS(this,g,{video:null,audio:null}),eS(this,v,{audio:!0}),ev(this,"tickInterceptor",(r=(0,t5._)(function(t,e){return(0,ec._)(this,function(t){return[2,e]})}),function(t,e){return r.apply(this,arguments)})),eS(this,b,new AbortController),!(e instanceof ReadableStream)&&!eN(e)&&!Array.isArray(e.videoSamples))throw Error("Illegal argument");ex(this,v,(0,es._)({audio:!0},w)),ex(this,d,"object"==(0,eu._)(w.audio)&&"volume"in w.audio?w.audio.volume:1);var x=(n=(0,t5._)(function(t){return(0,ec._)(this,function(e){switch(e.label){case 0:return[4,(0,em.write)(ew(S,h),t)];case 1:return[2,(e.sent(),ew(S,h))]}})}),function(t){return n.apply(this,arguments)});ex(this,h,eN(e)?e:"localFile"in e?e.localFile:(0,em.tmpfile)()),this.ready=(e instanceof ReadableStream?x(e).then(function(t){return eH(t,ew(a,v))}):eN(e)?eH(e,ew(this,v)):Promise.resolve(e)).then((s=(0,t5._)(function(t){var e,r,n,s,a,o,u,b;return(0,ec._)(this,function(w){switch(w.label){case 0:return e=t.videoSamples,r=t.audioSamples,n=t.decoderConf,s=t.headerBoxPos,ex(S,p,e),ex(S,_,r),ex(S,g,n),ex(S,f,s),b=[{video:null==n.video?null:(0,ea._)((0,es._)({},n.video),{hardwareAcceleration:ew(S,v).__unsafe_hardwareAcceleration__}),audio:n.audio}],[4,ew(S,h).createReader()];case 1:return o=(a=eY.apply(void 0,b.concat([w.sent(),e,r,!1!==ew(S,v).audio?ew(S,d):0]))).videoFrameFinder,u=a.audioFrameFinder,[2,(ex(S,m,o),ex(S,y,u),ex(S,c,function(t,e,r){var n,s,a={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};null!=t.video&&e.length>0&&(a.width=null!=(n=t.video.codedWidth)?n:0,a.height=null!=(s=t.video.codedHeight)?s:0),null!=t.audio&&r.length>0&&(a.audioSampleRate=eR.sampleRate,a.audioChanCount=eR.channelCount);var o=0,l=0;if(e.length>0)for(var u=e.length-1;u>=0;u--){var c=e[u];if(!c.deleted){o=c.cts+c.duration;break}}if(r.length>0){var h=r.at(-1);l=h.cts+h.duration}return a.duration=Math.max(o,l),a}(n,e,r)),ew(S,l).info("MP4Clip meta:",ew(S,c)),(0,es._)({},ew(S,c)))]}})}),function(t){return s.apply(this,arguments)}))}return(0,et._)(t,[{key:"meta",get:function(){return(0,es._)({},ew(this,c))}},{key:"getFileHeaderBinData",value:function(){var t=this;return(0,t5._)(function(){var e;return(0,ec._)(this,function(r){switch(r.label){case 0:return[4,t.ready];case 1:return r.sent(),[4,ew(t,h).getOriginFile()];case 2:if(null==(e=r.sent()))throw Error("MP4Clip localFile is not origin file");return[4,new Blob(ew(t,f).map(function(t){var r=t.start,n=t.size;return e.slice(r,r+n)})).arrayBuffer()];case 3:return[2,r.sent()]}})})()}},{key:"tick",value:function(t){var e=this;return(0,t5._)(function(){var r,n,s,a,o,l,u,h,f,d,p,_;return(0,ec._)(this,function(g){switch(g.label){case 0:if(!(t>=ew(e,c).duration))return[3,3];return o=e.tickInterceptor,l=[t],u={},[4,null==(r=ew(e,y))?void 0:r.find(t)];case 1:return[4,o.apply(e,l.concat([(u.audio=null!=(a=g.sent())?a:[],u.state="done",u)]))];case 2:return[2,g.sent()];case 3:return[4,Promise.all([null!=(h=null==(n=ew(e,y))?void 0:n.find(t))?h:[],null==(s=ew(e,m))?void 0:s.find(t)])];case 4:if(d=(f=eo._.apply(void 0,[g.sent(),2]))[0],null!=(p=f[1]))return[3,6];return[4,e.tickInterceptor(t,{audio:d,state:"success"})];case 5:return _=g.sent(),[3,8];case 6:return[4,e.tickInterceptor(t,{video:p,audio:d,state:"success"})];case 7:_=g.sent(),g.label=8;case 8:return[2,_]}})})()}},{key:"thumbnails",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,e=arguments.length>1?arguments[1]:void 0,r=this;return(0,t5._)(function(){var n,s,a,o,l;return(0,ec._)(this,function(u){switch(u.label){case 0:return ew(r,b).abort(),ex(r,b,new AbortController),n=ew(r,b).signal,[4,r.ready];case 1:var f,d,_,m,y,w,S;if(u.sent(),s="generate thumbnails aborted",n.aborted)throw Error(s);return o=(a=ew(r,c)).width,d=t,_=Math.round(t/o*a.height),m={quality:.1,type:"image/png"},S=(w=new OffscreenCanvas(d,_)).getContext("2d"),y=(0,t5._)(function(t){return(0,ec._)(this,function(e){switch(e.label){case 0:return S.drawImage(t,0,0,d,_),t.close(),[4,w.convertToBlob(m)];case 1:return[2,e.sent()]}})}),l=function(t){return y.apply(this,arguments)},[2,new Promise((f=(0,t5._)(function(t,a){var o,u,f,d,_,m,y,b,w,S,x,U;function E(){return k.apply(this,arguments)}function k(){return(k=(0,t5._)(function(){var e;return(0,ec._)(this,function(e){switch(e.label){case 0:var r;if(n.aborted)return[3,2];return[4,Promise.all(o.map((r=(0,t5._)(function(t){var e;return(0,ec._)(this,function(r){switch(r.label){case 0:return e={ts:t.ts},[4,t.img];case 1:return[2,(e.img=r.sent(),e)]}})}),function(t){return r.apply(this,arguments)})))];case 1:t.apply(void 0,[e.sent()]),e.label=2;case 2:return[2]}})})).apply(this,arguments)}function A(t){o.push({ts:t.timestamp,img:l(t)})}return(0,ec._)(this,function(t){switch(t.label){case 0:if(o=[],null==(u=ew(r,g).video)||0===ew(r,p).length)return E(),[2];if(n.addEventListener("abort",function(){a(Error(s))}),_=void 0===(d=(f=null!=e?e:{}).start)?0:d,y=void 0===(m=f.end)?ew(r,c).duration:m,!(b=f.step))return[3,6];return w=_,x=eZ.bind,[4,ew(r,h).createReader()];case 1:S=new(x.apply(eZ,[void 0,t.sent(),ew(r,p),(0,ea._)((0,es._)({},u),{hardwareAcceleration:ew(r,v).__unsafe_hardwareAcceleration__})])),t.label=2;case 2:if(!(w<=y&&!n.aborted))return[3,5];return[4,S.find(w)];case 3:(U=t.sent())&&A(U),w+=b,t.label=4;case 4:return[3,2];case 5:return S.destroy(),E(),[3,8];case 6:return[4,function(t,e,r,n,s,a){return e$.apply(this,arguments)}(ew(r,p),ew(r,h),u,n,{start:_,end:y},function(t,e){null!=t&&A(t),e&&E()})];case 7:t.sent(),t.label=8;case 8:return[2]}})}),function(t,e){return f.apply(this,arguments)}))]}})})()}},{key:"split",value:function(e){var r=this;return(0,t5._)(function(){var n,s,a,o,l,u,d,m;return(0,ec._)(this,function(y){switch(y.label){case 0:return[4,r.ready];case 1:if(y.sent(),e<=0||e>=ew(r,c).duration)throw Error('"time" out of bounds');return s=(n=(0,eo._)(function(t,e){if(0===t.length)return[];for(var r=0,n=0,s=-1,a=0;a<t.length;a++){var o=t[a];if(-1===s&&e<o.cts&&(s=a-1),o.is_idr)if(-1===s)r=a;else{n=a;break}}var l=t[s];if(null==l)throw Error("Not found video sample by time");for(var u=t.slice(0,0===n?t.length:n).map(function(t){return(0,es._)({},t)}),c=r;c<u.length;c++){var h=u[c];e<h.cts&&(h.deleted=!0,h.cts=-1)}e0(u);var f=t.slice(l.is_idr?s:r).map(function(t){return(0,ea._)((0,es._)({},t),{cts:t.cts-e})}),d=!0,p=!1,_=void 0;try{for(var m,y=f[Symbol.iterator]();!(d=(m=y.next()).done);d=!0){var g=m.value;g.cts<0&&(g.deleted=!0,g.cts=-1)}}catch(t){p=!0,_=t}finally{try{d||null==y.return||y.return()}finally{if(p)throw _}}return e0(f),[u,f]}(ew(r,p),e),2))[0],a=n[1],l=(o=(0,eo._)(function(t,e){if(0===t.length)return[];for(var r=-1,n=0;n<t.length;n++)if(!(e>t[n].cts)){r=n;break}if(-1===r)throw Error("Not found audio sample by time");return[t.slice(0,r).map(function(t){return(0,es._)({},t)}),t.slice(r).map(function(t){return(0,ea._)((0,es._)({},t),{cts:t.cts-e})})]}(ew(r,_),e),2))[0],u=o[1],d=new t({localFile:ew(r,h),videoSamples:null!=s?s:[],audioSamples:null!=l?l:[],decoderConf:ew(r,g),headerBoxPos:ew(r,f)},ew(r,v)),m=new t({localFile:ew(r,h),videoSamples:null!=a?a:[],audioSamples:null!=u?u:[],decoderConf:ew(r,g),headerBoxPos:ew(r,f)},ew(r,v)),[4,Promise.all([d.ready,m.ready])];case 2:return[2,(y.sent(),[d,m])]}})})()}},{key:"clone",value:function(){var e=this;return(0,t5._)(function(){var r;return(0,ec._)(this,function(n){switch(n.label){case 0:return[4,e.ready];case 1:return n.sent(),[4,(r=new t({localFile:ew(e,h),videoSamples:(0,el._)(ew(e,p)),audioSamples:(0,el._)(ew(e,_)),decoderConf:ew(e,g),headerBoxPos:ew(e,f)},ew(e,v))).ready];case 2:return[2,(n.sent(),r.tickInterceptor=e.tickInterceptor,r)]}})})()}},{key:"splitTrack",value:function(){var e=this;return(0,t5._)(function(){var r,n,s;return(0,ec._)(this,function(a){switch(a.label){case 0:return[4,e.ready];case 1:if(a.sent(),r=[],!(ew(e,p).length>0))return[3,3];return[4,(n=new t({localFile:ew(e,h),videoSamples:(0,el._)(ew(e,p)),audioSamples:[],decoderConf:{video:ew(e,g).video,audio:null},headerBoxPos:ew(e,f)},ew(e,v))).ready];case 2:a.sent(),n.tickInterceptor=e.tickInterceptor,r.push(n),a.label=3;case 3:if(!(ew(e,_).length>0))return[3,5];return[4,(s=new t({localFile:ew(e,h),videoSamples:[],audioSamples:(0,el._)(ew(e,_)),decoderConf:{audio:ew(e,g).audio,video:null},headerBoxPos:ew(e,f)},ew(e,v))).ready];case 4:a.sent(),s.tickInterceptor=e.tickInterceptor,r.push(s),a.label=5;case 5:return[2,r]}})})()}},{key:"destroy",value:function(){var t,e;ew(this,u)||(ew(this,l).info("MP4Clip destroy"),ex(this,u,!0),null==(t=ew(this,m))||t.destroy(),null==(e=ew(this,y))||e.destroy())}}]),t}();o=new WeakMap,l=new WeakMap,u=new WeakMap,c=new WeakMap,h=new WeakMap,f=new WeakMap,d=new WeakMap,p=new WeakMap,_=new WeakMap,m=new WeakMap,y=new WeakMap,g=new WeakMap,v=new WeakMap,b=new WeakMap;var eW=eG;function eY(t,e,r,n,s){return{audioFrameFinder:0===s||null==t.audio||0===n.length?null:new eX(e,n,t.audio,{volume:s,targetSampleRate:eR.sampleRate}),videoFrameFinder:null==t.video||0===r.length?null:new eZ(e,r,t.video)}}function eH(t){return eV.apply(this,arguments)}function eV(){return(eV=(0,t5._)(function(t){var e,r,n,s,a,o,l,u,c,h,f,d=arguments;function p(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2?arguments[2]:void 0,n="video"===r&&t.is_sync?function(t,e){if("avc1"!==e&&"hvc1"!==e)return 0;for(var r=new DataView(t.buffer),n=0;n<t.byteLength-4;){if("avc1"===e&&(31&r.getUint8(n+4))==5)return n;if("hvc1"===e){var s=r.getUint8(n+4)>>1&63;if(19===s||20===s)return n}n+=r.getUint32(n)+4}return -1}(t.data,t.description.type):-1,s=t.offset,a=t.size;return n>=0&&(s+=n,a-=n),(0,ea._)((0,es._)({},t),{is_idr:n>=0,offset:s,size:a,cts:(t.cts-e)/t.timescale*1e6,dts:(t.dts-e)/t.timescale*1e6,duration:t.duration/t.timescale*1e6,timescale:1e6,data:"video"===r?null:t.data})}return(0,ec._)(this,function(_){switch(_.label){case 0:return e=d.length>1&&void 0!==d[1]?d[1]:{},r=null,n={video:null,audio:null},s=[],a=[],o=[],l=-1,u=-1,[4,t.createReader()];case 1:return[4,function(t,e,r){return eD.apply(this,arguments)}(c=_.sent(),function(t){r=t.info;var e=t.mp4boxFile.ftyp;o.push({start:e.start,size:e.size});var s=t.mp4boxFile.moov;o.push({start:s.start,size:s.size});var a=eM(t.mp4boxFile,t.info),l=a.videoDecoderConf,u=a.audioDecoderConf;n.video=null!=l?l:null,n.audio=null!=u?u:null,null==l&&null==u&&ep.Log.error("MP4Clip no video and audio track"),ep.Log.info("mp4BoxFile moov ready",(0,ea._)((0,es._)({},t.info),{tracks:null,videoTracks:null,audioTracks:null}),n)},function(t,r,n){if("video"===r){-1===l&&(l=n[0].dts);var o=!0,c=!1,h=void 0;try{for(var f,d=n[Symbol.iterator]();!(o=(f=d.next()).done);o=!0){var _=f.value;s.push(p(_,l,"video"))}}catch(t){c=!0,h=t}finally{try{o||null==d.return||d.return()}finally{if(c)throw h}}}else if("audio"===r&&e.audio){-1===u&&(u=n[0].dts);var m=!0,y=!1,g=void 0;try{for(var v,b=n[Symbol.iterator]();!(m=(v=b.next()).done);m=!0){var w=v.value;a.push(p(w,u,"audio"))}}catch(t){y=!0,g=t}finally{try{m||null==b.return||b.return()}finally{if(y)throw g}}}})];case 2:return _.sent(),[4,c.close()];case 3:if(_.sent(),f=null!=(h=s.at(-1))?h:a.at(-1),null==r)throw Error("MP4Clip stream is done, but not emit ready");if(null==f)throw Error("MP4Clip stream not contain any sample");return[2,(e0(s),ep.Log.info("mp4 stream parsed"),{videoSamples:s,audioSamples:a,decoderConf:n,headerBoxPos:o})]}})})).apply(this,arguments)}var eZ=function t(e,r,n){"use strict";var s,a,o,l=this;(0,t7._)(this,t);var u=this;eS(this,w,null),eS(this,S,0),eS(this,x,{abort:!1,st:performance.now()}),ev(this,"find",(s=(0,t5._)(function(t){var e;return(0,ec._)(this,function(r){switch(r.label){case 0:return(null==ew(u,w)||"closed"===ew(u,w).state||t<=ew(u,S)||t-ew(u,S)>3e6)&&ew(u,L).call(u,t),ew(u,x).abort=!0,ex(u,S,t),ex(u,x,{abort:!1,st:performance.now()}),[4,ew(u,z).call(u,t,ew(u,w),ew(u,x))];case 1:return e=r.sent(),[2,(ex(u,I,0),e)]}})}),function(t){return s.apply(this,arguments)})),eS(this,U,0),eS(this,E,!1),eS(this,k,0),eS(this,A,[]),eS(this,T,0),eS(this,C,0),eS(this,I,0),eS(this,B,!1),eS(this,z,(a=(0,t5._)(function(t,e,r){var n,s,a,o,l;return(0,ec._)(this,function(c){switch(c.label){case 0:if(null==e||"closed"===e.state||r.abort)return[2,null];if(!(ew(u,A).length>0))return[3,6];if(!(t<(n=ew(u,A)[0]).timestamp))return[3,1];return a=null,[3,5];case 1:if(ew(u,A).shift(),!(t>n.timestamp+(null!=(s=n.duration)?s:0)))return[3,3];return n.close(),[4,ew(u,z).call(u,t,e,r)];case 2:return o=c.sent(),[3,4];case 3:!ew(u,B)&&ew(u,A).length<10&&ew(u,P).call(u,e).catch(function(e){throw ex(u,B,!0),ew(u,L).call(u,t),e}),o=n,c.label=4;case 4:a=o,c.label=5;case 5:return[2,a];case 6:if(!(ew(u,F)||ew(u,T)<ew(u,C)&&e.decodeQueueSize>0))return[3,8];if(performance.now()-r.st>6e3)throw Error("MP4Clip.tick video timeout, ".concat(JSON.stringify(ew(u,R).call(u))));return ex(u,I,ew(u,I)+1),[4,eF(15)];case 7:return c.sent(),[3,12];case 8:if(ew(u,k)>=u.samples.length)return[2,null];c.label=9;case 9:return c.trys.push([9,11,,12]),[4,ew(u,P).call(u,e)];case 10:return c.sent(),[3,12];case 11:throw l=c.sent(),ew(u,L).call(u,t),l;case 12:return[4,ew(u,z).call(u,t,e,r)];case 13:return[2,c.sent()]}})}),function(t,e,r){return a.apply(this,arguments)})),eS(this,F,!1),eS(this,P,(o=(0,t5._)(function(t){var e,r,n,s,a,o,l,c,h,f,d,p,_;return(0,ec._)(this,function(m){switch(m.label){case 0:if(ew(u,F)||t.decodeQueueSize>600||(n=ew(u,k)+1)>u.samples.length)return[2];for(ex(u,F,!0),s=!1;n<u.samples.length&&(a=u.samples[n],s||a.deleted||(s=!0),!a.is_idr);n++);if(!s)return[3,3];if((null==(e=(o=u.samples.slice(ew(u,k),n))[0])?void 0:e.is_idr)===!0)return[3,1];return ep.Log.warn("First sample not idr frame"),[3,3];case 1:return l=performance.now(),[4,eQ(o,u.localFileReader)];case 2:if(c=m.sent(),(h=performance.now()-l)>1e3&&(f=o[0],p=(d=o.at(-1)).offset+d.size-f.offset,ep.Log.warn("Read video samples time cost: ".concat(Math.round(h),"ms, file chunk size: ").concat(p))),"closed"===t.state)return[2];ex(u,U,null!=(_=null==(r=c[0])?void 0:r.duration)?_:0),eq(t,c,{onDecodingError:function(t){if(ew(u,E))throw t;0===ew(u,T)&&(ex(u,E,!0),ep.Log.warn("Downgrade to software decode"),ew(u,L).call(u))}}),ex(u,C,ew(u,C)+c.length),m.label=3;case 3:return ex(u,k,n),ex(u,F,!1),[2]}})}),function(t){return o.apply(this,arguments)})),eS(this,L,function(t){if(ex(l,F,!1),ew(l,A).forEach(function(t){return t.close()}),ex(l,A,[]),null==t||0===t)ex(l,k,0);else for(var e,r,n=0,s=0;s<l.samples.length;s++){var a=l.samples[s];if(a.is_idr&&(n=s),!(a.cts<t)){ex(l,k,n);break}}ex(l,C,0),ex(l,T,0),(null==(e=ew(l,w))?void 0:e.state)!=="closed"&&(null==(r=ew(l,w))||r.close());var o=(0,es._)({},l.conf,ew(l,E)?{hardwareAcceleration:"prefer-software"}:{});ex(l,w,new VideoDecoder({output:function(t){if(ex(l,T,ew(l,T)+1),-1===t.timestamp)return void t.close();var e=t;null==t.duration&&(e=new VideoFrame(t,{duration:ew(l,U)}),t.close()),ew(l,A).push(e)},error:function(t){if(t.message.includes("Codec reclaimed due to inactivity")){ex(l,w,null),ep.Log.warn(t.message);return}var e="VideoFinder VideoDecoder err: ".concat(t.message,", config: ").concat(JSON.stringify(o),", state: ").concat(JSON.stringify(ew(l,R).call(l)));throw ep.Log.error(e),Error(e)}})),ew(l,w).configure(o)}),eS(this,R,function(){var t,e;return{time:ew(l,S),decState:null==(t=ew(l,w))?void 0:t.state,decQSize:null==(e=ew(l,w))?void 0:e.decodeQueueSize,decCusorIdx:ew(l,k),sampleLen:l.samples.length,inputCnt:ew(l,C),outputCnt:ew(l,T),cacheFrameLen:ew(l,A).length,softDeocde:ew(l,E),clipIdCnt:ej,sleepCnt:ew(l,I),memInfo:e1()}}),ev(this,"destroy",function(){var t,e;(null==(t=ew(l,w))?void 0:t.state)!=="closed"&&(null==(e=ew(l,w))||e.close()),ex(l,w,null),ew(l,x).abort=!0,ew(l,A).forEach(function(t){return t.close()}),ex(l,A,[]),l.localFileReader.close()}),this.localFileReader=e,this.samples=r,this.conf=n};w=new WeakMap,S=new WeakMap,x=new WeakMap,U=new WeakMap,E=new WeakMap,k=new WeakMap,A=new WeakMap,T=new WeakMap,C=new WeakMap,I=new WeakMap,B=new WeakMap,z=new WeakMap,F=new WeakMap,P=new WeakMap,L=new WeakMap,R=new WeakMap;var eX=function t(e,r,n,s){"use strict";var a,o,l=this;(0,t7._)(this,t);var u=this;eS(this,M,1),eS(this,O),eS(this,D,null),eS(this,j,{abort:!1,st:performance.now()}),ev(this,"find",(a=(0,t5._)(function(t){var e,r,n;return(0,ec._)(this,function(s){switch(s.label){case 0:return e=t<=ew(u,N)||t-ew(u,N)>1e5,(null==ew(u,D)||"closed"===ew(u,D).state||e)&&ew(u,Z).call(u),e&&(ex(u,N,t),ex(u,G,function(t,e){for(var r=0;r<e.length;r++){var n=e[r];if(t>=n.cts&&t<n.cts+n.duration)return r;if(n.cts>t)break}return 0}(t,u.samples))),ew(u,j).abort=!0,r=t-ew(u,N),ex(u,N,t),ex(u,j,{abort:!1,st:performance.now()}),[4,ew(u,H).call(u,Math.ceil(r*(ew(u,O)/1e6)),ew(u,D),ew(u,j))];case 1:return n=s.sent(),[2,(ex(u,Y,0),n)]}})}),function(t){return a.apply(this,arguments)})),eS(this,N,0),eS(this,G,0),eS(this,W,{frameCnt:0,data:[]}),eS(this,Y,0),eS(this,H,(o=(0,t5._)(function(t){var e,r,n,s=arguments;return(0,ec._)(this,function(a){switch(a.label){case 0:if(e=s.length>1&&void 0!==s[1]?s[1]:null,r=s.length>2?s[2]:void 0,null==e||r.abort||"closed"===e.state||0===t)return[2,[]];if((n=ew(u,W).frameCnt-t)>0)return[2,(n<eR.sampleRate/10&&ew(u,V).call(u,e),eK(ew(u,W),t))];if(!e.decoding)return[3,2];if(performance.now()-r.st>3e3)throw r.abort=!0,Error("MP4Clip.tick audio timeout, ".concat(JSON.stringify(ew(u,X).call(u))));return ex(u,Y,ew(u,Y)+1),[4,eF(15)];case 1:return a.sent(),[3,3];case 2:if(ew(u,G)>=u.samples.length-1)return[2,eK(ew(u,W),ew(u,W).frameCnt)];ew(u,V).call(u,e),a.label=3;case 3:return[2,ew(u,H).call(u,t,e,r)]}})}),function(t){return o.apply(this,arguments)})),eS(this,V,function(t){if(!(t.decodeQueueSize>10)){for(var e=[],r=ew(l,G);r<l.samples.length;){var n=l.samples[r];if(r+=1,!n.deleted&&(e.push(n),e.length>=10))break}ex(l,G,r),t.decode(e.map(function(t){return new EncodedAudioChunk({type:"key",timestamp:t.cts,duration:t.duration,data:t.data})}))}}),eS(this,Z,function(){var t;ex(l,N,0),ex(l,G,0),ex(l,W,{frameCnt:0,data:[]}),null==(t=ew(l,D))||t.close(),ex(l,D,function(t,e,r){var n=0,s=0,a=function(t){if(s+=1,0!==t.length){var n=!0,a=!1,o=void 0;if(1!==e.volume)try{for(var l,u=t[Symbol.iterator]();!(n=(l=u.next()).done);n=!0)for(var c=l.value,h=0;h<c.length;h++)c[h]*=e.volume}catch(t){a=!0,o=t}finally{try{n||null==u.return||u.return()}finally{if(a)throw o}}1===t.length&&(t=[t[0],t[0]]),r(t)}},o=function(t){var e=[],r=0;function n(){var s=e[r];null!=s&&(t(s),r+=1,n())}var s=0;return function(t){var r=s;s+=1,t().then(function(t){e[r]=t,n()}).catch(function(t){e[r]=t,n()})}}(a),l=e.resampleRate!==t.sampleRate,u=new AudioDecoder({output:function(t){var r=eT(t);l?o(function(){return function(t,e,r){return ez.apply(this,arguments)}(r,t.sampleRate,{rate:e.resampleRate,chanCount:t.numberOfChannels})}):a(r),t.close()},error:function(t){t.message.includes("Codec reclaimed due to inactivity")||c("MP4Clip AudioDecoder err",t)}});function c(t,e){var r="".concat(t,": ").concat(e.message,", state: ").concat(JSON.stringify({qSize:u.decodeQueueSize,state:u.state,inputCnt:n,outputCnt:s}));throw ep.Log.error(r),Error(r)}return u.configure(t),{decode:function(t){n+=t.length;try{var e=!0,r=!1,s=void 0;try{for(var a,o=t[Symbol.iterator]();!(e=(a=o.next()).done);e=!0){var l=a.value;u.decode(l)}}catch(t){r=!0,s=t}finally{try{e||null==o.return||o.return()}finally{if(r)throw s}}}catch(t){c("decode audio chunk error",t)}},close:function(){"closed"!==u.state&&u.close()},get decoding(){return n>s&&u.decodeQueueSize>0},get state(){return u.state},get decodeQueueSize(){return u.decodeQueueSize}}}(l.conf,{resampleRate:eR.sampleRate,volume:ew(l,M)},function(t){ew(l,W).data.push(t),ew(l,W).frameCnt+=t[0].length}))}),eS(this,X,function(){var t,e;return{time:ew(l,N),decState:null==(t=ew(l,D))?void 0:t.state,decQSize:null==(e=ew(l,D))?void 0:e.decodeQueueSize,decCusorIdx:ew(l,G),sampleLen:l.samples.length,pcmLen:ew(l,W).frameCnt,clipIdCnt:ej,sleepCnt:ew(l,Y),memInfo:e1()}}),ev(this,"destroy",function(){ex(l,D,null),ew(l,j).abort=!0,ex(l,W,{frameCnt:0,data:[]}),l.localFileReader.close()}),this.localFileReader=e,this.samples=r,this.conf=n,ex(this,M,s.volume),ex(this,O,s.targetSampleRate)};function eK(t,e){for(var r=[new Float32Array(e),new Float32Array(e)],n=0,s=0;s<t.data.length;){var a=(0,eo._)(t.data[s],2),o=a[0],l=a[1];if(n+o.length>e){var u=e-n;r[0].set(o.subarray(0,u),n),r[1].set(l.subarray(0,u),n),t.data[s][0]=o.subarray(u,o.length),t.data[s][1]=l.subarray(u,l.length);break}r[0].set(o,n),r[1].set(l,n),n+=o.length,s++}return t.data=t.data.slice(s),t.frameCnt-=e,r}function eQ(t,e){return eJ.apply(this,arguments)}function eJ(){return(eJ=(0,t5._)(function(t,e){var r,n,s,a,o;return(0,ec._)(this,function(l){switch(l.label){case 0:if(r=t[0],null==(n=t.at(-1)))return[2,[]];if(!((s=n.offset+n.size-r.offset)<3e7))return[3,2];return o=Uint8Array.bind,[4,e.read(s,{at:r.offset})];case 1:return a=new(o.apply(Uint8Array,[void 0,l.sent()])),[2,t.map(function(t){var e=t.offset-r.offset;return new EncodedVideoChunk({type:t.is_sync?"key":"delta",timestamp:t.cts,duration:t.duration,data:a.subarray(e,e+t.size)})})];case 2:var u;return[4,Promise.all(t.map((u=(0,t5._)(function(t){var r,n;return(0,ec._)(this,function(s){switch(s.label){case 0:return r=EncodedVideoChunk.bind,n={type:t.is_sync?"key":"delta",timestamp:t.cts,duration:t.duration},[4,e.read(t.size,{at:t.offset})];case 1:return[2,new(r.apply(EncodedVideoChunk,[void 0,(n.data=s.sent(),n)]))]}})}),function(t){return u.apply(this,arguments)})))];case 3:return[2,l.sent()]}})})).apply(this,arguments)}function eq(t,e,r){var n=0;if("configured"===t.state){for(;n<e.length;n++)t.decode(e[n]);t.flush().catch(function(t){if(!(t instanceof Error))throw t;if(t.message.includes("Decoding error")&&null!=r.onDecodingError)return void r.onDecodingError(t);if(!t.message.includes("Aborted due to close"))throw t})}}function e$(){return(e$=(0,t5._)(function(t,e,r,n,s,a){var o,l,u;function c(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=(0,es._)({},r,t?{hardwareAcceleration:"prefer-software"}:{}),s=new VideoDecoder({output:function(t){var e=(u+=1)===l.length;a(t,e),e&&(o.close(),"closed"!==s.state&&s.close())},error:function(t){var r="thumbnails decoder error: ".concat(t.message,", config: ").concat(JSON.stringify(e),", state: ").concat(JSON.stringify({qSize:s.decodeQueueSize,state:s.state,outputCnt:u,inputCnt:l.length}));throw ep.Log.error(r),Error(r)}});return n.addEventListener("abort",function(){o.close(),"closed"!==s.state&&s.close()}),s.configure(e),s}return(0,ec._)(this,function(r){switch(r.label){case 0:return[4,e.createReader()];case 1:return o=r.sent(),[4,eQ(t.filter(function(t){return!t.deleted&&t.is_sync&&t.cts>=s.start&&t.cts<=s.end}),o)];case 2:if(0===(l=r.sent()).length||n.aborted)return[2];return u=0,eq(c(),l,{onDecodingError:function(t){ep.Log.warn("thumbnailsByKeyFrame",t),0===u?eq(c(!0),l,{onDecodingError:function(t){o.close(),ep.Log.error("thumbnailsByKeyFrame retry soft deocde",t)}}):(a(null,!0),o.close())}}),[2]}})})).apply(this,arguments)}function e0(t){var e=0,r=null,n=!0,s=!1,a=void 0;try{for(var o,l=t[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=o.value;if(!u.deleted){if(u.is_sync&&(e+=1),e>=2)break;(null==r||u.cts<r.cts)&&(r=u)}}}catch(t){s=!0,a=t}finally{try{n||null==l.return||l.return()}finally{if(s)throw a}}null!=r&&r.cts<2e5&&(r.duration+=r.cts,r.cts=0)}function e1(){try{var t=performance.memory;return{jsHeapSizeLimit:t.jsHeapSizeLimit,totalJSHeapSize:t.totalJSHeapSize,usedJSHeapSize:t.usedJSHeapSize,percentUsed:(t.usedJSHeapSize/t.jsHeapSizeLimit).toFixed(3),percentTotal:(t.totalJSHeapSize/t.jsHeapSizeLimit).toFixed(3)}}catch(t){return{}}}M=new WeakMap,O=new WeakMap,D=new WeakMap,j=new WeakMap,N=new WeakMap,G=new WeakMap,W=new WeakMap,Y=new WeakMap,H=new WeakMap,V=new WeakMap,Z=new WeakMap,X=new WeakMap;var e2=function(){"use strict";function t(e){var r,n=this;(0,t7._)(this,t),eS(this,q),ev(this,"ready"),eS(this,K,{duration:0,width:0,height:0}),eS(this,Q,null),eS(this,J,[]),ev(this,"tickInterceptor",(r=(0,t5._)(function(t,e){return(0,ec._)(this,function(t){return[2,e]})}),function(t,e){return r.apply(this,arguments)}));var s=function(t){return ex(n,Q,t),ew(n,K).width=t.width,ew(n,K).height=t.height,ew(n,K).duration=1/0,(0,es._)({},ew(n,K))};if(e instanceof ReadableStream)this.ready=new Response(e).blob().then(function(t){return createImageBitmap(t)}).then(s);else if(e instanceof ImageBitmap)this.ready=Promise.resolve(s(e));else if(Array.isArray(e)&&e.every(function(t){return t instanceof VideoFrame})){ex(this,J,e);var a=ew(this,J)[0];if(null==a)throw Error("The frame count must be greater than 0");ex(this,K,{width:a.displayWidth,height:a.displayHeight,duration:ew(this,J).reduce(function(t,e){var r;return t+(null!=(r=e.duration)?r:0)},0)}),this.ready=Promise.resolve((0,ea._)((0,es._)({},ew(this,K)),{duration:1/0}))}else if("type"in e)this.ready=eU(this,q,$).call(this,e.stream,e.type).then(function(){return{width:ew(n,K).width,height:ew(n,K).height,duration:1/0}});else throw Error("Illegal arguments")}return(0,et._)(t,[{key:"meta",get:function(){return(0,es._)({},ew(this,K))}},{key:"tick",value:function(t){var e=this;return(0,t5._)(function(){var r,n,s,a,o;return(0,ec._)(this,function(l){switch(l.label){case 0:if(null==ew(e,Q))return[3,3];return r=e.tickInterceptor,n=[t],s={},[4,createImageBitmap(ew(e,Q))];case 1:return[4,r.apply(e,n.concat([(s.video=l.sent(),s.state="success",s)]))];case 2:case 4:return[2,l.sent()];case 3:return a=t%ew(e,K).duration,[4,e.tickInterceptor(t,{video:(null!=(o=ew(e,J).find(function(t){var e;return a>=t.timestamp&&a<=t.timestamp+(null!=(e=t.duration)?e:0)}))?o:ew(e,J)[0]).clone(),state:"success"})]}})})()}},{key:"split",value:function(e){var r=this;return(0,t5._)(function(){var n,s,a,o,l,u,c;return(0,ec._)(this,function(h){switch(h.label){case 0:return[4,r.ready];case 1:if(h.sent(),null==ew(r,Q))return[3,4];return n=t.bind,[4,createImageBitmap(ew(r,Q))];case 2:return s=[new(n.apply(t,[void 0,h.sent()]))],a=t.bind,[4,createImageBitmap(ew(r,Q))];case 3:return[2,s.concat([new(a.apply(t,[void 0,h.sent()]))])];case 4:for(l=0,o=-1;l<ew(r,J).length;l++)if(!(e>ew(r,J)[l].timestamp)){o=l;break}if(-1===o)throw Error("Not found frame by time");return u=ew(r,J).slice(0,o).map(function(t){return new VideoFrame(t)}),c=ew(r,J).slice(o).map(function(t){return new VideoFrame(t,{timestamp:t.timestamp-e})}),[2,[new t(u),new t(c)]]}})})()}},{key:"clone",value:function(){var e=this;return(0,t5._)(function(){var r;return(0,ec._)(this,function(n){switch(n.label){case 0:return[4,e.ready];case 1:if(n.sent(),null!=ew(e,Q))return[3,2];return r=ew(e,J).map(function(t){return t.clone()}),[3,4];case 2:return[4,createImageBitmap(ew(e,Q))];case 3:r=n.sent(),n.label=4;case 4:return[2,new t(r)]}})})()}},{key:"destroy",value:function(){var t;ep.Log.info("ImgClip destroy"),null==(t=ew(this,Q))||t.close(),ew(this,J).forEach(function(t){return t.close()})}}]),t}();K=new WeakMap,Q=new WeakMap,J=new WeakMap,q=new WeakSet,s=(0,t5._)(function(t,e){var r,n;return(0,ec._)(this,function(s){switch(s.label){case 0:return r=[this,J],[4,function(t,e){return eI.apply(this,arguments)}(t,e)];case 1:if(ex.apply(void 0,r.concat([s.sent()])),null==(n=ew(this,J)[0]))throw Error("No frame available in gif");return ex(this,K,{duration:ew(this,J).reduce(function(t,e){var r;return t+(null!=(r=e.duration)?r:0)},0),width:n.codedWidth,height:n.codedHeight}),ep.Log.info("ImgClip ready:",ew(this,K)),[2]}})}),$=function(t,e){return s.apply(this,arguments)};var e3=e2,e4=function(){"use strict";function t(e){var r,n=this,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};(0,t7._)(this,t),eS(this,tn),ev(this,"ready"),eS(this,tt,{duration:0,width:0,height:0}),eS(this,te,new Float32Array),eS(this,tr,new Float32Array),eS(this,ti),ev(this,"tickInterceptor",(r=(0,t5._)(function(t,e){return(0,ec._)(this,function(t){return[2,e]})}),function(t,e){return r.apply(this,arguments)})),eS(this,ta,0),eS(this,to,0),ex(this,ti,(0,es._)({loop:!1,volume:1},s)),this.ready=eU(this,tn,ts).call(this,e).then(function(){return{width:0,height:0,duration:s.loop?1/0:ew(n,tt).duration}})}return(0,et._)(t,[{key:"meta",get:function(){return(0,ea._)((0,es._)({},ew(this,tt)),{sampleRate:eR.sampleRate,chanCount:2})}},{key:"getPCMData",value:function(){return[ew(this,te),ew(this,tr)]}},{key:"tick",value:function(t){var e=this;return(0,t5._)(function(){var r,n,s,a;return(0,ec._)(this,function(o){switch(o.label){case 0:if(!(!ew(e,ti).loop&&t>=ew(e,tt).duration))return[3,2];return[4,e.tickInterceptor(t,{audio:[],state:"done"})];case 1:case 3:case 5:return[2,o.sent()];case 2:if(r=t-ew(e,ta),!(t<ew(e,ta)||r>3e6))return[3,4];return ex(e,ta,t),ex(e,to,Math.ceil(ew(e,ta)/1e6*eR.sampleRate)),[4,e.tickInterceptor(t,{audio:[new Float32Array(0),new Float32Array(0)],state:"success"})];case 4:return ex(e,ta,t),n=Math.ceil(r/1e6*eR.sampleRate),s=ew(e,to)+n,a=ew(e,ti).loop?[eP(ew(e,te),ew(e,to),s),eP(ew(e,tr),ew(e,to),s)]:[ew(e,te).slice(ew(e,to),s),ew(e,tr).slice(ew(e,to),s)],ex(e,to,s),[4,e.tickInterceptor(t,{audio:a,state:"success"})]}})})()}},{key:"split",value:function(e){var r=this;return(0,t5._)(function(){var n;return(0,ec._)(this,function(s){switch(s.label){case 0:return[4,r.ready];case 1:return s.sent(),n=Math.ceil(e/1e6*eR.sampleRate),[2,[new t(r.getPCMData().map(function(t){return t.slice(0,n)}),ew(r,ti)),new t(r.getPCMData().map(function(t){return t.slice(n)}),ew(r,ti))]]}})})()}},{key:"clone",value:function(){var e=this;return(0,t5._)(function(){var r;return(0,ec._)(this,function(n){switch(n.label){case 0:return[4,e.ready];case 1:return n.sent(),[4,(r=new t(e.getPCMData(),ew(e,ti))).ready];case 2:return[2,(n.sent(),r)]}})})()}},{key:"destroy",value:function(){ex(this,te,new Float32Array(0)),ex(this,tr,new Float32Array(0)),ep.Log.info("---- audioclip destroy ----")}}]),t}();tt=new WeakMap,te=new WeakMap,tr=new WeakMap,ti=new WeakMap,tn=new WeakSet,a=(0,t5._)(function(t){var e,r,n,s,a,o,l,u,c,h,f,d;return(0,ec._)(this,function(p){switch(p.label){case 0:if(null==e4.ctx&&(e4.ctx=new AudioContext({sampleRate:eR.sampleRate})),e=performance.now(),!(t instanceof ReadableStream))return[3,2];return[4,function(t,e){return e8.apply(this,arguments)}(t,e4.ctx)];case 1:return n=p.sent(),[3,3];case 2:n=t,p.label=3;case 3:if(r=n,ep.Log.info("Audio clip decoded complete:",performance.now()-e),s=ew(this,ti).volume,a=!0,o=!1,l=void 0,1!==s)try{for(u=r[Symbol.iterator]();!(a=(c=u.next()).done);a=!0)for(f=0,h=c.value;f<h.length;f+=1)h[f]*=s}catch(t){o=!0,l=t}finally{try{a||null==u.return||u.return()}finally{if(o)throw l}}return ew(this,tt).duration=r[0].length/eR.sampleRate*1e6,ex(this,te,r[0]),ex(this,tr,null!=(d=r[1])?d:ew(this,te)),ep.Log.info("Audio clip convert to AudioData, time:",performance.now()-e),[2]}})}),ts=function(t){return a.apply(this,arguments)},ta=new WeakMap,to=new WeakMap,ev(e4,"ctx",null);var e6=e4;function e8(){return(e8=(0,t5._)(function(t,e){var r;return(0,ec._)(this,function(n){switch(n.label){case 0:return[4,new Response(t).arrayBuffer()];case 1:return r=n.sent(),[4,e.decodeAudioData(r)];case 2:return[2,eC.apply(void 0,[n.sent()])]}})})).apply(this,arguments)}var e5=function(){"use strict";function t(e){var r,n=this;(0,t7._)(this,t),ev(this,"ready"),eS(this,tl,{duration:0,width:0,height:0}),eS(this,tu,function(){}),ev(this,"audioTrack"),eS(this,tc,null),eS(this,th),ex(this,th,e),this.audioTrack=null!=(r=e.getAudioTracks()[0])?r:null,ew(this,tl).duration=1/0;var s=e.getVideoTracks()[0];null!=s?(s.contentHint="motion",this.ready=new Promise(function(t){var e,r,a,o,l;ex(n,tu,(e=s,r=function(e){ew(n,tl).width=e.width,ew(n,tl).height=e.height,ex(n,tc,e),t(n.meta)},l=!1,(0,ep.autoReadStream)(new MediaStreamTrackProcessor({track:e}).readable,{onChunk:(a=(0,t5._)(function(t){var e,n,s;return(0,ec._)(this,function(a){return l||(e=t.displayHeight,o=(s=new OffscreenCanvas(null!=(n=t.displayWidth)?n:0,null!=e?e:0)).getContext("2d"),r(s),l=!0),o.drawImage(t,0,0),t.close(),[2]})}),function(t){return a.apply(this,arguments)}),onDone:(0,t5._)(function(){return(0,ec._)(this,function(t){return[2]})})})))})):this.ready=Promise.resolve(this.meta)}return(0,et._)(t,[{key:"meta",get:function(){return(0,es._)({},ew(this,tl))}},{key:"tick",value:function(){var t=this;return(0,t5._)(function(){var e,r;return(0,ec._)(this,function(n){switch(n.label){case 0:if(e={},null!=ew(t,tc))return[3,1];return r=null,[3,3];case 1:return[4,createImageBitmap(ew(t,tc))];case 2:r=n.sent(),n.label=3;case 3:return[2,(e.video=r,e.audio=[],e.state="success",e)]}})})()}},{key:"split",value:function(){var t=this;return(0,t5._)(function(){var e;return(0,ec._)(this,function(r){switch(r.label){case 0:return[4,t.clone()];case 1:return e=[r.sent()],[4,t.clone()];case 2:return[2,e.concat([r.sent()])]}})})()}},{key:"clone",value:function(){var e=this;return(0,t5._)(function(){return(0,ec._)(this,function(r){return[2,new t(ew(e,th).clone())]})})()}},{key:"destroy",value:function(){ew(this,th).getTracks().forEach(function(t){return t.stop()}),ew(this,tu).call(this)}}]),t}();tl=new WeakMap,tu=new WeakMap,tc=new WeakMap,th=new WeakMap,ev(e5,"ctx",null);var e9=e5,e7=function(){"use strict";function t(e,r){if((0,t7._)(this,t),eS(this,tb),ev(this,"ready"),eS(this,tf,[]),eS(this,td,{width:0,height:0,duration:0}),eS(this,tp,{color:"#FFF",textBgColor:null,type:"srt",fontSize:30,letterSpacing:null,bottomOffset:30,fontFamily:"Noto Sans SC",strokeStyle:"#000",lineWidth:null,lineCap:null,lineJoin:null,textShadow:{offsetX:2,offsetY:2,blur:4,color:"#000"},videoWidth:1280,videoHeight:720}),eS(this,t_),eS(this,tm),eS(this,ty,null),eS(this,tg,0),eS(this,tv,0),ex(this,tf,Array.isArray(e)?e:e.split(/\r|\n/).map(function(t){return t.trim()}).filter(function(t){return t.length>0}).map(function(t){return{lineStr:t,match:t.match(/(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/)}}).filter(function(t,e,r){var n,s=t.lineStr;return!(/^\d+$/.test(s)&&(null==(n=r[e+1])?void 0:n.match)!=null)}).reduce(function(t,e){var r=e.lineStr,n=e.match;if(null==n){var s=t.at(-1);if(null==s)return t;s.text+=0===s.text.length?r:"\n".concat(r)}else t.push({start:re(n[1]),end:re(n[2]),text:""});return t},[]).map(function(t){return{start:1e6*t.start,end:1e6*t.end,text:t.text}})),0===ew(this,tf).length)throw Error("No subtitles content");ex(this,tp,Object.assign(ew(this,tp),r)),ex(this,tv,null==r.textBgColor?0:(null!=(s=r.fontSize)?s:50)*.2);var n,s,a,o=ew(this,tp),l=o.fontSize,u=o.fontFamily,c=o.videoWidth,h=o.videoHeight,f=o.letterSpacing;ex(this,tg,l+2*ew(this,tv)),ex(this,t_,new OffscreenCanvas(c,h)),ex(this,tm,ew(this,t_).getContext("2d")),ew(this,tm).font="".concat(l,"px ").concat(u),ew(this,tm).textAlign="center",ew(this,tm).textBaseline="top",ew(this,tm).letterSpacing=null!=f?f:"0px",ex(this,td,{width:c,height:h,duration:null!=(a=null==(n=ew(this,tf).at(-1))?void 0:n.end)?a:0}),this.ready=Promise.resolve(this.meta)}return(0,et._)(t,[{key:"meta",get:function(){return(0,es._)({},ew(this,td))}},{key:"tick",value:function(t){var e=this;return(0,t5._)(function(){var r,n,s,a,o,l,u,c;return(0,ec._)(this,function(h){if(null!=ew(e,ty)&&t>=ew(e,ty).timestamp&&t<=ew(e,ty).timestamp+(null!=(s=ew(e,ty).duration)?s:0))return[2,{video:ew(e,ty).clone(),state:"success"}];for(a=0;a<ew(e,tf).length&&!(t<=ew(e,tf)[a].end);a+=1);return t>(l=null!=(o=ew(e,tf)[a])?o:ew(e,tf).at(-1)).end?[2,{state:"done"}]:t<l.start?(ew(e,tm).clearRect(0,0,ew(e,t_).width,ew(e,t_).height),u=new VideoFrame(ew(e,t_),{timestamp:t,duration:l.start-t}),[2,(null==(r=ew(e,ty))||r.close(),ex(e,ty,u),{video:u.clone(),state:"success"})]):(eU(e,tb,tw).call(e,l.text),c=new VideoFrame(ew(e,t_),{timestamp:t,duration:l.end-t}),[2,(null==(n=ew(e,ty))||n.close(),ex(e,ty,c),{video:c.clone(),state:"success"})])})})()}},{key:"split",value:function(e){var r=this;return(0,t5._)(function(){var n,s,a,o,l,u;return(0,ec._)(this,function(c){switch(c.label){case 0:return[4,r.ready];case 1:for(c.sent(),n=-1,s=0;s<ew(r,tf).length;s++)if(!(e>ew(r,tf)[s].start)){n=s;break}if(-1===n)throw Error("Not found subtitle by time");return o=(a=ew(r,tf).slice(0,n).map(function(t){return(0,es._)({},t)})).at(-1),l=null,null!=o&&o.end>e&&(l={start:0,end:o.end-e,text:o.text},o.end=e),u=ew(r,tf).slice(n).map(function(t){return(0,ea._)((0,es._)({},t),{start:t.start-e,end:t.end-e})}),[2,(null!=l&&u.unshift(l),[new t(a,ew(r,tp)),new t(u,ew(r,tp))])]}})})()}},{key:"clone",value:function(){var e=this;return(0,t5._)(function(){return(0,ec._)(this,function(r){return[2,new t(ew(e,tf).slice(0),ew(e,tp))]})})()}},{key:"destroy",value:function(){var t;null==(t=ew(this,ty))||t.close()}}]),t}();tf=new WeakMap,td=new WeakMap,tp=new WeakMap,t_=new WeakMap,tm=new WeakMap,ty=new WeakMap,tg=new WeakMap,tv=new WeakMap,tb=new WeakSet,tw=function(t){var e=t.split("\n").reverse().map(function(t){return t.trim()}),r=ew(this,t_),n=r.width,s=r.height,a=ew(this,tp),o=a.color,l=a.fontSize,u=a.textBgColor,c=a.textShadow,h=a.strokeStyle,f=a.lineWidth,d=a.lineCap,p=a.lineJoin,_=a.bottomOffset,m=ew(this,tm);m.clearRect(0,0,n,s),m.globalAlpha=.6;var y=_,g=!0,v=!1,b=void 0;try{for(var w,S=e[Symbol.iterator]();!(g=(w=S.next()).done);g=!0){var x=w.value,U=m.measureText(x),E=n/2;null!=u&&(m.shadowOffsetX=0,m.shadowOffsetY=0,m.shadowBlur=0,m.fillStyle=u,m.globalAlpha=.5,m.fillRect(E-U.actualBoundingBoxLeft-ew(this,tv),s-y-ew(this,tg),U.width+2*ew(this,tv),ew(this,tg))),m.shadowColor=c.color,m.shadowOffsetX=c.offsetX,m.shadowOffsetY=c.offsetY,m.shadowBlur=c.blur,m.globalAlpha=1,null!=h&&(m.lineWidth=null!=f?f:l/6,null!=d&&(m.lineCap=d),null!=p&&(m.lineJoin=p),m.strokeStyle=h,m.strokeText(x,E,s-y-ew(this,tg)+ew(this,tv))),m.fillStyle=o,m.fillText(x,E,s-y-ew(this,tg)+ew(this,tv)),y+=ew(this,tg)+.2*l}}catch(t){v=!0,b=t}finally{try{g||null==S.return||S.return()}finally{if(v)throw b}}};var rt=e7;function re(t){var e=t.match(/(\d{2}):(\d{2}):(\d{2}),(\d{3})/);if(null==e)throw Error("time format error: ".concat(t));return 3600*Number(e[1])+60*Number(e[2])+Number(e[3])+Number(e[4])/1e3}var rr=function t(){"use strict";(0,t7._)(this,t);var e,r=this;ev(this,"readable"),ev(this,"writable"),eS(this,tS,0);var n=ed.default.createFile(),s=!1;this.readable=new ReadableStream({start:function(t){n.onReady=function(e){var r,s,a=null==(r=e.videoTracks[0])?void 0:r.id;null!=a&&n.setExtractionOptions(a,"video",{nbSamples:100});var o=null==(s=e.audioTracks[0])?void 0:s.id;null!=o&&n.setExtractionOptions(o,"audio",{nbSamples:100}),t.enqueue({chunkType:"ready",data:{info:e,file:n}}),n.start()};var e={};n.onSamples=function(r,s,a){var o;t.enqueue({chunkType:"samples",data:{id:r,type:s,samples:a.map(function(t){return(0,es._)({},t)})}}),e[r]=(null!=(o=e[r])?o:0)+a.length,n.releaseUsedSamples(r,e[r])},n.onFlush=function(){t.close()}},cancel:function(){n.stop(),s=!0}},{highWaterMark:50}),this.writable=new WritableStream({write:(e=(0,t5._)(function(t){var e;return(0,ec._)(this,function(a){return s?r.writable.abort():((e=t.buffer).fileStart=ew(r,tS),ex(r,tS,ew(r,tS)+e.byteLength),n.appendBuffer(e)),[2]})}),function(t){return e.apply(this,arguments)}),close:function(){var t;n.flush(),n.stop(),null==(t=n.onFlush)||t.call(n)}})};function ri(t){return rn.apply(this,arguments)}function rn(){return(rn=(0,t5._)(function(t){var e,r,n;return(0,ec._)(this,function(s){switch(s.label){case 0:return r=function(t){var e=0,r=t.boxes,n=[],s=0;function a(){return o.apply(this,arguments)}function o(){return(o=(0,t5._)(function(){var a,o;return(0,ec._)(this,function(o){switch(o.label){case 0:if(a=_(r,e),e=r.length,n.forEach(function(e){var r=e.track,n=e.id,a=r.samples.at(-1);null!=a&&(s=Math.max(s,a.cts+a.duration)),t.releaseUsedSamples(n,r.samples.length),r.samples=[]}),t.mdats=[],t.moofs=[],null==a)return[3,2];return[4,null==f?void 0:f.write(a)];case 1:o.sent(),o.label=2;case 2:return[2]}})})).apply(this,arguments)}var l=[];function u(){if(l.length>0)return!0;var s=r.findIndex(function(t){return"moov"===t.type});if(-1===s)return!1;if(l=r.slice(0,s+1),e=s+1,0===n.length)for(var a=1;;a+=1){var o=t.getTrackById(a);if(null==o)break;n.push({track:o,id:a})}return!0}var c=0,h=(0,em.tmpfile)(),f=null,d=(0,t5._)(function(){return(0,ec._)(this,function(t){switch(t.label){case 0:return[4,h.createWriter()];case 1:return f=t.sent(),c=self.setInterval(function(){u()&&a()},100),[2]}})})(),p=!1;return(0,t5._)(function(){var e,r,n;return(0,ec._)(this,function(o){switch(o.label){case 0:if(p)throw Error("File exported");return p=!0,[4,d];case 1:if(o.sent(),clearInterval(c),!u()||null==f)return[2,null];return t.flush(),[4,a()];case 2:return o.sent(),[4,null==f?void 0:f.close()];case 3:if(o.sent(),null==(e=l.find(function(t){return"moov"===t.type})))return[2,null];return e.mvhd.duration=s,r=(0,em.tmpfile)(),n=_(l,0),[4,(0,em.write)(r,n)];case 4:return o.sent(),[4,(0,em.write)(r,h,{overwrite:!1})];case 5:return o.sent(),[4,r.stream()];case 6:return[2,o.sent()]}})});function _(t,e){if(e>=t.length)return null;var r=new ed.default.DataStream;r.endianness=ed.default.DataStream.BIG_ENDIAN;for(var n=e;n<t.length;n++)null!==t[n]&&(t[n].write(r),delete t[n]);return new Uint8Array(r.buffer)}}(e=ed.default.createFile()),[4,function(t,e){return rs.apply(this,arguments)}(t,e)];case 1:return s.sent(),[4,r()];case 2:if(null==(n=s.sent()))throw Error("Can not generate file from streams");return[2,n]}})})).apply(this,arguments)}function rs(){return(rs=(0,t5._)(function(t,e){var r,n,s,a,o,l,u,c,h,f,d,p,_,m,y;return(0,ec._)(this,function(g){switch(g.label){case 0:r=0,n=0,s=0,a=0,o=0,l=0,u=null,c=null,h=!0,f=!1,d=void 0,g.label=1;case 1:g.trys.push([1,6,7,8]),p=function(){var t;return(0,ec._)(this,function(h){switch(h.label){case 0:var f;return t=m.value,[4,new Promise((f=(0,t5._)(function(h){return(0,ec._)(this,function(f){var d;return(0,ep.autoReadStream)(t.pipeThrough(new rr),{onDone:h,onChunk:(d=(0,t5._)(function(t){var h,f,d,p,_,m,y,g,v,b,w;return(0,ec._)(this,function(S){if(h=t.chunkType,f=t.data,"ready"===h)p=(d=eM(f.file,f.info)).videoTrackConf,_=d.audioTrackConf,0===r&&null!=p&&(r=e.addTrack(p)),0===a&&null!=_&&(a=e.addTrack(_));else if("samples"===h){if(m=f.type,y=f.samples,g="video"===m?r:a,v="video"===m?n:o,b="video"===m?s:l,y.forEach(function(t){e.addSample(g,t.data,{duration:t.duration,dts:t.dts+v,cts:t.cts+b,is_sync:t.is_sync})}),null==(w=y.at(-1)))return[2];"video"===m?u=w:"audio"===m&&(c=w)}return[2]})}),function(t){return d.apply(this,arguments)})}),[2]})}),function(t){return f.apply(this,arguments)}))];case 1:return h.sent(),null!=u&&(n+=u.dts,s+=u.cts),null!=c&&(o+=c.dts,l+=c.cts),[2]}})},_=t[Symbol.iterator](),g.label=2;case 2:if(h=(m=_.next()).done)return[3,5];return[5,(0,eh._)(p())];case 3:g.sent(),g.label=4;case 4:return h=!0,[3,2];case 5:return[3,8];case 6:return y=g.sent(),f=!0,d=y,[3,8];case 7:try{h||null==_.return||_.return()}finally{if(f)throw d}return[7];case 8:return[2]}})})).apply(this,arguments)}function ra(t){return ro.apply(this,arguments)}function ro(){return(ro=(0,t5._)(function(t){return(0,ec._)(this,function(e){switch(e.label){case 0:return[4,ri([t])];case 1:return[2,e.sent()]}})})).apply(this,arguments)}function rl(t,e){ep.Log.info("mixinMP4AndAudio, opts:",{volume:e.volume,loop:e.loop});var r,n=ed.default.createFile(),s=(0,ep.file2stream)(n,500),a=s.stream,o=s.stop,l=null,u=null,c=[],h=0,f=0,d=0,p=!0,_=eR.sampleRate;function m(t){var r=c.map(function(r){return e.loop?eP(r,d,d+t):r.slice(d,d+t)}),n=!0,s=!1,a=void 0;if(d+=t,1!==e.volume)try{for(var o,l=r[Symbol.iterator]();!(n=(o=l.next()).done);n=!0)for(var u=o.value,h=0;h<u.length;h++)u[h]*=e.volume}catch(t){s=!0,a=t}finally{try{n||null==l.return||l.return()}finally{if(s)throw a}}return r}function y(){return(y=(0,t5._)(function(t){var e,r,n;return(0,ec._)(this,function(s){return e=t[0],0!==(n=eB([m(Math.floor(((r=t[t.length-1]).cts+r.duration-e.cts)/r.timescale*_))])).length&&(null==u||u.encode(n,e.cts/e.timescale*1e6)),[2]})})).apply(this,arguments)}function g(){return(g=(0,t5._)(function(t){var e,r,n;return(0,ec._)(this,function(s){switch(s.label){case 0:if(null==l)return[2];return[4,l.decode(t)];case 1:return r=m((e=function(t){for(var e=[],r=0;r<t.length;r+=1)for(var n=0;n<t[r].length;n+=1)null==e[n]&&(e[n]=[]),e[n].push(t[r][n]);return e.map(eA)}(s.sent().map(eT)))[0].length),n=t[0],null==u||u.encode(eB([e,r]),n.cts/n.timescale*1e6),[2]}})})).apply(this,arguments)}return(0,ep.autoReadStream)(t.pipeThrough(new rr),{onDone:(0,t5._)(function(){return(0,ec._)(this,function(t){switch(t.label){case 0:return[4,null==u?void 0:u.stop()];case 1:return t.sent(),null==l||l.close(),o(),[2]}})}),onChunk:(r=(0,t5._)(function(t){var r,s,a,o,d,m,v,b,w,S,x,U,E,k,A;return(0,ec._)(this,function(k){switch(k.label){case 0:if(r=t.chunkType,s=t.data,"ready"!==r)return[3,3];return o=(a=eM(s.file,s.info)).videoTrackConf,d=a.audioTrackConf,m=a.audioDecoderConf,0===h&&null!=o&&(h=n.addTrack(o)),v=null!=d?d:{timescale:1e6,samplerate:_,channel_count:eR.channelCount,hdlr:"soun",name:"SoundHandler",type:"mp4a"},0===f&&(f=n.addTrack(v),_=null!=(b=null==d?void 0:d.samplerate)?b:_,p=null!=d),S=(w=new AudioContext({sampleRate:_})).decodeAudioData,[4,new Response(e.stream).arrayBuffer()];case 1:return[4,S.apply(w,[k.sent()])];case 2:var A,T,C,I;return c=eC.apply(void 0,[k.sent()]),null!=m&&(A=m,T=[],(C=new AudioDecoder({output:function(t){T.push(t)},error:ep.Log.error})).configure(A),l={decode:(I=(0,t5._)(function(t){var e;return(0,ec._)(this,function(r){switch(r.label){case 0:return t.forEach(function(t){C.decode(new EncodedAudioChunk({type:t.is_sync?"key":"delta",timestamp:1e6*t.cts/t.timescale,duration:1e6*t.duration/t.timescale,data:t.data}))}),[4,C.flush()];case 1:return r.sent(),e=T,[2,(T=[],e)]}})}),function(t){return I.apply(this,arguments)}),close:function(){C.close()}}),u=function(t,e){var r,n={codec:t.codec,sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels},s=new AudioEncoder({output:function(t){var r,n,s;e((n=new ArrayBuffer(t.byteLength),t.copyTo(n),s=t.timestamp,{duration:null!=(r=t.duration)?r:0,dts:s,cts:s,is_sync:"key"===t.type,data:n}))},error:function(t){ep.Log.error("AudioEncoder error:",t,", config:",n)}});s.configure(n);var a=null;function o(e,r){return new AudioData({timestamp:r,numberOfChannels:t.numberOfChannels,numberOfFrames:e.length/t.numberOfChannels,sampleRate:t.sampleRate,format:"f32-planar",data:e})}return{encode:(r=(0,t5._)(function(t,e){return(0,ec._)(this,function(r){return null!=a&&s.encode(o(a.data,a.ts)),a={data:t,ts:e},[2]})}),function(t,e){return r.apply(this,arguments)}),stop:(0,t5._)(function(){return(0,ec._)(this,function(e){switch(e.label){case 0:return null!=a&&(function(t,e,r){for(var n=t.length-1,s=Math.min(r/2,n),a=0;a<s;a++)for(var o=1;o<=e;o++)t[Math.floor(n/o)-a]*=a/s}(a.data,t.numberOfChannels,t.sampleRate),s.encode(o(a.data,a.ts)),a=null),[4,s.flush()];case 1:return e.sent(),s.close(),[2]}})})}}(null!=m?m:{codec:"mp4a"===v.type?eR.codec:v.type,numberOfChannels:v.channel_count,sampleRate:v.samplerate},function(t){return n.addSample(f,t.data,t)}),[3,9];case 3:if("samples"!==r)return[3,9];if(x=s.id,U=s.type,E=s.samples,"video"!==U)return[3,6];if(E.forEach(function(t){return n.addSample(x,t.data,t)}),p)return[3,5];return[4,function(t){return y.apply(this,arguments)}(E)];case 4:k.sent(),k.label=5;case 5:return[2];case 6:if("audio"!==U)return[3,8];return[4,function(t){return g.apply(this,arguments)}(E)];case 7:k.sent(),k.label=8;case 8:k.label=9;case 9:return[2]}})}),function(t){return r.apply(this,arguments)})}),a}tS=new WeakMap;var ru=[-1,1,-1,-1,1,-1,1,-1,1,1,-1,1],rc=[0,1,0,0,1,0,1,0,1,1,0,1];function rh(t,e,r){var n=t.createShader(e);if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){var s=t.getShaderInfoLog(n);throw t.deleteShader(n),Error(null!=s?s:"An error occurred compiling the shaders")}return n}var rf=function(t){var e,r=null,n=null,s=t.keyColor,a=null;return e=(0,t5._)(function(e){var o,l,u;return(0,ec._)(this,function(c){var h,f,d,p,_;return((null==r||null==n||null==a)&&(null==s&&((h=new OffscreenCanvas(1,1).getContext("2d")).drawImage(e,0,0),f=h.getImageData(0,0,1,1),s=[(d=(0,eo._)(f.data,3))[0],d[1],d[2]]),r=(o=function(t){var e="document"in globalThis?globalThis.document.createElement("canvas"):new OffscreenCanvas(t.width,t.height);e.width=t.width,e.height=t.height;var r=e.getContext("webgl2",{premultipliedAlpha:!1,alpha:!0});if(null==r)throw Error("Cant create gl context");var n=function(t,e,r){var n,s=rh(t,t.VERTEX_SHADER,e),a=rh(t,t.FRAGMENT_SHADER,r),o=t.createProgram();if(t.attachShader(o,s),t.attachShader(o,a),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw Error(null!=(n=t.getProgramInfoLog(o))?n:"Unable to initialize the shader program");return o}(r,"#version 300 es\n layout (location = 0) in vec4 a_position;\n layout (location = 1) in vec2 a_texCoord;\n out vec2 v_texCoord;\n void main () {\n gl_Position = a_position;\n v_texCoord = a_texCoord;\n }\n","#version 300 es\nprecision mediump float;\nout vec4 FragColor;\nin vec2 v_texCoord;\n\nuniform sampler2D frameTexture;\nuniform vec3 keyColor;\n\n// 色度的相似度计算\nuniform float similarity;\n// 透明度的平滑度计算\nuniform float smoothness;\n// 降低绿幕饱和度,提高抠图准确度\nuniform float spill;\n\nvec2 RGBtoUV(vec3 rgb) {\n return vec2(\n rgb.r * -0.169 + rgb.g * -0.331 + rgb.b * 0.5 + 0.5,\n rgb.r * 0.5 + rgb.g * -0.419 + rgb.b * -0.081 + 0.5\n );\n}\n\nvoid main() {\n // 获取当前像素的rgba值\n vec4 rgba = texture(frameTexture, v_texCoord);\n // 计算当前像素与绿幕像素的色度差值\n vec2 chromaVec = RGBtoUV(rgba.rgb) - RGBtoUV(keyColor);\n // 计算当前像素与绿幕像素的色度距离(向量长度), 越相像则色度距离越小\n float chromaDist = sqrt(dot(chromaVec, chromaVec));\n // 设置了一个相似度阈值,baseMask为负,则表明是绿幕,为正则表明不是绿幕\n float baseMask = chromaDist - similarity;\n // 如果baseMask为负数,fullMask等于0;baseMask为正数,越大,则透明度越低\n float fullMask = pow(clamp(baseMask / smoothness, 0., 1.), 1.5);\n rgba.a = fullMask; // 设置透明度\n // 如果baseMask为负数,spillVal等于0;baseMask为整数,越小,饱和度越低\n float spillVal = pow(clamp(baseMask / spill, 0., 1.), 1.5);\n float desat = clamp(rgba.r * 0.2126 + rgba.g * 0.7152 + rgba.b * 0.0722, 0., 1.); // 计算当前像素的灰度值\n rgba.rgb = mix(vec3(desat, desat, desat), rgba.rgb, spillVal);\n FragColor = rgba;\n}\n");r.useProgram(n),r.uniform3fv(r.getUniformLocation(n,"keyColor"),t.keyColor.map(function(t){return t/255})),r.uniform1f(r.getUniformLocation(n,"similarity"),t.similarity),r.uniform1f(r.getUniformLocation(n,"smoothness"),t.smoothness),r.uniform1f(r.getUniformLocation(n,"spill"),t.spill);var s=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,s),r.bufferData(r.ARRAY_BUFFER,new Float32Array(ru),r.STATIC_DRAW);var a=r.getAttribLocation(n,"a_position");r.vertexAttribPointer(a,2,r.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT,0),r.enableVertexAttribArray(a);var o=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array(rc),r.STATIC_DRAW);var l=r.getAttribLocation(n,"a_texCoord");return r.vertexAttribPointer(l,2,r.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT,0),r.enableVertexAttribArray(l),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),{cvs:e,gl:r}}((0,es._)((0,ea._)((0,es._)({},e instanceof VideoFrame?{width:e.codedWidth,height:e.codedHeight}:{width:e.width,height:e.height}),{keyColor:s}),t))).cvs,a=function(t){var e=t.createTexture();if(null==e)throw Error("Create WebGL texture error");t.bindTexture(t.TEXTURE_2D,e);var r=t.RGBA,n=t.RGBA,s=t.UNSIGNED_BYTE,a=new Uint8Array([0,0,255,255]);return t.texImage2D(t.TEXTURE_2D,0,r,1,1,0,n,s,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),e}(n=o.gl)),p=n,_=a,p.bindTexture(p.TEXTURE_2D,_),p.texImage2D(p.TEXTURE_2D,0,p.RGBA,p.RGBA,p.UNSIGNED_BYTE,e),p.drawArrays(p.TRIANGLES,0,6),null!=globalThis.VideoFrame&&e instanceof globalThis.VideoFrame)?(u=new VideoFrame(r,{alpha:"keep",timestamp:e.timestamp,duration:null!=(l=e.duration)?l:void 0}),[2,(e.close(),u)]):[2,createImageBitmap(r,{imageOrientation:e instanceof ImageBitmap?"flipY":"none"})]})}),function(t){return e.apply(this,arguments)}},rd=function(){"use strict";function t(e,r,n,s,a){(0,t7._)(this,t),eS(this,tC),eS(this,tx,new(0,ep.EventTool)),ev(this,"on",ew(this,tx).on),eS(this,tU,0),eS(this,tE,0),eS(this,tk,0),eS(this,tA,0),eS(this,tT,0),eS(this,tB,null),ev(this,"fixedAspectRatio",!1),ev(this,"fixedScaleCenter",!1),this.x=null!=e?e:0,this.y=null!=r?r:0,this.w=null!=n?n:0,this.h=null!=s?s:0,ex(this,tB,null!=a?a:null)}return(0,et._)(t,[{key:"x",get:function(){return ew(this,tU)},set:function(t){eU(this,tC,tI).call(this,"x",t)}},{key:"y",get:function(){return ew(this,tE)},set:function(t){eU(this,tC,tI).call(this,"y",t)}},{key:"w",get:function(){return ew(this,tk)},set:function(t){eU(this,tC,tI).call(this,"w",t)}},{key:"h",get:function(){return ew(this,tA)},set:function(t){eU(this,tC,tI).call(this,"h",t)}},{key:"angle",get:function(){return ew(this,tT)},set:function(t){eU(this,tC,tI).call(this,"angle",t)}},{key:"center",get:function(){var t=this.x,e=this.y;return{x:t+this.w/2,y:e+this.h/2}}},{key:"clone",value:function(){var e=new t(this.x,this.y,this.w,this.h,ew(this,tB));return e.angle=this.angle,e.fixedAspectRatio=this.fixedAspectRatio,e.fixedScaleCenter=this.fixedScaleCenter,e}},{key:"checkHit",value:function(t,e){var r,n,s,a,o=this.angle,l=this.center,u=this.x,c=this.y,h=this.w,f=this.h,d=null!=(s=null==(r=ew(this,tB))?void 0:r.center)?s:l,p=null!=(a=null==(n=ew(this,tB))?void 0:n.angle)?a:o;null==ew(this,tB)&&(u-=d.x,c-=d.y);var _=t-d.x,m=e-d.y,y=_,g=m;return 0!==p&&(y=_*Math.cos(p)+m*Math.sin(p),g=m*Math.cos(p)-_*Math.sin(p)),!(y<u||y>u+h||g<c||g>c+f)}}]),t}();tx=new WeakMap,tU=new WeakMap,tE=new WeakMap,tk=new WeakMap,tA=new WeakMap,tT=new WeakMap,tC=new WeakSet,tI=function(t,e){var r=this[t]!==e;switch(t){case"x":ex(this,tU,e);break;case"y":ex(this,tE,e);break;case"w":ex(this,tk,e);break;case"h":ex(this,tA,e);break;case"angle":ex(this,tT,e)}r&&ew(this,tx).emit("propsChange",(0,ee._)({},t,e))},tB=new WeakMap;var rp=rd,r_=function(){"use strict";function t(){var e=this;(0,t7._)(this,t),ev(this,"rect",new rp),eS(this,tz,{offset:0,duration:0,playbackRate:1}),eS(this,tF,new(0,ep.EventTool)),ev(this,"on",ew(this,tF).on),eS(this,tP,0),ev(this,"opacity",1),ev(this,"flip",null),eS(this,tL,null),eS(this,tR,null),ev(this,"ready",Promise.resolve()),this.rect.on("propsChange",function(t){ew(e,tF).emit("propsChange",{rect:t})})}return(0,et._)(t,[{key:"time",get:function(){return ew(this,tz)},set:function(t){Object.assign(ew(this,tz),t)}},{key:"zIndex",get:function(){return ew(this,tP)},set:function(t){var e=ew(this,tP)!==t;ex(this,tP,t),e&&ew(this,tF).emit("propsChange",{zIndex:t})}},{key:"_render",value:function(t){var e=this.rect,r=e.center,n=e.angle;t.setTransform("horizontal"===this.flip?-1:1,0,0,"vertical"===this.flip?-1:1,r.x,r.y),t.rotate((null==this.flip?1:-1)*n),t.globalAlpha=this.opacity}},{key:"setAnimation",value:function(t,e){var r,n;ex(this,tL,Object.entries(t).map(function(t){var e,r=(0,eo._)(t,2),n=r[0],s=r[1],a=null!=(e=({from:0,to:100})[n])?e:Number(n.slice(0,-1));if(isNaN(a)||a>100||a<0)throw Error("keyFrame must between 0~100");return[a/100,s]})),ex(this,tR,Object.assign({},ew(this,tR),{duration:e.duration,delay:null!=(r=e.delay)?r:0,iterCount:null!=(n=e.iterCount)?n:1/0}))}},{key:"animate",value:function(t){if(null!=ew(this,tL)&&null!=ew(this,tR)&&!(t<ew(this,tR).delay)){var e=function(t,e,r){var n=t-r.delay;if(n/r.duration>=r.iterCount)return{};var s=n%r.duration,a=n===r.duration?1:s/r.duration,o=e.findIndex(function(t){return t[0]>=a});if(-1===o)return{};var l=e[o-1],u=e[o],c=u[1];if(null==l)return c;var h=l[1],f={},d=(a-l[0])/(u[0]-l[0]);for(var p in c)null!=h[p]&&(f[p]=(c[p]-h[p])*d+h[p]);return f}(t,ew(this,tL),ew(this,tR));for(var r in e)switch(r){case"opacity":this.opacity=e[r];break;case"x":case"y":case"w":case"h":case"angle":this.rect[r]=e[r]}}}},{key:"copyStateTo",value:function(t){ex(t,tL,ew(this,tL)),ex(t,tR,ew(this,tR)),t.zIndex=this.zIndex,t.opacity=this.opacity,t.flip=this.flip,t.rect=this.rect.clone(),t.time=(0,es._)({},this.time)}},{key:"destroy",value:function(){ew(this,tF).destroy()}}]),t}();tz=new WeakMap,tF=new WeakMap,tP=new WeakMap,tL=new WeakMap,tR=new WeakMap;var rm=function(t){"use strict";function e(t){var r;return(0,t7._)(this,e),eS(r=(0,t9._)(this,e),tM),eS(r,tO,null),eS(r,tD,!1),ex(r,tM,t),r.ready=t.ready.then(function(t){var e=t.width,n=t.height,s=t.duration;r.rect.w=0===r.rect.w?e:r.rect.w,r.rect.h=0===r.rect.h?n:r.rect.h,r.time.duration=0===r.time.duration?s:r.time.duration}),r}return(0,en._)(e,t),(0,et._)(e,[{key:"offscreenRender",value:function(t,r){var n=this,s=this;return(0,t5._)(function(){var a,o,l,u,c,h,f,d,p,_,m;return(0,ec._)(this,function(y){switch(y.label){case 0:return o=r*s.time.playbackRate,s.animate(o),(0,er._)((0,ei._)(e.prototype),"_render",n).call(s,t),u=(l=s.rect).w,c=l.h,[4,ew(s,tM).tick(o)];case 1:if(f=(h=y.sent()).video,d=h.audio,p=h.state,_=null!=d?d:[],null!=d&&1!==s.time.playbackRate&&(_=d.map(function(t){return eL(t,s.time.playbackRate)})),"done"===p)return[2,{audio:_,done:!0}];return[2,(null!=(m=null!=f?f:ew(s,tO))&&t.drawImage(m,-u/2,-c/2,u,c),null!=f&&(null==(a=ew(s,tO))||a.close(),ex(s,tO,f)),{audio:_,done:!1})]}})})()}},{key:"clone",value:function(){var t=this;return(0,t5._)(function(){var r,n;return(0,ec._)(this,function(s){switch(s.label){case 0:return n=e.bind,[4,ew(t,tM).clone()];case 1:return[4,(r=new(n.apply(e,[void 0,s.sent()]))).ready];case 2:return[2,(s.sent(),t.copyStateTo(r),r)]}})})()}},{key:"destroy",value:function(){var t;ew(this,tD)||(ex(this,tD,!0),ep.Log.info("OffscreenSprite destroy"),(0,er._)((0,ei._)(e.prototype),"destroy",this).call(this),null==(t=ew(this,tO))||t.close(),ex(this,tO,null),ew(this,tM).destroy())}}]),e}(r_);tM=new WeakMap,tO=new WeakMap,tD=new WeakMap;var ry=rm,rg=function(t){"use strict";function e(t){var r;return(0,t7._)(this,e),eS(r=(0,t9._)(this,e),tY),eS(r,tj),ev(r,"visible",!0),eS(r,tN,null),eS(r,tG,[]),eS(r,tW,!1),eS(r,tV,-1),eS(r,tZ,!1),ex(r,tj,t),r.ready=t.ready.then(function(t){var e=t.width,n=t.height,s=t.duration;r.rect.w=0===r.rect.w?e:r.rect.w,r.rect.h=0===r.rect.h?n:r.rect.h,r.time.duration=0===r.time.duration?s:r.time.duration}),r}return(0,en._)(e,t),(0,et._)(e,[{key:"getClip",value:function(){return ew(this,tj)}},{key:"preFrame",value:function(t){eU(this,tY,tH).call(this,t)}},{key:"render",value:function(t,r){this.animate(r),(0,er._)((0,ei._)(e.prototype),"_render",this).call(this,t);var n=this.rect,s=n.w,a=n.h;ew(this,tV)!==r&&eU(this,tY,tH).call(this,r),ex(this,tV,r);var o=ew(this,tG);ex(this,tG,[]);var l=ew(this,tN);return null!=l&&t.drawImage(l,-s/2,-a/2,s,a),{audio:o}}},{key:"copyStateTo",value:function(t){(0,er._)((0,ei._)(e.prototype),"copyStateTo",this).call(this,t),t instanceof e&&(t.visible=this.visible)}},{key:"destroy",value:function(){var t;ew(this,tZ)||(ex(this,tZ,!0),ep.Log.info("VisibleSprite destroy"),(0,er._)((0,ei._)(e.prototype),"destroy",this).call(this),null==(t=ew(this,tN))||t.close(),ex(this,tN,null),ew(this,tj).destroy())}}]),e}(r_);tj=new WeakMap,tN=new WeakMap,tG=new WeakMap,tW=new WeakMap,tY=new WeakSet,tH=function(t){var e=this;ew(this,tW)||(ex(this,tW,!0),ew(this,tj).tick(t*this.time.playbackRate).then(function(t){var r,n=t.video,s=t.audio;null!=n&&(null==(r=ew(e,tN))||r.close(),ex(e,tN,null!=n?n:null)),ex(e,tG,null!=s?s:[]),null!=s&&1!==e.time.playbackRate&&ex(e,tG,s.map(function(t){return eL(t,e.time.playbackRate)}))}).finally(function(){ex(e,tW,!1)}))},tV=new WeakMap,tZ=new WeakMap;var rv=rg,rb=0;function rw(t){return rS.apply(this,arguments)}function rS(){return(rS=(0,t5._)(function(t){var e;return(0,ec._)(this,function(e){switch(e.label){case 0:if(!(t()>50))return[3,3];return[4,eF(15)];case 1:return e.sent(),[4,rw(t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})).apply(this,arguments)}var rx=function(){"use strict";function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,t7._)(this,t),eS(this,t3),eS(this,tX,ep.Log.create("id:".concat(rb++,","))),eS(this,tK,!1),eS(this,tQ,[]),eS(this,tJ),eS(this,tq),eS(this,t$,null),eS(this,t0),eS(this,t1),eS(this,t2,new(0,ep.EventTool)),ev(this,"on",ew(this,t2).on);var r=e.width,n=void 0===r?0:r,s=e.height,a=void 0===s?0:s;ex(this,tJ,new OffscreenCanvas(n,a));var o=ew(this,tJ).getContext("2d",{alpha:!1});if(null==o)throw Error("Can not create 2d offscreen context");ex(this,tq,o),ex(this,t0,Object.assign({bgColor:"#000",width:0,height:0,videoCodec:"avc1.42E032",audio:!0,bitrate:5e6,fps:30,metaDataTags:null},e)),ex(this,t1,n*a>0)}return(0,et._)(t,[{key:"addSprite",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this;return(0,t5._)(function(){var n,s,a;return(0,ec._)(this,function(o){switch(o.label){case 0:var l,u;return n={rect:(l=["x","y","w","h"],u=t.rect,l.reduce(function(t,e){return t[e]=u[e],t},{})),time:(0,es._)({},t.time),zIndex:t.zIndex},ew(r,tX).info("Combinator add sprite",n),[4,t.clone()];case 1:return s=o.sent(),ew(r,tX).info("Combinator add sprite ready"),ew(r,tQ).push(Object.assign(s,{main:null!=(a=e.main)&&a,expired:!1})),ew(r,tQ).sort(function(t,e){return t.zIndex-e.zIndex}),[2]}})})()}},{key:"output",value:function(){var t,e=this;if(0===ew(this,tQ).length)throw Error("No sprite added");var r=ew(this,tQ).find(function(t){return t.main}),n=null!=r?r.time.offset+r.time.duration:(t=Math).max.apply(t,(0,el._)(ew(this,tQ).map(function(t){return t.time.offset+t.time.duration})));if(n===1/0)throw Error("Unable to determine the end time, please specify a main sprite, or limit the duration of ImgClip, AudioCli");-1===n&&ew(this,tX).warn("Unable to determine the end time, process value don't update"),ew(this,tX).info("start combinate video, maxTime:".concat(n));var s=eU(this,t3,t4).call(this,n),a=performance.now(),o=this,l=eU(this,t3,t6).call(this,s,n,{onProgress:function(t){ew(e,tX).debug("OutputProgress:",t),ew(e,t2).emit("OutputProgress",t)},onEnded:(0,t5._)(function(){return(0,ec._)(this,function(t){switch(t.label){case 0:return[4,s.flush()];case 1:return t.sent(),ew(o,tX).info("===== output ended =====, cost:",performance.now()-a),ew(o,t2).emit("OutputProgress",1),o.destroy(),[2]}})}),onError:function(t){ew(e,t2).emit("error",t),h(t),e.destroy()}});ex(this,t$,function(){l(),s.close(),h()});var u=(0,ep.file2stream)(s.mp4file,500,this.destroy),c=u.stream,h=u.stop;return c}},{key:"destroy",value:function(){var t;ew(this,tK)||(ex(this,tK,!0),null==(t=ew(this,t$))||t.call(this),ew(this,t2).destroy())}}],[{key:"isSupported",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(0,t5._)(function(){var e,r,n,s,a,o,l,u;return(0,ec._)(this,function(c){switch(c.label){case 0:if(!(u=null!=self.OffscreenCanvas&&null!=self.VideoEncoder&&null!=self.VideoDecoder&&null!=self.VideoFrame&&null!=self.AudioEncoder&&null!=self.AudioDecoder&&null!=self.AudioData))return[3,2];return[4,self.VideoEncoder.isConfigSupported({codec:null!=(e=t.videoCodec)?e:"avc1.42E032",width:null!=(r=t.width)?r:1920,height:null!=(n=t.height)?n:1080,bitrate:null!=(s=t.bitrate)?s:7e6})];case 1:u=null!=(a=c.sent().supported)&&a,c.label=2;case 2:if(!(l=u))return[3,4];return[4,self.AudioEncoder.isConfigSupported({codec:eR.codec,sampleRate:eR.sampleRate,numberOfChannels:eR.channelCount})];case 3:l=c.sent().supported,c.label=4;case 4:return[2,null!=(o=l)&&o]}})})()}}]),t}();tX=new WeakMap,tK=new WeakMap,tQ=new WeakMap,tJ=new WeakMap,tq=new WeakMap,t$=new WeakMap,t0=new WeakMap,t1=new WeakMap,t2=new WeakMap,t3=new WeakSet,t4=function(t){var e=ew(this,t0),r=e.fps,n=e.width,s=e.height,a=e.videoCodec,o=e.bitrate,l=e.audio,u=e.metaDataTags;return(0,ep.recodemux)({video:ew(this,t1)?{width:n,height:s,expectFPS:r,codec:a,bitrate:o,__unsafe_hardwareAcceleration__:ew(this,t0).__unsafe_hardwareAcceleration__}:null,audio:!1===l?null:{codec:"aac",sampleRate:eR.sampleRate,channelCount:eR.channelCount},duration:t,metaDataTags:u})},t6=function(t,e,r){var n=this,s=r.onProgress,a=r.onEnded,o=r.onError,l=0,u={aborted:!1},c=null,h=this;(0,t5._)(function(){var r,n,s,o,f,p,_,m,y,g,v;return(0,ec._)(this,function(b){switch(b.label){case 0:var w,S,x,U,E,k,A,T,C,I,B,z,F,P,L,R,M,O,D,j,N,G,W,Y,H,V,Z,X,K;n=(r=ew(h,t0)).fps,s=r.bgColor,o=r.audio,f=Math.round(1e6/n),x=(w={ctx:p=ew(h,tq),bgColor:s,sprites:ew(h,tQ),aborter:u}).ctx,U=w.bgColor,E=w.sprites,k=w.aborter,T=(A=x.canvas).width,C=A.height,S=(0,t5._)(function(t){var e,r,n,s,a,o,l,u,c,h,f,d;return(0,ec._)(this,function(p){switch(p.label){case 0:x.fillStyle=U,x.fillRect(0,0,T,C),e=[],r=!1,n=!0,s=!1,a=void 0,p.label=1;case 1:p.trys.push([1,6,7,8]),o=E[Symbol.iterator](),p.label=2;case 2:if((n=(l=o.next()).done)||(u=l.value,k.aborted))return[3,5];if(t<u.time.offset||u.expired)return[3,4];return x.save(),[4,u.offscreenRender(x,t-u.time.offset)];case 3:h=(c=p.sent()).audio,f=c.done,e.push(h),x.restore(),(u.time.duration>0&&t>u.time.offset+u.time.duration||f)&&(u.main&&(r=!0),u.destroy(),u.expired=!0),p.label=4;case 4:return n=!0,[3,2];case 5:return[3,8];case 6:return d=p.sent(),s=!0,a=d,[3,8];case 7:try{n||null==o.return||o.return()}finally{if(s)throw a}return[7];case 8:return[2,{audios:e,mainSprDone:r}]}})}),_=function(t){return S.apply(this,arguments)},D=(I={remux:t,ctx:p,cvs:ew(h,tJ),outputAudio:o,hasVideoTrack:ew(h,t1),timeSlice:f,fps:n}).ctx,j=I.cvs,N=I.outputAudio,G=I.remux,W=I.hasVideoTrack,Y=I.timeSlice,H=j.width,V=j.height,Z=0,X=Math.floor(3*I.fps),K=(B=1024,F=new Float32Array(3*(z=1024*eR.channelCount)),P=0,L=0,R=B/eR.sampleRate*1e6,M=new Float32Array(z),O=function(t){for(var e=0,r=Math.floor(P/z),n=[],s=0;s<r;s++)n.push(new AudioData({timestamp:L,numberOfChannels:eR.channelCount,numberOfFrames:B,sampleRate:eR.sampleRate,format:"f32",data:F.subarray(e,e+z)})),e+=z,L+=R;for(F.set(F.subarray(e,P),0),P-=e;t-L>R;)n.push(new AudioData({timestamp:L,numberOfChannels:eR.channelCount,numberOfFrames:B,sampleRate:eR.sampleRate,format:"f32",data:M})),L+=R;return n},function(t,e){for(var r=(l=Math).max.apply(l,(0,el._)(e.map(function(t){var e,r;return null!=(r=null==(e=t[0])?void 0:e.length)?r:0}))),n=0;n<r;n++){for(var s=0,a=0,o=0;o<e.length;o++){var l,u,c,h,f,d=null!=(h=null==(u=e[o][0])?void 0:u[n])?h:0,p=null!=(f=null==(c=e[o][1])?void 0:c[n])?f:d;s+=d,a+=p}F[P]=s,F[P+1]=a,P+=2}return O(t)}),m=function(t,e){var r=!0,n=!1,s=void 0;if(!1!==N)try{for(var a,o=K(t,e)[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var l=a.value;G.encodeAudio(l)}}catch(t){n=!0,s=t}finally{try{r||null==o.return||o.return()}finally{if(n)throw s}}if(W){var u=new VideoFrame(j,{duration:Y,timestamp:t});G.encodeVideo(u,{keyFrame:Z%X==0}),D.resetTransform(),D.clearRect(0,0,H,V),Z+=1}},y=0,b.label=1;case 1:if(null!=c)return[2];if(!(u.aborted||-1!==e&&y>e||0===ew(h,tQ).length))return[3,3];return d(),[4,a()];case 2:case 5:return b.sent(),[2];case 3:return l=y/e,[4,_(y)];case 4:if(v=(g=b.sent()).audios,!g.mainSprDone)return[3,6];return d(),[4,a()];case 6:if(u.aborted)return[2];return m(y,v),y+=f,[4,rw(t.getEncodeQueueSize)];case 7:b.sent(),b.label=8;case 8:return[3,1];case 9:return[2]}})})().catch(function(t){c=t,ew(n,tX).error(t),d(),o(t)});var f=setInterval(function(){s(l)},500),d=function(){u.aborted||(u.aborted=!0,clearInterval(f),ew(n,tQ).forEach(function(t){return t.destroy()}))};return d}},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_call_super.cjs":"clpdF","@swc/helpers/cjs/_class_call_check.cjs":"4Uf9M","@swc/helpers/cjs/_create_class.cjs":"igUuK","@swc/helpers/cjs/_define_property.cjs":"ltU3W","@swc/helpers/cjs/_get.cjs":"2Zl1N","@swc/helpers/cjs/_get_prototype_of.cjs":"NOGHw","@swc/helpers/cjs/_inherits.cjs":"jtSwf","@swc/helpers/cjs/_object_spread.cjs":"kyoEj","@swc/helpers/cjs/_object_spread_props.cjs":"3G1wX","@swc/helpers/cjs/_sliced_to_array.cjs":"gIQTH","@swc/helpers/cjs/_to_consumable_array.cjs":"i81N6","@swc/helpers/cjs/_type_of.cjs":"iXhRw","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@swc/helpers/cjs/_ts_values.cjs":"94P5Q","@webav/mp4box.js":"9QpMm","@webav/internal-utils":"bA9PQ","wave-resampler":"asu2z","opfs-tools":"cfRHd","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],clpdF:[function(t,e,r,n){"use strict";var s=t("feddc910f69a01a6"),a=t("b644f6b72647b399"),o=t("ba991daace2b8ed9");r._=function(t,e,r){return e=s._(e),o._(t,a._()?Reflect.construct(e,r||[],s._(t).constructor):e.apply(t,r))}},{feddc910f69a01a6:"NOGHw",b644f6b72647b399:"83nDe",ba991daace2b8ed9:"hd12h"}],NOGHw:[function(t,e,r,n){"use strict";function s(t){return r._=s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}r._=s},{}],"83nDe":[function(t,e,r,n){"use strict";function s(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(r._=s=function(){return!!t})()}r._=s},{}],hd12h:[function(t,e,r,n){"use strict";var s=t("f7151fe13994d2aa"),a=t("f18e81760bb14899");r._=function(t,e){return e&&("object"===a._(e)||"function"==typeof e)?e:s._(t)}},{f7151fe13994d2aa:"1tlYe",f18e81760bb14899:"iXhRw"}],"1tlYe":[function(t,e,r,n){"use strict";r._=function(t){if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}},{}],"4Uf9M":[function(t,e,r,n){"use strict";r._=function(t,e){if(!(t instanceof e))throw TypeError("Cannot call a class as a function")}},{}],igUuK:[function(t,e,r,n){"use strict";function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r._=function(t,e,r){return e&&s(t.prototype,e),r&&s(t,r),t}},{}],ltU3W:[function(t,e,r,n){"use strict";r._=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}},{}],"2Zl1N":[function(t,e,r,n){"use strict";var s=t("eccd5cff84eb670a");function a(t,e,n){return"undefined"!=typeof Reflect&&Reflect.get?r._=a=Reflect.get:r._=a=function(t,e,r){var n=s._(t,e);if(n){var a=Object.getOwnPropertyDescriptor(n,e);return a.get?a.get.call(r||t):a.value}},a(t,e,n||t)}r._=a},{eccd5cff84eb670a:"8BvWV"}],"8BvWV":[function(t,e,r,n){"use strict";var s=t("4bc9bfb4aa5f6a");r._=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s._(t)););return t}},{"4bc9bfb4aa5f6a":"NOGHw"}],jtSwf:[function(t,e,r,n){"use strict";var s=t("b9db138b859a042c");r._=function(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s._(t,e)}},{b9db138b859a042c:"7ubVA"}],"7ubVA":[function(t,e,r,n){"use strict";function s(t,e){return r._=s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},s(t,e)}r._=s},{}],kyoEj:[function(t,e,r,n){"use strict";var s=t("9f9b8a24218ee51e");r._=function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){s._(t,e,r[e])})}return t}},{"9f9b8a24218ee51e":"ltU3W"}],"3G1wX":[function(t,e,r,n){"use strict";r._=function(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):(function(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r.push.apply(r,n)}return r})(Object(e)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}},{}],gIQTH:[function(t,e,r,n){"use strict";var s=t("d7c30a5ae0c1ab2"),a=t("3aacfce52f67defd"),o=t("f0dae09a1a08b16a"),l=t("83f3648e614d0830");r._=function(t,e){return s._(t)||a._(t,e)||l._(t,e)||o._()}},{d7c30a5ae0c1ab2:"3QSPl","3aacfce52f67defd":"5SSeo",f0dae09a1a08b16a:"heYSj","83f3648e614d0830":"fh7mx"}],"3QSPl":[function(t,e,r,n){"use strict";r._=function(t){if(Array.isArray(t))return t}},{}],"5SSeo":[function(t,e,r,n){"use strict";r._=function(t,e){var r,n,s=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=s){var a=[],o=!0,l=!1;try{for(s=s.call(t);!(o=(r=s.next()).done)&&(a.push(r.value),!e||a.length!==e);o=!0);}catch(t){l=!0,n=t}finally{try{o||null==s.return||s.return()}finally{if(l)throw n}}return a}}},{}],heYSj:[function(t,e,r,n){"use strict";r._=function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},{}],fh7mx:[function(t,e,r,n){"use strict";var s=t("3ee51b7dc02d0c44");r._=function(t,e){if(t){if("string"==typeof t)return s._(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);if("Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s._(t,e)}}},{"3ee51b7dc02d0c44":"1WOAB"}],"1WOAB":[function(t,e,r,n){"use strict";r._=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}},{}],i81N6:[function(t,e,r,n){"use strict";var s=t("d402183024004bc7"),a=t("3209e2b12672cd18"),o=t("fc58adb8f1bff142"),l=t("5e213dc122a10171");r._=function(t){return s._(t)||a._(t)||l._(t)||o._()}},{d402183024004bc7:"hfQG0","3209e2b12672cd18":"fQrlQ",fc58adb8f1bff142:"fWabh","5e213dc122a10171":"fh7mx"}],hfQG0:[function(t,e,r,n){"use strict";var s=t("5bd5b10bf87fc8e");r._=function(t){if(Array.isArray(t))return s._(t)}},{"5bd5b10bf87fc8e":"1WOAB"}],fQrlQ:[function(t,e,r,n){"use strict";r._=function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}},{}],fWabh:[function(t,e,r,n){"use strict";r._=function(){throw TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},{}],"94P5Q":[function(t,e,r,n){"use strict";r._=t("2ed00358a4809745").__values},{"2ed00358a4809745":"6yrAu"}],"9QpMm":[function(t,e,r,n){var s,a,o=t("@swc/helpers/cjs/_type_of.cjs"),l=(s=new Date,a=4,{setLogLevel:function(t){t==this.debug?a=1:t==this.info?a=2:t==this.warn?a=3:(this.error,a=4)},debug:function(t,e){void 0===console.debug&&(console.debug=console.log),1>=a&&console.debug("["+l.getDurationString(new Date-s,1e3)+"]","["+t+"]",e)},log:function(t,e){this.debug(t.msg)},info:function(t,e){2>=a&&console.info("["+l.getDurationString(new Date-s,1e3)+"]","["+t+"]",e)},warn:function(t,e){3>=a&&console.warn("["+l.getDurationString(new Date-s,1e3)+"]","["+t+"]",e)},error:function(t,e){4>=a&&console.error("["+l.getDurationString(new Date-s,1e3)+"]","["+t+"]",e)}});l.getDurationString=function(t,e){function r(t,e){for(var r=(""+t).split(".");r[0].length<e;)r[0]="0"+r[0];return r.join(".")}t<0?(n=!0,t=-t):n=!1;var n,s=t/(e||1),a=Math.floor(s/3600),o=Math.floor((s-=3600*a)/60),l=1e3*(s-=60*o);return l-=1e3*(s=Math.floor(s)),l=Math.floor(l),(n?"-":"")+a+":"+r(o,2)+":"+r(s,2)+"."+r(l,3)},l.printRanges=function(t){var e=t.length;if(!(e>0))return"(empty)";for(var r="",n=0;n<e;n++)n>0&&(r+=","),r+="["+l.getDurationString(t.start(n))+","+l.getDurationString(t.end(n))+"]";return r},r.Log=l;var u=function(t){if(t instanceof ArrayBuffer)this.buffer=t,this.dataview=new DataView(t);else throw"Needs an array buffer";this.position=0};u.prototype.getPosition=function(){return this.position},u.prototype.getEndPosition=function(){return this.buffer.byteLength},u.prototype.getLength=function(){return this.buffer.byteLength},u.prototype.seek=function(t){var e=Math.max(0,Math.min(this.buffer.byteLength,t));return this.position=isNaN(e)||!isFinite(e)?0:e,!0},u.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},u.prototype.readAnyInt=function(t,e){var r=0;if(this.position+t<=this.buffer.byteLength){switch(t){case 1:r=e?this.dataview.getInt8(this.position):this.dataview.getUint8(this.position);break;case 2:r=e?this.dataview.getInt16(this.position):this.dataview.getUint16(this.position);break;case 3:if(e)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16|this.dataview.getUint8(this.position+1)<<8|this.dataview.getUint8(this.position+2);break;case 4:r=e?this.dataview.getInt32(this.position):this.dataview.getUint32(this.position);break;case 8:if(e)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32|this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+t}return this.position+=t,r}throw"Not enough bytes in buffer"},u.prototype.readUint8=function(){return this.readAnyInt(1,!1)},u.prototype.readUint16=function(){return this.readAnyInt(2,!1)},u.prototype.readUint24=function(){return this.readAnyInt(3,!1)},u.prototype.readUint32=function(){return this.readAnyInt(4,!1)},u.prototype.readUint64=function(){return this.readAnyInt(8,!1)},u.prototype.readString=function(t){if(this.position+t<=this.buffer.byteLength){for(var e="",r=0;r<t;r++)e+=String.fromCharCode(this.readUint8());return e}throw"Not enough bytes in buffer"},u.prototype.readCString=function(){for(var t=[];;){var e=this.readUint8();if(0!==e)t.push(e);else break}return String.fromCharCode.apply(null,t)},u.prototype.readInt8=function(){return this.readAnyInt(1,!0)},u.prototype.readInt16=function(){return this.readAnyInt(2,!0)},u.prototype.readInt32=function(){return this.readAnyInt(4,!0)},u.prototype.readInt64=function(){return this.readAnyInt(8,!1)},u.prototype.readUint8Array=function(t){for(var e=new Uint8Array(t),r=0;r<t;r++)e[r]=this.readUint8();return e},u.prototype.readInt16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readInt16();return e},u.prototype.readUint16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readUint16();return e},u.prototype.readUint32Array=function(t){for(var e=new Uint32Array(t),r=0;r<t;r++)e[r]=this.readUint32();return e},u.prototype.readInt32Array=function(t){for(var e=new Int32Array(t),r=0;r<t;r++)e[r]=this.readInt32();return e},r.MP4BoxStream=u;var c=function(t,e,r){this._byteOffset=e||0,t instanceof ArrayBuffer?this.buffer=t:(void 0===t?"undefined":(0,o._)(t))=="object"?(this.dataView=t,e&&(this._byteOffset+=e)):this.buffer=new ArrayBuffer(t||0),this.position=0,this.endianness=null==r?c.LITTLE_ENDIAN:r};c.prototype={},c.prototype.getPosition=function(){return this.position},c.prototype._realloc=function(t){if(this._dynamicSize){var e=this._byteOffset+this.position+t,r=this._buffer.byteLength;if(e<=r){e>this._byteLength&&(this._byteLength=e);return}for(r<1&&(r=1);e>r;)r*=2;var n=new ArrayBuffer(r),s=new Uint8Array(this._buffer);new Uint8Array(n,0,s.length).set(s),this.buffer=n,this._byteLength=e}},c.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var t=new ArrayBuffer(this._byteLength),e=new Uint8Array(t),r=new Uint8Array(this._buffer,0,e.length);e.set(r),this.buffer=t}},c.BIG_ENDIAN=!1,c.LITTLE_ENDIAN=!0,c.prototype._byteLength=0,Object.defineProperty(c.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(c.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(t){this._buffer=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(c.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(c.prototype,"dataView",{get:function(){return this._dataView},set:function(t){this._byteOffset=t.byteOffset,this._buffer=t.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}}),c.prototype.seek=function(t){var e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e},c.prototype.isEof=function(){return this.position>=this._byteLength},c.prototype.mapUint8Array=function(t){this._realloc(+t);var e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=+t,e},c.prototype.readInt32Array=function(t,e){var r=new Int32Array(t=null==t?this.byteLength-this.position/4:t);return c.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),c.arrayToNative(r,null==e?this.endianness:e),this.position+=r.byteLength,r},c.prototype.readInt16Array=function(t,e){var r=new Int16Array(t=null==t?this.byteLength-this.position/2:t);return c.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),c.arrayToNative(r,null==e?this.endianness:e),this.position+=r.byteLength,r},c.prototype.readInt8Array=function(t){var e=new Int8Array(t=null==t?this.byteLength-this.position:t);return c.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},c.prototype.readUint32Array=function(t,e){var r=new Uint32Array(t=null==t?this.byteLength-this.position/4:t);return c.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),c.arrayToNative(r,null==e?this.endianness:e),this.position+=r.byteLength,r},c.prototype.readUint16Array=function(t,e){var r=new Uint16Array(t=null==t?this.byteLength-this.position/2:t);return c.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),c.arrayToNative(r,null==e?this.endianness:e),this.position+=r.byteLength,r},c.prototype.readUint8Array=function(t){var e=new Uint8Array(t=null==t?this.byteLength-this.position:t);return c.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},c.prototype.readFloat64Array=function(t,e){var r=new Float64Array(t=null==t?this.byteLength-this.position/8:t);return c.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),c.arrayToNative(r,null==e?this.endianness:e),this.position+=r.byteLength,r},c.prototype.readFloat32Array=function(t,e){var r=new Float32Array(t=null==t?this.byteLength-this.position/4:t);return c.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),c.arrayToNative(r,null==e?this.endianness:e),this.position+=r.byteLength,r},c.prototype.readInt32=function(t){var e=this._dataView.getInt32(this.position,null==t?this.endianness:t);return this.position+=4,e},c.prototype.readInt16=function(t){var e=this._dataView.getInt16(this.position,null==t?this.endianness:t);return this.position+=2,e},c.prototype.readInt8=function(){var t=this._dataView.getInt8(this.position);return this.position+=1,t},c.prototype.readUint32=function(t){var e=this._dataView.getUint32(this.position,null==t?this.endianness:t);return this.position+=4,e},c.prototype.readUint16=function(t){var e=this._dataView.getUint16(this.position,null==t?this.endianness:t);return this.position+=2,e},c.prototype.readUint8=function(){var t=this._dataView.getUint8(this.position);return this.position+=1,t},c.prototype.readFloat32=function(t){var e=this._dataView.getFloat32(this.position,null==t?this.endianness:t);return this.position+=4,e},c.prototype.readFloat64=function(t){var e=this._dataView.getFloat64(this.position,null==t?this.endianness:t);return this.position+=8,e},c.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,c.memcpy=function(t,e,r,n,s){var a=new Uint8Array(t,e,s),o=new Uint8Array(r,n,s);a.set(o)},c.arrayToNative=function(t,e){return e==this.endianness?t:this.flipArrayEndianness(t)},c.nativeToEndian=function(t,e){return this.endianness==e?t:this.flipArrayEndianness(t)},c.flipArrayEndianness=function(t){for(var e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=0;r<t.byteLength;r+=t.BYTES_PER_ELEMENT)for(var n=r+t.BYTES_PER_ELEMENT-1,s=r;n>s;n--,s++){var a=e[s];e[s]=e[n],e[n]=a}return t},c.prototype.failurePosition=0,String.fromCharCodeUint8=function(t){for(var e=[],r=0;r<t.length;r++)e[r]=t[r];return String.fromCharCode.apply(null,e)},c.prototype.readString=function(t,e){return null==e||"ASCII"==e?String.fromCharCodeUint8.apply(null,[this.mapUint8Array(null==t?this.byteLength-this.position:t)]):new TextDecoder(e).decode(this.mapUint8Array(t))},c.prototype.readCString=function(t){var e=this.byteLength-this.position,r=new Uint8Array(this._buffer,this._byteOffset+this.position),n=e;null!=t&&(n=Math.min(t,e));for(var s=0;s<n&&0!==r[s];s++);var a=String.fromCharCodeUint8.apply(null,[this.mapUint8Array(s)]);return null!=t?this.position+=n-s:s!=e&&(this.position+=1),a},c.prototype.readInt64=function(){return 0x100000000*this.readInt32()+this.readUint32()},c.prototype.readUint64=function(){return 0x100000000*this.readUint32()+this.readUint32()},c.prototype.readInt64=function(){return 0x100000000*this.readUint32()+this.readUint32()},c.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()},r.DataStream=c,c.prototype.save=function(t){var e=new Blob([this.buffer]);if(window.URL&&URL.createObjectURL){var r=window.URL.createObjectURL(e),n=document.createElement("a");document.body.appendChild(n),n.setAttribute("href",r),n.setAttribute("download",t),n.setAttribute("target","_self"),n.click(),window.URL.revokeObjectURL(r)}else throw"DataStream.save: Can't create object URL."},c.prototype._dynamicSize=!0,Object.defineProperty(c.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(t){t||this._trimAlloc(),this._dynamicSize=t}}),c.prototype.shift=function(t){var e=new ArrayBuffer(this._byteLength-t),r=new Uint8Array(e),n=new Uint8Array(this._buffer,t,r.length);r.set(n),this.buffer=e,this.position-=t},c.prototype.writeInt32Array=function(t,e){if(this._realloc(4*t.length),t instanceof Int32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt32(t[r],e)},c.prototype.writeInt16Array=function(t,e){if(this._realloc(2*t.length),t instanceof Int16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt16(t[r],e)},c.prototype.writeInt8Array=function(t){if(this._realloc(+t.length),t instanceof Int8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt8Array(t.length);else for(var e=0;e<t.length;e++)this.writeInt8(t[e])},c.prototype.writeUint32Array=function(t,e){if(this._realloc(4*t.length),t instanceof Uint32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint32(t[r],e)},c.prototype.writeUint16Array=function(t,e){if(this._realloc(2*t.length),t instanceof Uint16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint16(t[r],e)},c.prototype.writeUint8Array=function(t){if(this._realloc(+t.length),t instanceof Uint8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint8Array(t.length);else for(var e=0;e<t.length;e++)this.writeUint8(t[e])},c.prototype.writeFloat64Array=function(t,e){if(this._realloc(8*t.length),t instanceof Float64Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat64Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat64(t[r],e)},c.prototype.writeFloat32Array=function(t,e){if(this._realloc(4*t.length),t instanceof Float32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)c.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat32(t[r],e)},c.prototype.writeInt32=function(t,e){this._realloc(4),this._dataView.setInt32(this.position,t,null==e?this.endianness:e),this.position+=4},c.prototype.writeInt16=function(t,e){this._realloc(2),this._dataView.setInt16(this.position,t,null==e?this.endianness:e),this.position+=2},c.prototype.writeInt8=function(t){this._realloc(1),this._dataView.setInt8(this.position,t),this.position+=1},c.prototype.writeUint32=function(t,e){this._realloc(4),this._dataView.setUint32(this.position,t,null==e?this.endianness:e),this.position+=4},c.prototype.writeUint16=function(t,e){this._realloc(2),this._dataView.setUint16(this.position,t,null==e?this.endianness:e),this.position+=2},c.prototype.writeUint8=function(t){this._realloc(1),this._dataView.setUint8(this.position,t),this.position+=1},c.prototype.writeFloat32=function(t,e){this._realloc(4),this._dataView.setFloat32(this.position,t,null==e?this.endianness:e),this.position+=4},c.prototype.writeFloat64=function(t,e){this._realloc(8),this._dataView.setFloat64(this.position,t,null==e?this.endianness:e),this.position+=8},c.prototype.writeUCS2String=function(t,e,r){null==r&&(r=t.length);for(var n=0;n<t.length&&n<r;n++)this.writeUint16(t.charCodeAt(n),e);for(;n<r;n++)this.writeUint16(0)},c.prototype.writeString=function(t,e,r){var n=0;if(null==e||"ASCII"==e)if(null!=r){var s=Math.min(t.length,r);for(n=0;n<s;n++)this.writeUint8(t.charCodeAt(n));for(;n<r;n++)this.writeUint8(0)}else for(n=0;n<t.length;n++)this.writeUint8(t.charCodeAt(n));else this.writeUint8Array(new TextEncoder(e).encode(t.substring(0,r)))},c.prototype.writeCString=function(t,e){var r=0;if(null!=e){var n=Math.min(t.length,e);for(r=0;r<n;r++)this.writeUint8(t.charCodeAt(r));for(;r<e;r++)this.writeUint8(0)}else{for(r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));this.writeUint8(0)}},c.prototype.writeStruct=function(t,e){for(var r=0;r<t.length;r+=2){var n=t[r+1];this.writeType(n,e[t[r]],e)}},c.prototype.writeType=function(t,e,r){if("function"==typeof t)return t(this,e);if((void 0===t?"undefined":(0,o._)(t))=="object"&&!(t instanceof Array))return t.set(this,e,r);var n,s=null,a="ASCII",l=this.position;switch("string"==typeof t&&/:/.test(t)&&(t=(n=t.split(":"))[0],s=parseInt(n[1])),"string"==typeof t&&/,/.test(t)&&(t=(n=t.split(","))[0],a=parseInt(n[1])),t){case"uint8":this.writeUint8(e);break;case"int8":this.writeInt8(e);break;case"uint16":this.writeUint16(e,this.endianness);break;case"int16":this.writeInt16(e,this.endianness);break;case"uint32":this.writeUint32(e,this.endianness);break;case"int32":this.writeInt32(e,this.endianness);break;case"float32":this.writeFloat32(e,this.endianness);break;case"float64":this.writeFloat64(e,this.endianness);break;case"uint16be":this.writeUint16(e,c.BIG_ENDIAN);break;case"int16be":this.writeInt16(e,c.BIG_ENDIAN);break;case"uint32be":this.writeUint32(e,c.BIG_ENDIAN);break;case"int32be":this.writeInt32(e,c.BIG_ENDIAN);break;case"float32be":this.writeFloat32(e,c.BIG_ENDIAN);break;case"float64be":this.writeFloat64(e,c.BIG_ENDIAN);break;case"uint16le":this.writeUint16(e,c.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(e,c.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(e,c.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(e,c.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(e,c.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(e,c.LITTLE_ENDIAN);break;case"cstring":this.writeCString(e,s);break;case"string":this.writeString(e,a,s);break;case"u16string":this.writeUCS2String(e,this.endianness,s);break;case"u16stringle":this.writeUCS2String(e,c.LITTLE_ENDIAN,s);break;case"u16stringbe":this.writeUCS2String(e,c.BIG_ENDIAN,s);break;default:if(3==t.length)for(var u=t[1],h=0;h<e.length;h++)this.writeType(u,e[h]);else this.writeStruct(t,e)}null!=s&&(this.position=l,this._realloc(s),this.position=l+s)},c.prototype.writeUint64=function(t){var e=Math.floor(t/0x100000000);this.writeUint32(e),this.writeUint32(0|t)},c.prototype.writeUint24=function(t){this.writeUint8((0xff0000&t)>>16),this.writeUint8((65280&t)>>8),this.writeUint8(255&t)},c.prototype.adjustUint32=function(t,e){var r=this.position;this.seek(t),this.writeUint32(e),this.seek(r)},c.prototype.mapInt32Array=function(t,e){this._realloc(4*t);var r=new Int32Array(this._buffer,this.byteOffset+this.position,t);return c.arrayToNative(r,null==e?this.endianness:e),this.position+=4*t,r},c.prototype.mapInt16Array=function(t,e){this._realloc(2*t);var r=new Int16Array(this._buffer,this.byteOffset+this.position,t);return c.arrayToNative(r,null==e?this.endianness:e),this.position+=2*t,r},c.prototype.mapInt8Array=function(t){this._realloc(+t);var e=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=+t,e},c.prototype.mapUint32Array=function(t,e){this._realloc(4*t);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return c.arrayToNative(r,null==e?this.endianness:e),this.position+=4*t,r},c.prototype.mapUint16Array=function(t,e){this._realloc(2*t);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return c.arrayToNative(r,null==e?this.endianness:e),this.position+=2*t,r},c.prototype.mapFloat64Array=function(t,e){this._realloc(8*t);var r=new Float64Array(this._buffer,this.byteOffset+this.position,t);return c.arrayToNative(r,null==e?this.endianness:e),this.position+=8*t,r},c.prototype.mapFloat32Array=function(t,e){this._realloc(4*t);var r=new Float32Array(this._buffer,this.byteOffset+this.position,t);return c.arrayToNative(r,null==e?this.endianness:e),this.position+=4*t,r};var h=function(t){this.buffers=[],this.bufferIndex=-1,t&&(this.insertBuffer(t),this.bufferIndex=0)};h.prototype=new c(new ArrayBuffer,0,c.BIG_ENDIAN),h.prototype.initialized=function(){var t;return!!(this.bufferIndex>-1)||(this.buffers.length>0?0===(t=this.buffers[0]).fileStart?(this.buffer=t,this.bufferIndex=0,l.debug("MultiBufferStream","Stream ready for parsing"),!0):(l.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1):(l.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1))},ArrayBuffer.concat=function(t,e){l.debug("ArrayBuffer","Trying to create a new buffer of size: "+(t.byteLength+e.byteLength));var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer},h.prototype.reduceBuffer=function(t,e,r){var n;return(n=new Uint8Array(r)).set(new Uint8Array(t,e,r)),n.buffer.fileStart=t.fileStart+e,n.buffer.usedBytes=0,n.buffer},h.prototype.insertBuffer=function(t){for(var e=!0,r=0;r<this.buffers.length;r++){var n=this.buffers[r];if(t.fileStart<=n.fileStart){if(t.fileStart===n.fileStart)if(t.byteLength>n.byteLength){this.buffers.splice(r,1),r--;continue}else l.warn("MultiBufferStream","Buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+") already appended, ignoring");else t.fileStart+t.byteLength<=n.fileStart||(t=this.reduceBuffer(t,0,n.fileStart-t.fileStart)),l.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.splice(r,0,t),0===r&&(this.buffer=t);e=!1;break}if(t.fileStart<n.fileStart+n.byteLength){var s=n.fileStart+n.byteLength-t.fileStart,a=t.byteLength-s;if(a>0)t=this.reduceBuffer(t,s,a);else{e=!1;break}}}e&&(l.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.push(t),0===r&&(this.buffer=t))},h.prototype.logBufferLevel=function(t){var e,r,n,s,a,o=[],u="";for(e=0,n=0,s=0;e<this.buffers.length;e++)r=this.buffers[e],0===e?(o.push(a={}),a.start=r.fileStart,a.end=r.fileStart+r.byteLength,u+="["+a.start+"-"):a.end===r.fileStart?a.end=r.fileStart+r.byteLength:((a={}).start=r.fileStart,u+=o[o.length-1].end-1+"], ["+a.start+"-",a.end=r.fileStart+r.byteLength,o.push(a)),n+=r.usedBytes,s+=r.byteLength;o.length>0&&(u+=a.end-1+"]"),(t?l.info:l.debug)("MultiBufferStream",0===this.buffers.length?"No more buffer in memory":""+this.buffers.length+" stored buffer(s) ("+n+"/"+s+" bytes), continuous ranges: "+u)},h.prototype.cleanBuffers=function(){var t,e;for(t=0;t<this.buffers.length;t++)(e=this.buffers[t]).usedBytes===e.byteLength&&(l.debug("MultiBufferStream","Removing buffer #"+t),this.buffers.splice(t,1),t--)},h.prototype.mergeNextBuffer=function(){if(!(this.bufferIndex+1<this.buffers.length)||(t=this.buffers[this.bufferIndex+1]).fileStart!==this.buffer.fileStart+this.buffer.byteLength)return!1;var t,e=this.buffer.byteLength,r=this.buffer.usedBytes,n=this.buffer.fileStart;return this.buffers[this.bufferIndex]=ArrayBuffer.concat(this.buffer,t),this.buffer=this.buffers[this.bufferIndex],this.buffers.splice(this.bufferIndex+1,1),this.buffer.usedBytes=r,this.buffer.fileStart=n,l.debug("ISOFile","Concatenating buffer for box parsing (length: "+e+"->"+this.buffer.byteLength+")"),!0},h.prototype.findPosition=function(t,e,r){var n,s=null,a=-1;for(n=!0===t?0:this.bufferIndex;n<this.buffers.length&&(s=this.buffers[n]).fileStart<=e;)a=n,r&&(s.fileStart+s.byteLength<=e?s.usedBytes=s.byteLength:s.usedBytes=e-s.fileStart,this.logBufferLevel()),n++;return -1===a?-1:(s=this.buffers[a]).fileStart+s.byteLength>=e?(l.debug("MultiBufferStream","Found position in existing buffer #"+a),a):-1},h.prototype.findEndContiguousBuf=function(t){var e,r,n,s=void 0!==t?t:this.bufferIndex;if(r=this.buffers[s],this.buffers.length>s+1)for(e=s+1;e<this.buffers.length;e++)if((n=this.buffers[e]).fileStart===r.fileStart+r.byteLength)r=n;else break;return r.fileStart+r.byteLength},h.prototype.getEndFilePositionAfter=function(t){var e=this.findPosition(!0,t,!1);return -1!==e?this.findEndContiguousBuf(e):t},h.prototype.addUsedBytes=function(t){this.buffer.usedBytes+=t,this.logBufferLevel()},h.prototype.setAllUsedBytes=function(){this.buffer.usedBytes=this.buffer.byteLength,this.logBufferLevel()},h.prototype.seek=function(t,e,r){var n;return -1!==(n=this.findPosition(e,t,r))?(this.buffer=this.buffers[n],this.bufferIndex=n,this.position=t-this.buffer.fileStart,l.debug("MultiBufferStream","Repositioning parser at buffer position: "+this.position),!0):(l.debug("MultiBufferStream","Position "+t+" not found in buffered data"),!1)},h.prototype.getPosition=function(){if(-1===this.bufferIndex||null===this.buffers[this.bufferIndex])throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.position},h.prototype.getLength=function(){return this.byteLength},h.prototype.getEndPosition=function(){if(-1===this.bufferIndex||null===this.buffers[this.bufferIndex])throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.byteLength},r.MultiBufferStream=h;var f=function(){var t=[];t[3]="ES_Descriptor",t[4]="DecoderConfigDescriptor",t[5]="DecoderSpecificInfo",t[6]="SLConfigDescriptor",this.getDescriptorName=function(e){return t[e]};var e=this,r={};return this.parseOneDescriptor=function(e){var n,s,a,o=0,u=0;for(n=e.readUint8(),o++,a=e.readUint8(),o++;128&a;)u=(127&a)<<7,a=e.readUint8(),o++;return u+=127&a,l.debug("MPEG4DescriptorParser","Found "+(t[n]||"Descriptor "+n)+", size "+u+" at position "+e.getPosition()),(s=t[n]?new r[t[n]](u):new r.Descriptor(u)).parse(e),s},r.Descriptor=function(t,e){this.tag=t,this.size=e,this.descs=[]},r.Descriptor.prototype.parse=function(t){this.data=t.readUint8Array(this.size)},r.Descriptor.prototype.findDescriptor=function(t){for(var e=0;e<this.descs.length;e++)if(this.descs[e].tag==t)return this.descs[e];return null},r.Descriptor.prototype.parseRemainingDescriptors=function(t){for(var r=t.position;t.position<r+this.size;){var n=e.parseOneDescriptor(t);this.descs.push(n)}},r.ES_Descriptor=function(t){r.Descriptor.call(this,3,t)},r.ES_Descriptor.prototype=new r.Descriptor,r.ES_Descriptor.prototype.parse=function(t){if(this.ES_ID=t.readUint16(),this.flags=t.readUint8(),this.size-=3,128&this.flags?(this.dependsOn_ES_ID=t.readUint16(),this.size-=2):this.dependsOn_ES_ID=0,64&this.flags){var e=t.readUint8();this.URL=t.readString(e),this.size-=e+1}else this.URL="";32&this.flags?(this.OCR_ES_ID=t.readUint16(),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(t)},r.ES_Descriptor.prototype.getOTI=function(t){var e=this.findDescriptor(4);return e?e.oti:0},r.ES_Descriptor.prototype.getAudioConfig=function(t){var e=this.findDescriptor(4);if(!e)return null;var r=e.findDescriptor(5);if(!r||!r.data)return null;var n=(248&r.data[0])>>3;return 31===n&&r.data.length>=2&&(n=32+((7&r.data[0])<<3)+((224&r.data[1])>>5)),n},r.DecoderConfigDescriptor=function(t){r.Descriptor.call(this,4,t)},r.DecoderConfigDescriptor.prototype=new r.Descriptor,r.DecoderConfigDescriptor.prototype.parse=function(t){this.oti=t.readUint8(),this.streamType=t.readUint8(),this.upStream=(this.streamType>>1&1)!=0,this.streamType=this.streamType>>>2,this.bufferSize=t.readUint24(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32(),this.size-=13,this.parseRemainingDescriptors(t)},r.DecoderSpecificInfo=function(t){r.Descriptor.call(this,5,t)},r.DecoderSpecificInfo.prototype=new r.Descriptor,r.SLConfigDescriptor=function(t){r.Descriptor.call(this,6,t)},r.SLConfigDescriptor.prototype=new r.Descriptor,this};r.MPEG4DescriptorParser=f;var d={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"],["grpl"],["j2kH"],["etyp",["tyco"]]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){d.FullBox.prototype=new d.Box,d.ContainerBox.prototype=new d.Box,d.SampleEntry.prototype=new d.Box,d.TrackGroupTypeBox.prototype=new d.FullBox,d.BASIC_BOXES.forEach(function(t){d.createBoxCtor(t)}),d.FULL_BOXES.forEach(function(t){d.createFullBoxCtor(t)}),d.CONTAINER_BOXES.forEach(function(t){d.createContainerBoxCtor(t[0],null,t[1])})},Box:function(t,e,r){this.type=t,this.size=e,this.uuid=r},FullBox:function(t,e,r){d.Box.call(this,t,e,r),this.flags=0,this.version=0},ContainerBox:function(t,e,r){d.Box.call(this,t,e,r),this.boxes=[]},SampleEntry:function(t,e,r,n){d.ContainerBox.call(this,t,e),this.hdr_size=r,this.start=n},SampleGroupEntry:function(t){this.grouping_type=t},TrackGroupTypeBox:function(t,e){d.FullBox.call(this,t,e)},createBoxCtor:function(t,e){d.boxCodes.push(t),d[t+"Box"]=function(e){d.Box.call(this,t,e)},d[t+"Box"].prototype=new d.Box,e&&(d[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,e){d[t+"Box"]=function(e){d.FullBox.call(this,t,e)},d[t+"Box"].prototype=new d.FullBox,d[t+"Box"].prototype.parse=function(t){this.parseFullHeader(t),e&&e.call(this,t)}},addSubBoxArrays:function(t){if(t){this.subBoxNames=t;for(var e=t.length,r=0;r<e;r++)this[t[r]+"s"]=[]}},createContainerBoxCtor:function(t,e,r){d[t+"Box"]=function(e){d.ContainerBox.call(this,t,e),d.addSubBoxArrays.call(this,r)},d[t+"Box"].prototype=new d.ContainerBox,e&&(d[t+"Box"].prototype.parse=e)},createMediaSampleEntryCtor:function(t,e,r){d.sampleEntryCodes[t]=[],d[t+"SampleEntry"]=function(t,e){d.SampleEntry.call(this,t,e),d.addSubBoxArrays.call(this,r)},d[t+"SampleEntry"].prototype=new d.SampleEntry,e&&(d[t+"SampleEntry"].prototype.parse=e)},createSampleEntryCtor:function(t,e,r,n){d.sampleEntryCodes[t].push(e),d[e+"SampleEntry"]=function(r){d[t+"SampleEntry"].call(this,e,r),d.addSubBoxArrays.call(this,n)},d[e+"SampleEntry"].prototype=new d[t+"SampleEntry"],r&&(d[e+"SampleEntry"].prototype.parse=r)},createEncryptedSampleEntryCtor:function(t,e,r){d.createSampleEntryCtor.call(this,t,e,r,["sinf"])},createSampleGroupCtor:function(t,e){d[t+"SampleGroupEntry"]=function(e){d.SampleGroupEntry.call(this,t,e)},d[t+"SampleGroupEntry"].prototype=new d.SampleGroupEntry,e&&(d[t+"SampleGroupEntry"].prototype.parse=e)},createTrackGroupCtor:function(t,e){d[t+"TrackGroupTypeBox"]=function(e){d.TrackGroupTypeBox.call(this,t,e)},d[t+"TrackGroupTypeBox"].prototype=new d.TrackGroupTypeBox,e&&(d[t+"TrackGroupTypeBox"].prototype.parse=e)},createUUIDBox:function(t,e,r,n){d.UUIDs.push(t),d.UUIDBoxes[t]=function(n){e?d.FullBox.call(this,"uuid",n,t):r?d.ContainerBox.call(this,"uuid",n,t):d.Box.call(this,"uuid",n,t)},d.UUIDBoxes[t].prototype=e?new d.FullBox:r?new d.ContainerBox:new d.Box,n&&(e?d.UUIDBoxes[t].prototype.parse=function(t){this.parseFullHeader(t),n&&n.call(this,t)}:d.UUIDBoxes[t].prototype.parse=n)}};function p(t,e){this.x=t,this.y=e}function _(t,e){this.bad_pixel_row=t,this.bad_pixel_column=e}d.initialize(),d.TKHD_FLAG_ENABLED=1,d.TKHD_FLAG_IN_MOVIE=2,d.TKHD_FLAG_IN_PREVIEW=4,d.TFHD_FLAG_BASE_DATA_OFFSET=1,d.TFHD_FLAG_SAMPLE_DESC=2,d.TFHD_FLAG_SAMPLE_DUR=8,d.TFHD_FLAG_SAMPLE_SIZE=16,d.TFHD_FLAG_SAMPLE_FLAGS=32,d.TFHD_FLAG_DUR_EMPTY=65536,d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072,d.TRUN_FLAGS_DATA_OFFSET=1,d.TRUN_FLAGS_FIRST_FLAG=4,d.TRUN_FLAGS_DURATION=256,d.TRUN_FLAGS_SIZE=512,d.TRUN_FLAGS_FLAGS=1024,d.TRUN_FLAGS_CTS_OFFSET=2048,d.Box.prototype.add=function(t){return this.addBox(new d[t+"Box"])},d.Box.prototype.addBox=function(t){return this.boxes.push(t),this[t.type+"s"]?this[t.type+"s"].push(t):this[t.type]=t,t},d.Box.prototype.set=function(t,e){return this[t]=e,this},d.Box.prototype.addEntry=function(t,e){var r=e||"entries";return this[r]||(this[r]=[]),this[r].push(t),this},r.BoxParser=d,d.parseUUID=function(t){return d.parseHex16(t)},d.parseHex16=function(t){for(var e="",r=0;r<16;r++){var n=t.readUint8().toString(16);e+=1===n.length?"0"+n:n}return e},d.parseOneBox=function(t,e,r){var n,s,a,o=t.getPosition(),u=0;if(t.getEndPosition()-o<8)return l.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:d.ERR_NOT_ENOUGH_DATA};if(r&&r<8)return l.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:d.ERR_NOT_ENOUGH_DATA};var c=t.readUint32(),h=t.readString(4),f=h;if(l.debug("BoxParser","Found box of type '"+h+"' and size "+c+" at position "+o),u=8,"uuid"==h){if(t.getEndPosition()-t.getPosition()<16||r-u<16)return t.seek(o),l.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:d.ERR_NOT_ENOUGH_DATA};a=d.parseUUID(t),u+=16,f=a}if(1==c){if(t.getEndPosition()-t.getPosition()<8||r&&r-u<8)return t.seek(o),l.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+h+'" box'),{code:d.ERR_NOT_ENOUGH_DATA};c=t.readUint64(),u+=8}else if(0===c){if(r)c=r;else if("mdat"!==h)return l.error("BoxParser","Unlimited box size not supported for type: '"+h+"'"),n=new d.Box(h,c),{code:d.OK,box:n,size:n.size}}return 0!==c&&c<u?(l.error("BoxParser","Box of type "+h+" has an invalid size "+c+" (too small to be a box)"),{code:d.ERR_NOT_ENOUGH_DATA,type:h,size:c,hdr_size:u,start:o}):0!==c&&r&&c>r?(l.error("BoxParser","Box of type '"+h+"' has a size "+c+" greater than its container size "+r),{code:d.ERR_NOT_ENOUGH_DATA,type:h,size:c,hdr_size:u,start:o}):0!==c&&o+c>t.getEndPosition()?(t.seek(o),l.info("BoxParser","Not enough data in stream to parse the entire '"+h+"' box"),{code:d.ERR_NOT_ENOUGH_DATA,type:h,size:c,hdr_size:u,start:o}):e?{code:d.OK,type:h,size:c,hdr_size:u,start:o}:(d[h+"Box"]?n=new d[h+"Box"](c):"uuid"!==h?(l.warn("BoxParser","Unknown box type: '"+h+"'"),(n=new d.Box(h,c)).has_unparsed_data=!0):d.UUIDBoxes[a]?n=new d.UUIDBoxes[a](c):(l.warn("BoxParser","Unknown uuid type: '"+a+"'"),(n=new d.Box(h,c)).uuid=a,n.has_unparsed_data=!0),n.hdr_size=u,n.start=o,n.write===d.Box.prototype.write&&"mdat"!==n.type&&(l.info("BoxParser","'"+f+"' box writing not yet implemented, keeping unparsed data in memory for later write"),n.parseDataAndRewind(t)),n.parse(t),(s=t.getPosition()-(n.start+n.size))<0?(l.warn("BoxParser","Parsing of box '"+f+"' did not read the entire indicated box data size (missing "+-s+" bytes), seeking forward"),t.seek(n.start+n.size)):s>0&&(l.error("BoxParser","Parsing of box '"+f+"' read "+s+" more bytes than the indicated box data size, seeking backwards"),0!==n.size&&t.seek(n.start+n.size)),{code:d.OK,box:n,size:n.size})},d.Box.prototype.parse=function(t){"mdat"!=this.type?this.data=t.readUint8Array(this.size-this.hdr_size):0===this.size?t.seek(t.getEndPosition()):t.seek(this.start+this.size)},d.Box.prototype.parseDataAndRewind=function(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.position-=this.size-this.hdr_size},d.FullBox.prototype.parseDataAndRewind=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,t.position-=this.size-this.hdr_size},d.FullBox.prototype.parseFullHeader=function(t){this.version=t.readUint8(),this.flags=t.readUint24(),this.hdr_size+=4},d.FullBox.prototype.parse=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},d.ContainerBox.prototype.parse=function(t){for(;t.getPosition()<this.start+this.size;){if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;if(r=e.box,this.boxes.push(r),this.subBoxNames&&-1!=this.subBoxNames.indexOf(r.type))this[this.subBoxNames[this.subBoxNames.indexOf(r.type)]+"s"].push(r);else{var e,r,n="uuid"!==r.type?r.type:r.uuid;this[n]?l.warn("Box of type "+n+" already stored in field of this type"):this[n]=r}}},d.Box.prototype.parseLanguage=function(t){this.language=t.readUint16();var e=[];e[0]=this.language>>10&31,e[1]=this.language>>5&31,e[2]=31&this.language,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)},d.SAMPLE_ENTRY_TYPE_VISUAL="Visual",d.SAMPLE_ENTRY_TYPE_AUDIO="Audio",d.SAMPLE_ENTRY_TYPE_HINT="Hint",d.SAMPLE_ENTRY_TYPE_METADATA="Metadata",d.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",d.SAMPLE_ENTRY_TYPE_SYSTEM="System",d.SAMPLE_ENTRY_TYPE_TEXT="Text",d.SampleEntry.prototype.parseHeader=function(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8},d.SampleEntry.prototype.parse=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},d.SampleEntry.prototype.parseDataAndRewind=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.position-=this.size-this.hdr_size},d.SampleEntry.prototype.parseFooter=function(t){d.ContainerBox.prototype.parse.call(this,t)},d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_HINT),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SYSTEM),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_TEXT),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,function(t){var e;this.parseHeader(t),t.readUint16(),t.readUint16(),t.readUint32Array(3),this.width=t.readUint16(),this.height=t.readUint16(),this.horizresolution=t.readUint32(),this.vertresolution=t.readUint32(),t.readUint32(),this.frame_count=t.readUint16(),e=Math.min(31,t.readUint8()),this.compressorname=t.readString(e),e<31&&t.readString(31-e),this.depth=t.readUint16(),t.readUint16(),this.parseFooter(t)}),d.createMediaSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,function(t){this.parseHeader(t),t.readUint32Array(2),this.channel_count=t.readUint16(),this.samplesize=t.readUint16(),t.readUint16(),t.readUint16(),this.samplerate=t.readUint32()/65536,this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dav1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"hvt1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"lhe1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dvh1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"dvhe"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvc1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvi1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvs1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vvcN"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vp08"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"vp09"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"avs3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"j2ki"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"mjp2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"mjpg"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"uncv"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ac-4"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"Opus"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mha1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mha2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mhm1"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"mhm2"),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"fLaC"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_TEXT,"enct"),d.createEncryptedSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"encm"),d.createBoxCtor("a1lx",function(t){var e=((1&(1&t.readUint8()))+1)*16;this.layer_size=[];for(var r=0;r<3;r++)16==e?this.layer_size[r]=t.readUint16():this.layer_size[r]=t.readUint32()}),d.createBoxCtor("a1op",function(t){this.op_index=t.readUint8()}),d.createFullBoxCtor("auxC",function(t){this.aux_type=t.readCString();var e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)}),d.createBoxCtor("av1C",function(t){var e=t.readUint8();if(e>>7&!1)return void l.error("av1C marker problem");if(this.version=127&e,1!==this.version)return void l.error("av1C version "+this.version+" not supported");if(e=t.readUint8(),this.seq_profile=e>>5&7,this.seq_level_idx_0=31&e,e=t.readUint8(),this.seq_tier_0=e>>7&1,this.high_bitdepth=e>>6&1,this.twelve_bit=e>>5&1,this.monochrome=e>>4&1,this.chroma_subsampling_x=e>>3&1,this.chroma_subsampling_y=e>>2&1,this.chroma_sample_position=3&e,e=t.readUint8(),this.reserved_1=e>>5&7,0!==this.reserved_1)return void l.error("av1C reserved_1 parsing problem");if(this.initial_presentation_delay_present=e>>4&1,1===this.initial_presentation_delay_present)this.initial_presentation_delay_minus_one=15&e;else if(this.reserved_2=15&e,0!==this.reserved_2)return void l.error("av1C reserved_2 parsing problem");var r=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(r)}),d.createBoxCtor("avcC",function(t){var e,r;for(e=0,this.configurationVersion=t.readUint8(),this.AVCProfileIndication=t.readUint8(),this.profile_compatibility=t.readUint8(),this.AVCLevelIndication=t.readUint8(),this.lengthSizeMinusOne=3&t.readUint8(),this.nb_SPS_nalus=31&t.readUint8(),r=this.size-this.hdr_size-6,this.SPS=[];e<this.nb_SPS_nalus;e++)this.SPS[e]={},this.SPS[e].length=t.readUint16(),this.SPS[e].nalu=t.readUint8Array(this.SPS[e].length),r-=2+this.SPS[e].length;for(this.nb_PPS_nalus=t.readUint8(),r--,this.PPS=[],e=0;e<this.nb_PPS_nalus;e++)this.PPS[e]={},this.PPS[e].length=t.readUint16(),this.PPS[e].nalu=t.readUint8Array(this.PPS[e].length),r-=2+this.PPS[e].length;r>0&&(this.ext=t.readUint8Array(r))}),d.createBoxCtor("btrt",function(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()}),d.createFullBoxCtor("ccst",function(t){var e=t.readUint8();this.all_ref_pics_intra=(128&e)==128,this.intra_pred_used=(64&e)==64,this.max_ref_per_pic=(63&e)>>2,t.readUint24()}),d.createBoxCtor("cdef",function(t){var e;for(e=0,this.channel_count=t.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[];e<this.channel_count;e++)this.channel_indexes.push(t.readUint16()),this.channel_types.push(t.readUint16()),this.channel_associations.push(t.readUint16())}),d.createBoxCtor("clap",function(t){this.cleanApertureWidthN=t.readUint32(),this.cleanApertureWidthD=t.readUint32(),this.cleanApertureHeightN=t.readUint32(),this.cleanApertureHeightD=t.readUint32(),this.horizOffN=t.readUint32(),this.horizOffD=t.readUint32(),this.vertOffN=t.readUint32(),this.vertOffD=t.readUint32()}),d.createBoxCtor("clli",function(t){this.max_content_light_level=t.readUint16(),this.max_pic_average_light_level=t.readUint16()}),d.createFullBoxCtor("cmex",function(t){1&this.flags&&(this.pos_x=t.readInt32()),2&this.flags&&(this.pos_y=t.readInt32()),4&this.flags&&(this.pos_z=t.readInt32()),8&this.flags&&(0==this.version?16&this.flags?(this.quat_x=t.readInt32(),this.quat_y=t.readInt32(),this.quat_z=t.readInt32()):(this.quat_x=t.readInt16(),this.quat_y=t.readInt16(),this.quat_z=t.readInt16()):this.version),32&this.flags&&(this.id=t.readUint32())}),d.createFullBoxCtor("cmin",function(t){this.focal_length_x=t.readInt32(),this.principal_point_x=t.readInt32(),this.principal_point_y=t.readInt32(),1&this.flags&&(this.focal_length_y=t.readInt32(),this.skew_factor=t.readInt32())}),d.createBoxCtor("cmpd",function(t){for(i=0,this.component_count=t.readUint32(),this.component_types=[],this.component_type_urls=[];i<this.component_count;i++){var e=t.readUint16();this.component_types.push(e),e>=32768&&this.component_type_urls.push(t.readCString())}}),d.createFullBoxCtor("co64",function(t){var e,r;if(e=t.readUint32(),this.chunk_offsets=[],0===this.version)for(r=0;r<e;r++)this.chunk_offsets.push(t.readUint64())}),d.createFullBoxCtor("CoLL",function(t){this.maxCLL=t.readUint16(),this.maxFALL=t.readUint16()}),d.createBoxCtor("colr",function(t){if(this.colour_type=t.readString(4),"nclx"===this.colour_type){this.colour_primaries=t.readUint16(),this.transfer_characteristics=t.readUint16(),this.matrix_coefficients=t.readUint16();var e=t.readUint8();this.full_range_flag=e>>7}else"rICC"===this.colour_type?this.ICC_profile=t.readUint8Array(this.size-4):"prof"===this.colour_type&&(this.ICC_profile=t.readUint8Array(this.size-4))}),d.createFullBoxCtor("cprt",function(t){this.parseLanguage(t),this.notice=t.readCString()}),d.createFullBoxCtor("cslg",function(t){0===this.version&&(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32())}),d.createFullBoxCtor("ctts",function(t){if(e=t.readUint32(),this.sample_counts=[],this.sample_offsets=[],0===this.version)for(r=0;r<e;r++){this.sample_counts.push(t.readUint32());var e,r,n=t.readInt32();n<0&&l.warn("BoxParser","ctts box uses negative values without using version 1"),this.sample_offsets.push(n)}else if(1==this.version)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),this.sample_offsets.push(t.readInt32())}),d.createBoxCtor("dac3",function(t){var e=t.readUint8(),r=t.readUint8(),n=t.readUint8();this.fscod=e>>6,this.bsid=e>>1&31,this.bsmod=(1&e)<<2|r>>6&3,this.acmod=r>>3&7,this.lfeon=r>>2&1,this.bit_rate_code=3&r|n>>5&7}),d.createBoxCtor("dec3",function(t){var e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=7&e,this.ind_subs=[];for(var r=0;r<this.num_ind_sub+1;r++){var n={};this.ind_subs.push(n);var s=t.readUint8(),a=t.readUint8(),o=t.readUint8();n.fscod=s>>6,n.bsid=s>>1&31,n.bsmod=(1&s)<<4|a>>4&15,n.acmod=a>>1&7,n.lfeon=1&a,n.num_dep_sub=o>>1&15,n.num_dep_sub>0&&(n.chan_loc=(1&o)<<8|t.readUint8())}}),d.createFullBoxCtor("dfLa",function(t){for(var e=[],r=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];;){var n=t.readUint8(),s=Math.min(127&n,r.length-1);if(s?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),e.push(r[s]),128&n)break}this.numMetadataBlocks=e.length+" ("+e.join(", ")+")"}),d.createBoxCtor("dimm",function(t){this.bytessent=t.readUint64()}),d.createBoxCtor("dmax",function(t){this.time=t.readUint32()}),d.createBoxCtor("dmed",function(t){this.bytessent=t.readUint64()}),d.createBoxCtor("dOps",function(t){if(this.Version=t.readUint8(),this.OutputChannelCount=t.readUint8(),this.PreSkip=t.readUint16(),this.InputSampleRate=t.readUint32(),this.OutputGain=t.readInt16(),this.ChannelMappingFamily=t.readUint8(),0!==this.ChannelMappingFamily){this.StreamCount=t.readUint8(),this.CoupledCount=t.readUint8(),this.ChannelMapping=[];for(var e=0;e<this.OutputChannelCount;e++)this.ChannelMapping[e]=t.readUint8()}}),d.createFullBoxCtor("dref",function(t){this.entries=[];for(var e,r,n=t.readUint32(),s=0;s<n;s++){if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;r=e.box,this.entries.push(r)}}),d.createBoxCtor("drep",function(t){this.bytessent=t.readUint64()}),d.createFullBoxCtor("elng",function(t){this.extended_language=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("elst",function(t){this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.entries.push(n),1===this.version?(n.segment_duration=t.readUint64(),n.media_time=t.readInt64()):(n.segment_duration=t.readUint32(),n.media_time=t.readInt32()),n.media_rate_integer=t.readInt16(),n.media_rate_fraction=t.readInt16()}}),d.createFullBoxCtor("emsg",function(t){1==this.version?(this.timescale=t.readUint32(),this.presentation_time=t.readUint64(),this.event_duration=t.readUint32(),this.id=t.readUint32(),this.scheme_id_uri=t.readCString(),this.value=t.readCString()):(this.scheme_id_uri=t.readCString(),this.value=t.readCString(),this.timescale=t.readUint32(),this.presentation_time_delta=t.readUint32(),this.event_duration=t.readUint32(),this.id=t.readUint32());var e=this.size-this.hdr_size-(16+(this.scheme_id_uri.length+1)+(this.value.length+1));1==this.version&&(e-=4),this.message_data=t.readUint8Array(e)}),d.createEntityToGroupCtor=function(t,e){d[t+"Box"]=function(e){d.FullBox.call(this,t,e)},d[t+"Box"].prototype=new d.FullBox,d[t+"Box"].prototype.parse=function(t){if(this.parseFullHeader(t),e)e.call(this,t);else for(i=0,this.group_id=t.readUint32(),this.num_entities_in_group=t.readUint32(),this.entity_ids=[];i<this.num_entities_in_group;i++){var r=t.readUint32();this.entity_ids.push(r)}}},d.createEntityToGroupCtor("aebr"),d.createEntityToGroupCtor("afbr"),d.createEntityToGroupCtor("albc"),d.createEntityToGroupCtor("altr"),d.createEntityToGroupCtor("brst"),d.createEntityToGroupCtor("dobr"),d.createEntityToGroupCtor("eqiv"),d.createEntityToGroupCtor("favc"),d.createEntityToGroupCtor("fobr"),d.createEntityToGroupCtor("iaug"),d.createEntityToGroupCtor("pano"),d.createEntityToGroupCtor("slid"),d.createEntityToGroupCtor("ster"),d.createEntityToGroupCtor("tsyn"),d.createEntityToGroupCtor("wbbr"),d.createEntityToGroupCtor("prgr"),d.createEntityToGroupCtor("pymd",function(t){this.group_id=t.readUint32(),this.num_entities_in_group=t.readUint32(),this.entity_ids=[];for(var e=0;e<this.num_entities_in_group;e++){var r=t.readUint32();this.entity_ids.push(r)}for(e=0,this.tile_size_x=t.readUint16(),this.tile_size_y=t.readUint16(),this.layer_binning=[],this.tiles_in_layer_column_minus1=[],this.tiles_in_layer_row_minus1=[];e<this.num_entities_in_group;e++)this.layer_binning[e]=t.readUint16(),this.tiles_in_layer_row_minus1[e]=t.readUint16(),this.tiles_in_layer_column_minus1[e]=t.readUint16()}),d.createFullBoxCtor("esds",function(t){var e=t.readUint8Array(this.size-this.hdr_size);if(this.data=e,void 0!==f){var r=new f;this.esd=r.parseOneDescriptor(new c(e.buffer,0,c.BIG_ENDIAN))}}),d.createBoxCtor("fiel",function(t){this.fieldCount=t.readUint8(),this.fieldOrdering=t.readUint8()}),d.createBoxCtor("frma",function(t){this.data_format=t.readString(4)}),d.createBoxCtor("ftyp",function(t){var e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];for(var r=0;e>=4;)this.compatible_brands[r]=t.readString(4),e-=4,r++}),d.createFullBoxCtor("hdlr",function(t){0===this.version&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),this.name=t.readString(this.size-this.hdr_size-20),"\0"===this.name[this.name.length-1]&&(this.name=this.name.slice(0,-1)))}),d.createBoxCtor("hvcC",function(t){this.configurationVersion=t.readUint8(),s=t.readUint8(),this.general_profile_space=s>>6,this.general_tier_flag=(32&s)>>5,this.general_profile_idc=31&s,this.general_profile_compatibility=t.readUint32(),this.general_constraint_indicator=t.readUint8Array(6),this.general_level_idc=t.readUint8(),this.min_spatial_segmentation_idc=4095&t.readUint16(),this.parallelismType=3&t.readUint8(),this.chroma_format_idc=3&t.readUint8(),this.bit_depth_luma_minus8=7&t.readUint8(),this.bit_depth_chroma_minus8=7&t.readUint8(),this.avgFrameRate=t.readUint16(),s=t.readUint8(),this.constantFrameRate=s>>6,this.numTemporalLayers=(13&s)>>3,this.temporalIdNested=(4&s)>>2,this.lengthSizeMinusOne=3&s,this.nalu_arrays=[];var e,r,n,s,a=t.readUint8();for(e=0;e<a;e++){var o=[];this.nalu_arrays.push(o),o.completeness=(128&(s=t.readUint8()))>>7,o.nalu_type=63&s;var l=t.readUint16();for(r=0;r<l;r++){var u={};o.push(u),n=t.readUint16(),u.data=t.readUint8Array(n)}}}),d.createFullBoxCtor("iinf",function(t){var e;0===this.version?this.entry_count=t.readUint16():this.entry_count=t.readUint32(),this.item_infos=[];for(var r=0;r<this.entry_count;r++){if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;"infe"!==e.box.type&&l.error("BoxParser","Expected 'infe' box, got "+e.box.type),this.item_infos[r]=e.box}}),d.createFullBoxCtor("iloc",function(t){e=t.readUint8(),this.offset_size=e>>4&15,this.length_size=15&e,e=t.readUint8(),this.base_offset_size=e>>4&15,1===this.version||2===this.version?this.index_size=15&e:this.index_size=0,this.items=[];var e,r=0;if(this.version<2)r=t.readUint16();else if(2===this.version)r=t.readUint32();else throw"version of iloc box not supported";for(var n=0;n<r;n++){var s={};if(this.items.push(s),this.version<2)s.item_ID=t.readUint16();else if(2===this.version)s.item_ID=t.readUint32();else throw"version of iloc box not supported";switch(1===this.version||2===this.version?s.construction_method=15&t.readUint16():s.construction_method=0,s.data_reference_index=t.readUint16(),this.base_offset_size){case 0:s.base_offset=0;break;case 4:s.base_offset=t.readUint32();break;case 8:s.base_offset=t.readUint64();break;default:throw"Error reading base offset size"}var a=t.readUint16();s.extents=[];for(var o=0;o<a;o++){var l={};if(s.extents.push(l),1===this.version||2===this.version)switch(this.index_size){case 0:l.extent_index=0;break;case 4:l.extent_index=t.readUint32();break;case 8:l.extent_index=t.readUint64();break;default:throw"Error reading extent index"}switch(this.offset_size){case 0:l.extent_offset=0;break;case 4:l.extent_offset=t.readUint32();break;case 8:l.extent_offset=t.readUint64();break;default:throw"Error reading extent index"}switch(this.length_size){case 0:l.extent_length=0;break;case 4:l.extent_length=t.readUint32();break;case 8:l.extent_length=t.readUint64();break;default:throw"Error reading extent index"}}}}),d.createBoxCtor("imir",function(t){var e=t.readUint8();this.reserved=e>>7,this.axis=1&e}),d.createFullBoxCtor("infe",function(t){if((0===this.version||1===this.version)&&(this.item_ID=t.readUint16(),this.item_protection_index=t.readUint16(),this.item_name=t.readCString(),this.content_type=t.readCString(),this.content_encoding=t.readCString()),1===this.version){this.extension_type=t.readString(4),l.warn("BoxParser","Cannot parse extension type"),t.seek(this.start+this.size);return}this.version>=2&&(2===this.version?this.item_ID=t.readUint16():3===this.version&&(this.item_ID=t.readUint32()),this.item_protection_index=t.readUint16(),this.item_type=t.readString(4),this.item_name=t.readCString(),"mime"===this.item_type?(this.content_type=t.readCString(),this.content_encoding=t.readCString()):"uri "===this.item_type&&(this.item_uri_type=t.readCString()))}),d.createFullBoxCtor("ipma",function(t){var e,r;for(e=0,entry_count=t.readUint32(),this.associations=[];e<entry_count;e++){var n={};this.associations.push(n),this.version<1?n.id=t.readUint16():n.id=t.readUint32();var s=t.readUint8();for(r=0,n.props=[];r<s;r++){var a=t.readUint8(),o={};n.props.push(o),o.essential=(128&a)>>7==1,1&this.flags?o.property_index=(127&a)<<8|t.readUint8():o.property_index=127&a}}}),d.createFullBoxCtor("iref",function(t){var e,r;for(this.references=[];t.getPosition()<this.start+this.size;){if((e=d.parseOneBox(t,!0,this.size-(t.getPosition()-this.start))).code!==d.OK)return;(r=0===this.version?new d.SingleItemTypeReferenceBox(e.type,e.size,e.hdr_size,e.start):new d.SingleItemTypeReferenceBoxLarge(e.type,e.size,e.hdr_size,e.start)).write===d.Box.prototype.write&&"mdat"!==r.type&&(l.warn("BoxParser",r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.references.push(r)}}),d.createBoxCtor("irot",function(t){this.angle=3&t.readUint8()}),d.createFullBoxCtor("ispe",function(t){this.image_width=t.readUint32(),this.image_height=t.readUint32()}),d.createFullBoxCtor("kind",function(t){this.schemeURI=t.readCString(),this.value=t.readCString()}),d.createFullBoxCtor("leva",function(t){var e=t.readUint8();this.levels=[];for(var r=0;r<e;r++){var n={};this.levels[r]=n,n.track_ID=t.readUint32();var s=t.readUint8();switch(n.padding_flag=s>>7,n.assignment_type=127&s,n.assignment_type){case 0:n.grouping_type=t.readString(4);break;case 1:n.grouping_type=t.readString(4),n.grouping_type_parameter=t.readUint32();break;case 2:case 3:break;case 4:n.sub_track_id=t.readUint32();break;default:l.warn("BoxParser","Unknown leva assignement type")}}}),d.createBoxCtor("lhvC",function(t){this.configurationVersion=t.readUint8(),this.min_spatial_segmentation_idc=4095&t.readUint16(),this.parallelismType=3&t.readUint8(),n=t.readUint8(),this.numTemporalLayers=(13&n)>>3,this.temporalIdNested=(4&n)>>2,this.lengthSizeMinusOne=3&n,this.nalu_arrays=[];var e,r,n,s=t.readUint8();for(e=0;e<s;e++){var a=[];this.nalu_arrays.push(a),a.completeness=(128&(n=t.readUint8()))>>7,a.nalu_type=63&n;var o=t.readUint16();for(r=0;r<o;r++){var l={};a.push(l);var u=t.readUint16();l.data=t.readUint8Array(u)}}}),d.createBoxCtor("lsel",function(t){this.layer_id=t.readUint16()}),d.createBoxCtor("maxr",function(t){this.period=t.readUint32(),this.bytes=t.readUint32()}),p.prototype.toString=function(){return"("+this.x+","+this.y+")"},d.createBoxCtor("mdcv",function(t){this.display_primaries=[],this.display_primaries[0]=new p(t.readUint16(),t.readUint16()),this.display_primaries[1]=new p(t.readUint16(),t.readUint16()),this.display_primaries[2]=new p(t.readUint16(),t.readUint16()),this.white_point=new p(t.readUint16(),t.readUint16()),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()}),d.createFullBoxCtor("mdhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.parseLanguage(t),t.readUint16()}),d.createFullBoxCtor("mehd",function(t){1&this.flags&&(l.warn("BoxParser","mehd box incorrectly uses flags set to 1, converting version to 1"),this.version=1),1==this.version?this.fragment_duration=t.readUint64():this.fragment_duration=t.readUint32()}),d.createFullBoxCtor("meta",function(t){this.boxes=[],d.ContainerBox.prototype.parse.call(this,t)}),d.createFullBoxCtor("mfhd",function(t){this.sequence_number=t.readUint32()}),d.createFullBoxCtor("mfro",function(t){this._size=t.readUint32()}),d.createFullBoxCtor("mskC",function(t){this.bits_per_pixel=t.readUint8()}),d.createFullBoxCtor("mvhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.timescale=t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.timescale=t.readUint32(),this.duration=t.readUint32()),this.rate=t.readUint32(),this.volume=t.readUint16()>>8,t.readUint16(),t.readUint32Array(2),this.matrix=t.readUint32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()}),d.createBoxCtor("npck",function(t){this.packetssent=t.readUint32()}),d.createBoxCtor("nump",function(t){this.packetssent=t.readUint64()}),d.createFullBoxCtor("padb",function(t){var e=t.readUint32();this.padbits=[];for(var r=0;r<Math.floor((e+1)/2);r++)this.padbits=t.readUint8()}),d.createBoxCtor("pasp",function(t){this.hSpacing=t.readUint32(),this.vSpacing=t.readUint32()}),d.createBoxCtor("payl",function(t){this.text=t.readString(this.size-this.hdr_size)}),d.createBoxCtor("payt",function(t){this.payloadID=t.readUint32();var e=t.readUint8();this.rtpmap_string=t.readString(e)}),d.createFullBoxCtor("pdin",function(t){var e=(this.size-this.hdr_size)/8;this.rate=[],this.initial_delay=[];for(var r=0;r<e;r++)this.rate[r]=t.readUint32(),this.initial_delay[r]=t.readUint32()}),d.createFullBoxCtor("pitm",function(t){0===this.version?this.item_id=t.readUint16():this.item_id=t.readUint32()}),d.createFullBoxCtor("pixi",function(t){var e;for(e=0,this.num_channels=t.readUint8(),this.bits_per_channels=[];e<this.num_channels;e++)this.bits_per_channels[e]=t.readUint8()}),d.createBoxCtor("pmax",function(t){this.bytes=t.readUint32()}),d.createFullBoxCtor("prdi",function(t){if(this.step_count=t.readUint16(),this.item_count=[],2&this.flags)for(var e=0;e<this.step_count;e++)this.item_count[e]=t.readUint16()}),d.createFullBoxCtor("prft",function(t){this.ref_track_id=t.readUint32(),this.ntp_timestamp=t.readUint64(),0===this.version?this.media_time=t.readUint32():this.media_time=t.readUint64()}),d.createFullBoxCtor("pssh",function(t){if(this.system_id=d.parseHex16(t),this.version>0){var e=t.readUint32();this.kid=[];for(var r=0;r<e;r++)this.kid[r]=d.parseHex16(t)}var n=t.readUint32();n>0&&(this.data=t.readUint8Array(n))}),d.createFullBoxCtor("clef",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createFullBoxCtor("enof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createFullBoxCtor("prof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),d.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),d.createBoxCtor("rtp ",function(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)}),d.createFullBoxCtor("saio",function(t){1&this.flags&&(this.aux_info_type=t.readUint32(),this.aux_info_type_parameter=t.readUint32());var e=t.readUint32();this.offset=[];for(var r=0;r<e;r++)0===this.version?this.offset[r]=t.readUint32():this.offset[r]=t.readUint64()}),d.createFullBoxCtor("saiz",function(t){1&this.flags&&(this.aux_info_type=t.readUint32(),this.aux_info_type_parameter=t.readUint32()),this.default_sample_info_size=t.readUint8();var e=t.readUint32();if(this.sample_info_size=[],0===this.default_sample_info_size)for(var r=0;r<e;r++)this.sample_info_size[r]=t.readUint8()}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"mett",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"metx",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"sbtt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"stpp",function(t){this.parseHeader(t),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.auxiliary_mime_types=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"stxt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_SUBTITLE,"tx3g",function(t){this.parseHeader(t),this.displayFlags=t.readUint32(),this.horizontal_justification=t.readInt8(),this.vertical_justification=t.readInt8(),this.bg_color_rgba=t.readUint8Array(4),this.box_record=t.readInt16Array(4),this.style_record=t.readUint8Array(12),this.parseFooter(t)}),d.createSampleEntryCtor(d.SAMPLE_ENTRY_TYPE_METADATA,"wvtt",function(t){this.parseHeader(t),this.parseFooter(t)}),d.createSampleGroupCtor("alst",function(t){var e,r=t.readUint16();for(e=0,this.first_output_sample=t.readUint16(),this.sample_offset=[];e<r;e++)this.sample_offset[e]=t.readUint32();var n=this.description_length-4-4*r;for(e=0,this.num_output_samples=[],this.num_total_samples=[];e<n/4;e++)this.num_output_samples[e]=t.readUint16(),this.num_total_samples[e]=t.readUint16()}),d.createSampleGroupCtor("avll",function(t){this.layerNumber=t.readUint8(),this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()}),d.createSampleGroupCtor("avss",function(t){this.subSequenceIdentifier=t.readUint16(),this.layerNumber=t.readUint8();var e=t.readUint8();this.durationFlag=e>>7,this.avgRateFlag=e>>6&1,this.durationFlag&&(this.duration=t.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()),this.dependency=[];for(var r=t.readUint8(),n=0;n<r;n++){var s={};this.dependency.push(s),s.subSeqDirectionFlag=t.readUint8(),s.layerNumber=t.readUint8(),s.subSequenceIdentifier=t.readUint16()}}),d.createSampleGroupCtor("dtrt",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("mvif",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("prol",function(t){this.roll_distance=t.readInt16()}),d.createSampleGroupCtor("rap ",function(t){var e=t.readUint8();this.num_leading_samples_known=e>>7,this.num_leading_samples=127&e}),d.createSampleGroupCtor("rash",function(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(1===this.operation_point_count?2:6*this.operation_point_count)+9)l.warn("BoxParser","Mismatch in "+this.grouping_type+" sample group length"),this.data=t.readUint8Array(this.description_length-2);else{if(1===this.operation_point_count)this.target_rate_share=t.readUint16();else{this.target_rate_share=[],this.available_bitrate=[];for(var e=0;e<this.operation_point_count;e++)this.available_bitrate[e]=t.readUint32(),this.target_rate_share[e]=t.readUint16()}this.maximum_bitrate=t.readUint32(),this.minimum_bitrate=t.readUint32(),this.discard_priority=t.readUint8()}}),d.createSampleGroupCtor("roll",function(t){this.roll_distance=t.readInt16()}),d.SampleGroupEntry.prototype.parse=function(t){l.warn("BoxParser","Unknown Sample Group type: "+this.grouping_type),this.data=t.readUint8Array(this.description_length)},d.createSampleGroupCtor("scif",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("scnm",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("seig",function(t){this.reserved=t.readUint8();var e=t.readUint8();this.crypt_byte_block=e>>4,this.skip_byte_block=15&e,this.isProtected=t.readUint8(),this.Per_Sample_IV_Size=t.readUint8(),this.KID=d.parseHex16(t),this.constant_IV_size=0,this.constant_IV=0,1===this.isProtected&&0===this.Per_Sample_IV_Size&&(this.constant_IV_size=t.readUint8(),this.constant_IV=t.readUint8Array(this.constant_IV_size))}),d.createSampleGroupCtor("stsa",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("sync",function(t){var e=t.readUint8();this.NAL_unit_type=63&e}),d.createSampleGroupCtor("tele",function(t){var e=t.readUint8();this.level_independently_decodable=e>>7}),d.createSampleGroupCtor("tsas",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("tscl",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createSampleGroupCtor("vipr",function(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),d.createFullBoxCtor("sbgp",function(t){this.grouping_type=t.readString(4),1===this.version?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.entries.push(n),n.sample_count=t.readInt32(),n.group_description_index=t.readInt32()}}),_.prototype.toString=function(){return"[row: "+this.bad_pixel_row+", column: "+this.bad_pixel_column+"]"},d.createFullBoxCtor("sbpm",function(t){for(e=0,this.component_count=t.readUint16(),this.component_index=[];e<this.component_count;e++)this.component_index.push(t.readUint16());var e,r=t.readUint8();for(e=0,this.correction_applied=128==(128&r),this.num_bad_rows=t.readUint32(),this.num_bad_cols=t.readUint32(),this.num_bad_pixels=t.readUint32(),this.bad_rows=[],this.bad_columns=[],this.bad_pixels=[];e<this.num_bad_rows;e++)this.bad_rows.push(t.readUint32());for(e=0;e<this.num_bad_cols;e++)this.bad_columns.push(t.readUint32());for(e=0;e<this.num_bad_pixels;e++){var n=t.readUint32(),s=t.readUint32();this.bad_pixels.push(new _(n,s))}}),d.createFullBoxCtor("schm",function(t){this.scheme_type=t.readString(4),this.scheme_version=t.readUint32(),1&this.flags&&(this.scheme_uri=t.readString(this.size-this.hdr_size-8))}),d.createBoxCtor("sdp ",function(t){this.sdptext=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("sdtp",function(t){var e,r=this.size-this.hdr_size;this.is_leading=[],this.sample_depends_on=[],this.sample_is_depended_on=[],this.sample_has_redundancy=[];for(var n=0;n<r;n++)e=t.readUint8(),this.is_leading[n]=e>>6,this.sample_depends_on[n]=e>>4&3,this.sample_is_depended_on[n]=e>>2&3,this.sample_has_redundancy[n]=3&e}),d.createFullBoxCtor("senc"),d.createFullBoxCtor("sgpd",function(t){this.grouping_type=t.readString(4),l.debug("BoxParser","Found Sample Groups of type "+this.grouping_type),1===this.version?this.default_length=t.readUint32():this.default_length=0,this.version>=2&&(this.default_group_description_index=t.readUint32()),this.entries=[];for(var e,r=t.readUint32(),n=0;n<r;n++)e=d[this.grouping_type+"SampleGroupEntry"]?new d[this.grouping_type+"SampleGroupEntry"](this.grouping_type):new d.SampleGroupEntry(this.grouping_type),this.entries.push(e),1===this.version&&0===this.default_length?e.description_length=t.readUint32():e.description_length=this.default_length,e.write===d.SampleGroupEntry.prototype.write&&(l.info("BoxParser","SampleGroup for type "+this.grouping_type+" writing not yet implemented, keeping unparsed data in memory for later write"),e.data=t.readUint8Array(e.description_length),t.position-=e.description_length),e.parse(t)}),d.createFullBoxCtor("sidx",function(t){this.reference_ID=t.readUint32(),this.timescale=t.readUint32(),0===this.version?(this.earliest_presentation_time=t.readUint32(),this.first_offset=t.readUint32()):(this.earliest_presentation_time=t.readUint64(),this.first_offset=t.readUint64()),t.readUint16(),this.references=[];for(var e=t.readUint16(),r=0;r<e;r++){var n={};this.references.push(n);var s=t.readUint32();n.reference_type=s>>31&1,n.referenced_size=0x7fffffff&s,n.subsegment_duration=t.readUint32(),n.starts_with_SAP=(s=t.readUint32())>>31&1,n.SAP_type=s>>28&7,n.SAP_delta_time=0xfffffff&s}}),d.SingleItemTypeReferenceBox=function(t,e,r,n){d.Box.call(this,t,e),this.hdr_size=r,this.start=n},d.SingleItemTypeReferenceBox.prototype=new d.Box,d.SingleItemTypeReferenceBox.prototype.parse=function(t){this.from_item_ID=t.readUint16();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint16()},d.SingleItemTypeReferenceBoxLarge=function(t,e,r,n){d.Box.call(this,t,e),this.hdr_size=r,this.start=n},d.SingleItemTypeReferenceBoxLarge.prototype=new d.Box,d.SingleItemTypeReferenceBoxLarge.prototype.parse=function(t){this.from_item_ID=t.readUint32();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint32()},d.createFullBoxCtor("SmDm",function(t){this.primaryRChromaticity_x=t.readUint16(),this.primaryRChromaticity_y=t.readUint16(),this.primaryGChromaticity_x=t.readUint16(),this.primaryGChromaticity_y=t.readUint16(),this.primaryBChromaticity_x=t.readUint16(),this.primaryBChromaticity_y=t.readUint16(),this.whitePointChromaticity_x=t.readUint16(),this.whitePointChromaticity_y=t.readUint16(),this.luminanceMax=t.readUint32(),this.luminanceMin=t.readUint32()}),d.createFullBoxCtor("smhd",function(t){this.balance=t.readUint16(),t.readUint16()}),d.createFullBoxCtor("ssix",function(t){this.subsegments=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.subsegments.push(n),n.ranges=[];for(var s=t.readUint32(),a=0;a<s;a++){var o={};n.ranges.push(o),o.level=t.readUint8(),o.range_size=t.readUint24()}}}),d.createFullBoxCtor("stco",function(t){var e;if(e=t.readUint32(),this.chunk_offsets=[],0===this.version)for(var r=0;r<e;r++)this.chunk_offsets.push(t.readUint32())}),d.createFullBoxCtor("stdp",function(t){var e=(this.size-this.hdr_size)/2;this.priority=[];for(var r=0;r<e;r++)this.priority[r]=t.readUint16()}),d.createFullBoxCtor("sthd"),d.createFullBoxCtor("stri",function(t){this.switch_group=t.readUint16(),this.alternate_group=t.readUint16(),this.sub_track_id=t.readUint32();var e=(this.size-this.hdr_size-8)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),d.createFullBoxCtor("stsc",function(t){var e,r;if(e=t.readUint32(),this.first_chunk=[],this.samples_per_chunk=[],this.sample_description_index=[],0===this.version)for(r=0;r<e;r++)this.first_chunk.push(t.readUint32()),this.samples_per_chunk.push(t.readUint32()),this.sample_description_index.push(t.readUint32())}),d.createFullBoxCtor("stsd",function(t){var e,r,n,s;for(e=1,this.entries=[],n=t.readUint32();e<=n;e++){if((r=d.parseOneBox(t,!0,this.size-(t.getPosition()-this.start))).code!==d.OK)return;d[r.type+"SampleEntry"]?((s=new d[r.type+"SampleEntry"](r.size)).hdr_size=r.hdr_size,s.start=r.start):(l.warn("BoxParser","Unknown sample entry type: "+r.type),s=new d.SampleEntry(r.type,r.size,r.hdr_size,r.start)),s.write===d.SampleEntry.prototype.write&&(l.info("BoxParser","SampleEntry "+s.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),s.parseDataAndRewind(t)),s.parse(t),this.entries.push(s)}}),d.createFullBoxCtor("stsg",function(t){this.grouping_type=t.readUint32();var e=t.readUint16();this.group_description_index=[];for(var r=0;r<e;r++)this.group_description_index[r]=t.readUint32()}),d.createFullBoxCtor("stsh",function(t){var e,r;if(e=t.readUint32(),this.shadowed_sample_numbers=[],this.sync_sample_numbers=[],0===this.version)for(r=0;r<e;r++)this.shadowed_sample_numbers.push(t.readUint32()),this.sync_sample_numbers.push(t.readUint32())}),d.createFullBoxCtor("stss",function(t){var e,r;if(r=t.readUint32(),0===this.version)for(e=0,this.sample_numbers=[];e<r;e++)this.sample_numbers.push(t.readUint32())}),d.createFullBoxCtor("stsz",function(t){var e;if(this.sample_sizes=[],0===this.version)for(e=0,this.sample_size=t.readUint32(),this.sample_count=t.readUint32();e<this.sample_count;e++)0===this.sample_size?this.sample_sizes.push(t.readUint32()):this.sample_sizes[e]=this.sample_size}),d.createFullBoxCtor("stts",function(t){var e,r,n;if(e=t.readUint32(),this.sample_counts=[],this.sample_deltas=[],0===this.version)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),(n=t.readInt32())<0&&(l.warn("BoxParser","File uses negative stts sample delta, using value 1 instead, sync may be lost!"),n=1),this.sample_deltas.push(n)}),d.createFullBoxCtor("stvi",function(t){var e,r,n=t.readUint32();this.single_view_allowed=3&n,this.stereo_scheme=t.readUint32();var s=t.readUint32();for(this.stereo_indication_type=t.readString(s),this.boxes=[];t.getPosition()<this.start+this.size;){if((e=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;r=e.box,this.boxes.push(r),this[r.type]=r}}),d.createBoxCtor("styp",function(t){d.ftypBox.prototype.parse.call(this,t)}),d.createFullBoxCtor("stz2",function(t){if(this.sample_sizes=[],0===this.version)if(this.reserved=t.readUint24(),this.field_size=t.readUint8(),r=t.readUint32(),4===this.field_size)for(e=0;e<r;e+=2){var e,r,n=t.readUint8();this.sample_sizes[e]=n>>4&15,this.sample_sizes[e+1]=15&n}else if(8===this.field_size)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint8();else if(16===this.field_size)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint16();else l.error("BoxParser","Error in length field in stz2 box")}),d.createFullBoxCtor("subs",function(t){for(e=0,n=t.readUint32(),this.entries=[];e<n;e++){var e,r,n,s,a={};if(this.entries[e]=a,a.sample_delta=t.readUint32(),a.subsamples=[],(s=t.readUint16())>0)for(r=0;r<s;r++){var o={};a.subsamples.push(o),1==this.version?o.size=t.readUint32():o.size=t.readUint16(),o.priority=t.readUint8(),o.discardable=t.readUint8(),o.codec_specific_parameters=t.readUint32()}}}),d.createFullBoxCtor("tenc",function(t){if(t.readUint8(),0===this.version)t.readUint8();else{var e=t.readUint8();this.default_crypt_byte_block=e>>4&15,this.default_skip_byte_block=15&e}this.default_isProtected=t.readUint8(),this.default_Per_Sample_IV_Size=t.readUint8(),this.default_KID=d.parseHex16(t),1===this.default_isProtected&&0===this.default_Per_Sample_IV_Size&&(this.default_constant_IV_size=t.readUint8(),this.default_constant_IV=t.readUint8Array(this.default_constant_IV_size))}),d.createFullBoxCtor("tfdt",function(t){1==this.version?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()}),d.createFullBoxCtor("tfhd",function(t){var e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&d.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0}),d.createFullBoxCtor("tfra",function(t){this.track_ID=t.readUint32(),t.readUint24();var e=t.readUint8();this.length_size_of_traf_num=e>>4&3,this.length_size_of_trun_num=e>>2&3,this.length_size_of_sample_num=3&e,this.entries=[];for(var r=t.readUint32(),n=0;n<r;n++)1===this.version?(this.time=t.readUint64(),this.moof_offset=t.readUint64()):(this.time=t.readUint32(),this.moof_offset=t.readUint32()),this.traf_number=t["readUint"+8*(this.length_size_of_traf_num+1)](),this.trun_number=t["readUint"+8*(this.length_size_of_trun_num+1)](),this.sample_number=t["readUint"+8*(this.length_size_of_sample_num+1)]()}),d.createFullBoxCtor("tkhd",function(t){1==this.version?(this.creation_time=t.readUint64(),this.modification_time=t.readUint64(),this.track_id=t.readUint32(),t.readUint32(),this.duration=t.readUint64()):(this.creation_time=t.readUint32(),this.modification_time=t.readUint32(),this.track_id=t.readUint32(),t.readUint32(),this.duration=t.readUint32()),t.readUint32Array(2),this.layer=t.readInt16(),this.alternate_group=t.readInt16(),this.volume=t.readInt16()>>8,t.readUint16(),this.matrix=t.readInt32Array(9),this.width=t.readUint32(),this.height=t.readUint32()}),d.createBoxCtor("tmax",function(t){this.time=t.readUint32()}),d.createBoxCtor("tmin",function(t){this.time=t.readUint32()}),d.createBoxCtor("totl",function(t){this.bytessent=t.readUint32()}),d.createBoxCtor("tpay",function(t){this.bytessent=t.readUint32()}),d.createBoxCtor("tpyl",function(t){this.bytessent=t.readUint64()}),d.TrackGroupTypeBox.prototype.parse=function(t){this.parseFullHeader(t),this.track_group_id=t.readUint32()},d.createTrackGroupCtor("msrc"),d.TrackReferenceTypeBox=function(t,e,r,n){d.Box.call(this,t,e),this.hdr_size=r,this.start=n},d.TrackReferenceTypeBox.prototype=new d.Box,d.TrackReferenceTypeBox.prototype.parse=function(t){this.track_ids=t.readUint32Array((this.size-this.hdr_size)/4)},d.trefBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;){if((e=d.parseOneBox(t,!0,this.size-(t.getPosition()-this.start))).code!==d.OK)return;(r=new d.TrackReferenceTypeBox(e.type,e.size,e.hdr_size,e.start)).write===d.Box.prototype.write&&"mdat"!==r.type&&(l.info("BoxParser","TrackReference "+r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.boxes.push(r)}},d.createFullBoxCtor("trep",function(t){for(this.track_ID=t.readUint32(),this.boxes=[];t.getPosition()<this.start+this.size;){if((ret=d.parseOneBox(t,!1,this.size-(t.getPosition()-this.start))).code!==d.OK)return;box=ret.box,this.boxes.push(box)}}),d.createFullBoxCtor("trex",function(t){this.track_id=t.readUint32(),this.default_sample_description_index=t.readUint32(),this.default_sample_duration=t.readUint32(),this.default_sample_size=t.readUint32(),this.default_sample_flags=t.readUint32()}),d.createBoxCtor("trpy",function(t){this.bytessent=t.readUint64()}),d.createFullBoxCtor("trun",function(t){var e=0;if(this.sample_count=t.readUint32(),e+=4,this.size-this.hdr_size>e&&this.flags&d.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&d.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=t.readUint32(),e+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>e)for(var r=0;r<this.sample_count;r++)this.flags&d.TRUN_FLAGS_DURATION&&(this.sample_duration[r]=t.readUint32()),this.flags&d.TRUN_FLAGS_SIZE&&(this.sample_size[r]=t.readUint32()),this.flags&d.TRUN_FLAGS_FLAGS&&(this.sample_flags[r]=t.readUint32()),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?this.sample_composition_time_offset[r]=t.readUint32():this.sample_composition_time_offset[r]=t.readInt32())}),d.createFullBoxCtor("tsel",function(t){this.switch_group=t.readUint32();var e=(this.size-this.hdr_size-4)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),d.createFullBoxCtor("txtC",function(t){this.config=t.readCString()}),d.createBoxCtor("tyco",function(t){var e=(this.size-this.hdr_size)/4;this.compatible_brands=[];for(var r=0;r<e;r++)this.compatible_brands[r]=t.readString(4)}),d.createFullBoxCtor("udes",function(t){this.lang=t.readCString(),this.name=t.readCString(),this.description=t.readCString(),this.tags=t.readCString()}),d.createFullBoxCtor("uncC",function(t){var e;if(this.profile=t.readUint32(),1==this.version);else if(0==this.version){for(e=0,this.component_count=t.readUint32(),this.component_index=[],this.component_bit_depth_minus_one=[],this.component_format=[],this.component_align_size=[];e<this.component_count;e++)this.component_index.push(t.readUint16()),this.component_bit_depth_minus_one.push(t.readUint8()),this.component_format.push(t.readUint8()),this.component_align_size.push(t.readUint8());this.sampling_type=t.readUint8(),this.interleave_type=t.readUint8(),this.block_size=t.readUint8();var r=t.readUint8();this.component_little_endian=r>>7&1,this.block_pad_lsb=r>>6&1,this.block_little_endian=r>>5&1,this.block_reversed=r>>4&1,this.pad_unknown=r>>3&1,this.pixel_size=t.readUint32(),this.row_align_size=t.readUint32(),this.tile_align_size=t.readUint32(),this.num_tile_cols_minus_one=t.readUint32(),this.num_tile_rows_minus_one=t.readUint32()}}),d.createFullBoxCtor("url ",function(t){1!==this.flags&&(this.location=t.readCString())}),d.createFullBoxCtor("urn ",function(t){this.name=t.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=t.readCString())}),d.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,function(t){this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}),d.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,function(t){this.system_id=d.parseHex16(t);var e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))}),d.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),d.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,function(t){this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=d.parseHex16(t)}),d.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,function(t){this.fragment_count=t.readUint8(),this.entries=[];for(var e=0;e<this.fragment_count;e++){var r={},n=0,s=0;1===this.version?(n=t.readUint64(),s=t.readUint64()):(n=t.readUint32(),s=t.readUint32()),r.absolute_time=n,r.absolute_duration=s,this.entries.push(r)}}),d.createUUIDBox("6d1d9b0542d544e680e2141daff757b2",!0,!1,function(t){1===this.version?(this.absolute_time=t.readUint64(),this.duration=t.readUint64()):(this.absolute_time=t.readUint32(),this.duration=t.readUint32())}),d.createFullBoxCtor("vmhd",function(t){this.graphicsmode=t.readUint16(),this.opcolor=t.readUint16Array(3)}),d.createFullBoxCtor("vpcC",function(t){var e;1===this.version?(this.profile=t.readUint8(),this.level=t.readUint8(),e=t.readUint8(),this.bitDepth=e>>4,this.chromaSubsampling=e>>1&7,this.videoFullRangeFlag=1&e,this.colourPrimaries=t.readUint8(),this.transferCharacteristics=t.readUint8(),this.matrixCoefficients=t.readUint8()):(this.profile=t.readUint8(),this.level=t.readUint8(),e=t.readUint8(),this.bitDepth=e>>4&15,this.colorSpace=15&e,e=t.readUint8(),this.chromaSubsampling=e>>4&15,this.transferFunction=e>>1&7,this.videoFullRangeFlag=1&e),this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize)}),d.createBoxCtor("vttC",function(t){this.text=t.readString(this.size-this.hdr_size)}),d.createFullBoxCtor("vvcC",function(t){var e,r,n={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(t){this.held_bits=t.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(t){this.held_bits=t.readUint16(),this.num_held_bits=16},extract_bits:function(t){var e=this.held_bits>>this.num_held_bits-t&(1<<t)-1;return this.num_held_bits-=t,e}};if(n.stream_read_1_bytes(t),n.extract_bits(5),this.lengthSizeMinusOne=n.extract_bits(2),this.ptl_present_flag=n.extract_bits(1),this.ptl_present_flag){if(n.stream_read_2_bytes(t),this.ols_idx=n.extract_bits(9),this.num_sublayers=n.extract_bits(3),this.constant_frame_rate=n.extract_bits(2),this.chroma_format_idc=n.extract_bits(2),n.stream_read_1_bytes(t),this.bit_depth_minus8=n.extract_bits(3),n.extract_bits(5),n.stream_read_2_bytes(t),n.extract_bits(2),this.num_bytes_constraint_info=n.extract_bits(6),this.general_profile_idc=n.extract_bits(7),this.general_tier_flag=n.extract_bits(1),this.general_level_idc=t.readUint8(),n.stream_read_1_bytes(t),this.ptl_frame_only_constraint_flag=n.extract_bits(1),this.ptl_multilayer_enabled_flag=n.extract_bits(1),this.general_constraint_info=new Uint8Array(this.num_bytes_constraint_info),this.num_bytes_constraint_info){for(e=0;e<this.num_bytes_constraint_info-1;e++){var s=n.extract_bits(6);n.stream_read_1_bytes(t);var a=n.extract_bits(2);this.general_constraint_info[e]=s<<2|a}this.general_constraint_info[this.num_bytes_constraint_info-1]=n.extract_bits(6)}else n.extract_bits(6);if(this.num_sublayers>1){for(n.stream_read_1_bytes(t),this.ptl_sublayer_present_mask=0,r=this.num_sublayers-2;r>=0;--r){var o=n.extract_bits(1);this.ptl_sublayer_present_mask|=o<<r}for(r=this.num_sublayers;r<=8&&this.num_sublayers>1;++r)n.extract_bits(1);for(this.sublayer_level_idc=[],r=this.num_sublayers-2;r>=0;--r)this.ptl_sublayer_present_mask&1<<r&&(this.sublayer_level_idc[r]=t.readUint8())}if(this.ptl_num_sub_profiles=t.readUint8(),this.general_sub_profile_idc=[],this.ptl_num_sub_profiles)for(e=0;e<this.ptl_num_sub_profiles;e++)this.general_sub_profile_idc.push(t.readUint32());this.max_picture_width=t.readUint16(),this.max_picture_height=t.readUint16(),this.avg_frame_rate=t.readUint16()}this.nalu_arrays=[];var l=t.readUint8();for(e=0;e<l;e++){var u=[];this.nalu_arrays.push(u),n.stream_read_1_bytes(t),u.completeness=n.extract_bits(1),n.extract_bits(2),u.nalu_type=n.extract_bits(5);var c=1;for(13!=u.nalu_type&&12!=u.nalu_type&&(c=t.readUint16()),r=0;r<c;r++){var h=t.readUint16();u.push({data:t.readUint8Array(h),length:h})}}}),d.createFullBoxCtor("vvnC",function(t){var e=strm.readUint8();this.lengthSizeMinusOne=3&e}),d.SampleEntry.prototype.isVideo=function(){return!1},d.SampleEntry.prototype.isAudio=function(){return!1},d.SampleEntry.prototype.isSubtitle=function(){return!1},d.SampleEntry.prototype.isMetadata=function(){return!1},d.SampleEntry.prototype.isHint=function(){return!1},d.SampleEntry.prototype.getCodec=function(){return this.type.replace(".","")},d.SampleEntry.prototype.getWidth=function(){return""},d.SampleEntry.prototype.getHeight=function(){return""},d.SampleEntry.prototype.getChannelCount=function(){return""},d.SampleEntry.prototype.getSampleRate=function(){return""},d.SampleEntry.prototype.getSampleSize=function(){return""},d.VisualSampleEntry.prototype.isVideo=function(){return!0},d.VisualSampleEntry.prototype.getWidth=function(){return this.width},d.VisualSampleEntry.prototype.getHeight=function(){return this.height},d.AudioSampleEntry.prototype.isAudio=function(){return!0},d.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count},d.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate},d.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize},d.SubtitleSampleEntry.prototype.isSubtitle=function(){return!0},d.MetadataSampleEntry.prototype.isMetadata=function(){return!0},d.decimalToHex=function(t,e){var r=Number(t).toString(16);for(e=null==e?e=2:e;r.length<e;)r="0"+r;return r},d.avc1SampleEntry.prototype.getCodec=d.avc2SampleEntry.prototype.getCodec=d.avc3SampleEntry.prototype.getCodec=d.avc4SampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);return this.avcC?t+"."+d.decimalToHex(this.avcC.AVCProfileIndication)+d.decimalToHex(this.avcC.profile_compatibility)+d.decimalToHex(this.avcC.AVCLevelIndication):t},d.hev1SampleEntry.prototype.getCodec=d.hvc1SampleEntry.prototype.getCodec=function(){var t,e=d.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){switch(e+=".",this.hvcC.general_profile_space){case 0:e+="";break;case 1:e+="A";break;case 2:e+="B";break;case 3:e+="C"}e+=this.hvcC.general_profile_idc,e+=".";var r=this.hvcC.general_profile_compatibility,n=0;for(t=0;t<32&&(n|=1&r,31!=t);t++)n<<=1,r>>=1;e+=d.decimalToHex(n,0),e+=".",0===this.hvcC.general_tier_flag?e+="L":e+="H",e+=this.hvcC.general_level_idc;var s=!1,a="";for(t=5;t>=0;t--)(this.hvcC.general_constraint_indicator[t]||s)&&(a="."+d.decimalToHex(this.hvcC.general_constraint_indicator[t],0)+a,s=!0);e+=a}return e},d.vvc1SampleEntry.prototype.getCodec=d.vvi1SampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);if(this.vvcC){t+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?t+=".H":t+=".L",t+=this.vvcC.general_level_idc;var e="";if(this.vvcC.general_constraint_info){var r,n,s,a=[];for(n=0,r=this.vvcC.ptl_frame_only_constraint<<7|this.vvcC.ptl_multilayer_enabled<<6;n<this.vvcC.general_constraint_info.length;++n)r|=this.vvcC.general_constraint_info[n]>>2&63,a.push(r),r&&(s=n),r=this.vvcC.general_constraint_info[n]>>2&3;if(void 0===s)e=".CA";else{e=".C";var o="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",l=0,u=0;for(n=0;n<=s;++n)for(l=l<<8|a[n],u+=8;u>=5;)e+=o[l>>u-5&31],u-=5,l&=(1<<u)-1;u&&(l<<=5-u,e+=o[31&l])}}t+=e}return t},d.mp4aSampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);if(!this.esds||!this.esds.esd)return t;var e=this.esds.esd.getOTI(),r=this.esds.esd.getAudioConfig();return t+"."+d.decimalToHex(e)+(r?"."+r:"")},d.stxtSampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this);return this.mime_format?t+"."+this.mime_format:t},d.vp08SampleEntry.prototype.getCodec=d.vp09SampleEntry.prototype.getCodec=function(){var t=d.SampleEntry.prototype.getCodec.call(this),e=this.vpcC.level;0==e&&(e="00");var r=this.vpcC.bitDepth;return 8==r&&(r="08"),t+".0"+this.vpcC.profile+"."+e+"."+r},d.av01SampleEntry.prototype.getCodec=function(){var t,e=d.SampleEntry.prototype.getCodec.call(this),r=this.av1C.seq_level_idx_0;return r<10&&(r="0"+r),2===this.av1C.seq_profile&&1===this.av1C.high_bitdepth?t=1===this.av1C.twelve_bit?"12":"10":this.av1C.seq_profile<=2&&(t=1===this.av1C.high_bitdepth?"10":"08"),e+"."+this.av1C.seq_profile+"."+r+(this.av1C.seq_tier_0?"H":"M")+"."+t},d.Box.prototype.writeHeader=function(t,e){this.size+=8,this.size>0x100000000&&(this.size+=8),"uuid"===this.type&&(this.size+=16),l.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.size>0x100000000?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,null,4),"uuid"===this.type&&t.writeUint8Array(this.uuid),this.size>0x100000000&&t.writeUint64(this.size)},d.FullBox.prototype.writeHeader=function(t){this.size+=4,d.Box.prototype.writeHeader.call(this,t," v="+this.version+" f="+this.flags),t.writeUint8(this.version),t.writeUint24(this.flags)},d.Box.prototype.write=function(t){"mdat"===this.type?this.data&&(this.size=this.data.length,this.writeHeader(t),t.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data))},d.ContainerBox.prototype.write=function(t){this.size=0,this.writeHeader(t);for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&(this.boxes[e].write(t),this.size+=this.boxes[e].size);l.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.TrackReferenceTypeBox.prototype.write=function(t){this.size=4*this.track_ids.length,this.writeHeader(t),t.writeUint32Array(this.track_ids)},d.avcCBox.prototype.write=function(t){var e;for(e=0,this.size=7;e<this.SPS.length;e++)this.size+=2+this.SPS[e].length;for(e=0;e<this.PPS.length;e++)this.size+=2+this.PPS[e].length;for(this.ext&&(this.size+=this.ext.length),this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8(this.AVCProfileIndication),t.writeUint8(this.profile_compatibility),t.writeUint8(this.AVCLevelIndication),t.writeUint8(this.lengthSizeMinusOne+252),t.writeUint8(this.SPS.length+224),e=0;e<this.SPS.length;e++)t.writeUint16(this.SPS[e].length),t.writeUint8Array(this.SPS[e].nalu);for(t.writeUint8(this.PPS.length),e=0;e<this.PPS.length;e++)t.writeUint16(this.PPS[e].length),t.writeUint8Array(this.PPS[e].nalu);this.ext&&t.writeUint8Array(this.ext)},d.co64Box.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),e=0;e<this.chunk_offsets.length;e++)t.writeUint64(this.chunk_offsets[e])},d.cslgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20,this.writeHeader(t),t.writeInt32(this.compositionToDTSShift),t.writeInt32(this.leastDecodeToDisplayDelta),t.writeInt32(this.greatestDecodeToDisplayDelta),t.writeInt32(this.compositionStartTime),t.writeInt32(this.compositionEndTime)},d.cttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),1===this.version?t.writeInt32(this.sample_offsets[e]):t.writeUint32(this.sample_offsets[e])},d.drefBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;l.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.elngBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.extended_language.length,this.writeHeader(t),t.writeString(this.extended_language)},d.elstBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+12*this.entries.length,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeUint32(r.segment_duration),t.writeInt32(r.media_time),t.writeInt16(r.media_rate_integer),t.writeInt16(r.media_rate_fraction)}},d.emsgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=16+this.message_data.length+(this.scheme_id_uri.length+1)+(this.value.length+1),this.writeHeader(t),t.writeCString(this.scheme_id_uri),t.writeCString(this.value),t.writeUint32(this.timescale),t.writeUint32(this.presentation_time_delta),t.writeUint32(this.event_duration),t.writeUint32(this.id),t.writeUint8Array(this.message_data)},d.ftypBox.prototype.write=function(t){this.size=8+4*this.compatible_brands.length,this.writeHeader(t),t.writeString(this.major_brand,null,4),t.writeUint32(this.minor_version);for(var e=0;e<this.compatible_brands.length;e++)t.writeString(this.compatible_brands[e],null,4)},d.hdlrBox.prototype.write=function(t){this.size=20+this.name.length+1,this.version=0,this.flags=0,this.writeHeader(t),t.writeUint32(0),t.writeString(this.handler,null,4),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeCString(this.name)},d.hvcCBox.prototype.write=function(t){var e,r;for(e=0,this.size=23;e<this.nalu_arrays.length;e++)for(this.size+=3,r=0;r<this.nalu_arrays[e].length;r++)this.size+=2+this.nalu_arrays[e][r].data.length;for(this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8((this.general_profile_space<<6)+(this.general_tier_flag<<5)+this.general_profile_idc),t.writeUint32(this.general_profile_compatibility),t.writeUint8Array(this.general_constraint_indicator),t.writeUint8(this.general_level_idc),t.writeUint16(this.min_spatial_segmentation_idc+0xf000000),t.writeUint8(this.parallelismType+252),t.writeUint8(this.chroma_format_idc+252),t.writeUint8(this.bit_depth_luma_minus8+248),t.writeUint8(this.bit_depth_chroma_minus8+248),t.writeUint16(this.avgFrameRate),t.writeUint8((this.constantFrameRate<<6)+(this.numTemporalLayers<<3)+(this.temporalIdNested<<2)+this.lengthSizeMinusOne),t.writeUint8(this.nalu_arrays.length),e=0;e<this.nalu_arrays.length;e++)for(t.writeUint8((this.nalu_arrays[e].completeness<<7)+this.nalu_arrays[e].nalu_type),t.writeUint16(this.nalu_arrays[e].length),r=0;r<this.nalu_arrays[e].length;r++)t.writeUint16(this.nalu_arrays[e][r].data.length),t.writeUint8Array(this.nalu_arrays[e][r].data)},d.kindBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.schemeURI.length+1+(this.value.length+1),this.writeHeader(t),t.writeCString(this.schemeURI),t.writeCString(this.value)},d.mdhdBox.prototype.write=function(t){this.size=20,this.flags=0,this.version=0,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint16(this.language),t.writeUint16(0)},d.mehdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.fragment_duration)},d.mfhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.sequence_number)},d.mvhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=96,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint32(this.rate),t.writeUint16(this.volume<<8),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32Array(this.matrix),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(this.next_track_id)},d.SampleEntry.prototype.writeHeader=function(t){this.size=8,d.Box.prototype.writeHeader.call(this,t),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint16(this.data_reference_index)},d.SampleEntry.prototype.writeFooter=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t),this.size+=this.boxes[e].size;l.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.SampleEntry.prototype.write=function(t){this.writeHeader(t),t.writeUint8Array(this.data),this.size+=this.data.length,l.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.VisualSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=70,t.writeUint16(0),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint32(this.horizresolution),t.writeUint32(this.vertresolution),t.writeUint32(0),t.writeUint16(this.frame_count),t.writeUint8(Math.min(31,this.compressorname.length)),t.writeString(this.compressorname,null,31),t.writeUint16(this.depth),t.writeInt16(-1),this.writeFooter(t)},d.AudioSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=20,t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.channel_count),t.writeUint16(this.samplesize),t.writeUint16(0),t.writeUint16(0),t.writeUint32(this.samplerate<<16),this.writeFooter(t)},d.stppSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=this.namespace.length+1+this.schema_location.length+1+this.auxiliary_mime_types.length+1,t.writeCString(this.namespace),t.writeCString(this.schema_location),t.writeCString(this.auxiliary_mime_types),this.writeFooter(t)},d.SampleGroupEntry.prototype.write=function(t){t.writeUint8Array(this.data)},d.sbgpBox.prototype.write=function(t){this.version=1,this.flags=0,this.size=12+8*this.entries.length,this.writeHeader(t),t.writeString(this.grouping_type,null,4),t.writeUint32(this.grouping_type_parameter),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeInt32(r.sample_count),t.writeInt32(r.group_description_index)}},d.sgpdBox.prototype.write=function(t){var e,r;for(e=0,this.flags=0,this.size=12;e<this.entries.length;e++)r=this.entries[e],1===this.version&&(0===this.default_length&&(this.size+=4),this.size+=r.data.length);for(this.writeHeader(t),t.writeString(this.grouping_type,null,4),1===this.version&&t.writeUint32(this.default_length),this.version>=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length),e=0;e<this.entries.length;e++)r=this.entries[e],1===this.version&&0===this.default_length&&t.writeUint32(r.description_length),r.write(t)},d.sidxBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20+12*this.references.length,this.writeHeader(t),t.writeUint32(this.reference_ID),t.writeUint32(this.timescale),t.writeUint32(this.earliest_presentation_time),t.writeUint32(this.first_offset),t.writeUint16(0),t.writeUint16(this.references.length);for(var e=0;e<this.references.length;e++){var r=this.references[e];t.writeUint32(r.reference_type<<31|r.referenced_size),t.writeUint32(r.subsegment_duration),t.writeUint32(r.starts_with_SAP<<31|r.SAP_type<<28|r.SAP_delta_time)}},d.smhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=4,this.writeHeader(t),t.writeUint16(this.balance),t.writeUint16(0)},d.stcoBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),t.writeUint32Array(this.chunk_offsets)},d.stscBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+12*this.first_chunk.length,this.writeHeader(t),t.writeUint32(this.first_chunk.length),e=0;e<this.first_chunk.length;e++)t.writeUint32(this.first_chunk[e]),t.writeUint32(this.samples_per_chunk[e]),t.writeUint32(this.sample_description_index[e])},d.stsdBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=0,this.writeHeader(t),t.writeUint32(this.entries.length),this.size+=4,e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;l.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},d.stshBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.shadowed_sample_numbers.length,this.writeHeader(t),t.writeUint32(this.shadowed_sample_numbers.length),e=0;e<this.shadowed_sample_numbers.length;e++)t.writeUint32(this.shadowed_sample_numbers[e]),t.writeUint32(this.sync_sample_numbers[e])},d.stssBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.sample_numbers.length,this.writeHeader(t),t.writeUint32(this.sample_numbers.length),t.writeUint32Array(this.sample_numbers)},d.stszBox.prototype.write=function(t){var e,r=!0;if(this.version=0,this.flags=0,this.sample_sizes.length>0)for(e=0;e+1<this.sample_sizes.length;)if(this.sample_sizes[e+1]!==this.sample_sizes[0]){r=!1;break}else e++;else r=!1;this.size=8,r||(this.size+=4*this.sample_sizes.length),this.writeHeader(t),r?t.writeUint32(this.sample_sizes[0]):t.writeUint32(0),t.writeUint32(this.sample_sizes.length),r||t.writeUint32Array(this.sample_sizes)},d.sttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),t.writeUint32(this.sample_deltas[e])},d.tfdtBox.prototype.write=function(t){this.version=+(this.baseMediaDecodeTime>0xffffffff),this.flags=0,this.size=4,1===this.version&&(this.size+=4),this.writeHeader(t),1===this.version?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)},d.tfhdBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&d.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&d.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&d.TFHD_FLAG_BASE_DATA_OFFSET&&t.writeUint64(this.base_data_offset),this.flags&d.TFHD_FLAG_SAMPLE_DESC&&t.writeUint32(this.default_sample_description_index),this.flags&d.TFHD_FLAG_SAMPLE_DUR&&t.writeUint32(this.default_sample_duration),this.flags&d.TFHD_FLAG_SAMPLE_SIZE&&t.writeUint32(this.default_sample_size),this.flags&d.TFHD_FLAG_SAMPLE_FLAGS&&t.writeUint32(this.default_sample_flags)},d.tkhdBox.prototype.write=function(t){this.version=0,this.size=80,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration),t.writeUint32(0),t.writeUint32(0),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeUint16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)},d.trexBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=20,this.writeHeader(t),t.writeUint32(this.track_id),t.writeUint32(this.default_sample_description_index),t.writeUint32(this.default_sample_duration),t.writeUint32(this.default_sample_size),t.writeUint32(this.default_sample_flags)},d.trunBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&d.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&d.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&d.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&d.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&d.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&d.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&d.TRUN_FLAGS_FIRST_FLAG&&t.writeUint32(this.first_sample_flags);for(var e=0;e<this.sample_count;e++)this.flags&d.TRUN_FLAGS_DURATION&&t.writeUint32(this.sample_duration[e]),this.flags&d.TRUN_FLAGS_SIZE&&t.writeUint32(this.sample_size[e]),this.flags&d.TRUN_FLAGS_FLAGS&&t.writeUint32(this.sample_flags[e]),this.flags&d.TRUN_FLAGS_CTS_OFFSET&&(0===this.version?t.writeUint32(this.sample_composition_time_offset[e]):t.writeInt32(this.sample_composition_time_offset[e]))},d["url Box"].prototype.write=function(t){this.version=0,this.location?(this.flags=0,this.size=this.location.length+1):(this.flags=1,this.size=0),this.writeHeader(t),this.location&&t.writeCString(this.location)},d["urn Box"].prototype.write=function(t){this.version=0,this.flags=0,this.size=this.name.length+1+(this.location?this.location.length+1:0),this.writeHeader(t),t.writeCString(this.name),this.location&&t.writeCString(this.location)},d.vmhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=8,this.writeHeader(t),t.writeUint16(this.graphicsmode),t.writeUint16Array(this.opcolor)},d.cttsBox.prototype.unpack=function(t){var e,r,n;for(e=0,n=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)t[n].pts=t[n].dts+this.sample_offsets[e],n++},d.sttsBox.prototype.unpack=function(t){var e,r,n;for(e=0,n=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)0===n?t[n].dts=0:t[n].dts=t[n-1].dts+this.sample_deltas[e],n++},d.stcoBox.prototype.unpack=function(t){var e;for(e=0;e<this.chunk_offsets.length;e++)t[e].offset=this.chunk_offsets[e]},d.stscBox.prototype.unpack=function(t){var e,r,n,s,a;for(e=0,s=0,a=0;e<this.first_chunk.length;e++)for(r=0;r<(e+1<this.first_chunk.length?this.first_chunk[e+1]:1/0);r++)for(a++,n=0;n<this.samples_per_chunk[e];n++){if(!t[s])return;t[s].description_index=this.sample_description_index[e],t[s].chunk_index=a,s++}},d.stszBox.prototype.unpack=function(t){var e;for(e=0;e<this.sample_sizes.length;e++)t[e].size=this.sample_sizes[e]},d.DIFF_BOXES_PROP_NAMES=["boxes","entries","references","subsamples","items","item_infos","extents","associations","subsegments","ranges","seekLists","seekPoints","esd","levels"],d.DIFF_PRIMITIVE_ARRAY_PROP_NAMES=["compatible_brands","matrix","opcolor","sample_counts","sample_counts","sample_deltas","first_chunk","samples_per_chunk","sample_sizes","chunk_offsets","sample_offsets","sample_description_index","sample_duration"],d.boxEqualFields=function(t,e){var r;if(t&&!e)return!1;for(r in t)if(d.DIFF_BOXES_PROP_NAMES.indexOf(r)>-1)continue;else if(t[r]instanceof d.Box||e[r]instanceof d.Box)continue;else if(void 0===t[r]||void 0===e[r])continue;else if("function"==typeof t[r]||"function"==typeof e[r])continue;else if(t.subBoxNames&&t.subBoxNames.indexOf(r.slice(0,4))>-1||e.subBoxNames&&e.subBoxNames.indexOf(r.slice(0,4))>-1)continue;else if("data"===r||"start"===r||"size"===r||"creation_time"===r||"modification_time"===r)continue;else if(d.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(r)>-1)continue;else if(t[r]!==e[r])return!1;return!0},d.boxEqual=function(t,e){if(!d.boxEqualFields(t,e))return!1;for(var r=0;r<d.DIFF_BOXES_PROP_NAMES.length;r++){var n=d.DIFF_BOXES_PROP_NAMES[r];if(t[n]&&e[n]&&!d.boxEqual(t[n],e[n]))return!1}return!0};var m=function(){};m.prototype.parseSample=function(t){var e,r,n=new u(t.buffer);for(e=[];!n.isEos();)(r=d.parseOneBox(n,!1)).code===d.OK&&"vttc"===r.box.type&&e.push(r.box);return e},m.prototype.getText=function(t,e,r){function n(t,e,r){return r=r||"0",(t+="").length>=e?t:Array(e-t.length+1).join(r)+t}function s(t){var e=Math.floor(t/3600),r=Math.floor((t-3600*e)/60),s=Math.floor(t-3600*e-60*r),a=Math.floor((t-3600*e-60*r-s)*1e3);return""+n(e,2)+":"+n(r,2)+":"+n(s,2)+"."+n(a,3)}for(var a=this.parseSample(r),o="",l=0;l<a.length;l++){var u=a[l];o+=s(t)+" --\x3e "+s(e)+"\r\n",o+=u.payl.text}return o};var y=function(){};y.prototype.parseSample=function(t){var e,r={};r.resources=[];var n=new u(t.data.buffer);if(t.subsamples&&0!==t.subsamples.length){if(r.documentString=n.readString(t.subsamples[0].size),t.subsamples.length>1)for(e=1;e<t.subsamples.length;e++)r.resources[e]=n.readUint8Array(t.subsamples[e].size)}else r.documentString=n.readString(t.data.length);return"undefined"!=typeof DOMParser&&(r.document=new DOMParser().parseFromString(r.documentString,"application/xml")),r};var g=function(){};g.prototype.parseSample=function(t){return new u(t.data.buffer).readString(t.data.length)},g.prototype.parseConfig=function(t){var e=new u(t.buffer);return e.readUint32(),e.readCString()},r.XMLSubtitlein4Parser=y,r.Textin4Parser=g;var v=function(t){this.stream=t||new h,this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.onSidx=null,this.sidxSent=!1};v.prototype.setSegmentOptions=function(t,e,r){var n=this.getTrackById(t);if(n){var s={};this.fragmentedTracks.push(s),s.id=t,s.user=e,s.trak=n,n.nextSample=0,s.segmentStream=null,s.nb_samples=1e3,s.rapAlignement=!0,r&&(r.nbSamples&&(s.nb_samples=r.nbSamples),r.rapAlignement&&(s.rapAlignement=r.rapAlignement))}},v.prototype.unsetSegmentOptions=function(t){for(var e=-1,r=0;r<this.fragmentedTracks.length;r++)this.fragmentedTracks[r].id==t&&(e=r);e>-1&&this.fragmentedTracks.splice(e,1)},v.prototype.setExtractionOptions=function(t,e,r){var n=this.getTrackById(t);if(n){var s={};this.extractedTracks.push(s),s.id=t,s.user=e,s.trak=n,n.nextSample=0,s.nb_samples=1e3,s.samples=[],r&&r.nbSamples&&(s.nb_samples=r.nbSamples)}},v.prototype.unsetExtractionOptions=function(t){for(var e=-1,r=0;r<this.extractedTracks.length;r++)this.extractedTracks[r].id==t&&(e=r);e>-1&&this.extractedTracks.splice(e,1)},v.prototype.parse=function(){var t,e,r;if(!this.restoreParsePosition||this.restoreParsePosition())for(;;)if(this.hasIncompleteMdat&&this.hasIncompleteMdat())if(this.processIncompleteMdat())continue;else return;else{if(this.saveParsePosition&&this.saveParsePosition(),(t=d.parseOneBox(this.stream,!1)).code===d.ERR_NOT_ENOUGH_DATA)if(!this.processIncompleteBox)return;else if(this.processIncompleteBox(t))continue;else return;switch(r="uuid"!==(e=t.box).type?e.type:e.uuid,this.boxes.push(e),r){case"mdat":this.mdats.push(e);break;case"moof":this.moofs.push(e);break;case"moov":this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0);default:void 0!==this[r]&&l.warn("ISOFile","Duplicate Box of type: "+r+", overriding previous occurrence"),this[r]=e}this.updateUsedBytes&&this.updateUsedBytes(e,t)}},v.prototype.checkBuffer=function(t){if(null==t)throw"Buffer must be defined and non empty";if(void 0===t.fileStart)throw"Buffer must have a fileStart property";return 0===t.byteLength?(l.warn("ISOFile","Ignoring empty buffer (fileStart: "+t.fileStart+")"),this.stream.logBufferLevel(),!1):(l.info("ISOFile","Processing buffer (fileStart: "+t.fileStart+")"),t.usedBytes=0,this.stream.insertBuffer(t),this.stream.logBufferLevel(),!!this.stream.initialized()||(l.warn("ISOFile","Not ready to start parsing"),!1))},v.prototype.appendBuffer=function(t,e){var r;if(this.checkBuffer(t))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(e),this.nextSeekPosition?(r=this.nextSeekPosition,this.nextSeekPosition=void 0):r=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(r=this.stream.getEndFilePositionAfter(r))):r=this.nextParsePosition?this.nextParsePosition:0,this.sidx&&this.onSidx&&!this.sidxSent&&(this.onSidx(this.sidx),this.sidxSent=!0),this.meta&&(this.flattenItemInfo&&!this.itemListBuilt&&(this.flattenItemInfo(),this.itemListBuilt=!0),this.processItems&&this.processItems(this.onItem)),this.stream.cleanBuffers&&(l.info("ISOFile","Done processing buffer (fileStart: "+t.fileStart+") - next buffer to fetch should have a fileStart position of "+r),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),l.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),r},v.prototype.getInfo=function(){var t,e,r,n,s,a,o={},l=new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(o.hasMoov=!0,o.duration=this.moov.mvhd.duration,o.timescale=this.moov.mvhd.timescale,o.isFragmented=null!=this.moov.mvex,o.isFragmented&&this.moov.mvex.mehd&&(o.fragment_duration=this.moov.mvex.mehd.fragment_duration),o.isProgressive=this.isProgressive,o.hasIOD=null!=this.moov.iods,o.brands=[],o.brands.push(this.ftyp.major_brand),o.brands=o.brands.concat(this.ftyp.compatible_brands),o.created=new Date(l+1e3*this.moov.mvhd.creation_time),o.modified=new Date(l+1e3*this.moov.mvhd.modification_time),o.tracks=[],o.audioTracks=[],o.videoTracks=[],o.subtitleTracks=[],o.metadataTracks=[],o.hintTracks=[],o.otherTracks=[],t=0;t<this.moov.traks.length;t++){if(a=(r=this.moov.traks[t]).mdia.minf.stbl.stsd.entries[0],n={},o.tracks.push(n),n.id=r.tkhd.track_id,n.name=r.mdia.hdlr.name,n.references=[],r.tref)for(e=0;e<r.tref.boxes.length;e++)s={},n.references.push(s),s.type=r.tref.boxes[e].type,s.track_ids=r.tref.boxes[e].track_ids;r.edts&&(n.edits=r.edts.elst.entries),n.created=new Date(l+1e3*r.tkhd.creation_time),n.modified=new Date(l+1e3*r.tkhd.modification_time),n.movie_duration=r.tkhd.duration,n.movie_timescale=o.timescale,n.layer=r.tkhd.layer,n.alternate_group=r.tkhd.alternate_group,n.volume=r.tkhd.volume,n.matrix=r.tkhd.matrix,n.track_width=r.tkhd.width/65536,n.track_height=r.tkhd.height/65536,n.timescale=r.mdia.mdhd.timescale,n.cts_shift=r.mdia.minf.stbl.cslg,n.duration=r.mdia.mdhd.duration,n.samples_duration=r.samples_duration,n.codec=a.getCodec(),n.kind=r.udta&&r.udta.kinds.length?r.udta.kinds[0]:{schemeURI:"",value:""},n.language=r.mdia.elng?r.mdia.elng.extended_language:r.mdia.mdhd.languageString,n.nb_samples=r.samples.length,n.size=r.samples_size,n.bitrate=8*n.size*n.timescale/n.samples_duration,a.isAudio()?(n.type="audio",o.audioTracks.push(n),n.audio={},n.audio.sample_rate=a.getSampleRate(),n.audio.channel_count=a.getChannelCount(),n.audio.sample_size=a.getSampleSize()):a.isVideo()?(n.type="video",o.videoTracks.push(n),n.video={},n.video.width=a.getWidth(),n.video.height=a.getHeight()):a.isSubtitle()?(n.type="subtitles",o.subtitleTracks.push(n)):a.isHint()?(n.type="metadata",o.hintTracks.push(n)):a.isMetadata()?(n.type="metadata",o.metadataTracks.push(n)):(n.type="metadata",o.otherTracks.push(n))}else o.hasMoov=!1;if(o.mime="",o.hasMoov&&o.tracks){for(o.videoTracks&&o.videoTracks.length>0?o.mime+='video/mp4; codecs="':o.audioTracks&&o.audioTracks.length>0?o.mime+='audio/mp4; codecs="':o.mime+='application/mp4; codecs="',t=0;t<o.tracks.length;t++)0!==t&&(o.mime+=","),o.mime+=o.tracks[t].codec;o.mime+='"; profiles="',o.mime+=this.ftyp.compatible_brands.join(),o.mime+='"'}return o},v.prototype.setNextSeekPositionFromSample=function(t){t&&(this.nextSeekPosition?this.nextSeekPosition=Math.min(t.offset+t.alreadyRead,this.nextSeekPosition):this.nextSeekPosition=t.offset+t.alreadyRead)},v.prototype.processSamples=function(t){if(this.sampleProcessingStarted){if(this.isFragmentationInitialized&&null!==this.onSegment)for(e=0;e<this.fragmentedTracks.length;e++){var e,r,n=this.fragmentedTracks[e];for(r=n.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){l.debug("ISOFile","Creating media fragment on track #"+n.id+" for sample "+r.nextSample);var s=this.createFragment(n.id,r.nextSample,n.segmentStream);if(s)n.segmentStream=s,r.nextSample++;else break;if((r.nextSample%n.nb_samples==0||t||r.nextSample>=r.samples.length)&&(l.info("ISOFile","Sending fragmented data on track #"+n.id+" for samples ["+Math.max(0,r.nextSample-n.nb_samples)+","+(r.nextSample-1)+"]"),l.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(n.id,n.user,n.segmentStream.buffer,r.nextSample,t||r.nextSample>=r.samples.length),n.segmentStream=null,n!==this.fragmentedTracks[e]))break}}if(null!==this.onSamples)for(e=0;e<this.extractedTracks.length;e++){var a=this.extractedTracks[e];for(r=a.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){l.debug("ISOFile","Exporting on track #"+a.id+" sample #"+r.nextSample);var o=this.getSample(r,r.nextSample);if(o)r.nextSample++,a.samples.push(o);else{this.setNextSeekPositionFromSample(r.samples[r.nextSample]);break}if((r.nextSample%a.nb_samples==0||r.nextSample>=r.samples.length)&&(l.debug("ISOFile","Sending samples on track #"+a.id+" for sample "+r.nextSample),this.onSamples&&this.onSamples(a.id,a.user,a.samples),a.samples=[],a!==this.extractedTracks[e]))break}}}},v.prototype.getBox=function(t){var e=this.getBoxes(t,!0);return e.length?e[0]:null},v.prototype.getBoxes=function(t,e){var r=[];return v._sweep.call(this,t,r,e),r},v._sweep=function(t,e,r){for(var n in this.type&&this.type==t&&e.push(this),this.boxes){if(e.length&&r)return;v._sweep.call(this.boxes[n],t,e,r)}},v.prototype.getTrackSamplesInfo=function(t){var e=this.getTrackById(t);return e?e.samples:void 0},v.prototype.getTrackSample=function(t,e){var r=this.getTrackById(t);return this.getSample(r,e)},v.prototype.releaseUsedSamples=function(t,e){var r=0,n=this.getTrackById(t);n.lastValidSample||(n.lastValidSample=0);for(var s=n.lastValidSample;s<e;s++)r+=this.releaseSample(n,s);l.info("ISOFile","Track #"+t+" released samples up to "+e+" (released size: "+r+", remaining: "+this.samplesDataSize+")"),n.lastValidSample=e},v.prototype.start=function(){this.sampleProcessingStarted=!0,this.processSamples(!1)},v.prototype.stop=function(){this.sampleProcessingStarted=!1},v.prototype.flush=function(){l.info("ISOFile","Flushing remaining samples"),this.updateSampleLists(),this.processSamples(!0),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0)},v.prototype.seekTrack=function(t,e,r){var n,s,a,o=1/0,u=0,c=0;if(0===r.samples.length)return l.info("ISOFile","No sample in track, cannot seek! Using time "+l.getDurationString(0,1)+" and offset: 0"),{offset:0,time:0};for(n=0;n<r.samples.length;n++){if(s=r.samples[n],0===n)c=0,a=s.timescale;else if(s.cts>t*s.timescale){c=n-1;break}e&&s.is_sync&&(u=n)}for(e&&(c=u),t=r.samples[c].cts,r.nextSample=c;r.samples[c].alreadyRead===r.samples[c].size&&r.samples[c+1];)c++;return o=r.samples[c].offset+r.samples[c].alreadyRead,l.info("ISOFile","Seeking to "+(e?"RAP":"")+" sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+l.getDurationString(t,a)+" and offset: "+o),{offset:o,time:t/a}},v.prototype.getTrackDuration=function(t){var e;return t.samples?((e=t.samples[t.samples.length-1]).cts+e.duration)/e.timescale:1/0},v.prototype.seek=function(t,e){var r,n,s,a=this.moov,o={offset:1/0,time:1/0};if(this.moov){for(s=0;s<a.traks.length;s++)r=a.traks[s],!(t>this.getTrackDuration(r))&&((n=this.seekTrack(t,e,r)).offset<o.offset&&(o.offset=n.offset),n.time<o.time&&(o.time=n.time));return l.info("ISOFile","Seeking at time "+l.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset),o.offset===1/0?o={offset:this.nextParsePosition,time:0}:o.offset=this.stream.getEndFilePositionAfter(o.offset),l.info("ISOFile","Adjusted seek position (after checking data already in buffer): "+o.offset),o}throw"Cannot seek: moov not received!"},v.prototype.equal=function(t){for(var e=0;e<this.boxes.length&&e<t.boxes.length;){var r=this.boxes[e],n=t.boxes[e];if(!d.boxEqual(r,n))return!1;e++}return!0},r.ISOFile=v,v.prototype.lastBoxStartPosition=0,v.prototype.parsingMdat=null,v.prototype.nextParsePosition=0,v.prototype.discardMdatData=!1,v.prototype.processIncompleteBox=function(t){var e;return"mdat"===t.type?(e=new d[t.type+"Box"](t.size),this.parsingMdat=e,this.boxes.push(e),this.mdats.push(e),e.start=t.start,e.hdr_size=t.hdr_size,this.stream.addUsedBytes(e.hdr_size),this.lastBoxStartPosition=e.start+e.size,this.stream.seek(e.start+e.size,!1,this.discardMdatData))?(this.parsingMdat=null,!0):(this.moovStartFound?this.nextParsePosition=this.stream.findEndContiguousBuf():this.nextParsePosition=e.start+e.size,!1):("moov"===t.type&&(this.moovStartFound=!0,0===this.mdats.length&&(this.isProgressive=!0)),this.stream.mergeNextBuffer&&this.stream.mergeNextBuffer())?(this.nextParsePosition=this.stream.getEndPosition(),!0):(t.type?this.moovStartFound?this.nextParsePosition=this.stream.getEndPosition():this.nextParsePosition=this.stream.getPosition()+t.size:this.nextParsePosition=this.stream.getEndPosition(),!1)},v.prototype.hasIncompleteMdat=function(){return null!==this.parsingMdat},v.prototype.processIncompleteMdat=function(){var t;return(t=this.parsingMdat,this.stream.seek(t.start+t.size,!1,this.discardMdatData))?(l.debug("ISOFile","Found 'mdat' end in buffered data"),this.parsingMdat=null,!0):(this.nextParsePosition=this.stream.findEndContiguousBuf(),!1)},v.prototype.restoreParsePosition=function(){return this.stream.seek(this.lastBoxStartPosition,!0,this.discardMdatData)},v.prototype.saveParsePosition=function(){this.lastBoxStartPosition=this.stream.getPosition()},v.prototype.updateUsedBytes=function(t,e){this.stream.addUsedBytes&&("mdat"===t.type?(this.stream.addUsedBytes(t.hdr_size),this.discardMdatData&&this.stream.addUsedBytes(t.size-t.hdr_size)):this.stream.addUsedBytes(t.size))},v.prototype.add=d.Box.prototype.add,v.prototype.addBox=d.Box.prototype.addBox,v.prototype.init=function(t){var e=t||{};this.add("ftyp").set("major_brand",e.brands&&e.brands[0]||"iso4").set("minor_version",0).set("compatible_brands",e.brands||["iso4"]);var r=this.add("moov");return r.add("mvhd").set("timescale",e.timescale||600).set("rate",e.rate||65536).set("creation_time",0).set("modification_time",0).set("duration",e.duration||0).set("volume",256*!e.width).set("matrix",[65536,0,0,0,65536,0,0,0,0x40000000]).set("next_track_id",1),r.add("mvex"),this},v.prototype.addTrack=function(t){this.moov||this.init(t);var e=t||{};e.width=e.width||320,e.height=e.height||320,e.id=e.id||this.moov.mvhd.next_track_id,e.type=e.type||"avc1";var r=this.moov.add("trak");this.moov.mvhd.next_track_id=e.id+1,r.add("tkhd").set("flags",d.TKHD_FLAG_ENABLED|d.TKHD_FLAG_IN_MOVIE|d.TKHD_FLAG_IN_PREVIEW).set("creation_time",0).set("modification_time",0).set("track_id",e.id).set("duration",e.duration||0).set("layer",e.layer||0).set("alternate_group",0).set("volume",1).set("matrix",[65536,0,0,0,65536,0,0,0,0x40000000]).set("width",e.width<<16).set("height",e.height<<16);var n=r.add("mdia");n.add("mdhd").set("creation_time",0).set("modification_time",0).set("timescale",e.timescale||1).set("duration",e.media_duration||0).set("language",e.language||"und"),n.add("hdlr").set("handler",e.hdlr||"vide").set("name",e.name||"Track created with MP4Box.js"),n.add("elng").set("extended_language",e.language||"fr-FR");var s=n.add("minf");if(void 0!==d[e.type+"SampleEntry"]){var a=new d[e.type+"SampleEntry"];a.data_reference_index=1;var o="";for(var l in d.sampleEntryCodes)for(var c=d.sampleEntryCodes[l],h=0;h<c.length;h++)if(c.indexOf(e.type)>-1){o=l;break}switch(o){case"Visual":if(s.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),a.set("width",e.width).set("height",e.height).set("horizresolution",4718592).set("vertresolution",4718592).set("frame_count",1).set("compressorname",e.type+" Compressor").set("depth",24),e.avcDecoderConfigRecord){var f=new d.avcCBox;f.parse(new u(e.avcDecoderConfigRecord)),a.addBox(f)}else if(e.hevcDecoderConfigRecord){var p=new d.hvcCBox;p.parse(new u(e.hevcDecoderConfigRecord)),a.addBox(p)}break;case"Audio":s.add("smhd").set("balance",e.balance||0),a.set("channel_count",e.channel_count||2).set("samplesize",e.samplesize||16).set("samplerate",e.samplerate||65536);break;case"Hint":s.add("hmhd");break;case"Subtitle":s.add("sthd"),"stpp"===e.type&&a.set("namespace",e.namespace||"nonamespace").set("schema_location",e.schema_location||"").set("auxiliary_mime_types",e.auxiliary_mime_types||"");break;default:s.add("nmhd")}e.description&&a.addBox(e.description),e.description_boxes&&e.description_boxes.forEach(function(t){a.addBox(t)}),s.add("dinf").add("dref").addEntry(new d["url Box"]().set("flags",1));var _=s.add("stbl");return _.add("stsd").addEntry(a),_.add("stts").set("sample_counts",[]).set("sample_deltas",[]),_.add("stsc").set("first_chunk",[]).set("samples_per_chunk",[]).set("sample_description_index",[]),_.add("stco").set("chunk_offsets",[]),_.add("stsz").set("sample_sizes",[]),this.moov.mvex.add("trex").set("track_id",e.id).set("default_sample_description_index",e.default_sample_description_index||1).set("default_sample_duration",e.default_sample_duration||0).set("default_sample_size",e.default_sample_size||0).set("default_sample_flags",e.default_sample_flags||0),this.buildTrakSampleLists(r),e.id}},d.Box.prototype.computeSize=function(t){var e=t||new c;e.endianness=c.BIG_ENDIAN,this.write(e)},v.prototype.addSample=function(t,e,r){var n=r||{},s={},a=this.getTrackById(t);if(null!==a){s.number=a.samples.length,s.track_id=a.tkhd.track_id,s.timescale=a.mdia.mdhd.timescale,s.description_index=n.sample_description_index?n.sample_description_index-1:0,s.description=a.mdia.minf.stbl.stsd.entries[s.description_index],s.data=e,s.size=e.byteLength,s.alreadyRead=s.size,s.duration=n.duration||1,s.cts=n.cts||0,s.dts=n.dts||0,s.is_sync=n.is_sync||!1,s.is_leading=n.is_leading||0,s.depends_on=n.depends_on||0,s.is_depended_on=n.is_depended_on||0,s.has_redundancy=n.has_redundancy||0,s.degradation_priority=n.degradation_priority||0,s.offset=0,s.subsamples=n.subsamples,a.samples.push(s),a.samples_size+=s.size,a.samples_duration+=s.duration,void 0===a.first_dts&&(a.first_dts=n.dts),this.processSamples();var o=this.createSingleSampleMoof(s);return this.addBox(o),o.computeSize(),o.trafs[0].truns[0].data_offset=o.size+8,this.add("mdat").data=new Uint8Array(e),s}},v.prototype.createSingleSampleMoof=function(t){var e=0;e=t.is_sync?0x2000000:65536;var r=new d.moofBox;r.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var n=r.add("traf"),s=this.getTrackById(t.track_id);return n.add("tfhd").set("track_id",t.track_id).set("flags",d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),n.add("tfdt").set("baseMediaDecodeTime",t.dts-(s.first_dts||0)),n.add("trun").set("flags",d.TRUN_FLAGS_DATA_OFFSET|d.TRUN_FLAGS_DURATION|d.TRUN_FLAGS_SIZE|d.TRUN_FLAGS_FLAGS|d.TRUN_FLAGS_CTS_OFFSET).set("data_offset",0).set("first_sample_flags",0).set("sample_count",1).set("sample_duration",[t.duration]).set("sample_size",[t.size]).set("sample_flags",[e]).set("sample_composition_time_offset",[t.cts-t.dts]),r},v.prototype.lastMoofIndex=0,v.prototype.samplesDataSize=0,v.prototype.resetTables=function(){for(t=0,this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0;t<this.moov.traks.length;t++){(e=this.moov.traks[t]).tkhd.duration=0,e.mdia.mdhd.duration=0,(e.mdia.minf.stbl.stco||e.mdia.minf.stbl.co64).chunk_offsets=[],(r=e.mdia.minf.stbl.stsc).first_chunk=[],r.samples_per_chunk=[],r.sample_description_index=[],(e.mdia.minf.stbl.stsz||e.mdia.minf.stbl.stz2).sample_sizes=[],(n=e.mdia.minf.stbl.stts).sample_counts=[],n.sample_deltas=[],(s=e.mdia.minf.stbl.ctts)&&(s.sample_counts=[],s.sample_offsets=[]);var t,e,r,n,s,a=e.mdia.minf.stbl.stss,o=e.mdia.minf.stbl.boxes.indexOf(a);-1!=o&&(e.mdia.minf.stbl.boxes[o]=null)}},v.initSampleGroups=function(t,e,r,n,s){var a,o,l,u;function c(t,e,r){this.grouping_type=t,this.grouping_type_parameter=e,this.sbgp=r,this.last_sample_in_run=-1,this.entry_index=-1}for(e&&(e.sample_groups_info=[]),t.sample_groups_info||(t.sample_groups_info=[]),o=0;o<r.length;o++){for(u=r[o].grouping_type+"/"+r[o].grouping_type_parameter,l=new c(r[o].grouping_type,r[o].grouping_type_parameter,r[o]),e&&(e.sample_groups_info[u]=l),t.sample_groups_info[u]||(t.sample_groups_info[u]=l),a=0;a<n.length;a++)n[a].grouping_type===r[o].grouping_type&&(l.description=n[a],l.description.used=!0);if(s)for(a=0;a<s.length;a++)s[a].grouping_type===r[o].grouping_type&&(l.fragment_description=s[a],l.fragment_description.used=!0,l.is_fragment=!0)}if(e){if(s)for(o=0;o<s.length;o++)!s[o].used&&s[o].version>=2&&(u=s[o].grouping_type+"/0",(l=new c(s[o].grouping_type,0)).is_fragment=!0,e.sample_groups_info[u]||(e.sample_groups_info[u]=l))}else for(o=0;o<n.length;o++)!n[o].used&&n[o].version>=2&&(u=n[o].grouping_type+"/0",l=new c(n[o].grouping_type,0),t.sample_groups_info[u]||(t.sample_groups_info[u]=l))},v.setSampleGroupProperties=function(t,e,r,n){var s,a,o;for(s in e.sample_groups=[],n)e.sample_groups[s]={},e.sample_groups[s].grouping_type=n[s].grouping_type,e.sample_groups[s].grouping_type_parameter=n[s].grouping_type_parameter,r>=n[s].last_sample_in_run&&(n[s].last_sample_in_run<0&&(n[s].last_sample_in_run=0),n[s].entry_index++,n[s].entry_index<=n[s].sbgp.entries.length-1&&(n[s].last_sample_in_run+=n[s].sbgp.entries[n[s].entry_index].sample_count)),n[s].entry_index<=n[s].sbgp.entries.length-1?e.sample_groups[s].group_description_index=n[s].sbgp.entries[n[s].entry_index].group_description_index:e.sample_groups[s].group_description_index=-1,0!==e.sample_groups[s].group_description_index&&(o=n[s].fragment_description?n[s].fragment_description:n[s].description,e.sample_groups[s].group_description_index>0?(a=e.sample_groups[s].group_description_index>65535?(e.sample_groups[s].group_description_index>>16)-1:e.sample_groups[s].group_description_index-1,o&&a>=0&&(e.sample_groups[s].description=o.entries[a])):o&&o.version>=2&&o.default_group_description_index>0&&(e.sample_groups[s].description=o.entries[o.default_group_description_index-1]))},v.process_sdtp=function(t,e,r){e&&(t?(e.is_leading=t.is_leading[r],e.depends_on=t.sample_depends_on[r],e.is_depended_on=t.sample_is_depended_on[r],e.has_redundancy=t.sample_has_redundancy[r]):(e.is_leading=0,e.depends_on=0,e.is_depended_on=0,e.has_redundancy=0))},v.prototype.buildSampleLists=function(){var t,e;for(t=0;t<this.moov.traks.length;t++)e=this.moov.traks[t],this.buildTrakSampleLists(e)},v.prototype.buildTrakSampleLists=function(t){if(t.samples=[],t.samples_duration=0,t.samples_size=0,r=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64,n=t.mdia.minf.stbl.stsc,s=t.mdia.minf.stbl.stsz||t.mdia.minf.stbl.stz2,a=t.mdia.minf.stbl.stts,o=t.mdia.minf.stbl.ctts,l=t.mdia.minf.stbl.stss,u=t.mdia.minf.stbl.stsd,c=t.mdia.minf.stbl.subs,d=t.mdia.minf.stbl.stdp,h=t.mdia.minf.stbl.sbgps,f=t.mdia.minf.stbl.sgpds,b=-1,w=-1,S=-1,x=-1,U=0,E=0,k=0,v.initSampleGroups(t,null,h,f),void 0!==s){for(e=0;e<s.sample_sizes.length;e++){var e,r,n,s,a,o,l,u,c,h,f,d,p,_,m,y,g,b,w,S,x,U,E,k,A={};A.number=e,A.track_id=t.tkhd.track_id,A.timescale=t.mdia.mdhd.timescale,A.alreadyRead=0,t.samples[e]=A,A.size=s.sample_sizes[e],t.samples_size+=A.size,0===e?(p=0,A.chunk_index=_=1,A.chunk_run_index=p,g=n.samples_per_chunk[p],y=0,m=p+1<n.first_chunk.length?n.first_chunk[p+1]-1:1/0):e<g?(A.chunk_index=_,A.chunk_run_index=p):(A.chunk_index=++_,y=0,_<=m||(m=++p+1<n.first_chunk.length?n.first_chunk[p+1]-1:1/0),A.chunk_run_index=p,g+=n.samples_per_chunk[p]),A.description_index=n.sample_description_index[A.chunk_run_index]-1,A.description=u.entries[A.description_index],A.offset=r.chunk_offsets[A.chunk_index-1]+y,y+=A.size,e>b&&(w++,b<0&&(b=0),b+=a.sample_counts[w]),e>0?(t.samples[e-1].duration=a.sample_deltas[w],t.samples_duration+=t.samples[e-1].duration,A.dts=t.samples[e-1].dts+t.samples[e-1].duration):A.dts=0,o?(e>=S&&(x++,S<0&&(S=0),S+=o.sample_counts[x]),A.cts=t.samples[e].dts+o.sample_offsets[x]):A.cts=A.dts,l?(e==l.sample_numbers[U]-1?(A.is_sync=!0,U++):(A.is_sync=!1,A.degradation_priority=0),c&&c.entries[E].sample_delta+k==e+1&&(A.subsamples=c.entries[E].subsamples,k+=c.entries[E].sample_delta,E++)):A.is_sync=!0,v.process_sdtp(t.mdia.minf.stbl.sdtp,A,A.number),d?A.degradation_priority=d.priority[e]:A.degradation_priority=0,c&&c.entries[E].sample_delta+k==e&&(A.subsamples=c.entries[E].subsamples,k+=c.entries[E].sample_delta),(h.length>0||f.length>0)&&v.setSampleGroupProperties(t,A,e,t.sample_groups_info)}e>0&&(t.samples[e-1].duration=Math.max(t.mdia.mdhd.duration-t.samples[e-1].dts,0),t.samples_duration+=t.samples[e-1].duration)}},v.prototype.updateSampleLists=function(){if(void 0!==this.moov){for(;this.lastMoofIndex<this.moofs.length;)if(u=this.moofs[this.lastMoofIndex],this.lastMoofIndex++,"moof"==u.type)for(t=0;t<u.trafs.length;t++){for(c=u.trafs[t],null==(h=this.getTrackById(c.tfhd.track_id)).samples&&(h.samples=[]),f=this.getTrexById(c.tfhd.track_id),n=c.tfhd.flags&d.TFHD_FLAG_SAMPLE_DESC?c.tfhd.default_sample_description_index:f?f.default_sample_description_index:1,s=c.tfhd.flags&d.TFHD_FLAG_SAMPLE_DUR?c.tfhd.default_sample_duration:f?f.default_sample_duration:0,a=c.tfhd.flags&d.TFHD_FLAG_SAMPLE_SIZE?c.tfhd.default_sample_size:f?f.default_sample_size:0,o=c.tfhd.flags&d.TFHD_FLAG_SAMPLE_FLAGS?c.tfhd.default_sample_flags:f?f.default_sample_flags:0,c.sample_number=0,c.sbgps.length>0&&v.initSampleGroups(h,c,c.sbgps,h.mdia.minf.stbl.sgpds,c.sgpds),e=0;e<c.truns.length;e++){var t,e,r,n,s,a,o,l,u,c,h,f,p,_,m=c.truns[e];for(r=0;r<m.sample_count;r++){(p={}).moof_number=this.lastMoofIndex,p.number_in_traf=c.sample_number,c.sample_number++,p.number=h.samples.length,c.first_sample_index=h.samples.length,h.samples.push(p),p.track_id=h.tkhd.track_id,p.timescale=h.mdia.mdhd.timescale,p.description_index=n-1,p.description=h.mdia.minf.stbl.stsd.entries[p.description_index],p.size=a,m.flags&d.TRUN_FLAGS_SIZE&&(p.size=m.sample_size[r]),h.samples_size+=p.size,p.duration=s,m.flags&d.TRUN_FLAGS_DURATION&&(p.duration=m.sample_duration[r]),h.samples_duration+=p.duration,h.first_traf_merged||r>0?p.dts=h.samples[h.samples.length-2].dts+h.samples[h.samples.length-2].duration:(c.tfdt?p.dts=c.tfdt.baseMediaDecodeTime:p.dts=0,h.first_traf_merged=!0),p.cts=p.dts,m.flags&d.TRUN_FLAGS_CTS_OFFSET&&(p.cts=p.dts+m.sample_composition_time_offset[r]),_=o,m.flags&d.TRUN_FLAGS_FLAGS?_=m.sample_flags[r]:0===r&&m.flags&d.TRUN_FLAGS_FIRST_FLAG&&(_=m.first_sample_flags),p.is_sync=!(_>>16&1),p.is_leading=_>>26&3,p.depends_on=_>>24&3,p.is_depended_on=_>>22&3,p.has_redundancy=_>>20&3,p.degradation_priority=65535&_;var y=!!(c.tfhd.flags&d.TFHD_FLAG_BASE_DATA_OFFSET),g=!!(c.tfhd.flags&d.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),b=!!(m.flags&d.TRUN_FLAGS_DATA_OFFSET),w=0;w=y?c.tfhd.base_data_offset:g||0===e?u.start:l,0===e&&0===r?b?p.offset=w+m.data_offset:p.offset=w:p.offset=l,l=p.offset+p.size,(c.sbgps.length>0||c.sgpds.length>0||h.mdia.minf.stbl.sbgps.length>0||h.mdia.minf.stbl.sgpds.length>0)&&v.setSampleGroupProperties(h,p,p.number_in_traf,c.sample_groups_info)}}if(c.subs){h.has_fragment_subsamples=!0;var S=c.first_sample_index;for(e=0;e<c.subs.entries.length;e++)S+=c.subs.entries[e].sample_delta,(p=h.samples[S-1]).subsamples=c.subs.entries[e].subsamples}}}},v.prototype.getSample=function(t,e){var r,n=t.samples[e];if(!this.moov)return null;if(n.data){if(n.alreadyRead==n.size)return n}else n.data=new Uint8Array(n.size),n.alreadyRead=0,this.samplesDataSize+=n.size,l.debug("ISOFile","Allocating sample #"+e+" on track #"+t.tkhd.track_id+" of size "+n.size+" (total: "+this.samplesDataSize+")");for(;;){var s=this.stream.findPosition(!0,n.offset+n.alreadyRead,!1);if(!(s>-1))return null;var a=(r=this.stream.buffers[s]).byteLength-(n.offset+n.alreadyRead-r.fileStart);if(n.size-n.alreadyRead<=a)return l.debug("ISOFile","Getting sample #"+e+" data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-r.fileStart)+" read size: "+(n.size-n.alreadyRead)+" full size: "+n.size+")"),c.memcpy(n.data.buffer,n.alreadyRead,r,n.offset+n.alreadyRead-r.fileStart,n.size-n.alreadyRead),r.usedBytes+=n.size-n.alreadyRead,this.stream.logBufferLevel(),n.alreadyRead=n.size,n;if(0===a)return null;l.debug("ISOFile","Getting sample #"+e+" partial data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-r.fileStart)+" read size: "+a+" full size: "+n.size+")"),c.memcpy(n.data.buffer,n.alreadyRead,r,n.offset+n.alreadyRead-r.fileStart,a),n.alreadyRead+=a,r.usedBytes+=a,this.stream.logBufferLevel()}},v.prototype.releaseSample=function(t,e){var r=t.samples[e];return r.data?(this.samplesDataSize-=r.size,r.data=null,r.alreadyRead=0,r.size):0},v.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},v.prototype.getCodecs=function(){var t,e="";for(t=0;t<this.moov.traks.length;t++){var r=this.moov.traks[t];t>0&&(e+=","),e+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return e},v.prototype.getTrexById=function(t){var e;if(!this.moov||!this.moov.mvex)return null;for(e=0;e<this.moov.mvex.trexs.length;e++){var r=this.moov.mvex.trexs[e];if(r.track_id==t)return r}return null},v.prototype.getTrackById=function(t){if(void 0===this.moov)return null;for(var e=0;e<this.moov.traks.length;e++){var r=this.moov.traks[e];if(r.tkhd.track_id==t)return r}return null},v.prototype.items=[],v.prototype.entity_groups=[],v.prototype.itemsDataSize=0,v.prototype.flattenItemInfo=function(){var t,e,r,n=this.items,s=this.entity_groups,a=this.meta;if(null!=a&&void 0!==a.hdlr&&void 0!==a.iinf){for(t=0;t<a.iinf.item_infos.length;t++)(r={}).id=a.iinf.item_infos[t].item_ID,n[r.id]=r,r.ref_to=[],r.name=a.iinf.item_infos[t].item_name,a.iinf.item_infos[t].protection_index>0&&(r.protection=a.ipro.protections[a.iinf.item_infos[t].protection_index-1]),a.iinf.item_infos[t].item_type?r.type=a.iinf.item_infos[t].item_type:r.type="mime",r.content_type=a.iinf.item_infos[t].content_type,r.content_encoding=a.iinf.item_infos[t].content_encoding;if(a.grpl)for(t=0;t<a.grpl.boxes.length;t++)(entity_group={}).id=a.grpl.boxes[t].group_id,entity_group.entity_ids=a.grpl.boxes[t].entity_ids,entity_group.type=a.grpl.boxes[t].type,s[entity_group.id]=entity_group;if(a.iloc)for(t=0;t<a.iloc.items.length;t++){var o=a.iloc.items[t];switch(r=n[o.item_ID],0!==o.data_reference_index&&(l.warn("Item storage with reference to other files: not supported"),r.source=a.dinf.boxes[o.data_reference_index-1]),o.construction_method){case 0:break;case 1:case 2:l.warn("Item storage with construction_method : not supported")}for(e=0,r.extents=[],r.size=0;e<o.extents.length;e++)r.extents[e]={},r.extents[e].offset=o.extents[e].extent_offset+o.base_offset,r.extents[e].length=o.extents[e].extent_length,r.extents[e].alreadyRead=0,r.size+=r.extents[e].length}if(a.pitm&&(n[a.pitm.item_id].primary=!0),a.iref)for(t=0;t<a.iref.references.length;t++){var u=a.iref.references[t];for(e=0;e<u.references.length;e++)n[u.from_item_ID].ref_to.push({type:u.type,id:u.references[e]})}if(a.iprp)for(var c=0;c<a.iprp.ipmas.length;c++){var h=a.iprp.ipmas[c];for(t=0;t<h.associations.length;t++){var f=h.associations[t];if((r=n[f.id])||(r=s[f.id]),r)for(void 0===r.properties&&(r.properties={},r.properties.boxes=[]),e=0;e<f.props.length;e++){var d=f.props[e];if(d.property_index>0&&d.property_index-1<a.iprp.ipco.boxes.length){var p=a.iprp.ipco.boxes[d.property_index-1];r.properties[p.type]=p,r.properties.boxes.push(p)}}}}}},v.prototype.getItem=function(t){if(!this.meta)return null;if(!(r=this.items[t]).data&&r.size)r.data=new Uint8Array(r.size),r.alreadyRead=0,this.itemsDataSize+=r.size,l.debug("ISOFile","Allocating item #"+t+" of size "+r.size+" (total: "+this.itemsDataSize+")");else if(r.alreadyRead===r.size)return r;for(var e,r,n=0;n<r.extents.length;n++){var s=r.extents[n];if(s.alreadyRead!==s.length){var a=this.stream.findPosition(!0,s.offset+s.alreadyRead,!1);if(!(a>-1))return null;var o=(e=this.stream.buffers[a]).byteLength-(s.offset+s.alreadyRead-e.fileStart);if(!(s.length-s.alreadyRead<=o))return l.debug("ISOFile","Getting item #"+t+" extent #"+n+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-e.fileStart)+" read size: "+o+" full extent size: "+s.length+" full item size: "+r.size+")"),c.memcpy(r.data.buffer,r.alreadyRead,e,s.offset+s.alreadyRead-e.fileStart,o),s.alreadyRead+=o,r.alreadyRead+=o,e.usedBytes+=o,this.stream.logBufferLevel(),null;l.debug("ISOFile","Getting item #"+t+" extent #"+n+" data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-e.fileStart)+" read size: "+(s.length-s.alreadyRead)+" full extent size: "+s.length+" full item size: "+r.size+")"),c.memcpy(r.data.buffer,r.alreadyRead,e,s.offset+s.alreadyRead-e.fileStart,s.length-s.alreadyRead),e.usedBytes+=s.length-s.alreadyRead,this.stream.logBufferLevel(),r.alreadyRead+=s.length-s.alreadyRead,s.alreadyRead=s.length}}return r.alreadyRead===r.size?r:null},v.prototype.releaseItem=function(t){var e=this.items[t];if(!e.data)return 0;this.itemsDataSize-=e.size,e.data=null,e.alreadyRead=0;for(var r=0;r<e.extents.length;r++)e.extents[r].alreadyRead=0;return e.size},v.prototype.processItems=function(t){for(var e in this.items){var r=this.items[e];this.getItem(r.id),t&&!r.sent&&(t(r),r.sent=!0,r.data=null)}},v.prototype.hasItem=function(t){for(var e in this.items){var r=this.items[e];if(r.name===t)return r.id}return -1},v.prototype.getMetaHandler=function(){return this.meta?this.meta.hdlr.handler:null},v.prototype.getPrimaryItem=function(){return this.meta&&this.meta.pitm?this.getItem(this.meta.pitm.item_id):null},v.prototype.itemToFragmentedTrackFile=function(t){var e=t||{},r=null;if(null==(r=e.itemId?this.getItem(e.itemId):this.getPrimaryItem()))return null;var n=new v;n.discardMdatData=!1;var s={type:r.type,description_boxes:r.properties.boxes};r.properties.ispe&&(s.width=r.properties.ispe.image_width,s.height=r.properties.ispe.image_height);var a=n.addTrack(s);return a?(n.addSample(a,r.data),n):null},v.prototype.write=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t)},v.prototype.createFragment=function(t,e,r){var n=this.getTrackById(t),s=this.getSample(n,e);if(null==s)return this.setNextSeekPositionFromSample(n.samples[e]),null;var a=r||new c;a.endianness=c.BIG_ENDIAN;var o=this.createSingleSampleMoof(s);o.write(a),o.trafs[0].truns[0].data_offset=o.size+8,l.debug("MP4Box","Adjusting data_offset with new value "+o.trafs[0].truns[0].data_offset),a.adjustUint32(o.trafs[0].truns[0].data_offset_position,o.trafs[0].truns[0].data_offset);var u=new d.mdatBox;return u.data=s.data,u.write(a),a},v.writeInitializationSegment=function(t,e,r,n){l.debug("ISOFile","Generating initialization segment");var s,a=new c;a.endianness=c.BIG_ENDIAN,t.write(a);var o=e.add("mvex");for(r&&o.add("mehd").set("fragment_duration",r),s=0;s<e.traks.length;s++)o.add("trex").set("track_id",e.traks[s].tkhd.track_id).set("default_sample_description_index",1).set("default_sample_duration",n).set("default_sample_size",0).set("default_sample_flags",65536);return e.write(a),a.buffer},v.prototype.save=function(t){var e=new c;e.endianness=c.BIG_ENDIAN,this.write(e),e.save(t)},v.prototype.getBuffer=function(){var t=new c;return t.endianness=c.BIG_ENDIAN,this.write(t),t.buffer},v.prototype.initializeSegmentation=function(){for(null===this.onSegment&&l.warn("MP4Box","No segmentation callback set!"),this.isFragmentationInitialized||(this.isFragmentationInitialized=!0,this.nextMoofNumber=0,this.resetTables()),e=[],t=0;t<this.fragmentedTracks.length;t++){var t,e,r,n,s=new d.moovBox;s.mvhd=this.moov.mvhd,s.boxes.push(s.mvhd),r=this.getTrackById(this.fragmentedTracks[t].id),s.boxes.push(r),s.traks.push(r),(n={}).id=r.tkhd.track_id,n.user=this.fragmentedTracks[t].user,n.buffer=v.writeInitializationSegment(this.ftyp,s,this.moov.mvex&&this.moov.mvex.mehd?this.moov.mvex.mehd.fragment_duration:void 0,this.moov.traks[t].samples.length>0?this.moov.traks[t].samples[0].duration:0),e.push(n)}return e},d.Box.prototype.printHeader=function(t){this.size+=8,this.size>0x100000000&&(this.size+=8),"uuid"===this.type&&(this.size+=16),t.log(t.indent+"size:"+this.size),t.log(t.indent+"type:"+this.type)},d.FullBox.prototype.printHeader=function(t){this.size+=4,d.Box.prototype.printHeader.call(this,t),t.log(t.indent+"version:"+this.version),t.log(t.indent+"flags:"+this.flags)},d.Box.prototype.print=function(t){this.printHeader(t)},d.ContainerBox.prototype.print=function(t){this.printHeader(t);for(var e=0;e<this.boxes.length;e++)if(this.boxes[e]){var r=t.indent;t.indent+=" ",this.boxes[e].print(t),t.indent=r}},v.prototype.print=function(t){t.indent="";for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&this.boxes[e].print(t)},d.mvhdBox.prototype.print=function(t){d.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"timescale: "+this.timescale),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"rate: "+this.rate),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"next_track_id: "+this.next_track_id)},d.tkhdBox.prototype.print=function(t){d.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"track_id: "+this.track_id),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"layer: "+this.layer),t.log(t.indent+"alternate_group: "+this.alternate_group),t.log(t.indent+"width: "+this.width),t.log(t.indent+"height: "+this.height)};var b={};b.createFile=function(t,e){var r=new v(e);return r.discardMdatData=!(void 0===t||t),r},r.createFile=b.createFile},{"@swc/helpers/cjs/_type_of.cjs":"iXhRw"}],bA9PQ:[function(t,e,r,n){var s,a,o=t("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"EventTool",function(){return U}),o.export(r,"Log",function(){return j}),o.export(r,"autoReadStream",function(){return C}),o.export(r,"file2stream",function(){return I}),o.export(r,"recodemux",function(){return N}),o.export(r,"workerTimer",function(){return T});var l=t("@swc/helpers/cjs/_async_to_generator.cjs"),u=t("@swc/helpers/cjs/_class_call_check.cjs"),c=t("@swc/helpers/cjs/_create_class.cjs"),h=t("@swc/helpers/cjs/_define_property.cjs"),f=t("@swc/helpers/cjs/_object_spread.cjs"),d=t("@swc/helpers/cjs/_object_spread_props.cjs"),p=t("@swc/helpers/cjs/_sliced_to_array.cjs"),_=t("@swc/helpers/cjs/_to_consumable_array.cjs"),m=t("@swc/helpers/cjs/_type_of.cjs"),y=t("@swc/helpers/cjs/_ts_generator.cjs"),g=t("@webav/mp4box.js"),v=o.interopDefault(g),b=Object.defineProperty,w=function(t){throw TypeError(t)},S=function(t,e,r){var n;return n=(void 0===e?"undefined":(0,m._)(e))!="symbol"?e+"":e,n in t?b(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r},x=function(t,e,r){return e.has(t)||w("Cannot read from private field"),r?r.call(t):e.get(t)},U=function(){"use strict";function t(){var e,r,n=this,s=this;(0,u._)(this,t),e=a,r=new Map,e.has(this)?w("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(this):e.set(this,r),S(this,"on",function(t,e){var r,s=null!=(r=x(n,a).get(t))?r:new Set;return s.add(e),x(n,a).has(t)||x(n,a).set(t,s),function(){s.delete(e),0===s.size&&x(n,a).delete(t)}}),S(this,"once",function(t,e){var r=n.on(t,function(){for(var t=arguments.length,n=Array(t),s=0;s<t;s++)n[s]=arguments[s];r(),e.apply(void 0,(0,_._)(n))});return r}),S(this,"emit",function(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];var o=x(s,a).get(t);null!=o&&o.forEach(function(t){return t.apply(void 0,(0,_._)(r))})})}return(0,c._)(t,[{key:"destroy",value:function(){x(this,a).clear()}}],[{key:"forwardEvent",value:function(t,e,r){var n=r.map(function(r){var n=(0,p._)(Array.isArray(r)?r:[r,r],2),s=n[0],a=n[1];return t.on(s,function(){for(var t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];e.emit.apply(e,[a].concat((0,_._)(r)))})});return function(){n.forEach(function(t){return t()})}}}]),t}();a=new WeakMap;var E=new Map,k=1,A=null;null!=globalThis.Worker&&(s=new Blob(["(".concat((function(){var t;self.onmessage=function(e){"start"===e.data.event&&(self.clearInterval(t),t=self.setInterval(function(){self.postMessage({})},16.6)),"stop"===e.data.event&&self.clearInterval(t)}}).toString(),")()")]),(A=new Worker(URL.createObjectURL(s))).onmessage=function(){k+=1;var t=!0,e=!1,r=void 0,n=!0,s=!1,a=void 0;try{for(var o,l=E[Symbol.iterator]();!(n=(o=l.next()).done);n=!0){var u=(0,p._)(o.value,2),c=u[0],h=u[1];if(k%c==0)try{for(var f,d=h[Symbol.iterator]();!(t=(f=d.next()).done);t=!0)(0,f.value)()}catch(t){e=!0,r=t}finally{try{t||null==d.return||d.return()}finally{if(e)throw r}}}}catch(t){s=!0,a=t}finally{try{n||null==l.return||l.return()}finally{if(s)throw a}}});var T=function(t,e){var r,n=Math.round(e/16.6),s=null!=(r=E.get(n))?r:new Set;return s.add(t),E.set(n,s),1===E.size&&1===s.size&&(null==A||A.postMessage({event:"start"})),function(){s.delete(t),0===s.size&&E.delete(n),0===E.size&&(k=0,null==A||A.postMessage({event:"stop"}))}};function C(t,e){var r=!1;function n(){return(n=(0,l._)(function(){var n,s,a;return(0,y._)(this,function(o){switch(o.label){case 0:n=t.getReader(),o.label=1;case 1:if(r)return[3,5];return[4,n.read()];case 2:if(a=(s=o.sent()).value,s.done)return e.onDone(),[2];return[4,e.onChunk(a)];case 3:o.sent(),o.label=4;case 4:return[3,1];case 5:return n.releaseLock(),[4,t.cancel()];case 6:return o.sent(),[2]}})})).apply(this,arguments)}return(function(){return n.apply(this,arguments)})().catch(console.error),function(){r=!0}}function I(t,e,r){var n=0,s=0,a=t.boxes,o=!1,l=function(){if(!o)if(null==a.find(function(t){return"moof"===t.type}))return null;else o=!0;if(s>=a.length)return null;var e=new v.default.DataStream;e.endianness=v.default.DataStream.BIG_ENDIAN;var r=s;try{for(;r<a.length;)a[r].write(e),delete a[r],r+=1}catch(t){var n,l,u=a[r];throw t instanceof Error&&null!=u?Error("".concat(t.message," | deltaBuf( boxType: ").concat(u.type,", boxSize: ").concat(u.size,", boxDataLen: ").concat(null!=(l=null==(n=u.data)?void 0:n.length)?l:-1,")")):t}return function(t){if(null!=t.moov){for(var e=0;e<t.moov.traks.length;e++)t.moov.traks[e].samples=[];t.mdats=[],t.moofs=[]}}(t),s=a.length,new Uint8Array(e.buffer)},u=!1,c=!1,h=null;return{stream:new ReadableStream({start:function(r){n=self.setInterval(function(){var t=l();null==t||c||r.enqueue(t)},e),h=function(e){if(clearInterval(n),t.flush(),null!=e)return void r.error(e);var s=l();null==s||c||r.enqueue(s),c||r.close()},u&&h()},cancel:function(){c=!0,clearInterval(n),null==r||r()}}),stop:function(t){u||(u=!0,null==h||h(t))}}}var B=function(t,e){var r=new Uint8Array(8);new DataView(r.buffer).setUint32(0,e);for(var n=0;n<4;n++)r[4+n]=t.charCodeAt(n);return r},z=function(){var t=new TextEncoder,e=t.encode("mdta"),r=t.encode("mp4 handler"),n=32+r.byteLength+1,s=new Uint8Array(n),a=new DataView(s.buffer);return s.set(B("hdlr",n),0),a.setUint32(8,0),s.set(e,16),s.set(r,32),s},F=function(t){var e=new TextEncoder,r=e.encode("mdta"),n=t.map(function(t){var n=e.encode(t),s=8+n.byteLength,a=new Uint8Array(s);return new DataView(a.buffer).setUint32(0,s),a.set(r,4),a.set(n,4+r.byteLength),a}),s=16+n.reduce(function(t,e){return t+e.byteLength},0),a=new Uint8Array(s),o=new DataView(a.buffer);a.set(B("keys",s),0),o.setUint32(8,0),o.setUint32(12,t.length);var l=16,u=!0,c=!1,h=void 0;try{for(var f,d=n[Symbol.iterator]();!(u=(f=d.next()).done);u=!0){var p=f.value;a.set(p,l),l+=p.byteLength}}catch(t){c=!0,h=t}finally{try{u||null==d.return||d.return()}finally{if(c)throw h}}return a},P=function(t){var e=new TextEncoder,r=e.encode("data"),n=Object.entries(t).map(function(t,n){var s=(0,p._)(t,2),a=(s[0],s[1]),o=e.encode(a),l=24+o.byteLength,u=new Uint8Array(l),c=new DataView(u.buffer);return c.setUint32(0,l),c.setUint32(4,n+1),c.setUint32(8,16+o.byteLength),u.set(r,12),c.setUint32(16,1),u.set(o,24),u}),s=8+n.reduce(function(t,e){return t+e.byteLength},0),a=new Uint8Array(s);a.set(B("ilst",s),0);var o=8,l=!0,u=!1,c=void 0;try{for(var h,f=n[Symbol.iterator]();!(l=(h=f.next()).done);l=!0){var d=h.value;a.set(d,o),o+=d.byteLength}}catch(t){u=!0,c=t}finally{try{l||null==f.return||f.return()}finally{if(u)throw c}}return a},L=function(t){var e=z(),r=F(Object.keys(t)),n=P(t),s=new Uint8Array(e.length+r.length+n.length);return s.set(e,0),s.set(r,e.length),s.set(n,e.length+r.length),s},R=1,M=[],O=["debug","info","warn","error"].reduce(function(t,e,r){return Object.assign(t,(0,h._)({},e,function(){for(var t,n,s=arguments.length,a=Array(s),o=0;o<s;o++)a[o]=arguments[o];R<=r&&((n=console)[e].apply(n,(0,_._)(a)),M.push({lvName:e,timeStr:(t=new Date,"".concat(t.getHours(),":").concat(t.getMinutes(),":").concat(t.getSeconds(),".").concat(t.getMilliseconds())),args:a}))}))},{}),D=new Map,j=(0,d._)((0,f._)({setLogLevel:function(t){var e;R=null!=(e=D.get(t))?e:1}},O),{create:function(t){return Object.fromEntries(Object.entries(O).map(function(e){var r=(0,p._)(e,2),n=r[0],s=r[1];return[n,function(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];return s.apply(void 0,[t].concat((0,_._)(r)))}]}))},dump:function(){return(0,l._)(function(){return(0,y._)(this,function(t){return[2,M.reduce(function(t,e){var r=e.lvName,n=e.timeStr,s=e.args;return t+"[".concat(r,"][").concat(n,"] ").concat(s.map(function(t){return t instanceof Error?String(t):(void 0===t?"undefined":(0,m._)(t))=="object"?JSON.stringify(t,function(t,e){return e instanceof Error?String(e):e}):String(t)}).join(" "),"\n")},"")]})})()}});function N(t){j.info("recodemux opts:",t);var e,r,n,s,a,o,u,c,h,p=v.default.createFile(),m=new U,g=function(t,e){var r=t.add("udta").add("meta");r.data=L(e),r.size=r.data.byteLength},b=!1,w=function(){null==p.moov||b||(b=!0,null!=t.metaDataTags&&g(p.moov,t.metaDataTags),null!=t.duration&&(p.moov.mvhd.duration=t.duration))};m.once("VideoReady",w),m.once("AudioReady",w);var S=null!=t.video?function(t,e,r){var n={timescale:1e6,width:t.width,height:t.height,brands:["isom","iso2","avc1","mp42","mp41"],avcDecoderConfigRecord:null,name:"Track created with WebAV"},s=-1,a=!1;r.once("AudioReady",function(){a=!0});var o={encoder0:[],encoder1:[]},u=function(t,a,l){var u;if(-1===s&&null!=l){var c,h=null==(u=l.decoderConfig)?void 0:u.description;(c=new Uint8Array(h))[2].toString(2).slice(-2).includes("1")&&(c[2]=0),n.avcDecoderConfigRecord=h,s=e.addTrack(n),r.emit("VideoReady"),j.info("VideoEncoder, video track ready, trackId:",s)}o[t].push(W(a))},c="encoder1",h=0,f=Math.floor(1e3/t.expectFPS*1e3);function d(){if(a){var t="encoder1"===c?"encoder0":"encoder1",e=o[c],r=o[t];if(0!==e.length||0!==r.length){var n=e[0];if(null!=n&&(!n.is_sync||n.cts-h<f)){var s=p(e);s>h&&(h=s)}var l=r[0];if(null!=l&&l.is_sync&&l.cts-h<f){c=t,d();return}if(null!=n&&n.is_sync&&null!=l&&l.is_sync)if(n.cts<=l.cts){var u=p(e);u>h&&(h=u)}else{c=t,d();return}}}}function p(t){for(var r=-1,n=0;n<t.length;n++){var a=t[n];if(n>0&&a.is_sync)break;e.addSample(s,a.data,a),r=a.cts+a.duration}return t.splice(0,n),r}var _=T(d,15),m=G(t,function(t,e){return u("encoder0",t,e)}),g=G(t,function(t,e){return u("encoder1",t,e)}),v=0;return{get encodeQueueSize(){return m.encodeQueueSize+g.encodeQueueSize},encode:function(t,e){try{e.keyFrame&&(v+=1),(v%2==0?m:g).encode(t,e)}catch(n){var r="encode video frame error: ".concat(n.message,", state: ").concat(JSON.stringify({ts:t.timestamp,keyFrame:e.keyFrame,duration:t.duration,gopId:v}));throw j.error(r),Error(r)}},flush:(0,l._)(function(){var t,e,r,n;return(0,y._)(this,function(s){switch(s.label){case 0:if(t=Promise.all,"configured"!==m.state)return[3,2];return[4,m.flush()];case 1:return e=s.sent(),[3,3];case 2:e=null,s.label=3;case 3:if(r=[e],"configured"!==g.state)return[3,5];return[4,g.flush()];case 4:return n=s.sent(),[3,6];case 5:n=null,s.label=6;case 6:return[4,t.apply(Promise,[r.concat([n])])];case 7:return s.sent(),_(),d(),[2]}})}),close:function(){"configured"===m.state&&m.close(),"configured"===g.state&&g.close()}}}(t.video,p,m):null,x=null!=t.audio?(e=t.audio,r=p,n=m,s={timescale:1e6,samplerate:e.sampleRate,channel_count:e.channelCount,hdlr:"soun",type:"aac"===e.codec?"mp4a":"Opus",name:"Track created with WebAV"},a=-1,o=[],u=!1,n.once("VideoReady",function(){u=!0,o.forEach(function(t){var e=W(t);r.addSample(a,e.data,e)}),o=[]}),c={codec:"aac"===e.codec?"mp4a.40.2":"opus",sampleRate:e.sampleRate,numberOfChannels:e.channelCount,bitrate:128e3},(h=new AudioEncoder({error:function(t){var e="AudioEncoder error: ".concat(t.message,", config: ").concat(JSON.stringify(c),", state: ").concat(JSON.stringify({qSize:h.encodeQueueSize,state:h.state}));throw j.error(e),Error(e)},output:function(t,e){var l;if(-1===a){var c,h,p,m,y=null==(l=e.decoderConfig)?void 0:l.description;a=r.addTrack((0,d._)((0,f._)({},s),{description:null==y?void 0:(p=new Uint8Array([0,0,0,0,3,23+(h=(c=y).byteLength),0,2,0,4,18+h,64,21,0,0,0,0,0,0,0,0,0,0,0,5,h].concat((0,_._)(new Uint8Array(c instanceof ArrayBuffer?c:c.buffer)),[6,1,2])),(m=new v.default.BoxParser.esdsBox(p.byteLength)).hdr_size=0,m.parse(new v.default.DataStream(p,0,v.default.DataStream.BIG_ENDIAN)),m)})),n.emit("AudioReady"),j.info("AudioEncoder, audio track ready, trackId:",a)}if(u){var g=W(t);r.addSample(a,g.data,g)}else o.push(t)}})).configure(c),h):null;return null==t.video&&m.emit("VideoReady"),null==t.audio&&m.emit("AudioReady"),{encodeVideo:function(t,e){null==S||S.encode(t,e),t.close()},encodeAudio:function(t){if(null!=x)try{x.encode(t),t.close()}catch(t){var e="encode audio chunk error: ".concat(t.message,", state: ").concat(JSON.stringify({qSize:x.encodeQueueSize,state:x.state}));throw j.error(e),Error(e)}},getEncodeQueueSize:function(){var t,e;return null!=(e=null!=(t=null==S?void 0:S.encodeQueueSize)?t:null==x?void 0:x.encodeQueueSize)?e:0},flush:(0,l._)(function(){return(0,y._)(this,function(t){switch(t.label){case 0:return[4,Promise.all([null==S?void 0:S.flush(),(null==x?void 0:x.state)==="configured"?x.flush():null])];case 1:return t.sent(),[2]}})}),close:function(){m.destroy(),null==S||S.close(),(null==x?void 0:x.state)==="configured"&&x.close()},mp4file:p}}function G(t,e){var r={codec:t.codec,framerate:t.expectFPS,hardwareAcceleration:t.__unsafe_hardwareAcceleration__,bitrate:t.bitrate,width:t.width,height:t.height,alpha:"discard",avc:{format:"avc"}},n=new VideoEncoder({error:function(t){var e="VideoEncoder error: ".concat(t.message,", config: ").concat(JSON.stringify(r),", state: ").concat(JSON.stringify({qSize:n.encodeQueueSize,state:n.state}));throw j.error(e),Error(e)},output:e});return n.configure(r),n}function W(t){var e,r=new ArrayBuffer(t.byteLength);t.copyTo(r);var n=t.timestamp;return{duration:null!=(e=t.duration)?e:0,dts:n,cts:n,is_sync:"key"===t.type,data:r}}D.set(j.debug,0),D.set(j.info,1),D.set(j.warn,2),D.set(j.error,3),(0,l._)(function(){return(0,y._)(this,function(t){switch(t.label){case 0:return[4,Promise.resolve()];case 1:return t.sent(),null!=globalThis.navigator&&null!=globalThis.document&&(j.info("@webav version: 1.1.0, date: ".concat(new Date().toLocaleDateString())),j.info(globalThis.navigator.userAgent),document.addEventListener("visibilitychange",function(){j.info("visibilitychange: ".concat(document.visibilityState))}),"PressureObserver"in globalThis&&new PressureObserver(function(t){j.info("cpu state change: ".concat(JSON.stringify(t.map(function(t){return t.state}))))}).observe("cpu")),[2]}})})()},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_class_call_check.cjs":"4Uf9M","@swc/helpers/cjs/_create_class.cjs":"igUuK","@swc/helpers/cjs/_define_property.cjs":"ltU3W","@swc/helpers/cjs/_object_spread.cjs":"kyoEj","@swc/helpers/cjs/_object_spread_props.cjs":"3G1wX","@swc/helpers/cjs/_sliced_to_array.cjs":"gIQTH","@swc/helpers/cjs/_to_consumable_array.cjs":"i81N6","@swc/helpers/cjs/_type_of.cjs":"iXhRw","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@webav/mp4box.js":"9QpMm","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],asu2z:[function(t,e,r,n){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"resample",function(){return f});var a=t("./lib/interpolator"),o=t("./lib/fir-lpf"),l=t("./lib/butterworth-lpf"),u={point:!1,linear:!1,cubic:!0,sinc:!0},c={IIR:16,FIR:71},h={IIR:l.ButterworthLPF,FIR:o.FIRLPF};function f(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=(r-e)/e+1,o=new Float64Array(t.length*s);n.method=n.method||"cubic";var l=new(0,a.Interpolator)(t.length,o.length,{method:n.method,tension:n.tension||0,sincFilterSize:n.sincFilterSize||6,sincWindow:n.sincWindow||void 0});if(void 0===n.LPF&&(n.LPF=u[n.method]),n.LPF){n.LPFType=n.LPFType||"IIR";var f=h[n.LPFType];r>e?function(t,e,r,n){for(var s=0,a=e.length;s<a;s++)e[s]=n.filter(r.interpolate(s,t));n.reset();for(var o=e.length-1;o>=0;o--)e[o]=n.filter(e[o])}(t,o,l,new f(n.LPFOrder||c[n.LPFType],r,e/2)):function(t,e,r,n){for(var s=0,a=t.length;s<a;s++)t[s]=n.filter(t[s]);n.reset();for(var o=t.length-1;o>=0;o--)t[o]=n.filter(t[o]);d(t,e,r)}(t,o,l,new f(n.LPFOrder||c[n.LPFType],e,r/2))}else d(t,o,l);return o}function d(t,e,r){for(var n=0,s=e.length;n<s;n++)e[n]=r.interpolate(n,t)}},{"./lib/interpolator":"hVO3X","./lib/fir-lpf":"4eVTq","./lib/butterworth-lpf":"hfRca","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],hVO3X:[function(t,e,r,n){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"Interpolator",function(){return l});var a=t("@swc/helpers/cjs/_class_call_check.cjs"),o=t("@swc/helpers/cjs/_create_class.cjs"),l=function(){"use strict";function t(e,r,n){var s;(0,a._)(this,t),this.length_=e,this.scaleFactor_=(e-1)/r,this.interpolate=this.cubic,"point"===n.method?this.interpolate=this.point:"linear"===n.method?this.interpolate=this.linear:"sinc"===n.method&&(this.interpolate=this.sinc),this.tangentFactor_=1-Math.max(0,Math.min(1,n.tension||0)),this.sincFilterSize_=n.sincFilterSize||1,this.kernel_=(s=n.sincWindow||u,function(t){var e;return(0===(e=t)?1:Math.sin(Math.PI*e)/(Math.PI*e))*s(t)})}return(0,o._)(t,[{key:"point",value:function(t,e){return this.getClippedInput_(Math.round(this.scaleFactor_*t),e)}},{key:"linear",value:function(t,e){var r=Math.floor(t=this.scaleFactor_*t);return(1-(t-=r))*this.getClippedInput_(r,e)+t*this.getClippedInput_(r+1,e)}},{key:"cubic",value:function(t,e){var r=Math.floor(t=this.scaleFactor_*t),n=[this.getTangent_(r,e),this.getTangent_(r+1,e)],s=[this.getClippedInput_(r,e),this.getClippedInput_(r+1,e)],a=(t-=r)*t,o=t*a;return(2*o-3*a+1)*s[0]+(o-2*a+t)*n[0]+(-2*o+3*a)*s[1]+(o-a)*n[1]}},{key:"sinc",value:function(t,e){for(var r=Math.floor(t=this.scaleFactor_*t),n=r-this.sincFilterSize_+1,s=r+this.sincFilterSize_,a=0,o=n;o<=s;o++)a+=this.kernel_(t-o)*this.getClippedInput_(o,e);return a}},{key:"getTangent_",value:function(t,e){return this.tangentFactor_*(this.getClippedInput_(t+1,e)-this.getClippedInput_(t-1,e))/2}},{key:"getClippedInput_",value:function(t,e){return 0<=t&&t<this.length_?e[t]:0}}]),t}();function u(t){return Math.exp(-t/2*t/2)}},{"@swc/helpers/cjs/_class_call_check.cjs":"4Uf9M","@swc/helpers/cjs/_create_class.cjs":"igUuK","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],"4eVTq":[function(t,e,r,n){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"FIRLPF",function(){return l});var a=t("@swc/helpers/cjs/_class_call_check.cjs"),o=t("@swc/helpers/cjs/_create_class.cjs"),l=function(){"use strict";function t(e,r,n){(0,a._)(this,t);var s=2*Math.PI*n/r,o=0;this.filters=[];for(var l=0;l<=e;l++)l-e/2==0?this.filters[l]=s:(this.filters[l]=Math.sin(s*(l-e/2))/(l-e/2),this.filters[l]*=.54-.46*Math.cos(2*Math.PI*l/e)),o+=this.filters[l];for(var u=0;u<=e;u++)this.filters[u]/=o;this.z=this.initZ_()}return(0,o._)(t,[{key:"filter",value:function(t){this.z.buf[this.z.pointer]=t;for(var e=0,r=0,n=this.z.buf.length;r<n;r++)e+=this.filters[r]*this.z.buf[(this.z.pointer+r)%this.z.buf.length];return this.z.pointer=(this.z.pointer+1)%this.z.buf.length,e}},{key:"reset",value:function(){this.z=this.initZ_()}},{key:"initZ_",value:function(){for(var t=[],e=0;e<this.filters.length-1;e++)t.push(0);return{buf:t,pointer:0}}}]),t}()},{"@swc/helpers/cjs/_class_call_check.cjs":"4Uf9M","@swc/helpers/cjs/_create_class.cjs":"igUuK","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],hfRca:[function(t,e,r,n){var s=t("@parcel/transformer-js/src/esmodule-helpers.js");s.defineInteropFlag(r),s.export(r,"ButterworthLPF",function(){return l});var a=t("@swc/helpers/cjs/_class_call_check.cjs"),o=t("@swc/helpers/cjs/_create_class.cjs"),l=function(){"use strict";function t(e,r,n){(0,a._)(this,t);for(var s=[],o=0;o<e;o++)s.push(this.getCoeffs_({Fs:r,Fc:n,Q:.5/Math.sin(Math.PI/(2*e)*(o+.5))}));this.stages=[];for(var l=0;l<s.length;l++)this.stages[l]={b0:s[l].b[0],b1:s[l].b[1],b2:s[l].b[2],a1:s[l].a[0],a2:s[l].a[1],k:s[l].k,z:[0,0]}}return(0,o._)(t,[{key:"filter",value:function(t){for(var e=t,r=0,n=this.stages.length;r<n;r++)e=this.runStage_(r,e);return e}},{key:"getCoeffs_",value:function(t){var e={};e.z=[0,0],e.a=[],e.b=[];var r=this.preCalc_(t,e);return e.k=1,e.b.push((1-r.cw)/(2*r.a0)),e.b.push(2*e.b[0]),e.b.push(e.b[0]),e}},{key:"preCalc_",value:function(t,e){var r={},n=2*Math.PI*t.Fc/t.Fs;return r.alpha=Math.sin(n)/(2*t.Q),r.cw=Math.cos(n),r.a0=1+r.alpha,e.a0=r.a0,e.a.push(-2*r.cw/r.a0),e.k=1,e.a.push((1-r.alpha)/r.a0),r}},{key:"runStage_",value:function(t,e){var r=e*this.stages[t].k-this.stages[t].a1*this.stages[t].z[0]-this.stages[t].a2*this.stages[t].z[1],n=this.stages[t].b0*r+this.stages[t].b1*this.stages[t].z[0]+this.stages[t].b2*this.stages[t].z[1];return this.stages[t].z[1]=this.stages[t].z[0],this.stages[t].z[0]=r,n}},{key:"reset",value:function(){for(var t=0;t<this.stages.length;t++)this.stages[t].z=[0,0]}}]),t}()},{"@swc/helpers/cjs/_class_call_check.cjs":"4Uf9M","@swc/helpers/cjs/_create_class.cjs":"igUuK","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],cfRHd:[function(t,e,r,n){var s,a,o,l,u,c,h,f,d,p,_,m=t("@parcel/transformer-js/src/esmodule-helpers.js");m.defineInteropFlag(r),m.export(r,"dir",function(){return N}),m.export(r,"file",function(){return H}),m.export(r,"rollfile",function(){return tn}),m.export(r,"tmpfile",function(){return ti}),m.export(r,"write",function(){return V});var y=t("@swc/helpers/cjs/_async_iterator.cjs"),g=t("@swc/helpers/cjs/_async_to_generator.cjs"),v=t("@swc/helpers/cjs/_class_call_check.cjs"),b=t("@swc/helpers/cjs/_create_class.cjs"),w=t("@swc/helpers/cjs/_sliced_to_array.cjs"),S=t("@swc/helpers/cjs/_type_of.cjs"),x=t("@swc/helpers/cjs/_ts_generator.cjs"),U=function(t){throw TypeError(t)},E=function(t,e,r){return e.has(t)||U("Cannot "+r)},k=function(t,e,r){return E(t,e,"read from private field"),r?r.call(t):e.get(t)},A=function(t,e,r){return e.has(t)?U("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r)},T=function(t,e,r,n){return E(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r},C="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2Z1bmN0aW9uIHUobil7aWYobj09PSIvIilyZXR1cm57cGFyZW50Om51bGwsbmFtZToiIn07Y29uc3QgZT1uLnNwbGl0KCIvIikuZmlsdGVyKGk9PmkubGVuZ3RoPjApO2lmKGUubGVuZ3RoPT09MCl0aHJvdyBFcnJvcigiSW52YWxpZCBwYXRoIik7Y29uc3QgYT1lW2UubGVuZ3RoLTFdLHI9Ii8iK2Uuc2xpY2UoMCwtMSkuam9pbigiLyIpO3JldHVybntuYW1lOmEscGFyZW50OnJ9fWFzeW5jIGZ1bmN0aW9uIHcobixlKXtjb25zdHtwYXJlbnQ6YSxuYW1lOnJ9PXUobik7aWYoYT09bnVsbClyZXR1cm4gYXdhaXQgbmF2aWdhdG9yLnN0b3JhZ2UuZ2V0RGlyZWN0b3J5KCk7Y29uc3QgaT1hLnNwbGl0KCIvIikuZmlsdGVyKHQ9PnQubGVuZ3RoPjApO3RyeXtsZXQgdD1hd2FpdCBuYXZpZ2F0b3Iuc3RvcmFnZS5nZXREaXJlY3RvcnkoKTtmb3IoY29uc3QgcyBvZiBpKXQ9YXdhaXQgdC5nZXREaXJlY3RvcnlIYW5kbGUocyx7Y3JlYXRlOmUuY3JlYXRlfSk7aWYoZS5pc0ZpbGUpcmV0dXJuIGF3YWl0IHQuZ2V0RmlsZUhhbmRsZShyLHtjcmVhdGU6ZS5jcmVhdGV9KX1jYXRjaCh0KXtpZih0Lm5hbWU9PT0iTm90Rm91bmRFcnJvciIpcmV0dXJuIG51bGw7dGhyb3cgdH19Y29uc3QgZj17fTtzZWxmLm9ubWVzc2FnZT1hc3luYyBuPT57dmFyIGk7Y29uc3R7ZXZ0VHlwZTplLGFyZ3M6YX09bi5kYXRhO2xldCByPWZbYS5maWxlSWRdO3RyeXtsZXQgdDtjb25zdCBzPVtdO2lmKGU9PT0icmVnaXN0ZXIiKXtjb25zdCBsPWF3YWl0IHcoYS5maWxlUGF0aCx7Y3JlYXRlOiEwLGlzRmlsZTohMH0pO2lmKGw9PW51bGwpdGhyb3cgRXJyb3IoYG5vdCBmb3VuZCBmaWxlOiAke2EuZmlsZUlkfWApO3I9YXdhaXQgbC5jcmVhdGVTeW5jQWNjZXNzSGFuZGxlKHttb2RlOmEubW9kZX0pLGZbYS5maWxlSWRdPXJ9ZWxzZSBpZihlPT09ImNsb3NlIilhd2FpdCByLmNsb3NlKCksZGVsZXRlIGZbYS5maWxlSWRdO2Vsc2UgaWYoZT09PSJ0cnVuY2F0ZSIpYXdhaXQgci50cnVuY2F0ZShhLm5ld1NpemUpO2Vsc2UgaWYoZT09PSJ3cml0ZSIpe2NvbnN0e2RhdGE6bCxvcHRzOm99PW4uZGF0YS5hcmdzO3Q9YXdhaXQgci53cml0ZShsLG8pfWVsc2UgaWYoZT09PSJyZWFkIil7Y29uc3R7b2Zmc2V0Omwsc2l6ZTpvfT1uLmRhdGEuYXJncyxnPW5ldyBVaW50OEFycmF5KG8pLGQ9YXdhaXQgci5yZWFkKGcse2F0Omx9KSxjPWcuYnVmZmVyO3Q9ZD09PW8/YzooKGk9Yy50cmFuc2Zlcik9PW51bGw/dm9pZCAwOmkuY2FsbChjLGQpKT8/Yy5zbGljZSgwLGQpLHMucHVzaCh0KX1lbHNlIGU9PT0iZ2V0U2l6ZSI/dD1hd2FpdCByLmdldFNpemUoKTplPT09ImZsdXNoIiYmYXdhaXQgci5mbHVzaCgpO3NlbGYucG9zdE1lc3NhZ2Uoe2V2dFR5cGU6ImNhbGxiYWNrIixjYklkOm4uZGF0YS5jYklkLHJldHVyblZhbDp0fSxzKX1jYXRjaCh0KXtjb25zdCBzPXQ7c2VsZi5wb3N0TWVzc2FnZSh7ZXZ0VHlwZToidGhyb3dFcnJvciIsY2JJZDpuLmRhdGEuY2JJZCxlcnJNc2c6cy5uYW1lKyI6ICIrcy5tZXNzYWdlK2AKYCtKU09OLnN0cmluZ2lmeShuLmRhdGEpfSl9fX0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPW9wZnMtd29ya2VyLUY0UldscWNfLmpzLm1hcAo=",I=("undefined"==typeof self?"undefined":(0,S._)(self))<"u"&&self.Blob&&new Blob([Uint8Array.from(atob(C),function(t){return t.charCodeAt(0)})],{type:"text/javascript;charset=utf-8"});function B(t){var e;try{if(!(e=I&&(self.URL||self.webkitURL).createObjectURL(I)))throw"";var r=new Worker(e,{name:null==t?void 0:t.name});return r.addEventListener("error",function(){(self.URL||self.webkitURL).revokeObjectURL(e)}),r}catch(e){return new Worker("data:text/javascript;base64,"+C,{name:null==t?void 0:t.name})}finally{e&&(self.URL||self.webkitURL).revokeObjectURL(e)}}function z(){return(z=(0,g._)(function(t,e,r){var n;return(0,x._)(this,function(s){switch(s.label){case 0:return[4,(n=function(){if(F.length<3){var t,e,r,n,s=(e=new B,r=0,n={},e.onmessage=function(t){var e,r,s=t.data;"callback"===s.evtType?null==(e=n[s.cbId])||e.resolve(s.returnVal):"throwError"===s.evtType&&(null==(r=n[s.cbId])||r.reject(Error(s.errMsg))),delete n[s.cbId]},t=(0,g._)(function(t,s){var a,o,l=arguments;return(0,x._)(this,function(u){return a=l.length>2&&void 0!==l[2]?l[2]:[],r+=1,o=new Promise(function(t,e){n[r]={resolve:t,reject:e}}),[2,(e.postMessage({cbId:r,evtType:t,args:s},a),o)]})}),function(e,r){return t.apply(this,arguments)});return F.push(s),s}var a=F[P];return P=(P+1)%F.length,a}())("register",{fileId:t,filePath:e,mode:r})];case 1:var a,o,l;return[2,(s.sent(),{read:(a=(0,g._)(function(e,r){return(0,x._)(this,function(s){switch(s.label){case 0:return[4,n("read",{fileId:t,offset:e,size:r})];case 1:return[2,s.sent()]}})}),function(t,e){return a.apply(this,arguments)}),write:(o=(0,g._)(function(e,r){return(0,x._)(this,function(s){switch(s.label){case 0:return[4,n("write",{fileId:t,data:e,opts:r},[ArrayBuffer.isView(e)?e.buffer:e])];case 1:return[2,s.sent()]}})}),function(t,e){return o.apply(this,arguments)}),close:(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:return[4,n("close",{fileId:t})];case 1:return[2,e.sent()]}})}),truncate:(l=(0,g._)(function(e){return(0,x._)(this,function(r){switch(r.label){case 0:return[4,n("truncate",{fileId:t,newSize:e})];case 1:return[2,r.sent()]}})}),function(t){return l.apply(this,arguments)}),getSize:(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:return[4,n("getSize",{fileId:t})];case 1:return[2,e.sent()]}})}),flush:(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:return[4,n("flush",{fileId:t})];case 1:return[2,e.sent()]}})})})]}})})).apply(this,arguments)}var F=[],P=0;function L(t){if("/"===t)return{parent:null,name:""};var e=t.split("/").filter(function(t){return t.length>0});if(0===e.length)throw Error("Invalid path");return{name:e[e.length-1],parent:"/"+e.slice(0,-1).join("/")}}function R(t,e){return M.apply(this,arguments)}function M(){return(M=(0,g._)(function(t,e){var r,n,s,a,o,l,u,c,h,f,d,p,_,m;return(0,x._)(this,function(y){switch(y.label){case 0:if(n=(r=L(t)).parent,s=r.name,null!=n)return[3,2];return[4,navigator.storage.getDirectory()];case 1:return[2,y.sent()];case 2:a=n.split("/").filter(function(t){return t.length>0}),y.label=3;case 3:return y.trys.push([3,17,,18]),[4,navigator.storage.getDirectory()];case 4:o=y.sent(),l=!0,u=!1,c=void 0,y.label=5;case 5:y.trys.push([5,10,11,12]),h=a[Symbol.iterator](),y.label=6;case 6:if(l=(f=h.next()).done)return[3,9];return d=f.value,[4,o.getDirectoryHandle(d,{create:e.create})];case 7:o=y.sent(),y.label=8;case 8:return l=!0,[3,6];case 9:return[3,12];case 10:return p=y.sent(),u=!0,c=p,[3,12];case 11:try{l||null==h.return||h.return()}finally{if(u)throw c}return[7];case 12:if(!e.isFile)return[3,14];return[4,o.getFileHandle(s,{create:e.create})];case 13:return _=y.sent(),[3,16];case 14:return[4,o.getDirectoryHandle(s,{create:e.create})];case 15:_=y.sent(),y.label=16;case 16:return[2,_];case 17:if("NotFoundError"===(m=y.sent()).name)return[2,null];throw m;case 18:return[2]}})})).apply(this,arguments)}function O(t){return D.apply(this,arguments)}function D(){return(D=(0,g._)(function(t){var e,r,n,s,a,o,l,u,c,h,f,d,p;return(0,x._)(this,function(_){switch(_.label){case 0:if(r=(e=L(t)).parent,n=e.name,null!=r)return[3,15];return[4,navigator.storage.getDirectory()];case 1:s=_.sent(),a=!1,o=!1,_.label=2;case 2:_.trys.push([2,8,9,14]),u=(0,y._)(s.keys()),_.label=3;case 3:return[4,u.next()];case 4:if(!(a=!(c=_.sent()).done))return[3,7];return h=c.value,[4,s.removeEntry(h,{recursive:!0})];case 5:_.sent(),_.label=6;case 6:return a=!1,[3,3];case 7:return[3,14];case 8:return f=_.sent(),o=!0,l=f,[3,14];case 9:if(_.trys.push([9,,12,13]),!(a&&null!=u.return))return[3,11];return[4,u.return()];case 10:_.sent(),_.label=11;case 11:return[3,13];case 12:if(o)throw l;return[7];case 13:return[7];case 14:return[2];case 15:return[4,R(r,{create:!1,isFile:!1})];case 16:if(null==(d=_.sent()))return[3,20];_.label=17;case 17:return _.trys.push([17,19,,20]),[4,d.removeEntry(n,{recursive:!0})];case 18:return _.sent(),[3,20];case 19:if("NotFoundError"===(p=_.sent()).name)return[2];throw p;case 20:return[2]}})})).apply(this,arguments)}function j(t,e){return"".concat(t,"/").concat(e).replace("//","/")}function N(t){return new W(t)}var G=function(){"use strict";function t(e){(0,v._)(this,t),A(this,s),A(this,a),A(this,o),T(this,s,e);var r=L(e),n=r.parent,l=r.name;T(this,a,l),T(this,o,n)}return(0,b._)(t,[{key:"kind",get:function(){return"dir"}},{key:"name",get:function(){return k(this,a)}},{key:"path",get:function(){return k(this,s)}},{key:"parent",get:function(){return null==k(this,o)?null:N(k(this,o))}},{key:"create",value:function(){var t=this;return(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:return[4,R(k(t,s),{create:!0,isFile:!1})];case 1:return[2,(e.sent(),N(k(t,s)))]}})})()}},{key:"exists",value:function(){var t=this;return(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:return[4,R(k(t,s),{create:!1,isFile:!1})];case 1:return[2,e.sent()instanceof FileSystemDirectoryHandle]}})})()}},{key:"remove",value:function(){var t=this;return(0,g._)(function(){var e,r,n,a,o,l,u;return(0,x._)(this,function(c){switch(c.label){case 0:e=!0,r=!1,n=void 0,c.label=1;case 1:return c.trys.push([1,9,10,11]),[4,t.children()];case 2:a=c.sent()[Symbol.iterator](),c.label=3;case 3:if(e=(o=a.next()).done)return[3,8];l=o.value,c.label=4;case 4:return c.trys.push([4,6,,7]),[4,l.remove()];case 5:return c.sent(),[3,7];case 6:return console.warn(c.sent()),[3,7];case 7:return e=!0,[3,3];case 8:return[3,11];case 9:return u=c.sent(),r=!0,n=u,[3,11];case 10:try{e||null==a.return||a.return()}finally{if(r)throw n}return[7];case 11:return c.trys.push([11,13,,14]),[4,O(k(t,s))];case 12:return c.sent(),[3,14];case 13:return console.warn(c.sent()),[3,14];case 14:return[2]}})})()}},{key:"children",value:function(){var t=this;return(0,g._)(function(){var e,r,n,a,o,l,u,c,h;return(0,x._)(this,function(f){switch(f.label){case 0:return[4,R(k(t,s),{create:!1,isFile:!1})];case 1:if(null==(e=f.sent()))return[2,[]];r=[],n=!1,a=!1,f.label=2;case 2:f.trys.push([2,7,8,13]),l=(0,y._)(e.values()),f.label=3;case 3:return[4,l.next()];case 4:if(!(n=!(u=f.sent()).done))return[3,6];c=u.value,r.push(("file"===c.kind?H:N)(j(k(t,s),c.name))),f.label=5;case 5:return n=!1,[3,3];case 6:return[3,13];case 7:return h=f.sent(),a=!0,o=h,[3,13];case 8:if(f.trys.push([8,,11,12]),!(n&&null!=l.return))return[3,10];return[4,l.return()];case 9:f.sent(),f.label=10;case 10:return[3,12];case 11:if(a)throw o;return[7];case 12:return[7];case 13:return[2,r]}})})()}},{key:"copyTo",value:function(e){var r=this;return(0,g._)(function(){var n,s,a;return(0,x._)(this,function(o){switch(o.label){case 0:return[4,r.exists()];case 1:if(!o.sent())throw Error("dir ".concat(r.path," not exists"));if(!(e instanceof t))return[3,6];return[4,e.exists()];case 2:return[4,(n=o.sent()?N(j(e.path,r.name)):e).create()];case 3:return o.sent(),s=Promise.all,[4,r.children()];case 4:return[4,s.apply(Promise,[o.sent().map(function(t){return t.copyTo(n)})])];case 5:return[2,(o.sent(),n)];case 6:if(!(e instanceof FileSystemDirectoryHandle))return[3,9];return a=Promise.all,[4,r.children()];case 7:var l;return[4,a.apply(Promise,[o.sent().map((l=(0,g._)(function(t){var r,n;return(0,x._)(this,function(s){switch(s.label){case 0:if("file"!==t.kind)return[3,3];return r=t.copyTo,[4,e.getFileHandle(t.name,{create:!0})];case 1:return[4,r.apply(t,[s.sent()])];case 2:return s.sent(),[3,6];case 3:return n=t.copyTo,[4,e.getDirectoryHandle(t.name,{create:!0})];case 4:return[4,n.apply(t,[s.sent()])];case 5:s.sent(),s.label=6;case 6:return[2]}})}),function(t){return l.apply(this,arguments)}))])];case 8:return[2,(o.sent(),null)];case 9:throw Error("Illegal target type")}})})()}},{key:"moveTo",value:function(t){var e=this;return(0,g._)(function(){var r;return(0,x._)(this,function(n){switch(n.label){case 0:return[4,e.copyTo(t)];case 1:return r=n.sent(),[4,e.remove()];case 2:return[2,(n.sent(),r)]}})})()}}]),t}();s=new WeakMap,a=new WeakMap,o=new WeakMap;var W=G,Y=new Map;function H(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rw";if("rw"===e){var r,n=null!=(r=Y.get(t))?r:new Q(t,e);return Y.set(t,n),n}return new Q(t,e)}function V(t,e){return Z.apply(this,arguments)}function Z(){return(Z=(0,g._)(function(t,e){var r,n,s,a,o,l,u,c,h=arguments;return(0,x._)(this,function(a){switch(a.label){case 0:if(r=h.length>2&&void 0!==h[2]?h[2]:{overwrite:!0},!(e instanceof Q))return[3,3];return n=[t],[4,e.stream()];case 1:return[4,V.apply(void 0,n.concat([a.sent(),r]))];case 2:return a.sent(),[2];case 3:return[4,(t instanceof Q?t:H(t,"rw")).createWriter()];case 4:s=a.sent(),a.label=5;case 5:if(a.trys.push([5,16,17,19]),!r.overwrite)return[3,7];return[4,s.truncate(0)];case 6:a.sent(),a.label=7;case 7:if(!(e instanceof ReadableStream))return[3,13];o=e.getReader(),a.label=8;case 8:return[4,o.read()];case 9:if(u=(l=a.sent()).done,c=l.value,u)return[3,12];return[4,s.write(c)];case 10:a.sent(),a.label=11;case 11:return[3,8];case 12:return[3,15];case 13:return[4,s.write(e)];case 14:a.sent(),a.label=15;case 15:return[3,19];case 16:throw a.sent();case 17:return[4,s.close()];case 18:return a.sent(),[7];case 19:return[2]}})})).apply(this,arguments)}var X=0,K=function(){"use strict";function t(e,r){var n,s=this;(0,v._)(this,t),A(this,l),A(this,u),A(this,c),A(this,h),A(this,f),A(this,d,0),A(this,p,(n=null,function(){var t;return T(s,d,k(s,d)+1),null!=n?n:n=new Promise((t=(0,g._)(function(t,e){var r;return(0,x._)(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,function(t,e,r){return z.apply(this,arguments)}(k(s,f),k(s,l),k(s,h))];case 1:return t([r=a.sent(),(0,g._)(function(){var t;return(0,x._)(this,function(t){switch(t.label){case 0:if(T(s,d,k(s,d)-1),k(s,d)>0)return[3,2];return n=null,[4,r.close()];case 1:t.sent(),t.label=2;case 2:return[2]}})})]),[3,3];case 2:return e(a.sent()),[3,3];case 3:return[2]}})}),function(e,r){return t.apply(this,arguments)}))})),A(this,_,!1),T(this,f,++X),T(this,l,e),T(this,h,{r:"read-only",rw:"readwrite","rw-unsafe":"readwrite-unsafe"}[r]);var a=L(e),o=a.parent,m=a.name;if(null==o)throw Error("Invalid path");T(this,c,m),T(this,u,o)}return(0,b._)(t,[{key:"kind",get:function(){return"file"}},{key:"path",get:function(){return k(this,l)}},{key:"name",get:function(){return k(this,c)}},{key:"parent",get:function(){return null==k(this,u)?null:N(k(this,u))}},{key:"createWriter",value:function(){var t=this;return(0,g._)(function(){var e,r,n,s,a,o;return(0,x._)(this,function(l){switch(l.label){case 0:if("read-only"===k(t,h))throw Error("file is read-only");if(k(t,_))throw Error("Other writer have not been closed");return T(t,_,!0),e=new TextEncoder,[4,k(t,p).call(t)];case 1:return n=(r=w._.apply(void 0,[l.sent(),2]))[0],s=r[1],[4,n.getSize()];case 2:var u,c;return a=l.sent(),o=!1,[2,{write:(u=(0,g._)(function(t){var r,s,l,u,c=arguments;return(0,x._)(this,function(h){switch(h.label){case 0:if(r=c.length>1&&void 0!==c[1]?c[1]:{},o)throw Error("Writer is closed");return l="string"==typeof t?e.encode(t):t,a=(u=null!=(s=r.at)?s:a)+l.byteLength,[4,n.write(l,{at:u})];case 1:return[2,h.sent()]}})}),function(t){return u.apply(this,arguments)}),truncate:(c=(0,g._)(function(t){return(0,x._)(this,function(e){switch(e.label){case 0:if(o)throw Error("Writer is closed");return[4,n.truncate(t)];case 1:return e.sent(),a>t&&(a=t),[2]}})}),function(t){return c.apply(this,arguments)}),flush:(0,g._)(function(){return(0,x._)(this,function(t){switch(t.label){case 0:if(o)throw Error("Writer is closed");return[4,n.flush()];case 1:return t.sent(),[2]}})}),close:(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:if(o)throw Error("Writer is closed");return o=!0,T(t,_,!1),[4,s()];case 1:return e.sent(),[2]}})})}]}})})()}},{key:"createReader",value:function(){var t=this;return(0,g._)(function(){var e,r,n,s,a;return(0,x._)(this,function(o){switch(o.label){case 0:return[4,k(t,p).call(t)];case 1:var l;return r=(e=w._.apply(void 0,[o.sent(),2]))[0],n=e[1],s=!1,a=0,[2,{read:(l=(0,g._)(function(t){var e,n,o,l,u=arguments;return(0,x._)(this,function(c){switch(c.label){case 0:if(e=u.length>1&&void 0!==u[1]?u[1]:{},s)throw Error("Reader is closed");return o=null!=(n=e.at)?n:a,[4,r.read(o,t)];case 1:return l=c.sent(),[2,(a=o+l.byteLength,l)]}})}),function(t){return l.apply(this,arguments)}),getSize:(0,g._)(function(){return(0,x._)(this,function(t){switch(t.label){case 0:if(s)throw Error("Reader is closed");return[4,r.getSize()];case 1:return[2,t.sent()]}})}),close:(0,g._)(function(){var t;return(0,x._)(this,function(t){switch(t.label){case 0:if(s)return[3,2];return s=!0,[4,n()];case 1:t.sent(),t.label=2;case 2:return[2]}})})}]}})})()}},{key:"text",value:function(){var t=this;return(0,g._)(function(){var e,r;return(0,x._)(this,function(n){switch(n.label){case 0:return r=(e=new TextDecoder).decode,[4,t.arrayBuffer()];case 1:return[2,r.apply(e,[n.sent()])]}})})()}},{key:"arrayBuffer",value:function(){var t=this;return(0,g._)(function(){var e,r;return(0,x._)(this,function(n){switch(n.label){case 0:return[4,R(k(t,l),{create:!1,isFile:!0})];case 1:if(null!=(e=n.sent()))return[3,2];return r=new ArrayBuffer(0),[3,4];case 2:return[4,e.getFile()];case 3:r=n.sent().arrayBuffer(),n.label=4;case 4:return[2,r]}})})()}},{key:"stream",value:function(){var t=this;return(0,g._)(function(){var e;return(0,x._)(this,function(r){switch(r.label){case 0:return[4,t.getOriginFile()];case 1:return[2,null==(e=r.sent())?new ReadableStream({pull:function(t){t.close()}}):e.stream()]}})})()}},{key:"getOriginFile",value:function(){var t=this;return(0,g._)(function(){var e;return(0,x._)(this,function(r){switch(r.label){case 0:return[4,R(k(t,l),{create:!1,isFile:!0})];case 1:return[2,null==(e=r.sent())?void 0:e.getFile()]}})})()}},{key:"getSize",value:function(){var t=this;return(0,g._)(function(){var e,r;return(0,x._)(this,function(n){switch(n.label){case 0:return[4,R(k(t,l),{create:!1,isFile:!0})];case 1:if(null!=(e=n.sent()))return[3,2];return r=0,[3,4];case 2:return[4,e.getFile()];case 3:r=n.sent().size,n.label=4;case 4:return[2,r]}})})()}},{key:"exists",value:function(){var t=this;return(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:return[4,R(k(t,l),{create:!1,isFile:!0})];case 1:return[2,e.sent()instanceof FileSystemFileHandle]}})})()}},{key:"remove",value:function(){var t=this;return(0,g._)(function(){return(0,x._)(this,function(e){switch(e.label){case 0:if(k(t,d))throw Error("exists unclosed reader/writer");return[4,O(k(t,l))];case 1:return e.sent(),[2]}})})()}},{key:"copyTo",value:function(e){var r=this;return(0,g._)(function(){var n,s,a;return(0,x._)(this,function(o){switch(o.label){case 0:if(!(e instanceof t))return[3,4];if(e.path!==r.path)return[3,1];return n=r,[3,3];case 1:return[4,V(e.path,r)];case 2:o.sent(),n=H(e.path),o.label=3;case 3:return[2,n];case 4:if(!(e instanceof W))return[3,7];return[4,r.exists()];case 5:if(!o.sent())throw Error("file ".concat(r.path," not exists"));return[4,r.copyTo(H(j(e.path,r.name)))];case 6:return[2,o.sent()];case 7:if(!(e instanceof FileSystemFileHandle))return[3,11];return[4,r.stream()];case 8:return a=(s=o.sent()).pipeTo,[4,e.createWritable()];case 9:return[4,a.apply(s,[o.sent()])];case 10:return[2,(o.sent(),null)];case 11:throw Error("Illegal target type")}})})()}},{key:"moveTo",value:function(t){var e=this;return(0,g._)(function(){var r;return(0,x._)(this,function(n){switch(n.label){case 0:return[4,e.copyTo(t)];case 1:return r=n.sent(),[4,e.remove()];case 2:return[2,(n.sent(),r)]}})})()}}]),t}();l=new WeakMap,u=new WeakMap,c=new WeakMap,h=new WeakMap,f=new WeakMap,d=new WeakMap,p=new WeakMap,_=new WeakMap;var Q=K,J="/.opfs-tools-temp-dir";function q(t){return $.apply(this,arguments)}function $(){return($=(0,g._)(function(t){var e;return(0,x._)(this,function(r){switch(r.label){case 0:if(r.trys.push([0,9,,10]),"file"!==t.kind)return[3,6];return[4,t.exists()];case 1:if(!r.sent())return[2,!0];return[4,t.createWriter()];case 2:return[4,(e=r.sent()).truncate(0)];case 3:return r.sent(),[4,e.close()];case 4:return r.sent(),[4,t.remove()];case 5:return r.sent(),[3,8];case 6:return[4,t.remove()];case 7:r.sent(),r.label=8;case 8:return[2,!0];case 9:return[2,(console.warn(r.sent()),!1)];case 10:return[2]}})})).apply(this,arguments)}var tt=[],te=!1;function tr(){return(tr=(0,g._)(function(){var t,e,r,n,s,a,o,l,u,c,h;return(0,x._)(this,function(f){switch(f.label){case 0:if(null==globalThis.localStorage)return[2];t="OPFS_TOOLS_EXPIRES_TMP_FILES",te||(te=!0,globalThis.addEventListener("unload",function(){var e;0!==tt.length&&localStorage.setItem(t,"".concat(null!=(e=localStorage.getItem(t))?e:"",",").concat(tt.join(",")))})),r=null!=(e=localStorage.getItem(t))?e:"",n=!0,s=!1,a=void 0,f.label=1;case 1:f.trys.push([1,7,8,9]),o=r.split(",")[Symbol.iterator](),f.label=2;case 2:if(n=(l=o.next()).done)return[3,6];if(!(c=0!==(u=l.value).length))return[3,4];return[4,q(H("".concat(J,"/").concat(u)))];case 3:c=f.sent(),f.label=4;case 4:c&&(r=r.replace(u,"")),f.label=5;case 5:return n=!0,[3,2];case 6:return[3,9];case 7:return h=f.sent(),s=!0,a=h,[3,9];case 8:try{n||null==o.return||o.return()}finally{if(s)throw a}return[7];case 9:return localStorage.setItem(t,r.replace(/,{2,}/g,",")),[2]}})})).apply(this,arguments)}function ti(){var t="".concat(Math.random().toString().slice(2),"-").concat(Date.now());return tt.push(t),H("".concat(J,"/").concat(t))}function tn(t,e){var r,n,s=H(t),a=0,o=s.createWriter(),l=s.createReader(),u=(r=(0,g._)(function(t){var e;return(0,x._)(this,function(r){switch(r.label){case 0:return[4,l];case 1:return[4,r.sent().read(a,{at:Math.round(.3*a)})];case 2:return e=r.sent(),[4,t.write(e,{at:0})];case 3:return a=r.sent(),[4,t.truncate(a)];case 4:return r.sent(),[2]}})}),function(t){return r.apply(this,arguments)});return{append:(n=(0,g._)(function(t){var r,n;return(0,x._)(this,function(n){switch(n.label){case 0:return[4,o];case 1:return[4,(r=n.sent()).write(t)];case 2:if(!((a+=n.sent())>=e))return[3,4];return[4,u(r)];case 3:n.sent(),n.label=4;case 4:return[2]}})}),function(t){return n.apply(this,arguments)}),text:s.text.bind(s),remove:(0,g._)(function(){return(0,x._)(this,function(t){switch(t.label){case 0:return[4,l];case 1:case 3:return[4,t.sent().close()];case 2:return t.sent(),[4,o];case 4:return t.sent(),[4,s.remove()];case 5:return t.sent(),[2]}})}),getSize:(0,g._)(function(){return(0,x._)(this,function(t){return[2,a]})})}}(0,g._)(function(){var t,e,r;return(0,x._)(this,function(e){switch(e.label){case 0:if(!0===globalThis.__opfs_tools_tmpfile_init__)return[3,3];if(globalThis.__opfs_tools_tmpfile_init__=!0,!(r=null!=globalThis.FileSystemDirectoryHandle&&null!=globalThis.FileSystemFileHandle&&(null==(t=globalThis.navigator)?void 0:t.storage.getDirectory)!=null))return[3,2];return setInterval((0,g._)(function(){var t,e,r,n,s,a,o,l,u;return(0,x._)(this,function(l){switch(l.label){case 0:t=!0,e=!1,r=void 0,l.label=1;case 1:return l.trys.push([1,8,9,10]),[4,N(J).children()];case 2:n=l.sent()[Symbol.iterator](),l.label=3;case 3:if(t=(s=n.next()).done)return[3,7];if(a=s.value,!(null==(o=/^\d+-(\d+)$/.exec(a.name))||Date.now()-Number(o[1])>2592e5))return[3,5];return[4,q(a)];case 4:l.sent(),l.label=5;case 5:l.label=6;case 6:return t=!0,[3,3];case 7:return[3,10];case 8:return u=l.sent(),e=!0,r=u,[3,10];case 9:try{t||null==n.return||n.return()}finally{if(e)throw r}return[7];case 10:return[2]}})}),6e4),[4,function(){return tr.apply(this,arguments)}()];case 1:r=e.sent(),e.label=2;case 2:e.label=3;case 3:return[2]}})})()},{"@swc/helpers/cjs/_async_iterator.cjs":"f3IhJ","@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_class_call_check.cjs":"4Uf9M","@swc/helpers/cjs/_create_class.cjs":"igUuK","@swc/helpers/cjs/_sliced_to_array.cjs":"gIQTH","@swc/helpers/cjs/_type_of.cjs":"iXhRw","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],f3IhJ:[function(t,e,r,n){"use strict";function s(t){function e(t){if(Object(t)!==t)return Promise.reject(TypeError(t+" is not an object."));var e=t.done;return Promise.resolve(t.value).then(function(t){return{value:t,done:e}})}return(s=function(t){this.s=t,this.n=t.next}).prototype={s:null,n:null,next:function(){return e(this.n.apply(this.s,arguments))},return:function(t){var r=this.s.return;return void 0===r?Promise.resolve({value:t,done:!0}):e(r.apply(this.s,arguments))},throw:function(t){var r=this.s.return;return void 0===r?Promise.reject(t):e(r.apply(this.s,arguments))}},new s(t)}r._=function(t){var e,r,n,a=2;for("undefined"!=typeof Symbol&&(r=Symbol.asyncIterator,n=Symbol.iterator);a--;){if(r&&null!=(e=t[r]))return e.call(t);if(n&&null!=(e=t[n]))return new s(e.call(t));r="@@asyncIterator",n="@@iterator"}throw TypeError("Object is not async iterable")}},{}]},["8nMKB"],"8nMKB","parcelRequire4dc0",{}); |