@taole/giftstage 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ "use strict";var Jn=r=>{throw TypeError(r)};var Rn=(r,t,e)=>t.has(r)||Jn("Cannot "+e);var Zn=(r,t,e)=>(Rn(r,t,"read from private field"),e?e.call(r):t.get(r)),Mn=(r,t,e)=>t.has(r)?Jn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),ta=(r,t,e,i)=>(Rn(r,t,"write to private field"),i?i.call(r,e):t.set(r,e),e),Nn=(r,t,e)=>(Rn(r,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var no=Object.defineProperty,oa=(r,t)=>{for(var e in t)no(r,e,{get:t[e],enumerable:!0})},Gn=Math.pow(2,32),w=Math.pow(2,32)-1,ao=1,oo=2,ho=4,vn=1,Sn=2,Un=8,Bn=16,wn=32,ea=131072,fn=1,zn=4,un=256,pn=512,_n=1024,mn=2048,ha=-1,j=0,D=1,R=class ca extends ArrayBuffer{constructor(t){super(t),this.fileStart=0,this.usedBytes=0}static fromArrayBuffer(t,e){const i=new ca(t.byteLength);return new Uint8Array(i).set(new Uint8Array(t)),i.fileStart=e,i}},la=(r=>(r[r.BIG_ENDIAN=1]="BIG_ENDIAN",r[r.LITTLE_ENDIAN=2]="LITTLE_ENDIAN",r))(la||{}),gn,Vn,g,z=(g=class{constructor(t,e,i){Mn(this,gn);this._byteLength=0,this.failurePosition=0,this._dynamicSize=1,this._byteOffset=e||0,t instanceof ArrayBuffer?this.buffer=R.fromArrayBuffer(t,0):t instanceof DataView?(this.dataView=t,e&&(this._byteOffset+=e)):this.buffer=new R(t||0),this.position=0,this.endianness=i||1}getPosition(){return this.position}_realloc(t){if(!this._dynamicSize)return;const e=this._byteOffset+this.position+t;let i=this._buffer.byteLength;if(e<=i){e>this._byteLength&&(this._byteLength=e);return}for(i<1&&(i=1);e>i;)i*=2;const s=new R(i),n=new Uint8Array(this._buffer);new Uint8Array(s,0,n.length).set(n),this.buffer=s,this._byteLength=e}_trimAlloc(){if(this._byteLength===this._buffer.byteLength)return;const t=new R(this._byteLength),e=new Uint8Array(t),i=new Uint8Array(this._buffer,0,e.length);e.set(i),this.buffer=t}get byteLength(){return this._byteLength-this._byteOffset}get buffer(){return this._trimAlloc(),this._buffer}set buffer(t){this._buffer=t,this._dataView=new DataView(t,this._byteOffset),this._byteLength=t.byteLength}get byteOffset(){return this._byteOffset}set byteOffset(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}get dataView(){return this._dataView}set dataView(t){this._byteOffset=t.byteOffset,this._buffer=R.fromArrayBuffer(t.buffer,0),this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}seek(t){const e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e}isEof(){return this.position>=this._byteLength}mapUint8Array(t){this._realloc(t*1);const e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=t*1,e}readInt32Array(t,e){t=t===void 0?this.byteLength-this.position/4:t;const i=new Int32Array(t);return g.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),g.arrayToNative(i,e!=null?e:this.endianness),this.position+=i.byteLength,i}readInt16Array(t,e){t=t===void 0?this.byteLength-this.position/2:t;const i=new Int16Array(t);return g.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),g.arrayToNative(i,e!=null?e:this.endianness),this.position+=i.byteLength,i}readInt8Array(t){t=t===void 0?this.byteLength-this.position:t;const e=new Int8Array(t);return g.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e}readUint32Array(t,e){t=t===void 0?this.byteLength-this.position/4:t;const i=new Uint32Array(t);return g.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),g.arrayToNative(i,e!=null?e:this.endianness),this.position+=i.byteLength,i}readUint16Array(t,e){t=t===void 0?this.byteLength-this.position/2:t;const i=new Uint16Array(t);return g.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),g.arrayToNative(i,e!=null?e:this.endianness),this.position+=i.byteLength,i}readUint8Array(t){t=t===void 0?this.byteLength-this.position:t;const e=new Uint8Array(t);return g.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e}readFloat64Array(t,e){t=t===void 0?this.byteLength-this.position/8:t;const i=new Float64Array(t);return g.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),g.arrayToNative(i,e!=null?e:this.endianness),this.position+=i.byteLength,i}readFloat32Array(t,e){t=t===void 0?this.byteLength-this.position/4:t;const i=new Float32Array(t);return g.memcpy(i.buffer,0,this.buffer,this.byteOffset+this.position,t*i.BYTES_PER_ELEMENT),g.arrayToNative(i,e!=null?e:this.endianness),this.position+=i.byteLength,i}readInt32(t){const e=this._dataView.getInt32(this.position,(t!=null?t:this.endianness)===2);return this.position+=4,e}readInt16(t){const e=this._dataView.getInt16(this.position,(t!=null?t:this.endianness)===2);return this.position+=2,e}readInt8(){const t=this._dataView.getInt8(this.position);return this.position+=1,t}readUint32(t){const e=this._dataView.getUint32(this.position,(t!=null?t:this.endianness)===2);return this.position+=4,e}readUint16(t){const e=this._dataView.getUint16(this.position,(t!=null?t:this.endianness)===2);return this.position+=2,e}readUint8(){const t=this._dataView.getUint8(this.position);return this.position+=1,t}readFloat32(t){const e=this._dataView.getFloat32(this.position,(t!=null?t:this.endianness)===2);return this.position+=4,e}readFloat64(t){const e=this._dataView.getFloat64(this.position,(t!=null?t:this.endianness)===2);return this.position+=8,e}static memcpy(t,e,i,s,n){const a=new Uint8Array(t,e,n),o=new Uint8Array(i,s,n);a.set(o)}static arrayToNative(t,e){return e===g.ENDIANNESS?t:this.flipArrayEndianness(t)}static nativeToEndian(t,e){return e&&g.ENDIANNESS===2?t:this.flipArrayEndianness(t)}static flipArrayEndianness(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let i=0;i<t.byteLength;i+=t.BYTES_PER_ELEMENT)for(let s=i+t.BYTES_PER_ELEMENT-1,n=i;s>n;s--,n++){const a=e[n];e[n]=e[s],e[s]=a}return t}readString(t,e){return e===void 0||e==="ASCII"?ia(this.mapUint8Array(t===void 0?this.byteLength-this.position:t)):new TextDecoder(e).decode(this.mapUint8Array(t))}readCString(t){let e=0;const i=this.byteLength-this.position,s=new Uint8Array(this._buffer,this._byteOffset+this.position),n=t!==void 0?Math.min(t,i):i;for(;e<n&&s[e]!==0;e++);const a=ia(this.mapUint8Array(e));return t!==void 0?this.position+=n-e:e!==i&&(this.position+=1),a}readInt64(){return this.readInt32()*Gn+this.readUint32()}readUint64(){return this.readUint32()*Gn+this.readUint32()}readUint24(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()}save(t){const e=new Blob([this.buffer]);if(typeof window!="undefined"&&typeof document!="undefined")if(window.URL&&URL.createObjectURL){const i=window.URL.createObjectURL(e),s=document.createElement("a");document.body.appendChild(s),s.setAttribute("href",i),s.setAttribute("download",t),s.setAttribute("target","_self"),s.click(),window.URL.revokeObjectURL(i),document.body.removeChild(s)}else throw new Error("DataStream.save: Can't create object URL.");return e}get dynamicSize(){return this._dynamicSize}set dynamicSize(t){t||this._trimAlloc(),this._dynamicSize=t}shift(t){const e=new R(this._byteLength-t),i=new Uint8Array(e),s=new Uint8Array(this._buffer,t,i.length);i.set(s),this.buffer=e,this.position-=t}writeInt32Array(t,e){if(this._realloc(t.length*4),t instanceof Int32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt32Array(t.length,e);else for(let i=0;i<t.length;i++)this.writeInt32(t[i],e)}writeInt16Array(t,e){if(this._realloc(t.length*2),t instanceof Int16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt16Array(t.length,e);else for(let i=0;i<t.length;i++)this.writeInt16(t[i],e)}writeInt8Array(t){if(this._realloc(t.length*1),t instanceof Int8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt8Array(t.length);else for(let e=0;e<t.length;e++)this.writeInt8(t[e])}writeUint32Array(t,e){if(this._realloc(t.length*4),t instanceof Uint32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint32Array(t.length,e);else for(let i=0;i<t.length;i++)this.writeUint32(t[i],e)}writeUint16Array(t,e){if(this._realloc(t.length*2),t instanceof Uint16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint16Array(t.length,e);else for(let i=0;i<t.length;i++)this.writeUint16(t[i],e)}writeUint8Array(t){if(this._realloc(t.length*1),t instanceof Uint8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint8Array(t.length);else for(let e=0;e<t.length;e++)this.writeUint8(t[e])}writeFloat64Array(t,e){if(this._realloc(t.length*8),t instanceof Float64Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat64Array(t.length,e);else for(let i=0;i<t.length;i++)this.writeFloat64(t[i],e)}writeFloat32Array(t,e){if(this._realloc(t.length*4),t instanceof Float32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)g.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat32Array(t.length,e);else for(let i=0;i<t.length;i++)this.writeFloat32(t[i],e)}writeInt64(t,e){this._realloc(8),this._dataView.setBigInt64(this.position,BigInt(t),(e!=null?e:this.endianness)===2),this.position+=8}writeInt32(t,e){this._realloc(4),this._dataView.setInt32(this.position,t,(e!=null?e:this.endianness)===2),this.position+=4}writeInt16(t,e){this._realloc(2),this._dataView.setInt16(this.position,t,(e!=null?e:this.endianness)===2),this.position+=2}writeInt8(t){this._realloc(1),this._dataView.setInt8(this.position,t),this.position+=1}writeUint32(t,e){this._realloc(4),this._dataView.setUint32(this.position,t,(e!=null?e:this.endianness)===2),this.position+=4}writeUint16(t,e){this._realloc(2),this._dataView.setUint16(this.position,t,(e!=null?e:this.endianness)===2),this.position+=2}writeUint8(t){this._realloc(1),this._dataView.setUint8(this.position,t),this.position+=1}writeFloat32(t,e){this._realloc(4),this._dataView.setFloat32(this.position,t,(e!=null?e:this.endianness)===2),this.position+=4}writeFloat64(t,e){this._realloc(8),this._dataView.setFloat64(this.position,t,(e!=null?e:this.endianness)===2),this.position+=8}writeUCS2String(t,e,i){i===void 0&&(i=t.length);let s;for(s=0;s<t.length&&s<i;s++)this.writeUint16(t.charCodeAt(s),e);for(;s<i;s++)this.writeUint16(0)}writeString(t,e,i){let s=0;if(e===void 0||e==="ASCII")if(i!==void 0){const n=Math.min(t.length,i);for(s=0;s<n;s++)this.writeUint8(t.charCodeAt(s));for(;s<i;s++)this.writeUint8(0)}else for(s=0;s<t.length;s++)this.writeUint8(t.charCodeAt(s));else this.writeUint8Array(new TextEncoder(e).encode(t.substring(0,i)))}writeCString(t,e){let i=0;if(e!==void 0){const s=Math.min(t.length,e);for(i=0;i<s;i++)this.writeUint8(t.charCodeAt(i));for(;i<e;i++)this.writeUint8(0)}else{for(i=0;i<t.length;i++)this.writeUint8(t.charCodeAt(i));this.writeUint8(0)}}writeStruct(t,e){for(let i=0;i<t.length;i++){const[s,n]=t[i],a=e[s];this.writeType(n,a,e)}}writeType(t,e,i){if(typeof t=="function")return t(this,e);if(typeof t=="object"&&!(t instanceof Array))return t.set(this,e,i);let s,n="ASCII";const a=this.position;let o=t;if(typeof t=="string"&&/:/.test(t)){const h=t.split(":");o=h[0],s=parseInt(h[1])}if(typeof o=="string"&&/,/.test(o)){const h=o.split(",");o=h[0],n=h[1]}switch(o){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,1);break;case"int16be":this.writeInt16(e,1);break;case"uint32be":this.writeUint32(e,1);break;case"int32be":this.writeInt32(e,1);break;case"float32be":this.writeFloat32(e,1);break;case"float64be":this.writeFloat64(e,1);break;case"uint16le":this.writeUint16(e,2);break;case"int16le":this.writeInt16(e,2);break;case"uint32le":this.writeUint32(e,2);break;case"int32le":this.writeInt32(e,2);break;case"float32le":this.writeFloat32(e,2);break;case"float64le":this.writeFloat64(e,2);break;case"cstring":this.writeCString(e,s);break;case"string":this.writeString(e,n,s);break;case"u16string":this.writeUCS2String(e,this.endianness,s);break;case"u16stringle":this.writeUCS2String(e,2,s);break;case"u16stringbe":this.writeUCS2String(e,1,s);break;default:if(Nn(this,gn,Vn).call(this,o)){const[,h]=o;for(let c=0;c<e.length;c++)this.writeType(h,e[c]);break}else{this.writeStruct(o,e);break}}s&&(this.position=a,this._realloc(s),this.position=a+s)}writeUint64(t){const e=Math.floor(t/Gn);this.writeUint32(e),this.writeUint32(t&4294967295)}writeUint24(t){this.writeUint8((t&16711680)>>16),this.writeUint8((t&65280)>>8),this.writeUint8(t&255)}adjustUint32(t,e){const i=this.position;this.seek(t),this.writeUint32(e),this.seek(i)}readStruct(t){const e={},i=this.position;for(let s=0;s<t.length;s+=1){const n=t[s][1],a=this.readType(n,e);if(!a){this.failurePosition===0&&(this.failurePosition=this.position),this.position=i;return}e[t[s][0]]=a}return e}readUCS2String(t,e){return String.fromCharCode.apply(void 0,this.readUint16Array(t,e))}readType(t,e){if(typeof t=="function")return t(this,e);if(typeof t=="object"&&!(t instanceof Array))return t.get(this,e);if(t instanceof Array&&t.length!==3)return this.readStruct(t);let i,s,n="ASCII";const a=this.position;let o=t;if(typeof o=="string"&&/:/.test(o)){const h=o.split(":");o=h[0],s=parseInt(h[1])}if(typeof o=="string"&&/,/.test(o)){const h=o.split(",");o=h[0],n=h[1]}switch(o){case"uint8":i=this.readUint8();break;case"int8":i=this.readInt8();break;case"uint16":i=this.readUint16(this.endianness);break;case"int16":i=this.readInt16(this.endianness);break;case"uint32":i=this.readUint32(this.endianness);break;case"int32":i=this.readInt32(this.endianness);break;case"float32":i=this.readFloat32(this.endianness);break;case"float64":i=this.readFloat64(this.endianness);break;case"uint16be":i=this.readUint16(1);break;case"int16be":i=this.readInt16(1);break;case"uint32be":i=this.readUint32(1);break;case"int32be":i=this.readInt32(1);break;case"float32be":i=this.readFloat32(1);break;case"float64be":i=this.readFloat64(1);break;case"uint16le":i=this.readUint16(2);break;case"int16le":i=this.readInt16(2);break;case"uint32le":i=this.readUint32(2);break;case"int32le":i=this.readInt32(2);break;case"float32le":i=this.readFloat32(2);break;case"float64le":i=this.readFloat64(2);break;case"cstring":i=this.readCString(s);break;case"string":i=this.readString(s,n);break;case"u16string":i=this.readUCS2String(s,this.endianness);break;case"u16stringle":i=this.readUCS2String(s,2);break;case"u16stringbe":i=this.readUCS2String(s,1);break;default:if(Nn(this,gn,Vn).call(this,o)){const[,h,c]=o,f=typeof c=="function"?c(e,this,o):typeof c=="string"&&e[c]!==void 0?parseInt(e[c]):typeof c=="number"?c:c==="*"?void 0:parseInt(c);if(typeof h=="string"){const u=h.replace(/(le|be)$/,"");let _;switch(/le$/.test(h)?_=2:/be$/.test(h)&&(_=1),u){case"uint8":i=this.readUint8Array(f);break;case"uint16":i=this.readUint16Array(f,_);break;case"uint32":i=this.readUint32Array(f,_);break;case"int8":i=this.readInt8Array(f);break;case"int16":i=this.readInt16Array(f,_);break;case"int32":i=this.readInt32Array(f,_);break;case"float32":i=this.readFloat32Array(f,_);break;case"float64":i=this.readFloat64Array(f,_);break;case"cstring":case"utf16string":case"string":if(f){i=new Array(f);for(let m=0;m<f;m++)i[m]=this.readType(h,e)}else for(i=[];!this.isEof();){const m=this.readType(h,e);if(!m)break;i.push(m)}break}}else if(f){i=new Array(f);for(let u=0;u<f;u++){const _=this.readType(h,e);if(!_)return;i[u]=_}}else for(i=[];;){const u=this.position;try{const _=this.readType(h,e);if(!_){this.position=u;break}i.push(_)}catch(_){this.position=u;break}}break}}return s&&(this.position=a+s),i}mapInt32Array(t,e){this._realloc(t*4);const i=new Int32Array(this._buffer,this.byteOffset+this.position,t);return g.arrayToNative(i,e!=null?e:this.endianness),this.position+=t*4,i}mapInt16Array(t,e){this._realloc(t*2);const i=new Int16Array(this._buffer,this.byteOffset+this.position,t);return g.arrayToNative(i,e!=null?e:this.endianness),this.position+=t*2,i}mapInt8Array(t,e){this._realloc(t*1);const i=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=t*1,i}mapUint32Array(t,e){this._realloc(t*4);const i=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return g.arrayToNative(i,e!=null?e:this.endianness),this.position+=t*4,i}mapUint16Array(t,e){this._realloc(t*2);const i=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return g.arrayToNative(i,e!=null?e:this.endianness),this.position+=t*2,i}mapFloat64Array(t,e){this._realloc(t*8);const i=new Float64Array(this._buffer,this.byteOffset+this.position,t);return g.arrayToNative(i,e!=null?e:this.endianness),this.position+=t*8,i}mapFloat32Array(t,e){this._realloc(t*4);const i=new Float32Array(this._buffer,this.byteOffset+this.position,t);return g.arrayToNative(i,e!=null?e:this.endianness),this.position+=t*4,i}},gn=new WeakSet,Vn=function(t){return Array.isArray(t)&&t.length===3&&t[0]==="[]"},g.ENDIANNESS=new Int8Array(new Int16Array([1]).buffer)[0]>0?2:1,g);function ia(r){const t=[];for(let e=0;e<r.length;e++)t[e]=r[e];return String.fromCharCode.apply(void 0,t)}var yn=new Date,En=4,sa=3,ra=2,na=1,G=En,l={setLogLevel(r){r===this.debug?G=na:r===this.info?G=ra:r===this.warn?G=sa:(this.error,G=En)},debug(r,t){console.debug===void 0&&(console.debug=console.log),na>=G&&console.debug("["+l.getDurationString(new Date().getTime()-yn.getTime(),1e3)+"]","["+r+"]",t)},log(r,t){this.debug(r.msg)},info(r,t){ra>=G&&console.info("["+l.getDurationString(new Date().getTime()-yn.getTime(),1e3)+"]","["+r+"]",t)},warn(r,t){sa>=G&&console.warn("["+l.getDurationString(new Date().getTime()-yn.getTime(),1e3)+"]","["+r+"]",t)},error(r,t,e){e!=null&&e.onError?e.onError(r,t):En>=G&&console.error("["+l.getDurationString(new Date().getTime()-yn.getTime(),1e3)+"]","["+r+"]",t)},getDurationString(r,t){let e;function i(c,f){const _=(""+c).split(".");for(;_[0].length<f;)_[0]="0"+_[0];return _.join(".")}r<0?(e=!0,r=-r):e=!1;let n=r/(t||1);const a=Math.floor(n/3600);n-=a*3600;const o=Math.floor(n/60);n-=o*60;let h=n*1e3;return n=Math.floor(n),h-=n*1e3,h=Math.floor(h),(e?"-":"")+a+":"+i(o,2)+":"+i(n,2)+"."+i(h,3)},printRanges(r){const t=r.length;if(t>0){let e="";for(let i=0;i<t;i++)i>0&&(e+=","),e+="["+l.getDurationString(r.start(i))+","+l.getDurationString(r.end(i))+"]";return e}else return"(empty)"}};function co(r,t){l.debug("ArrayBuffer","Trying to create a new buffer of size: "+(r.byteLength+t.byteLength));const e=new Uint8Array(r.byteLength+t.byteLength);return e.set(new Uint8Array(r),0),e.set(new Uint8Array(t),r.byteLength),e.buffer}var Z=class extends z{constructor(r){super(new ArrayBuffer,0),this.buffers=[],this.bufferIndex=-1,r&&(this.insertBuffer(r),this.bufferIndex=0)}initialized(){if(this.bufferIndex>-1)return!0;if(this.buffers.length>0){const r=this.buffers[0];return r.fileStart===0?(this.buffer=r,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)}else return l.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1}reduceBuffer(r,t,e){const i=new Uint8Array(e);return i.set(new Uint8Array(r,t,e)),i.buffer.fileStart=r.fileStart+t,i.buffer.usedBytes=0,i.buffer}insertBuffer(r){let t=!0,e=0;for(;e<this.buffers.length;e++){const i=this.buffers[e];if(r.fileStart<=i.fileStart){if(r.fileStart===i.fileStart)if(r.byteLength>i.byteLength){this.buffers.splice(e,1),e--;continue}else l.warn("MultiBufferStream","Buffer (fileStart: "+r.fileStart+" - Length: "+r.byteLength+") already appended, ignoring");else r.fileStart+r.byteLength<=i.fileStart||(r=this.reduceBuffer(r,0,i.fileStart-r.fileStart)),l.debug("MultiBufferStream","Appending new buffer (fileStart: "+r.fileStart+" - Length: "+r.byteLength+")"),this.buffers.splice(e,0,r),e===0&&(this.buffer=r);t=!1;break}else if(r.fileStart<i.fileStart+i.byteLength){const s=i.fileStart+i.byteLength-r.fileStart,n=r.byteLength-s;if(n>0)r=this.reduceBuffer(r,s,n);else{t=!1;break}}}t&&(l.debug("MultiBufferStream","Appending new buffer (fileStart: "+r.fileStart+" - Length: "+r.byteLength+")"),this.buffers.push(r),e===0&&(this.buffer=r))}logBufferLevel(r){const t=[];let e="",i,s=0,n=0;for(let o=0;o<this.buffers.length;o++){const h=this.buffers[o];o===0?(i={start:h.fileStart,end:h.fileStart+h.byteLength},t.push(i),e+="["+i.start+"-"):i.end===h.fileStart?i.end=h.fileStart+h.byteLength:(i={start:h.fileStart,end:h.fileStart+h.byteLength},e+=t[t.length-1].end-1+"], ["+i.start+"-",t.push(i)),s+=h.usedBytes,n+=h.byteLength}t.length>0&&(e+=i.end-1+"]");const a=r?l.info:l.debug;this.buffers.length===0?a("MultiBufferStream","No more buffer in memory"):a("MultiBufferStream",""+this.buffers.length+" stored buffer(s) ("+s+"/"+n+" bytes), continuous ranges: "+e)}cleanBuffers(){for(let r=0;r<this.buffers.length;r++){const t=this.buffers[r];t.usedBytes===t.byteLength&&(l.debug("MultiBufferStream","Removing buffer #"+r),this.buffers.splice(r,1),r--)}}mergeNextBuffer(){if(this.bufferIndex+1<this.buffers.length){const r=this.buffers[this.bufferIndex+1];if(r.fileStart===this.buffer.fileStart+this.buffer.byteLength){const t=this.buffer.byteLength,e=this.buffer.usedBytes,i=this.buffer.fileStart;return this.buffers[this.bufferIndex]=co(this.buffer,r),this.buffer=this.buffers[this.bufferIndex],this.buffers.splice(this.bufferIndex+1,1),this.buffer.usedBytes=e,this.buffer.fileStart=i,l.debug("ISOFile","Concatenating buffer for box parsing (length: "+t+"->"+this.buffer.byteLength+")"),!0}else return!1}else return!1}findPosition(r,t,e){let i=-1,s=r===!0?0:this.bufferIndex;for(;s<this.buffers.length;){const a=this.buffers[s];if(a&&a.fileStart<=t)i=s,e&&(a.fileStart+a.byteLength<=t?a.usedBytes=a.byteLength:a.usedBytes=t-a.fileStart,this.logBufferLevel());else break;s++}if(i===-1)return-1;const n=this.buffers[i];return n.fileStart+n.byteLength>=t?(l.debug("MultiBufferStream","Found position in existing buffer #"+i),i):-1}findEndContiguousBuf(r){const t=r!==void 0?r:this.bufferIndex;let e=this.buffers[t];if(this.buffers.length>t+1)for(let i=t+1;i<this.buffers.length;i++){const s=this.buffers[i];if(s.fileStart===e.fileStart+e.byteLength)e=s;else break}return e.fileStart+e.byteLength}getEndFilePositionAfter(r){const t=this.findPosition(!0,r,!1);return t!==-1?this.findEndContiguousBuf(t):r}addUsedBytes(r){this.buffer.usedBytes+=r,this.logBufferLevel()}setAllUsedBytes(){this.buffer.usedBytes=this.buffer.byteLength,this.logBufferLevel()}seek(r,t,e){const i=this.findPosition(t,r,e);return i!==-1?(this.buffer=this.buffers[i],this.bufferIndex=i,this.position=r-this.buffer.fileStart,l.debug("MultiBufferStream","Repositioning parser at buffer position: "+this.position),!0):(l.debug("MultiBufferStream","Position "+r+" not found in buffered data"),!1)}getPosition(){return this.bufferIndex===-1||this.buffers[this.bufferIndex]===void 0?0:this.buffers[this.bufferIndex].fileStart+this.position}getLength(){return this.byteLength}getEndPosition(){return this.bufferIndex===-1||this.buffers[this.bufferIndex]===void 0?0:this.buffers[this.bufferIndex].fileStart+this.byteLength}getAbsoluteEndPosition(){if(this.buffers.length===0)return 0;const r=this.buffers[this.buffers.length-1];return r.fileStart+r.byteLength}},xn,et,p=(et=class{constructor(t=0){Mn(this,xn);this.size=t}get type(){var t;return(t=this.constructor.fourcc)!=null?t:Zn(this,xn)}set type(t){ta(this,xn,t)}addBox(t){return this.boxes||(this.boxes=[]),this.boxes.push(t),this[t.type+"s"]?this[t.type+"s"].push(t):this[t.type]=t,t}set(t,e){return this[t]=e,this}addEntry(t,e){const i=e||"entries";return this[i]||(this[i]=[]),this[i].push(t),this}writeHeader(t,e){if(this.size+=8,(this.size>w||this.original_size===1)&&(this.size+=8),this.type==="uuid"&&(this.size+=16),l.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.original_size===0?t.writeUint32(0):this.size>w||this.original_size===1?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,void 0,4),this.type==="uuid"){const i=new Uint8Array(16);for(let s=0;s<16;s++)i[s]=parseInt(this.uuid.substring(s*2,s*2+2),16);t.writeUint8Array(i)}(this.size>w||this.original_size===1)&&(this.sizePosition=t.getPosition(),t.writeUint64(this.size))}write(t){if(this.type==="mdat"){const e=this;if(e.stream){this.size=e.stream.getAbsoluteEndPosition(),this.writeHeader(t);for(const i of e.stream.buffers){const s=new Uint8Array(i);t.writeUint8Array(s)}}else e.data&&(this.size=e.data.length,this.writeHeader(t),t.writeUint8Array(e.data))}else this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data)}printHeader(t){this.size+=8,this.size>w&&(this.size+=8),this.type==="uuid"&&(this.size+=16),t.log(t.indent+"size:"+this.size),t.log(t.indent+"type:"+this.type)}print(t){this.printHeader(t)}parse(t){this.type!=="mdat"?this.data=t.readUint8Array(this.size-this.hdr_size):this.size===0?t.seek(t.getEndPosition()):t.seek(this.start+this.size)}parseDataAndRewind(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.seek(this.start+this.hdr_size)}parseLanguage(t){this.language=t.readUint16();const e=[];e[0]=this.language>>10&31,e[1]=this.language>>5&31,e[2]=this.language&31,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)}computeSize(t){const e=t||new Z;this.write(e)}isEndOfBox(t){const e=t.getPosition(),i=this.start+this.size;return e===i}},xn=new WeakMap,et.registryId=Symbol.for("BoxIdentifier"),et),d=class extends p{constructor(){super(...arguments),this.flags=0,this.version=0}writeHeader(r){this.size+=4,super.writeHeader(r," v="+this.version+" f="+this.flags),r.writeUint8(this.version),r.writeUint24(this.flags)}printHeader(r){this.size+=4,super.printHeader(r),r.log(r.indent+"version:"+this.version),r.log(r.indent+"flags:"+this.flags)}parseDataAndRewind(r){this.parseFullHeader(r),this.data=r.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,r.seek(this.start+this.hdr_size)}parseFullHeader(r){this.version=r.readUint8(),this.flags=r.readUint24(),this.hdr_size+=4}parse(r){this.parseFullHeader(r),this.data=r.readUint8Array(this.size-this.hdr_size)}},it,B=(it=class{constructor(t){this.grouping_type=t}write(t){t.writeUint8Array(this.data)}parse(t){l.warn("BoxParser",`Unknown sample group type: '${this.grouping_type}'`),this.data=t.readUint8Array(this.description_length)}},it.registryId=Symbol.for("SampleGroupEntryIdentifier"),it),da=class extends d{parse(r){this.parseFullHeader(r),this.track_group_id=r.readUint32()}},fa=class extends p{constructor(r,t,e,i,s){super(t),this.box_name=e,this.hdr_size=i,this.start=s,this.type=r}parse(r){this.from_item_ID=r.readUint16();const t=r.readUint16();this.references=[];for(let e=0;e<t;e++)this.references[e]={to_item_ID:r.readUint16()}}},ua=class extends p{constructor(r,t,e,i,s){super(t),this.box_name=e,this.hdr_size=i,this.start=s,this.type=r}parse(r){this.from_item_ID=r.readUint32();const t=r.readUint16();this.references=[];for(let e=0;e<t;e++)this.references[e]={to_item_ID:r.readUint32()}}},pa=class extends p{constructor(r,t,e,i){super(t),this.hdr_size=e,this.start=i,this.type=r}parse(r){this.track_ids=r.readUint32Array((this.size-this.hdr_size)/4)}write(r){this.size=this.track_ids.length*4,this.writeHeader(r),r.writeUint32Array(this.track_ids)}},An=["boxes","entries","references","subsamples","items","item_infos","extents","associations","subsegments","ranges","seekLists","seekPoints","esd","levels"],_a=["compatible_brands","matrix","opcolor","sample_counts","sample_deltas","first_chunk","samples_per_chunk","sample_sizes","chunk_offsets","sample_offsets","sample_description_index","sample_duration"];function ma(r,t){if(r&&!t)return!1;let e;for(e in r)if(!An.find(i=>i===e)){if(r[e]instanceof p||t[e]instanceof p)continue;if(typeof r[e]=="undefined"||typeof t[e]=="undefined")continue;if(typeof r[e]=="function"||typeof t[e]=="function")continue;if("subBoxNames"in r&&r.subBoxNames.indexOf(e.slice(0,4))>-1||"subBoxNames"in t&&t.subBoxNames.indexOf(e.slice(0,4))>-1)continue;if(e==="data"||e==="start"||e==="size"||e==="creation_time"||e==="modification_time")continue;if(_a.find(i=>i===e))continue;if(r[e]!==t[e])return!1}return!0}function Wn(r,t){if(!ma(r,t))return!1;for(let e=0;e<An.length;e++){const i=An[e];if(r[i]&&t[i]&&!Wn(r[i],t[i]))return!1}return!0}function Kn(r){let t=r;for(;t;){if("registryId"in t)return t.registryId;t=Object.getPrototypeOf(t)}}var lo=r=>{const t=Symbol.for("SampleGroupEntryIdentifier");return Kn(r)===t},fo=r=>{const t=Symbol.for("SampleEntryIdentifier");return Kn(r)===t},uo=r=>{const t=Symbol.for("BoxIdentifier");return Kn(r)===t},C={uuid:{},sampleEntry:{},sampleGroupEntry:{},box:{}};function po(r){const t={uuid:{},sampleEntry:{},sampleGroupEntry:{},box:{}};for(const[e,i]of Object.entries(r)){if(lo(i)){const s="grouping_type"in i?i.grouping_type:void 0;if(!s)throw new Error(`SampleGroupEntry class ${e} does not have a valid static grouping_type. Please ensure it is defined correctly.`);if(s in t.sampleGroupEntry)throw new Error(`SampleGroupEntry class ${e} has a grouping_type that is already registered. Please ensure it is unique.`);t.sampleGroupEntry[s]=i;continue}if(fo(i)){const s="fourcc"in i?i.fourcc:void 0;if(!s)throw new Error(`SampleEntry class ${e} does not have a valid static fourcc. Please ensure it is defined correctly.`);if(s in t.sampleEntry)throw new Error(`SampleEntry class ${e} has a fourcc that is already registered. Please ensure it is unique.`);t.sampleEntry[s]=i;continue}if(uo(i)){const s="fourcc"in i?i.fourcc:void 0,n="uuid"in i?i.uuid:void 0;if(s==="uuid"){if(!n)throw new Error(`Box class ${e} has a fourcc of 'uuid' but does not have a valid uuid. Please ensure it is defined correctly.`);if(n in t.uuid)throw new Error(`Box class ${e} has a uuid that is already registered. Please ensure it is unique.`);t.uuid[n]=i;continue}t.box[s]=i;continue}throw new Error(`Box class ${e} does not have a valid static fourcc, uuid, or grouping_type. Please ensure it is defined correctly.`)}return C.uuid={...t.uuid},C.sampleEntry={...t.sampleEntry},C.sampleGroupEntry={...t.sampleGroupEntry},C.box={...t.box},C}var Fn={};function _o(r){return Object.entries(r).forEach(([t,e])=>Fn[t]=e),Fn}function mo(r){return Q(r)}function Q(r){let t="";for(let e=0;e<16;e++){const i=r.readUint8().toString(16);t+=i.length===1?"0"+i:i}return t}function H(r,t,e){let i,s;const n=r.getPosition();let a=0,o;if(r.getEndPosition()-n<8)return l.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:j};if(e&&e<8)return l.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:j};let h=r.readUint32();const c=r.readString(4);if(c.length!==4||!/^[\x20-\x7E]{4}$/.test(c))return l.error("BoxParser",`Invalid box type: '${c}'`),{code:ha,start:n,type:c};let f=c;if(l.debug("BoxParser","Found box of type '"+c+"' and size "+h+" at position "+n),a=8,c==="uuid"){if(r.getEndPosition()-r.getPosition()<16||e-a<16)return r.seek(n),l.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:j};o=mo(r),a+=16,f=o}if(h===1){if(r.getEndPosition()-r.getPosition()<8||e&&e-a<8)return r.seek(n),l.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+c+'" box'),{code:j};s=h,h=r.readUint64(),a+=8}else if(h===0){if(e)h=e;else if(c!=="mdat")return l.error("BoxParser","Unlimited box size not supported for type: '"+c+"'"),i=new p(h),i.type=c,{code:D,box:i,size:i.size}}if(h!==0&&h<a)return l.error("BoxParser","Box of type "+c+" has an invalid size "+h+" (too small to be a box)"),{code:j,type:c,size:h,hdr_size:a,start:n};if(h!==0&&e&&h>e)return l.error("BoxParser","Box of type '"+c+"' has a size "+h+" greater than its container size "+e),{code:j,type:c,size:h,hdr_size:a,start:n};if(h!==0&&n+h>r.getEndPosition())return r.seek(n),l.info("BoxParser","Not enough data in stream to parse the entire '"+c+"' box"),{code:j,type:c,size:h,hdr_size:a,start:n,original_size:s};if(t)return{code:D,type:c,size:h,hdr_size:a,start:n};c in C.box?i=new C.box[c](h):c!=="uuid"?(l.warn("BoxParser",`Unknown box type: '${c}'`),i=new p(h),i.type=c,i.has_unparsed_data=!0):o in C.uuid?i=new C.uuid[o](h):(l.warn("BoxParser",`Unknown UUID box type: '${o}'`),i=new p(h),i.type=c,i.uuid=o,i.has_unparsed_data=!0),i.original_size=s,i.hdr_size=a,i.start=n,i.write===p.prototype.write&&i.type!=="mdat"&&(l.info("BoxParser","'"+f+"' box writing not yet implemented, keeping unparsed data in memory for later write"),i.parseDataAndRewind(r)),i.parse(r);const u=r.getPosition()-(i.start+i.size);return u<0?(l.warn("BoxParser","Parsing of box '"+f+"' did not read the entire indicated box data size (missing "+-u+" bytes), seeking forward"),r.seek(i.start+i.size)):u>0&&i.size!==0&&(l.error("BoxParser","Parsing of box '"+f+"' read "+u+" more bytes than the indicated box data size, seeking backwards"),r.seek(i.start+i.size)),{code:D,box:i,size:i.size}}var y=class extends p{write(r){if(this.size=0,this.writeHeader(r),this.boxes)for(let t=0;t<this.boxes.length;t++)this.boxes[t]&&(this.boxes[t].write(r),this.size+=this.boxes[t].size);l.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),r.adjustUint32(this.sizePosition,this.size)}print(r){this.printHeader(r);for(let t=0;t<this.boxes.length;t++)if(this.boxes[t]){const e=r.indent;r.indent+=" ",this.boxes[t].print(r),r.indent=e}}parse(r){let t;for(;r.getPosition()<this.start+this.size;)if(t=H(r,!1,this.size-(r.getPosition()-this.start)),t.code===D){const e=t.box;if(this.boxes||(this.boxes=[]),this.boxes.push(e),this.subBoxNames&&this.subBoxNames.indexOf(e.type)!==-1){const i=this.subBoxNames[this.subBoxNames.indexOf(e.type)]+"s";this[i]||(this[i]=[]),this[i].push(e)}else{const i=e.type!=="uuid"?e.type:e.uuid;this[i]?l.warn("ContainerBox",`Box of type ${i} already exists in container box ${this.type}.`):this[i]=e}}else return}},st,M=(st=class extends y{constructor(t,e,i){super(t),this.hdr_size=e,this.start=i}isVideo(){return!1}isAudio(){return!1}isSubtitle(){return!1}isMetadata(){return!1}isHint(){return!1}getCodec(){return this.type.replace(".","")}getWidth(){return""}getHeight(){return""}getChannelCount(){return""}getSampleRate(){return""}getSampleSize(){return""}parseHeader(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8}parse(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)}parseDataAndRewind(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.seek(this.start+this.hdr_size)}parseFooter(t){super.parse(t)}writeHeader(t){this.size=8,super.writeHeader(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)}writeFooter(t){if(this.boxes)for(let 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)}write(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)}},st.registryId=Symbol.for("SampleEntryIdentifier"),st),jn=class extends M{},J=class extends M{isMetadata(){return!0}},W=class extends M{isSubtitle(){return!0}},ga=class extends M{},S=class extends M{parse(r){this.parseHeader(r),r.readUint16(),r.readUint16(),r.readUint32Array(3),this.width=r.readUint16(),this.height=r.readUint16(),this.horizresolution=r.readUint32(),this.vertresolution=r.readUint32(),r.readUint32(),this.frame_count=r.readUint16();const t=Math.min(31,r.readUint8());this.compressorname=r.readString(t),t<31&&r.readString(31-t),this.depth=r.readUint16(),r.readUint16(),this.parseFooter(r)}isVideo(){return!0}getWidth(){return this.width}getHeight(){return this.height}write(r){this.writeHeader(r),this.size+=70,r.writeUint16(0),r.writeUint16(0),r.writeUint32(0),r.writeUint32(0),r.writeUint32(0),r.writeUint16(this.width),r.writeUint16(this.height),r.writeUint32(this.horizresolution),r.writeUint32(this.vertresolution),r.writeUint32(0),r.writeUint16(this.frame_count),r.writeUint8(Math.min(31,this.compressorname.length)),r.writeString(this.compressorname,void 0,31),r.writeUint16(this.depth),r.writeInt16(-1),this.writeFooter(r)}},A=class extends M{parse(r){var e,i;this.parseHeader(r),this.version=r.readUint16(),r.readUint16(),r.readUint32(),this.channel_count=r.readUint16(),this.samplesize=r.readUint16(),r.readUint16(),r.readUint16(),this.samplerate=r.readUint32()/65536,((i=(e=r.isofile)==null?void 0:e.ftyp)==null?void 0:i.major_brand.includes("qt"))&&(this.version===1?this.extensions=r.readUint8Array(16):this.version===2&&(this.extensions=r.readUint8Array(36))),this.parseFooter(r)}isAudio(){return!0}getChannelCount(){return this.channel_count}getSampleRate(){return this.samplerate}getSampleSize(){return this.samplesize}write(r){this.writeHeader(r),this.size+=20,r.writeUint32(0),r.writeUint32(0),r.writeUint16(this.channel_count),r.writeUint16(this.samplesize),r.writeUint16(0),r.writeUint16(0),r.writeUint32(this.samplerate<<16),this.writeFooter(r)}},Dn=class extends M{parse(r){this.parseHeader(r),this.parseFooter(r)}write(r){this.writeHeader(r),this.writeFooter(r)}},aa=class extends Array{toString(){let r="<table class='inner-table'>";r+="<thead><tr><th>length</th><th>nalu_data</th></tr></thead>",r+="<tbody>";for(let t=0;t<this.length;t++){const e=this[t];r+="<tr>",r+="<td>"+e.length+"</td>",r+="<td>",r+=e.data.reduce(function(i,s){return i+s.toString(16).padStart(2,"0")},"0x"),r+="</td></tr>"}return r+="</tbody></table>",r}},rt,xa=(rt=class extends p{constructor(){super(...arguments),this.box_name="AVCConfigurationBox"}parse(t){this.configurationVersion=t.readUint8(),this.AVCProfileIndication=t.readUint8(),this.profile_compatibility=t.readUint8(),this.AVCLevelIndication=t.readUint8(),this.lengthSizeMinusOne=t.readUint8()&3,this.nb_SPS_nalus=t.readUint8()&31;let e=this.size-this.hdr_size-6;this.SPS=new aa;for(let i=0;i<this.nb_SPS_nalus;i++){const s=t.readUint16();this.SPS.push({length:s,data:t.readUint8Array(s)}),e-=2+s}this.nb_PPS_nalus=t.readUint8(),e--,this.PPS=new aa;for(let i=0;i<this.nb_PPS_nalus;i++){const s=t.readUint16();this.PPS.push({length:s,data:t.readUint8Array(s)}),e-=2+s}e>0&&(this.ext=t.readUint8Array(e))}write(t){this.size=7;for(let e=0;e<this.SPS.length;e++)this.size+=2+this.SPS[e].length;for(let e=0;e<this.PPS.length;e++)this.size+=2+this.PPS[e].length;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);for(let e=0;e<this.SPS.length;e++)t.writeUint16(this.SPS[e].length),t.writeUint8Array(this.SPS[e].data);t.writeUint8(this.PPS.length);for(let e=0;e<this.PPS.length;e++)t.writeUint16(this.PPS[e].length),t.writeUint8Array(this.PPS[e].data);this.ext&&t.writeUint8Array(this.ext)}},rt.fourcc="avcC",rt),nt,kn=(nt=class extends p{constructor(){super(...arguments),this.box_name="MediaDataBox"}},nt.fourcc="mdat",nt),at,go=(at=class extends p{constructor(){super(...arguments),this.box_name="ItemDataBox"}},at.fourcc="idat",at),ot,xo=(ot=class extends p{constructor(){super(...arguments),this.box_name="FreeSpaceBox"}},ot.fourcc="free",ot),ht,yo=(ht=class extends p{constructor(){super(...arguments),this.box_name="FreeSpaceBox"}},ht.fourcc="skip",ht),ct,ya=(ct=class extends d{constructor(){super(...arguments),this.box_name="HintMediaHeaderBox"}},ct.fourcc="hmhd",ct),lt,In=(lt=class extends d{constructor(){super(...arguments),this.box_name="NullMediaHeaderBox"}},lt.fourcc="nmhd",lt),dt,bo=(dt=class extends d{constructor(){super(...arguments),this.box_name="ObjectDescriptorBox"}},dt.fourcc="iods",dt),ft,vo=(ft=class extends d{constructor(){super(...arguments),this.box_name="XMLBox"}},ft.fourcc="xml ",ft),ut,So=(ut=class extends d{constructor(){super(...arguments),this.box_name="BinaryXMLBox"}},ut.fourcc="bxml",ut),pt,Uo=(pt=class extends d{constructor(){super(...arguments),this.box_name="ItemProtectionBox",this.sinfs=[]}get protections(){return this.sinfs}},pt.fourcc="ipro",pt),_t,$n=(_t=class extends y{constructor(){super(...arguments),this.box_name="MovieBox",this.traks=[],this.psshs=[],this.subBoxNames=["trak","pssh"]}},_t.fourcc="moov",_t),mt,ba=(mt=class extends y{constructor(){super(...arguments),this.box_name="TrackBox",this.samples=[]}},mt.fourcc="trak",mt),gt,Bo=(gt=class extends y{constructor(){super(...arguments),this.box_name="EditBox"}},gt.fourcc="edts",gt),xt,va=(xt=class extends y{constructor(){super(...arguments),this.box_name="MediaBox"}},xt.fourcc="mdia",xt),yt,Sa=(yt=class extends y{constructor(){super(...arguments),this.box_name="MediaInformationBox"}},yt.fourcc="minf",yt),bt,Ua=(bt=class extends y{constructor(){super(...arguments),this.box_name="DataInformationBox"}},bt.fourcc="dinf",bt),vt,Ba=(vt=class extends y{constructor(){super(...arguments),this.box_name="SampleTableBox",this.sgpds=[],this.sbgps=[],this.subBoxNames=["sgpd","sbgp"]}},vt.fourcc="stbl",vt),St,qn=(St=class extends y{constructor(){super(...arguments),this.box_name="MovieExtendsBox",this.trexs=[],this.subBoxNames=["trex"]}},St.fourcc="mvex",St),Ut,wa=(Ut=class extends y{constructor(){super(...arguments),this.box_name="MovieFragmentBox",this.trafs=[],this.subBoxNames=["traf"]}},Ut.fourcc="moof",Ut),Bt,za=(Bt=class extends y{constructor(){super(...arguments),this.box_name="TrackFragmentBox",this.truns=[],this.sgpds=[],this.sbgps=[],this.subBoxNames=["trun","sgpd","sbgp"]}},Bt.fourcc="traf",Bt),wt,wo=(wt=class extends y{constructor(){super(...arguments),this.box_name="VTTCueBox"}},wt.fourcc="vttc",wt),zt,zo=(zt=class extends y{constructor(){super(...arguments),this.box_name="MovieFragmentRandomAccessBox",this.tfras=[],this.subBoxNames=["tfra"]}},zt.fourcc="mfra",zt),Et,Eo=(Et=class extends y{constructor(){super(...arguments),this.box_name="AdditionalMetadataContainerBox"}},Et.fourcc="meco",Et),kt,ko=(kt=class extends y{constructor(){super(...arguments),this.box_name="trackhintinformation",this.subBoxNames=["sdp ","rtp "]}},kt.fourcc="hnti",kt),It,Io=(It=class extends y{constructor(){super(...arguments),this.box_name="hintstatisticsbox",this.maxrs=[],this.subBoxNames=["maxr"]}},It.fourcc="hinf",It),Tt,To=(Tt=class extends y{constructor(){super(...arguments),this.box_name="SubTrackBox"}},Tt.fourcc="strk",Tt),Pt,Po=(Pt=class extends y{constructor(){super(...arguments),this.box_name="SubTrackDefinitionBox"}},Pt.fourcc="strd",Pt),At,Ao=(At=class extends y{constructor(){super(...arguments),this.box_name="ProtectionSchemeInfoBox"}},At.fourcc="sinf",At),Ft,Fo=(Ft=class extends y{constructor(){super(...arguments),this.box_name="RestrictedSchemeInfoBox"}},Ft.fourcc="rinf",Ft),Ct,Co=(Ct=class extends y{constructor(){super(...arguments),this.box_name="SchemeInformationBox"}},Ct.fourcc="schi",Ct),Dt,Do=(Dt=class extends y{constructor(){super(...arguments),this.box_name="TrackGroupBox"}},Dt.fourcc="trgr",Dt),Lt,Lo=(Lt=class extends y{constructor(){super(...arguments),this.box_name="UserDataBox",this.kinds=[],this.strks=[],this.subBoxNames=["kind","strk"]}},Lt.fourcc="udta",Lt),Ht,Ho=(Ht=class extends y{constructor(){super(...arguments),this.box_name="ItemPropertiesBox",this.ipmas=[],this.subBoxNames=["ipma"]}},Ht.fourcc="iprp",Ht),Ot,Oo=(Ot=class extends y{constructor(){super(...arguments),this.box_name="ItemPropertyContainerBox",this.hvcCs=[],this.ispes=[],this.claps=[],this.irots=[],this.subBoxNames=["hvcC","ispe","clap","irot"]}},Ot.fourcc="ipco",Ot),Rt,Ro=(Rt=class extends y{constructor(){super(...arguments),this.box_name="GroupsListBox"}},Rt.fourcc="grpl",Rt),Mt,Mo=(Mt=class extends y{constructor(){super(...arguments),this.box_name="J2KHeaderInfoBox"}},Mt.fourcc="j2kH",Mt),Nt,No=(Nt=class extends y{constructor(){super(...arguments),this.box_name="ExtendedTypeBox",this.tycos=[],this.subBoxNames=["tyco"]}},Nt.fourcc="etyp",Nt),Gt,Go=(Gt=class extends y{constructor(){super(...arguments),this.box_name="ProjectedOmniVideoBox",this.subBoxNames=["prfr"]}},Gt.fourcc="povd",Gt),Vt,Ea=(Vt=class extends d{constructor(){super(...arguments),this.box_name="DataReferenceBox"}parse(t){this.parseFullHeader(t),this.entries=[];const e=t.readUint32();for(let i=0;i<e;i++){const s=H(t,!1,this.size-(t.getPosition()-this.start));if(s.code===D){const n=s.box;this.entries.push(n)}else return}}write(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.entries.length);for(let 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)}},Vt.fourcc="dref",Vt),jt,ka=(jt=class extends d{constructor(){super(...arguments),this.box_name="ExtendedLanguageBox"}parse(t){this.parseFullHeader(t),this.extended_language=t.readString(this.size-this.hdr_size)}write(t){this.version=0,this.flags=0,this.size=this.extended_language.length,this.writeHeader(t),t.writeString(this.extended_language)}},jt.fourcc="elng",jt),$t,Ia=($t=class extends p{constructor(){super(...arguments),this.box_name="FileTypeBox"}parse(t){let e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];let i=0;for(;e>=4;)this.compatible_brands[i]=t.readString(4),e-=4,i++}write(t){this.size=8+4*this.compatible_brands.length,this.writeHeader(t),t.writeString(this.major_brand,void 0,4),t.writeUint32(this.minor_version);for(let e=0;e<this.compatible_brands.length;e++)t.writeString(this.compatible_brands[e],void 0,4)}},$t.fourcc="ftyp",$t),qt,Ta=(qt=class extends d{constructor(){super(...arguments),this.box_name="HandlerBox"}parse(t){if(this.parseFullHeader(t),this.version===0&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),!this.isEndOfBox(t))){const e=this.start+this.size-t.getPosition();this.name=t.readCString();const i=this.start+this.size-1;t.seek(i),t.readUint8()!==0&&e>1&&(l.info("BoxParser","Warning: hdlr name is not null-terminated, possibly length-prefixed string. Trimming first byte."),this.name=this.name.slice(1))}}write(t){this.size=20+this.name.length+1,this.version=0,this.flags=0,this.writeHeader(t),t.writeUint32(0),t.writeString(this.handler,void 0,4),t.writeUint32Array([0,0,0]),t.writeCString(this.name)}},qt.fourcc="hdlr",qt),Yt,Pa=(Yt=class extends p{constructor(){super(...arguments),this.box_name="HEVCConfigurationBox"}parse(t){this.configurationVersion=t.readUint8();let e=t.readUint8();this.general_profile_space=e>>6,this.general_tier_flag=(e&32)>>5,this.general_profile_idc=e&31,this.general_profile_compatibility=t.readUint32(),this.general_constraint_indicator=t.readUint8Array(6),this.general_level_idc=t.readUint8(),this.min_spatial_segmentation_idc=t.readUint16()&4095,this.parallelismType=t.readUint8()&3,this.chroma_format_idc=t.readUint8()&3,this.bit_depth_luma_minus8=t.readUint8()&7,this.bit_depth_chroma_minus8=t.readUint8()&7,this.avgFrameRate=t.readUint16(),e=t.readUint8(),this.constantFrameRate=e>>6,this.numTemporalLayers=(e&13)>>3,this.temporalIdNested=(e&4)>>2,this.lengthSizeMinusOne=e&3,this.nalu_arrays=[];const i=t.readUint8();for(let s=0;s<i;s++){const n=[];this.nalu_arrays.push(n),e=t.readUint8(),n.completeness=(e&128)>>7,n.nalu_type=e&63;const a=t.readUint16();for(let o=0;o<a;o++){const h=t.readUint16();n.push({data:t.readUint8Array(h)})}}}write(t){this.size=23;for(let e=0;e<this.nalu_arrays.length;e++){this.size+=3;for(let i=0;i<this.nalu_arrays[e].length;i++)this.size+=2+this.nalu_arrays[e][i].data.length}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+(15<<24)),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);for(let e=0;e<this.nalu_arrays.length;e++){t.writeUint8((this.nalu_arrays[e].completeness<<7)+this.nalu_arrays[e].nalu_type),t.writeUint16(this.nalu_arrays[e].length);for(let i=0;i<this.nalu_arrays[e].length;i++)t.writeUint16(this.nalu_arrays[e][i].data.length),t.writeUint8Array(this.nalu_arrays[e][i].data)}}},Yt.fourcc="hvcC",Yt),Wt,Aa=(Wt=class extends d{constructor(){super(...arguments),this.box_name="MediaHeaderBox"}parse(t){this.parseFullHeader(t),this.version===1?(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()}write(t){const e=this.modification_time>w||this.creation_time>w||this.duration>w||this.version===1;this.version=e?1:0,this.size=20,this.size+=e?12:0,this.flags=0,this.writeHeader(t),e?(t.writeUint64(this.creation_time),t.writeUint64(this.modification_time),t.writeUint32(this.timescale),t.writeUint64(this.duration)):(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)}},Wt.fourcc="mdhd",Wt),Kt,Fa=(Kt=class extends d{constructor(){super(...arguments),this.box_name="MovieExtendsHeaderBox"}parse(t){this.parseFullHeader(t),this.flags&1&&(l.warn("BoxParser","mehd box incorrectly uses flags set to 1, converting version to 1"),this.version=1),this.version===1?this.fragment_duration=t.readUint64():this.fragment_duration=t.readUint32()}write(t){const e=this.fragment_duration>w||this.version===1;this.version=e?1:0,this.size=4,this.size+=e?4:0,this.flags=0,this.writeHeader(t),e?t.writeUint64(this.fragment_duration):t.writeUint32(this.fragment_duration)}},Kt.fourcc="mehd",Kt),Xt,Vo=(Xt=class extends d{constructor(){super(...arguments),this.box_name="ItemInfoEntry"}parse(t){if(this.parseFullHeader(t),(this.version===0||this.version===1)&&(this.item_ID=t.readUint16(),this.item_protection_index=t.readUint16(),this.item_name=t.readCString(),this.content_type=t.readCString(),this.isEndOfBox(t)||(this.content_encoding=t.readCString())),this.version===1){this.extension_type=t.readString(4),l.warn("BoxParser","Cannot parse extension type"),t.seek(this.start+this.size);return}this.version>=2&&(this.version===2?this.item_ID=t.readUint16():this.version===3&&(this.item_ID=t.readUint32()),this.item_protection_index=t.readUint16(),this.item_type=t.readString(4),this.item_name=t.readCString(),this.item_type==="mime"?(this.content_type=t.readCString(),this.content_encoding=t.readCString()):this.item_type==="uri "&&(this.item_uri_type=t.readCString()))}},Xt.fourcc="infe",Xt),Qt,jo=(Qt=class extends d{constructor(){super(...arguments),this.box_name="ItemInfoBox"}parse(t){this.parseFullHeader(t),this.version===0?this.entry_count=t.readUint16():this.entry_count=t.readUint32(),this.item_infos=[];for(let e=0;e<this.entry_count;e++){const i=H(t,!1,this.size-(t.getPosition()-this.start));if(i.code===D){const s=i.box;s.type==="infe"?this.item_infos[e]=s:l.error("BoxParser","Expected 'infe' box, got "+i.box.type,t.isofile)}else return}}},Qt.fourcc="iinf",Qt),Jt,$o=(Jt=class extends d{constructor(){super(...arguments),this.box_name="ItemLocationBox"}parse(t){this.parseFullHeader(t);let e;e=t.readUint8(),this.offset_size=e>>4&15,this.length_size=e&15,e=t.readUint8(),this.base_offset_size=e>>4&15,this.version===1||this.version===2?this.index_size=e&15:this.index_size=0,this.items=[];let i=0;if(this.version<2)i=t.readUint16();else if(this.version===2)i=t.readUint32();else throw new Error("version of iloc box not supported");for(let s=0;s<i;s++){let n=0,a=0,o=0;if(this.version<2)n=t.readUint16();else if(this.version===2)n=t.readUint32();else throw new Error("version of iloc box not supported");this.version===1||this.version===2?a=t.readUint16()&15:a=0;const h=t.readUint16();switch(this.base_offset_size){case 0:o=0;break;case 4:o=t.readUint32();break;case 8:o=t.readUint64();break;default:throw new Error("Error reading base offset size")}const c=[],f=t.readUint16();for(let u=0;u<f;u++){let _=0,m=0,v=0;if(this.version===1||this.version===2)switch(this.index_size){case 0:_=0;break;case 4:_=t.readUint32();break;case 8:_=t.readUint64();break;default:throw new Error("Error reading extent index")}switch(this.offset_size){case 0:m=0;break;case 4:m=t.readUint32();break;case 8:m=t.readUint64();break;default:throw new Error("Error reading extent index")}switch(this.length_size){case 0:v=0;break;case 4:v=t.readUint32();break;case 8:v=t.readUint64();break;default:throw new Error("Error reading extent index")}c.push({extent_index:_,extent_length:v,extent_offset:m})}this.items.push({base_offset:o,construction_method:a,item_ID:n,data_reference_index:h,extents:c})}}},Jt.fourcc="iloc",Jt),qo={auxl:"Auxiliary image item",base:"Pre-derived image item base",cdsc:"Item describes referenced item",dimg:"Derived image item",dpnd:"Item coding dependency",eroi:"Region",evir:"EVC slice",exbl:"Scalable image item","fdl ":"File delivery",font:"Font item",iloc:"Item data location",mask:"Region mask",mint:"Data integrity",pred:"Predictively coded item",prem:"Pre-multiplied item",tbas:"HEVC tile track base item",text:"Text item",thmb:"Thumbnail image item"},q,Yo=(q=class extends d{constructor(){super(...arguments),this.box_name="ItemReferenceBox",this.references=[]}parse(t){for(this.parseFullHeader(t),this.references=[];t.getPosition()<this.start+this.size;){const e=H(t,!0,this.size-(t.getPosition()-this.start));if(e.code===D){let i="Unknown item reference";q.allowed_types.includes(e.type)?i=qo[e.type]:l.warn("BoxParser",`Unknown item reference type: '${e.type}'`);const s=this.version===0?new fa(e.type,e.size,i,e.hdr_size,e.start):new ua(e.type,e.size,i,e.hdr_size,e.start);s.write===p.prototype.write&&s.type!=="mdat"&&(l.warn("BoxParser",s.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),s.parseDataAndRewind(t)),s.parse(t),this.references.push(s)}else return}}},q.fourcc="iref",q.allowed_types=["auxl","base","cdsc","dimg","dpnd","eroi","evir","exbl","fdl ","font","iloc","mask","mint","pred","prem","tbas","text","thmb"],q),Zt,Wo=(Zt=class extends d{constructor(){super(...arguments),this.box_name="PrimaryItemBox"}parse(t){this.parseFullHeader(t),this.version===0?this.item_id=t.readUint16():this.item_id=t.readUint32()}},Zt.fourcc="pitm",Zt),te,Ko=(te=class extends d{constructor(){super(...arguments),this.box_name="MetaBox",this.isQT=!1}parse(t){const e=t.getPosition();if(this.size>8){switch(t.readUint32(),t.readString(4)){case"hdlr":case"mhdr":case"keys":case"ilst":case"ctry":case"lang":this.isQT=!0;break}t.seek(e)}this.isQT||this.parseFullHeader(t),y.prototype.parse.call(this,t)}},te.fourcc="meta",te),ee,Ca=(ee=class extends d{constructor(){super(...arguments),this.box_name="MovieFragmentHeaderBox"}parse(t){this.parseFullHeader(t),this.sequence_number=t.readUint32()}write(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.sequence_number)}},ee.fourcc="mfhd",ee),ie,Da=(ie=class extends d{constructor(){super(...arguments),this.box_name="MovieHeaderBox"}parse(t){this.parseFullHeader(t),this.version===1?(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.readInt32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()}write(t){const e=this.modification_time>w||this.creation_time>w||this.duration>w||this.version===1;this.version=e?1:0,this.size=96,this.size+=e?12:0,this.flags=0,this.writeHeader(t),e?(t.writeUint64(this.creation_time),t.writeUint64(this.modification_time),t.writeUint32(this.timescale),t.writeUint64(this.duration)):(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.writeInt32Array(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)}print(t){super.printHeader(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)}},ie.fourcc="mvhd",ie),se,Xo=(se=class extends J{parse(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}},se.fourcc="mett",se),re,Qo=(re=class extends J{parse(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.parseFooter(t)}},re.fourcc="metx",re),ne,Jo=(ne=class extends p{constructor(){super(...arguments),this.box_name="AV1CodecConfigurationBox"}parse(t){let e=t.readUint8();if((e>>7&1)!==1){l.error("BoxParser","av1C marker problem",t.isofile);return}if(this.version=e&127,this.version!==1){l.error("BoxParser","av1C version "+this.version+" not supported",t.isofile);return}if(e=t.readUint8(),this.seq_profile=e>>5&7,this.seq_level_idx_0=e&31,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=e&3,e=t.readUint8(),this.reserved_1=e>>5&7,this.reserved_1!==0){l.error("BoxParser","av1C reserved_1 parsing problem",t.isofile);return}if(this.initial_presentation_delay_present=e>>4&1,this.initial_presentation_delay_present===1)this.initial_presentation_delay_minus_one=e&15;else if(this.reserved_2=e&15,this.reserved_2!==0){l.error("BoxParser","av1C reserved_2 parsing problem",t.isofile);return}const i=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(i)}},ne.fourcc="av1C",ne),ae,Zo=(ae=class extends d{constructor(){super(...arguments),this.box_name="ElementaryStreamDescriptorBox"}parse(t){this.parseFullHeader(t);const e=t.readUint8Array(this.size-this.hdr_size);if("MPEG4DescriptorParser"in Fn){const i=new Fn.MPEG4DescriptorParser;this.esd=i.parseOneDescriptor(new z(e.buffer,0))}}},ae.fourcc="esds",ae),oe,th=(oe=class extends d{constructor(){super(...arguments),this.box_name="VPCodecConfigurationRecord"}parse(t){if(this.parseFullHeader(t),this.version===1){this.profile=t.readUint8(),this.level=t.readUint8();const e=t.readUint8();this.bitDepth=e>>4,this.chromaSubsampling=e>>1&7,this.videoFullRangeFlag=e&1,this.colourPrimaries=t.readUint8(),this.transferCharacteristics=t.readUint8(),this.matrixCoefficients=t.readUint8(),this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize)}else{this.profile=t.readUint8(),this.level=t.readUint8();let e=t.readUint8();this.bitDepth=e>>4&15,this.colorSpace=e&15,e=t.readUint8(),this.chromaSubsampling=e>>4&15,this.transferFunction=e>>1&7,this.videoFullRangeFlag=e&1,this.codecIntializationDataSize=t.readUint16(),this.codecIntializationData=t.readUint8Array(this.codecIntializationDataSize)}}},oe.fourcc="vpcC",oe),he,eh=(he=class extends d{constructor(){super(...arguments),this.box_name="VvcConfigurationBox"}parse(t){this.parseFullHeader(t);const e={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(a){this.held_bits=a.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(a){this.held_bits=a.readUint16(),this.num_held_bits=16},extract_bits:function(a){const o=this.held_bits>>this.num_held_bits-a&(1<<a)-1;return this.num_held_bits-=a,o}};if(e.stream_read_1_bytes(t),e.extract_bits(5),this.lengthSizeMinusOne=e.extract_bits(2),this.ptl_present_flag=e.extract_bits(1),this.ptl_present_flag){e.stream_read_2_bytes(t),this.ols_idx=e.extract_bits(9),this.num_sublayers=e.extract_bits(3),this.constant_frame_rate=e.extract_bits(2),this.chroma_format_idc=e.extract_bits(2),e.stream_read_1_bytes(t),this.bit_depth_minus8=e.extract_bits(3),e.extract_bits(5);{if(e.stream_read_2_bytes(t),e.extract_bits(2),this.num_bytes_constraint_info=e.extract_bits(6),this.general_profile_idc=e.extract_bits(7),this.general_tier_flag=e.extract_bits(1),this.general_level_idc=t.readUint8(),e.stream_read_1_bytes(t),this.ptl_frame_only_constraint_flag=e.extract_bits(1),this.ptl_multilayer_enabled_flag=e.extract_bits(1),this.general_constraint_info=new Uint8Array(this.num_bytes_constraint_info),this.num_bytes_constraint_info){for(let a=0;a<this.num_bytes_constraint_info-1;a++){const o=e.extract_bits(6);e.stream_read_1_bytes(t);const h=e.extract_bits(2);this.general_constraint_info[a]=o<<2|h}this.general_constraint_info[this.num_bytes_constraint_info-1]=e.extract_bits(6)}else e.extract_bits(6);if(this.num_sublayers>1){e.stream_read_1_bytes(t),this.ptl_sublayer_present_mask=0;for(let a=this.num_sublayers-2;a>=0;--a){const o=e.extract_bits(1);this.ptl_sublayer_present_mask|=o<<a}for(let a=this.num_sublayers;a<=8&&this.num_sublayers>1;++a)e.extract_bits(1);this.sublayer_level_idc=[];for(let a=this.num_sublayers-2;a>=0;--a)this.ptl_sublayer_present_mask&1<<a&&(this.sublayer_level_idc[a]=t.readUint8())}if(this.ptl_num_sub_profiles=t.readUint8(),this.general_sub_profile_idc=[],this.ptl_num_sub_profiles)for(let a=0;a<this.ptl_num_sub_profiles;a++)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()}const i=12,s=13;this.nalu_arrays=[];const n=t.readUint8();for(let a=0;a<n;a++){const o=[];this.nalu_arrays.push(o),e.stream_read_1_bytes(t),o.completeness=e.extract_bits(1),e.extract_bits(2),o.nalu_type=e.extract_bits(5);let h=1;o.nalu_type!==s&&o.nalu_type!==i&&(h=t.readUint16());for(let c=0;c<h;c++){const f=t.readUint16();o.push({data:t.readUint8Array(f),length:f})}}}},he.fourcc="vvcC",he),ce,ih=(ce=class extends p{constructor(){super(...arguments),this.box_name="ColourInformationBox"}parse(t){if(this.colour_type=t.readString(4),this.colour_type==="nclx"){this.colour_primaries=t.readUint16(),this.transfer_characteristics=t.readUint16(),this.matrix_coefficients=t.readUint16();const e=t.readUint8();this.full_range_flag=e>>7}else this.colour_type==="rICC"?this.ICC_profile=t.readUint8Array(this.size-4):this.colour_type==="prof"&&(this.ICC_profile=t.readUint8Array(this.size-4))}},ce.fourcc="colr",ce);function tt(r,t){let e=Number(r).toString(16);for(t=typeof t=="undefined"?2:t;e.length<t;)e="0"+e;return e}var Ln=class extends S{getCodec(){const r=super.getCodec();return this.avcC?`${r}.${tt(this.avcC.AVCProfileIndication)}${tt(this.avcC.profile_compatibility)}${tt(this.avcC.AVCLevelIndication)}`:r}},le,sh=(le=class extends Ln{constructor(){super(...arguments),this.box_name="AVCSampleEntry"}},le.fourcc="avc1",le),de,rh=(de=class extends Ln{constructor(){super(...arguments),this.box_name="AVC2SampleEntry"}},de.fourcc="avc2",de),fe,nh=(fe=class extends Ln{constructor(){super(...arguments),this.box_name="AVCSampleEntry"}},fe.fourcc="avc3",fe),ue,ah=(ue=class extends Ln{constructor(){super(...arguments),this.box_name="AVC2SampleEntry"}},ue.fourcc="avc4",ue),pe,oh=(pe=class extends S{constructor(){super(...arguments),this.box_name="AV1SampleEntry"}getCodec(){const t=super.getCodec(),e=this.av1C.seq_level_idx_0,i=e<10?"0"+e:e;let s;return this.av1C.seq_profile===2&&this.av1C.high_bitdepth===1?s=this.av1C.twelve_bit===1?"12":"10":this.av1C.seq_profile<=2&&(s=this.av1C.high_bitdepth===1?"10":"08"),t+"."+this.av1C.seq_profile+"."+i+(this.av1C.seq_tier_0?"H":"M")+"."+s}},pe.fourcc="av01",pe),_e,hh=(_e=class extends S{},_e.fourcc="dav1",_e),Hn=class extends S{getCodec(){let r=super.getCodec();if(this.hvcC){switch(r+=".",this.hvcC.general_profile_space){case 0:r+="";break;case 1:r+="A";break;case 2:r+="B";break;case 3:r+="C";break}r+=this.hvcC.general_profile_idc,r+=".";let t=this.hvcC.general_profile_compatibility,e=0;for(let n=0;n<32&&(e|=t&1,n!==31);n++)e<<=1,t>>=1;r+=tt(e,0),r+=".",this.hvcC.general_tier_flag===0?r+="L":r+="H",r+=this.hvcC.general_level_idc;let i=!1,s="";for(let n=5;n>=0;n--)(this.hvcC.general_constraint_indicator[n]||i)&&(s="."+tt(this.hvcC.general_constraint_indicator[n],0)+s,i=!0);r+=s}return r}},me,ch=(me=class extends Hn{constructor(){super(...arguments),this.box_name="HEVCSampleEntry"}},me.fourcc="hvc1",me),ge,lh=(ge=class extends Hn{},ge.fourcc="hvc2",ge),xe,dh=(xe=class extends Hn{constructor(){super(...arguments),this.box_name="HEVCSampleEntry",this.colrs=[],this.subBoxNames=["colr"]}},xe.fourcc="hev1",xe),ye,fh=(ye=class extends Hn{},ye.fourcc="hev2",ye),be,uh=(be=class extends S{constructor(){super(...arguments),this.box_name="HEVCTileSampleSampleEntry"}},be.fourcc="hvt1",be),ve,ph=(ve=class extends S{constructor(){super(...arguments),this.box_name="LHEVCSampleEntry"}},ve.fourcc="lhe1",ve),Se,_h=(Se=class extends S{constructor(){super(...arguments),this.box_name="LHEVCSampleEntry"}},Se.fourcc="lhv1",Se),Ue,mh=(Ue=class extends S{},Ue.fourcc="dvh1",Ue),Be,gh=(Be=class extends S{},Be.fourcc="dvhe",Be),La=class extends S{getCodec(){let r=super.getCodec();if(this.vvcC){r+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?r+=".H":r+=".L",r+=this.vvcC.general_level_idc;let t="";if(this.vvcC.general_constraint_info){const e=[];let i=0;i|=this.vvcC.ptl_frame_only_constraint_flag<<7,i|=this.vvcC.ptl_multilayer_enabled_flag<<6;let s;for(let n=0;n<this.vvcC.general_constraint_info.length;++n)i|=this.vvcC.general_constraint_info[n]>>2&63,e.push(i),i&&(s=n),i=this.vvcC.general_constraint_info[n]>>2&3;if(s===void 0)t=".CA";else{t=".C";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";let a=0,o=0;for(let h=0;h<=s;++h)for(a=a<<8|e[h],o+=8;o>=5;){const c=a>>o-5&31;t+=n[c],o-=5,a&=(1<<o)-1}o&&(a<<=5-o,t+=n[a&31])}}r+=t}return r}},we,xh=(we=class extends La{constructor(){super(...arguments),this.box_name="VvcSampleEntry"}},we.fourcc="vvc1",we),ze,yh=(ze=class extends La{constructor(){super(...arguments),this.box_name="VvcSampleEntry"}},ze.fourcc="vvi1",ze),Ee,bh=(Ee=class extends S{constructor(){super(...arguments),this.box_name="VvcSampleEntry"}},Ee.fourcc="vvs1",Ee),ke,vh=(ke=class extends S{constructor(){super(...arguments),this.box_name="VvcNonVCLSampleEntry"}},ke.fourcc="vvcN",ke),Ha=class extends S{getCodec(){const r=super.getCodec();let t=this.vpcC.level;t===0&&(t="00");let e=this.vpcC.bitDepth;return e===8&&(e="08"),`${r}.0${this.vpcC.profile}.${t}.${e}`}},Ie,Sh=(Ie=class extends Ha{},Ie.fourcc="vp08",Ie),Te,Uh=(Te=class extends Ha{},Te.fourcc="vp09",Te),Pe,Bh=(Pe=class extends S{},Pe.fourcc="avs3",Pe),Ae,wh=(Ae=class extends S{constructor(){super(...arguments),this.box_name="J2KSampleEntry"}},Ae.fourcc="j2ki",Ae),Fe,zh=(Fe=class extends S{},Fe.fourcc="mjp2",Fe),Ce,Eh=(Ce=class extends S{},Ce.fourcc="mjpg",Ce),De,kh=(De=class extends S{constructor(){super(...arguments),this.box_name="UncompressedVideoSampleEntry"}},De.fourcc="uncv",De),Le,Ih=(Le=class extends S{constructor(){super(...arguments),this.box_name="MP4VisualSampleEntry"}},Le.fourcc="mp4v",Le),He,Th=(He=class extends A{constructor(){super(...arguments),this.box_name="MP4AudioSampleEntry"}getCodec(){const t=super.getCodec();if(this.esds&&this.esds.esd){const e=this.esds.esd.getOTI(),i=this.esds.esd.getAudioConfig();return t+"."+tt(e)+(i?"."+i:"")}else return t}},He.fourcc="mp4a",He),Oe,Ph=(Oe=class extends A{},Oe.fourcc="m4ae",Oe),Re,Ah=(Re=class extends A{},Re.fourcc="ac-3",Re),Me,Fh=(Me=class extends A{},Me.fourcc="ac-4",Me),Ne,Ch=(Ne=class extends A{},Ne.fourcc="ec-3",Ne),Ge,Dh=(Ge=class extends A{},Ge.fourcc="Opus",Ge),Ve,Lh=(Ve=class extends A{},Ve.fourcc="mha1",Ve),je,Hh=(je=class extends A{},je.fourcc="mha2",je),$e,Oh=($e=class extends A{},$e.fourcc="mhm1",$e),qe,Rh=(qe=class extends A{},qe.fourcc="mhm2",qe),Ye,Mh=(Ye=class extends A{},Ye.fourcc="fLaC",Ye),We,Nh=(We=class extends S{},We.fourcc="encv",We),Ke,Gh=(Ke=class extends A{},Ke.fourcc="enca",Ke),Xe,Vh=(Xe=class extends W{constructor(){super(...arguments),this.subBoxNames=["sinf"],this.sinfs=[]}},Xe.fourcc="encu",Xe),Qe,jh=(Qe=class extends Dn{constructor(){super(...arguments),this.subBoxNames=["sinf"],this.sinfs=[]}},Qe.fourcc="encs",Qe),Je,$h=(Je=class extends Dn{},Je.fourcc="mp4s",Je),Ze,qh=(Ze=class extends ga{constructor(){super(...arguments),this.subBoxNames=["sinf"],this.sinfs=[]}},Ze.fourcc="enct",Ze),ti,Yh=(ti=class extends J{constructor(){super(...arguments),this.subBoxNames=["sinf"],this.sinfs=[]}},ti.fourcc="encm",ti),ei,Wh=(ei=class extends S{constructor(){super(...arguments),this.box_name="RestrictedVideoSampleEntry"}},ei.fourcc="resv",ei),ii,Kh=(ii=class extends W{parse(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}},ii.fourcc="sbtt",ii),si,Oa=(si=class extends W{parse(t){this.parseHeader(t),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.auxiliary_mime_types=t.readCString(),this.parseFooter(t)}write(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)}},si.fourcc="stpp",si),ri,Xh=(ri=class extends W{parse(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}getCodec(){const t=super.getCodec();return this.mime_format?t+"."+this.mime_format:t}},ri.fourcc="stxt",ri),ni,Qh=(ni=class extends W{parse(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)}},ni.fourcc="tx3g",ni),ai,Jh=(ai=class extends J{parse(t){this.parseHeader(t),this.parseFooter(t)}},ai.fourcc="wvtt",ai),oi,Zh=(oi=class extends d{constructor(){super(...arguments),this.box_name="SampleToGroupBox"}parse(t){this.parseFullHeader(t),this.grouping_type=t.readString(4),this.version===1?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];const e=t.readUint32();for(let i=0;i<e;i++)this.entries.push({sample_count:t.readInt32(),group_description_index:t.readInt32()})}write(t){this.grouping_type_parameter?this.version=1:this.version=0,this.flags=0,this.size=8+8*this.entries.length+(this.version===1?4:0),this.writeHeader(t),t.writeString(this.grouping_type,void 0,4),this.version===1&&t.writeUint32(this.grouping_type_parameter),t.writeUint32(this.entries.length);for(let e=0;e<this.entries.length;e++){const i=this.entries[e];t.writeInt32(i.sample_count),t.writeInt32(i.group_description_index)}}},oi.fourcc="sbgp",oi),hi,tc=(hi=class extends d{constructor(){super(...arguments),this.box_name="SampleDependencyTypeBox"}parse(t){this.parseFullHeader(t);const e=this.size-this.hdr_size;this.is_leading=[],this.sample_depends_on=[],this.sample_is_depended_on=[],this.sample_has_redundancy=[];for(let i=0;i<e;i++){const s=t.readUint8();this.is_leading[i]=s>>6,this.sample_depends_on[i]=s>>4&3,this.sample_is_depended_on[i]=s>>2&3,this.sample_has_redundancy[i]=s&3}}},hi.fourcc="sdtp",hi),ci,ec=(ci=class extends d{constructor(){super(...arguments),this.box_name="SampleGroupDescriptionBox"}parse(t){this.parseFullHeader(t),this.grouping_type=t.readString(4),l.debug("BoxParser","Found Sample Groups of type "+this.grouping_type),this.version===1?this.default_length=t.readUint32():this.default_length=0,this.version>=2&&(this.default_group_description_index=t.readUint32()),this.entries=[];const e=t.readUint32();for(let i=0;i<e;i++){let s;this.grouping_type in C.sampleGroupEntry?s=new C.sampleGroupEntry[this.grouping_type](this.grouping_type):s=new B(this.grouping_type),this.entries.push(s),this.version===1?this.default_length===0?s.description_length=t.readUint32():s.description_length=this.default_length:s.description_length=this.default_length,s.write===B.prototype.write&&(l.info("BoxParser","SampleGroup for type "+this.grouping_type+" writing not yet implemented, keeping unparsed data in memory for later write"),s.data=t.readUint8Array(s.description_length),t.seek(t.getPosition()-s.description_length)),s.parse(t)}}write(t){this.flags=0,this.size=12;for(let e=0;e<this.entries.length;e++){const i=this.entries[e];this.version===1&&(this.default_length===0&&(this.size+=4),this.size+=i.data.length)}this.writeHeader(t),t.writeString(this.grouping_type,void 0,4),this.version===1&&t.writeUint32(this.default_length),this.version>=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length);for(let e=0;e<this.entries.length;e++){const i=this.entries[e];this.version===1&&this.default_length===0&&t.writeUint32(i.description_length),i.write(t)}}},ci.fourcc="sgpd",ci),li,ic=(li=class extends d{constructor(){super(...arguments),this.box_name="CompressedSegmentIndexBox"}parse(t){this.parseFullHeader(t),this.reference_ID=t.readUint32(),this.timescale=t.readUint32(),this.version===0?(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=[];const e=t.readUint16();for(let i=0;i<e;i++){const s=t.readUint32(),n=t.readUint32(),a=t.readUint32();this.references.push({reference_type:s>>31&1,referenced_size:s&2147483647,subsegment_duration:n,starts_with_SAP:a>>31&1,SAP_type:a>>28&7,SAP_delta_time:a&268435455})}}write(t){const e=this.earliest_presentation_time>w||this.first_offset>w||this.version===1;this.version=e?1:0,this.size=12+12*this.references.length,this.size+=e?16:8,this.flags=0,this.writeHeader(t),t.writeUint32(this.reference_ID),t.writeUint32(this.timescale),e?(t.writeUint64(this.earliest_presentation_time),t.writeUint64(this.first_offset)):(t.writeUint32(this.earliest_presentation_time),t.writeUint32(this.first_offset)),t.writeUint16(0),t.writeUint16(this.references.length);for(let i=0;i<this.references.length;i++){const s=this.references[i];t.writeUint32(s.reference_type<<31|s.referenced_size),t.writeUint32(s.subsegment_duration),t.writeUint32(s.starts_with_SAP<<31|s.SAP_type<<28|s.SAP_delta_time)}}},li.fourcc="sidx",li),di,Ra=(di=class extends d{constructor(){super(...arguments),this.box_name="SoundMediaHeaderBox"}parse(t){this.parseFullHeader(t),this.balance=t.readUint16(),t.readUint16()}write(t){this.version=0,this.size=4,this.writeHeader(t),t.writeUint16(this.balance),t.writeUint16(0)}},di.fourcc="smhd",di),fi,Ma=(fi=class extends d{constructor(){super(...arguments),this.box_name="ChunkOffsetBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.chunk_offsets=[],this.version===0)for(let i=0;i<e;i++)this.chunk_offsets.push(t.readUint32())}write(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)}unpack(t){for(let e=0;e<this.chunk_offsets.length;e++)t[e].offset=this.chunk_offsets[e]}},fi.fourcc="stco",fi),ui,Na=(ui=class extends d{constructor(){super(...arguments),this.box_name="SubtitleMediaHeaderBox"}},ui.fourcc="sthd",ui),pi,Ga=(pi=class extends d{constructor(){super(...arguments),this.box_name="SampleToChunkBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.first_chunk=[],this.samples_per_chunk=[],this.sample_description_index=[],this.version===0)for(let i=0;i<e;i++)this.first_chunk.push(t.readUint32()),this.samples_per_chunk.push(t.readUint32()),this.sample_description_index.push(t.readUint32())}write(t){this.version=0,this.flags=0,this.size=4+12*this.first_chunk.length,this.writeHeader(t),t.writeUint32(this.first_chunk.length);for(let 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])}unpack(t){let e=0,i=0;for(let s=0;s<this.first_chunk.length;s++)for(let n=0;n<(s+1<this.first_chunk.length?this.first_chunk[s+1]:1/0);n++){i++;for(let a=0;a<this.samples_per_chunk[s];a++){if(t[e])t[e].description_index=this.sample_description_index[s],t[e].chunk_index=i;else return;e++}}}},pi.fourcc="stsc",pi),_i,Va=(_i=class extends d{constructor(){super(...arguments),this.box_name="SampleDescriptionBox"}parse(t){this.parseFullHeader(t),this.entries=[];const e=t.readUint32();for(let i=1;i<=e;i++){const s=H(t,!0,this.size-(t.getPosition()-this.start));if(s.code===D){let n;s.type in C.sampleEntry?(n=new C.sampleEntry[s.type](s.size),n.hdr_size=s.hdr_size,n.start=s.start):(l.warn("BoxParser",`Unknown sample entry type: '${s.type}'`),n=new M(s.size,s.hdr_size,s.start),n.type=s.type),n.write===M.prototype.write&&(l.info("BoxParser","SampleEntry "+n.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),n.parseDataAndRewind(t)),n.parse(t),this.entries.push(n)}else return}}write(t){this.version=0,this.flags=0,this.size=0,this.writeHeader(t),t.writeUint32(this.entries.length),this.size+=4;for(let 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)}},_i.fourcc="stsd",_i),mi,ja=(mi=class extends d{constructor(){super(...arguments),this.box_name="SampleSizeBox"}parse(t){if(this.parseFullHeader(t),this.sample_sizes=[],this.version===0){this.sample_size=t.readUint32(),this.sample_count=t.readUint32();for(let e=0;e<this.sample_count;e++)this.sample_size===0?this.sample_sizes.push(t.readUint32()):this.sample_sizes[e]=this.sample_size}}write(t){let e=!0;if(this.version=0,this.flags=0,this.sample_sizes.length>0){let i=0;for(;i+1<this.sample_sizes.length;)if(this.sample_sizes[i+1]!==this.sample_sizes[0]){e=!1;break}else i++}else e=!1;this.size=8,e||(this.size+=4*this.sample_sizes.length),this.writeHeader(t),e?t.writeUint32(this.sample_sizes[0]):t.writeUint32(0),t.writeUint32(this.sample_sizes.length),e||t.writeUint32Array(this.sample_sizes)}unpack(t){for(let e=0;e<this.sample_sizes.length;e++)t[e].size=this.sample_sizes[e]}},mi.fourcc="stsz",mi),gi,$a=(gi=class extends d{constructor(){super(...arguments),this.box_name="TimeToSampleBox",this.sample_counts=[],this.sample_deltas=[]}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.sample_counts.length=0,this.sample_deltas.length=0,this.version===0)for(let i=0;i<e;i++){this.sample_counts.push(t.readUint32());let s=t.readInt32();s<0&&(l.warn("BoxParser","File uses negative stts sample delta, using value 1 instead, sync may be lost!"),s=1),this.sample_deltas.push(s)}}write(t){this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length);for(let e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),t.writeUint32(this.sample_deltas[e])}unpack(t){let e=0;for(let i=0;i<this.sample_counts.length;i++)for(let s=0;s<this.sample_counts[i];s++)e===0?t[e].dts=0:t[e].dts=t[e-1].dts+this.sample_deltas[i],e++}},gi.fourcc="stts",gi),xi,qa=(xi=class extends d{constructor(){super(...arguments),this.box_name="TrackFragmentBaseMediaDecodeTimeBox"}parse(t){this.parseFullHeader(t),this.version===1?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()}write(t){const e=this.baseMediaDecodeTime>w||this.version===1;this.version=e?1:0,this.size=4,this.size+=e?4:0,this.flags=0,this.writeHeader(t),e?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)}},xi.fourcc="tfdt",xi),yi,Ya=(yi=class extends d{constructor(){super(...arguments),this.box_name="TrackFragmentHeaderBox"}parse(t){this.parseFullHeader(t);let e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&vn?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&Sn?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&Un?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&Bn?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&wn?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0}write(t){this.version=0,this.size=4,this.flags&vn&&(this.size+=8),this.flags&Sn&&(this.size+=4),this.flags&Un&&(this.size+=4),this.flags&Bn&&(this.size+=4),this.flags&wn&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&vn&&t.writeUint64(this.base_data_offset),this.flags&Sn&&t.writeUint32(this.default_sample_description_index),this.flags&Un&&t.writeUint32(this.default_sample_duration),this.flags&Bn&&t.writeUint32(this.default_sample_size),this.flags&wn&&t.writeUint32(this.default_sample_flags)}},yi.fourcc="tfhd",yi),bi,Wa=(bi=class extends d{constructor(){super(...arguments),this.box_name="TrackHeaderBox",this.layer=0,this.alternate_group=0}parse(t){this.parseFullHeader(t),this.version===1?(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()}write(t){var i;const e=this.modification_time>w||this.creation_time>w||this.duration>w||this.version===1;this.version=e?1:0,this.size=80,this.size+=e?12:0,this.flags=(i=this.flags)!=null?i:3,this.writeHeader(t),e?(t.writeUint64(this.creation_time),t.writeUint64(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint64(this.duration)):(t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration)),t.writeUint32Array([0,0]),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeInt16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)}print(t){super.printHeader(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)}},bi.fourcc="tkhd",bi),vi,Yn=(vi=class extends d{constructor(){super(...arguments),this.box_name="TrackExtendsBox"}parse(t){this.parseFullHeader(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()}write(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)}},vi.fourcc="trex",vi),Si,Ka=(Si=class extends d{constructor(){super(...arguments),this.box_name="TrackRunBox",this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[]}parse(t){this.parseFullHeader(t);let e=0;if(this.sample_count=t.readUint32(),e+=4,this.size-this.hdr_size>e&&this.flags&fn?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&zn?(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(let i=0;i<this.sample_count;i++)this.flags&un&&(this.sample_duration[i]=t.readUint32()),this.flags&pn&&(this.sample_size[i]=t.readUint32()),this.flags&_n&&(this.sample_flags[i]=t.readUint32()),this.flags&mn&&(this.version===0?this.sample_composition_time_offset[i]=t.readUint32():this.sample_composition_time_offset[i]=t.readInt32())}write(t){this.size=4,this.flags&fn&&(this.size+=4),this.flags&zn&&(this.size+=4),this.flags&un&&(this.size+=4*this.sample_duration.length),this.flags&pn&&(this.size+=4*this.sample_size.length),this.flags&_n&&(this.size+=4*this.sample_flags.length),this.flags&mn&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&fn&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&zn&&t.writeUint32(this.first_sample_flags);for(let e=0;e<this.sample_count;e++)this.flags&un&&t.writeUint32(this.sample_duration[e]),this.flags&pn&&t.writeUint32(this.sample_size[e]),this.flags&_n&&t.writeUint32(this.sample_flags[e]),this.flags&mn&&(this.version===0?t.writeUint32(this.sample_composition_time_offset[e]):t.writeInt32(this.sample_composition_time_offset[e]))}},Si.fourcc="trun",Si),Ui,Xa=(Ui=class extends d{constructor(){super(...arguments),this.box_name="DataEntryUrlBox"}parse(t){this.parseFullHeader(t),this.flags!==1&&(this.location=t.readCString())}write(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)}},Ui.fourcc="url ",Ui),Bi,Qa=(Bi=class extends d{constructor(){super(...arguments),this.box_name="VideoMediaHeaderBox"}parse(t){this.parseFullHeader(t),this.graphicsmode=t.readUint16(),this.opcolor=t.readUint16Array(3)}write(t){this.version=0,this.size=8,this.writeHeader(t),t.writeUint16(this.graphicsmode),t.writeUint16Array(this.opcolor)}},Bi.fourcc="vmhd",Bi),Tn=class{constructor(r,t,e){this.grouping_type=r,this.grouping_type_parameter=t,this.sbgp=e,this.last_sample_in_run=-1,this.entry_index=-1}},Ja=class ${constructor(t,e=!0){this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.moovStartSent=!1,this.readySent=!1,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.sidxSent=!1,this.items=[],this.entity_groups=[],this.itemsDataSize=0,this.lastMoofIndex=0,this.samplesDataSize=0,this.lastBoxStartPosition=0,this.nextParsePosition=0,this.discardMdatData=!0,this.discardMdatData=e,t?(this.stream=t,this.parse()):this.stream=new Z,this.stream.isofile=this}setSegmentOptions(t,e,i){var c,f,u;const{sizePerSegment:s=Number.MAX_SAFE_INTEGER,rapAlignement:n=!0}=i;let a=(f=(c=i.nbSamples)!=null?c:i.nbSamplesPerFragment)!=null?f:1e3;const o=(u=i.nbSamplesPerFragment)!=null?u:a;if(a<=0||o<=0||s<=0){l.error("ISOFile",`Invalid segment options: nbSamples=${a}, nbSamplesPerFragment=${o}, sizePerSegment=${s}`);return}if(a<o&&(l.warn("ISOFile",`nbSamples (${a}) is less than nbSamplesPerFragment (${o}), setting nbSamples to nbSamplesPerFragment`),a=o),this.fragmentedTracks.some(_=>_.nb_samples!==a)){l.error("ISOFile",`Cannot set segment options for track ${t}: nbSamples (${a}) does not match existing tracks`);return}const h=this.getTrackById(t);if(h){const _={id:t,user:e,trak:h,segmentStream:void 0,nb_samples:a,nb_samples_per_fragment:o,size_per_segment:s,rapAlignement:n,state:{lastFragmentSampleNumber:0,lastSegmentSampleNumber:0,accumulatedSize:0}};this.fragmentedTracks.push(_),h.nextSample=0}this.discardMdatData&&l.warn("ISOFile","Segmentation options set but discardMdatData is true, samples will not be segmented")}unsetSegmentOptions(t){let e=-1;for(let i=0;i<this.fragmentedTracks.length;i++)this.fragmentedTracks[i].id===t&&(e=i);e>-1&&this.fragmentedTracks.splice(e,1)}setExtractionOptions(t,e,{nbSamples:i=1e3}={}){const s=this.getTrackById(t);s&&(this.extractedTracks.push({id:t,user:e,trak:s,nb_samples:i,samples:[]}),s.nextSample=0),this.discardMdatData&&l.warn("ISOFile","Extraction options set but discardMdatData is true, samples will not be extracted")}unsetExtractionOptions(t){let e=-1;for(let i=0;i<this.extractedTracks.length;i++)this.extractedTracks[i].id===t&&(e=i);e>-1&&this.extractedTracks.splice(e,1)}parse(){if(!(this.restoreParsePosition&&!this.restoreParsePosition()))for(;;)if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}else{this.saveParsePosition&&this.saveParsePosition();const e=H(this.stream,!1);if(e.code===j)if(this.processIncompleteBox){if(this.processIncompleteBox(e))continue;return}else return;else if(e.code===D){const i=e.box;if(this.boxes.push(i),i.type==="uuid")this[i.uuid]!==void 0&&l.warn("ISOFile","Duplicate Box of uuid: "+i.uuid+", overriding previous occurrence"),this[i.uuid]=i;else switch(i.type){case"mdat":this.mdats.push(i),this.transferMdatData(i);break;case"moof":this.moofs.push(i);break;case"free":case"skip":break;case"moov":this.moovStartFound=!0,this.mdats.length===0&&(this.isProgressive=!0);default:this[i.type]!==void 0?Array.isArray(this[i.type+"s"])?(l.info("ISOFile",`Found multiple boxes of type ${i.type} in ISOFile, adding to array`),this[i.type+"s"].push(i)):(l.warn("ISOFile",`Found multiple boxes of type ${i.type} but no array exists. Creating array dynamically.`),this[i.type+"s"]=[this[i.type],i]):(this[i.type]=i,Array.isArray(this[i.type+"s"])&&this[i.type+"s"].push(i));break}this.updateUsedBytes&&this.updateUsedBytes(i,e)}else if(e.code===ha){l.error("ISOFile",`Invalid data found while parsing box of type '${e.type}' at position ${e.start}. Aborting parsing.`,this);break}}}checkBuffer(t){if(!t)throw new Error("Buffer must be defined and non empty");return t.byteLength===0?(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()?!0:(l.warn("ISOFile","Not ready to start parsing"),!1))}appendBuffer(t,e){let i;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?(i=this.nextSeekPosition,this.nextSeekPosition=void 0):i=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(i=this.stream.getEndFilePositionAfter(i))):this.nextParsePosition?i=this.nextParsePosition:i=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 "+i),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),l.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),i}getFragmentDuration(){const t=this.getBox("mvex");if(!t)return;if(t.mehd)return{num:t.mehd.fragment_duration,den:this.moov.mvhd.timescale};const e=this.getBoxes("trak",!1);let i={num:0,den:1};for(const s of e){const n=s.samples_duration,a=s.mdia.mdhd.timescale;n&&a&&n/a>i.num/i.den&&(i={num:n,den:a})}return i}getInfo(){if(!this.moov)return{hasMoov:!1,mime:""};const t=new Date("1904-01-01T00:00:00Z").getTime(),e=this.getBox("mvex")!==void 0,i={hasMoov:!0,duration:this.moov.mvhd.duration,timescale:this.moov.mvhd.timescale,isFragmented:e,fragment_duration:this.getFragmentDuration(),isProgressive:this.isProgressive,hasIOD:this.moov.iods!==void 0,brands:[this.ftyp.major_brand].concat(this.ftyp.compatible_brands),created:new Date(t+this.moov.mvhd.creation_time*1e3),modified:new Date(t+this.moov.mvhd.modification_time*1e3),tracks:[],audioTracks:[],videoTracks:[],subtitleTracks:[],metadataTracks:[],hintTracks:[],otherTracks:[],mime:""};for(let s=0;s<this.moov.traks.length;s++){const n=this.moov.traks[s],a=n.mdia.minf.stbl.stsd.entries[0],o=n.samples_size,h=n.mdia.mdhd.timescale,c=n.samples_duration,f=o*8*h/c,u={samples_duration:c,bitrate:f,size:o,timescale:h,alternate_group:n.tkhd.alternate_group,codec:a.getCodec(),created:new Date(t+n.tkhd.creation_time*1e3),cts_shift:n.mdia.minf.stbl.cslg,duration:n.mdia.mdhd.duration,id:n.tkhd.track_id,kind:n.udta&&n.udta.kinds.length?n.udta.kinds[0]:{schemeURI:"",value:""},language:n.mdia.elng?n.mdia.elng.extended_language:n.mdia.mdhd.languageString,layer:n.tkhd.layer,matrix:n.tkhd.matrix,modified:new Date(t+n.tkhd.modification_time*1e3),movie_duration:n.tkhd.duration,movie_timescale:i.timescale,name:n.mdia.hdlr.name,nb_samples:n.samples.length,references:[],track_height:n.tkhd.height/65536,track_width:n.tkhd.width/65536,volume:n.tkhd.volume};if(i.tracks.push(u),n.tref)for(let _=0;_<n.tref.references.length;_++)u.references.push({type:n.tref.references[_].type,track_ids:n.tref.references[_].track_ids});n.edts!==void 0&&n.edts.elst!==void 0&&(u.edits=n.edts.elst.entries),a instanceof A?(u.type="audio",i.audioTracks.push(u),u.audio={sample_rate:a.getSampleRate(),channel_count:a.getChannelCount(),sample_size:a.getSampleSize()}):a instanceof S?(u.type="video",i.videoTracks.push(u),u.video={width:a.getWidth(),height:a.getHeight()}):a instanceof W?(u.type="subtitles",i.subtitleTracks.push(u)):a instanceof jn?(u.type="metadata",i.hintTracks.push(u)):a instanceof J?(u.type="metadata",i.metadataTracks.push(u)):(u.type="metadata",i.otherTracks.push(u))}i.videoTracks&&i.videoTracks.length>0?i.mime+='video/mp4; codecs="':i.audioTracks&&i.audioTracks.length>0?i.mime+='audio/mp4; codecs="':i.mime+='application/mp4; codecs="';for(let s=0;s<i.tracks.length;s++)s!==0&&(i.mime+=","),i.mime+=i.tracks[s].codec;return i.mime+='"; profiles="',i.mime+=this.ftyp.compatible_brands.join(),i.mime+='"',i}setNextSeekPositionFromSample(t){t&&(this.nextSeekPosition?this.nextSeekPosition=Math.min(t.offset+t.alreadyRead,this.nextSeekPosition):this.nextSeekPosition=t.offset+t.alreadyRead)}processSamples(t){if(this.sampleProcessingStarted){if(this.isFragmentationInitialized&&this.onSegment!==void 0){const e=new Set;for(;e.size<this.fragmentedTracks.length&&this.fragmentedTracks.some(i=>i.trak.nextSample<i.trak.samples.length)&&this.sampleProcessingStarted;)for(const i of this.fragmentedTracks){const s=i.trak;if(!e.has(i.id)){const n=s.nextSample<s.samples.length?this.getSample(s,s.nextSample):void 0;if(!n){this.setNextSeekPositionFromSample(s.samples[s.nextSample]),e.add(i.id);continue}i.state.accumulatedSize+=n.size;const a=s.nextSample+1,o=a-i.state.lastFragmentSampleNumber>i.nb_samples_per_fragment,h=a-i.state.lastSegmentSampleNumber>i.nb_samples;let c=o||a%i.nb_samples_per_fragment===0,f=h||a%i.nb_samples===0,u=i.state.accumulatedSize>=i.size_per_segment;const _=!i.rapAlignement||n.is_sync,m=t||s.nextSample+1>=s.samples.length;if(m&&!_&&l.warn("ISOFile","Flushing track #"+i.id+" at sample #"+s.nextSample+" which is not a RAP, this may lead to playback issues"),c=c&&_,f=f&&_,u=u&&_,c||u||m){o?l.warn("ISOFile","Fragment on track #"+i.id+" is overdue, creating it with samples ["+i.state.lastFragmentSampleNumber+", "+s.nextSample+"]"):l.debug("ISOFile","Creating media fragment on track #"+i.id+" for samples ["+i.state.lastFragmentSampleNumber+", "+s.nextSample+"]");const v=this.createFragment(i.id,i.state.lastFragmentSampleNumber,s.nextSample,i.segmentStream);if(v)i.segmentStream=v,i.state.lastFragmentSampleNumber=s.nextSample+1;else{e.add(i.id);continue}}(f||u||m)&&(h?l.warn("ISOFile","Segment on track #"+i.id+" is overdue, sending it with samples ["+Math.max(0,s.nextSample-i.nb_samples)+", "+(s.nextSample-1)+"]"):l.info("ISOFile","Sending fragmented data on track #"+i.id+" for samples ["+Math.max(0,s.nextSample-i.nb_samples)+", "+(s.nextSample-1)+"]"),l.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(i.id,i.user,i.segmentStream.buffer,s.nextSample+1,t||s.nextSample+1>=s.samples.length),i.segmentStream=void 0,i.state.accumulatedSize=0,i.state.lastSegmentSampleNumber=s.nextSample+1),s.nextSample++}}}if(this.onSamples!==void 0)for(let e=0;e<this.extractedTracks.length;e++){const i=this.extractedTracks[e],s=i.trak;for(;s.nextSample<s.samples.length&&this.sampleProcessingStarted;){l.debug("ISOFile","Exporting on track #"+i.id+" sample #"+s.nextSample);const n=this.getSample(s,s.nextSample);if(n)s.nextSample++,i.samples.push(n);else{this.setNextSeekPositionFromSample(s.samples[s.nextSample]);break}if((s.nextSample%i.nb_samples===0||s.nextSample>=s.samples.length)&&(l.debug("ISOFile","Sending samples on track #"+i.id+" for sample "+s.nextSample),this.onSamples&&this.onSamples(i.id,i.user,i.samples),i.samples=[],i!==this.extractedTracks[e]))break}}}}getBox(t){const e=this.getBoxes(t,!0);return e.length?e[0]:void 0}getBoxes(t,e){const i=[],s=n=>{n instanceof p&&n.type&&n.type===t&&i.push(n);const a=[];n.boxes&&a.push(...n.boxes),n.entries&&a.push(...n.entries),n.item_infos&&a.push(...n.item_infos),n.references&&a.push(...n.references);for(const o of a){if(i.length&&e)return;s(o)}};return s(this),i}getTrackSamplesInfo(t){const e=this.getTrackById(t);if(e)return e.samples}getTrackSample(t,e){const i=this.getTrackById(t);return this.getSample(i,e)}releaseUsedSamples(t,e){let i=0;const s=this.getTrackById(t);s.lastValidSample||(s.lastValidSample=0);for(let n=s.lastValidSample;n<e;n++)i+=this.releaseSample(s,n);l.info("ISOFile","Track #"+t+" released samples up to "+e+" (released size: "+i+", remaining: "+this.samplesDataSize+")"),s.lastValidSample=e}start(){this.sampleProcessingStarted=!0,this.processSamples(!1)}stop(){this.sampleProcessingStarted=!1}flush(){l.info("ISOFile","Flushing remaining samples"),this.updateSampleLists(),this.processSamples(!0),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0)}seekTrack(t,e,i){let s=0,n=0,a;if(i.samples.length===0)return l.info("ISOFile","No sample in track, cannot seek! Using time "+l.getDurationString(0,1)+" and offset: 0"),{offset:0,time:0};for(let h=0;h<i.samples.length;h++){const c=i.samples[h];if(h===0)n=0,a=c.timescale;else if(c.cts>t*c.timescale){n=h-1;break}e&&c.is_sync&&(s=h)}for(e&&(n=s),t=i.samples[n].cts,i.nextSample=n;i.samples[n].alreadyRead===i.samples[n].size&&i.samples[n+1];)n++;const o=i.samples[n].offset+i.samples[n].alreadyRead;return l.info("ISOFile","Seeking to "+(e?"RAP":"")+" sample #"+i.nextSample+" on track "+i.tkhd.track_id+", time "+l.getDurationString(t,a)+" and offset: "+o),{offset:o,time:t/a}}getTrackDuration(t){if(!t.samples)return 1/0;const e=t.samples[t.samples.length-1];return(e.cts+e.duration)/e.timescale}seek(t,e){const i=this.moov;let s={offset:1/0,time:1/0};if(this.moov){for(let n=0;n<i.traks.length;n++){const a=i.traks[n];if(t>this.getTrackDuration(a))continue;const o=this.seekTrack(t,e,a);o.offset<s.offset&&(s.offset=o.offset),o.time<s.time&&(s.time=o.time)}return l.info("ISOFile","Seeking at time "+l.getDurationString(s.time,1)+" needs a buffer with a fileStart position of "+s.offset),s.offset===1/0?s={offset:this.nextParsePosition,time:0}:s.offset=this.stream.getEndFilePositionAfter(s.offset),l.info("ISOFile","Adjusted seek position (after checking data already in buffer): "+s.offset),s}else throw new Error("Cannot seek: moov not received!")}equal(t){let e=0;for(;e<this.boxes.length&&e<t.boxes.length;){const i=this.boxes[e],s=t.boxes[e];if(!Wn(i,s))return!1;e++}return!0}write(t){for(let e=0;e<this.boxes.length;e++)this.boxes[e].write(t)}createFragment(t,e,i,s){const n=[];for(let f=e;f<=i;f++){const u=this.getTrackById(t),_=this.getSample(u,f);if(!_){this.setNextSeekPositionFromSample(u.samples[f]);return}n.push(_)}const a=s||new z,o=this.createMoof(n);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);const h=new kn;h.stream=new Z;let c=0;for(const f of n)if(f.data){const u=R.fromArrayBuffer(f.data.buffer,c);h.stream.insertBuffer(u),c+=f.data.byteLength}return h.write(a),a}static writeInitializationSegment(t,e,i){var a,o;l.debug("ISOFile","Generating initialization segment");const s=new z;t.write(s);const n=e.addBox(new qn);if(i){const h=n.addBox(new Fa);h.fragment_duration=i}for(let h=0;h<e.traks.length;h++){const c=n.addBox(new Yn);c.track_id=e.traks[h].tkhd.track_id,c.default_sample_description_index=1,c.default_sample_duration=(o=(a=e.traks[h].samples[0])==null?void 0:a.duration)!=null?o:0,c.default_sample_size=0,c.default_sample_flags=65536}return e.write(s),s.buffer}save(t){const e=new z;return e.isofile=this,this.write(e),e.save(t)}getBuffer(){const t=new z;return t.isofile=this,this.write(t),t}initializeSegmentation(){var e,i;this.onSegment||l.warn("MP4Box","No segmentation callback set!"),this.isFragmentationInitialized||(this.isFragmentationInitialized=!0,this.resetTables());const t=new $n;t.addBox(this.moov.mvhd);for(let s=0;s<this.fragmentedTracks.length;s++){const n=this.getTrackById(this.fragmentedTracks[s].id);if(!n){l.warn("ISOFile",`Track with id ${this.fragmentedTracks[s].id} not found, skipping fragmentation initialization`);continue}t.addBox(n)}return{tracks:t.traks.map((s,n)=>({id:s.tkhd.track_id,user:this.fragmentedTracks[n].user})),buffer:$.writeInitializationSegment(this.ftyp,t,(i=(e=this.moov)==null?void 0:e.mvex)==null?void 0:i.mehd.fragment_duration)}}resetTables(){this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0;for(let t=0;t<this.moov.traks.length;t++){const e=this.moov.traks[t];e.tkhd.duration=0,e.mdia.mdhd.duration=0;const i=e.mdia.minf.stbl.stco||e.mdia.minf.stbl.co64;i.chunk_offsets=[];const s=e.mdia.minf.stbl.stsc;s.first_chunk=[],s.samples_per_chunk=[],s.sample_description_index=[];const n=e.mdia.minf.stbl.stsz||e.mdia.minf.stbl.stz2;n.sample_sizes=[];const a=e.mdia.minf.stbl.stts;a.sample_counts=[],a.sample_deltas=[];const o=e.mdia.minf.stbl.ctts;o&&(o.sample_counts=[],o.sample_offsets=[]);const h=e.mdia.minf.stbl.stss,c=e.mdia.minf.stbl.boxes.indexOf(h);c!==-1&&(e.mdia.minf.stbl.boxes[c]=void 0)}}static initSampleGroups(t,e,i,s,n){e&&(e.sample_groups_info=[]),t.sample_groups_info||(t.sample_groups_info=[]);for(let a=0;a<i.length;a++){const o=i[a].grouping_type+"/"+i[a].grouping_type_parameter,h=new Tn(i[a].grouping_type,i[a].grouping_type_parameter,i[a]);e&&(e.sample_groups_info[o]=h),t.sample_groups_info[o]||(t.sample_groups_info[o]=h);for(let c=0;c<s.length;c++)s[c].grouping_type===i[a].grouping_type&&(h.description=s[c],h.description.used=!0);if(n)for(let c=0;c<n.length;c++)n[c].grouping_type===i[a].grouping_type&&(h.fragment_description=n[c],h.fragment_description.used=!0,h.is_fragment=!0)}if(e){if(n){for(let a=0;a<n.length;a++)if(!n[a].used&&n[a].version>=2){const o=n[a].grouping_type+"/0",h=new Tn(n[a].grouping_type,0);h.is_fragment=!0,e.sample_groups_info[o]||(e.sample_groups_info[o]=h)}}}else for(let a=0;a<s.length;a++)if(!s[a].used&&s[a].version>=2){const o=s[a].grouping_type+"/0",h=new Tn(s[a].grouping_type,0);t.sample_groups_info[o]||(t.sample_groups_info[o]=h)}}static setSampleGroupProperties(t,e,i,s){e.sample_groups=[];for(const n in s)if(e.sample_groups[n]={grouping_type:s[n].grouping_type,grouping_type_parameter:s[n].grouping_type_parameter},i>=s[n].last_sample_in_run&&(s[n].last_sample_in_run<0&&(s[n].last_sample_in_run=0),s[n].entry_index++,s[n].entry_index<=s[n].sbgp.entries.length-1&&(s[n].last_sample_in_run+=s[n].sbgp.entries[s[n].entry_index].sample_count)),s[n].entry_index<=s[n].sbgp.entries.length-1?e.sample_groups[n].group_description_index=s[n].sbgp.entries[s[n].entry_index].group_description_index:e.sample_groups[n].group_description_index=-1,e.sample_groups[n].group_description_index!==0){let a;if(s[n].fragment_description?a=s[n].fragment_description:a=s[n].description,e.sample_groups[n].group_description_index>0){let o;e.sample_groups[n].group_description_index>65535?o=(e.sample_groups[n].group_description_index>>16)-1:o=e.sample_groups[n].group_description_index-1,a&&o>=0&&(e.sample_groups[n].description=a.entries[o])}else a&&a.version>=2&&a.default_group_description_index>0&&(e.sample_groups[n].description=a.entries[a.default_group_description_index-1])}}static process_sdtp(t,e,i){e&&(t?(e.is_leading=t.is_leading[i],e.depends_on=t.sample_depends_on[i],e.is_depended_on=t.sample_is_depended_on[i],e.has_redundancy=t.sample_has_redundancy[i]):(e.is_leading=0,e.depends_on=0,e.is_depended_on=0,e.has_redundancy=0))}buildSampleLists(){for(let t=0;t<this.moov.traks.length;t++)this.buildTrakSampleLists(this.moov.traks[t])}buildTrakSampleLists(t){let e,i,s,n,a,o;t.samples=[],t.samples_duration=0,t.samples_size=0;const h=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64,c=t.mdia.minf.stbl.stsc,f=t.mdia.minf.stbl.stsz||t.mdia.minf.stbl.stz2,u=t.mdia.minf.stbl.stts,_=t.mdia.minf.stbl.ctts,m=t.mdia.minf.stbl.stss,v=t.mdia.minf.stbl.stsd,b=t.mdia.minf.stbl.subs,T=t.mdia.minf.stbl.stdp,k=t.mdia.minf.stbl.sbgps,F=t.mdia.minf.stbl.sgpds;let P=-1,V=-1,L=-1,U=-1,N=0,I=0,O=0;if($.initSampleGroups(t,void 0,k,F),typeof f!="undefined"){for(e=0;e<f.sample_sizes.length;e++){const x={number:e,track_id:t.tkhd.track_id,timescale:t.mdia.mdhd.timescale,alreadyRead:0,size:f.sample_sizes[e]};t.samples[e]=x,t.samples_size+=x.size,e===0?(s=1,i=0,x.chunk_index=s,x.chunk_run_index=i,o=c.samples_per_chunk[i],a=0,i+1<c.first_chunk.length?n=c.first_chunk[i+1]-1:n=1/0):e<o?(x.chunk_index=s,x.chunk_run_index=i):(s++,x.chunk_index=s,a=0,s<=n||(i++,i+1<c.first_chunk.length?n=c.first_chunk[i+1]-1:n=1/0),x.chunk_run_index=i,o+=c.samples_per_chunk[i]),x.description_index=c.sample_description_index[x.chunk_run_index]-1,x.description=v.entries[x.description_index],x.offset=h.chunk_offsets[x.chunk_index-1]+a,a+=x.size,e>P&&(V++,P<0&&(P=0),P+=u.sample_counts[V]),e>0?(t.samples[e-1].duration=u.sample_deltas[V],t.samples_duration+=t.samples[e-1].duration,x.dts=t.samples[e-1].dts+t.samples[e-1].duration):x.dts=0,_?(e>=L&&(U++,L<0&&(L=0),L+=_.sample_counts[U]),x.cts=t.samples[e].dts+_.sample_offsets[U]):x.cts=x.dts,m?(e===m.sample_numbers[N]-1?(x.is_sync=!0,N++):(x.is_sync=!1,x.degradation_priority=0),b&&b.entries[I].sample_delta+O===e+1&&(x.subsamples=b.entries[I].subsamples,O+=b.entries[I].sample_delta,I++)):x.is_sync=!0,$.process_sdtp(t.mdia.minf.stbl.sdtp,x,x.number),T?x.degradation_priority=T.priority[e]:x.degradation_priority=0,b&&b.entries[I].sample_delta+O===e&&(x.subsamples=b.entries[I].subsamples,O+=b.entries[I].sample_delta),(k.length>0||F.length>0)&&$.setSampleGroupProperties(t,x,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)}}updateSampleLists(){let t,e,i,s,n;if(this.moov!==void 0)for(;this.lastMoofIndex<this.moofs.length;){const a=this.moofs[this.lastMoofIndex];if(this.lastMoofIndex++,a.type==="moof"){const o=a;for(let h=0;h<o.trafs.length;h++){const c=o.trafs[h],f=this.getTrackById(c.tfhd.track_id),u=this.getTrexById(c.tfhd.track_id);c.tfhd.flags&Sn?t=c.tfhd.default_sample_description_index:t=u?u.default_sample_description_index:1,c.tfhd.flags&Un?e=c.tfhd.default_sample_duration:e=u?u.default_sample_duration:0,c.tfhd.flags&Bn?i=c.tfhd.default_sample_size:i=u?u.default_sample_size:0,c.tfhd.flags&wn?s=c.tfhd.default_sample_flags:s=u?u.default_sample_flags:0,c.sample_number=0,c.sbgps.length>0&&$.initSampleGroups(f,c,c.sbgps,f.mdia.minf.stbl.sgpds,c.sgpds);for(let _=0;_<c.truns.length;_++){const m=c.truns[_];for(let v=0;v<m.sample_count;v++){const b=t-1;let T=s;m.flags&_n?T=m.sample_flags[v]:v===0&&m.flags&zn&&(T=m.first_sample_flags);let k=i;m.flags&pn&&(k=m.sample_size[v]),f.samples_size+=k;let F=e;m.flags&un&&(F=m.sample_duration[v]),f.samples_duration+=F;let P;f.first_traf_merged||v>0?P=f.samples[f.samples.length-1].dts+f.samples[f.samples.length-1].duration:(c.tfdt?P=c.tfdt.baseMediaDecodeTime:P=0,f.first_traf_merged=!0);let V=P;m.flags&mn&&(V=P+m.sample_composition_time_offset[v]);const L=!!(c.tfhd.flags&vn),U=!!(c.tfhd.flags&ea),N=!!(m.flags&fn);let I=0;L?I=c.tfhd.base_data_offset:U||_===0?I=o.start:I=n;let O;_===0&&v===0?N?O=I+m.data_offset:O=I:O=n,n=O+k;const x=c.sample_number;c.sample_number++;const On={cts:V,description_index:b,description:f.mdia.minf.stbl.stsd.entries[b],dts:P,duration:F,moof_number:this.lastMoofIndex,number_in_traf:x,number:f.samples.length,offset:O,size:k,timescale:f.mdia.mdhd.timescale,track_id:f.tkhd.track_id,is_sync:!(T>>16&1),is_leading:T>>26&3,depends_on:T>>24&3,is_depended_on:T>>22&3,has_redundancy:T>>20&3,degradation_priority:T&65535};c.first_sample_index=f.samples.length,f.samples.push(On),(c.sbgps.length>0||c.sgpds.length>0||f.mdia.minf.stbl.sbgps.length>0||f.mdia.minf.stbl.sgpds.length>0)&&$.setSampleGroupProperties(f,On,On.number_in_traf,c.sample_groups_info)}}if(c.subs){f.has_fragment_subsamples=!0;let _=c.first_sample_index;for(let m=0;m<c.subs.entries.length;m++){_+=c.subs.entries[m].sample_delta;const v=f.samples[_-1];v.subsamples=c.subs.entries[m].subsamples}}}}}}getSample(t,e){const i=t.samples[e];if(this.moov){if(!i.data)i.data=new Uint8Array(i.size),i.alreadyRead=0,this.samplesDataSize+=i.size,l.debug("ISOFile","Allocating sample #"+e+" on track #"+t.tkhd.track_id+" of size "+i.size+" (total: "+this.samplesDataSize+")");else if(i.alreadyRead===i.size)return i;for(;;){let s=this.stream,n=s.findPosition(!0,i.offset+i.alreadyRead,!1),a,o;if(n>-1)a=s.buffers[n],o=a.fileStart;else for(const h of this.mdats){if(!h.stream){l.debug("ISOFile","mdat stream not yet fully read for #"+this.mdats.indexOf(h)+" mdat");continue}if(n=h.stream.findPosition(!0,i.offset+i.alreadyRead-h.start-h.hdr_size,!1),n>-1){s=h.stream,a=h.stream.buffers[n],o=h.start+h.hdr_size+a.fileStart;break}}if(a){const h=a.byteLength-(i.offset+i.alreadyRead-o);if(i.size-i.alreadyRead<=h)return l.debug("ISOFile","Getting sample #"+e+" data (alreadyRead: "+i.alreadyRead+" offset: "+(i.offset+i.alreadyRead-o)+" read size: "+(i.size-i.alreadyRead)+" full size: "+i.size+")"),z.memcpy(i.data.buffer,i.alreadyRead,a,i.offset+i.alreadyRead-o,i.size-i.alreadyRead),a.usedBytes+=i.size-i.alreadyRead,s.logBufferLevel(),i.alreadyRead=i.size,i;if(h===0)return;l.debug("ISOFile","Getting sample #"+e+" partial data (alreadyRead: "+i.alreadyRead+" offset: "+(i.offset+i.alreadyRead-o)+" read size: "+h+" full size: "+i.size+")"),z.memcpy(i.data.buffer,i.alreadyRead,a,i.offset+i.alreadyRead-o,h),i.alreadyRead+=h,a.usedBytes+=h,s.logBufferLevel()}else return}}}releaseSample(t,e){const i=t.samples[e];return i.data?(this.samplesDataSize-=i.size,i.data=void 0,i.alreadyRead=0,i.size):0}getAllocatedSampleDataSize(){return this.samplesDataSize}getCodecs(){let t="";for(let e=0;e<this.moov.traks.length;e++){const i=this.moov.traks[e];e>0&&(t+=","),t+=i.mdia.minf.stbl.stsd.entries[0].getCodec()}return t}getTrexById(t){if(!(!this.moov||!this.moov.mvex))for(let e=0;e<this.moov.mvex.trexs.length;e++){const i=this.moov.mvex.trexs[e];if(i.track_id===t)return i}}getTrackById(t){if(this.moov)for(let e=0;e<this.moov.traks.length;e++){const i=this.moov.traks[e];if(i.tkhd.track_id===t)return i}}flattenItemInfo(){var s;const t=this.items,e=this.entity_groups,i=this.meta;if(!(!i||!i.hdlr||!i.iinf)){for(let n=0;n<i.iinf.item_infos.length;n++){const a=i.iinf.item_infos[n].item_ID;t[a]={id:a,name:i.iinf.item_infos[n].item_name,ref_to:[],content_type:i.iinf.item_infos[n].content_type,content_encoding:i.iinf.item_infos[n].content_encoding,item_uri_type:i.iinf.item_infos[n].item_uri_type,type:i.iinf.item_infos[n].item_type?i.iinf.item_infos[n].item_type:"mime",protection:i.iinf.item_infos[n].item_protection_index>0?i.ipro.protections[i.iinf.item_infos[n].item_protection_index-1]:void 0}}if(i.grpl)for(let n=0;n<i.grpl.boxes.length;n++){const a=i.grpl.boxes[n];e[a.group_id]={id:a.group_id,entity_ids:a.entity_ids,type:a.type}}if(i.iloc)for(let n=0;n<i.iloc.items.length;n++){const a=i.iloc.items[n],o=t[a.item_ID];a.data_reference_index!==0&&(l.warn("Item storage with reference to other files: not supported"),o.source=i.dinf.boxes[a.data_reference_index-1]),o.extents=[],o.size=0;for(let h=0;h<a.extents.length;h++)o.extents[h]={offset:a.extents[h].extent_offset+a.base_offset,length:a.extents[h].extent_length,alreadyRead:0},a.construction_method===1&&(o.extents[h].offset+=i.idat.start+i.idat.hdr_size),o.size+=o.extents[h].length}if(i.pitm&&(t[i.pitm.item_id].primary=!0),i.iref)for(let n=0;n<i.iref.references.length;n++){const a=i.iref.references[n];for(let o=0;o<a.references.length;o++)t[a.from_item_ID].ref_to.push({type:a.type,id:a.references[o]})}if(i.iprp)for(let n=0;n<i.iprp.ipmas.length;n++){const a=i.iprp.ipmas[n];for(let o=0;o<a.associations.length;o++){const h=a.associations[o],c=(s=t[h.id])!=null?s:e[h.id];if(c){c.properties===void 0&&(c.properties={boxes:[]});for(let f=0;f<h.props.length;f++){const u=h.props[f];if(u.property_index>0&&u.property_index-1<i.iprp.ipco.boxes.length){const _=i.iprp.ipco.boxes[u.property_index-1];c.properties[_.type]=_,c.properties.boxes.push(_)}}}}}}}getItem(t){if(!this.meta)return;const e=this.items[t];if(!e.data&&e.size)e.data=new Uint8Array(e.size),e.alreadyRead=0,this.itemsDataSize+=e.size,l.debug("ISOFile","Allocating item #"+t+" of size "+e.size+" (total: "+this.itemsDataSize+")");else if(e.alreadyRead===e.size)return e;for(let i=0;i<e.extents.length;i++){const s=e.extents[i];if(s.alreadyRead!==s.length){const n=this.stream.findPosition(!0,s.offset+s.alreadyRead,!1);if(n>-1){const a=this.stream.buffers[n],o=a.byteLength-(s.offset+s.alreadyRead-a.fileStart);if(s.length-s.alreadyRead<=o)l.debug("ISOFile","Getting item #"+t+" extent #"+i+" data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-a.fileStart)+" read size: "+(s.length-s.alreadyRead)+" full extent size: "+s.length+" full item size: "+e.size+")"),z.memcpy(e.data.buffer,e.alreadyRead,a,s.offset+s.alreadyRead-a.fileStart,s.length-s.alreadyRead),(!this.parsingMdat||this.discardMdatData)&&(a.usedBytes+=s.length-s.alreadyRead),this.stream.logBufferLevel(),e.alreadyRead+=s.length-s.alreadyRead,s.alreadyRead=s.length;else{l.debug("ISOFile","Getting item #"+t+" extent #"+i+" partial data (alreadyRead: "+s.alreadyRead+" offset: "+(s.offset+s.alreadyRead-a.fileStart)+" read size: "+o+" full extent size: "+s.length+" full item size: "+e.size+")"),z.memcpy(e.data.buffer,e.alreadyRead,a,s.offset+s.alreadyRead-a.fileStart,o),s.alreadyRead+=o,e.alreadyRead+=o,(!this.parsingMdat||this.discardMdatData)&&(a.usedBytes+=o),this.stream.logBufferLevel();return}}else return}}if(e.alreadyRead===e.size)return e}releaseItem(t){const e=this.items[t];if(e.data){this.itemsDataSize-=e.size,e.data=void 0,e.alreadyRead=0;for(let i=0;i<e.extents.length;i++){const s=e.extents[i];s.alreadyRead=0}return e.size}else return 0}processItems(t){for(const e in this.items){const i=this.items[e];this.getItem(i.id),t&&!i.sent&&(t(i),i.sent=!0,i.data=void 0)}}hasItem(t){for(const e in this.items){const i=this.items[e];if(i.name===t)return i.id}return-1}getMetaHandler(){if(this.meta)return this.meta.hdlr.handler}getPrimaryItem(){if(this.meta&&this.meta.pitm)return this.getItem(this.meta.pitm.item_id)}itemToFragmentedTrackFile({itemId:t}={}){let e;if(t?e=this.getItem(t):e=this.getPrimaryItem(),!e)return;const i=new $;i.discardMdatData=!1;const s={type:e.type,description_boxes:e.properties.boxes};e.properties.ispe&&(s.width=e.properties.ispe.image_width,s.height=e.properties.ispe.image_height);const n=i.addTrack(s);if(n)return i.addSample(n,e.data),i}processIncompleteBox(t){if(t.type==="mdat"){const e=new kn(t.size);return this.parsingMdat=e,this.boxes.push(e),this.mdats.push(e),e.start=t.start,e.hdr_size=t.hdr_size,e.original_size=t.original_size,this.stream.addUsedBytes(e.hdr_size),this.lastBoxStartPosition=e.start+e.size,this.stream.seek(e.start+e.size,!1,this.discardMdatData)?(this.transferMdatData(),this.parsingMdat=void 0,!0):(this.moovStartFound?this.nextParsePosition=this.stream.findEndContiguousBuf():this.nextParsePosition=e.start+e.size,!1)}else return t.type==="moov"&&(this.moovStartFound=!0,this.mdats.length===0&&(this.isProgressive=!0)),(this.stream.mergeNextBuffer?this.stream.mergeNextBuffer():!1)?(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)}hasIncompleteMdat(){return this.parsingMdat!==void 0}transferMdatData(t){const e=t!=null?t:this.parsingMdat;if(this.discardMdatData){l.debug("ISOFile","Discarding 'mdat' data, not transferring it to the mdat box stream");return}if(!e){l.warn("ISOFile","Cannot transfer 'mdat' data, no mdat box is being parsed");return}const i=this.stream.findPosition(!0,e.start+e.hdr_size,!1),s=this.stream.findPosition(!0,e.start+e.size,!1);if(i===-1||s===-1){l.warn("ISOFile","Cannot transfer 'mdat' data, start or end buffer not found");return}e.stream=new Z;for(let n=i;n<=s;n++){const a=this.stream.buffers[n],o=n===i?e.start+e.hdr_size-a.fileStart:0,h=n===s?e.start+e.size-a.fileStart:a.byteLength;if(h>o){l.debug("ISOFile","Transferring 'mdat' data from buffer #"+n+" ("+o+" to "+h+")");const c=h-o,f=new R(c),u=e.stream.getAbsoluteEndPosition();z.memcpy(f,0,a,o,c),f.fileStart=u,e.stream.insertBuffer(f),a.usedBytes+=c}}}processIncompleteMdat(){const t=this.parsingMdat;return this.stream.seek(t.start+t.size,!1,this.discardMdatData)?(l.debug("ISOFile","Found 'mdat' end in buffered data"),this.transferMdatData(),this.parsingMdat=void 0,!0):(this.nextParsePosition=this.stream.findEndContiguousBuf(),!1)}restoreParsePosition(){return this.stream.seek(this.lastBoxStartPosition,!0,this.discardMdatData)}saveParsePosition(){this.lastBoxStartPosition=this.stream.getPosition()}updateUsedBytes(t,e){this.stream.addUsedBytes&&(t.type==="mdat"?(this.stream.addUsedBytes(t.hdr_size),this.discardMdatData&&this.stream.addUsedBytes(t.size-t.hdr_size)):this.stream.addUsedBytes(t.size))}addBox(t){return p.prototype.addBox.call(this,t)}init(t={}){const e=this.addBox(new Ia);e.major_brand=t.brands&&t.brands[0]||"iso4",e.minor_version=0,e.compatible_brands=t.brands||["iso4"];const i=this.addBox(new $n);i.addBox(new qn);const s=i.addBox(new Da);return s.timescale=t.timescale||600,s.rate=t.rate||65536,s.creation_time=0,s.modification_time=0,s.duration=t.duration||0,s.volume=t.width?0:256,s.matrix=[65536,0,0,0,65536,0,0,0,1073741824],s.next_track_id=1,this}addTrack(t={}){this.moov||this.init(t);const 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";const i=this.moov.addBox(new ba);this.moov.mvhd.next_track_id=e.id+1;const s=i.addBox(new Wa);s.flags=ao|oo|ho,s.creation_time=0,s.modification_time=0,s.track_id=e.id,s.duration=e.duration||0,s.layer=e.layer||0,s.alternate_group=0,s.volume=1,s.matrix=[65536,0,0,0,65536,0,0,0,1073741824],s.width=e.width<<16,s.height=e.height<<16;const n=i.addBox(new va),a=n.addBox(new Aa);a.creation_time=0,a.modification_time=0,a.timescale=e.timescale||1,a.duration=e.media_duration||0,a.language=e.language||"und";const o=n.addBox(new Ta);o.handler=e.hdlr||"vide",o.name=e.name||"Track created with MP4Box.js";const h=n.addBox(new ka);h.extended_language=e.language||"fr-FR";const c=n.addBox(new Sa),f=C.sampleEntry[e.type];if(!f)return;const u=new f;if(u.data_reference_index=1,u instanceof S){const U=u,N=c.addBox(new Qa);N.graphicsmode=0,N.opcolor=[0,0,0],U.width=e.width,U.height=e.height,U.horizresolution=72<<16,U.vertresolution=72<<16,U.frame_count=1,U.compressorname=e.type+" Compressor",U.depth=24,e.avcDecoderConfigRecord?U.addBox(new xa(e.avcDecoderConfigRecord.byteLength)).parse(new z(e.avcDecoderConfigRecord)):e.hevcDecoderConfigRecord&&U.addBox(new Pa(e.hevcDecoderConfigRecord.byteLength)).parse(new z(e.hevcDecoderConfigRecord))}else if(u instanceof A){const U=u,N=c.addBox(new Ra);N.balance=e.balance||0,U.channel_count=e.channel_count||2,U.samplesize=e.samplesize||16,U.samplerate=e.samplerate||65536}else u instanceof jn?c.addBox(new ya):u instanceof W?(c.addBox(new Na),u instanceof Oa&&(u.namespace=e.namespace||"nonamespace",u.schema_location=e.schema_location||"",u.auxiliary_mime_types=e.auxiliary_mime_types||"")):u instanceof J?c.addBox(new In):u instanceof Dn?c.addBox(new In):c.addBox(new In);e.description&&u.addBox.call(u,e.description),e.description_boxes&&e.description_boxes.forEach(function(U){u.addBox.call(u,U)});const m=c.addBox(new Ua).addBox(new Ea),v=new Xa;v.flags=1,m.addEntry(v);const b=c.addBox(new Ba);b.addBox(new Va).addEntry(u);const k=b.addBox(new $a);k.sample_counts=[],k.sample_deltas=[];const F=b.addBox(new Ga);F.first_chunk=[],F.samples_per_chunk=[],F.sample_description_index=[];const P=b.addBox(new Ma);P.chunk_offsets=[];const V=b.addBox(new ja);V.sample_sizes=[];const L=this.moov.mvex.addBox(new Yn);return L.track_id=e.id,L.default_sample_description_index=e.default_sample_description_index||1,L.default_sample_duration=e.default_sample_duration||0,L.default_sample_size=e.default_sample_size||0,L.default_sample_flags=e.default_sample_flags||0,this.buildTrakSampleLists(i),e.id}addSample(t,e,{sample_description_index:i,duration:s=1,cts:n=0,dts:a=0,is_sync:o=!1,is_leading:h=0,depends_on:c=0,is_depended_on:f=0,has_redundancy:u=0,degradation_priority:_=0,subsamples:m,offset:v=0}={}){const b=this.getTrackById(t);if(b===void 0)return;const T=i?i-1:0,k={number:b.samples.length,track_id:b.tkhd.track_id,timescale:b.mdia.mdhd.timescale,description_index:T,description:b.mdia.minf.stbl.stsd.entries[T],data:e,size:e.byteLength,alreadyRead:e.byteLength,duration:s,cts:n,dts:a,is_sync:o,is_leading:h,depends_on:c,is_depended_on:f,has_redundancy:u,degradation_priority:_,offset:v,subsamples:m};b.samples.push(k),b.samples_size+=k.size,b.samples_duration+=k.duration,b.first_dts===void 0&&(b.first_dts=a),this.processSamples();const F=this.addBox(this.createMoof([k]));F.computeSize(),F.trafs[0].truns[0].data_offset=F.size+8;const P=this.addBox(new kn);return P.data=new Uint8Array(e),k}createMoof(t){if(t.length===0)return;if(t.some(f=>f.track_id!==t[0].track_id))throw new Error("Cannot create moof for samples from different tracks: "+t.map(f=>f.track_id).join(", "));const e=t[0].track_id,i=this.getTrackById(e);if(!i)throw new Error("Cannot create moof for non-existing track: "+e);const s=new wa,n=s.addBox(new Ca);n.sequence_number=++this.nextMoofNumber;const a=s.addBox(new za),o=a.addBox(new Ya);o.track_id=e,o.flags=ea;const h=a.addBox(new qa);h.baseMediaDecodeTime=t[0].dts-(i.first_dts||0);const c=a.addBox(new Ka);c.flags=fn|un|pn|_n|mn,c.data_offset=0,c.first_sample_flags=0,c.sample_count=t.length;for(const f of t){let u=0;f.is_sync?u=1<<25:u=65536,c.sample_duration.push(f.duration),c.sample_size.push(f.size),c.sample_flags.push(u),c.sample_composition_time_offset.push(f.cts-f.dts)}return s}print(t){t.indent="";for(let e=0;e<this.boxes.length;e++)this.boxes[e]&&this.boxes[e].print(t)}};function sc(r=!1,t){return new Ja(t,!r)}var Za={};oa(Za,{Descriptor:()=>K,ES_Descriptor:()=>Qn,MPEG4DescriptorParser:()=>so});var to=3,Cn=4,Xn=5,eo=6,K=class io{constructor(t,e){this.tag=t,this.size=e,this.descs=[]}parse(t){this.data=t.readUint8Array(this.size)}findDescriptor(t){for(let e=0;e<this.descs.length;e++)if(this.descs[e].tag===t)return this.descs[e]}parseOneDescriptor(t){let e=0;const i=t.readUint8();let s=t.readUint8();for(;s&128;)e=(e<<7)+(s&127),s=t.readUint8();e=(e<<7)+(s&127),l.debug("Descriptor","Found "+(Pn[i]||"Descriptor "+i)+", size "+e+" at position "+t.getPosition());const n=Pn[i]?new oc[Pn[i]](e):new io(e);return n.parse(t),n}parseRemainingDescriptors(t){var i;const e=t.getPosition();for(;t.getPosition()<e+this.size;){const s=(i=this.parseOneDescriptor)==null?void 0:i.call(this,t);this.descs.push(s)}}},Qn=class extends K{constructor(r){super(to,r)}parse(r){if(this.ES_ID=r.readUint16(),this.flags=r.readUint8(),this.size-=3,this.flags&128?(this.dependsOn_ES_ID=r.readUint16(),this.size-=2):this.dependsOn_ES_ID=0,this.flags&64){const t=r.readUint8();this.URL=r.readString(t),this.size-=t+1}else this.URL="";this.flags&32?(this.OCR_ES_ID=r.readUint16(),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(r)}getOTI(){const r=this.findDescriptor(Cn);return r?r.oti:0}getAudioConfig(){const r=this.findDescriptor(Cn);if(!r)return;const t=r.findDescriptor(Xn);if(t&&t.data){let e=(t.data[0]&248)>>3;return e===31&&t.data.length>=2&&(e=32+((t.data[0]&7)<<3)+((t.data[1]&224)>>5)),e}}},rc=class extends K{constructor(r){super(Cn,r)}parse(r){this.oti=r.readUint8(),this.streamType=r.readUint8(),this.upStream=(this.streamType>>1&1)!==0,this.streamType=this.streamType>>>2,this.bufferSize=r.readUint24(),this.maxBitrate=r.readUint32(),this.avgBitrate=r.readUint32(),this.size-=13,this.parseRemainingDescriptors(r)}},nc=class extends K{constructor(r){super(Xn,r)}},ac=class extends K{constructor(r){super(eo,r)}},oc={Descriptor:K,ES_Descriptor:Qn,DecoderConfigDescriptor:rc,DecoderSpecificInfo:nc,SLConfigDescriptor:ac},Pn={[to]:"ES_Descriptor",[Cn]:"DecoderConfigDescriptor",[Xn]:"DecoderSpecificInfo",[eo]:"SLConfigDescriptor"},so=class{constructor(){this.parseOneDescriptor=K.prototype.parseOneDescriptor}getDescriptorName(r){return Pn[r]}},hc=class{parseSample(r){var i;const t=[],e=new Z(R.fromArrayBuffer(r.buffer,0));for(;!e.isEof();){const s=H(e,!1);s.code===D&&((i=s.box)==null?void 0:i.type)==="vttc"&&t.push(s.box)}return t}getText(r,t,e){function i(o,h){const c=o.toString();return c.length>=h?c:new Array(h-c.length+1).join("0")+c}function s(o){const h=Math.floor(o/3600),c=Math.floor((o-h*3600)/60),f=Math.floor(o-h*3600-c*60),u=Math.floor((o-h*3600-c*60-f)*1e3);return""+i(h,2)+":"+i(c,2)+":"+i(f,2)+"."+i(u,3)}const n=this.parseSample(e);let a="";for(let o=0;o<n.length;o++){const h=n[o];a+=s(r)+" --> "+s(t)+`\r
2
+ `,a+=h.payl.text}return a}},cc=class{parseSample(r){const t={resources:[],documentString:"",document:void 0},e=new z(r.data.buffer);if(!r.subsamples||r.subsamples.length===0)t.documentString=e.readString(r.data.length);else if(t.documentString=e.readString(r.subsamples[0].size),r.subsamples.length>1)for(let i=1;i<r.subsamples.length;i++)t.resources[i]=e.readUint8Array(r.subsamples[i].size);return typeof DOMParser!="undefined"&&(t.document=new DOMParser().parseFromString(t.documentString,"application/xml")),t}},lc=class{parseSample(r){return new z(r.data.buffer).readString(r.data.length)}parseConfig(r){const t=new z(r.buffer);return t.readUint32(),t.readCString()}},dc=class{parseSample(r){const t=new z(r.data.buffer),e=t.readUint16();if(e!==0)return t.readString(e)}},ro={};oa(ro,{CoLLBox:()=>Bc,ItemContentIDPropertyBox:()=>Zd,OpusSampleEntry:()=>Dh,SmDmBox:()=>Xl,a1lxBox:()=>fc,a1opBox:()=>uc,ac_3SampleEntry:()=>Ah,ac_4SampleEntry:()=>Fh,aebrBox:()=>Gc,afbrBox:()=>Vc,albcBox:()=>jc,alstSampleGroupEntry:()=>kd,altrBox:()=>$c,auxCBox:()=>pc,av01SampleEntry:()=>oh,av1CBox:()=>Jo,avc1SampleEntry:()=>sh,avc2SampleEntry:()=>rh,avc3SampleEntry:()=>nh,avc4SampleEntry:()=>ah,avcCBox:()=>xa,avllSampleGroupEntry:()=>Id,avs3SampleEntry:()=>Bh,avssSampleGroupEntry:()=>Td,brstBox:()=>qc,btrtBox:()=>_c,bxmlBox:()=>So,ccstBox:()=>mc,cdefBox:()=>gc,clapBox:()=>xc,clefBox:()=>Cl,clliBox:()=>yc,cmexBox:()=>bc,cminBox:()=>vc,cmpdBox:()=>Sc,co64Box:()=>Uc,colrBox:()=>ih,coviBox:()=>Ec,cprtBox:()=>kc,cschBox:()=>Ic,cslgBox:()=>Tc,cttsBox:()=>Pc,dOpsBox:()=>Oc,dac3Box:()=>Ac,dataBox:()=>dn,dav1SampleEntry:()=>hh,dec3Box:()=>Fc,dfLaBox:()=>Cc,dimmBox:()=>Dc,dinfBox:()=>Ua,dmax:()=>Lc,dmedBox:()=>Hc,dobrBox:()=>Yc,drefBox:()=>Ea,drepBox:()=>Rc,dtrtSampleGroupEntry:()=>Pd,dvh1SampleEntry:()=>mh,dvheSampleEntry:()=>gh,ec_3SampleEntry:()=>Ch,edtsBox:()=>Bo,elngBox:()=>ka,elstBox:()=>Mc,emsgBox:()=>Nc,encaSampleEntry:()=>Gh,encmSampleEntry:()=>Yh,encsSampleEntry:()=>jh,enctSampleEntry:()=>qh,encuSampleEntry:()=>Vh,encvSampleEntry:()=>Nh,enofBox:()=>Ll,eqivBox:()=>Wc,esdsBox:()=>Zo,etypBox:()=>No,fLaCSampleEntry:()=>Mh,favcBox:()=>Kc,fielBox:()=>nl,fobrBox:()=>Xc,freeBox:()=>xo,frmaBox:()=>al,ftypBox:()=>Ia,grplBox:()=>Ro,hdlrBox:()=>Ta,hev1SampleEntry:()=>dh,hev2SampleEntry:()=>fh,hinfBox:()=>Io,hmhdBox:()=>ya,hntiBox:()=>ko,hvc1SampleEntry:()=>ch,hvc2SampleEntry:()=>lh,hvcCBox:()=>Pa,hvt1SampleEntry:()=>uh,iaugBox:()=>Qc,idatBox:()=>go,iinfBox:()=>jo,ilocBox:()=>$o,ilstBox:()=>Hl,imirBox:()=>ol,infeBox:()=>Vo,iodsBox:()=>bo,ipcoBox:()=>Oo,ipmaBox:()=>hl,iproBox:()=>Uo,iprpBox:()=>Ho,irefBox:()=>Yo,irotBox:()=>cl,ispeBox:()=>ll,itaiBox:()=>dl,j2kHBox:()=>Mo,j2kiSampleEntry:()=>wh,keysBox:()=>Ol,kindBox:()=>fl,levaBox:()=>ul,lhe1SampleEntry:()=>ph,lhv1SampleEntry:()=>_h,lhvCBox:()=>pl,lselBox:()=>_l,m4aeSampleEntry:()=>Ph,maxrBox:()=>ml,mdatBox:()=>kn,mdcvBox:()=>gl,mdhdBox:()=>Aa,mdiaBox:()=>va,mecoBox:()=>Eo,mehdBox:()=>Fa,metaBox:()=>Ko,mettSampleEntry:()=>Xo,metxSampleEntry:()=>Qo,mfhdBox:()=>Ca,mfraBox:()=>zo,mfroBox:()=>xl,mha1SampleEntry:()=>Lh,mha2SampleEntry:()=>Hh,mhm1SampleEntry:()=>Oh,mhm2SampleEntry:()=>Rh,minfBox:()=>Sa,mjp2SampleEntry:()=>zh,mjpgSampleEntry:()=>Eh,moofBox:()=>wa,moovBox:()=>$n,mp4aSampleEntry:()=>Th,mp4sSampleEntry:()=>$h,mp4vSampleEntry:()=>Ih,mskCBox:()=>yl,msrcTrackGroupTypeBox:()=>md,mvexBox:()=>qn,mvhdBox:()=>Da,mvifSampleGroupEntry:()=>Ad,nmhdBox:()=>In,npckBox:()=>bl,numpBox:()=>vl,padbBox:()=>Ul,panoBox:()=>Jc,paspBox:()=>Bl,paylBox:()=>wl,paytBox:()=>zl,pdinBox:()=>El,piffLsmBox:()=>Yd,piffPsshBox:()=>Wd,piffSencBox:()=>Kd,piffTencBox:()=>Xd,piffTfrfBox:()=>Qd,piffTfxdBox:()=>Jd,pitmBox:()=>Wo,pixiBox:()=>kl,pmaxBox:()=>Il,povdBox:()=>Go,prdiBox:()=>Tl,prfrBox:()=>Pl,prftBox:()=>Al,prgrBox:()=>sl,profBox:()=>Rl,prolSampleGroupEntry:()=>Fd,psshBox:()=>Fl,pymdBox:()=>rl,rapSampleGroupEntry:()=>Cd,rashSampleGroupEntry:()=>Dd,resvSampleEntry:()=>Wh,rinfBox:()=>Fo,rollSampleGroupEntry:()=>Ld,rtp_Box:()=>Gl,saioBox:()=>Vl,saizBox:()=>jl,sbgpBox:()=>Zh,sbpmBox:()=>ql,sbttSampleEntry:()=>Kh,schiBox:()=>Co,schmBox:()=>Yl,scifSampleGroupEntry:()=>Hd,scnmSampleGroupEntry:()=>Od,sdp_Box:()=>Wl,sdtpBox:()=>tc,seigSampleGroupEntry:()=>Rd,sencBox:()=>Kl,sgpdBox:()=>ec,sidxBox:()=>ic,sinfBox:()=>Ao,skipBox:()=>yo,slidBox:()=>Zc,smhdBox:()=>Ra,sratBox:()=>Ql,ssixBox:()=>Jl,stblBox:()=>Ba,stcoBox:()=>Ma,stdpBox:()=>Zl,sterBox:()=>tl,sthdBox:()=>Na,stppSampleEntry:()=>Oa,strdBox:()=>Po,striBox:()=>td,strkBox:()=>To,stsaSampleGroupEntry:()=>Md,stscBox:()=>Ga,stsdBox:()=>Va,stsgBox:()=>ed,stshBox:()=>id,stssBox:()=>sd,stszBox:()=>ja,sttsBox:()=>$a,stviBox:()=>rd,stxtSampleEntry:()=>Xh,stypBox:()=>nd,stz2Box:()=>ad,subsBox:()=>od,syncSampleGroupEntry:()=>Nd,taicBox:()=>hd,taptBox:()=>Ml,teleSampleGroupEntry:()=>Gd,tencBox:()=>cd,tfdtBox:()=>qa,tfhdBox:()=>Ya,tfraBox:()=>ld,tkhdBox:()=>Wa,tmaxBox:()=>dd,tminBox:()=>fd,totlBox:()=>ud,tpayBox:()=>pd,tpylBox:()=>_d,trafBox:()=>za,trakBox:()=>ba,trefBox:()=>gd,trepBox:()=>xd,trexBox:()=>Yn,trgrBox:()=>Do,trpyBox:()=>yd,trunBox:()=>Ka,tsasSampleGroupEntry:()=>Vd,tsclSampleGroupEntry:()=>jd,tselBox:()=>bd,tsynBox:()=>el,tx3gSampleEntry:()=>Qh,txtcBox:()=>vd,tycoBox:()=>Sd,udesBox:()=>Ud,udtaBox:()=>Lo,uncCBox:()=>Bd,uncvSampleEntry:()=>kh,urlBox:()=>Xa,urnBox:()=>wd,viprSampleGroupEntry:()=>$d,vmhdBox:()=>Qa,vp08SampleEntry:()=>Sh,vp09SampleEntry:()=>Uh,vpcCBox:()=>th,vttCBox:()=>zd,vttcBox:()=>wo,vvc1SampleEntry:()=>xh,vvcCBox:()=>eh,vvcNSampleEntry:()=>vh,vvi1SampleEntry:()=>yh,vvnCBox:()=>Ed,vvs1SampleEntry:()=>bh,waveBox:()=>Nl,wbbrBox:()=>il,wvttSampleEntry:()=>Jh,xmlBox:()=>vo});var wi,fc=(wi=class extends p{constructor(){super(...arguments),this.box_name="AV1LayeredImageIndexingProperty"}parse(t){const i=((t.readUint8()&1&1)+1)*16;this.layer_size=[];for(let s=0;s<3;s++)i===16?this.layer_size[s]=t.readUint16():this.layer_size[s]=t.readUint32()}},wi.fourcc="a1lx",wi),zi,uc=(zi=class extends p{constructor(){super(...arguments),this.box_name="OperatingPointSelectorProperty"}parse(t){this.op_index=t.readUint8()}},zi.fourcc="a1op",zi),Ei,pc=(Ei=class extends d{constructor(){super(...arguments),this.box_name="AuxiliaryTypeProperty"}parse(t){this.parseFullHeader(t),this.aux_type=t.readCString();const e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)}},Ei.fourcc="auxC",Ei),ki,_c=(ki=class extends p{constructor(){super(...arguments),this.box_name="BitRateBox"}parse(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()}},ki.fourcc="btrt",ki),Ii,mc=(Ii=class extends d{constructor(){super(...arguments),this.box_name="CodingConstraintsBox"}parse(t){this.parseFullHeader(t);const e=t.readUint8();this.all_ref_pics_intra=(e&128)===128,this.intra_pred_used=(e&64)===64,this.max_ref_per_pic=(e&63)>>2,t.readUint24()}},Ii.fourcc="ccst",Ii),Ti,gc=(Ti=class extends p{constructor(){super(...arguments),this.box_name="ComponentDefinitionBox"}parse(t){this.channel_count=t.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[];for(let e=0;e<this.channel_count;e++)this.channel_indexes.push(t.readUint16()),this.channel_types.push(t.readUint16()),this.channel_associations.push(t.readUint16())}},Ti.fourcc="cdef",Ti),Pi,xc=(Pi=class extends p{constructor(){super(...arguments),this.box_name="CleanApertureBox"}parse(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()}},Pi.fourcc="clap",Pi),Ai,yc=(Ai=class extends p{constructor(){super(...arguments),this.box_name="ContentLightLevelBox"}parse(t){this.max_content_light_level=t.readUint16(),this.max_pic_average_light_level=t.readUint16()}},Ai.fourcc="clli",Ai),Fi,bc=(Fi=class extends p{constructor(){super(...arguments),this.box_name="CameraExtrinsicMatrixProperty"}parse(t){this.flags&1&&(this.pos_x=t.readInt32()),this.flags&2&&(this.pos_y=t.readInt32()),this.flags&4&&(this.pos_z=t.readInt32()),this.flags&8&&(this.version===0?this.flags&16?(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),this.flags&32&&(this.id=t.readUint32())}},Fi.fourcc="cmex",Fi),Ci,vc=(Ci=class extends p{constructor(){super(...arguments),this.box_name="CameraIntrinsicMatrixProperty"}parse(t){this.focal_length_x=t.readInt32(),this.principal_point_x=t.readInt32(),this.principal_point_y=t.readInt32(),this.flags&1&&(this.focal_length_y=t.readInt32(),this.skew_factor=t.readInt32())}},Ci.fourcc="cmin",Ci),Di,Sc=(Di=class extends p{constructor(){super(...arguments),this.box_name="ComponentDefinitionBox"}parse(t){this.component_count=t.readUint32(),this.component_types=[],this.component_type_urls=[];for(let e=0;e<this.component_count;e++){const i=t.readUint16();this.component_types.push(i),i>=32768&&this.component_type_urls.push(t.readCString())}}},Di.fourcc="cmpd",Di),Li,Uc=(Li=class extends d{constructor(){super(...arguments),this.box_name="ChunkLargeOffsetBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.chunk_offsets=[],this.version===0)for(let i=0;i<e;i++)this.chunk_offsets.push(t.readUint64())}write(t){this.version=0,this.flags=0,this.size=4+8*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length);for(let e=0;e<this.chunk_offsets.length;e++)t.writeUint64(this.chunk_offsets[e])}},Li.fourcc="co64",Li),Hi,Bc=(Hi=class extends d{constructor(){super(...arguments),this.box_name="ContentLightLevelBox"}parse(t){this.parseFullHeader(t),this.maxCLL=t.readUint16(),this.maxFALL=t.readUint16()}},Hi.fourcc="CoLL",Hi),wc=class{toString(){let r="centre_azimuth: ";return r+=this.centre_azimuth,r+=" (",r+=this.centre_azimuth*2**-16,r+="°), centre_elevation: ",r+=this.centre_elevation,r+=" (",r+=this.centre_elevation*2**-16,r+="°), centre_tilt: ",r+=this.centre_tilt,r+=" (",r+=this.centre_tilt*2**-16,r+="°)",this.range_included_flag&&(r+=", azimuth_range: ",r+=this.azimuth_range,r+=" (",r+=this.azimuth_range*2**-16,r+="°), elevation_range: ",r+=this.elevation_range,r+=" (",r+=this.elevation_range*2**-16,r+="°)"),this.interpolate_included_flag&&(r+=", interpolate: ",r+=this.interpolate),r}},zc=class{toString(){let r="";return this.view_idc&&(r+="view_idc: ",r+=this.view_idc,r+=", "),r+="sphere_region: {",r+=this.sphere_region,r+="}",r}},Oi,Ec=(Oi=class extends d{constructor(){super(...arguments),this.box_name="CoverageInformationBox"}parse(t){this.parseFullHeader(t),this.coverage_shape_type=t.readUint8();const e=t.readUint8(),i=t.readInt8(),s=i&128;s&&(this.default_view_idc=(i&96)>>5),this.coverage_regions=new Array;for(let n=0;n<e;n++){const a=new zc;s&&(a.view_idc=t.readUint8()>>6),a.sphere_region=this.parseSphereRegion(t,!0,!0),this.coverage_regions.push(a)}}parseSphereRegion(t,e,i){const s=new wc;return s.centre_azimuth=t.readInt32(),s.centre_elevation=t.readInt32(),s.centre_tilt=t.readInt32(),s.range_included_flag=e,e&&(s.azimuth_range=t.readUint32(),s.elevation_range=t.readUint32()),s.interpolate_included_flag=i,i&&(s.interpolate=(t.readUint8()&128)===128),s}},Oi.fourcc="covi",Oi),Ri,kc=(Ri=class extends d{constructor(){super(...arguments),this.box_name="CopyrightBox"}parse(t){this.parseFullHeader(t),this.parseLanguage(t),this.notice=t.readCString()}},Ri.fourcc="cprt",Ri),Mi,Ic=(Mi=class extends d{constructor(){super(...arguments),this.box_name="CompatibleSchemeTypeBox"}parse(t){this.parseFullHeader(t),this.scheme_type=t.readString(4),this.scheme_version=t.readUint32(),this.flags&1&&(this.scheme_uri=t.readCString())}},Mi.fourcc="csch",Mi),ln=2147483647,Ni,Tc=(Ni=class extends d{constructor(){super(...arguments),this.box_name="CompositionToDecodeBox"}parse(t){this.parseFullHeader(t),this.version===0?(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32()):this.version===1&&(this.compositionToDTSShift=t.readInt64(),this.leastDecodeToDisplayDelta=t.readInt64(),this.greatestDecodeToDisplayDelta=t.readInt64(),this.compositionStartTime=t.readInt64(),this.compositionEndTime=t.readInt64())}write(t){this.version=0,(this.compositionToDTSShift>ln||this.leastDecodeToDisplayDelta>ln||this.greatestDecodeToDisplayDelta>ln||this.compositionStartTime>ln||this.compositionEndTime>ln)&&(this.version=1),this.flags=0,this.version===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)):this.version===1&&(this.size=40,this.writeHeader(t),t.writeInt64(this.compositionToDTSShift),t.writeInt64(this.leastDecodeToDisplayDelta),t.writeInt64(this.greatestDecodeToDisplayDelta),t.writeInt64(this.compositionStartTime),t.writeInt64(this.compositionEndTime))}},Ni.fourcc="cslg",Ni),Gi,Pc=(Gi=class extends d{constructor(){super(...arguments),this.box_name="CompositionOffsetBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.sample_counts=[],this.sample_offsets=[],this.version===0)for(let i=0;i<e;i++){this.sample_counts.push(t.readUint32());const s=t.readInt32();s<0&&l.warn("BoxParser","ctts box uses negative values without using version 1"),this.sample_offsets.push(s)}else if(this.version===1)for(let i=0;i<e;i++)this.sample_counts.push(t.readUint32()),this.sample_offsets.push(t.readInt32())}write(t){this.version=this.sample_offsets.some(e=>e<0)?1:0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length);for(let e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),this.version===1?t.writeInt32(this.sample_offsets[e]):t.writeUint32(this.sample_offsets[e])}unpack(t){let e=0;for(let i=0;i<this.sample_counts.length;i++)for(let s=0;s<this.sample_counts[i];s++)t[e].pts=t[e].dts+this.sample_offsets[i],e++}},Gi.fourcc="ctts",Gi),Vi,Ac=(Vi=class extends p{constructor(){super(...arguments),this.box_name="AC3SpecificBox"}parse(t){const e=t.readUint8(),i=t.readUint8(),s=t.readUint8();this.fscod=e>>6,this.bsid=e>>1&31,this.bsmod=(e&1)<<2|i>>6&3,this.acmod=i>>3&7,this.lfeon=i>>2&1,this.bit_rate_code=i&3|s>>5&7}},Vi.fourcc="dac3",Vi),ji,Fc=(ji=class extends p{constructor(){super(...arguments),this.box_name="EC3SpecificBox"}parse(t){const e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=e&7,this.ind_subs=[];for(let i=0;i<this.num_ind_sub+1;i++){const s=t.readUint8(),n=t.readUint8(),a=t.readUint8(),o={fscod:s>>6,bsid:s>>1&31,bsmod:(s&1)<<4|n>>4&15,acmod:n>>1&7,lfeon:n&1,num_dep_sub:a>>1&15};this.ind_subs.push(o),o.num_dep_sub>0&&(o.chan_loc=(a&1)<<8|t.readUint8())}}},ji.fourcc="dec3",ji),$i,Cc=($i=class extends d{constructor(){super(...arguments),this.box_name="FLACSpecificBox"}parse(t){this.parseFullHeader(t);const e=127,i=128,s=[],n=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];let a;do{a=t.readUint8();const o=Math.min(a&e,n.length-1);o?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),s.push(n[o])}while(a&i);this.numMetadataBlocks=s.length+" ("+s.join(", ")+")"}},$i.fourcc="dfLa",$i),qi,Dc=(qi=class extends p{constructor(){super(...arguments),this.box_name="hintimmediateBytesSent"}parse(t){this.bytessent=t.readUint64()}},qi.fourcc="dimm",qi),Yi,Lc=(Yi=class extends p{constructor(){super(...arguments),this.box_name="hintlongestpacket"}parse(t){this.time=t.readUint32()}},Yi.fourcc="dmax",Yi),Wi,Hc=(Wi=class extends p{constructor(){super(...arguments),this.box_name="hintmediaBytesSent"}parse(t){this.bytessent=t.readUint64()}},Wi.fourcc="dmed",Wi),Ki,Oc=(Ki=class extends p{constructor(){super(...arguments),this.box_name="OpusSpecificBox"}parse(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(),this.ChannelMappingFamily!==0){this.StreamCount=t.readUint8(),this.CoupledCount=t.readUint8(),this.ChannelMapping=[];for(let e=0;e<this.OutputChannelCount;e++)this.ChannelMapping[e]=t.readUint8()}}write(t){if(this.size=11,this.ChannelMappingFamily!==0&&(this.size+=2+this.OutputChannelCount),this.writeHeader(t),t.writeUint8(this.Version),t.writeUint8(this.OutputChannelCount),t.writeUint16(this.PreSkip),t.writeUint32(this.InputSampleRate),t.writeInt16(this.OutputGain),t.writeUint8(this.ChannelMappingFamily),this.ChannelMappingFamily!==0){t.writeUint8(this.StreamCount),t.writeUint8(this.CoupledCount);for(let e=0;e<this.OutputChannelCount;e++)t.writeUint8(this.ChannelMapping[e])}}},Ki.fourcc="dOps",Ki),Xi,Rc=(Xi=class extends p{constructor(){super(...arguments),this.box_name="hintrepeatedBytesSent"}parse(t){this.bytessent=t.readUint64()}},Xi.fourcc="drep",Xi),Qi,Mc=(Qi=class extends d{constructor(){super(...arguments),this.box_name="EditListBox"}parse(t){this.parseFullHeader(t),this.entries=[];const e=t.readUint32();for(let i=0;i<e;i++){const s={segment_duration:this.version===1?t.readUint64():t.readUint32(),media_time:this.version===1?t.readInt64():t.readInt32(),media_rate_integer:t.readInt16(),media_rate_fraction:t.readInt16()};this.entries.push(s)}}write(t){const e=this.entries.some(i=>i.segment_duration>w||i.media_time>w)||this.version===1;this.version=e?1:0,this.size=4+12*this.entries.length,this.size+=e?8*this.entries.length:0,this.writeHeader(t),t.writeUint32(this.entries.length);for(let i=0;i<this.entries.length;i++){const s=this.entries[i];e?(t.writeUint64(s.segment_duration),t.writeInt64(s.media_time)):(t.writeUint32(s.segment_duration),t.writeInt32(s.media_time)),t.writeInt16(s.media_rate_integer),t.writeInt16(s.media_rate_fraction)}}},Qi.fourcc="elst",Qi),Ji,Nc=(Ji=class extends d{constructor(){super(...arguments),this.box_name="EventMessageBox"}parse(t){this.parseFullHeader(t),this.version===1?(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());let e=this.size-this.hdr_size-(16+(this.scheme_id_uri.length+1)+(this.value.length+1));this.version===1&&(e-=4),this.message_data=t.readUint8Array(e)}write(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)}},Ji.fourcc="emsg",Ji),E=class extends d{parse(r){this.parseFullHeader(r),this.group_id=r.readUint32(),this.num_entities_in_group=r.readUint32(),this.entity_ids=[];for(let t=0;t<this.num_entities_in_group;t++){const e=r.readUint32();this.entity_ids.push(e)}}},Zi,Gc=(Zi=class extends E{constructor(){super(...arguments),this.box_name="Auto exposure bracketing"}},Zi.fourcc="aebr",Zi),ts,Vc=(ts=class extends E{constructor(){super(...arguments),this.box_name="Flash exposure information"}},ts.fourcc="afbr",ts),es,jc=(es=class extends E{constructor(){super(...arguments),this.box_name="Album collection"}},es.fourcc="albc",es),is,$c=(is=class extends E{constructor(){super(...arguments),this.box_name="Alternative entity"}},is.fourcc="altr",is),ss,qc=(ss=class extends E{constructor(){super(...arguments),this.box_name="Burst image"}},ss.fourcc="brst",ss),rs,Yc=(rs=class extends E{constructor(){super(...arguments),this.box_name="Depth of field bracketing"}},rs.fourcc="dobr",rs),ns,Wc=(ns=class extends E{constructor(){super(...arguments),this.box_name="Equivalent entity"}},ns.fourcc="eqiv",ns),as,Kc=(as=class extends E{constructor(){super(...arguments),this.box_name="Favorites collection"}},as.fourcc="favc",as),os,Xc=(os=class extends E{constructor(){super(...arguments),this.box_name="Focus bracketing"}},os.fourcc="fobr",os),hs,Qc=(hs=class extends E{constructor(){super(...arguments),this.box_name="Image item with an audio track"}},hs.fourcc="iaug",hs),cs,Jc=(cs=class extends E{constructor(){super(...arguments),this.box_name="Panorama"}},cs.fourcc="pano",cs),ls,Zc=(ls=class extends E{constructor(){super(...arguments),this.box_name="Slideshow"}},ls.fourcc="slid",ls),ds,tl=(ds=class extends E{constructor(){super(...arguments),this.box_name="Stereo"}},ds.fourcc="ster",ds),fs,el=(fs=class extends E{constructor(){super(...arguments),this.box_name="Time-synchronized capture"}},fs.fourcc="tsyn",fs),us,il=(us=class extends E{constructor(){super(...arguments),this.box_name="White balance bracketing"}},us.fourcc="wbbr",us),ps,sl=(ps=class extends E{constructor(){super(...arguments),this.box_name="Progressive rendering"}},ps.fourcc="prgr",ps),_s,rl=(_s=class extends E{constructor(){super(...arguments),this.box_name="Image pyramid"}parse(t){this.parseFullHeader(t),this.group_id=t.readUint32(),this.num_entities_in_group=t.readUint32(),this.entity_ids=[];for(let e=0;e<this.num_entities_in_group;e++){const i=t.readUint32();this.entity_ids.push(i)}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=[];for(let e=0;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()}},_s.fourcc="pymd",_s),ms,nl=(ms=class extends p{constructor(){super(...arguments),this.box_name="FieldHandlingBox"}parse(t){this.fieldCount=t.readUint8(),this.fieldOrdering=t.readUint8()}},ms.fourcc="fiel",ms),gs,al=(gs=class extends p{constructor(){super(...arguments),this.box_name="OriginalFormatBox"}parse(t){this.data_format=t.readString(4)}},gs.fourcc="frma",gs),xs,ol=(xs=class extends p{constructor(){super(...arguments),this.box_name="ImageMirror"}parse(t){const e=t.readUint8();this.reserved=e>>7,this.axis=e&1}},xs.fourcc="imir",xs),ys,hl=(ys=class extends d{constructor(){super(...arguments),this.box_name="ItemPropertyAssociationBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();this.associations=[];for(let i=0;i<e;i++){const s=this.version<1?t.readUint16():t.readUint32(),n=[],a=t.readUint8();for(let o=0;o<a;o++){const h=t.readUint8();n.push({essential:(h&128)>>7===1,property_index:this.flags&1?(h&127)<<8|t.readUint8():h&127})}this.associations.push({id:s,props:n})}}},ys.fourcc="ipma",ys),bs,cl=(bs=class extends p{constructor(){super(...arguments),this.box_name="ImageRotation"}parse(t){this.angle=t.readUint8()&3}},bs.fourcc="irot",bs),vs,ll=(vs=class extends d{constructor(){super(...arguments),this.box_name="ImageSpatialExtentsProperty"}parse(t){this.parseFullHeader(t),this.image_width=t.readUint32(),this.image_height=t.readUint32()}},vs.fourcc="ispe",vs),Ss,dl=(Ss=class extends d{constructor(){super(...arguments),this.box_name="TAITimestampBox"}parse(t){this.TAI_timestamp=t.readUint64();const e=t.readUint8();this.sychronization_state=e>>7&1,this.timestamp_generation_failure=e>>6&1,this.timestamp_is_modified=e>>5&1}},Ss.fourcc="itai",Ss),Us,fl=(Us=class extends d{constructor(){super(...arguments),this.box_name="KindBox"}parse(t){this.parseFullHeader(t),this.schemeURI=t.readCString(),this.isEndOfBox(t)||(this.value=t.readCString())}write(t){this.version=0,this.flags=0,this.size=this.schemeURI.length+1+(this.value?this.value.length+1:0),this.writeHeader(t),t.writeCString(this.schemeURI),this.value&&t.writeCString(this.value)}},Us.fourcc="kind",Us),Bs,ul=(Bs=class extends d{constructor(){super(...arguments),this.box_name="LevelAssignmentBox"}parse(t){this.parseFullHeader(t);const e=t.readUint8();this.levels=[];for(let i=0;i<e;i++){const s={};this.levels[i]=s,s.track_ID=t.readUint32();const n=t.readUint8();switch(s.padding_flag=n>>7,s.assignment_type=n&127,s.assignment_type){case 0:s.grouping_type=t.readString(4);break;case 1:s.grouping_type=t.readString(4),s.grouping_type_parameter=t.readUint32();break;case 2:break;case 3:break;case 4:s.sub_track_id=t.readUint32();break;default:l.warn("BoxParser",`Unknown level assignment type: ${s.assignment_type}`)}}}},Bs.fourcc="leva",Bs),ws,pl=(ws=class extends p{constructor(){super(...arguments),this.box_name="LHEVCConfigurationBox"}parse(t){this.configurationVersion=t.readUint8(),this.min_spatial_segmentation_idc=t.readUint16()&4095,this.parallelismType=t.readUint8()&3;let e=t.readUint8();this.numTemporalLayers=(e&13)>>3,this.temporalIdNested=(e&4)>>2,this.lengthSizeMinusOne=e&3,this.nalu_arrays=[];const i=t.readUint8();for(let s=0;s<i;s++){const n=[];this.nalu_arrays.push(n),e=t.readUint8(),n.completeness=(e&128)>>7,n.nalu_type=e&63;const a=t.readUint16();for(let o=0;o<a;o++){const h=t.readUint16();n.push({data:t.readUint8Array(h)})}}}},ws.fourcc="lhvC",ws),zs,_l=(zs=class extends p{constructor(){super(...arguments),this.box_name="LayerSelectorProperty"}parse(t){this.layer_id=t.readUint16()}},zs.fourcc="lsel",zs),Es,ml=(Es=class extends p{constructor(){super(...arguments),this.box_name="hintmaxrate"}parse(t){this.period=t.readUint32(),this.bytes=t.readUint32()}},Es.fourcc="maxr",Es),bn=class{constructor(r,t){this.x=r,this.y=t}toString(){return"("+this.x+","+this.y+")"}},ks,gl=(ks=class extends p{constructor(){super(...arguments),this.box_name="MasteringDisplayColourVolumeBox"}parse(t){this.display_primaries=[],this.display_primaries[0]=new bn(t.readUint16(),t.readUint16()),this.display_primaries[1]=new bn(t.readUint16(),t.readUint16()),this.display_primaries[2]=new bn(t.readUint16(),t.readUint16()),this.white_point=new bn(t.readUint16(),t.readUint16()),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()}},ks.fourcc="mdcv",ks),Is,xl=(Is=class extends d{constructor(){super(...arguments),this.box_name="MovieFragmentRandomAccessOffsetBox"}parse(t){this.parseFullHeader(t),this._size=t.readUint32()}},Is.fourcc="mfro",Is),Ts,yl=(Ts=class extends d{constructor(){super(...arguments),this.box_name="MaskConfigurationProperty"}parse(t){this.parseFullHeader(t),this.bits_per_pixel=t.readUint8()}},Ts.fourcc="mskC",Ts),Ps,bl=(Ps=class extends p{constructor(){super(...arguments),this.box_name="hintPacketsSent"}parse(t){this.packetssent=t.readUint32()}},Ps.fourcc="npck",Ps),As,vl=(As=class extends p{constructor(){super(...arguments),this.box_name="hintPacketsSent"}parse(t){this.packetssent=t.readUint64()}},As.fourcc="nump",As),Sl=class{constructor(r,t){this.pad1=r,this.pad2=t}},Fs,Ul=(Fs=class extends d{constructor(){super(...arguments),this.box_name="PaddingBitsBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();this.padbits=[];for(let i=0;i<Math.floor((e+1)/2);i++){const s=t.readUint8(),n=(s&112)>>4,a=s&7;this.padbits.push(new Sl(n,a))}}},Fs.fourcc="padb",Fs),Cs,Bl=(Cs=class extends p{constructor(){super(...arguments),this.box_name="PixelAspectRatioBox"}parse(t){this.hSpacing=t.readUint32(),this.vSpacing=t.readUint32()}},Cs.fourcc="pasp",Cs),Ds,wl=(Ds=class extends p{constructor(){super(...arguments),this.box_name="CuePayloadBox"}parse(t){this.text=t.readString(this.size-this.hdr_size)}},Ds.fourcc="payl",Ds),Ls,zl=(Ls=class extends p{constructor(){super(...arguments),this.box_name="hintpayloadID"}parse(t){this.payloadID=t.readUint32();const e=t.readUint8();this.rtpmap_string=t.readString(e)}},Ls.fourcc="payt",Ls),Hs,El=(Hs=class extends d{constructor(){super(...arguments),this.box_name="ProgressiveDownloadInfoBox",this.rate=[],this.initial_delay=[]}parse(t){this.parseFullHeader(t);const e=(this.size-this.hdr_size)/8;for(let i=0;i<e;i++)this.rate[i]=t.readUint32(),this.initial_delay[i]=t.readUint32()}},Hs.fourcc="pdin",Hs),Os,kl=(Os=class extends d{constructor(){super(...arguments),this.box_name="PixelInformationProperty"}parse(t){this.parseFullHeader(t),this.num_channels=t.readUint8(),this.bits_per_channels=[];for(let e=0;e<this.num_channels;e++)this.bits_per_channels[e]=t.readUint8()}},Os.fourcc="pixi",Os),Rs,Il=(Rs=class extends p{constructor(){super(...arguments),this.box_name="hintlargestpacket"}parse(t){this.bytes=t.readUint32()}},Rs.fourcc="pmax",Rs),Ms,Tl=(Ms=class extends d{constructor(){super(...arguments),this.box_name="ProgressiveDerivedImageItemInformationProperty"}parse(t){if(this.parseFullHeader(t),this.step_count=t.readUint16(),this.item_count=[],this.flags&2)for(let e=0;e<this.step_count;e++)this.item_count[e]=t.readUint16()}},Ms.fourcc="prdi",Ms),Ns,Pl=(Ns=class extends d{constructor(){super(...arguments),this.box_name="ProjectionFormatBox"}parse(t){this.parseFullHeader(t),this.projection_type=t.readUint8()&31}},Ns.fourcc="prfr",Ns),Gs,Al=(Gs=class extends d{constructor(){super(...arguments),this.box_name="ProducerReferenceTimeBox"}parse(t){this.parseFullHeader(t),this.ref_track_id=t.readUint32(),this.ntp_timestamp=t.readUint64(),this.version===0?this.media_time=t.readUint32():this.media_time=t.readUint64()}},Gs.fourcc="prft",Gs),Vs,Fl=(Vs=class extends d{constructor(){super(...arguments),this.box_name="ProtectionSystemSpecificHeaderBox"}parse(t){if(this.parseFullHeader(t),this.system_id=Q(t),this.kid=[],this.version>0){const i=t.readUint32();for(let s=0;s<i;s++)this.kid[s]=Q(t)}const e=t.readUint32();e>0&&(this.protection_data=t.readUint8Array(e))}},Vs.fourcc="pssh",Vs),js,Cl=(js=class extends d{constructor(){super(...arguments),this.box_name="TrackCleanApertureDimensionsBox"}parse(t){this.parseFullHeader(t),this.width=t.readUint32(),this.height=t.readUint32()}},js.fourcc="clef",js);function Dl(r,t){if(r===dn.Types.UTF8)return new TextDecoder("utf-8").decode(t);const e=new DataView(t.buffer);if(r===dn.Types.BE_UNSIGNED_INT){if(t.length===1)return e.getUint8(0);if(t.length===2)return e.getUint16(0,!1);if(t.length===4)return e.getUint32(0,!1);if(t.length===8)return e.getBigUint64(0,!1);throw new Error("Unsupported ITIF_TYPE_BE_UNSIGNED_INT length "+t.length)}else if(r===dn.Types.BE_SIGNED_INT){if(t.length===1)return e.getInt8(0);if(t.length===2)return e.getInt16(0,!1);if(t.length===4)return e.getInt32(0,!1);if(t.length===8)return e.getBigInt64(0,!1);throw new Error("Unsupported ITIF_TYPE_BE_SIGNED_INT length "+t.length)}else if(r===dn.Types.BE_FLOAT32)return e.getFloat32(0,!1);l.warn("DataBox","Unsupported or unimplemented itif data type: "+r)}var X,dn=(X=class extends p{constructor(){super(...arguments),this.box_name="DataBox"}parse(t){this.valueType=t.readUint32(),this.country=t.readUint16(),this.country>255&&(t.seek(t.getPosition()-2),this.countryString=t.readString(2)),this.language=t.readUint16(),this.language>255&&(t.seek(t.getPosition()-2),this.parseLanguage(t)),this.raw=t.readUint8Array(this.size-this.hdr_size-8),this.value=Dl(this.valueType,this.raw)}},X.fourcc="data",X.Types={RESERVED:0,UTF8:1,UTF16:2,SJIS:3,UTF8_SORT:4,UTF16_SORT:5,JPEG:13,PNG:14,BE_SIGNED_INT:21,BE_UNSIGNED_INT:22,BE_FLOAT32:23,BE_FLOAT64:24,BMP:27,QT_ATOM:28,BE_SIGNED_INT8:65,BE_SIGNED_INT16:66,BE_SIGNED_INT32:67,BE_FLOAT32_POINT:70,BE_FLOAT32_DIMENSIONS:71,BE_FLOAT32_RECT:72,BE_SIGNED_INT64:74,BE_UNSIGNED_INT8:75,BE_UNSIGNED_INT16:76,BE_UNSIGNED_INT32:77,BE_UNSIGNED_INT64:78,BE_FLOAT64_AFFINE_TRANSFORM:79},X),$s,Ll=($s=class extends d{constructor(){super(...arguments),this.box_name="TrackEncodedPixelsDimensionsBox"}parse(t){this.parseFullHeader(t),this.width=t.readUint32(),this.height=t.readUint32()}},$s.fourcc="enof",$s),qs,Hl=(qs=class extends p{constructor(){super(...arguments),this.box_name="IlstBox"}parse(t){this.list={};let e=this.size-this.hdr_size;for(;e>0;){const i=t.readUint32(),s=t.readUint32(),n=H(t,!1,i-8);n.code===D&&(this.list[s]=n.box),e-=i}}},qs.fourcc="ilst",qs),Ys,Ol=(Ys=class extends d{constructor(){super(...arguments),this.box_name="KeysBox"}parse(t){this.parseFullHeader(t),this.count=t.readUint32(),this.keys={};for(let e=0;e<this.count;e++){const i=t.readUint32();this.keys[e+1]=t.readString(i-4)}}},Ys.fourcc="keys",Ys),Ws,Rl=(Ws=class extends d{constructor(){super(...arguments),this.box_name="TrackProductionApertureDimensionsBox"}parse(t){this.parseFullHeader(t),this.width=t.readUint32(),this.height=t.readUint32()}},Ws.fourcc="prof",Ws),Ks,Ml=(Ks=class extends y{constructor(){super(...arguments),this.box_name="TrackApertureModeDimensionsBox",this.clefs=[],this.profs=[],this.enofs=[],this.subBoxNames=["clef","prof","enof"]}},Ks.fourcc="tapt",Ks),Xs,Nl=(Xs=class extends y{constructor(){super(...arguments),this.box_name="siDecompressionParamBox"}},Xs.fourcc="wave",Xs),Qs,Gl=(Qs=class extends p{constructor(){super(...arguments),this.box_name="rtpmoviehintinformation"}parse(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)}},Qs.fourcc="rtp ",Qs),Js,Vl=(Js=class extends d{constructor(){super(...arguments),this.box_name="SampleAuxiliaryInformationOffsetsBox"}parse(t){this.parseFullHeader(t),this.flags&1&&(this.aux_info_type=t.readString(4),this.aux_info_type_parameter=t.readUint32());const e=t.readUint32();this.offset=[];for(let i=0;i<e;i++)this.version===0?this.offset[i]=t.readUint32():this.offset[i]=t.readUint64()}},Js.fourcc="saio",Js),Zs,jl=(Zs=class extends d{constructor(){super(...arguments),this.box_name="SampleAuxiliaryInformationSizesBox"}parse(t){if(this.parseFullHeader(t),this.flags&1&&(this.aux_info_type=t.readString(4),this.aux_info_type_parameter=t.readUint32()),this.default_sample_info_size=t.readUint8(),this.sample_count=t.readUint32(),this.sample_info_size=[],this.default_sample_info_size===0)for(let e=0;e<this.sample_count;e++)this.sample_info_size[e]=t.readUint8()}},Zs.fourcc="saiz",Zs),$l=class{constructor(r,t){this.bad_pixel_row=r,this.bad_pixel_column=t}toString(){return"[row: "+this.bad_pixel_row+", column: "+this.bad_pixel_column+"]"}},tr,ql=(tr=class extends d{constructor(){super(...arguments),this.box_name="SensorBadPixelsMapBox"}parse(t){this.parseFullHeader(t),this.component_count=t.readUint16(),this.component_index=[];for(let i=0;i<this.component_count;i++)this.component_index.push(t.readUint16());const e=t.readUint8();this.correction_applied=(e&128)===128,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=[];for(let i=0;i<this.num_bad_rows;i++)this.bad_rows.push(t.readUint32());for(let i=0;i<this.num_bad_cols;i++)this.bad_columns.push(t.readUint32());for(let i=0;i<this.num_bad_pixels;i++){const s=t.readUint32(),n=t.readUint32();this.bad_pixels.push(new $l(s,n))}}},tr.fourcc="sbpm",tr),er,Yl=(er=class extends d{constructor(){super(...arguments),this.box_name="SchemeTypeBox"}parse(t){this.parseFullHeader(t),this.scheme_type=t.readString(4),this.scheme_version=t.readUint32(),this.flags&1&&(this.scheme_uri=t.readString(this.size-this.hdr_size-8))}},er.fourcc="schm",er),ir,Wl=(ir=class extends p{constructor(){super(...arguments),this.box_name="rtptracksdphintinformation"}parse(t){this.sdptext=t.readString(this.size-this.hdr_size)}},ir.fourcc="sdp ",ir),sr,Kl=(sr=class extends d{constructor(){super(...arguments),this.box_name="SampleEncryptionBox"}},sr.fourcc="senc",sr),rr,Xl=(rr=class extends d{constructor(){super(...arguments),this.box_name="SMPTE2086MasteringDisplayMetadataBox"}parse(t){this.parseFullHeader(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()}},rr.fourcc="SmDm",rr),nr,Ql=(nr=class extends d{constructor(){super(...arguments),this.box_name="SamplingRateBox"}parse(t){this.parseFullHeader(t),this.sampling_rate=t.readUint32()}},nr.fourcc="srat",nr),ar,Jl=(ar=class extends d{constructor(){super(...arguments),this.box_name="CompressedSubsegmentIndexBox"}parse(t){this.parseFullHeader(t),this.subsegments=[];const e=t.readUint32();for(let i=0;i<e;i++){const s={};this.subsegments.push(s),s.ranges=[];const n=t.readUint32();for(let a=0;a<n;a++){const o={};s.ranges.push(o),o.level=t.readUint8(),o.range_size=t.readUint24()}}}},ar.fourcc="ssix",ar),or,Zl=(or=class extends d{constructor(){super(...arguments),this.box_name="DegradationPriorityBox"}parse(t){this.parseFullHeader(t);const e=(this.size-this.hdr_size)/2;this.priority=[];for(let i=0;i<e;i++)this.priority[i]=t.readUint16()}},or.fourcc="stpd",or),hr,td=(hr=class extends d{constructor(){super(...arguments),this.box_name="SubTrackInformationBox"}parse(t){this.parseFullHeader(t),this.switch_group=t.readUint16(),this.alternate_group=t.readUint16(),this.sub_track_id=t.readUint32();const e=(this.size-this.hdr_size-8)/4;this.attribute_list=[];for(let i=0;i<e;i++)this.attribute_list[i]=t.readUint32()}},hr.fourcc="stri",hr),cr,ed=(cr=class extends d{constructor(){super(...arguments),this.box_name="SubTrackSampleGroupBox"}parse(t){this.parseFullHeader(t),this.grouping_type=t.readUint32();const e=t.readUint16();this.group_description_index=[];for(let i=0;i<e;i++)this.group_description_index[i]=t.readUint32()}},cr.fourcc="stsg",cr),lr,id=(lr=class extends d{constructor(){super(...arguments),this.box_name="ShadowSyncSampleBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.shadowed_sample_numbers=[],this.sync_sample_numbers=[],this.version===0)for(let i=0;i<e;i++)this.shadowed_sample_numbers.push(t.readUint32()),this.sync_sample_numbers.push(t.readUint32())}write(t){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);for(let e=0;e<this.shadowed_sample_numbers.length;e++)t.writeUint32(this.shadowed_sample_numbers[e]),t.writeUint32(this.sync_sample_numbers[e])}},lr.fourcc="stsh",lr),dr,sd=(dr=class extends d{constructor(){super(...arguments),this.box_name="SyncSampleBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();if(this.version===0){this.sample_numbers=[];for(let i=0;i<e;i++)this.sample_numbers.push(t.readUint32())}}write(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)}},dr.fourcc="stss",dr),fr,rd=(fr=class extends d{constructor(){super(...arguments),this.box_name="StereoVideoBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();this.single_view_allowed=e&3,this.stereo_scheme=t.readUint32();const i=t.readUint32();for(this.stereo_indication_type=t.readString(i),this.boxes=[];t.getPosition()<this.start+this.size;){const s=H(t,!1,this.size-(t.getPosition()-this.start));if(s.code===D){const n=s.box;this.boxes.push(n),this[n.type]=n}else return}}},fr.fourcc="stvi",fr),ur,nd=(ur=class extends p{constructor(){super(...arguments),this.box_name="SegmentTypeBox"}parse(t){let e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];let i=0;for(;e>=4;)this.compatible_brands[i]=t.readString(4),e-=4,i++}write(t){this.size=8+4*this.compatible_brands.length,this.writeHeader(t),t.writeString(this.major_brand,void 0,4),t.writeUint32(this.minor_version);for(let e=0;e<this.compatible_brands.length;e++)t.writeString(this.compatible_brands[e],void 0,4)}},ur.fourcc="styp",ur),pr,ad=(pr=class extends d{constructor(){super(...arguments),this.box_name="CompactSampleSizeBox"}parse(t){if(this.parseFullHeader(t),this.sample_sizes=[],this.version===0){this.reserved=t.readUint24(),this.field_size=t.readUint8();const e=t.readUint32();if(this.field_size===4)for(let i=0;i<e;i+=2){const s=t.readUint8();this.sample_sizes[i]=s>>4&15,this.sample_sizes[i+1]=s&15}else if(this.field_size===8)for(let i=0;i<e;i++)this.sample_sizes[i]=t.readUint8();else if(this.field_size===16)for(let i=0;i<e;i++)this.sample_sizes[i]=t.readUint16();else l.error("BoxParser","Error in length field in stz2 box",t.isofile)}}},pr.fourcc="stz2",pr),_r,od=(_r=class extends d{constructor(){super(...arguments),this.box_name="SubSampleInformationBox"}parse(t){this.parseFullHeader(t);const e=t.readUint32();this.entries=[];let i;for(let s=0;s<e;s++){const n={};if(this.entries[s]=n,n.sample_delta=t.readUint32(),n.subsamples=[],i=t.readUint16(),i>0)for(let a=0;a<i;a++){const o={};n.subsamples.push(o),this.version===1?o.size=t.readUint32():o.size=t.readUint16(),o.priority=t.readUint8(),o.discardable=t.readUint8(),o.codec_specific_parameters=t.readUint32()}}}},_r.fourcc="subs",_r),mr,hd=(mr=class extends d{constructor(){super(...arguments),this.box_name="TAIClockInfoBox"}parse(t){this.time_uncertainty=t.readUint64(),this.clock_resolution=t.readUint32(),this.clock_drift_rate=t.readInt32();const e=t.readUint8();this.clock_type=(e&192)>>6}},mr.fourcc="taic",mr),gr,cd=(gr=class extends d{constructor(){super(...arguments),this.box_name="TrackEncryptionBox"}parse(t){if(this.parseFullHeader(t),t.readUint8(),this.version===0)t.readUint8();else{const e=t.readUint8();this.default_crypt_byte_block=e>>4&15,this.default_skip_byte_block=e&15}this.default_isProtected=t.readUint8(),this.default_Per_Sample_IV_Size=t.readUint8(),this.default_KID=Q(t),this.default_isProtected===1&&this.default_Per_Sample_IV_Size===0&&(this.default_constant_IV_size=t.readUint8(),this.default_constant_IV=t.readUint8Array(this.default_constant_IV_size))}},gr.fourcc="tenc",gr),xr,ld=(xr=class extends d{constructor(){super(...arguments),this.box_name="TrackFragmentRandomAccessBox"}parse(t){this.parseFullHeader(t),this.track_ID=t.readUint32(),t.readUint24();const 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=e&3,this.entries=[];const i=t.readUint32();for(let s=0;s<i;s++)this.version===1?(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)]()}},xr.fourcc="tfra",xr),yr,dd=(yr=class extends p{constructor(){super(...arguments),this.box_name="hintmaxrelativetime"}parse(t){this.time=t.readUint32()}},yr.fourcc="tmax",yr),br,fd=(br=class extends p{constructor(){super(...arguments),this.box_name="hintminrelativetime"}parse(t){this.time=t.readUint32()}},br.fourcc="tmin",br),vr,ud=(vr=class extends p{constructor(){super(...arguments),this.box_name="hintBytesSent"}parse(t){this.bytessent=t.readUint32()}},vr.fourcc="totl",vr),Sr,pd=(Sr=class extends p{constructor(){super(...arguments),this.box_name="hintBytesSent"}parse(t){this.bytessent=t.readUint32()}},Sr.fourcc="tpay",Sr),Ur,_d=(Ur=class extends p{constructor(){super(...arguments),this.box_name="hintBytesSent"}parse(t){this.bytessent=t.readUint64()}},Ur.fourcc="tpyl",Ur),Br,md=(Br=class extends da{},Br.fourcc="msrc",Br),Y,gd=(Y=class extends p{constructor(){super(...arguments),this.box_name="TrackReferenceBox",this.references=[]}parse(t){for(;t.getPosition()<this.start+this.size;){const e=H(t,!0,this.size-(t.getPosition()-this.start));if(e.code===D){Y.allowed_types.includes(e.type)||l.warn("BoxParser",`Unknown track reference type: '${e.type}'`);const i=new pa(e.type,e.size,e.hdr_size,e.start);i.write===p.prototype.write&&i.type!=="mdat"&&(l.info("BoxParser","TrackReference "+i.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),i.parseDataAndRewind(t)),i.parse(t),this.references.push(i)}else return}}},Y.fourcc="tref",Y.allowed_types=["hint","cdsc","font","hind","vdep","vplx","subt","thmb","auxl","cdtg","shsc","aest"],Y),wr,xd=(wr=class extends d{constructor(){super(...arguments),this.box_name="TrackExtensionPropertiesBox"}parse(t){for(this.parseFullHeader(t),this.track_ID=t.readUint32(),this.boxes=[];t.getPosition()<this.start+this.size;){const e=H(t,!1,this.size-(t.getPosition()-this.start));if(e.code===D){const i=e.box;this.boxes.push(i)}else return}}},wr.fourcc="trep",wr),zr,yd=(zr=class extends p{constructor(){super(...arguments),this.box_name="hintBytesSent"}parse(t){this.bytessent=t.readUint64()}},zr.fourcc="trpy",zr),Er,bd=(Er=class extends d{constructor(){super(...arguments),this.box_name="TrackSelectionBox"}parse(t){this.parseFullHeader(t),this.switch_group=t.readUint32();const e=(this.size-this.hdr_size-4)/4;this.attribute_list=[];for(let i=0;i<e;i++)this.attribute_list[i]=t.readUint32()}},Er.fourcc="tsel",Er),kr,vd=(kr=class extends d{constructor(){super(...arguments),this.box_name="TextConfigBox"}parse(t){this.parseFullHeader(t),this.config=t.readCString()}},kr.fourcc="txtc",kr),Ir,Sd=(Ir=class extends p{constructor(){super(...arguments),this.box_name="TypeCombinationBox"}parse(t){const e=(this.size-this.hdr_size)/4;this.compatible_brands=[];for(let i=0;i<e;i++)this.compatible_brands[i]=t.readString(4)}},Ir.fourcc="tyco",Ir),Tr,Ud=(Tr=class extends d{constructor(){super(...arguments),this.box_name="UserDescriptionProperty"}parse(t){this.parseFullHeader(t),this.lang=t.readCString(),this.name=t.readCString(),this.description=t.readCString(),this.tags=t.readCString()}},Tr.fourcc="udes",Tr),Pr,Bd=(Pr=class extends d{constructor(){super(...arguments),this.box_name="UncompressedFrameConfigBox"}parse(t){if(this.parseFullHeader(t),this.profile=t.readString(4),this.version!==1){if(this.version===0){this.component_count=t.readUint32(),this.component_index=[],this.component_bit_depth_minus_one=[],this.component_format=[],this.component_align_size=[];for(let i=0;i<this.component_count;i++)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();const e=t.readUint8();this.component_little_endian=e>>7&1,this.block_pad_lsb=e>>6&1,this.block_little_endian=e>>5&1,this.block_reversed=e>>4&1,this.pad_unknown=e>>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()}}}},Pr.fourcc="uncC",Pr),Ar,wd=(Ar=class extends d{constructor(){super(...arguments),this.box_name="DataEntryUrnBox"}parse(t){this.parseFullHeader(t),this.name=t.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=t.readCString())}write(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)}},Ar.fourcc="urn ",Ar),Fr,zd=(Fr=class extends p{constructor(){super(...arguments),this.box_name="WebVTTConfigurationBox"}parse(t){this.text=t.readString(this.size-this.hdr_size)}},Fr.fourcc="vttC",Fr),Cr,Ed=(Cr=class extends d{constructor(){super(...arguments),this.box_name="VvcNALUConfigBox"}parse(t){this.parseFullHeader(t);const e=t.readUint8();this.lengthSizeMinusOne=e&3}},Cr.fourcc="vvnC",Cr),Dr,kd=(Dr=class extends B{parse(t){const e=t.readUint16();this.first_output_sample=t.readUint16(),this.sample_offset=[];for(let s=0;s<e;s++)this.sample_offset[s]=t.readUint32();const i=this.description_length-4-4*e;this.num_output_samples=[],this.num_total_samples=[];for(let s=0;s<i/4;s++)this.num_output_samples[s]=t.readUint16(),this.num_total_samples[s]=t.readUint16()}},Dr.grouping_type="alst",Dr),Lr,Id=(Lr=class extends B{parse(t){this.layerNumber=t.readUint8(),this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()}},Lr.grouping_type="avll",Lr),Hr,Td=(Hr=class extends B{parse(t){this.subSequenceIdentifier=t.readUint16(),this.layerNumber=t.readUint8();const 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=[];const i=t.readUint8();for(let s=0;s<i;s++)this.dependency.push({subSeqDirectionFlag:t.readUint8(),layerNumber:t.readUint8(),subSequenceIdentifier:t.readUint16()})}},Hr.grouping_type="avss",Hr),Or,Pd=(Or=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},Or.grouping_type="dtrt",Or),Rr,Ad=(Rr=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},Rr.grouping_type="mvif",Rr),Mr,Fd=(Mr=class extends B{parse(t){this.roll_distance=t.readInt16()}},Mr.grouping_type="prol",Mr),Nr,Cd=(Nr=class extends B{parse(t){const e=t.readUint8();this.num_leading_samples_known=e>>7,this.num_leading_samples=e&127}},Nr.grouping_type="rap ",Nr),Gr,Dd=(Gr=class extends B{parse(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(this.operation_point_count===1?2:this.operation_point_count*6)+9)l.warn("BoxParser","Mismatch in "+this.grouping_type+" sample group length"),this.data=t.readUint8Array(this.description_length-2);else{if(this.operation_point_count===1)this.target_rate_share=t.readUint16();else{this.target_rate_share=[],this.available_bitrate=[];for(let 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()}}},Gr.grouping_type="rash",Gr),Vr,Ld=(Vr=class extends B{parse(t){this.roll_distance=t.readInt16()}},Vr.grouping_type="roll",Vr),jr,Hd=(jr=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},jr.grouping_type="scif",jr),$r,Od=($r=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},$r.grouping_type="scnm",$r),qr,Rd=(qr=class extends B{parse(t){this.reserved=t.readUint8();const e=t.readUint8();this.crypt_byte_block=e>>4,this.skip_byte_block=e&15,this.isProtected=t.readUint8(),this.Per_Sample_IV_Size=t.readUint8(),this.KID=Q(t),this.constant_IV_size=0,this.constant_IV=0,this.isProtected===1&&this.Per_Sample_IV_Size===0&&(this.constant_IV_size=t.readUint8(),this.constant_IV=t.readUint8Array(this.constant_IV_size))}},qr.grouping_type="seig",qr),Yr,Md=(Yr=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},Yr.grouping_type="stsa",Yr),Wr,Nd=(Wr=class extends B{parse(t){const e=t.readUint8();this.NAL_unit_type=e&63}},Wr.grouping_type="sync",Wr),Kr,Gd=(Kr=class extends B{parse(t){const e=t.readUint8();this.level_independently_decodable=e>>7}},Kr.grouping_type="tele",Kr),Xr,Vd=(Xr=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},Xr.grouping_type="tsas",Xr),Qr,jd=(Qr=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},Qr.grouping_type="tscl",Qr),Jr,$d=(Jr=class extends B{parse(t){l.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}},Jr.grouping_type="vipr",Jr),Zr,qd=(Zr=class extends p{},Zr.fourcc="uuid",Zr),tn,cn=(tn=class extends d{},tn.fourcc="uuid",tn),en,Yd=(en=class extends cn{constructor(){super(...arguments),this.box_name="LiveServerManifestBox"}parse(t){this.parseFullHeader(t),this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}},en.uuid="a5d40b30e81411ddba2f0800200c9a66",en),sn,Wd=(sn=class extends cn{constructor(){super(...arguments),this.box_name="PiffProtectionSystemSpecificHeaderBox"}parse(t){this.parseFullHeader(t),this.system_id=Q(t);const e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))}},sn.uuid="d08a4f1810f34a82b6c832d8aba183d3",sn),rn,Kd=(rn=class extends cn{constructor(){super(...arguments),this.box_name="PiffSampleEncryptionBox"}},rn.uuid="a2394f525a9b4f14a2446c427c648df4",rn),nn,Xd=(nn=class extends cn{constructor(){super(...arguments),this.box_name="PiffTrackEncryptionBox"}parse(t){this.parseFullHeader(t),this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=Q(t)}},nn.uuid="8974dbce7be74c5184f97148f9882554",nn),an,Qd=(an=class extends cn{constructor(){super(...arguments),this.box_name="TfrfBox"}parse(t){this.parseFullHeader(t),this.fragment_count=t.readUint8(),this.entries=[];for(let e=0;e<this.fragment_count;e++){let i=0,s=0;this.version===1?(i=t.readUint64(),s=t.readUint64()):(i=t.readUint32(),s=t.readUint32()),this.entries.push({absolute_time:i,absolute_duration:s})}}},an.uuid="d4807ef2ca3946958e5426cb9e46a79f",an),on,Jd=(on=class extends cn{constructor(){super(...arguments),this.box_name="TfxdBox"}parse(t){this.parseFullHeader(t),this.version===1?(this.absolute_time=t.readUint64(),this.duration=t.readUint64()):(this.absolute_time=t.readUint32(),this.duration=t.readUint32())}},on.uuid="6d1d9b0542d544e680e2141daff757b2",on),hn,Zd=(hn=class extends qd{constructor(){super(...arguments),this.box_name="ItemContentIDProperty"}parse(t){this.content_id=t.readCString()}},hn.uuid="261ef3741d975bbaacbd9d2c8ea73522",hn),tf=po(ro);_o(Za);exports.AudioSampleEntry=A;exports.Box=p;exports.BoxParser=tf;exports.DIFF_BOXES_PROP_NAMES=An;exports.DIFF_PRIMITIVE_ARRAY_PROP_NAMES=_a;exports.DataStream=z;exports.Descriptor=K;exports.ES_Descriptor=Qn;exports.Endianness=la;exports.FullBox=d;exports.HintSampleEntry=jn;exports.ISOFile=Ja;exports.Log=l;exports.MP4BoxBuffer=R;exports.MPEG4DescriptorParser=so;exports.MetadataSampleEntry=J;exports.MultiBufferStream=Z;exports.SampleEntry=M;exports.SampleGroupEntry=B;exports.SampleGroupInfo=Tn;exports.SingleItemTypeReferenceBox=fa;exports.SingleItemTypeReferenceBoxLarge=ua;exports.SubtitleSampleEntry=W;exports.SystemSampleEntry=Dn;exports.TX3GParser=dc;exports.TextSampleEntry=ga;exports.Textin4Parser=lc;exports.TrackGroupTypeBox=da;exports.TrackReferenceTypeBox=pa;exports.VTTin4Parser=hc;exports.VisualSampleEntry=S;exports.XMLSubtitlein4Parser=cc;exports.boxEqual=Wn;exports.boxEqualFields=ma;exports.createFile=sc;
3
+ //# sourceMappingURL=mp4box.all-DH-U-29f.cjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/giftstage",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "High-performance WebGPU/WebGL2 gift animation player unifying SVGA, VAP, and AlphaVideo",
5
5
  "type": "module",
6
6
  "main": "dist/gift-stage.cjs.js",
@@ -19,11 +19,13 @@
19
19
  },
20
20
  "files": [
21
21
  "dist",
22
- "!dist/**/*.map"
22
+ "!dist/**/*.map",
23
+ "!dist/bundle-report.*.html"
23
24
  ],
24
25
  "scripts": {
25
26
  "dev": "vite",
26
27
  "build": "tsc --noEmit && vite build",
28
+ "build:analyze": "tsc --noEmit && vite build --mode analyze-es && vite build --mode analyze-cjs",
27
29
  "build:demo": "tsc --noEmit && vite build --config vite.demo.config.ts && node -e \"const fs=require('fs'); fs.mkdirSync('dist-demo/static',{recursive:true}); fs.copyFileSync('static/vap.min.js','dist-demo/static/vap.min.js');\"",
28
30
  "build:wasm": "echo \"Requires: cargo install wasm-pack\" && cd wasm && wasm-pack build --target web --out-dir pkg",
29
31
  "test": "vitest run",
@@ -46,6 +48,7 @@
46
48
  "jsdom": "^24.1.3",
47
49
  "playwright": "^1.50.0",
48
50
  "prettier": "^3.4.0",
51
+ "rollup-plugin-visualizer": "^7.0.1",
49
52
  "typescript": "^5.7.0",
50
53
  "vite": "^6.0.0",
51
54
  "vite-plugin-wasm": "^3.4.0",