@brandbrigade/ott-bb-player 1.0.52 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/dist/OTTPlayer.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -280,6 +280,11 @@ Fixed multiple instances of OTT Player,
|
|
|
280
280
|
Applied SetInterval in Adepter,
|
|
281
281
|
Added OTTActions support
|
|
282
282
|
|
|
283
|
-
### Version v1.0.
|
|
283
|
+
### Version v1.0.52
|
|
284
|
+
|
|
285
|
+
Adapter, Downloader and Decoder Settings added to global player options
|
|
286
|
+
|
|
287
|
+
### Version v1.0.53
|
|
284
288
|
|
|
285
|
-
|
|
289
|
+
More debug metrix added,
|
|
290
|
+
Pixel tickers color changed to dark gray
|
package/dist/OTTPlayer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(v,b){typeof exports=="object"&&typeof module<"u"?module.exports=b():typeof define=="function"&&define.amd?define(b):(v=typeof globalThis<"u"?globalThis:v||self,v.OTTPlayer=b())})(this,function(){"use strict";const v=s=>Math.abs(s-59.94005994005994)<20?59.94:Math.abs(s-29.97002997002997)<10?29.97:Math.abs(s-14.985014985014985)<8?14.98:0,b=s=>s>30&&s<70?59.94005994005994:s>15?29.97002997002997:s>7?14.985014985014985:0;class C{constructor(t){this.frameDurations=[],this.frameDurationsCapacity=t,this.lastTimestamp=null}addFrameDuration(t){return this.frameDurations.push(t),this.frameDurations.length>this.frameDurationsCapacity&&this.frameDurations.shift(),this.calculateAverage()}addTimestamp(t){if(this.lastTimestamp===null)return this.lastTimestamp=t,null;const e=t-this.lastTimestamp;return this.lastTimestamp=t,this.addFrameDuration(e)}calculateAverage(){if(this.frameDurations.length===0)return 0;const e=this.frameDurations.reduce((o,a)=>o+a,0)/this.frameDurations.length,i=this.frameDurations.filter(o=>Math.abs(o-e)<=e*.2);return i.reduce((o,a)=>o+a,0)/i.length||e}getFPS(){const t=this.calculateAverage();if(t===0)return 0;const e=1/t;return b(e)}getPerciseFPS(){const t=this.calculateAverage();return t===0?0:1/t}}const y=(()=>{const s=()=>{const d=navigator.userAgent;return/windows/i.test(d)?"Windows":/android/i.test(d)?"Android":/iphone|ipad|ipod/i.test(d)?"iOS":/mac/i.test(d)?"Mac":/ipad/i.test(d)?"iPad":"Something else"},t=()=>s()==="Mac",e=()=>s()==="iPad",i=()=>s()==="iOS",r=()=>{const d=s();return d==="iOS"||d==="Mac"||d==="iPad"},n=()=>s()==="Windows",o=()=>s()==="Android",a=()=>{switch(s()){case"Windows":return"a Windows PC";case"Android":return"an Android phone";case"iOS":return"an iPhone";case"Mac":return"a Mac";case"iPad":return"an iPad";default:return"an Unknown device"}},h=()=>({header:[navigator.platform,navigator.userAgent,navigator.appVersion,navigator.vendor,window.opera],dataos:[{name:"Windows Phone",value:"Windows Phone",version:"OS"},{name:"Windows",value:"Win",version:"NT"},{name:"iPhone",value:"iPhone",version:"OS"},{name:"iPad",value:"iPad",version:"OS"},{name:"Kindle",value:"Silk",version:"Silk"},{name:"Android",value:"Android",version:"Android"},{name:"PlayBook",value:"PlayBook",version:"OS"},{name:"BlackBerry",value:"BlackBerry",version:"/"},{name:"Macintosh",value:"Mac",version:"OS X"},{name:"Linux",value:"Linux",version:"rv"},{name:"Palm",value:"Palm",version:"PalmOS"}],databrowser:[{name:"Chrome",value:"Chrome",version:"Chrome"},{name:"Firefox",value:"Firefox",version:"Firefox"},{name:"Safari",value:"Safari",version:"Version"},{name:"Internet Explorer",value:"MSIE",version:"MSIE"},{name:"Opera",value:"Opera",version:"Opera"},{name:"BlackBerry",value:"CLDC",version:"CLDC"},{name:"Mozilla",value:"Mozilla",version:"Mozilla"}],init(){const U=this.header.join(" ");return this.matchItem(U,this.dataos)},matchItem(U,w){for(let T=0;T<w.length;T+=1)if(new RegExp(w[T].value,"i").test(U))return w[T].name;return"unknown"}}).init(),l=()=>{const d=navigator.userAgent;return d.indexOf("Chrome")>-1&&d.indexOf("Edge")===-1?"Chrome":d.indexOf("Safari")>-1&&d.indexOf("Chrome")===-1?"Safari":d.indexOf("Firefox")>-1?"Firefox":d.indexOf("MSIE")>-1||d.indexOf("Trident")>-1?"Internet Explorer":d.indexOf("Edge")>-1?"Edge":"Unknown"};return{getCurrentPlatform:s,isMac:t,isiPad:e,isiPhone:i,isApple:r,isWindows:n,isAndroid:o,getDeviceDescription:a,getDeviceName:h,getBrowserName:l,isSafariMac:()=>t()&&l()==="Safari",isChromeMac:()=>t()&&l()==="Chrome",isChromeWin:()=>n()&&l()==="Chrome"}})(),p=class p{constructor(t,e,i,r,n){this.copy=()=>new p(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const o=":";let a=("0"+this.h).slice(-2)+o+("0"+this.m).slice(-2)+o+("0"+this.s).slice(-2)+o+("0"+this.f).slice(-2);return a+="."+(this.field?"1":"2"),a},this.toZipTimeCodeString=()=>{const o=this.copy();return o.f=0,o.s=o.s%2===0?o.s:o.s-1,o.field=0,p.toStr(o)},this.toFrames=o=>{let a=60,h=0;Math.floor(o)==60?(a=60,h=0):Math.floor(o)==59?(a=60,h=4):Math.floor(o)==30?(a=30,h=0):Math.floor(o)==29&&(a=30,h=2);let l=this.h,f=this.m,c=this.s,_=this.f,g=this.field;const d=l*60+f,U=(d-Math.floor(d/10))*h;return l*(a*3600)+f*(a*60)+c*a+(_*2+g)-U},this.addSeconds=o=>{let a=this.copy();return a.s+=o,a.s>=60&&(a.s=0,a.m++,a.m>=60&&(a.m=0,a.h++)),a},this.addFrames=(o,a)=>{let h=this.toFrames(a);return h+=o,p.fromFrames(h,a)},this.subtractFrames=(o,a)=>this.addFrames(-o,a),this.h=t||0,this.m=e||0,this.s=i||0,this.f=r||0,this.field=n||0}static compare(t,e){return t.h!==e.h?t.h<e.h?-1:1:t.m!==e.m?t.m<e.m?-1:1:t.s!==e.s?t.s<e.s?-1:1:t.f!==e.f?t.f<e.f?-1:1:t.field!==e.field?t.field<e.field?-1:1:0}static generateTimecodeRange(t,e,i){const r=[];let n=t;for(;p.compare(n,e)<=0;)r.push(n),n=n.addSeconds(i);return r}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(t){return this.toFrames(t)*1e3/t}};p.calculateCurrentTimeCode=t=>{var c;if(!t.video||!t.clocker||!t.gameParams)throw new Error("OTTPlayer is not initialized");const e=t.video,i=t.clocker,r=i.videoFPScalculator.getFPS(),a=(e.currentTime-i.syncPoint.playerTime)%(60*60*24)*r+i.syncPoint.frame;if(a===0||r===0)throw new Error("Current frame is 0 or fps is 0");const h=p.calculateCurrentOffset(a,(c=t.gameParams)==null?void 0:c.offsets);if(h===void 0)throw new Error("Offset is undefined");let l=Math.floor(a-h);return l<0&&(l+=5178816),l>=5178816&&(l-=5178816),p.fromFrames(l,r)},p.calculateCurrentOffset=(t,e)=>{for(let i=1;i<e.length;i++)if(t<e[i].frame)return e[i-1].offset;return e[e.length-1].offset},p.fromFrames=(t,e)=>{let i=60,r=0;Math.floor(e)==60?(i=60,r=0):Math.floor(e)==59?(i=60,r=4):Math.floor(e)==30?(i=30,r=0):Math.floor(e)==29&&(i=30,r=2);let n=Math.floor(e*60),o=Math.floor(e*60*10),a=o*6,h=t,l=Math.floor(h/a);h-=l*a;let f=Math.floor(h/o);h-=f*o,h>=i*60&&(h+=r*(Math.floor((h-i*60)/n)+1));let c=Math.floor(h/(i*60));h-=c*(i*60);let _=Math.floor(h/i);h-=_*i;let g=h;c+=f*10;let d=0;return d=g%2,g=Math.floor(g/2),new p(l,c,_,g,d)},p.toStr=t=>{const e="_";let i=("0"+t.h).slice(-2)+e+("0"+t.m).slice(-2)+e+("0"+t.s).slice(-2)+e+("0"+t.f).slice(-2);return t.field&&(i+="_1"),i},p.fromStr=t=>{const i=t.split("_").map(Number);if(i.length==4){const[r,n,o,a]=i;return new p(r,n,o,a,0)}else if(i.length==5){const[r,n,o,a,h]=i;return new p(r,n,o,a,h)}else throw new Error("Invalid timecode format: "+t)},p.fromMetadata=t=>{const e=/^(\d{2}):(\d{2}):(\d{2}):(\d{2})(?:\.(\d))?$/,i=t.timecode.match(e);if(!i)throw new Error("Invalid timecode format: "+t.timecode);const[,r,n,o,a,h]=i,l=Number(r),f=Number(n),c=Number(o),_=Number(a),g=h?Number(h):0;return new p(l,f,c,_,g)};let u=p,A=0,E=0;const D=s=>{if(s.metadata.messageData){s.metadata.messageData=R(s.metadata.messageData,s.metadata.presentationTime);return}if(s.metadata.frames&&s.metadata.frames.length&&s.metadata.frames[0].key&&s.metadata.frames[0].key.toLowerCase()==="priv"){const t=s.metadata.frames.filter(e=>e.info&&e.info.toLowerCase().includes("ntc"));if(t.length){const e=t[t.length-1],i=`${e.info}\0${String.fromCharCode(...e.data)}`;s.metadata.messageData=R(i,s.metadata.presentationTime)}}},P=()=>{const s=new Date(A-E);let t=Math.round(s.getUTCMilliseconds()*30*2/1001)/2;const e=t%1;let i=1;return e===.5&&(t=Math.floor(t),i=2),new u(s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds(),Math.floor(t),i===1?0:1)},V=s=>{if((s&&s.metadata&&s.metadata.id==0||y.isSafariMac())&&(D(s),s.metadata.id==0||y.isSafariMac()&&E==0))return P()},H=s=>(D(s),P()),R=(s,t)=>{let e="";if(s&&s.includes("www.mediakind.com/NTC")){const i=s.replace(/.*NTC./,"");let r=0;for(;r+8<=i.length;){const n=i.substring(r,r+4),o=((i.charCodeAt(r+4)*256+i.charCodeAt(r+5))*256+i.charCodeAt(r+6))*256+i.charCodeAt(r+7);if(r+8+o>i.length)break;const a=i.substring(r+8,r+8+o);n==="utc_"&&new Date(parseInt(a)).getTime()/1e3,n==="tc__"&&(A=new Date(parseInt(a)).getTime()),n==="offs"&&(E=parseInt(a)/90),r+=8+o}}return e},Y=(s,t,e)=>{const i=e.toFrames(t),r=e.print();console.log("New segment ("+s.url+"): "+r+" ("+i+") playing at "+s.playbackTime);const n=s.playbackTime;return{frame:i,playerTime:n,stringTime:r}},W=(s,t,e)=>{const i=e.toFrames(t),r=e.print(),n=s.metadata.presentationTime;return{frame:i,playerTime:n,stringTime:r}},j=async s=>{let t;typeof document>"u"?t=new URL(self.location.href):t=new URL(document.location.href);const e=t.searchParams.get("config");if(e){const r=await(await fetch(e)).json();Object.assign(s,r)}},m=(s,t)=>!s.debug||!s.debug.on?!1:s.debug[`log${t}`];class ${constructor(t){this.last10=[],this.errorsInProgress=[],this.lastFrameTC=null,this.fps=t}setFPS(t){this.fps=t}timecodeRecieved(t){if(!t)return;const e=u.fromStr(t);if(this.last10.push(e),this.last10.length>10&&this.last10.shift(),this.lastFrameTC){const i=this.incrementInterlaced(this.lastFrameTC);u.compare(e,i)!==0&&(console.warn("Timecode sequence is invalid! Detected at:",t),this.errorsInProgress.push({preTCs:[...this.last10],postTCs:[],framesAfter:0,printed:!1}))}for(const i of this.errorsInProgress)i.printed||(i.postTCs.push(e),i.framesAfter++);for(const i of this.errorsInProgress)if(!i.printed&&i.framesAfter>=10){console.error("Full 20-frame sequence around error:");const r=[...i.preTCs,...i.postTCs];console.error(r.map(n=>u.toStr(n))),i.printed=!0}this.lastFrameTC=e}incrementInterlaced(t){const e=t.copy();return e.field===0?(e.field=1,e):(e.field=0,e.f++,e.f>=30&&(e.f=0,e.s++,e.s>=60&&(e.s=0,e.m++,e.m>=60&&(e.m=0,e.h++))),e)}}class X{constructor(t,e){this.click=async i=>{const r=this.video.getBoundingClientRect(),n=(i.clientX-r.left)/r.width,o=(i.clientY-r.top)/r.height,a={x:n,y:o};this.renderer.postMessage({type:"VIDEO_CLICK",clickData:a})},this.video=t,this.renderer=e,this.renderer.onmessage=i=>{if(i.data.type==="OPEN_URL"){const r=i.data.url;r&&window.open(r,"_blank")}}}}const B='(function(){"use strict";const d=(l,t)=>!l.debug||!l.debug.on?!1:l.debug[`log${t}`];class E{constructor(t){this.fetchGameParams=async(s,r)=>{const n=`${s}/${r}.json`;this.options&&d(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching GameParams from ${n}`);const a=await fetch(n);if(!a.ok)throw new Error(`HTTP error! Status: ${a.status}`);const o=await a.json();return o.hasOwnProperty("bucketName")&&o.hasOwnProperty("offsets")?o:(this.options&&d(this.options,"Errors")&&console.error(`[Fetcher] Game params for ${r} not found in JSON.`),a)},this.fetchMetadata=async(s,r,n,a)=>{const e=`${`${s}/${r}`}/manifests/59.94/${a}.zip`;this.options&&d(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching metadata from ${e}`);const i=await fetch(e),c=i.headers.get("x-tgi-ott-actions");let f;if(c?f=JSON.parse(c):f={toggle:{ios:!0,android:!0,web:!0}},!i.ok)throw new Error(`HTTP error! Status: ${i.status}`);return{arrayBuffer:await i.arrayBuffer(),ottActions:f}},this.options=t}}const h=class h{constructor(t,s,r,n,a){this.copy=()=>new h(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const o=":";let e=("0"+this.h).slice(-2)+o+("0"+this.m).slice(-2)+o+("0"+this.s).slice(-2)+o+("0"+this.f).slice(-2);return e+="."+(this.field?"1":"2"),e},this.toZipTimeCodeString=()=>{const o=this.copy();return o.f=0,o.s=o.s%2===0?o.s:o.s-1,o.field=0,h.toStr(o)},this.toFrames=o=>{let e=60,i=0;Math.floor(o)==60?(e=60,i=0):Math.floor(o)==59?(e=60,i=4):Math.floor(o)==30?(e=30,i=0):Math.floor(o)==29&&(e=30,i=2);let c=this.h,f=this.m,m=this.s,u=this.f,g=this.field;const b=c*60+f,R=(b-Math.floor(b/10))*i;return c*(e*3600)+f*(e*60)+m*e+(u*2+g)-R},this.addSeconds=o=>{let e=this.copy();return e.s+=o,e.s>=60&&(e.s=0,e.m++,e.m>=60&&(e.m=0,e.h++)),e},this.addFrames=(o,e)=>{let i=this.toFrames(e);return i+=o,h.fromFrames(i,e)},this.subtractFrames=(o,e)=>this.addFrames(-o,e),this.h=t||0,this.m=s||0,this.s=r||0,this.f=n||0,this.field=a||0}static compare(t,s){return t.h!==s.h?t.h<s.h?-1:1:t.m!==s.m?t.m<s.m?-1:1:t.s!==s.s?t.s<s.s?-1:1:t.f!==s.f?t.f<s.f?-1:1:t.field!==s.field?t.field<s.field?-1:1:0}static generateTimecodeRange(t,s,r){const n=[];let a=t;for(;h.compare(a,s)<=0;)n.push(a),a=a.addSeconds(r);return n}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(t){return this.toFrames(t)*1e3/t}};h.calculateCurrentTimeCode=t=>{var m;if(!t.video||!t.clocker||!t.gameParams)throw new Error("OTTPlayer is not initialized");const s=t.video,r=t.clocker,n=r.videoFPScalculator.getFPS(),e=(s.currentTime-r.syncPoint.playerTime)%(60*60*24)*n+r.syncPoint.frame;if(e===0||n===0)throw new Error("Current frame is 0 or fps is 0");const i=h.calculateCurrentOffset(e,(m=t.gameParams)==null?void 0:m.offsets);if(i===void 0)throw new Error("Offset is undefined");let c=Math.floor(e-i);return c<0&&(c+=5178816),c>=5178816&&(c-=5178816),h.fromFrames(c,n)},h.calculateCurrentOffset=(t,s)=>{for(let r=1;r<s.length;r++)if(t<s[r].frame)return s[r-1].offset;return s[s.length-1].offset},h.fromFrames=(t,s)=>{let r=60,n=0;Math.floor(s)==60?(r=60,n=0):Math.floor(s)==59?(r=60,n=4):Math.floor(s)==30?(r=30,n=0):Math.floor(s)==29&&(r=30,n=2);let a=Math.floor(s*60),o=Math.floor(s*60*10),e=o*6,i=t,c=Math.floor(i/e);i-=c*e;let f=Math.floor(i/o);i-=f*o,i>=r*60&&(i+=n*(Math.floor((i-r*60)/a)+1));let m=Math.floor(i/(r*60));i-=m*(r*60);let u=Math.floor(i/r);i-=u*r;let g=i;m+=f*10;let b=0;return b=g%2,g=Math.floor(g/2),new h(c,m,u,g,b)},h.toStr=t=>{const s="_";let r=("0"+t.h).slice(-2)+s+("0"+t.m).slice(-2)+s+("0"+t.s).slice(-2)+s+("0"+t.f).slice(-2);return t.field&&(r+="_1"),r},h.fromStr=t=>{const r=t.split("_").map(Number);if(r.length==4){const[n,a,o,e]=r;return new h(n,a,o,e,0)}else if(r.length==5){const[n,a,o,e,i]=r;return new h(n,a,o,e,i)}else throw new Error("Invalid timecode format: "+t)},h.fromMetadata=t=>{const s=/^(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d))?$/,r=t.timecode.match(s);if(!r)throw new Error("Invalid timecode format: "+t.timecode);const[,n,a,o,e,i]=r,c=Number(n),f=Number(a),m=Number(o),u=Number(e),g=i?Number(i):0;return new h(c,f,m,u,g)};let D=h;class T{constructor(t,s,r){this.jobsQueue=[],this.processedTimecodes=[],this.updateStreamData=n=>{this.streamData=n,this.initiateJobs(this.options.DOWNLOADER_ZIP_START_OFFSET,this.options.DOWNLOADER_ZIP_END_OFFSET,this.options.DOWNLOADER_ZIP_LENGTH_SECONDS),this.clearOldJobs(1)},this.initiateJobs=(n,a,o)=>{if(!this.streamData){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Stream data is not available");return}const e=D.fromStr(this.streamData.timeCode),i=e.addSeconds(n),c=e.addSeconds(a),f=D.generateTimecodeRange(i,c,o);for(const m of f){const u=m.toZipTimeCodeString();this.processedTimecodes.includes(u)||(this.processedTimecodes.push(u),this.addJob(u))}},this.clearOldJobs=n=>{if(!this.streamData){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Stream data is not available");return}const o=D.fromStr(this.streamData.timeCode).totalSeconds()-n;this.processedTimecodes=this.processedTimecodes.filter(e=>D.fromStr(e).totalSeconds()>o)},this.addJob=n=>{if(this.jobsQueue.some(a=>a===n)){this.options&&d(this.options,"Downloader")&&console.log(`[Downloader] Job already exists for timeCode=${n}`);return}this.jobsQueue.push(n),this.startNextJob()},this.startNextJob=()=>{!this.currentJob&&this.jobsQueue.length>0&&(this.currentJob=this.jobsQueue.shift(),this.options&&d(this.options,"Downloader")&&console.log(`[Downloader] Starting job timeCode=${this.currentJob}`),this.downloadZip(this.currentJob))},this.jobDone=()=>{this.currentJob=void 0,this.startNextJob()},this.downloadZip=async n=>{if(!this.streamData){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Stream data is not available");return}const{fps:a,cloudFrontURL:o,bucketName:e}=this.streamData;try{this.options&&d(this.options,"Downloader")&&console.log(`[Downloader] Fetching zip for timeCode=${n}`);const{arrayBuffer:i,ottActions:c}=await this.fetcher.fetchMetadata(o,e,a,n);this.postOTTActionsToRenderer(c),this.postArrayBufferToDecoder(n,i)}catch(i){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Error:",i)}this.jobDone()},this.postArrayBufferToDecoder=t,this.postOTTActionsToRenderer=s,this.options=r,this.fetcher=new E(r)}}let w=null,S=null,F,p;self.onmessage=async l=>{const{data:t}=l;t.type==="SET_RENDERER_PORT"&&(w=t.port,w.onmessage=y),t.type==="SET_DECODER_PORT"&&(S=t.port,S.onmessage=N),t.type==="SET_OPTIONS"&&(p=t.options,F=new T(M,O,p))};async function y(l){const{data:t}=l;t.type==="DOWNLOADER_INPUT"&&F.updateStreamData(t.streamData)}function M(l,t){if(!S)return;p&&d(p,"Downloader")&&console.log(`[DownloaderWorker] Posting an ArrayBuffer to Decoder, timeCode=${l}`);const s={type:"DECODER_INPUT",timeCode:l,arrayBuffer:t};S==null||S.postMessage(s,{transfer:[t]})}function O(l){if(!w)return;p&&d(p,"Downloader")&&console.log(`[DownloaderWorker] Posting OTTActions to Renderer, toggle=${l.toggle}`);const t={type:"OTT_ACTIONS",ottActions:l};w==null||w.postMessage(t)}function N(l){p&&d(p,"Downloader")&&console.log("[DownloaderWorker] Received message from Decoder:",l.data)}})();\n',k=typeof self<"u"&&self.Blob&&new Blob([B],{type:"text/javascript;charset=utf-8"});function q(s){let t;try{if(t=k&&(self.URL||self.webkitURL).createObjectURL(k),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(B),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const I=`(function(){"use strict";const L=(C,f)=>!C.debug||!C.debug.on?!1:C.debug[\`log\${f}\`];function X(C){return C&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C.default:C}var K={},Q;function et(){return Q||(Q=1,function(C){var f=function(){var t=new Date,e=4,r=3,n=2,a=1,u=e,p={setLogLevel:function(_){_==this.debug?u=a:_==this.info?u=n:_==this.warn?u=r:(_==this.error,u=e)},debug:function(_,U){console.debug===void 0&&(console.debug=console.log),a>=u&&console.debug("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)},log:function(_,U){this.debug(_.msg)},info:function(_,U){n>=u&&console.info("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)},warn:function(_,U){r>=u&&console.warn("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)},error:function(_,U){e>=u&&console.error("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)}};return p}();f.getDurationString=function(t,e){var r;function n(S,b){for(var E=""+S,B=E.split(".");B[0].length<b;)B[0]="0"+B[0];return B.join(".")}t<0?(r=!0,t=-t):r=!1;var a=e||1,u=t/a,p=Math.floor(u/3600);u-=p*3600;var _=Math.floor(u/60);u-=_*60;var U=u*1e3;return u=Math.floor(u),U-=u*1e3,U=Math.floor(U),(r?"-":"")+p+":"+n(_,2)+":"+n(u,2)+"."+n(U,3)},f.printRanges=function(t){var e=t.length;if(e>0){for(var r="",n=0;n<e;n++)n>0&&(r+=","),r+="["+f.getDurationString(t.start(n))+","+f.getDurationString(t.end(n))+"]";return r}else return"(empty)"},C.Log=f;var h=function(t){if(t instanceof ArrayBuffer)this.buffer=t,this.dataview=new DataView(t);else throw"Needs an array buffer";this.position=0};h.prototype.getPosition=function(){return this.position},h.prototype.getEndPosition=function(){return this.buffer.byteLength},h.prototype.getLength=function(){return this.buffer.byteLength},h.prototype.seek=function(t){var e=Math.max(0,Math.min(this.buffer.byteLength,t));return this.position=isNaN(e)||!isFinite(e)?0:e,!0},h.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},h.prototype.readAnyInt=function(t,e){var r=0;if(this.position+t<=this.buffer.byteLength){switch(t){case 1:e?r=this.dataview.getInt8(this.position):r=this.dataview.getUint8(this.position);break;case 2:e?r=this.dataview.getInt16(this.position):r=this.dataview.getUint16(this.position);break;case 3:if(e)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16,r|=this.dataview.getUint8(this.position+1)<<8,r|=this.dataview.getUint8(this.position+2);break;case 4:e?r=this.dataview.getInt32(this.position):r=this.dataview.getUint32(this.position);break;case 8:if(e)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32,r|=this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+t}return this.position+=t,r}else throw"Not enough bytes in buffer"},h.prototype.readUint8=function(){return this.readAnyInt(1,!1)},h.prototype.readUint16=function(){return this.readAnyInt(2,!1)},h.prototype.readUint24=function(){return this.readAnyInt(3,!1)},h.prototype.readUint32=function(){return this.readAnyInt(4,!1)},h.prototype.readUint64=function(){return this.readAnyInt(8,!1)},h.prototype.readString=function(t){if(this.position+t<=this.buffer.byteLength){for(var e="",r=0;r<t;r++)e+=String.fromCharCode(this.readUint8());return e}else throw"Not enough bytes in buffer"},h.prototype.readCString=function(){for(var t=[];;){var e=this.readUint8();if(e!==0)t.push(e);else break}return String.fromCharCode.apply(null,t)},h.prototype.readInt8=function(){return this.readAnyInt(1,!0)},h.prototype.readInt16=function(){return this.readAnyInt(2,!0)},h.prototype.readInt32=function(){return this.readAnyInt(4,!0)},h.prototype.readInt64=function(){return this.readAnyInt(8,!1)},h.prototype.readUint8Array=function(t){for(var e=new Uint8Array(t),r=0;r<t;r++)e[r]=this.readUint8();return e},h.prototype.readInt16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readInt16();return e},h.prototype.readUint16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readUint16();return e},h.prototype.readUint32Array=function(t){for(var e=new Uint32Array(t),r=0;r<t;r++)e[r]=this.readUint32();return e},h.prototype.readInt32Array=function(t){for(var e=new Int32Array(t),r=0;r<t;r++)e[r]=this.readInt32();return e},C.MP4BoxStream=h;var o=function(t,e,r){this._byteOffset=e||0,t instanceof ArrayBuffer?this.buffer=t:typeof t=="object"?(this.dataView=t,e&&(this._byteOffset+=e)):this.buffer=new ArrayBuffer(t||0),this.position=0,this.endianness=r??o.LITTLE_ENDIAN};o.prototype={},o.prototype.getPosition=function(){return this.position},o.prototype._realloc=function(t){if(this._dynamicSize){var e=this._byteOffset+this.position+t,r=this._buffer.byteLength;if(e<=r){e>this._byteLength&&(this._byteLength=e);return}for(r<1&&(r=1);e>r;)r*=2;var n=new ArrayBuffer(r),a=new Uint8Array(this._buffer),u=new Uint8Array(n,0,a.length);u.set(a),this.buffer=n,this._byteLength=e}},o.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var t=new ArrayBuffer(this._byteLength),e=new Uint8Array(t),r=new Uint8Array(this._buffer,0,e.length);e.set(r),this.buffer=t}},o.BIG_ENDIAN=!1,o.LITTLE_ENDIAN=!0,o.prototype._byteLength=0,Object.defineProperty(o.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(o.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(t){this._buffer=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(o.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(o.prototype,"dataView",{get:function(){return this._dataView},set:function(t){this._byteOffset=t.byteOffset,this._buffer=t.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}}),o.prototype.seek=function(t){var e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e},o.prototype.isEof=function(){return this.position>=this._byteLength},o.prototype.mapUint8Array=function(t){this._realloc(t*1);var e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=t*1,e},o.prototype.readInt32Array=function(t,e){t=t??this.byteLength-this.position/4;var r=new Int32Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readInt16Array=function(t,e){t=t??this.byteLength-this.position/2;var r=new Int16Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readInt8Array=function(t){t=t??this.byteLength-this.position;var e=new Int8Array(t);return o.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},o.prototype.readUint32Array=function(t,e){t=t??this.byteLength-this.position/4;var r=new Uint32Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readUint16Array=function(t,e){t=t??this.byteLength-this.position/2;var r=new Uint16Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readUint8Array=function(t){t=t??this.byteLength-this.position;var e=new Uint8Array(t);return o.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},o.prototype.readFloat64Array=function(t,e){t=t??this.byteLength-this.position/8;var r=new Float64Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readFloat32Array=function(t,e){t=t??this.byteLength-this.position/4;var r=new Float32Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readInt32=function(t){var e=this._dataView.getInt32(this.position,t??this.endianness);return this.position+=4,e},o.prototype.readInt16=function(t){var e=this._dataView.getInt16(this.position,t??this.endianness);return this.position+=2,e},o.prototype.readInt8=function(){var t=this._dataView.getInt8(this.position);return this.position+=1,t},o.prototype.readUint32=function(t){var e=this._dataView.getUint32(this.position,t??this.endianness);return this.position+=4,e},o.prototype.readUint16=function(t){var e=this._dataView.getUint16(this.position,t??this.endianness);return this.position+=2,e},o.prototype.readUint8=function(){var t=this._dataView.getUint8(this.position);return this.position+=1,t},o.prototype.readFloat32=function(t){var e=this._dataView.getFloat32(this.position,t??this.endianness);return this.position+=4,e},o.prototype.readFloat64=function(t){var e=this._dataView.getFloat64(this.position,t??this.endianness);return this.position+=8,e},o.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,o.memcpy=function(t,e,r,n,a){var u=new Uint8Array(t,e,a),p=new Uint8Array(r,n,a);u.set(p)},o.arrayToNative=function(t,e){return e==this.endianness?t:this.flipArrayEndianness(t)},o.nativeToEndian=function(t,e){return this.endianness==e?t:this.flipArrayEndianness(t)},o.flipArrayEndianness=function(t){for(var e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=0;r<t.byteLength;r+=t.BYTES_PER_ELEMENT)for(var n=r+t.BYTES_PER_ELEMENT-1,a=r;n>a;n--,a++){var u=e[a];e[a]=e[n],e[n]=u}return t},o.prototype.failurePosition=0,String.fromCharCodeUint8=function(t){for(var e=[],r=0;r<t.length;r++)e[r]=t[r];return String.fromCharCode.apply(null,e)},o.prototype.readString=function(t,e){return e==null||e=="ASCII"?String.fromCharCodeUint8.apply(null,[this.mapUint8Array(t??this.byteLength-this.position)]):new TextDecoder(e).decode(this.mapUint8Array(t))},o.prototype.readCString=function(t){var e=this.byteLength-this.position,r=new Uint8Array(this._buffer,this._byteOffset+this.position),n=e;t!=null&&(n=Math.min(t,e));for(var a=0;a<n&&r[a]!==0;a++);var u=String.fromCharCodeUint8.apply(null,[this.mapUint8Array(a)]);return t!=null?this.position+=n-a:a!=e&&(this.position+=1),u};var d=Math.pow(2,32);o.prototype.readInt64=function(){return this.readInt32()*d+this.readUint32()},o.prototype.readUint64=function(){return this.readUint32()*d+this.readUint32()},o.prototype.readInt64=function(){return this.readUint32()*d+this.readUint32()},o.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()},C.DataStream=o,o.prototype.save=function(t){var e=new Blob([this.buffer]);if(window.URL&&URL.createObjectURL){var r=window.URL.createObjectURL(e),n=document.createElement("a");document.body.appendChild(n),n.setAttribute("href",r),n.setAttribute("download",t),n.setAttribute("target","_self"),n.click(),window.URL.revokeObjectURL(r)}else throw"DataStream.save: Can't create object URL."},o.prototype._dynamicSize=!0,Object.defineProperty(o.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(t){t||this._trimAlloc(),this._dynamicSize=t}}),o.prototype.shift=function(t){var e=new ArrayBuffer(this._byteLength-t),r=new Uint8Array(e),n=new Uint8Array(this._buffer,t,r.length);r.set(n),this.buffer=e,this.position-=t},o.prototype.writeInt32Array=function(t,e){if(this._realloc(t.length*4),t instanceof Int32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt32(t[r],e)},o.prototype.writeInt16Array=function(t,e){if(this._realloc(t.length*2),t instanceof Int16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt16(t[r],e)},o.prototype.writeInt8Array=function(t){if(this._realloc(t.length*1),t instanceof Int8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt8Array(t.length);else for(var e=0;e<t.length;e++)this.writeInt8(t[e])},o.prototype.writeUint32Array=function(t,e){if(this._realloc(t.length*4),t instanceof Uint32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint32(t[r],e)},o.prototype.writeUint16Array=function(t,e){if(this._realloc(t.length*2),t instanceof Uint16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint16(t[r],e)},o.prototype.writeUint8Array=function(t){if(this._realloc(t.length*1),t instanceof Uint8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint8Array(t.length);else for(var e=0;e<t.length;e++)this.writeUint8(t[e])},o.prototype.writeFloat64Array=function(t,e){if(this._realloc(t.length*8),t instanceof Float64Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat64Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat64(t[r],e)},o.prototype.writeFloat32Array=function(t,e){if(this._realloc(t.length*4),t instanceof Float32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat32(t[r],e)},o.prototype.writeInt32=function(t,e){this._realloc(4),this._dataView.setInt32(this.position,t,e??this.endianness),this.position+=4},o.prototype.writeInt16=function(t,e){this._realloc(2),this._dataView.setInt16(this.position,t,e??this.endianness),this.position+=2},o.prototype.writeInt8=function(t){this._realloc(1),this._dataView.setInt8(this.position,t),this.position+=1},o.prototype.writeUint32=function(t,e){this._realloc(4),this._dataView.setUint32(this.position,t,e??this.endianness),this.position+=4},o.prototype.writeUint16=function(t,e){this._realloc(2),this._dataView.setUint16(this.position,t,e??this.endianness),this.position+=2},o.prototype.writeUint8=function(t){this._realloc(1),this._dataView.setUint8(this.position,t),this.position+=1},o.prototype.writeFloat32=function(t,e){this._realloc(4),this._dataView.setFloat32(this.position,t,e??this.endianness),this.position+=4},o.prototype.writeFloat64=function(t,e){this._realloc(8),this._dataView.setFloat64(this.position,t,e??this.endianness),this.position+=8},o.prototype.writeUCS2String=function(t,e,r){r==null&&(r=t.length);for(var n=0;n<t.length&&n<r;n++)this.writeUint16(t.charCodeAt(n),e);for(;n<r;n++)this.writeUint16(0)},o.prototype.writeString=function(t,e,r){var n=0;if(e==null||e=="ASCII")if(r!=null){var a=Math.min(t.length,r);for(n=0;n<a;n++)this.writeUint8(t.charCodeAt(n));for(;n<r;n++)this.writeUint8(0)}else for(n=0;n<t.length;n++)this.writeUint8(t.charCodeAt(n));else this.writeUint8Array(new TextEncoder(e).encode(t.substring(0,r)))},o.prototype.writeCString=function(t,e){var r=0;if(e!=null){var n=Math.min(t.length,e);for(r=0;r<n;r++)this.writeUint8(t.charCodeAt(r));for(;r<e;r++)this.writeUint8(0)}else{for(r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));this.writeUint8(0)}},o.prototype.writeStruct=function(t,e){for(var r=0;r<t.length;r+=2){var n=t[r+1];this.writeType(n,e[t[r]],e)}},o.prototype.writeType=function(t,e,r){var n;if(typeof t=="function")return t(this,e);if(typeof t=="object"&&!(t instanceof Array))return t.set(this,e,r);var a=null,u="ASCII",p=this.position;switch(typeof t=="string"&&/:/.test(t)&&(n=t.split(":"),t=n[0],a=parseInt(n[1])),typeof t=="string"&&/,/.test(t)&&(n=t.split(","),t=n[0],u=parseInt(n[1])),t){case"uint8":this.writeUint8(e);break;case"int8":this.writeInt8(e);break;case"uint16":this.writeUint16(e,this.endianness);break;case"int16":this.writeInt16(e,this.endianness);break;case"uint32":this.writeUint32(e,this.endianness);break;case"int32":this.writeInt32(e,this.endianness);break;case"float32":this.writeFloat32(e,this.endianness);break;case"float64":this.writeFloat64(e,this.endianness);break;case"uint16be":this.writeUint16(e,o.BIG_ENDIAN);break;case"int16be":this.writeInt16(e,o.BIG_ENDIAN);break;case"uint32be":this.writeUint32(e,o.BIG_ENDIAN);break;case"int32be":this.writeInt32(e,o.BIG_ENDIAN);break;case"float32be":this.writeFloat32(e,o.BIG_ENDIAN);break;case"float64be":this.writeFloat64(e,o.BIG_ENDIAN);break;case"uint16le":this.writeUint16(e,o.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(e,o.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(e,o.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(e,o.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(e,o.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(e,o.LITTLE_ENDIAN);break;case"cstring":this.writeCString(e,a);break;case"string":this.writeString(e,u,a);break;case"u16string":this.writeUCS2String(e,this.endianness,a);break;case"u16stringle":this.writeUCS2String(e,o.LITTLE_ENDIAN,a);break;case"u16stringbe":this.writeUCS2String(e,o.BIG_ENDIAN,a);break;default:if(t.length==3){for(var _=t[1],U=0;U<e.length;U++)this.writeType(_,e[U]);break}else{this.writeStruct(t,e);break}}a!=null&&(this.position=p,this._realloc(a),this.position=p+a)},o.prototype.writeUint64=function(t){var e=Math.floor(t/d);this.writeUint32(e),this.writeUint32(t&4294967295)},o.prototype.writeUint24=function(t){this.writeUint8((t&16711680)>>16),this.writeUint8((t&65280)>>8),this.writeUint8(t&255)},o.prototype.adjustUint32=function(t,e){var r=this.position;this.seek(t),this.writeUint32(e),this.seek(r)},o.prototype.mapInt32Array=function(t,e){this._realloc(t*4);var r=new Int32Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*4,r},o.prototype.mapInt16Array=function(t,e){this._realloc(t*2);var r=new Int16Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*2,r},o.prototype.mapInt8Array=function(t){this._realloc(t*1);var e=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=t*1,e},o.prototype.mapUint32Array=function(t,e){this._realloc(t*4);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*4,r},o.prototype.mapUint16Array=function(t,e){this._realloc(t*2);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*2,r},o.prototype.mapFloat64Array=function(t,e){this._realloc(t*8);var r=new Float64Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*8,r},o.prototype.mapFloat32Array=function(t,e){this._realloc(t*4);var r=new Float32Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*4,r};var l=function(t){this.buffers=[],this.bufferIndex=-1,t&&(this.insertBuffer(t),this.bufferIndex=0)};l.prototype=new o(new ArrayBuffer,0,o.BIG_ENDIAN),l.prototype.initialized=function(){var t;return this.bufferIndex>-1?!0:this.buffers.length>0?(t=this.buffers[0],t.fileStart===0?(this.buffer=t,this.bufferIndex=0,f.debug("MultiBufferStream","Stream ready for parsing"),!0):(f.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1)):(f.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1)},ArrayBuffer.concat=function(t,e){f.debug("ArrayBuffer","Trying to create a new buffer of size: "+(t.byteLength+e.byteLength));var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer},l.prototype.reduceBuffer=function(t,e,r){var n;return n=new Uint8Array(r),n.set(new Uint8Array(t,e,r)),n.buffer.fileStart=t.fileStart+e,n.buffer.usedBytes=0,n.buffer},l.prototype.insertBuffer=function(t){for(var e=!0,r=0;r<this.buffers.length;r++){var n=this.buffers[r];if(t.fileStart<=n.fileStart){if(t.fileStart===n.fileStart)if(t.byteLength>n.byteLength){this.buffers.splice(r,1),r--;continue}else f.warn("MultiBufferStream","Buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+") already appended, ignoring");else t.fileStart+t.byteLength<=n.fileStart||(t=this.reduceBuffer(t,0,n.fileStart-t.fileStart)),f.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.splice(r,0,t),r===0&&(this.buffer=t);e=!1;break}else if(t.fileStart<n.fileStart+n.byteLength){var a=n.fileStart+n.byteLength-t.fileStart,u=t.byteLength-a;if(u>0)t=this.reduceBuffer(t,a,u);else{e=!1;break}}}e&&(f.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.push(t),r===0&&(this.buffer=t))},l.prototype.logBufferLevel=function(t){var e,r,n,a,u=[],p,_="";for(n=0,a=0,e=0;e<this.buffers.length;e++)r=this.buffers[e],e===0?(p={},u.push(p),p.start=r.fileStart,p.end=r.fileStart+r.byteLength,_+="["+p.start+"-"):p.end===r.fileStart?p.end=r.fileStart+r.byteLength:(p={},p.start=r.fileStart,_+=u[u.length-1].end-1+"], ["+p.start+"-",p.end=r.fileStart+r.byteLength,u.push(p)),n+=r.usedBytes,a+=r.byteLength;u.length>0&&(_+=p.end-1+"]");var U=t?f.info:f.debug;this.buffers.length===0?U("MultiBufferStream","No more buffer in memory"):U("MultiBufferStream",""+this.buffers.length+" stored buffer(s) ("+n+"/"+a+" bytes), continuous ranges: "+_)},l.prototype.cleanBuffers=function(){var t,e;for(t=0;t<this.buffers.length;t++)e=this.buffers[t],e.usedBytes===e.byteLength&&(f.debug("MultiBufferStream","Removing buffer #"+t),this.buffers.splice(t,1),t--)},l.prototype.mergeNextBuffer=function(){var t;if(this.bufferIndex+1<this.buffers.length)if(t=this.buffers[this.bufferIndex+1],t.fileStart===this.buffer.fileStart+this.buffer.byteLength){var e=this.buffer.byteLength,r=this.buffer.usedBytes,n=this.buffer.fileStart;return this.buffers[this.bufferIndex]=ArrayBuffer.concat(this.buffer,t),this.buffer=this.buffers[this.bufferIndex],this.buffers.splice(this.bufferIndex+1,1),this.buffer.usedBytes=r,this.buffer.fileStart=n,f.debug("ISOFile","Concatenating buffer for box parsing (length: "+e+"->"+this.buffer.byteLength+")"),!0}else return!1;else return!1},l.prototype.findPosition=function(t,e,r){var n,a=null,u=-1;for(t===!0?n=0:n=this.bufferIndex;n<this.buffers.length&&(a=this.buffers[n],a.fileStart<=e);){u=n,r&&(a.fileStart+a.byteLength<=e?a.usedBytes=a.byteLength:a.usedBytes=e-a.fileStart,this.logBufferLevel());n++}return u!==-1?(a=this.buffers[u],a.fileStart+a.byteLength>=e?(f.debug("MultiBufferStream","Found position in existing buffer #"+u),u):-1):-1},l.prototype.findEndContiguousBuf=function(t){var e,r,n,a=t!==void 0?t:this.bufferIndex;if(r=this.buffers[a],this.buffers.length>a+1)for(e=a+1;e<this.buffers.length&&(n=this.buffers[e],n.fileStart===r.fileStart+r.byteLength);e++)r=n;return r.fileStart+r.byteLength},l.prototype.getEndFilePositionAfter=function(t){var e=this.findPosition(!0,t,!1);return e!==-1?this.findEndContiguousBuf(e):t},l.prototype.addUsedBytes=function(t){this.buffer.usedBytes+=t,this.logBufferLevel()},l.prototype.setAllUsedBytes=function(){this.buffer.usedBytes=this.buffer.byteLength,this.logBufferLevel()},l.prototype.seek=function(t,e,r){var n;return n=this.findPosition(e,t,r),n!==-1?(this.buffer=this.buffers[n],this.bufferIndex=n,this.position=t-this.buffer.fileStart,f.debug("MultiBufferStream","Repositioning parser at buffer position: "+this.position),!0):(f.debug("MultiBufferStream","Position "+t+" not found in buffered data"),!1)},l.prototype.getPosition=function(){if(this.bufferIndex===-1||this.buffers[this.bufferIndex]===null)throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.position},l.prototype.getLength=function(){return this.byteLength},l.prototype.getEndPosition=function(){if(this.bufferIndex===-1||this.buffers[this.bufferIndex]===null)throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.byteLength},C.MultiBufferStream=l;var c=function(){var t=3,e=4,r=5,n=6,a=[];a[t]="ES_Descriptor",a[e]="DecoderConfigDescriptor",a[r]="DecoderSpecificInfo",a[n]="SLConfigDescriptor",this.getDescriptorName=function(_){return a[_]};var u=this,p={};return this.parseOneDescriptor=function(_){var U=0,S,b,E;for(S=_.readUint8(),E=_.readUint8();E&128;)U=(U<<7)+(E&127),E=_.readUint8();return U=(U<<7)+(E&127),f.debug("MPEG4DescriptorParser","Found "+(a[S]||"Descriptor "+S)+", size "+U+" at position "+_.getPosition()),a[S]?b=new p[a[S]](U):b=new p.Descriptor(U),b.parse(_),b},p.Descriptor=function(_,U){this.tag=_,this.size=U,this.descs=[]},p.Descriptor.prototype.parse=function(_){this.data=_.readUint8Array(this.size)},p.Descriptor.prototype.findDescriptor=function(_){for(var U=0;U<this.descs.length;U++)if(this.descs[U].tag==_)return this.descs[U];return null},p.Descriptor.prototype.parseRemainingDescriptors=function(_){for(var U=_.position;_.position<U+this.size;){var S=u.parseOneDescriptor(_);this.descs.push(S)}},p.ES_Descriptor=function(_){p.Descriptor.call(this,t,_)},p.ES_Descriptor.prototype=new p.Descriptor,p.ES_Descriptor.prototype.parse=function(_){if(this.ES_ID=_.readUint16(),this.flags=_.readUint8(),this.size-=3,this.flags&128?(this.dependsOn_ES_ID=_.readUint16(),this.size-=2):this.dependsOn_ES_ID=0,this.flags&64){var U=_.readUint8();this.URL=_.readString(U),this.size-=U+1}else this.URL="";this.flags&32?(this.OCR_ES_ID=_.readUint16(),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(_)},p.ES_Descriptor.prototype.getOTI=function(_){var U=this.findDescriptor(e);return U?U.oti:0},p.ES_Descriptor.prototype.getAudioConfig=function(_){var U=this.findDescriptor(e);if(!U)return null;var S=U.findDescriptor(r);if(S&&S.data){var b=(S.data[0]&248)>>3;return b===31&&S.data.length>=2&&(b=32+((S.data[0]&7)<<3)+((S.data[1]&224)>>5)),b}else return null},p.DecoderConfigDescriptor=function(_){p.Descriptor.call(this,e,_)},p.DecoderConfigDescriptor.prototype=new p.Descriptor,p.DecoderConfigDescriptor.prototype.parse=function(_){this.oti=_.readUint8(),this.streamType=_.readUint8(),this.upStream=(this.streamType>>1&1)!==0,this.streamType=this.streamType>>>2,this.bufferSize=_.readUint24(),this.maxBitrate=_.readUint32(),this.avgBitrate=_.readUint32(),this.size-=13,this.parseRemainingDescriptors(_)},p.DecoderSpecificInfo=function(_){p.Descriptor.call(this,r,_)},p.DecoderSpecificInfo.prototype=new p.Descriptor,p.SLConfigDescriptor=function(_){p.Descriptor.call(this,n,_)},p.SLConfigDescriptor.prototype=new p.Descriptor,this};C.MPEG4DescriptorParser=c;var s={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"],["grpl"],["j2kH"],["etyp",["tyco"]]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){s.FullBox.prototype=new s.Box,s.ContainerBox.prototype=new s.Box,s.SampleEntry.prototype=new s.Box,s.TrackGroupTypeBox.prototype=new s.FullBox,s.BASIC_BOXES.forEach(function(t){s.createBoxCtor(t)}),s.FULL_BOXES.forEach(function(t){s.createFullBoxCtor(t)}),s.CONTAINER_BOXES.forEach(function(t){s.createContainerBoxCtor(t[0],null,t[1])})},Box:function(t,e,r){this.type=t,this.size=e,this.uuid=r},FullBox:function(t,e,r){s.Box.call(this,t,e,r),this.flags=0,this.version=0},ContainerBox:function(t,e,r){s.Box.call(this,t,e,r),this.boxes=[]},SampleEntry:function(t,e,r,n){s.ContainerBox.call(this,t,e),this.hdr_size=r,this.start=n},SampleGroupEntry:function(t){this.grouping_type=t},TrackGroupTypeBox:function(t,e){s.FullBox.call(this,t,e)},createBoxCtor:function(t,e){s.boxCodes.push(t),s[t+"Box"]=function(r){s.Box.call(this,t,r)},s[t+"Box"].prototype=new s.Box,e&&(s[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,e){s[t+"Box"]=function(r){s.FullBox.call(this,t,r)},s[t+"Box"].prototype=new s.FullBox,s[t+"Box"].prototype.parse=function(r){this.parseFullHeader(r),e&&e.call(this,r)}},addSubBoxArrays:function(t){if(t){this.subBoxNames=t;for(var e=t.length,r=0;r<e;r++)this[t[r]+"s"]=[]}},createContainerBoxCtor:function(t,e,r){s[t+"Box"]=function(n){s.ContainerBox.call(this,t,n),s.addSubBoxArrays.call(this,r)},s[t+"Box"].prototype=new s.ContainerBox,e&&(s[t+"Box"].prototype.parse=e)},createMediaSampleEntryCtor:function(t,e,r){s.sampleEntryCodes[t]=[],s[t+"SampleEntry"]=function(n,a){s.SampleEntry.call(this,n,a),s.addSubBoxArrays.call(this,r)},s[t+"SampleEntry"].prototype=new s.SampleEntry,e&&(s[t+"SampleEntry"].prototype.parse=e)},createSampleEntryCtor:function(t,e,r,n){s.sampleEntryCodes[t].push(e),s[e+"SampleEntry"]=function(a){s[t+"SampleEntry"].call(this,e,a),s.addSubBoxArrays.call(this,n)},s[e+"SampleEntry"].prototype=new s[t+"SampleEntry"],r&&(s[e+"SampleEntry"].prototype.parse=r)},createEncryptedSampleEntryCtor:function(t,e,r){s.createSampleEntryCtor.call(this,t,e,r,["sinf"])},createSampleGroupCtor:function(t,e){s[t+"SampleGroupEntry"]=function(r){s.SampleGroupEntry.call(this,t,r)},s[t+"SampleGroupEntry"].prototype=new s.SampleGroupEntry,e&&(s[t+"SampleGroupEntry"].prototype.parse=e)},createTrackGroupCtor:function(t,e){s[t+"TrackGroupTypeBox"]=function(r){s.TrackGroupTypeBox.call(this,t,r)},s[t+"TrackGroupTypeBox"].prototype=new s.TrackGroupTypeBox,e&&(s[t+"TrackGroupTypeBox"].prototype.parse=e)},createUUIDBox:function(t,e,r,n){s.UUIDs.push(t),s.UUIDBoxes[t]=function(a){e?s.FullBox.call(this,"uuid",a,t):r?s.ContainerBox.call(this,"uuid",a,t):s.Box.call(this,"uuid",a,t)},s.UUIDBoxes[t].prototype=e?new s.FullBox:r?new s.ContainerBox:new s.Box,n&&(e?s.UUIDBoxes[t].prototype.parse=function(a){this.parseFullHeader(a),n&&n.call(this,a)}:s.UUIDBoxes[t].prototype.parse=n)}};s.initialize(),s.TKHD_FLAG_ENABLED=1,s.TKHD_FLAG_IN_MOVIE=2,s.TKHD_FLAG_IN_PREVIEW=4,s.TFHD_FLAG_BASE_DATA_OFFSET=1,s.TFHD_FLAG_SAMPLE_DESC=2,s.TFHD_FLAG_SAMPLE_DUR=8,s.TFHD_FLAG_SAMPLE_SIZE=16,s.TFHD_FLAG_SAMPLE_FLAGS=32,s.TFHD_FLAG_DUR_EMPTY=65536,s.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072,s.TRUN_FLAGS_DATA_OFFSET=1,s.TRUN_FLAGS_FIRST_FLAG=4,s.TRUN_FLAGS_DURATION=256,s.TRUN_FLAGS_SIZE=512,s.TRUN_FLAGS_FLAGS=1024,s.TRUN_FLAGS_CTS_OFFSET=2048,s.Box.prototype.add=function(t){return this.addBox(new s[t+"Box"])},s.Box.prototype.addBox=function(t){return this.boxes.push(t),this[t.type+"s"]?this[t.type+"s"].push(t):this[t.type]=t,t},s.Box.prototype.set=function(t,e){return this[t]=e,this},s.Box.prototype.addEntry=function(t,e){var r=e||"entries";return this[r]||(this[r]=[]),this[r].push(t),this},C.BoxParser=s,s.parseUUID=function(t){return s.parseHex16(t)},s.parseHex16=function(t){for(var e="",r=0;r<16;r++){var n=t.readUint8().toString(16);e+=n.length===1?"0"+n:n}return e},s.parseOneBox=function(t,e,r){var n,a=t.getPosition(),u=0,p,_;if(t.getEndPosition()-a<8)return f.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:s.ERR_NOT_ENOUGH_DATA};if(r&&r<8)return f.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:s.ERR_NOT_ENOUGH_DATA};var U=t.readUint32(),S=t.readString(4),b=S;if(f.debug("BoxParser","Found box of type '"+S+"' and size "+U+" at position "+a),u=8,S=="uuid"){if(t.getEndPosition()-t.getPosition()<16||r-u<16)return t.seek(a),f.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:s.ERR_NOT_ENOUGH_DATA};_=s.parseUUID(t),u+=16,b=_}if(U==1){if(t.getEndPosition()-t.getPosition()<8||r&&r-u<8)return t.seek(a),f.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+S+'" box'),{code:s.ERR_NOT_ENOUGH_DATA};U=t.readUint64(),u+=8}else if(U===0){if(r)U=r;else if(S!=="mdat")return f.error("BoxParser","Unlimited box size not supported for type: '"+S+"'"),n=new s.Box(S,U),{code:s.OK,box:n,size:n.size}}return U!==0&&U<u?(f.error("BoxParser","Box of type "+S+" has an invalid size "+U+" (too small to be a box)"),{code:s.ERR_NOT_ENOUGH_DATA,type:S,size:U,hdr_size:u,start:a}):U!==0&&r&&U>r?(f.error("BoxParser","Box of type '"+S+"' has a size "+U+" greater than its container size "+r),{code:s.ERR_NOT_ENOUGH_DATA,type:S,size:U,hdr_size:u,start:a}):U!==0&&a+U>t.getEndPosition()?(t.seek(a),f.info("BoxParser","Not enough data in stream to parse the entire '"+S+"' box"),{code:s.ERR_NOT_ENOUGH_DATA,type:S,size:U,hdr_size:u,start:a}):e?{code:s.OK,type:S,size:U,hdr_size:u,start:a}:(s[S+"Box"]?n=new s[S+"Box"](U):S!=="uuid"?(f.warn("BoxParser","Unknown box type: '"+S+"'"),n=new s.Box(S,U),n.has_unparsed_data=!0):s.UUIDBoxes[_]?n=new s.UUIDBoxes[_](U):(f.warn("BoxParser","Unknown uuid type: '"+_+"'"),n=new s.Box(S,U),n.uuid=_,n.has_unparsed_data=!0),n.hdr_size=u,n.start=a,n.write===s.Box.prototype.write&&n.type!=="mdat"&&(f.info("BoxParser","'"+b+"' box writing not yet implemented, keeping unparsed data in memory for later write"),n.parseDataAndRewind(t)),n.parse(t),p=t.getPosition()-(n.start+n.size),p<0?(f.warn("BoxParser","Parsing of box '"+b+"' did not read the entire indicated box data size (missing "+-p+" bytes), seeking forward"),t.seek(n.start+n.size)):p>0&&(f.error("BoxParser","Parsing of box '"+b+"' read "+p+" more bytes than the indicated box data size, seeking backwards"),n.size!==0&&t.seek(n.start+n.size)),{code:s.OK,box:n,size:n.size})},s.Box.prototype.parse=function(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)},s.Box.prototype.parseDataAndRewind=function(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.position-=this.size-this.hdr_size},s.FullBox.prototype.parseDataAndRewind=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,t.position-=this.size-this.hdr_size},s.FullBox.prototype.parseFullHeader=function(t){this.version=t.readUint8(),this.flags=t.readUint24(),this.hdr_size+=4},s.FullBox.prototype.parse=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},s.ContainerBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;)if(e=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),e.code===s.OK)if(r=e.box,this.boxes.push(r),this.subBoxNames&&this.subBoxNames.indexOf(r.type)!=-1)this[this.subBoxNames[this.subBoxNames.indexOf(r.type)]+"s"].push(r);else{var n=r.type!=="uuid"?r.type:r.uuid;this[n]?f.warn("Box of type "+n+" already stored in field of this type"):this[n]=r}else return},s.Box.prototype.parseLanguage=function(t){this.language=t.readUint16();var e=[];e[0]=this.language>>10&31,e[1]=this.language>>5&31,e[2]=this.language&31,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)},s.SAMPLE_ENTRY_TYPE_VISUAL="Visual",s.SAMPLE_ENTRY_TYPE_AUDIO="Audio",s.SAMPLE_ENTRY_TYPE_HINT="Hint",s.SAMPLE_ENTRY_TYPE_METADATA="Metadata",s.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",s.SAMPLE_ENTRY_TYPE_SYSTEM="System",s.SAMPLE_ENTRY_TYPE_TEXT="Text",s.SampleEntry.prototype.parseHeader=function(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8},s.SampleEntry.prototype.parse=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},s.SampleEntry.prototype.parseDataAndRewind=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.position-=this.size-this.hdr_size},s.SampleEntry.prototype.parseFooter=function(t){s.ContainerBox.prototype.parse.call(this,t)},s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_HINT),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SYSTEM),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_TEXT),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,function(t){var e;this.parseHeader(t),t.readUint16(),t.readUint16(),t.readUint32Array(3),this.width=t.readUint16(),this.height=t.readUint16(),this.horizresolution=t.readUint32(),this.vertresolution=t.readUint32(),t.readUint32(),this.frame_count=t.readUint16(),e=Math.min(31,t.readUint8()),this.compressorname=t.readString(e),e<31&&t.readString(31-e),this.depth=t.readUint16(),t.readUint16(),this.parseFooter(t)}),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,function(t){this.parseHeader(t),t.readUint32Array(2),this.channel_count=t.readUint16(),this.samplesize=t.readUint16(),t.readUint16(),t.readUint16(),this.samplerate=t.readUint32()/65536,this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"dav1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"hvt1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"lhe1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"dvh1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"dvhe"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvc1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvi1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvs1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvcN"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vp08"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vp09"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avs3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"j2ki"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"mjp2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"mjpg"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"uncv"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"ac-4"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"Opus"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mha1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mha2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mhm1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mhm2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"fLaC"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_TEXT,"enct"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"encm"),s.createBoxCtor("a1lx",function(t){var e=t.readUint8()&1,r=((e&1)+1)*16;this.layer_size=[];for(var n=0;n<3;n++)r==16?this.layer_size[n]=t.readUint16():this.layer_size[n]=t.readUint32()}),s.createBoxCtor("a1op",function(t){this.op_index=t.readUint8()}),s.createFullBoxCtor("auxC",function(t){this.aux_type=t.readCString();var e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)}),s.createBoxCtor("av1C",function(t){var e=t.readUint8();if(e>>7&!1){f.error("av1C marker problem");return}if(this.version=e&127,this.version!==1){f.error("av1C version "+this.version+" not supported");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){f.error("av1C reserved_1 parsing problem");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){f.error("av1C reserved_2 parsing problem");return}var r=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(r)}),s.createBoxCtor("avcC",function(t){var e,r;for(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,r=this.size-this.hdr_size-6,this.SPS=[],e=0;e<this.nb_SPS_nalus;e++)this.SPS[e]={},this.SPS[e].length=t.readUint16(),this.SPS[e].nalu=t.readUint8Array(this.SPS[e].length),r-=2+this.SPS[e].length;for(this.nb_PPS_nalus=t.readUint8(),r--,this.PPS=[],e=0;e<this.nb_PPS_nalus;e++)this.PPS[e]={},this.PPS[e].length=t.readUint16(),this.PPS[e].nalu=t.readUint8Array(this.PPS[e].length),r-=2+this.PPS[e].length;r>0&&(this.ext=t.readUint8Array(r))}),s.createBoxCtor("btrt",function(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()}),s.createFullBoxCtor("ccst",function(t){var 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()}),s.createBoxCtor("cdef",function(t){var e;for(this.channel_count=t.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[],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())}),s.createBoxCtor("clap",function(t){this.cleanApertureWidthN=t.readUint32(),this.cleanApertureWidthD=t.readUint32(),this.cleanApertureHeightN=t.readUint32(),this.cleanApertureHeightD=t.readUint32(),this.horizOffN=t.readUint32(),this.horizOffD=t.readUint32(),this.vertOffN=t.readUint32(),this.vertOffD=t.readUint32()}),s.createBoxCtor("clli",function(t){this.max_content_light_level=t.readUint16(),this.max_pic_average_light_level=t.readUint16()}),s.createFullBoxCtor("cmex",function(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==1),this.flags&32&&(this.id=t.readUint32())}),s.createFullBoxCtor("cmin",function(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())}),s.createBoxCtor("cmpd",function(t){for(this.component_count=t.readUint32(),this.component_types=[],this.component_type_urls=[],i=0;i<this.component_count;i++){var e=t.readUint16();this.component_types.push(e),e>=32768&&this.component_type_urls.push(t.readCString())}}),s.createFullBoxCtor("co64",function(t){var e,r;if(e=t.readUint32(),this.chunk_offsets=[],this.version===0)for(r=0;r<e;r++)this.chunk_offsets.push(t.readUint64())}),s.createFullBoxCtor("CoLL",function(t){this.maxCLL=t.readUint16(),this.maxFALL=t.readUint16()}),s.createBoxCtor("colr",function(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();var 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))}),s.createFullBoxCtor("cprt",function(t){this.parseLanguage(t),this.notice=t.readCString()}),s.createFullBoxCtor("cslg",function(t){this.version===0&&(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32())}),s.createFullBoxCtor("ctts",function(t){var e,r;if(e=t.readUint32(),this.sample_counts=[],this.sample_offsets=[],this.version===0)for(r=0;r<e;r++){this.sample_counts.push(t.readUint32());var n=t.readInt32();n<0&&f.warn("BoxParser","ctts box uses negative values without using version 1"),this.sample_offsets.push(n)}else if(this.version==1)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),this.sample_offsets.push(t.readInt32())}),s.createBoxCtor("dac3",function(t){var e=t.readUint8(),r=t.readUint8(),n=t.readUint8();this.fscod=e>>6,this.bsid=e>>1&31,this.bsmod=(e&1)<<2|r>>6&3,this.acmod=r>>3&7,this.lfeon=r>>2&1,this.bit_rate_code=r&3|n>>5&7}),s.createBoxCtor("dec3",function(t){var e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=e&7,this.ind_subs=[];for(var r=0;r<this.num_ind_sub+1;r++){var n={};this.ind_subs.push(n);var a=t.readUint8(),u=t.readUint8(),p=t.readUint8();n.fscod=a>>6,n.bsid=a>>1&31,n.bsmod=(a&1)<<4|u>>4&15,n.acmod=u>>1&7,n.lfeon=u&1,n.num_dep_sub=p>>1&15,n.num_dep_sub>0&&(n.chan_loc=(p&1)<<8|t.readUint8())}}),s.createFullBoxCtor("dfLa",function(t){var e=127,r=128,n=[],a=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];do{var u=t.readUint8(),p=Math.min(u&e,a.length-1);if(p?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),n.push(a[p]),u&r)break}while(!0);this.numMetadataBlocks=n.length+" ("+n.join(", ")+")"}),s.createBoxCtor("dimm",function(t){this.bytessent=t.readUint64()}),s.createBoxCtor("dmax",function(t){this.time=t.readUint32()}),s.createBoxCtor("dmed",function(t){this.bytessent=t.readUint64()}),s.createBoxCtor("dOps",function(t){if(this.Version=t.readUint8(),this.OutputChannelCount=t.readUint8(),this.PreSkip=t.readUint16(),this.InputSampleRate=t.readUint32(),this.OutputGain=t.readInt16(),this.ChannelMappingFamily=t.readUint8(),this.ChannelMappingFamily!==0){this.StreamCount=t.readUint8(),this.CoupledCount=t.readUint8(),this.ChannelMapping=[];for(var e=0;e<this.OutputChannelCount;e++)this.ChannelMapping[e]=t.readUint8()}}),s.createFullBoxCtor("dref",function(t){var e,r;this.entries=[];for(var n=t.readUint32(),a=0;a<n;a++)if(e=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),e.code===s.OK)r=e.box,this.entries.push(r);else return}),s.createBoxCtor("drep",function(t){this.bytessent=t.readUint64()}),s.createFullBoxCtor("elng",function(t){this.extended_language=t.readString(this.size-this.hdr_size)}),s.createFullBoxCtor("elst",function(t){this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.entries.push(n),this.version===1?(n.segment_duration=t.readUint64(),n.media_time=t.readInt64()):(n.segment_duration=t.readUint32(),n.media_time=t.readInt32()),n.media_rate_integer=t.readInt16(),n.media_rate_fraction=t.readInt16()}}),s.createFullBoxCtor("emsg",function(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());var e=this.size-this.hdr_size-(4*4+(this.scheme_id_uri.length+1)+(this.value.length+1));this.version==1&&(e-=4),this.message_data=t.readUint8Array(e)}),s.createEntityToGroupCtor=function(t,e){s[t+"Box"]=function(r){s.FullBox.call(this,t,r)},s[t+"Box"].prototype=new s.FullBox,s[t+"Box"].prototype.parse=function(r){if(this.parseFullHeader(r),e)e.call(this,r);else for(this.group_id=r.readUint32(),this.num_entities_in_group=r.readUint32(),this.entity_ids=[],i=0;i<this.num_entities_in_group;i++){var n=r.readUint32();this.entity_ids.push(n)}}},s.createEntityToGroupCtor("aebr"),s.createEntityToGroupCtor("afbr"),s.createEntityToGroupCtor("albc"),s.createEntityToGroupCtor("altr"),s.createEntityToGroupCtor("brst"),s.createEntityToGroupCtor("dobr"),s.createEntityToGroupCtor("eqiv"),s.createEntityToGroupCtor("favc"),s.createEntityToGroupCtor("fobr"),s.createEntityToGroupCtor("iaug"),s.createEntityToGroupCtor("pano"),s.createEntityToGroupCtor("slid"),s.createEntityToGroupCtor("ster"),s.createEntityToGroupCtor("tsyn"),s.createEntityToGroupCtor("wbbr"),s.createEntityToGroupCtor("prgr"),s.createEntityToGroupCtor("pymd",function(t){this.group_id=t.readUint32(),this.num_entities_in_group=t.readUint32(),this.entity_ids=[];for(var e=0;e<this.num_entities_in_group;e++){var r=t.readUint32();this.entity_ids.push(r)}for(this.tile_size_x=t.readUint16(),this.tile_size_y=t.readUint16(),this.layer_binning=[],this.tiles_in_layer_column_minus1=[],this.tiles_in_layer_row_minus1=[],e=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.createFullBoxCtor("esds",function(t){var e=t.readUint8Array(this.size-this.hdr_size);if(typeof c<"u"){var r=new c;this.esd=r.parseOneDescriptor(new o(e.buffer,0,o.BIG_ENDIAN))}}),s.createBoxCtor("fiel",function(t){this.fieldCount=t.readUint8(),this.fieldOrdering=t.readUint8()}),s.createBoxCtor("frma",function(t){this.data_format=t.readString(4)}),s.createBoxCtor("ftyp",function(t){var e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];for(var r=0;e>=4;)this.compatible_brands[r]=t.readString(4),e-=4,r++}),s.createFullBoxCtor("hdlr",function(t){this.version===0&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),this.name=t.readString(this.size-this.hdr_size-20),this.name[this.name.length-1]==="\\0"&&(this.name=this.name.slice(0,-1)))}),s.createBoxCtor("hvcC",function(t){var e,r,n,a;this.configurationVersion=t.readUint8(),a=t.readUint8(),this.general_profile_space=a>>6,this.general_tier_flag=(a&32)>>5,this.general_profile_idc=a&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(),a=t.readUint8(),this.constantFrameRate=a>>6,this.numTemporalLayers=(a&13)>>3,this.temporalIdNested=(a&4)>>2,this.lengthSizeMinusOne=a&3,this.nalu_arrays=[];var u=t.readUint8();for(e=0;e<u;e++){var p=[];this.nalu_arrays.push(p),a=t.readUint8(),p.completeness=(a&128)>>7,p.nalu_type=a&63;var _=t.readUint16();for(r=0;r<_;r++){var U={};p.push(U),n=t.readUint16(),U.data=t.readUint8Array(n)}}}),s.createFullBoxCtor("iinf",function(t){var e;this.version===0?this.entry_count=t.readUint16():this.entry_count=t.readUint32(),this.item_infos=[];for(var r=0;r<this.entry_count;r++)if(e=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),e.code===s.OK)e.box.type!=="infe"&&f.error("BoxParser","Expected 'infe' box, got "+e.box.type),this.item_infos[r]=e.box;else return}),s.createFullBoxCtor("iloc",function(t){var 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=[];var r=0;if(this.version<2)r=t.readUint16();else if(this.version===2)r=t.readUint32();else throw"version of iloc box not supported";for(var n=0;n<r;n++){var a={};if(this.items.push(a),this.version<2)a.item_ID=t.readUint16();else if(this.version===2)a.item_ID=t.readUint32();else throw"version of iloc box not supported";switch(this.version===1||this.version===2?a.construction_method=t.readUint16()&15:a.construction_method=0,a.data_reference_index=t.readUint16(),this.base_offset_size){case 0:a.base_offset=0;break;case 4:a.base_offset=t.readUint32();break;case 8:a.base_offset=t.readUint64();break;default:throw"Error reading base offset size"}var u=t.readUint16();a.extents=[];for(var p=0;p<u;p++){var _={};if(a.extents.push(_),this.version===1||this.version===2)switch(this.index_size){case 0:_.extent_index=0;break;case 4:_.extent_index=t.readUint32();break;case 8:_.extent_index=t.readUint64();break;default:throw"Error reading extent index"}switch(this.offset_size){case 0:_.extent_offset=0;break;case 4:_.extent_offset=t.readUint32();break;case 8:_.extent_offset=t.readUint64();break;default:throw"Error reading extent index"}switch(this.length_size){case 0:_.extent_length=0;break;case 4:_.extent_length=t.readUint32();break;case 8:_.extent_length=t.readUint64();break;default:throw"Error reading extent index"}}}}),s.createBoxCtor("imir",function(t){var e=t.readUint8();this.reserved=e>>7,this.axis=e&1}),s.createFullBoxCtor("infe",function(t){if((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.content_encoding=t.readCString()),this.version===1){this.extension_type=t.readString(4),f.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()))}),s.createFullBoxCtor("ipma",function(t){var e,r;for(entry_count=t.readUint32(),this.associations=[],e=0;e<entry_count;e++){var n={};this.associations.push(n),this.version<1?n.id=t.readUint16():n.id=t.readUint32();var a=t.readUint8();for(n.props=[],r=0;r<a;r++){var u=t.readUint8(),p={};n.props.push(p),p.essential=(u&128)>>7===1,this.flags&1?p.property_index=(u&127)<<8|t.readUint8():p.property_index=u&127}}}),s.createFullBoxCtor("iref",function(t){var e,r;for(this.references=[];t.getPosition()<this.start+this.size;)if(e=s.parseOneBox(t,!0,this.size-(t.getPosition()-this.start)),e.code===s.OK)this.version===0?r=new s.SingleItemTypeReferenceBox(e.type,e.size,e.hdr_size,e.start):r=new s.SingleItemTypeReferenceBoxLarge(e.type,e.size,e.hdr_size,e.start),r.write===s.Box.prototype.write&&r.type!=="mdat"&&(f.warn("BoxParser",r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.references.push(r);else return}),s.createBoxCtor("irot",function(t){this.angle=t.readUint8()&3}),s.createFullBoxCtor("ispe",function(t){this.image_width=t.readUint32(),this.image_height=t.readUint32()}),s.createFullBoxCtor("kind",function(t){this.schemeURI=t.readCString(),this.value=t.readCString()}),s.createFullBoxCtor("leva",function(t){var e=t.readUint8();this.levels=[];for(var r=0;r<e;r++){var n={};this.levels[r]=n,n.track_ID=t.readUint32();var a=t.readUint8();switch(n.padding_flag=a>>7,n.assignment_type=a&127,n.assignment_type){case 0:n.grouping_type=t.readString(4);break;case 1:n.grouping_type=t.readString(4),n.grouping_type_parameter=t.readUint32();break;case 2:break;case 3:break;case 4:n.sub_track_id=t.readUint32();break;default:f.warn("BoxParser","Unknown leva assignement type")}}}),s.createBoxCtor("lhvC",function(t){var e,r,n;this.configurationVersion=t.readUint8(),this.min_spatial_segmentation_idc=t.readUint16()&4095,this.parallelismType=t.readUint8()&3,n=t.readUint8(),this.numTemporalLayers=(n&13)>>3,this.temporalIdNested=(n&4)>>2,this.lengthSizeMinusOne=n&3,this.nalu_arrays=[];var a=t.readUint8();for(e=0;e<a;e++){var u=[];this.nalu_arrays.push(u),n=t.readUint8(),u.completeness=(n&128)>>7,u.nalu_type=n&63;var p=t.readUint16();for(r=0;r<p;r++){var _={};u.push(_);var U=t.readUint16();_.data=t.readUint8Array(U)}}}),s.createBoxCtor("lsel",function(t){this.layer_id=t.readUint16()}),s.createBoxCtor("maxr",function(t){this.period=t.readUint32(),this.bytes=t.readUint32()});function g(t,e){this.x=t,this.y=e}g.prototype.toString=function(){return"("+this.x+","+this.y+")"},s.createBoxCtor("mdcv",function(t){this.display_primaries=[],this.display_primaries[0]=new g(t.readUint16(),t.readUint16()),this.display_primaries[1]=new g(t.readUint16(),t.readUint16()),this.display_primaries[2]=new g(t.readUint16(),t.readUint16()),this.white_point=new g(t.readUint16(),t.readUint16()),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()}),s.createFullBoxCtor("mdhd",function(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()}),s.createFullBoxCtor("mehd",function(t){this.flags&1&&(f.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()}),s.createFullBoxCtor("meta",function(t){this.boxes=[],s.ContainerBox.prototype.parse.call(this,t)}),s.createFullBoxCtor("mfhd",function(t){this.sequence_number=t.readUint32()}),s.createFullBoxCtor("mfro",function(t){this._size=t.readUint32()}),s.createFullBoxCtor("mskC",function(t){this.bits_per_pixel=t.readUint8()}),s.createFullBoxCtor("mvhd",function(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.readUint32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()}),s.createBoxCtor("npck",function(t){this.packetssent=t.readUint32()}),s.createBoxCtor("nump",function(t){this.packetssent=t.readUint64()}),s.createFullBoxCtor("padb",function(t){var e=t.readUint32();this.padbits=[];for(var r=0;r<Math.floor((e+1)/2);r++)this.padbits=t.readUint8()}),s.createBoxCtor("pasp",function(t){this.hSpacing=t.readUint32(),this.vSpacing=t.readUint32()}),s.createBoxCtor("payl",function(t){this.text=t.readString(this.size-this.hdr_size)}),s.createBoxCtor("payt",function(t){this.payloadID=t.readUint32();var e=t.readUint8();this.rtpmap_string=t.readString(e)}),s.createFullBoxCtor("pdin",function(t){var e=(this.size-this.hdr_size)/8;this.rate=[],this.initial_delay=[];for(var r=0;r<e;r++)this.rate[r]=t.readUint32(),this.initial_delay[r]=t.readUint32()}),s.createFullBoxCtor("pitm",function(t){this.version===0?this.item_id=t.readUint16():this.item_id=t.readUint32()}),s.createFullBoxCtor("pixi",function(t){var e;for(this.num_channels=t.readUint8(),this.bits_per_channels=[],e=0;e<this.num_channels;e++)this.bits_per_channels[e]=t.readUint8()}),s.createBoxCtor("pmax",function(t){this.bytes=t.readUint32()}),s.createFullBoxCtor("prdi",function(t){if(this.step_count=t.readUint16(),this.item_count=[],this.flags&2)for(var e=0;e<this.step_count;e++)this.item_count[e]=t.readUint16()}),s.createFullBoxCtor("prft",function(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()}),s.createFullBoxCtor("pssh",function(t){if(this.system_id=s.parseHex16(t),this.version>0){var e=t.readUint32();this.kid=[];for(var r=0;r<e;r++)this.kid[r]=s.parseHex16(t)}var n=t.readUint32();n>0&&(this.data=t.readUint8Array(n))}),s.createFullBoxCtor("clef",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),s.createFullBoxCtor("enof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),s.createFullBoxCtor("prof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),s.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),s.createBoxCtor("rtp ",function(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)}),s.createFullBoxCtor("saio",function(t){this.flags&1&&(this.aux_info_type=t.readString(4),this.aux_info_type_parameter=t.readUint32());var e=t.readUint32();this.offset=[];for(var r=0;r<e;r++)this.version===0?this.offset[r]=t.readUint32():this.offset[r]=t.readUint64()}),s.createFullBoxCtor("saiz",function(t){if(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(var e=0;e<this.sample_count;e++)this.sample_info_size[e]=t.readUint8()}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"mett",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"metx",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"sbtt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"stpp",function(t){this.parseHeader(t),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.auxiliary_mime_types=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"stxt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"tx3g",function(t){this.parseHeader(t),this.displayFlags=t.readUint32(),this.horizontal_justification=t.readInt8(),this.vertical_justification=t.readInt8(),this.bg_color_rgba=t.readUint8Array(4),this.box_record=t.readInt16Array(4),this.style_record=t.readUint8Array(12),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"wvtt",function(t){this.parseHeader(t),this.parseFooter(t)}),s.createSampleGroupCtor("alst",function(t){var e,r=t.readUint16();for(this.first_output_sample=t.readUint16(),this.sample_offset=[],e=0;e<r;e++)this.sample_offset[e]=t.readUint32();var n=this.description_length-4-4*r;for(this.num_output_samples=[],this.num_total_samples=[],e=0;e<n/4;e++)this.num_output_samples[e]=t.readUint16(),this.num_total_samples[e]=t.readUint16()}),s.createSampleGroupCtor("avll",function(t){this.layerNumber=t.readUint8(),this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()}),s.createSampleGroupCtor("avss",function(t){this.subSequenceIdentifier=t.readUint16(),this.layerNumber=t.readUint8();var e=t.readUint8();this.durationFlag=e>>7,this.avgRateFlag=e>>6&1,this.durationFlag&&(this.duration=t.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()),this.dependency=[];for(var r=t.readUint8(),n=0;n<r;n++){var a={};this.dependency.push(a),a.subSeqDirectionFlag=t.readUint8(),a.layerNumber=t.readUint8(),a.subSequenceIdentifier=t.readUint16()}}),s.createSampleGroupCtor("dtrt",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("mvif",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("prol",function(t){this.roll_distance=t.readInt16()}),s.createSampleGroupCtor("rap ",function(t){var e=t.readUint8();this.num_leading_samples_known=e>>7,this.num_leading_samples=e&127}),s.createSampleGroupCtor("rash",function(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(this.operation_point_count===1?2:this.operation_point_count*6)+9)f.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(var e=0;e<this.operation_point_count;e++)this.available_bitrate[e]=t.readUint32(),this.target_rate_share[e]=t.readUint16()}this.maximum_bitrate=t.readUint32(),this.minimum_bitrate=t.readUint32(),this.discard_priority=t.readUint8()}}),s.createSampleGroupCtor("roll",function(t){this.roll_distance=t.readInt16()}),s.SampleGroupEntry.prototype.parse=function(t){f.warn("BoxParser","Unknown Sample Group type: "+this.grouping_type),this.data=t.readUint8Array(this.description_length)},s.createSampleGroupCtor("scif",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("scnm",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("seig",function(t){this.reserved=t.readUint8();var 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=s.parseHex16(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))}),s.createSampleGroupCtor("stsa",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("sync",function(t){var e=t.readUint8();this.NAL_unit_type=e&63}),s.createSampleGroupCtor("tele",function(t){var e=t.readUint8();this.level_independently_decodable=e>>7}),s.createSampleGroupCtor("tsas",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("tscl",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("vipr",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createFullBoxCtor("sbgp",function(t){this.grouping_type=t.readString(4),this.version===1?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.entries.push(n),n.sample_count=t.readInt32(),n.group_description_index=t.readInt32()}});function v(t,e){this.bad_pixel_row=t,this.bad_pixel_column=e}v.prototype.toString=function(){return"[row: "+this.bad_pixel_row+", column: "+this.bad_pixel_column+"]"},s.createFullBoxCtor("sbpm",function(t){var e;for(this.component_count=t.readUint16(),this.component_index=[],e=0;e<this.component_count;e++)this.component_index.push(t.readUint16());var r=t.readUint8();for(this.correction_applied=(r&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=[],e=0;e<this.num_bad_rows;e++)this.bad_rows.push(t.readUint32());for(e=0;e<this.num_bad_cols;e++)this.bad_columns.push(t.readUint32());for(e=0;e<this.num_bad_pixels;e++){var n=t.readUint32(),a=t.readUint32();this.bad_pixels.push(new v(n,a))}}),s.createFullBoxCtor("schm",function(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))}),s.createBoxCtor("sdp ",function(t){this.sdptext=t.readString(this.size-this.hdr_size)}),s.createFullBoxCtor("sdtp",function(t){var e,r=this.size-this.hdr_size;this.is_leading=[],this.sample_depends_on=[],this.sample_is_depended_on=[],this.sample_has_redundancy=[];for(var n=0;n<r;n++)e=t.readUint8(),this.is_leading[n]=e>>6,this.sample_depends_on[n]=e>>4&3,this.sample_is_depended_on[n]=e>>2&3,this.sample_has_redundancy[n]=e&3}),s.createFullBoxCtor("senc"),s.createFullBoxCtor("sgpd",function(t){this.grouping_type=t.readString(4),f.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=[];for(var e=t.readUint32(),r=0;r<e;r++){var n;s[this.grouping_type+"SampleGroupEntry"]?n=new s[this.grouping_type+"SampleGroupEntry"](this.grouping_type):n=new s.SampleGroupEntry(this.grouping_type),this.entries.push(n),this.version===1?this.default_length===0?n.description_length=t.readUint32():n.description_length=this.default_length:n.description_length=this.default_length,n.write===s.SampleGroupEntry.prototype.write&&(f.info("BoxParser","SampleGroup for type "+this.grouping_type+" writing not yet implemented, keeping unparsed data in memory for later write"),n.data=t.readUint8Array(n.description_length),t.position-=n.description_length),n.parse(t)}}),s.createFullBoxCtor("sidx",function(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=[];for(var e=t.readUint16(),r=0;r<e;r++){var n={};this.references.push(n);var a=t.readUint32();n.reference_type=a>>31&1,n.referenced_size=a&2147483647,n.subsegment_duration=t.readUint32(),a=t.readUint32(),n.starts_with_SAP=a>>31&1,n.SAP_type=a>>28&7,n.SAP_delta_time=a&268435455}}),s.SingleItemTypeReferenceBox=function(t,e,r,n){s.Box.call(this,t,e),this.hdr_size=r,this.start=n},s.SingleItemTypeReferenceBox.prototype=new s.Box,s.SingleItemTypeReferenceBox.prototype.parse=function(t){this.from_item_ID=t.readUint16();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint16()},s.SingleItemTypeReferenceBoxLarge=function(t,e,r,n){s.Box.call(this,t,e),this.hdr_size=r,this.start=n},s.SingleItemTypeReferenceBoxLarge.prototype=new s.Box,s.SingleItemTypeReferenceBoxLarge.prototype.parse=function(t){this.from_item_ID=t.readUint32();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint32()},s.createFullBoxCtor("SmDm",function(t){this.primaryRChromaticity_x=t.readUint16(),this.primaryRChromaticity_y=t.readUint16(),this.primaryGChromaticity_x=t.readUint16(),this.primaryGChromaticity_y=t.readUint16(),this.primaryBChromaticity_x=t.readUint16(),this.primaryBChromaticity_y=t.readUint16(),this.whitePointChromaticity_x=t.readUint16(),this.whitePointChromaticity_y=t.readUint16(),this.luminanceMax=t.readUint32(),this.luminanceMin=t.readUint32()}),s.createFullBoxCtor("smhd",function(t){this.balance=t.readUint16(),t.readUint16()}),s.createFullBoxCtor("ssix",function(t){this.subsegments=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.subsegments.push(n),n.ranges=[];for(var a=t.readUint32(),u=0;u<a;u++){var p={};n.ranges.push(p),p.level=t.readUint8(),p.range_size=t.readUint24()}}}),s.createFullBoxCtor("stco",function(t){var e;if(e=t.readUint32(),this.chunk_offsets=[],this.version===0)for(var r=0;r<e;r++)this.chunk_offsets.push(t.readUint32())}),s.createFullBoxCtor("stdp",function(t){var e=(this.size-this.hdr_size)/2;this.priority=[];for(var r=0;r<e;r++)this.priority[r]=t.readUint16()}),s.createFullBoxCtor("sthd"),s.createFullBoxCtor("stri",function(t){this.switch_group=t.readUint16(),this.alternate_group=t.readUint16(),this.sub_track_id=t.readUint32();var e=(this.size-this.hdr_size-8)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),s.createFullBoxCtor("stsc",function(t){var e,r;if(e=t.readUint32(),this.first_chunk=[],this.samples_per_chunk=[],this.sample_description_index=[],this.version===0)for(r=0;r<e;r++)this.first_chunk.push(t.readUint32()),this.samples_per_chunk.push(t.readUint32()),this.sample_description_index.push(t.readUint32())}),s.createFullBoxCtor("stsd",function(t){var e,r,n,a;for(this.entries=[],n=t.readUint32(),e=1;e<=n;e++)if(r=s.parseOneBox(t,!0,this.size-(t.getPosition()-this.start)),r.code===s.OK)s[r.type+"SampleEntry"]?(a=new s[r.type+"SampleEntry"](r.size),a.hdr_size=r.hdr_size,a.start=r.start):(f.warn("BoxParser","Unknown sample entry type: "+r.type),a=new s.SampleEntry(r.type,r.size,r.hdr_size,r.start)),a.write===s.SampleEntry.prototype.write&&(f.info("BoxParser","SampleEntry "+a.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),a.parseDataAndRewind(t)),a.parse(t),this.entries.push(a);else return}),s.createFullBoxCtor("stsg",function(t){this.grouping_type=t.readUint32();var e=t.readUint16();this.group_description_index=[];for(var r=0;r<e;r++)this.group_description_index[r]=t.readUint32()}),s.createFullBoxCtor("stsh",function(t){var e,r;if(e=t.readUint32(),this.shadowed_sample_numbers=[],this.sync_sample_numbers=[],this.version===0)for(r=0;r<e;r++)this.shadowed_sample_numbers.push(t.readUint32()),this.sync_sample_numbers.push(t.readUint32())}),s.createFullBoxCtor("stss",function(t){var e,r;if(r=t.readUint32(),this.version===0)for(this.sample_numbers=[],e=0;e<r;e++)this.sample_numbers.push(t.readUint32())}),s.createFullBoxCtor("stsz",function(t){var e;if(this.sample_sizes=[],this.version===0)for(this.sample_size=t.readUint32(),this.sample_count=t.readUint32(),e=0;e<this.sample_count;e++)this.sample_size===0?this.sample_sizes.push(t.readUint32()):this.sample_sizes[e]=this.sample_size}),s.createFullBoxCtor("stts",function(t){var e,r,n;if(e=t.readUint32(),this.sample_counts=[],this.sample_deltas=[],this.version===0)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),n=t.readInt32(),n<0&&(f.warn("BoxParser","File uses negative stts sample delta, using value 1 instead, sync may be lost!"),n=1),this.sample_deltas.push(n)}),s.createFullBoxCtor("stvi",function(t){var e=t.readUint32();this.single_view_allowed=e&3,this.stereo_scheme=t.readUint32();var r=t.readUint32();this.stereo_indication_type=t.readString(r);var n,a;for(this.boxes=[];t.getPosition()<this.start+this.size;)if(n=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),n.code===s.OK)a=n.box,this.boxes.push(a),this[a.type]=a;else return}),s.createBoxCtor("styp",function(t){s.ftypBox.prototype.parse.call(this,t)}),s.createFullBoxCtor("stz2",function(t){var e,r;if(this.sample_sizes=[],this.version===0)if(this.reserved=t.readUint24(),this.field_size=t.readUint8(),r=t.readUint32(),this.field_size===4)for(e=0;e<r;e+=2){var n=t.readUint8();this.sample_sizes[e]=n>>4&15,this.sample_sizes[e+1]=n&15}else if(this.field_size===8)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint8();else if(this.field_size===16)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint16();else f.error("BoxParser","Error in length field in stz2 box")}),s.createFullBoxCtor("subs",function(t){var e,r,n,a;for(n=t.readUint32(),this.entries=[],e=0;e<n;e++){var u={};if(this.entries[e]=u,u.sample_delta=t.readUint32(),u.subsamples=[],a=t.readUint16(),a>0)for(r=0;r<a;r++){var p={};u.subsamples.push(p),this.version==1?p.size=t.readUint32():p.size=t.readUint16(),p.priority=t.readUint8(),p.discardable=t.readUint8(),p.codec_specific_parameters=t.readUint32()}}}),s.createFullBoxCtor("tenc",function(t){if(t.readUint8(),this.version===0)t.readUint8();else{var 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=s.parseHex16(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))}),s.createFullBoxCtor("tfdt",function(t){this.version==1?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()}),s.createFullBoxCtor("tfhd",function(t){var e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0}),s.createFullBoxCtor("tfra",function(t){this.track_ID=t.readUint32(),t.readUint24();var e=t.readUint8();this.length_size_of_traf_num=e>>4&3,this.length_size_of_trun_num=e>>2&3,this.length_size_of_sample_num=e&3,this.entries=[];for(var r=t.readUint32(),n=0;n<r;n++)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)]()}),s.createFullBoxCtor("tkhd",function(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()}),s.createBoxCtor("tmax",function(t){this.time=t.readUint32()}),s.createBoxCtor("tmin",function(t){this.time=t.readUint32()}),s.createBoxCtor("totl",function(t){this.bytessent=t.readUint32()}),s.createBoxCtor("tpay",function(t){this.bytessent=t.readUint32()}),s.createBoxCtor("tpyl",function(t){this.bytessent=t.readUint64()}),s.TrackGroupTypeBox.prototype.parse=function(t){this.parseFullHeader(t),this.track_group_id=t.readUint32()},s.createTrackGroupCtor("msrc"),s.TrackReferenceTypeBox=function(t,e,r,n){s.Box.call(this,t,e),this.hdr_size=r,this.start=n},s.TrackReferenceTypeBox.prototype=new s.Box,s.TrackReferenceTypeBox.prototype.parse=function(t){this.track_ids=t.readUint32Array((this.size-this.hdr_size)/4)},s.trefBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;)if(e=s.parseOneBox(t,!0,this.size-(t.getPosition()-this.start)),e.code===s.OK)r=new s.TrackReferenceTypeBox(e.type,e.size,e.hdr_size,e.start),r.write===s.Box.prototype.write&&r.type!=="mdat"&&(f.info("BoxParser","TrackReference "+r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.boxes.push(r);else return},s.createFullBoxCtor("trep",function(t){for(this.track_ID=t.readUint32(),this.boxes=[];t.getPosition()<this.start+this.size;)if(ret=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),ret.code===s.OK)box=ret.box,this.boxes.push(box);else return}),s.createFullBoxCtor("trex",function(t){this.track_id=t.readUint32(),this.default_sample_description_index=t.readUint32(),this.default_sample_duration=t.readUint32(),this.default_sample_size=t.readUint32(),this.default_sample_flags=t.readUint32()}),s.createBoxCtor("trpy",function(t){this.bytessent=t.readUint64()}),s.createFullBoxCtor("trun",function(t){var e=0;if(this.sample_count=t.readUint32(),e+=4,this.size-this.hdr_size>e&&this.flags&s.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&s.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=t.readUint32(),e+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>e)for(var r=0;r<this.sample_count;r++)this.flags&s.TRUN_FLAGS_DURATION&&(this.sample_duration[r]=t.readUint32()),this.flags&s.TRUN_FLAGS_SIZE&&(this.sample_size[r]=t.readUint32()),this.flags&s.TRUN_FLAGS_FLAGS&&(this.sample_flags[r]=t.readUint32()),this.flags&s.TRUN_FLAGS_CTS_OFFSET&&(this.version===0?this.sample_composition_time_offset[r]=t.readUint32():this.sample_composition_time_offset[r]=t.readInt32())}),s.createFullBoxCtor("tsel",function(t){this.switch_group=t.readUint32();var e=(this.size-this.hdr_size-4)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),s.createFullBoxCtor("txtC",function(t){this.config=t.readCString()}),s.createBoxCtor("tyco",function(t){var e=(this.size-this.hdr_size)/4;this.compatible_brands=[];for(var r=0;r<e;r++)this.compatible_brands[r]=t.readString(4)}),s.createFullBoxCtor("udes",function(t){this.lang=t.readCString(),this.name=t.readCString(),this.description=t.readCString(),this.tags=t.readCString()}),s.createFullBoxCtor("uncC",function(t){var e;if(this.profile=t.readUint32(),this.version!=1){if(this.version==0){for(this.component_count=t.readUint32(),this.component_index=[],this.component_bit_depth_minus_one=[],this.component_format=[],this.component_align_size=[],e=0;e<this.component_count;e++)this.component_index.push(t.readUint16()),this.component_bit_depth_minus_one.push(t.readUint8()),this.component_format.push(t.readUint8()),this.component_align_size.push(t.readUint8());this.sampling_type=t.readUint8(),this.interleave_type=t.readUint8(),this.block_size=t.readUint8();var r=t.readUint8();this.component_little_endian=r>>7&1,this.block_pad_lsb=r>>6&1,this.block_little_endian=r>>5&1,this.block_reversed=r>>4&1,this.pad_unknown=r>>3&1,this.pixel_size=t.readUint32(),this.row_align_size=t.readUint32(),this.tile_align_size=t.readUint32(),this.num_tile_cols_minus_one=t.readUint32(),this.num_tile_rows_minus_one=t.readUint32()}}}),s.createFullBoxCtor("url ",function(t){this.flags!==1&&(this.location=t.readCString())}),s.createFullBoxCtor("urn ",function(t){this.name=t.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=t.readCString())}),s.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,function(t){this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}),s.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,function(t){this.system_id=s.parseHex16(t);var e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))}),s.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),s.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,function(t){this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=s.parseHex16(t)}),s.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,function(t){this.fragment_count=t.readUint8(),this.entries=[];for(var e=0;e<this.fragment_count;e++){var r={},n=0,a=0;this.version===1?(n=t.readUint64(),a=t.readUint64()):(n=t.readUint32(),a=t.readUint32()),r.absolute_time=n,r.absolute_duration=a,this.entries.push(r)}}),s.createUUIDBox("6d1d9b0542d544e680e2141daff757b2",!0,!1,function(t){this.version===1?(this.absolute_time=t.readUint64(),this.duration=t.readUint64()):(this.absolute_time=t.readUint32(),this.duration=t.readUint32())}),s.createFullBoxCtor("vmhd",function(t){this.graphicsmode=t.readUint16(),this.opcolor=t.readUint16Array(3)}),s.createFullBoxCtor("vpcC",function(t){var e;this.version===1?(this.profile=t.readUint8(),this.level=t.readUint8(),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)):(this.profile=t.readUint8(),this.level=t.readUint8(),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))}),s.createBoxCtor("vttC",function(t){this.text=t.readString(this.size-this.hdr_size)}),s.createFullBoxCtor("vvcC",function(t){var e,r,n={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(F){this.held_bits=F.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(F){this.held_bits=F.readUint16(),this.num_held_bits=16},extract_bits:function(F){var I=this.held_bits>>this.num_held_bits-F&(1<<F)-1;return this.num_held_bits-=F,I}};if(n.stream_read_1_bytes(t),n.extract_bits(5),this.lengthSizeMinusOne=n.extract_bits(2),this.ptl_present_flag=n.extract_bits(1),this.ptl_present_flag){n.stream_read_2_bytes(t),this.ols_idx=n.extract_bits(9),this.num_sublayers=n.extract_bits(3),this.constant_frame_rate=n.extract_bits(2),this.chroma_format_idc=n.extract_bits(2),n.stream_read_1_bytes(t),this.bit_depth_minus8=n.extract_bits(3),n.extract_bits(5);{if(n.stream_read_2_bytes(t),n.extract_bits(2),this.num_bytes_constraint_info=n.extract_bits(6),this.general_profile_idc=n.extract_bits(7),this.general_tier_flag=n.extract_bits(1),this.general_level_idc=t.readUint8(),n.stream_read_1_bytes(t),this.ptl_frame_only_constraint_flag=n.extract_bits(1),this.ptl_multilayer_enabled_flag=n.extract_bits(1),this.general_constraint_info=new Uint8Array(this.num_bytes_constraint_info),this.num_bytes_constraint_info){for(e=0;e<this.num_bytes_constraint_info-1;e++){var a=n.extract_bits(6);n.stream_read_1_bytes(t);var u=n.extract_bits(2);this.general_constraint_info[e]=a<<2|u}this.general_constraint_info[this.num_bytes_constraint_info-1]=n.extract_bits(6)}else n.extract_bits(6);if(this.num_sublayers>1){for(n.stream_read_1_bytes(t),this.ptl_sublayer_present_mask=0,r=this.num_sublayers-2;r>=0;--r){var p=n.extract_bits(1);this.ptl_sublayer_present_mask|=p<<r}for(r=this.num_sublayers;r<=8&&this.num_sublayers>1;++r)n.extract_bits(1);for(this.sublayer_level_idc=[],r=this.num_sublayers-2;r>=0;--r)this.ptl_sublayer_present_mask&1<<r&&(this.sublayer_level_idc[r]=t.readUint8())}if(this.ptl_num_sub_profiles=t.readUint8(),this.general_sub_profile_idc=[],this.ptl_num_sub_profiles)for(e=0;e<this.ptl_num_sub_profiles;e++)this.general_sub_profile_idc.push(t.readUint32())}this.max_picture_width=t.readUint16(),this.max_picture_height=t.readUint16(),this.avg_frame_rate=t.readUint16()}var _=12,U=13;this.nalu_arrays=[];var S=t.readUint8();for(e=0;e<S;e++){var b=[];this.nalu_arrays.push(b),n.stream_read_1_bytes(t),b.completeness=n.extract_bits(1),n.extract_bits(2),b.nalu_type=n.extract_bits(5);var E=1;for(b.nalu_type!=U&&b.nalu_type!=_&&(E=t.readUint16()),r=0;r<E;r++){var B=t.readUint16();b.push({data:t.readUint8Array(B),length:B})}}}),s.createFullBoxCtor("vvnC",function(t){var e=strm.readUint8();this.lengthSizeMinusOne=e&3}),s.SampleEntry.prototype.isVideo=function(){return!1},s.SampleEntry.prototype.isAudio=function(){return!1},s.SampleEntry.prototype.isSubtitle=function(){return!1},s.SampleEntry.prototype.isMetadata=function(){return!1},s.SampleEntry.prototype.isHint=function(){return!1},s.SampleEntry.prototype.getCodec=function(){return this.type.replace(".","")},s.SampleEntry.prototype.getWidth=function(){return""},s.SampleEntry.prototype.getHeight=function(){return""},s.SampleEntry.prototype.getChannelCount=function(){return""},s.SampleEntry.prototype.getSampleRate=function(){return""},s.SampleEntry.prototype.getSampleSize=function(){return""},s.VisualSampleEntry.prototype.isVideo=function(){return!0},s.VisualSampleEntry.prototype.getWidth=function(){return this.width},s.VisualSampleEntry.prototype.getHeight=function(){return this.height},s.AudioSampleEntry.prototype.isAudio=function(){return!0},s.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count},s.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate},s.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize},s.SubtitleSampleEntry.prototype.isSubtitle=function(){return!0},s.MetadataSampleEntry.prototype.isMetadata=function(){return!0},s.decimalToHex=function(t,e){var r=Number(t).toString(16);for(e=typeof e>"u"||e===null?e=2:e;r.length<e;)r="0"+r;return r},s.avc1SampleEntry.prototype.getCodec=s.avc2SampleEntry.prototype.getCodec=s.avc3SampleEntry.prototype.getCodec=s.avc4SampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this);return this.avcC?t+"."+s.decimalToHex(this.avcC.AVCProfileIndication)+s.decimalToHex(this.avcC.profile_compatibility)+s.decimalToHex(this.avcC.AVCLevelIndication):t},s.hev1SampleEntry.prototype.getCodec=s.hvc1SampleEntry.prototype.getCodec=function(){var t,e=s.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){switch(e+=".",this.hvcC.general_profile_space){case 0:e+="";break;case 1:e+="A";break;case 2:e+="B";break;case 3:e+="C";break}e+=this.hvcC.general_profile_idc,e+=".";var r=this.hvcC.general_profile_compatibility,n=0;for(t=0;t<32&&(n|=r&1,t!=31);t++)n<<=1,r>>=1;e+=s.decimalToHex(n,0),e+=".",this.hvcC.general_tier_flag===0?e+="L":e+="H",e+=this.hvcC.general_level_idc;var a=!1,u="";for(t=5;t>=0;t--)(this.hvcC.general_constraint_indicator[t]||a)&&(u="."+s.decimalToHex(this.hvcC.general_constraint_indicator[t],0)+u,a=!0);e+=u}return e},s.vvc1SampleEntry.prototype.getCodec=s.vvi1SampleEntry.prototype.getCodec=function(){var t,e=s.SampleEntry.prototype.getCodec.call(this);if(this.vvcC){e+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?e+=".H":e+=".L",e+=this.vvcC.general_level_idc;var r="";if(this.vvcC.general_constraint_info){var n=[],a=0;a|=this.vvcC.ptl_frame_only_constraint<<7,a|=this.vvcC.ptl_multilayer_enabled<<6;var u;for(t=0;t<this.vvcC.general_constraint_info.length;++t)a|=this.vvcC.general_constraint_info[t]>>2&63,n.push(a),a&&(u=t),a=this.vvcC.general_constraint_info[t]>>2&3;if(u===void 0)r=".CA";else{r=".C";var p="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",_=0,U=0;for(t=0;t<=u;++t)for(_=_<<8|n[t],U+=8;U>=5;){var S=_>>U-5&31;r+=p[S],U-=5,_&=(1<<U)-1}U&&(_<<=5-U,r+=p[_&31])}}e+=r}return e},s.mp4aSampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var e=this.esds.esd.getOTI(),r=this.esds.esd.getAudioConfig();return t+"."+s.decimalToHex(e)+(r?"."+r:"")}else return t},s.stxtSampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this);return this.mime_format?t+"."+this.mime_format:t},s.vp08SampleEntry.prototype.getCodec=s.vp09SampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this),e=this.vpcC.level;e==0&&(e="00");var r=this.vpcC.bitDepth;return r==8&&(r="08"),t+".0"+this.vpcC.profile+"."+e+"."+r},s.av01SampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this),e=this.av1C.seq_level_idx_0;e<10&&(e="0"+e);var r;return this.av1C.seq_profile===2&&this.av1C.high_bitdepth===1?r=this.av1C.twelve_bit===1?"12":"10":this.av1C.seq_profile<=2&&(r=this.av1C.high_bitdepth===1?"10":"08"),t+"."+this.av1C.seq_profile+"."+e+(this.av1C.seq_tier_0?"H":"M")+"."+r},s.Box.prototype.writeHeader=function(t,e){this.size+=8,this.size>d&&(this.size+=8),this.type==="uuid"&&(this.size+=16),f.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.size>d?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,null,4),this.type==="uuid"&&t.writeUint8Array(this.uuid),this.size>d&&t.writeUint64(this.size)},s.FullBox.prototype.writeHeader=function(t){this.size+=4,s.Box.prototype.writeHeader.call(this,t," v="+this.version+" f="+this.flags),t.writeUint8(this.version),t.writeUint24(this.flags)},s.Box.prototype.write=function(t){this.type==="mdat"?this.data&&(this.size=this.data.length,this.writeHeader(t),t.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data))},s.ContainerBox.prototype.write=function(t){this.size=0,this.writeHeader(t);for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&(this.boxes[e].write(t),this.size+=this.boxes[e].size);f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.TrackReferenceTypeBox.prototype.write=function(t){this.size=this.track_ids.length*4,this.writeHeader(t),t.writeUint32Array(this.track_ids)},s.avcCBox.prototype.write=function(t){var e;for(this.size=7,e=0;e<this.SPS.length;e++)this.size+=2+this.SPS[e].length;for(e=0;e<this.PPS.length;e++)this.size+=2+this.PPS[e].length;for(this.ext&&(this.size+=this.ext.length),this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8(this.AVCProfileIndication),t.writeUint8(this.profile_compatibility),t.writeUint8(this.AVCLevelIndication),t.writeUint8(this.lengthSizeMinusOne+252),t.writeUint8(this.SPS.length+224),e=0;e<this.SPS.length;e++)t.writeUint16(this.SPS[e].length),t.writeUint8Array(this.SPS[e].nalu);for(t.writeUint8(this.PPS.length),e=0;e<this.PPS.length;e++)t.writeUint16(this.PPS[e].length),t.writeUint8Array(this.PPS[e].nalu);this.ext&&t.writeUint8Array(this.ext)},s.co64Box.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),e=0;e<this.chunk_offsets.length;e++)t.writeUint64(this.chunk_offsets[e])},s.cslgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*5,this.writeHeader(t),t.writeInt32(this.compositionToDTSShift),t.writeInt32(this.leastDecodeToDisplayDelta),t.writeInt32(this.greatestDecodeToDisplayDelta),t.writeInt32(this.compositionStartTime),t.writeInt32(this.compositionEndTime)},s.cttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),this.version===1?t.writeInt32(this.sample_offsets[e]):t.writeUint32(this.sample_offsets[e])},s.drefBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.elngBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.extended_language.length,this.writeHeader(t),t.writeString(this.extended_language)},s.elstBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+12*this.entries.length,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeUint32(r.segment_duration),t.writeInt32(r.media_time),t.writeInt16(r.media_rate_integer),t.writeInt16(r.media_rate_fraction)}},s.emsgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*4+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)},s.ftypBox.prototype.write=function(t){this.size=8+4*this.compatible_brands.length,this.writeHeader(t),t.writeString(this.major_brand,null,4),t.writeUint32(this.minor_version);for(var e=0;e<this.compatible_brands.length;e++)t.writeString(this.compatible_brands[e],null,4)},s.hdlrBox.prototype.write=function(t){this.size=5*4+this.name.length+1,this.version=0,this.flags=0,this.writeHeader(t),t.writeUint32(0),t.writeString(this.handler,null,4),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeCString(this.name)},s.hvcCBox.prototype.write=function(t){var e,r;for(this.size=23,e=0;e<this.nalu_arrays.length;e++)for(this.size+=3,r=0;r<this.nalu_arrays[e].length;r++)this.size+=2+this.nalu_arrays[e][r].data.length;for(this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8((this.general_profile_space<<6)+(this.general_tier_flag<<5)+this.general_profile_idc),t.writeUint32(this.general_profile_compatibility),t.writeUint8Array(this.general_constraint_indicator),t.writeUint8(this.general_level_idc),t.writeUint16(this.min_spatial_segmentation_idc+(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),e=0;e<this.nalu_arrays.length;e++)for(t.writeUint8((this.nalu_arrays[e].completeness<<7)+this.nalu_arrays[e].nalu_type),t.writeUint16(this.nalu_arrays[e].length),r=0;r<this.nalu_arrays[e].length;r++)t.writeUint16(this.nalu_arrays[e][r].data.length),t.writeUint8Array(this.nalu_arrays[e][r].data)},s.kindBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.schemeURI.length+1+(this.value.length+1),this.writeHeader(t),t.writeCString(this.schemeURI),t.writeCString(this.value)},s.mdhdBox.prototype.write=function(t){this.size=4*4+2*2,this.flags=0,this.version=0,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint16(this.language),t.writeUint16(0)},s.mehdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.fragment_duration)},s.mfhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.sequence_number)},s.mvhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=23*4+2*2,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint32(this.rate),t.writeUint16(this.volume<<8),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32Array(this.matrix),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(this.next_track_id)},s.SampleEntry.prototype.writeHeader=function(t){this.size=8,s.Box.prototype.writeHeader.call(this,t),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint16(this.data_reference_index)},s.SampleEntry.prototype.writeFooter=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t),this.size+=this.boxes[e].size;f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.SampleEntry.prototype.write=function(t){this.writeHeader(t),t.writeUint8Array(this.data),this.size+=this.data.length,f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.VisualSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=2*7+6*4+32,t.writeUint16(0),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint32(this.horizresolution),t.writeUint32(this.vertresolution),t.writeUint32(0),t.writeUint16(this.frame_count),t.writeUint8(Math.min(31,this.compressorname.length)),t.writeString(this.compressorname,null,31),t.writeUint16(this.depth),t.writeInt16(-1),this.writeFooter(t)},s.AudioSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=2*4+3*4,t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.channel_count),t.writeUint16(this.samplesize),t.writeUint16(0),t.writeUint16(0),t.writeUint32(this.samplerate<<16),this.writeFooter(t)},s.stppSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=this.namespace.length+1+this.schema_location.length+1+this.auxiliary_mime_types.length+1,t.writeCString(this.namespace),t.writeCString(this.schema_location),t.writeCString(this.auxiliary_mime_types),this.writeFooter(t)},s.SampleGroupEntry.prototype.write=function(t){t.writeUint8Array(this.data)},s.sbgpBox.prototype.write=function(t){this.version=1,this.flags=0,this.size=12+8*this.entries.length,this.writeHeader(t),t.writeString(this.grouping_type,null,4),t.writeUint32(this.grouping_type_parameter),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeInt32(r.sample_count),t.writeInt32(r.group_description_index)}},s.sgpdBox.prototype.write=function(t){var e,r;for(this.flags=0,this.size=12,e=0;e<this.entries.length;e++)r=this.entries[e],this.version===1&&(this.default_length===0&&(this.size+=4),this.size+=r.data.length);for(this.writeHeader(t),t.writeString(this.grouping_type,null,4),this.version===1&&t.writeUint32(this.default_length),this.version>=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length),e=0;e<this.entries.length;e++)r=this.entries[e],this.version===1&&this.default_length===0&&t.writeUint32(r.description_length),r.write(t)},s.sidxBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*4+2+2+12*this.references.length,this.writeHeader(t),t.writeUint32(this.reference_ID),t.writeUint32(this.timescale),t.writeUint32(this.earliest_presentation_time),t.writeUint32(this.first_offset),t.writeUint16(0),t.writeUint16(this.references.length);for(var e=0;e<this.references.length;e++){var r=this.references[e];t.writeUint32(r.reference_type<<31|r.referenced_size),t.writeUint32(r.subsegment_duration),t.writeUint32(r.starts_with_SAP<<31|r.SAP_type<<28|r.SAP_delta_time)}},s.smhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=4,this.writeHeader(t),t.writeUint16(this.balance),t.writeUint16(0)},s.stcoBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),t.writeUint32Array(this.chunk_offsets)},s.stscBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+12*this.first_chunk.length,this.writeHeader(t),t.writeUint32(this.first_chunk.length),e=0;e<this.first_chunk.length;e++)t.writeUint32(this.first_chunk[e]),t.writeUint32(this.samples_per_chunk[e]),t.writeUint32(this.sample_description_index[e])},s.stsdBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=0,this.writeHeader(t),t.writeUint32(this.entries.length),this.size+=4,e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.stshBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.shadowed_sample_numbers.length,this.writeHeader(t),t.writeUint32(this.shadowed_sample_numbers.length),e=0;e<this.shadowed_sample_numbers.length;e++)t.writeUint32(this.shadowed_sample_numbers[e]),t.writeUint32(this.sync_sample_numbers[e])},s.stssBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.sample_numbers.length,this.writeHeader(t),t.writeUint32(this.sample_numbers.length),t.writeUint32Array(this.sample_numbers)},s.stszBox.prototype.write=function(t){var e,r=!0;if(this.version=0,this.flags=0,this.sample_sizes.length>0)for(e=0;e+1<this.sample_sizes.length;)if(this.sample_sizes[e+1]!==this.sample_sizes[0]){r=!1;break}else e++;else r=!1;this.size=8,r||(this.size+=4*this.sample_sizes.length),this.writeHeader(t),r?t.writeUint32(this.sample_sizes[0]):t.writeUint32(0),t.writeUint32(this.sample_sizes.length),r||t.writeUint32Array(this.sample_sizes)},s.sttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),t.writeUint32(this.sample_deltas[e])},s.tfdtBox.prototype.write=function(t){var e=Math.pow(2,32)-1;this.version=this.baseMediaDecodeTime>e?1:0,this.flags=0,this.size=4,this.version===1&&(this.size+=4),this.writeHeader(t),this.version===1?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)},s.tfhdBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&s.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&s.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&s.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&s.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&s.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&s.TFHD_FLAG_BASE_DATA_OFFSET&&t.writeUint64(this.base_data_offset),this.flags&s.TFHD_FLAG_SAMPLE_DESC&&t.writeUint32(this.default_sample_description_index),this.flags&s.TFHD_FLAG_SAMPLE_DUR&&t.writeUint32(this.default_sample_duration),this.flags&s.TFHD_FLAG_SAMPLE_SIZE&&t.writeUint32(this.default_sample_size),this.flags&s.TFHD_FLAG_SAMPLE_FLAGS&&t.writeUint32(this.default_sample_flags)},s.tkhdBox.prototype.write=function(t){this.version=0,this.size=4*18+2*4,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration),t.writeUint32(0),t.writeUint32(0),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeUint16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)},s.trexBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*5,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)},s.trunBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&s.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&s.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&s.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&s.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&s.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&s.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&s.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&s.TRUN_FLAGS_FIRST_FLAG&&t.writeUint32(this.first_sample_flags);for(var e=0;e<this.sample_count;e++)this.flags&s.TRUN_FLAGS_DURATION&&t.writeUint32(this.sample_duration[e]),this.flags&s.TRUN_FLAGS_SIZE&&t.writeUint32(this.sample_size[e]),this.flags&s.TRUN_FLAGS_FLAGS&&t.writeUint32(this.sample_flags[e]),this.flags&s.TRUN_FLAGS_CTS_OFFSET&&(this.version===0?t.writeUint32(this.sample_composition_time_offset[e]):t.writeInt32(this.sample_composition_time_offset[e]))},s["url Box"].prototype.write=function(t){this.version=0,this.location?(this.flags=0,this.size=this.location.length+1):(this.flags=1,this.size=0),this.writeHeader(t),this.location&&t.writeCString(this.location)},s["urn Box"].prototype.write=function(t){this.version=0,this.flags=0,this.size=this.name.length+1+(this.location?this.location.length+1:0),this.writeHeader(t),t.writeCString(this.name),this.location&&t.writeCString(this.location)},s.vmhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=8,this.writeHeader(t),t.writeUint16(this.graphicsmode),t.writeUint16Array(this.opcolor)},s.cttsBox.prototype.unpack=function(t){var e,r,n;for(n=0,e=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)t[n].pts=t[n].dts+this.sample_offsets[e],n++},s.sttsBox.prototype.unpack=function(t){var e,r,n;for(n=0,e=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)n===0?t[n].dts=0:t[n].dts=t[n-1].dts+this.sample_deltas[e],n++},s.stcoBox.prototype.unpack=function(t){var e;for(e=0;e<this.chunk_offsets.length;e++)t[e].offset=this.chunk_offsets[e]},s.stscBox.prototype.unpack=function(t){var e,r,n,a,u;for(a=0,u=0,e=0;e<this.first_chunk.length;e++)for(r=0;r<(e+1<this.first_chunk.length?this.first_chunk[e+1]:1/0);r++)for(u++,n=0;n<this.samples_per_chunk[e];n++){if(t[a])t[a].description_index=this.sample_description_index[e],t[a].chunk_index=u;else return;a++}},s.stszBox.prototype.unpack=function(t){var e;for(e=0;e<this.sample_sizes.length;e++)t[e].size=this.sample_sizes[e]},s.DIFF_BOXES_PROP_NAMES=["boxes","entries","references","subsamples","items","item_infos","extents","associations","subsegments","ranges","seekLists","seekPoints","esd","levels"],s.DIFF_PRIMITIVE_ARRAY_PROP_NAMES=["compatible_brands","matrix","opcolor","sample_counts","sample_counts","sample_deltas","first_chunk","samples_per_chunk","sample_sizes","chunk_offsets","sample_offsets","sample_description_index","sample_duration"],s.boxEqualFields=function(t,e){if(t&&!e)return!1;var r;for(r in t)if(!(s.DIFF_BOXES_PROP_NAMES.indexOf(r)>-1)){if(t[r]instanceof s.Box||e[r]instanceof s.Box)continue;if(typeof t[r]>"u"||typeof e[r]>"u")continue;if(typeof t[r]=="function"||typeof e[r]=="function")continue;if(t.subBoxNames&&t.subBoxNames.indexOf(r.slice(0,4))>-1||e.subBoxNames&&e.subBoxNames.indexOf(r.slice(0,4))>-1)continue;if(r==="data"||r==="start"||r==="size"||r==="creation_time"||r==="modification_time")continue;if(s.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(r)>-1)continue;if(t[r]!==e[r])return!1}return!0},s.boxEqual=function(t,e){if(!s.boxEqualFields(t,e))return!1;for(var r=0;r<s.DIFF_BOXES_PROP_NAMES.length;r++){var n=s.DIFF_BOXES_PROP_NAMES[r];if(t[n]&&e[n]&&!s.boxEqual(t[n],e[n]))return!1}return!0};var x=function(){};x.prototype.parseSample=function(t){var e,r,n=new h(t.buffer);for(e=[];!n.isEos();)r=s.parseOneBox(n,!1),r.code===s.OK&&r.box.type==="vttc"&&e.push(r.box);return e},x.prototype.getText=function(t,e,r){function n(S,b,E){return E=E||"0",S=S+"",S.length>=b?S:new Array(b-S.length+1).join(E)+S}function a(S){var b=Math.floor(S/3600),E=Math.floor((S-b*3600)/60),B=Math.floor(S-b*3600-E*60),F=Math.floor((S-b*3600-E*60-B)*1e3);return""+n(b,2)+":"+n(E,2)+":"+n(B,2)+"."+n(F,3)}for(var u=this.parseSample(r),p="",_=0;_<u.length;_++){var U=u[_];p+=a(t)+" --> "+a(e)+\`\\r
|
|
1
|
+
(function(v,b){typeof exports=="object"&&typeof module<"u"?module.exports=b():typeof define=="function"&&define.amd?define(b):(v=typeof globalThis<"u"?globalThis:v||self,v.OTTPlayer=b())})(this,function(){"use strict";const v=s=>Math.abs(s-59.94005994005994)<20?59.94:Math.abs(s-29.97002997002997)<10?29.97:Math.abs(s-14.985014985014985)<8?14.98:0,b=s=>s>30&&s<70?59.94005994005994:s>15?29.97002997002997:s>7?14.985014985014985:0;class C{constructor(t){this.frameDurations=[],this.frameDurationsCapacity=t,this.lastTimestamp=null}addFrameDuration(t){return this.frameDurations.push(t),this.frameDurations.length>this.frameDurationsCapacity&&this.frameDurations.shift(),this.calculateAverage()}addTimestamp(t){if(this.lastTimestamp===null)return this.lastTimestamp=t,null;const e=t-this.lastTimestamp;return this.lastTimestamp=t,this.addFrameDuration(e)}calculateAverage(){if(this.frameDurations.length===0)return 0;const e=this.frameDurations.reduce((o,a)=>o+a,0)/this.frameDurations.length,i=this.frameDurations.filter(o=>Math.abs(o-e)<=e*.2);return i.reduce((o,a)=>o+a,0)/i.length||e}getFPS(){const t=this.calculateAverage();if(t===0)return 0;const e=1/t;return b(e)}getPerciseFPS(){const t=this.calculateAverage();return t===0?0:1/t}}const y=(()=>{const s=()=>{const d=navigator.userAgent;return/windows/i.test(d)?"Windows":/android/i.test(d)?"Android":/iphone|ipad|ipod/i.test(d)?"iOS":/mac/i.test(d)?"Mac":/ipad/i.test(d)?"iPad":"Something else"},t=()=>s()==="Mac",e=()=>s()==="iPad",i=()=>s()==="iOS",r=()=>{const d=s();return d==="iOS"||d==="Mac"||d==="iPad"},n=()=>s()==="Windows",o=()=>s()==="Android",a=()=>{switch(s()){case"Windows":return"a Windows PC";case"Android":return"an Android phone";case"iOS":return"an iPhone";case"Mac":return"a Mac";case"iPad":return"an iPad";default:return"an Unknown device"}},h=()=>({header:[navigator.platform,navigator.userAgent,navigator.appVersion,navigator.vendor,window.opera],dataos:[{name:"Windows Phone",value:"Windows Phone",version:"OS"},{name:"Windows",value:"Win",version:"NT"},{name:"iPhone",value:"iPhone",version:"OS"},{name:"iPad",value:"iPad",version:"OS"},{name:"Kindle",value:"Silk",version:"Silk"},{name:"Android",value:"Android",version:"Android"},{name:"PlayBook",value:"PlayBook",version:"OS"},{name:"BlackBerry",value:"BlackBerry",version:"/"},{name:"Macintosh",value:"Mac",version:"OS X"},{name:"Linux",value:"Linux",version:"rv"},{name:"Palm",value:"Palm",version:"PalmOS"}],databrowser:[{name:"Chrome",value:"Chrome",version:"Chrome"},{name:"Firefox",value:"Firefox",version:"Firefox"},{name:"Safari",value:"Safari",version:"Version"},{name:"Internet Explorer",value:"MSIE",version:"MSIE"},{name:"Opera",value:"Opera",version:"Opera"},{name:"BlackBerry",value:"CLDC",version:"CLDC"},{name:"Mozilla",value:"Mozilla",version:"Mozilla"}],init(){const U=this.header.join(" ");return this.matchItem(U,this.dataos)},matchItem(U,w){for(let T=0;T<w.length;T+=1)if(new RegExp(w[T].value,"i").test(U))return w[T].name;return"unknown"}}).init(),l=()=>{const d=navigator.userAgent;return d.indexOf("Chrome")>-1&&d.indexOf("Edge")===-1?"Chrome":d.indexOf("Safari")>-1&&d.indexOf("Chrome")===-1?"Safari":d.indexOf("Firefox")>-1?"Firefox":d.indexOf("MSIE")>-1||d.indexOf("Trident")>-1?"Internet Explorer":d.indexOf("Edge")>-1?"Edge":"Unknown"};return{getCurrentPlatform:s,isMac:t,isiPad:e,isiPhone:i,isApple:r,isWindows:n,isAndroid:o,getDeviceDescription:a,getDeviceName:h,getBrowserName:l,isSafariMac:()=>t()&&l()==="Safari",isChromeMac:()=>t()&&l()==="Chrome",isChromeWin:()=>n()&&l()==="Chrome"}})(),c=class c{constructor(t,e,i,r,n){this.copy=()=>new c(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const o=":";let a=("0"+this.h).slice(-2)+o+("0"+this.m).slice(-2)+o+("0"+this.s).slice(-2)+o+("0"+this.f).slice(-2);return a+="."+(this.field?"1":"2"),a},this.toZipTimeCodeString=()=>{const o=this.copy();return o.f=0,o.s=o.s%2===0?o.s:o.s-1,o.field=0,c.toStr(o)},this.toFrames=o=>{let a=60,h=0;Math.floor(o)==60?(a=60,h=0):Math.floor(o)==59?(a=60,h=4):Math.floor(o)==30?(a=30,h=0):Math.floor(o)==29&&(a=30,h=2);let l=this.h,f=this.m,u=this.s,_=this.f,g=this.field;const d=l*60+f,U=(d-Math.floor(d/10))*h;return l*(a*3600)+f*(a*60)+u*a+(_*2+g)-U},this.addSeconds=o=>{let a=this.copy();return a.s+=o,a.s>=60&&(a.s=0,a.m++,a.m>=60&&(a.m=0,a.h++)),a},this.addFrames=(o,a)=>{let h=this.toFrames(a);return h+=o,c.fromFrames(h,a)},this.subtractFrames=(o,a)=>this.addFrames(-o,a),this.h=t||0,this.m=e||0,this.s=i||0,this.f=r||0,this.field=n||0}static compare(t,e){return t.h!==e.h?t.h<e.h?-1:1:t.m!==e.m?t.m<e.m?-1:1:t.s!==e.s?t.s<e.s?-1:1:t.f!==e.f?t.f<e.f?-1:1:t.field!==e.field?t.field<e.field?-1:1:0}static generateTimecodeRange(t,e,i){const r=[];let n=t;for(;c.compare(n,e)<=0;)r.push(n),n=n.addSeconds(i);return r}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(t){return this.toFrames(t)*1e3/t}};c.calculateCurrentTimeCode=t=>{var u;if(!t.video||!t.clocker||!t.gameParams)throw new Error("OTTPlayer is not initialized");const e=t.video,i=t.clocker,r=i.videoFPScalculator.getFPS(),a=(e.currentTime-i.syncPoint.playerTime)%(60*60*24)*r+i.syncPoint.frame;if(a===0||r===0)throw new Error("Current frame is 0 or fps is 0");const h=c.calculateCurrentOffset(a,(u=t.gameParams)==null?void 0:u.offsets);if(h===void 0)throw new Error("Offset is undefined");let l=Math.floor(a-h);return l<0&&(l+=5178816),l>=5178816&&(l-=5178816),c.fromFrames(l,r)},c.calculateCurrentOffset=(t,e)=>{for(let i=1;i<e.length;i++)if(t<e[i].frame)return e[i-1].offset;return e[e.length-1].offset},c.fromFrames=(t,e)=>{let i=60,r=0;Math.floor(e)==60?(i=60,r=0):Math.floor(e)==59?(i=60,r=4):Math.floor(e)==30?(i=30,r=0):Math.floor(e)==29&&(i=30,r=2);let n=Math.floor(e*60),o=Math.floor(e*60*10),a=o*6,h=t,l=Math.floor(h/a);h-=l*a;let f=Math.floor(h/o);h-=f*o,h>=i*60&&(h+=r*(Math.floor((h-i*60)/n)+1));let u=Math.floor(h/(i*60));h-=u*(i*60);let _=Math.floor(h/i);h-=_*i;let g=h;u+=f*10;let d=0;return d=g%2,g=Math.floor(g/2),new c(l,u,_,g,d)},c.toStr=t=>{const e="_";let i=("0"+t.h).slice(-2)+e+("0"+t.m).slice(-2)+e+("0"+t.s).slice(-2)+e+("0"+t.f).slice(-2);return t.field&&(i+="_1"),i},c.fromStr=t=>{const i=t.split("_").map(Number);if(i.length==4){const[r,n,o,a]=i;return new c(r,n,o,a,0)}else if(i.length==5){const[r,n,o,a,h]=i;return new c(r,n,o,a,h)}else throw new Error("Invalid timecode format: "+t)},c.fromMetadata=t=>{const e=/^(\d{2}):(\d{2}):(\d{2}):(\d{2})(?:\.(\d))?$/,i=t.timecode.match(e);if(!i)throw new Error("Invalid timecode format: "+t.timecode);const[,r,n,o,a,h]=i,l=Number(r),f=Number(n),u=Number(o),_=Number(a),g=h?Number(h):0;return new c(l,f,u,_,g)};let p=c,A=0,E=0;const D=s=>{if(s.metadata.messageData){s.metadata.messageData=R(s.metadata.messageData,s.metadata.presentationTime);return}if(s.metadata.frames&&s.metadata.frames.length&&s.metadata.frames[0].key&&s.metadata.frames[0].key.toLowerCase()==="priv"){const t=s.metadata.frames.filter(e=>e.info&&e.info.toLowerCase().includes("ntc"));if(t.length){const e=t[t.length-1],i=`${e.info}\0${String.fromCharCode(...e.data)}`;s.metadata.messageData=R(i,s.metadata.presentationTime)}}},P=()=>{const s=new Date(A-E);let t=Math.round(s.getUTCMilliseconds()*30*2/1001)/2;const e=t%1;let i=1;return e===.5&&(t=Math.floor(t),i=2),new p(s.getUTCHours(),s.getUTCMinutes(),s.getUTCSeconds(),Math.floor(t),i===1?0:1)},V=s=>{if((s&&s.metadata&&s.metadata.id==0||y.isSafariMac())&&(D(s),s.metadata.id==0||y.isSafariMac()&&E==0))return P()},H=s=>(D(s),P()),R=(s,t)=>{let e="";if(s&&s.includes("www.mediakind.com/NTC")){const i=s.replace(/.*NTC./,"");let r=0;for(;r+8<=i.length;){const n=i.substring(r,r+4),o=((i.charCodeAt(r+4)*256+i.charCodeAt(r+5))*256+i.charCodeAt(r+6))*256+i.charCodeAt(r+7);if(r+8+o>i.length)break;const a=i.substring(r+8,r+8+o);n==="utc_"&&new Date(parseInt(a)).getTime()/1e3,n==="tc__"&&(A=new Date(parseInt(a)).getTime()),n==="offs"&&(E=parseInt(a)/90),r+=8+o}}return e},Y=(s,t,e)=>{const i=e.toFrames(t),r=e.print();console.log("New segment ("+s.url+"): "+r+" ("+i+") playing at "+s.playbackTime);const n=s.playbackTime;return{frame:i,playerTime:n,stringTime:r}},W=(s,t,e)=>{const i=e.toFrames(t),r=e.print(),n=s.metadata.presentationTime;return{frame:i,playerTime:n,stringTime:r}},j=async s=>{let t;typeof document>"u"?t=new URL(self.location.href):t=new URL(document.location.href);const e=t.searchParams.get("config");if(e){const r=await(await fetch(e)).json();Object.assign(s,r)}},m=(s,t)=>!s.debug||!s.debug.on?!1:s.debug[`log${t}`];class ${constructor(t){this.last10=[],this.errorsInProgress=[],this.lastFrameTC=null,this.fps=t}setFPS(t){this.fps=t}timecodeRecieved(t){if(!t)return;const e=p.fromStr(t);if(this.last10.push(e),this.last10.length>10&&this.last10.shift(),this.lastFrameTC){const i=this.incrementInterlaced(this.lastFrameTC);p.compare(e,i)!==0&&(console.warn("Timecode sequence is invalid! Detected at:",t),this.errorsInProgress.push({preTCs:[...this.last10],postTCs:[],framesAfter:0,printed:!1}))}for(const i of this.errorsInProgress)i.printed||(i.postTCs.push(e),i.framesAfter++);for(const i of this.errorsInProgress)if(!i.printed&&i.framesAfter>=10){console.error("Full 20-frame sequence around error:");const r=[...i.preTCs,...i.postTCs];console.error(r.map(n=>p.toStr(n))),i.printed=!0}this.lastFrameTC=e}incrementInterlaced(t){const e=t.copy();return e.field===0?(e.field=1,e):(e.field=0,e.f++,e.f>=30&&(e.f=0,e.s++,e.s>=60&&(e.s=0,e.m++,e.m>=60&&(e.m=0,e.h++))),e)}}class X{constructor(t,e){this.click=async i=>{const r=this.video.getBoundingClientRect(),n=(i.clientX-r.left)/r.width,o=(i.clientY-r.top)/r.height,a={x:n,y:o};this.renderer.postMessage({type:"VIDEO_CLICK",clickData:a})},this.video=t,this.renderer=e,this.renderer.onmessage=i=>{if(i.data.type==="OPEN_URL"){const r=i.data.url;r&&window.open(r,"_blank")}}}}const B='(function(){"use strict";const d=(l,t)=>!l.debug||!l.debug.on?!1:l.debug[`log${t}`];class E{constructor(t){this.fetchGameParams=async(s,r)=>{const n=`${s}/${r}.json`;this.options&&d(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching GameParams from ${n}`);const a=await fetch(n);if(!a.ok)throw new Error(`HTTP error! Status: ${a.status}`);const o=await a.json();return o.hasOwnProperty("bucketName")&&o.hasOwnProperty("offsets")?o:(this.options&&d(this.options,"Errors")&&console.error(`[Fetcher] Game params for ${r} not found in JSON.`),a)},this.fetchMetadata=async(s,r,n,a)=>{const e=`${`${s}/${r}`}/manifests/59.94/${a}.zip`;this.options&&d(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching metadata from ${e}`);const i=await fetch(e),c=i.headers.get("x-tgi-ott-actions");let f;if(c?f=JSON.parse(c):f={toggle:{ios:!0,android:!0,web:!0}},!i.ok)throw new Error(`HTTP error! Status: ${i.status}`);return{arrayBuffer:await i.arrayBuffer(),ottActions:f}},this.options=t}}const h=class h{constructor(t,s,r,n,a){this.copy=()=>new h(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const o=":";let e=("0"+this.h).slice(-2)+o+("0"+this.m).slice(-2)+o+("0"+this.s).slice(-2)+o+("0"+this.f).slice(-2);return e+="."+(this.field?"1":"2"),e},this.toZipTimeCodeString=()=>{const o=this.copy();return o.f=0,o.s=o.s%2===0?o.s:o.s-1,o.field=0,h.toStr(o)},this.toFrames=o=>{let e=60,i=0;Math.floor(o)==60?(e=60,i=0):Math.floor(o)==59?(e=60,i=4):Math.floor(o)==30?(e=30,i=0):Math.floor(o)==29&&(e=30,i=2);let c=this.h,f=this.m,m=this.s,u=this.f,g=this.field;const b=c*60+f,R=(b-Math.floor(b/10))*i;return c*(e*3600)+f*(e*60)+m*e+(u*2+g)-R},this.addSeconds=o=>{let e=this.copy();return e.s+=o,e.s>=60&&(e.s=0,e.m++,e.m>=60&&(e.m=0,e.h++)),e},this.addFrames=(o,e)=>{let i=this.toFrames(e);return i+=o,h.fromFrames(i,e)},this.subtractFrames=(o,e)=>this.addFrames(-o,e),this.h=t||0,this.m=s||0,this.s=r||0,this.f=n||0,this.field=a||0}static compare(t,s){return t.h!==s.h?t.h<s.h?-1:1:t.m!==s.m?t.m<s.m?-1:1:t.s!==s.s?t.s<s.s?-1:1:t.f!==s.f?t.f<s.f?-1:1:t.field!==s.field?t.field<s.field?-1:1:0}static generateTimecodeRange(t,s,r){const n=[];let a=t;for(;h.compare(a,s)<=0;)n.push(a),a=a.addSeconds(r);return n}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(t){return this.toFrames(t)*1e3/t}};h.calculateCurrentTimeCode=t=>{var m;if(!t.video||!t.clocker||!t.gameParams)throw new Error("OTTPlayer is not initialized");const s=t.video,r=t.clocker,n=r.videoFPScalculator.getFPS(),e=(s.currentTime-r.syncPoint.playerTime)%(60*60*24)*n+r.syncPoint.frame;if(e===0||n===0)throw new Error("Current frame is 0 or fps is 0");const i=h.calculateCurrentOffset(e,(m=t.gameParams)==null?void 0:m.offsets);if(i===void 0)throw new Error("Offset is undefined");let c=Math.floor(e-i);return c<0&&(c+=5178816),c>=5178816&&(c-=5178816),h.fromFrames(c,n)},h.calculateCurrentOffset=(t,s)=>{for(let r=1;r<s.length;r++)if(t<s[r].frame)return s[r-1].offset;return s[s.length-1].offset},h.fromFrames=(t,s)=>{let r=60,n=0;Math.floor(s)==60?(r=60,n=0):Math.floor(s)==59?(r=60,n=4):Math.floor(s)==30?(r=30,n=0):Math.floor(s)==29&&(r=30,n=2);let a=Math.floor(s*60),o=Math.floor(s*60*10),e=o*6,i=t,c=Math.floor(i/e);i-=c*e;let f=Math.floor(i/o);i-=f*o,i>=r*60&&(i+=n*(Math.floor((i-r*60)/a)+1));let m=Math.floor(i/(r*60));i-=m*(r*60);let u=Math.floor(i/r);i-=u*r;let g=i;m+=f*10;let b=0;return b=g%2,g=Math.floor(g/2),new h(c,m,u,g,b)},h.toStr=t=>{const s="_";let r=("0"+t.h).slice(-2)+s+("0"+t.m).slice(-2)+s+("0"+t.s).slice(-2)+s+("0"+t.f).slice(-2);return t.field&&(r+="_1"),r},h.fromStr=t=>{const r=t.split("_").map(Number);if(r.length==4){const[n,a,o,e]=r;return new h(n,a,o,e,0)}else if(r.length==5){const[n,a,o,e,i]=r;return new h(n,a,o,e,i)}else throw new Error("Invalid timecode format: "+t)},h.fromMetadata=t=>{const s=/^(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d))?$/,r=t.timecode.match(s);if(!r)throw new Error("Invalid timecode format: "+t.timecode);const[,n,a,o,e,i]=r,c=Number(n),f=Number(a),m=Number(o),u=Number(e),g=i?Number(i):0;return new h(c,f,m,u,g)};let D=h;class T{constructor(t,s,r){this.jobsQueue=[],this.processedTimecodes=[],this.updateStreamData=n=>{this.streamData=n,this.initiateJobs(this.options.DOWNLOADER_ZIP_START_OFFSET,this.options.DOWNLOADER_ZIP_END_OFFSET,this.options.DOWNLOADER_ZIP_LENGTH_SECONDS),this.clearOldJobs(1)},this.initiateJobs=(n,a,o)=>{if(!this.streamData){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Stream data is not available");return}const e=D.fromStr(this.streamData.timeCode),i=e.addSeconds(n),c=e.addSeconds(a),f=D.generateTimecodeRange(i,c,o);for(const m of f){const u=m.toZipTimeCodeString();this.processedTimecodes.includes(u)||(this.processedTimecodes.push(u),this.addJob(u))}},this.clearOldJobs=n=>{if(!this.streamData){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Stream data is not available");return}const o=D.fromStr(this.streamData.timeCode).totalSeconds()-n;this.processedTimecodes=this.processedTimecodes.filter(e=>D.fromStr(e).totalSeconds()>o)},this.addJob=n=>{if(this.jobsQueue.some(a=>a===n)){this.options&&d(this.options,"Downloader")&&console.log(`[Downloader] Job already exists for timeCode=${n}`);return}this.jobsQueue.push(n),this.startNextJob()},this.startNextJob=()=>{!this.currentJob&&this.jobsQueue.length>0&&(this.currentJob=this.jobsQueue.shift(),this.options&&d(this.options,"Downloader")&&console.log(`[Downloader] Starting job timeCode=${this.currentJob}`),this.downloadZip(this.currentJob))},this.jobDone=()=>{this.currentJob=void 0,this.startNextJob()},this.downloadZip=async n=>{if(!this.streamData){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Stream data is not available");return}const{fps:a,cloudFrontURL:o,bucketName:e}=this.streamData;try{this.options&&d(this.options,"Downloader")&&console.log(`[Downloader] Fetching zip for timeCode=${n}`);const{arrayBuffer:i,ottActions:c}=await this.fetcher.fetchMetadata(o,e,a,n);this.postOTTActionsToRenderer(c),this.postArrayBufferToDecoder(n,i)}catch(i){this.options&&d(this.options,"Errors")&&console.error("[Downloader] Error:",i)}this.jobDone()},this.postArrayBufferToDecoder=t,this.postOTTActionsToRenderer=s,this.options=r,this.fetcher=new E(r)}}let w=null,S=null,F,p;self.onmessage=async l=>{const{data:t}=l;t.type==="SET_RENDERER_PORT"&&(w=t.port,w.onmessage=y),t.type==="SET_DECODER_PORT"&&(S=t.port,S.onmessage=N),t.type==="SET_OPTIONS"&&(p=t.options,F=new T(M,O,p))};async function y(l){const{data:t}=l;t.type==="DOWNLOADER_INPUT"&&F.updateStreamData(t.streamData)}function M(l,t){if(!S)return;p&&d(p,"Downloader")&&console.log(`[DownloaderWorker] Posting an ArrayBuffer to Decoder, timeCode=${l}`);const s={type:"DECODER_INPUT",timeCode:l,arrayBuffer:t};S==null||S.postMessage(s,{transfer:[t]})}function O(l){if(!w)return;p&&d(p,"Downloader")&&console.log(`[DownloaderWorker] Posting OTTActions to Renderer, toggle=${l.toggle}`);const t={type:"OTT_ACTIONS",ottActions:l};w==null||w.postMessage(t)}function N(l){p&&d(p,"Downloader")&&console.log("[DownloaderWorker] Received message from Decoder:",l.data)}})();\n',k=typeof self<"u"&&self.Blob&&new Blob([B],{type:"text/javascript;charset=utf-8"});function q(s){let t;try{if(t=k&&(self.URL||self.webkitURL).createObjectURL(k),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(B),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const M=`(function(){"use strict";const L=(C,f)=>!C.debug||!C.debug.on?!1:C.debug[\`log\${f}\`];function X(C){return C&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C.default:C}var K={},Q;function et(){return Q||(Q=1,function(C){var f=function(){var t=new Date,e=4,r=3,n=2,a=1,u=e,p={setLogLevel:function(_){_==this.debug?u=a:_==this.info?u=n:_==this.warn?u=r:(_==this.error,u=e)},debug:function(_,U){console.debug===void 0&&(console.debug=console.log),a>=u&&console.debug("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)},log:function(_,U){this.debug(_.msg)},info:function(_,U){n>=u&&console.info("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)},warn:function(_,U){r>=u&&console.warn("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)},error:function(_,U){e>=u&&console.error("["+f.getDurationString(new Date-t,1e3)+"]","["+_+"]",U)}};return p}();f.getDurationString=function(t,e){var r;function n(S,b){for(var E=""+S,B=E.split(".");B[0].length<b;)B[0]="0"+B[0];return B.join(".")}t<0?(r=!0,t=-t):r=!1;var a=e||1,u=t/a,p=Math.floor(u/3600);u-=p*3600;var _=Math.floor(u/60);u-=_*60;var U=u*1e3;return u=Math.floor(u),U-=u*1e3,U=Math.floor(U),(r?"-":"")+p+":"+n(_,2)+":"+n(u,2)+"."+n(U,3)},f.printRanges=function(t){var e=t.length;if(e>0){for(var r="",n=0;n<e;n++)n>0&&(r+=","),r+="["+f.getDurationString(t.start(n))+","+f.getDurationString(t.end(n))+"]";return r}else return"(empty)"},C.Log=f;var h=function(t){if(t instanceof ArrayBuffer)this.buffer=t,this.dataview=new DataView(t);else throw"Needs an array buffer";this.position=0};h.prototype.getPosition=function(){return this.position},h.prototype.getEndPosition=function(){return this.buffer.byteLength},h.prototype.getLength=function(){return this.buffer.byteLength},h.prototype.seek=function(t){var e=Math.max(0,Math.min(this.buffer.byteLength,t));return this.position=isNaN(e)||!isFinite(e)?0:e,!0},h.prototype.isEos=function(){return this.getPosition()>=this.getEndPosition()},h.prototype.readAnyInt=function(t,e){var r=0;if(this.position+t<=this.buffer.byteLength){switch(t){case 1:e?r=this.dataview.getInt8(this.position):r=this.dataview.getUint8(this.position);break;case 2:e?r=this.dataview.getInt16(this.position):r=this.dataview.getUint16(this.position);break;case 3:if(e)throw"No method for reading signed 24 bits values";r=this.dataview.getUint8(this.position)<<16,r|=this.dataview.getUint8(this.position+1)<<8,r|=this.dataview.getUint8(this.position+2);break;case 4:e?r=this.dataview.getInt32(this.position):r=this.dataview.getUint32(this.position);break;case 8:if(e)throw"No method for reading signed 64 bits values";r=this.dataview.getUint32(this.position)<<32,r|=this.dataview.getUint32(this.position+4);break;default:throw"readInt method not implemented for size: "+t}return this.position+=t,r}else throw"Not enough bytes in buffer"},h.prototype.readUint8=function(){return this.readAnyInt(1,!1)},h.prototype.readUint16=function(){return this.readAnyInt(2,!1)},h.prototype.readUint24=function(){return this.readAnyInt(3,!1)},h.prototype.readUint32=function(){return this.readAnyInt(4,!1)},h.prototype.readUint64=function(){return this.readAnyInt(8,!1)},h.prototype.readString=function(t){if(this.position+t<=this.buffer.byteLength){for(var e="",r=0;r<t;r++)e+=String.fromCharCode(this.readUint8());return e}else throw"Not enough bytes in buffer"},h.prototype.readCString=function(){for(var t=[];;){var e=this.readUint8();if(e!==0)t.push(e);else break}return String.fromCharCode.apply(null,t)},h.prototype.readInt8=function(){return this.readAnyInt(1,!0)},h.prototype.readInt16=function(){return this.readAnyInt(2,!0)},h.prototype.readInt32=function(){return this.readAnyInt(4,!0)},h.prototype.readInt64=function(){return this.readAnyInt(8,!1)},h.prototype.readUint8Array=function(t){for(var e=new Uint8Array(t),r=0;r<t;r++)e[r]=this.readUint8();return e},h.prototype.readInt16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readInt16();return e},h.prototype.readUint16Array=function(t){for(var e=new Int16Array(t),r=0;r<t;r++)e[r]=this.readUint16();return e},h.prototype.readUint32Array=function(t){for(var e=new Uint32Array(t),r=0;r<t;r++)e[r]=this.readUint32();return e},h.prototype.readInt32Array=function(t){for(var e=new Int32Array(t),r=0;r<t;r++)e[r]=this.readInt32();return e},C.MP4BoxStream=h;var o=function(t,e,r){this._byteOffset=e||0,t instanceof ArrayBuffer?this.buffer=t:typeof t=="object"?(this.dataView=t,e&&(this._byteOffset+=e)):this.buffer=new ArrayBuffer(t||0),this.position=0,this.endianness=r??o.LITTLE_ENDIAN};o.prototype={},o.prototype.getPosition=function(){return this.position},o.prototype._realloc=function(t){if(this._dynamicSize){var e=this._byteOffset+this.position+t,r=this._buffer.byteLength;if(e<=r){e>this._byteLength&&(this._byteLength=e);return}for(r<1&&(r=1);e>r;)r*=2;var n=new ArrayBuffer(r),a=new Uint8Array(this._buffer),u=new Uint8Array(n,0,a.length);u.set(a),this.buffer=n,this._byteLength=e}},o.prototype._trimAlloc=function(){if(this._byteLength!=this._buffer.byteLength){var t=new ArrayBuffer(this._byteLength),e=new Uint8Array(t),r=new Uint8Array(this._buffer,0,e.length);e.set(r),this.buffer=t}},o.BIG_ENDIAN=!1,o.LITTLE_ENDIAN=!0,o.prototype._byteLength=0,Object.defineProperty(o.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}}),Object.defineProperty(o.prototype,"buffer",{get:function(){return this._trimAlloc(),this._buffer},set:function(t){this._buffer=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(o.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(t){this._byteOffset=t,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._buffer.byteLength}}),Object.defineProperty(o.prototype,"dataView",{get:function(){return this._dataView},set:function(t){this._byteOffset=t.byteOffset,this._buffer=t.buffer,this._dataView=new DataView(this._buffer,this._byteOffset),this._byteLength=this._byteOffset+t.byteLength}}),o.prototype.seek=function(t){var e=Math.max(0,Math.min(this.byteLength,t));this.position=isNaN(e)||!isFinite(e)?0:e},o.prototype.isEof=function(){return this.position>=this._byteLength},o.prototype.mapUint8Array=function(t){this._realloc(t*1);var e=new Uint8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=t*1,e},o.prototype.readInt32Array=function(t,e){t=t??this.byteLength-this.position/4;var r=new Int32Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readInt16Array=function(t,e){t=t??this.byteLength-this.position/2;var r=new Int16Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readInt8Array=function(t){t=t??this.byteLength-this.position;var e=new Int8Array(t);return o.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},o.prototype.readUint32Array=function(t,e){t=t??this.byteLength-this.position/4;var r=new Uint32Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readUint16Array=function(t,e){t=t??this.byteLength-this.position/2;var r=new Uint16Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readUint8Array=function(t){t=t??this.byteLength-this.position;var e=new Uint8Array(t);return o.memcpy(e.buffer,0,this.buffer,this.byteOffset+this.position,t*e.BYTES_PER_ELEMENT),this.position+=e.byteLength,e},o.prototype.readFloat64Array=function(t,e){t=t??this.byteLength-this.position/8;var r=new Float64Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readFloat32Array=function(t,e){t=t??this.byteLength-this.position/4;var r=new Float32Array(t);return o.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,t*r.BYTES_PER_ELEMENT),o.arrayToNative(r,e??this.endianness),this.position+=r.byteLength,r},o.prototype.readInt32=function(t){var e=this._dataView.getInt32(this.position,t??this.endianness);return this.position+=4,e},o.prototype.readInt16=function(t){var e=this._dataView.getInt16(this.position,t??this.endianness);return this.position+=2,e},o.prototype.readInt8=function(){var t=this._dataView.getInt8(this.position);return this.position+=1,t},o.prototype.readUint32=function(t){var e=this._dataView.getUint32(this.position,t??this.endianness);return this.position+=4,e},o.prototype.readUint16=function(t){var e=this._dataView.getUint16(this.position,t??this.endianness);return this.position+=2,e},o.prototype.readUint8=function(){var t=this._dataView.getUint8(this.position);return this.position+=1,t},o.prototype.readFloat32=function(t){var e=this._dataView.getFloat32(this.position,t??this.endianness);return this.position+=4,e},o.prototype.readFloat64=function(t){var e=this._dataView.getFloat64(this.position,t??this.endianness);return this.position+=8,e},o.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0,o.memcpy=function(t,e,r,n,a){var u=new Uint8Array(t,e,a),p=new Uint8Array(r,n,a);u.set(p)},o.arrayToNative=function(t,e){return e==this.endianness?t:this.flipArrayEndianness(t)},o.nativeToEndian=function(t,e){return this.endianness==e?t:this.flipArrayEndianness(t)},o.flipArrayEndianness=function(t){for(var e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),r=0;r<t.byteLength;r+=t.BYTES_PER_ELEMENT)for(var n=r+t.BYTES_PER_ELEMENT-1,a=r;n>a;n--,a++){var u=e[a];e[a]=e[n],e[n]=u}return t},o.prototype.failurePosition=0,String.fromCharCodeUint8=function(t){for(var e=[],r=0;r<t.length;r++)e[r]=t[r];return String.fromCharCode.apply(null,e)},o.prototype.readString=function(t,e){return e==null||e=="ASCII"?String.fromCharCodeUint8.apply(null,[this.mapUint8Array(t??this.byteLength-this.position)]):new TextDecoder(e).decode(this.mapUint8Array(t))},o.prototype.readCString=function(t){var e=this.byteLength-this.position,r=new Uint8Array(this._buffer,this._byteOffset+this.position),n=e;t!=null&&(n=Math.min(t,e));for(var a=0;a<n&&r[a]!==0;a++);var u=String.fromCharCodeUint8.apply(null,[this.mapUint8Array(a)]);return t!=null?this.position+=n-a:a!=e&&(this.position+=1),u};var d=Math.pow(2,32);o.prototype.readInt64=function(){return this.readInt32()*d+this.readUint32()},o.prototype.readUint64=function(){return this.readUint32()*d+this.readUint32()},o.prototype.readInt64=function(){return this.readUint32()*d+this.readUint32()},o.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()},C.DataStream=o,o.prototype.save=function(t){var e=new Blob([this.buffer]);if(window.URL&&URL.createObjectURL){var r=window.URL.createObjectURL(e),n=document.createElement("a");document.body.appendChild(n),n.setAttribute("href",r),n.setAttribute("download",t),n.setAttribute("target","_self"),n.click(),window.URL.revokeObjectURL(r)}else throw"DataStream.save: Can't create object URL."},o.prototype._dynamicSize=!0,Object.defineProperty(o.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(t){t||this._trimAlloc(),this._dynamicSize=t}}),o.prototype.shift=function(t){var e=new ArrayBuffer(this._byteLength-t),r=new Uint8Array(e),n=new Uint8Array(this._buffer,t,r.length);r.set(n),this.buffer=e,this.position-=t},o.prototype.writeInt32Array=function(t,e){if(this._realloc(t.length*4),t instanceof Int32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt32(t[r],e)},o.prototype.writeInt16Array=function(t,e){if(this._realloc(t.length*2),t instanceof Int16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeInt16(t[r],e)},o.prototype.writeInt8Array=function(t){if(this._realloc(t.length*1),t instanceof Int8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapInt8Array(t.length);else for(var e=0;e<t.length;e++)this.writeInt8(t[e])},o.prototype.writeUint32Array=function(t,e){if(this._realloc(t.length*4),t instanceof Uint32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint32(t[r],e)},o.prototype.writeUint16Array=function(t,e){if(this._realloc(t.length*2),t instanceof Uint16Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint16Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeUint16(t[r],e)},o.prototype.writeUint8Array=function(t){if(this._realloc(t.length*1),t instanceof Uint8Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapUint8Array(t.length);else for(var e=0;e<t.length;e++)this.writeUint8(t[e])},o.prototype.writeFloat64Array=function(t,e){if(this._realloc(t.length*8),t instanceof Float64Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat64Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat64(t[r],e)},o.prototype.writeFloat32Array=function(t,e){if(this._realloc(t.length*4),t instanceof Float32Array&&this.byteOffset+this.position%t.BYTES_PER_ELEMENT===0)o.memcpy(this._buffer,this.byteOffset+this.position,t.buffer,0,t.byteLength),this.mapFloat32Array(t.length,e);else for(var r=0;r<t.length;r++)this.writeFloat32(t[r],e)},o.prototype.writeInt32=function(t,e){this._realloc(4),this._dataView.setInt32(this.position,t,e??this.endianness),this.position+=4},o.prototype.writeInt16=function(t,e){this._realloc(2),this._dataView.setInt16(this.position,t,e??this.endianness),this.position+=2},o.prototype.writeInt8=function(t){this._realloc(1),this._dataView.setInt8(this.position,t),this.position+=1},o.prototype.writeUint32=function(t,e){this._realloc(4),this._dataView.setUint32(this.position,t,e??this.endianness),this.position+=4},o.prototype.writeUint16=function(t,e){this._realloc(2),this._dataView.setUint16(this.position,t,e??this.endianness),this.position+=2},o.prototype.writeUint8=function(t){this._realloc(1),this._dataView.setUint8(this.position,t),this.position+=1},o.prototype.writeFloat32=function(t,e){this._realloc(4),this._dataView.setFloat32(this.position,t,e??this.endianness),this.position+=4},o.prototype.writeFloat64=function(t,e){this._realloc(8),this._dataView.setFloat64(this.position,t,e??this.endianness),this.position+=8},o.prototype.writeUCS2String=function(t,e,r){r==null&&(r=t.length);for(var n=0;n<t.length&&n<r;n++)this.writeUint16(t.charCodeAt(n),e);for(;n<r;n++)this.writeUint16(0)},o.prototype.writeString=function(t,e,r){var n=0;if(e==null||e=="ASCII")if(r!=null){var a=Math.min(t.length,r);for(n=0;n<a;n++)this.writeUint8(t.charCodeAt(n));for(;n<r;n++)this.writeUint8(0)}else for(n=0;n<t.length;n++)this.writeUint8(t.charCodeAt(n));else this.writeUint8Array(new TextEncoder(e).encode(t.substring(0,r)))},o.prototype.writeCString=function(t,e){var r=0;if(e!=null){var n=Math.min(t.length,e);for(r=0;r<n;r++)this.writeUint8(t.charCodeAt(r));for(;r<e;r++)this.writeUint8(0)}else{for(r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));this.writeUint8(0)}},o.prototype.writeStruct=function(t,e){for(var r=0;r<t.length;r+=2){var n=t[r+1];this.writeType(n,e[t[r]],e)}},o.prototype.writeType=function(t,e,r){var n;if(typeof t=="function")return t(this,e);if(typeof t=="object"&&!(t instanceof Array))return t.set(this,e,r);var a=null,u="ASCII",p=this.position;switch(typeof t=="string"&&/:/.test(t)&&(n=t.split(":"),t=n[0],a=parseInt(n[1])),typeof t=="string"&&/,/.test(t)&&(n=t.split(","),t=n[0],u=parseInt(n[1])),t){case"uint8":this.writeUint8(e);break;case"int8":this.writeInt8(e);break;case"uint16":this.writeUint16(e,this.endianness);break;case"int16":this.writeInt16(e,this.endianness);break;case"uint32":this.writeUint32(e,this.endianness);break;case"int32":this.writeInt32(e,this.endianness);break;case"float32":this.writeFloat32(e,this.endianness);break;case"float64":this.writeFloat64(e,this.endianness);break;case"uint16be":this.writeUint16(e,o.BIG_ENDIAN);break;case"int16be":this.writeInt16(e,o.BIG_ENDIAN);break;case"uint32be":this.writeUint32(e,o.BIG_ENDIAN);break;case"int32be":this.writeInt32(e,o.BIG_ENDIAN);break;case"float32be":this.writeFloat32(e,o.BIG_ENDIAN);break;case"float64be":this.writeFloat64(e,o.BIG_ENDIAN);break;case"uint16le":this.writeUint16(e,o.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(e,o.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(e,o.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(e,o.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(e,o.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(e,o.LITTLE_ENDIAN);break;case"cstring":this.writeCString(e,a);break;case"string":this.writeString(e,u,a);break;case"u16string":this.writeUCS2String(e,this.endianness,a);break;case"u16stringle":this.writeUCS2String(e,o.LITTLE_ENDIAN,a);break;case"u16stringbe":this.writeUCS2String(e,o.BIG_ENDIAN,a);break;default:if(t.length==3){for(var _=t[1],U=0;U<e.length;U++)this.writeType(_,e[U]);break}else{this.writeStruct(t,e);break}}a!=null&&(this.position=p,this._realloc(a),this.position=p+a)},o.prototype.writeUint64=function(t){var e=Math.floor(t/d);this.writeUint32(e),this.writeUint32(t&4294967295)},o.prototype.writeUint24=function(t){this.writeUint8((t&16711680)>>16),this.writeUint8((t&65280)>>8),this.writeUint8(t&255)},o.prototype.adjustUint32=function(t,e){var r=this.position;this.seek(t),this.writeUint32(e),this.seek(r)},o.prototype.mapInt32Array=function(t,e){this._realloc(t*4);var r=new Int32Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*4,r},o.prototype.mapInt16Array=function(t,e){this._realloc(t*2);var r=new Int16Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*2,r},o.prototype.mapInt8Array=function(t){this._realloc(t*1);var e=new Int8Array(this._buffer,this.byteOffset+this.position,t);return this.position+=t*1,e},o.prototype.mapUint32Array=function(t,e){this._realloc(t*4);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*4,r},o.prototype.mapUint16Array=function(t,e){this._realloc(t*2);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*2,r},o.prototype.mapFloat64Array=function(t,e){this._realloc(t*8);var r=new Float64Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*8,r},o.prototype.mapFloat32Array=function(t,e){this._realloc(t*4);var r=new Float32Array(this._buffer,this.byteOffset+this.position,t);return o.arrayToNative(r,e??this.endianness),this.position+=t*4,r};var l=function(t){this.buffers=[],this.bufferIndex=-1,t&&(this.insertBuffer(t),this.bufferIndex=0)};l.prototype=new o(new ArrayBuffer,0,o.BIG_ENDIAN),l.prototype.initialized=function(){var t;return this.bufferIndex>-1?!0:this.buffers.length>0?(t=this.buffers[0],t.fileStart===0?(this.buffer=t,this.bufferIndex=0,f.debug("MultiBufferStream","Stream ready for parsing"),!0):(f.warn("MultiBufferStream","The first buffer should have a fileStart of 0"),this.logBufferLevel(),!1)):(f.warn("MultiBufferStream","No buffer to start parsing from"),this.logBufferLevel(),!1)},ArrayBuffer.concat=function(t,e){f.debug("ArrayBuffer","Trying to create a new buffer of size: "+(t.byteLength+e.byteLength));var r=new Uint8Array(t.byteLength+e.byteLength);return r.set(new Uint8Array(t),0),r.set(new Uint8Array(e),t.byteLength),r.buffer},l.prototype.reduceBuffer=function(t,e,r){var n;return n=new Uint8Array(r),n.set(new Uint8Array(t,e,r)),n.buffer.fileStart=t.fileStart+e,n.buffer.usedBytes=0,n.buffer},l.prototype.insertBuffer=function(t){for(var e=!0,r=0;r<this.buffers.length;r++){var n=this.buffers[r];if(t.fileStart<=n.fileStart){if(t.fileStart===n.fileStart)if(t.byteLength>n.byteLength){this.buffers.splice(r,1),r--;continue}else f.warn("MultiBufferStream","Buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+") already appended, ignoring");else t.fileStart+t.byteLength<=n.fileStart||(t=this.reduceBuffer(t,0,n.fileStart-t.fileStart)),f.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.splice(r,0,t),r===0&&(this.buffer=t);e=!1;break}else if(t.fileStart<n.fileStart+n.byteLength){var a=n.fileStart+n.byteLength-t.fileStart,u=t.byteLength-a;if(u>0)t=this.reduceBuffer(t,a,u);else{e=!1;break}}}e&&(f.debug("MultiBufferStream","Appending new buffer (fileStart: "+t.fileStart+" - Length: "+t.byteLength+")"),this.buffers.push(t),r===0&&(this.buffer=t))},l.prototype.logBufferLevel=function(t){var e,r,n,a,u=[],p,_="";for(n=0,a=0,e=0;e<this.buffers.length;e++)r=this.buffers[e],e===0?(p={},u.push(p),p.start=r.fileStart,p.end=r.fileStart+r.byteLength,_+="["+p.start+"-"):p.end===r.fileStart?p.end=r.fileStart+r.byteLength:(p={},p.start=r.fileStart,_+=u[u.length-1].end-1+"], ["+p.start+"-",p.end=r.fileStart+r.byteLength,u.push(p)),n+=r.usedBytes,a+=r.byteLength;u.length>0&&(_+=p.end-1+"]");var U=t?f.info:f.debug;this.buffers.length===0?U("MultiBufferStream","No more buffer in memory"):U("MultiBufferStream",""+this.buffers.length+" stored buffer(s) ("+n+"/"+a+" bytes), continuous ranges: "+_)},l.prototype.cleanBuffers=function(){var t,e;for(t=0;t<this.buffers.length;t++)e=this.buffers[t],e.usedBytes===e.byteLength&&(f.debug("MultiBufferStream","Removing buffer #"+t),this.buffers.splice(t,1),t--)},l.prototype.mergeNextBuffer=function(){var t;if(this.bufferIndex+1<this.buffers.length)if(t=this.buffers[this.bufferIndex+1],t.fileStart===this.buffer.fileStart+this.buffer.byteLength){var e=this.buffer.byteLength,r=this.buffer.usedBytes,n=this.buffer.fileStart;return this.buffers[this.bufferIndex]=ArrayBuffer.concat(this.buffer,t),this.buffer=this.buffers[this.bufferIndex],this.buffers.splice(this.bufferIndex+1,1),this.buffer.usedBytes=r,this.buffer.fileStart=n,f.debug("ISOFile","Concatenating buffer for box parsing (length: "+e+"->"+this.buffer.byteLength+")"),!0}else return!1;else return!1},l.prototype.findPosition=function(t,e,r){var n,a=null,u=-1;for(t===!0?n=0:n=this.bufferIndex;n<this.buffers.length&&(a=this.buffers[n],a.fileStart<=e);){u=n,r&&(a.fileStart+a.byteLength<=e?a.usedBytes=a.byteLength:a.usedBytes=e-a.fileStart,this.logBufferLevel());n++}return u!==-1?(a=this.buffers[u],a.fileStart+a.byteLength>=e?(f.debug("MultiBufferStream","Found position in existing buffer #"+u),u):-1):-1},l.prototype.findEndContiguousBuf=function(t){var e,r,n,a=t!==void 0?t:this.bufferIndex;if(r=this.buffers[a],this.buffers.length>a+1)for(e=a+1;e<this.buffers.length&&(n=this.buffers[e],n.fileStart===r.fileStart+r.byteLength);e++)r=n;return r.fileStart+r.byteLength},l.prototype.getEndFilePositionAfter=function(t){var e=this.findPosition(!0,t,!1);return e!==-1?this.findEndContiguousBuf(e):t},l.prototype.addUsedBytes=function(t){this.buffer.usedBytes+=t,this.logBufferLevel()},l.prototype.setAllUsedBytes=function(){this.buffer.usedBytes=this.buffer.byteLength,this.logBufferLevel()},l.prototype.seek=function(t,e,r){var n;return n=this.findPosition(e,t,r),n!==-1?(this.buffer=this.buffers[n],this.bufferIndex=n,this.position=t-this.buffer.fileStart,f.debug("MultiBufferStream","Repositioning parser at buffer position: "+this.position),!0):(f.debug("MultiBufferStream","Position "+t+" not found in buffered data"),!1)},l.prototype.getPosition=function(){if(this.bufferIndex===-1||this.buffers[this.bufferIndex]===null)throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.position},l.prototype.getLength=function(){return this.byteLength},l.prototype.getEndPosition=function(){if(this.bufferIndex===-1||this.buffers[this.bufferIndex]===null)throw"Error accessing position in the MultiBufferStream";return this.buffers[this.bufferIndex].fileStart+this.byteLength},C.MultiBufferStream=l;var c=function(){var t=3,e=4,r=5,n=6,a=[];a[t]="ES_Descriptor",a[e]="DecoderConfigDescriptor",a[r]="DecoderSpecificInfo",a[n]="SLConfigDescriptor",this.getDescriptorName=function(_){return a[_]};var u=this,p={};return this.parseOneDescriptor=function(_){var U=0,S,b,E;for(S=_.readUint8(),E=_.readUint8();E&128;)U=(U<<7)+(E&127),E=_.readUint8();return U=(U<<7)+(E&127),f.debug("MPEG4DescriptorParser","Found "+(a[S]||"Descriptor "+S)+", size "+U+" at position "+_.getPosition()),a[S]?b=new p[a[S]](U):b=new p.Descriptor(U),b.parse(_),b},p.Descriptor=function(_,U){this.tag=_,this.size=U,this.descs=[]},p.Descriptor.prototype.parse=function(_){this.data=_.readUint8Array(this.size)},p.Descriptor.prototype.findDescriptor=function(_){for(var U=0;U<this.descs.length;U++)if(this.descs[U].tag==_)return this.descs[U];return null},p.Descriptor.prototype.parseRemainingDescriptors=function(_){for(var U=_.position;_.position<U+this.size;){var S=u.parseOneDescriptor(_);this.descs.push(S)}},p.ES_Descriptor=function(_){p.Descriptor.call(this,t,_)},p.ES_Descriptor.prototype=new p.Descriptor,p.ES_Descriptor.prototype.parse=function(_){if(this.ES_ID=_.readUint16(),this.flags=_.readUint8(),this.size-=3,this.flags&128?(this.dependsOn_ES_ID=_.readUint16(),this.size-=2):this.dependsOn_ES_ID=0,this.flags&64){var U=_.readUint8();this.URL=_.readString(U),this.size-=U+1}else this.URL="";this.flags&32?(this.OCR_ES_ID=_.readUint16(),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(_)},p.ES_Descriptor.prototype.getOTI=function(_){var U=this.findDescriptor(e);return U?U.oti:0},p.ES_Descriptor.prototype.getAudioConfig=function(_){var U=this.findDescriptor(e);if(!U)return null;var S=U.findDescriptor(r);if(S&&S.data){var b=(S.data[0]&248)>>3;return b===31&&S.data.length>=2&&(b=32+((S.data[0]&7)<<3)+((S.data[1]&224)>>5)),b}else return null},p.DecoderConfigDescriptor=function(_){p.Descriptor.call(this,e,_)},p.DecoderConfigDescriptor.prototype=new p.Descriptor,p.DecoderConfigDescriptor.prototype.parse=function(_){this.oti=_.readUint8(),this.streamType=_.readUint8(),this.upStream=(this.streamType>>1&1)!==0,this.streamType=this.streamType>>>2,this.bufferSize=_.readUint24(),this.maxBitrate=_.readUint32(),this.avgBitrate=_.readUint32(),this.size-=13,this.parseRemainingDescriptors(_)},p.DecoderSpecificInfo=function(_){p.Descriptor.call(this,r,_)},p.DecoderSpecificInfo.prototype=new p.Descriptor,p.SLConfigDescriptor=function(_){p.Descriptor.call(this,n,_)},p.SLConfigDescriptor.prototype=new p.Descriptor,this};C.MPEG4DescriptorParser=c;var s={ERR_INVALID_DATA:-1,ERR_NOT_ENOUGH_DATA:0,OK:1,BASIC_BOXES:["mdat","idat","free","skip","meco","strk"],FULL_BOXES:["hmhd","nmhd","iods","xml ","bxml","ipro","mere"],CONTAINER_BOXES:[["moov",["trak","pssh"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl",["sgpd","sbgp"]],["mvex",["trex"]],["moof",["traf"]],["traf",["trun","sgpd","sbgp"]],["vttc"],["tref"],["iref"],["mfra",["tfra"]],["meco"],["hnti"],["hinf"],["strk"],["strd"],["sinf"],["rinf"],["schi"],["trgr"],["udta",["kind"]],["iprp",["ipma"]],["ipco"],["grpl"],["j2kH"],["etyp",["tyco"]]],boxCodes:[],fullBoxCodes:[],containerBoxCodes:[],sampleEntryCodes:{},sampleGroupEntryCodes:[],trackGroupTypes:[],UUIDBoxes:{},UUIDs:[],initialize:function(){s.FullBox.prototype=new s.Box,s.ContainerBox.prototype=new s.Box,s.SampleEntry.prototype=new s.Box,s.TrackGroupTypeBox.prototype=new s.FullBox,s.BASIC_BOXES.forEach(function(t){s.createBoxCtor(t)}),s.FULL_BOXES.forEach(function(t){s.createFullBoxCtor(t)}),s.CONTAINER_BOXES.forEach(function(t){s.createContainerBoxCtor(t[0],null,t[1])})},Box:function(t,e,r){this.type=t,this.size=e,this.uuid=r},FullBox:function(t,e,r){s.Box.call(this,t,e,r),this.flags=0,this.version=0},ContainerBox:function(t,e,r){s.Box.call(this,t,e,r),this.boxes=[]},SampleEntry:function(t,e,r,n){s.ContainerBox.call(this,t,e),this.hdr_size=r,this.start=n},SampleGroupEntry:function(t){this.grouping_type=t},TrackGroupTypeBox:function(t,e){s.FullBox.call(this,t,e)},createBoxCtor:function(t,e){s.boxCodes.push(t),s[t+"Box"]=function(r){s.Box.call(this,t,r)},s[t+"Box"].prototype=new s.Box,e&&(s[t+"Box"].prototype.parse=e)},createFullBoxCtor:function(t,e){s[t+"Box"]=function(r){s.FullBox.call(this,t,r)},s[t+"Box"].prototype=new s.FullBox,s[t+"Box"].prototype.parse=function(r){this.parseFullHeader(r),e&&e.call(this,r)}},addSubBoxArrays:function(t){if(t){this.subBoxNames=t;for(var e=t.length,r=0;r<e;r++)this[t[r]+"s"]=[]}},createContainerBoxCtor:function(t,e,r){s[t+"Box"]=function(n){s.ContainerBox.call(this,t,n),s.addSubBoxArrays.call(this,r)},s[t+"Box"].prototype=new s.ContainerBox,e&&(s[t+"Box"].prototype.parse=e)},createMediaSampleEntryCtor:function(t,e,r){s.sampleEntryCodes[t]=[],s[t+"SampleEntry"]=function(n,a){s.SampleEntry.call(this,n,a),s.addSubBoxArrays.call(this,r)},s[t+"SampleEntry"].prototype=new s.SampleEntry,e&&(s[t+"SampleEntry"].prototype.parse=e)},createSampleEntryCtor:function(t,e,r,n){s.sampleEntryCodes[t].push(e),s[e+"SampleEntry"]=function(a){s[t+"SampleEntry"].call(this,e,a),s.addSubBoxArrays.call(this,n)},s[e+"SampleEntry"].prototype=new s[t+"SampleEntry"],r&&(s[e+"SampleEntry"].prototype.parse=r)},createEncryptedSampleEntryCtor:function(t,e,r){s.createSampleEntryCtor.call(this,t,e,r,["sinf"])},createSampleGroupCtor:function(t,e){s[t+"SampleGroupEntry"]=function(r){s.SampleGroupEntry.call(this,t,r)},s[t+"SampleGroupEntry"].prototype=new s.SampleGroupEntry,e&&(s[t+"SampleGroupEntry"].prototype.parse=e)},createTrackGroupCtor:function(t,e){s[t+"TrackGroupTypeBox"]=function(r){s.TrackGroupTypeBox.call(this,t,r)},s[t+"TrackGroupTypeBox"].prototype=new s.TrackGroupTypeBox,e&&(s[t+"TrackGroupTypeBox"].prototype.parse=e)},createUUIDBox:function(t,e,r,n){s.UUIDs.push(t),s.UUIDBoxes[t]=function(a){e?s.FullBox.call(this,"uuid",a,t):r?s.ContainerBox.call(this,"uuid",a,t):s.Box.call(this,"uuid",a,t)},s.UUIDBoxes[t].prototype=e?new s.FullBox:r?new s.ContainerBox:new s.Box,n&&(e?s.UUIDBoxes[t].prototype.parse=function(a){this.parseFullHeader(a),n&&n.call(this,a)}:s.UUIDBoxes[t].prototype.parse=n)}};s.initialize(),s.TKHD_FLAG_ENABLED=1,s.TKHD_FLAG_IN_MOVIE=2,s.TKHD_FLAG_IN_PREVIEW=4,s.TFHD_FLAG_BASE_DATA_OFFSET=1,s.TFHD_FLAG_SAMPLE_DESC=2,s.TFHD_FLAG_SAMPLE_DUR=8,s.TFHD_FLAG_SAMPLE_SIZE=16,s.TFHD_FLAG_SAMPLE_FLAGS=32,s.TFHD_FLAG_DUR_EMPTY=65536,s.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072,s.TRUN_FLAGS_DATA_OFFSET=1,s.TRUN_FLAGS_FIRST_FLAG=4,s.TRUN_FLAGS_DURATION=256,s.TRUN_FLAGS_SIZE=512,s.TRUN_FLAGS_FLAGS=1024,s.TRUN_FLAGS_CTS_OFFSET=2048,s.Box.prototype.add=function(t){return this.addBox(new s[t+"Box"])},s.Box.prototype.addBox=function(t){return this.boxes.push(t),this[t.type+"s"]?this[t.type+"s"].push(t):this[t.type]=t,t},s.Box.prototype.set=function(t,e){return this[t]=e,this},s.Box.prototype.addEntry=function(t,e){var r=e||"entries";return this[r]||(this[r]=[]),this[r].push(t),this},C.BoxParser=s,s.parseUUID=function(t){return s.parseHex16(t)},s.parseHex16=function(t){for(var e="",r=0;r<16;r++){var n=t.readUint8().toString(16);e+=n.length===1?"0"+n:n}return e},s.parseOneBox=function(t,e,r){var n,a=t.getPosition(),u=0,p,_;if(t.getEndPosition()-a<8)return f.debug("BoxParser","Not enough data in stream to parse the type and size of the box"),{code:s.ERR_NOT_ENOUGH_DATA};if(r&&r<8)return f.debug("BoxParser","Not enough bytes left in the parent box to parse a new box"),{code:s.ERR_NOT_ENOUGH_DATA};var U=t.readUint32(),S=t.readString(4),b=S;if(f.debug("BoxParser","Found box of type '"+S+"' and size "+U+" at position "+a),u=8,S=="uuid"){if(t.getEndPosition()-t.getPosition()<16||r-u<16)return t.seek(a),f.debug("BoxParser","Not enough bytes left in the parent box to parse a UUID box"),{code:s.ERR_NOT_ENOUGH_DATA};_=s.parseUUID(t),u+=16,b=_}if(U==1){if(t.getEndPosition()-t.getPosition()<8||r&&r-u<8)return t.seek(a),f.warn("BoxParser",'Not enough data in stream to parse the extended size of the "'+S+'" box'),{code:s.ERR_NOT_ENOUGH_DATA};U=t.readUint64(),u+=8}else if(U===0){if(r)U=r;else if(S!=="mdat")return f.error("BoxParser","Unlimited box size not supported for type: '"+S+"'"),n=new s.Box(S,U),{code:s.OK,box:n,size:n.size}}return U!==0&&U<u?(f.error("BoxParser","Box of type "+S+" has an invalid size "+U+" (too small to be a box)"),{code:s.ERR_NOT_ENOUGH_DATA,type:S,size:U,hdr_size:u,start:a}):U!==0&&r&&U>r?(f.error("BoxParser","Box of type '"+S+"' has a size "+U+" greater than its container size "+r),{code:s.ERR_NOT_ENOUGH_DATA,type:S,size:U,hdr_size:u,start:a}):U!==0&&a+U>t.getEndPosition()?(t.seek(a),f.info("BoxParser","Not enough data in stream to parse the entire '"+S+"' box"),{code:s.ERR_NOT_ENOUGH_DATA,type:S,size:U,hdr_size:u,start:a}):e?{code:s.OK,type:S,size:U,hdr_size:u,start:a}:(s[S+"Box"]?n=new s[S+"Box"](U):S!=="uuid"?(f.warn("BoxParser","Unknown box type: '"+S+"'"),n=new s.Box(S,U),n.has_unparsed_data=!0):s.UUIDBoxes[_]?n=new s.UUIDBoxes[_](U):(f.warn("BoxParser","Unknown uuid type: '"+_+"'"),n=new s.Box(S,U),n.uuid=_,n.has_unparsed_data=!0),n.hdr_size=u,n.start=a,n.write===s.Box.prototype.write&&n.type!=="mdat"&&(f.info("BoxParser","'"+b+"' box writing not yet implemented, keeping unparsed data in memory for later write"),n.parseDataAndRewind(t)),n.parse(t),p=t.getPosition()-(n.start+n.size),p<0?(f.warn("BoxParser","Parsing of box '"+b+"' did not read the entire indicated box data size (missing "+-p+" bytes), seeking forward"),t.seek(n.start+n.size)):p>0&&(f.error("BoxParser","Parsing of box '"+b+"' read "+p+" more bytes than the indicated box data size, seeking backwards"),n.size!==0&&t.seek(n.start+n.size)),{code:s.OK,box:n,size:n.size})},s.Box.prototype.parse=function(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)},s.Box.prototype.parseDataAndRewind=function(t){this.data=t.readUint8Array(this.size-this.hdr_size),t.position-=this.size-this.hdr_size},s.FullBox.prototype.parseDataAndRewind=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=4,t.position-=this.size-this.hdr_size},s.FullBox.prototype.parseFullHeader=function(t){this.version=t.readUint8(),this.flags=t.readUint24(),this.hdr_size+=4},s.FullBox.prototype.parse=function(t){this.parseFullHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},s.ContainerBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;)if(e=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),e.code===s.OK)if(r=e.box,this.boxes.push(r),this.subBoxNames&&this.subBoxNames.indexOf(r.type)!=-1)this[this.subBoxNames[this.subBoxNames.indexOf(r.type)]+"s"].push(r);else{var n=r.type!=="uuid"?r.type:r.uuid;this[n]?f.warn("Box of type "+n+" already stored in field of this type"):this[n]=r}else return},s.Box.prototype.parseLanguage=function(t){this.language=t.readUint16();var e=[];e[0]=this.language>>10&31,e[1]=this.language>>5&31,e[2]=this.language&31,this.languageString=String.fromCharCode(e[0]+96,e[1]+96,e[2]+96)},s.SAMPLE_ENTRY_TYPE_VISUAL="Visual",s.SAMPLE_ENTRY_TYPE_AUDIO="Audio",s.SAMPLE_ENTRY_TYPE_HINT="Hint",s.SAMPLE_ENTRY_TYPE_METADATA="Metadata",s.SAMPLE_ENTRY_TYPE_SUBTITLE="Subtitle",s.SAMPLE_ENTRY_TYPE_SYSTEM="System",s.SAMPLE_ENTRY_TYPE_TEXT="Text",s.SampleEntry.prototype.parseHeader=function(t){t.readUint8Array(6),this.data_reference_index=t.readUint16(),this.hdr_size+=8},s.SampleEntry.prototype.parse=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size)},s.SampleEntry.prototype.parseDataAndRewind=function(t){this.parseHeader(t),this.data=t.readUint8Array(this.size-this.hdr_size),this.hdr_size-=8,t.position-=this.size-this.hdr_size},s.SampleEntry.prototype.parseFooter=function(t){s.ContainerBox.prototype.parse.call(this,t)},s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_HINT),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SYSTEM),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_TEXT),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,function(t){var e;this.parseHeader(t),t.readUint16(),t.readUint16(),t.readUint32Array(3),this.width=t.readUint16(),this.height=t.readUint16(),this.horizresolution=t.readUint32(),this.vertresolution=t.readUint32(),t.readUint32(),this.frame_count=t.readUint16(),e=Math.min(31,t.readUint8()),this.compressorname=t.readString(e),e<31&&t.readString(31-e),this.depth=t.readUint16(),t.readUint16(),this.parseFooter(t)}),s.createMediaSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,function(t){this.parseHeader(t),t.readUint32Array(2),this.channel_count=t.readUint16(),this.samplesize=t.readUint16(),t.readUint16(),t.readUint16(),this.samplerate=t.readUint32()/65536,this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avc4"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"av01"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"dav1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"hvc1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"hev1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"hvt1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"lhe1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"dvh1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"dvhe"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvc1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvi1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvs1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vvcN"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vp08"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"vp09"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"avs3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"j2ki"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"mjp2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"mjpg"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"uncv"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mp4a"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"ac-3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"ac-4"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"ec-3"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"Opus"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mha1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mha2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mhm1"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"mhm2"),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"fLaC"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_VISUAL,"encv"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_AUDIO,"enca"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"encu"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SYSTEM,"encs"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_TEXT,"enct"),s.createEncryptedSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"encm"),s.createBoxCtor("a1lx",function(t){var e=t.readUint8()&1,r=((e&1)+1)*16;this.layer_size=[];for(var n=0;n<3;n++)r==16?this.layer_size[n]=t.readUint16():this.layer_size[n]=t.readUint32()}),s.createBoxCtor("a1op",function(t){this.op_index=t.readUint8()}),s.createFullBoxCtor("auxC",function(t){this.aux_type=t.readCString();var e=this.size-this.hdr_size-(this.aux_type.length+1);this.aux_subtype=t.readUint8Array(e)}),s.createBoxCtor("av1C",function(t){var e=t.readUint8();if(e>>7&!1){f.error("av1C marker problem");return}if(this.version=e&127,this.version!==1){f.error("av1C version "+this.version+" not supported");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){f.error("av1C reserved_1 parsing problem");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){f.error("av1C reserved_2 parsing problem");return}var r=this.size-this.hdr_size-4;this.configOBUs=t.readUint8Array(r)}),s.createBoxCtor("avcC",function(t){var e,r;for(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,r=this.size-this.hdr_size-6,this.SPS=[],e=0;e<this.nb_SPS_nalus;e++)this.SPS[e]={},this.SPS[e].length=t.readUint16(),this.SPS[e].nalu=t.readUint8Array(this.SPS[e].length),r-=2+this.SPS[e].length;for(this.nb_PPS_nalus=t.readUint8(),r--,this.PPS=[],e=0;e<this.nb_PPS_nalus;e++)this.PPS[e]={},this.PPS[e].length=t.readUint16(),this.PPS[e].nalu=t.readUint8Array(this.PPS[e].length),r-=2+this.PPS[e].length;r>0&&(this.ext=t.readUint8Array(r))}),s.createBoxCtor("btrt",function(t){this.bufferSizeDB=t.readUint32(),this.maxBitrate=t.readUint32(),this.avgBitrate=t.readUint32()}),s.createFullBoxCtor("ccst",function(t){var 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()}),s.createBoxCtor("cdef",function(t){var e;for(this.channel_count=t.readUint16(),this.channel_indexes=[],this.channel_types=[],this.channel_associations=[],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())}),s.createBoxCtor("clap",function(t){this.cleanApertureWidthN=t.readUint32(),this.cleanApertureWidthD=t.readUint32(),this.cleanApertureHeightN=t.readUint32(),this.cleanApertureHeightD=t.readUint32(),this.horizOffN=t.readUint32(),this.horizOffD=t.readUint32(),this.vertOffN=t.readUint32(),this.vertOffD=t.readUint32()}),s.createBoxCtor("clli",function(t){this.max_content_light_level=t.readUint16(),this.max_pic_average_light_level=t.readUint16()}),s.createFullBoxCtor("cmex",function(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==1),this.flags&32&&(this.id=t.readUint32())}),s.createFullBoxCtor("cmin",function(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())}),s.createBoxCtor("cmpd",function(t){for(this.component_count=t.readUint32(),this.component_types=[],this.component_type_urls=[],i=0;i<this.component_count;i++){var e=t.readUint16();this.component_types.push(e),e>=32768&&this.component_type_urls.push(t.readCString())}}),s.createFullBoxCtor("co64",function(t){var e,r;if(e=t.readUint32(),this.chunk_offsets=[],this.version===0)for(r=0;r<e;r++)this.chunk_offsets.push(t.readUint64())}),s.createFullBoxCtor("CoLL",function(t){this.maxCLL=t.readUint16(),this.maxFALL=t.readUint16()}),s.createBoxCtor("colr",function(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();var 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))}),s.createFullBoxCtor("cprt",function(t){this.parseLanguage(t),this.notice=t.readCString()}),s.createFullBoxCtor("cslg",function(t){this.version===0&&(this.compositionToDTSShift=t.readInt32(),this.leastDecodeToDisplayDelta=t.readInt32(),this.greatestDecodeToDisplayDelta=t.readInt32(),this.compositionStartTime=t.readInt32(),this.compositionEndTime=t.readInt32())}),s.createFullBoxCtor("ctts",function(t){var e,r;if(e=t.readUint32(),this.sample_counts=[],this.sample_offsets=[],this.version===0)for(r=0;r<e;r++){this.sample_counts.push(t.readUint32());var n=t.readInt32();n<0&&f.warn("BoxParser","ctts box uses negative values without using version 1"),this.sample_offsets.push(n)}else if(this.version==1)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),this.sample_offsets.push(t.readInt32())}),s.createBoxCtor("dac3",function(t){var e=t.readUint8(),r=t.readUint8(),n=t.readUint8();this.fscod=e>>6,this.bsid=e>>1&31,this.bsmod=(e&1)<<2|r>>6&3,this.acmod=r>>3&7,this.lfeon=r>>2&1,this.bit_rate_code=r&3|n>>5&7}),s.createBoxCtor("dec3",function(t){var e=t.readUint16();this.data_rate=e>>3,this.num_ind_sub=e&7,this.ind_subs=[];for(var r=0;r<this.num_ind_sub+1;r++){var n={};this.ind_subs.push(n);var a=t.readUint8(),u=t.readUint8(),p=t.readUint8();n.fscod=a>>6,n.bsid=a>>1&31,n.bsmod=(a&1)<<4|u>>4&15,n.acmod=u>>1&7,n.lfeon=u&1,n.num_dep_sub=p>>1&15,n.num_dep_sub>0&&(n.chan_loc=(p&1)<<8|t.readUint8())}}),s.createFullBoxCtor("dfLa",function(t){var e=127,r=128,n=[],a=["STREAMINFO","PADDING","APPLICATION","SEEKTABLE","VORBIS_COMMENT","CUESHEET","PICTURE","RESERVED"];do{var u=t.readUint8(),p=Math.min(u&e,a.length-1);if(p?t.readUint8Array(t.readUint24()):(t.readUint8Array(13),this.samplerate=t.readUint32()>>12,t.readUint8Array(20)),n.push(a[p]),u&r)break}while(!0);this.numMetadataBlocks=n.length+" ("+n.join(", ")+")"}),s.createBoxCtor("dimm",function(t){this.bytessent=t.readUint64()}),s.createBoxCtor("dmax",function(t){this.time=t.readUint32()}),s.createBoxCtor("dmed",function(t){this.bytessent=t.readUint64()}),s.createBoxCtor("dOps",function(t){if(this.Version=t.readUint8(),this.OutputChannelCount=t.readUint8(),this.PreSkip=t.readUint16(),this.InputSampleRate=t.readUint32(),this.OutputGain=t.readInt16(),this.ChannelMappingFamily=t.readUint8(),this.ChannelMappingFamily!==0){this.StreamCount=t.readUint8(),this.CoupledCount=t.readUint8(),this.ChannelMapping=[];for(var e=0;e<this.OutputChannelCount;e++)this.ChannelMapping[e]=t.readUint8()}}),s.createFullBoxCtor("dref",function(t){var e,r;this.entries=[];for(var n=t.readUint32(),a=0;a<n;a++)if(e=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),e.code===s.OK)r=e.box,this.entries.push(r);else return}),s.createBoxCtor("drep",function(t){this.bytessent=t.readUint64()}),s.createFullBoxCtor("elng",function(t){this.extended_language=t.readString(this.size-this.hdr_size)}),s.createFullBoxCtor("elst",function(t){this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.entries.push(n),this.version===1?(n.segment_duration=t.readUint64(),n.media_time=t.readInt64()):(n.segment_duration=t.readUint32(),n.media_time=t.readInt32()),n.media_rate_integer=t.readInt16(),n.media_rate_fraction=t.readInt16()}}),s.createFullBoxCtor("emsg",function(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());var e=this.size-this.hdr_size-(4*4+(this.scheme_id_uri.length+1)+(this.value.length+1));this.version==1&&(e-=4),this.message_data=t.readUint8Array(e)}),s.createEntityToGroupCtor=function(t,e){s[t+"Box"]=function(r){s.FullBox.call(this,t,r)},s[t+"Box"].prototype=new s.FullBox,s[t+"Box"].prototype.parse=function(r){if(this.parseFullHeader(r),e)e.call(this,r);else for(this.group_id=r.readUint32(),this.num_entities_in_group=r.readUint32(),this.entity_ids=[],i=0;i<this.num_entities_in_group;i++){var n=r.readUint32();this.entity_ids.push(n)}}},s.createEntityToGroupCtor("aebr"),s.createEntityToGroupCtor("afbr"),s.createEntityToGroupCtor("albc"),s.createEntityToGroupCtor("altr"),s.createEntityToGroupCtor("brst"),s.createEntityToGroupCtor("dobr"),s.createEntityToGroupCtor("eqiv"),s.createEntityToGroupCtor("favc"),s.createEntityToGroupCtor("fobr"),s.createEntityToGroupCtor("iaug"),s.createEntityToGroupCtor("pano"),s.createEntityToGroupCtor("slid"),s.createEntityToGroupCtor("ster"),s.createEntityToGroupCtor("tsyn"),s.createEntityToGroupCtor("wbbr"),s.createEntityToGroupCtor("prgr"),s.createEntityToGroupCtor("pymd",function(t){this.group_id=t.readUint32(),this.num_entities_in_group=t.readUint32(),this.entity_ids=[];for(var e=0;e<this.num_entities_in_group;e++){var r=t.readUint32();this.entity_ids.push(r)}for(this.tile_size_x=t.readUint16(),this.tile_size_y=t.readUint16(),this.layer_binning=[],this.tiles_in_layer_column_minus1=[],this.tiles_in_layer_row_minus1=[],e=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.createFullBoxCtor("esds",function(t){var e=t.readUint8Array(this.size-this.hdr_size);if(typeof c<"u"){var r=new c;this.esd=r.parseOneDescriptor(new o(e.buffer,0,o.BIG_ENDIAN))}}),s.createBoxCtor("fiel",function(t){this.fieldCount=t.readUint8(),this.fieldOrdering=t.readUint8()}),s.createBoxCtor("frma",function(t){this.data_format=t.readString(4)}),s.createBoxCtor("ftyp",function(t){var e=this.size-this.hdr_size;this.major_brand=t.readString(4),this.minor_version=t.readUint32(),e-=8,this.compatible_brands=[];for(var r=0;e>=4;)this.compatible_brands[r]=t.readString(4),e-=4,r++}),s.createFullBoxCtor("hdlr",function(t){this.version===0&&(t.readUint32(),this.handler=t.readString(4),t.readUint32Array(3),this.name=t.readString(this.size-this.hdr_size-20),this.name[this.name.length-1]==="\\0"&&(this.name=this.name.slice(0,-1)))}),s.createBoxCtor("hvcC",function(t){var e,r,n,a;this.configurationVersion=t.readUint8(),a=t.readUint8(),this.general_profile_space=a>>6,this.general_tier_flag=(a&32)>>5,this.general_profile_idc=a&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(),a=t.readUint8(),this.constantFrameRate=a>>6,this.numTemporalLayers=(a&13)>>3,this.temporalIdNested=(a&4)>>2,this.lengthSizeMinusOne=a&3,this.nalu_arrays=[];var u=t.readUint8();for(e=0;e<u;e++){var p=[];this.nalu_arrays.push(p),a=t.readUint8(),p.completeness=(a&128)>>7,p.nalu_type=a&63;var _=t.readUint16();for(r=0;r<_;r++){var U={};p.push(U),n=t.readUint16(),U.data=t.readUint8Array(n)}}}),s.createFullBoxCtor("iinf",function(t){var e;this.version===0?this.entry_count=t.readUint16():this.entry_count=t.readUint32(),this.item_infos=[];for(var r=0;r<this.entry_count;r++)if(e=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),e.code===s.OK)e.box.type!=="infe"&&f.error("BoxParser","Expected 'infe' box, got "+e.box.type),this.item_infos[r]=e.box;else return}),s.createFullBoxCtor("iloc",function(t){var 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=[];var r=0;if(this.version<2)r=t.readUint16();else if(this.version===2)r=t.readUint32();else throw"version of iloc box not supported";for(var n=0;n<r;n++){var a={};if(this.items.push(a),this.version<2)a.item_ID=t.readUint16();else if(this.version===2)a.item_ID=t.readUint32();else throw"version of iloc box not supported";switch(this.version===1||this.version===2?a.construction_method=t.readUint16()&15:a.construction_method=0,a.data_reference_index=t.readUint16(),this.base_offset_size){case 0:a.base_offset=0;break;case 4:a.base_offset=t.readUint32();break;case 8:a.base_offset=t.readUint64();break;default:throw"Error reading base offset size"}var u=t.readUint16();a.extents=[];for(var p=0;p<u;p++){var _={};if(a.extents.push(_),this.version===1||this.version===2)switch(this.index_size){case 0:_.extent_index=0;break;case 4:_.extent_index=t.readUint32();break;case 8:_.extent_index=t.readUint64();break;default:throw"Error reading extent index"}switch(this.offset_size){case 0:_.extent_offset=0;break;case 4:_.extent_offset=t.readUint32();break;case 8:_.extent_offset=t.readUint64();break;default:throw"Error reading extent index"}switch(this.length_size){case 0:_.extent_length=0;break;case 4:_.extent_length=t.readUint32();break;case 8:_.extent_length=t.readUint64();break;default:throw"Error reading extent index"}}}}),s.createBoxCtor("imir",function(t){var e=t.readUint8();this.reserved=e>>7,this.axis=e&1}),s.createFullBoxCtor("infe",function(t){if((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.content_encoding=t.readCString()),this.version===1){this.extension_type=t.readString(4),f.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()))}),s.createFullBoxCtor("ipma",function(t){var e,r;for(entry_count=t.readUint32(),this.associations=[],e=0;e<entry_count;e++){var n={};this.associations.push(n),this.version<1?n.id=t.readUint16():n.id=t.readUint32();var a=t.readUint8();for(n.props=[],r=0;r<a;r++){var u=t.readUint8(),p={};n.props.push(p),p.essential=(u&128)>>7===1,this.flags&1?p.property_index=(u&127)<<8|t.readUint8():p.property_index=u&127}}}),s.createFullBoxCtor("iref",function(t){var e,r;for(this.references=[];t.getPosition()<this.start+this.size;)if(e=s.parseOneBox(t,!0,this.size-(t.getPosition()-this.start)),e.code===s.OK)this.version===0?r=new s.SingleItemTypeReferenceBox(e.type,e.size,e.hdr_size,e.start):r=new s.SingleItemTypeReferenceBoxLarge(e.type,e.size,e.hdr_size,e.start),r.write===s.Box.prototype.write&&r.type!=="mdat"&&(f.warn("BoxParser",r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.references.push(r);else return}),s.createBoxCtor("irot",function(t){this.angle=t.readUint8()&3}),s.createFullBoxCtor("ispe",function(t){this.image_width=t.readUint32(),this.image_height=t.readUint32()}),s.createFullBoxCtor("kind",function(t){this.schemeURI=t.readCString(),this.value=t.readCString()}),s.createFullBoxCtor("leva",function(t){var e=t.readUint8();this.levels=[];for(var r=0;r<e;r++){var n={};this.levels[r]=n,n.track_ID=t.readUint32();var a=t.readUint8();switch(n.padding_flag=a>>7,n.assignment_type=a&127,n.assignment_type){case 0:n.grouping_type=t.readString(4);break;case 1:n.grouping_type=t.readString(4),n.grouping_type_parameter=t.readUint32();break;case 2:break;case 3:break;case 4:n.sub_track_id=t.readUint32();break;default:f.warn("BoxParser","Unknown leva assignement type")}}}),s.createBoxCtor("lhvC",function(t){var e,r,n;this.configurationVersion=t.readUint8(),this.min_spatial_segmentation_idc=t.readUint16()&4095,this.parallelismType=t.readUint8()&3,n=t.readUint8(),this.numTemporalLayers=(n&13)>>3,this.temporalIdNested=(n&4)>>2,this.lengthSizeMinusOne=n&3,this.nalu_arrays=[];var a=t.readUint8();for(e=0;e<a;e++){var u=[];this.nalu_arrays.push(u),n=t.readUint8(),u.completeness=(n&128)>>7,u.nalu_type=n&63;var p=t.readUint16();for(r=0;r<p;r++){var _={};u.push(_);var U=t.readUint16();_.data=t.readUint8Array(U)}}}),s.createBoxCtor("lsel",function(t){this.layer_id=t.readUint16()}),s.createBoxCtor("maxr",function(t){this.period=t.readUint32(),this.bytes=t.readUint32()});function g(t,e){this.x=t,this.y=e}g.prototype.toString=function(){return"("+this.x+","+this.y+")"},s.createBoxCtor("mdcv",function(t){this.display_primaries=[],this.display_primaries[0]=new g(t.readUint16(),t.readUint16()),this.display_primaries[1]=new g(t.readUint16(),t.readUint16()),this.display_primaries[2]=new g(t.readUint16(),t.readUint16()),this.white_point=new g(t.readUint16(),t.readUint16()),this.max_display_mastering_luminance=t.readUint32(),this.min_display_mastering_luminance=t.readUint32()}),s.createFullBoxCtor("mdhd",function(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()}),s.createFullBoxCtor("mehd",function(t){this.flags&1&&(f.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()}),s.createFullBoxCtor("meta",function(t){this.boxes=[],s.ContainerBox.prototype.parse.call(this,t)}),s.createFullBoxCtor("mfhd",function(t){this.sequence_number=t.readUint32()}),s.createFullBoxCtor("mfro",function(t){this._size=t.readUint32()}),s.createFullBoxCtor("mskC",function(t){this.bits_per_pixel=t.readUint8()}),s.createFullBoxCtor("mvhd",function(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.readUint32Array(9),t.readUint32Array(6),this.next_track_id=t.readUint32()}),s.createBoxCtor("npck",function(t){this.packetssent=t.readUint32()}),s.createBoxCtor("nump",function(t){this.packetssent=t.readUint64()}),s.createFullBoxCtor("padb",function(t){var e=t.readUint32();this.padbits=[];for(var r=0;r<Math.floor((e+1)/2);r++)this.padbits=t.readUint8()}),s.createBoxCtor("pasp",function(t){this.hSpacing=t.readUint32(),this.vSpacing=t.readUint32()}),s.createBoxCtor("payl",function(t){this.text=t.readString(this.size-this.hdr_size)}),s.createBoxCtor("payt",function(t){this.payloadID=t.readUint32();var e=t.readUint8();this.rtpmap_string=t.readString(e)}),s.createFullBoxCtor("pdin",function(t){var e=(this.size-this.hdr_size)/8;this.rate=[],this.initial_delay=[];for(var r=0;r<e;r++)this.rate[r]=t.readUint32(),this.initial_delay[r]=t.readUint32()}),s.createFullBoxCtor("pitm",function(t){this.version===0?this.item_id=t.readUint16():this.item_id=t.readUint32()}),s.createFullBoxCtor("pixi",function(t){var e;for(this.num_channels=t.readUint8(),this.bits_per_channels=[],e=0;e<this.num_channels;e++)this.bits_per_channels[e]=t.readUint8()}),s.createBoxCtor("pmax",function(t){this.bytes=t.readUint32()}),s.createFullBoxCtor("prdi",function(t){if(this.step_count=t.readUint16(),this.item_count=[],this.flags&2)for(var e=0;e<this.step_count;e++)this.item_count[e]=t.readUint16()}),s.createFullBoxCtor("prft",function(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()}),s.createFullBoxCtor("pssh",function(t){if(this.system_id=s.parseHex16(t),this.version>0){var e=t.readUint32();this.kid=[];for(var r=0;r<e;r++)this.kid[r]=s.parseHex16(t)}var n=t.readUint32();n>0&&(this.data=t.readUint8Array(n))}),s.createFullBoxCtor("clef",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),s.createFullBoxCtor("enof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),s.createFullBoxCtor("prof",function(t){this.width=t.readUint32(),this.height=t.readUint32()}),s.createContainerBoxCtor("tapt",null,["clef","prof","enof"]),s.createBoxCtor("rtp ",function(t){this.descriptionformat=t.readString(4),this.sdptext=t.readString(this.size-this.hdr_size-4)}),s.createFullBoxCtor("saio",function(t){this.flags&1&&(this.aux_info_type=t.readString(4),this.aux_info_type_parameter=t.readUint32());var e=t.readUint32();this.offset=[];for(var r=0;r<e;r++)this.version===0?this.offset[r]=t.readUint32():this.offset[r]=t.readUint64()}),s.createFullBoxCtor("saiz",function(t){if(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(var e=0;e<this.sample_count;e++)this.sample_info_size[e]=t.readUint8()}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"mett",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"metx",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"sbtt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"stpp",function(t){this.parseHeader(t),this.namespace=t.readCString(),this.schema_location=t.readCString(),this.auxiliary_mime_types=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"stxt",function(t){this.parseHeader(t),this.content_encoding=t.readCString(),this.mime_format=t.readCString(),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_SUBTITLE,"tx3g",function(t){this.parseHeader(t),this.displayFlags=t.readUint32(),this.horizontal_justification=t.readInt8(),this.vertical_justification=t.readInt8(),this.bg_color_rgba=t.readUint8Array(4),this.box_record=t.readInt16Array(4),this.style_record=t.readUint8Array(12),this.parseFooter(t)}),s.createSampleEntryCtor(s.SAMPLE_ENTRY_TYPE_METADATA,"wvtt",function(t){this.parseHeader(t),this.parseFooter(t)}),s.createSampleGroupCtor("alst",function(t){var e,r=t.readUint16();for(this.first_output_sample=t.readUint16(),this.sample_offset=[],e=0;e<r;e++)this.sample_offset[e]=t.readUint32();var n=this.description_length-4-4*r;for(this.num_output_samples=[],this.num_total_samples=[],e=0;e<n/4;e++)this.num_output_samples[e]=t.readUint16(),this.num_total_samples[e]=t.readUint16()}),s.createSampleGroupCtor("avll",function(t){this.layerNumber=t.readUint8(),this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()}),s.createSampleGroupCtor("avss",function(t){this.subSequenceIdentifier=t.readUint16(),this.layerNumber=t.readUint8();var e=t.readUint8();this.durationFlag=e>>7,this.avgRateFlag=e>>6&1,this.durationFlag&&(this.duration=t.readUint32()),this.avgRateFlag&&(this.accurateStatisticsFlag=t.readUint8(),this.avgBitRate=t.readUint16(),this.avgFrameRate=t.readUint16()),this.dependency=[];for(var r=t.readUint8(),n=0;n<r;n++){var a={};this.dependency.push(a),a.subSeqDirectionFlag=t.readUint8(),a.layerNumber=t.readUint8(),a.subSequenceIdentifier=t.readUint16()}}),s.createSampleGroupCtor("dtrt",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("mvif",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("prol",function(t){this.roll_distance=t.readInt16()}),s.createSampleGroupCtor("rap ",function(t){var e=t.readUint8();this.num_leading_samples_known=e>>7,this.num_leading_samples=e&127}),s.createSampleGroupCtor("rash",function(t){if(this.operation_point_count=t.readUint16(),this.description_length!==2+(this.operation_point_count===1?2:this.operation_point_count*6)+9)f.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(var e=0;e<this.operation_point_count;e++)this.available_bitrate[e]=t.readUint32(),this.target_rate_share[e]=t.readUint16()}this.maximum_bitrate=t.readUint32(),this.minimum_bitrate=t.readUint32(),this.discard_priority=t.readUint8()}}),s.createSampleGroupCtor("roll",function(t){this.roll_distance=t.readInt16()}),s.SampleGroupEntry.prototype.parse=function(t){f.warn("BoxParser","Unknown Sample Group type: "+this.grouping_type),this.data=t.readUint8Array(this.description_length)},s.createSampleGroupCtor("scif",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("scnm",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("seig",function(t){this.reserved=t.readUint8();var 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=s.parseHex16(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))}),s.createSampleGroupCtor("stsa",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("sync",function(t){var e=t.readUint8();this.NAL_unit_type=e&63}),s.createSampleGroupCtor("tele",function(t){var e=t.readUint8();this.level_independently_decodable=e>>7}),s.createSampleGroupCtor("tsas",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("tscl",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createSampleGroupCtor("vipr",function(t){f.warn("BoxParser","Sample Group type: "+this.grouping_type+" not fully parsed")}),s.createFullBoxCtor("sbgp",function(t){this.grouping_type=t.readString(4),this.version===1?this.grouping_type_parameter=t.readUint32():this.grouping_type_parameter=0,this.entries=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.entries.push(n),n.sample_count=t.readInt32(),n.group_description_index=t.readInt32()}});function v(t,e){this.bad_pixel_row=t,this.bad_pixel_column=e}v.prototype.toString=function(){return"[row: "+this.bad_pixel_row+", column: "+this.bad_pixel_column+"]"},s.createFullBoxCtor("sbpm",function(t){var e;for(this.component_count=t.readUint16(),this.component_index=[],e=0;e<this.component_count;e++)this.component_index.push(t.readUint16());var r=t.readUint8();for(this.correction_applied=(r&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=[],e=0;e<this.num_bad_rows;e++)this.bad_rows.push(t.readUint32());for(e=0;e<this.num_bad_cols;e++)this.bad_columns.push(t.readUint32());for(e=0;e<this.num_bad_pixels;e++){var n=t.readUint32(),a=t.readUint32();this.bad_pixels.push(new v(n,a))}}),s.createFullBoxCtor("schm",function(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))}),s.createBoxCtor("sdp ",function(t){this.sdptext=t.readString(this.size-this.hdr_size)}),s.createFullBoxCtor("sdtp",function(t){var e,r=this.size-this.hdr_size;this.is_leading=[],this.sample_depends_on=[],this.sample_is_depended_on=[],this.sample_has_redundancy=[];for(var n=0;n<r;n++)e=t.readUint8(),this.is_leading[n]=e>>6,this.sample_depends_on[n]=e>>4&3,this.sample_is_depended_on[n]=e>>2&3,this.sample_has_redundancy[n]=e&3}),s.createFullBoxCtor("senc"),s.createFullBoxCtor("sgpd",function(t){this.grouping_type=t.readString(4),f.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=[];for(var e=t.readUint32(),r=0;r<e;r++){var n;s[this.grouping_type+"SampleGroupEntry"]?n=new s[this.grouping_type+"SampleGroupEntry"](this.grouping_type):n=new s.SampleGroupEntry(this.grouping_type),this.entries.push(n),this.version===1?this.default_length===0?n.description_length=t.readUint32():n.description_length=this.default_length:n.description_length=this.default_length,n.write===s.SampleGroupEntry.prototype.write&&(f.info("BoxParser","SampleGroup for type "+this.grouping_type+" writing not yet implemented, keeping unparsed data in memory for later write"),n.data=t.readUint8Array(n.description_length),t.position-=n.description_length),n.parse(t)}}),s.createFullBoxCtor("sidx",function(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=[];for(var e=t.readUint16(),r=0;r<e;r++){var n={};this.references.push(n);var a=t.readUint32();n.reference_type=a>>31&1,n.referenced_size=a&2147483647,n.subsegment_duration=t.readUint32(),a=t.readUint32(),n.starts_with_SAP=a>>31&1,n.SAP_type=a>>28&7,n.SAP_delta_time=a&268435455}}),s.SingleItemTypeReferenceBox=function(t,e,r,n){s.Box.call(this,t,e),this.hdr_size=r,this.start=n},s.SingleItemTypeReferenceBox.prototype=new s.Box,s.SingleItemTypeReferenceBox.prototype.parse=function(t){this.from_item_ID=t.readUint16();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint16()},s.SingleItemTypeReferenceBoxLarge=function(t,e,r,n){s.Box.call(this,t,e),this.hdr_size=r,this.start=n},s.SingleItemTypeReferenceBoxLarge.prototype=new s.Box,s.SingleItemTypeReferenceBoxLarge.prototype.parse=function(t){this.from_item_ID=t.readUint32();var e=t.readUint16();this.references=[];for(var r=0;r<e;r++)this.references[r]={},this.references[r].to_item_ID=t.readUint32()},s.createFullBoxCtor("SmDm",function(t){this.primaryRChromaticity_x=t.readUint16(),this.primaryRChromaticity_y=t.readUint16(),this.primaryGChromaticity_x=t.readUint16(),this.primaryGChromaticity_y=t.readUint16(),this.primaryBChromaticity_x=t.readUint16(),this.primaryBChromaticity_y=t.readUint16(),this.whitePointChromaticity_x=t.readUint16(),this.whitePointChromaticity_y=t.readUint16(),this.luminanceMax=t.readUint32(),this.luminanceMin=t.readUint32()}),s.createFullBoxCtor("smhd",function(t){this.balance=t.readUint16(),t.readUint16()}),s.createFullBoxCtor("ssix",function(t){this.subsegments=[];for(var e=t.readUint32(),r=0;r<e;r++){var n={};this.subsegments.push(n),n.ranges=[];for(var a=t.readUint32(),u=0;u<a;u++){var p={};n.ranges.push(p),p.level=t.readUint8(),p.range_size=t.readUint24()}}}),s.createFullBoxCtor("stco",function(t){var e;if(e=t.readUint32(),this.chunk_offsets=[],this.version===0)for(var r=0;r<e;r++)this.chunk_offsets.push(t.readUint32())}),s.createFullBoxCtor("stdp",function(t){var e=(this.size-this.hdr_size)/2;this.priority=[];for(var r=0;r<e;r++)this.priority[r]=t.readUint16()}),s.createFullBoxCtor("sthd"),s.createFullBoxCtor("stri",function(t){this.switch_group=t.readUint16(),this.alternate_group=t.readUint16(),this.sub_track_id=t.readUint32();var e=(this.size-this.hdr_size-8)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),s.createFullBoxCtor("stsc",function(t){var e,r;if(e=t.readUint32(),this.first_chunk=[],this.samples_per_chunk=[],this.sample_description_index=[],this.version===0)for(r=0;r<e;r++)this.first_chunk.push(t.readUint32()),this.samples_per_chunk.push(t.readUint32()),this.sample_description_index.push(t.readUint32())}),s.createFullBoxCtor("stsd",function(t){var e,r,n,a;for(this.entries=[],n=t.readUint32(),e=1;e<=n;e++)if(r=s.parseOneBox(t,!0,this.size-(t.getPosition()-this.start)),r.code===s.OK)s[r.type+"SampleEntry"]?(a=new s[r.type+"SampleEntry"](r.size),a.hdr_size=r.hdr_size,a.start=r.start):(f.warn("BoxParser","Unknown sample entry type: "+r.type),a=new s.SampleEntry(r.type,r.size,r.hdr_size,r.start)),a.write===s.SampleEntry.prototype.write&&(f.info("BoxParser","SampleEntry "+a.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),a.parseDataAndRewind(t)),a.parse(t),this.entries.push(a);else return}),s.createFullBoxCtor("stsg",function(t){this.grouping_type=t.readUint32();var e=t.readUint16();this.group_description_index=[];for(var r=0;r<e;r++)this.group_description_index[r]=t.readUint32()}),s.createFullBoxCtor("stsh",function(t){var e,r;if(e=t.readUint32(),this.shadowed_sample_numbers=[],this.sync_sample_numbers=[],this.version===0)for(r=0;r<e;r++)this.shadowed_sample_numbers.push(t.readUint32()),this.sync_sample_numbers.push(t.readUint32())}),s.createFullBoxCtor("stss",function(t){var e,r;if(r=t.readUint32(),this.version===0)for(this.sample_numbers=[],e=0;e<r;e++)this.sample_numbers.push(t.readUint32())}),s.createFullBoxCtor("stsz",function(t){var e;if(this.sample_sizes=[],this.version===0)for(this.sample_size=t.readUint32(),this.sample_count=t.readUint32(),e=0;e<this.sample_count;e++)this.sample_size===0?this.sample_sizes.push(t.readUint32()):this.sample_sizes[e]=this.sample_size}),s.createFullBoxCtor("stts",function(t){var e,r,n;if(e=t.readUint32(),this.sample_counts=[],this.sample_deltas=[],this.version===0)for(r=0;r<e;r++)this.sample_counts.push(t.readUint32()),n=t.readInt32(),n<0&&(f.warn("BoxParser","File uses negative stts sample delta, using value 1 instead, sync may be lost!"),n=1),this.sample_deltas.push(n)}),s.createFullBoxCtor("stvi",function(t){var e=t.readUint32();this.single_view_allowed=e&3,this.stereo_scheme=t.readUint32();var r=t.readUint32();this.stereo_indication_type=t.readString(r);var n,a;for(this.boxes=[];t.getPosition()<this.start+this.size;)if(n=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),n.code===s.OK)a=n.box,this.boxes.push(a),this[a.type]=a;else return}),s.createBoxCtor("styp",function(t){s.ftypBox.prototype.parse.call(this,t)}),s.createFullBoxCtor("stz2",function(t){var e,r;if(this.sample_sizes=[],this.version===0)if(this.reserved=t.readUint24(),this.field_size=t.readUint8(),r=t.readUint32(),this.field_size===4)for(e=0;e<r;e+=2){var n=t.readUint8();this.sample_sizes[e]=n>>4&15,this.sample_sizes[e+1]=n&15}else if(this.field_size===8)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint8();else if(this.field_size===16)for(e=0;e<r;e++)this.sample_sizes[e]=t.readUint16();else f.error("BoxParser","Error in length field in stz2 box")}),s.createFullBoxCtor("subs",function(t){var e,r,n,a;for(n=t.readUint32(),this.entries=[],e=0;e<n;e++){var u={};if(this.entries[e]=u,u.sample_delta=t.readUint32(),u.subsamples=[],a=t.readUint16(),a>0)for(r=0;r<a;r++){var p={};u.subsamples.push(p),this.version==1?p.size=t.readUint32():p.size=t.readUint16(),p.priority=t.readUint8(),p.discardable=t.readUint8(),p.codec_specific_parameters=t.readUint32()}}}),s.createFullBoxCtor("tenc",function(t){if(t.readUint8(),this.version===0)t.readUint8();else{var 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=s.parseHex16(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))}),s.createFullBoxCtor("tfdt",function(t){this.version==1?this.baseMediaDecodeTime=t.readUint64():this.baseMediaDecodeTime=t.readUint32()}),s.createFullBoxCtor("tfhd",function(t){var e=0;this.track_id=t.readUint32(),this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_BASE_DATA_OFFSET?(this.base_data_offset=t.readUint64(),e+=8):this.base_data_offset=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_DESC?(this.default_sample_description_index=t.readUint32(),e+=4):this.default_sample_description_index=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_DUR?(this.default_sample_duration=t.readUint32(),e+=4):this.default_sample_duration=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_SIZE?(this.default_sample_size=t.readUint32(),e+=4):this.default_sample_size=0,this.size-this.hdr_size>e&&this.flags&s.TFHD_FLAG_SAMPLE_FLAGS?(this.default_sample_flags=t.readUint32(),e+=4):this.default_sample_flags=0}),s.createFullBoxCtor("tfra",function(t){this.track_ID=t.readUint32(),t.readUint24();var e=t.readUint8();this.length_size_of_traf_num=e>>4&3,this.length_size_of_trun_num=e>>2&3,this.length_size_of_sample_num=e&3,this.entries=[];for(var r=t.readUint32(),n=0;n<r;n++)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)]()}),s.createFullBoxCtor("tkhd",function(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()}),s.createBoxCtor("tmax",function(t){this.time=t.readUint32()}),s.createBoxCtor("tmin",function(t){this.time=t.readUint32()}),s.createBoxCtor("totl",function(t){this.bytessent=t.readUint32()}),s.createBoxCtor("tpay",function(t){this.bytessent=t.readUint32()}),s.createBoxCtor("tpyl",function(t){this.bytessent=t.readUint64()}),s.TrackGroupTypeBox.prototype.parse=function(t){this.parseFullHeader(t),this.track_group_id=t.readUint32()},s.createTrackGroupCtor("msrc"),s.TrackReferenceTypeBox=function(t,e,r,n){s.Box.call(this,t,e),this.hdr_size=r,this.start=n},s.TrackReferenceTypeBox.prototype=new s.Box,s.TrackReferenceTypeBox.prototype.parse=function(t){this.track_ids=t.readUint32Array((this.size-this.hdr_size)/4)},s.trefBox.prototype.parse=function(t){for(var e,r;t.getPosition()<this.start+this.size;)if(e=s.parseOneBox(t,!0,this.size-(t.getPosition()-this.start)),e.code===s.OK)r=new s.TrackReferenceTypeBox(e.type,e.size,e.hdr_size,e.start),r.write===s.Box.prototype.write&&r.type!=="mdat"&&(f.info("BoxParser","TrackReference "+r.type+" box writing not yet implemented, keeping unparsed data in memory for later write"),r.parseDataAndRewind(t)),r.parse(t),this.boxes.push(r);else return},s.createFullBoxCtor("trep",function(t){for(this.track_ID=t.readUint32(),this.boxes=[];t.getPosition()<this.start+this.size;)if(ret=s.parseOneBox(t,!1,this.size-(t.getPosition()-this.start)),ret.code===s.OK)box=ret.box,this.boxes.push(box);else return}),s.createFullBoxCtor("trex",function(t){this.track_id=t.readUint32(),this.default_sample_description_index=t.readUint32(),this.default_sample_duration=t.readUint32(),this.default_sample_size=t.readUint32(),this.default_sample_flags=t.readUint32()}),s.createBoxCtor("trpy",function(t){this.bytessent=t.readUint64()}),s.createFullBoxCtor("trun",function(t){var e=0;if(this.sample_count=t.readUint32(),e+=4,this.size-this.hdr_size>e&&this.flags&s.TRUN_FLAGS_DATA_OFFSET?(this.data_offset=t.readInt32(),e+=4):this.data_offset=0,this.size-this.hdr_size>e&&this.flags&s.TRUN_FLAGS_FIRST_FLAG?(this.first_sample_flags=t.readUint32(),e+=4):this.first_sample_flags=0,this.sample_duration=[],this.sample_size=[],this.sample_flags=[],this.sample_composition_time_offset=[],this.size-this.hdr_size>e)for(var r=0;r<this.sample_count;r++)this.flags&s.TRUN_FLAGS_DURATION&&(this.sample_duration[r]=t.readUint32()),this.flags&s.TRUN_FLAGS_SIZE&&(this.sample_size[r]=t.readUint32()),this.flags&s.TRUN_FLAGS_FLAGS&&(this.sample_flags[r]=t.readUint32()),this.flags&s.TRUN_FLAGS_CTS_OFFSET&&(this.version===0?this.sample_composition_time_offset[r]=t.readUint32():this.sample_composition_time_offset[r]=t.readInt32())}),s.createFullBoxCtor("tsel",function(t){this.switch_group=t.readUint32();var e=(this.size-this.hdr_size-4)/4;this.attribute_list=[];for(var r=0;r<e;r++)this.attribute_list[r]=t.readUint32()}),s.createFullBoxCtor("txtC",function(t){this.config=t.readCString()}),s.createBoxCtor("tyco",function(t){var e=(this.size-this.hdr_size)/4;this.compatible_brands=[];for(var r=0;r<e;r++)this.compatible_brands[r]=t.readString(4)}),s.createFullBoxCtor("udes",function(t){this.lang=t.readCString(),this.name=t.readCString(),this.description=t.readCString(),this.tags=t.readCString()}),s.createFullBoxCtor("uncC",function(t){var e;if(this.profile=t.readUint32(),this.version!=1){if(this.version==0){for(this.component_count=t.readUint32(),this.component_index=[],this.component_bit_depth_minus_one=[],this.component_format=[],this.component_align_size=[],e=0;e<this.component_count;e++)this.component_index.push(t.readUint16()),this.component_bit_depth_minus_one.push(t.readUint8()),this.component_format.push(t.readUint8()),this.component_align_size.push(t.readUint8());this.sampling_type=t.readUint8(),this.interleave_type=t.readUint8(),this.block_size=t.readUint8();var r=t.readUint8();this.component_little_endian=r>>7&1,this.block_pad_lsb=r>>6&1,this.block_little_endian=r>>5&1,this.block_reversed=r>>4&1,this.pad_unknown=r>>3&1,this.pixel_size=t.readUint32(),this.row_align_size=t.readUint32(),this.tile_align_size=t.readUint32(),this.num_tile_cols_minus_one=t.readUint32(),this.num_tile_rows_minus_one=t.readUint32()}}}),s.createFullBoxCtor("url ",function(t){this.flags!==1&&(this.location=t.readCString())}),s.createFullBoxCtor("urn ",function(t){this.name=t.readCString(),this.size-this.hdr_size-this.name.length-1>0&&(this.location=t.readCString())}),s.createUUIDBox("a5d40b30e81411ddba2f0800200c9a66",!0,!1,function(t){this.LiveServerManifest=t.readString(this.size-this.hdr_size).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}),s.createUUIDBox("d08a4f1810f34a82b6c832d8aba183d3",!0,!1,function(t){this.system_id=s.parseHex16(t);var e=t.readUint32();e>0&&(this.data=t.readUint8Array(e))}),s.createUUIDBox("a2394f525a9b4f14a2446c427c648df4",!0,!1),s.createUUIDBox("8974dbce7be74c5184f97148f9882554",!0,!1,function(t){this.default_AlgorithmID=t.readUint24(),this.default_IV_size=t.readUint8(),this.default_KID=s.parseHex16(t)}),s.createUUIDBox("d4807ef2ca3946958e5426cb9e46a79f",!0,!1,function(t){this.fragment_count=t.readUint8(),this.entries=[];for(var e=0;e<this.fragment_count;e++){var r={},n=0,a=0;this.version===1?(n=t.readUint64(),a=t.readUint64()):(n=t.readUint32(),a=t.readUint32()),r.absolute_time=n,r.absolute_duration=a,this.entries.push(r)}}),s.createUUIDBox("6d1d9b0542d544e680e2141daff757b2",!0,!1,function(t){this.version===1?(this.absolute_time=t.readUint64(),this.duration=t.readUint64()):(this.absolute_time=t.readUint32(),this.duration=t.readUint32())}),s.createFullBoxCtor("vmhd",function(t){this.graphicsmode=t.readUint16(),this.opcolor=t.readUint16Array(3)}),s.createFullBoxCtor("vpcC",function(t){var e;this.version===1?(this.profile=t.readUint8(),this.level=t.readUint8(),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)):(this.profile=t.readUint8(),this.level=t.readUint8(),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))}),s.createBoxCtor("vttC",function(t){this.text=t.readString(this.size-this.hdr_size)}),s.createFullBoxCtor("vvcC",function(t){var e,r,n={held_bits:void 0,num_held_bits:0,stream_read_1_bytes:function(F){this.held_bits=F.readUint8(),this.num_held_bits=8},stream_read_2_bytes:function(F){this.held_bits=F.readUint16(),this.num_held_bits=16},extract_bits:function(F){var I=this.held_bits>>this.num_held_bits-F&(1<<F)-1;return this.num_held_bits-=F,I}};if(n.stream_read_1_bytes(t),n.extract_bits(5),this.lengthSizeMinusOne=n.extract_bits(2),this.ptl_present_flag=n.extract_bits(1),this.ptl_present_flag){n.stream_read_2_bytes(t),this.ols_idx=n.extract_bits(9),this.num_sublayers=n.extract_bits(3),this.constant_frame_rate=n.extract_bits(2),this.chroma_format_idc=n.extract_bits(2),n.stream_read_1_bytes(t),this.bit_depth_minus8=n.extract_bits(3),n.extract_bits(5);{if(n.stream_read_2_bytes(t),n.extract_bits(2),this.num_bytes_constraint_info=n.extract_bits(6),this.general_profile_idc=n.extract_bits(7),this.general_tier_flag=n.extract_bits(1),this.general_level_idc=t.readUint8(),n.stream_read_1_bytes(t),this.ptl_frame_only_constraint_flag=n.extract_bits(1),this.ptl_multilayer_enabled_flag=n.extract_bits(1),this.general_constraint_info=new Uint8Array(this.num_bytes_constraint_info),this.num_bytes_constraint_info){for(e=0;e<this.num_bytes_constraint_info-1;e++){var a=n.extract_bits(6);n.stream_read_1_bytes(t);var u=n.extract_bits(2);this.general_constraint_info[e]=a<<2|u}this.general_constraint_info[this.num_bytes_constraint_info-1]=n.extract_bits(6)}else n.extract_bits(6);if(this.num_sublayers>1){for(n.stream_read_1_bytes(t),this.ptl_sublayer_present_mask=0,r=this.num_sublayers-2;r>=0;--r){var p=n.extract_bits(1);this.ptl_sublayer_present_mask|=p<<r}for(r=this.num_sublayers;r<=8&&this.num_sublayers>1;++r)n.extract_bits(1);for(this.sublayer_level_idc=[],r=this.num_sublayers-2;r>=0;--r)this.ptl_sublayer_present_mask&1<<r&&(this.sublayer_level_idc[r]=t.readUint8())}if(this.ptl_num_sub_profiles=t.readUint8(),this.general_sub_profile_idc=[],this.ptl_num_sub_profiles)for(e=0;e<this.ptl_num_sub_profiles;e++)this.general_sub_profile_idc.push(t.readUint32())}this.max_picture_width=t.readUint16(),this.max_picture_height=t.readUint16(),this.avg_frame_rate=t.readUint16()}var _=12,U=13;this.nalu_arrays=[];var S=t.readUint8();for(e=0;e<S;e++){var b=[];this.nalu_arrays.push(b),n.stream_read_1_bytes(t),b.completeness=n.extract_bits(1),n.extract_bits(2),b.nalu_type=n.extract_bits(5);var E=1;for(b.nalu_type!=U&&b.nalu_type!=_&&(E=t.readUint16()),r=0;r<E;r++){var B=t.readUint16();b.push({data:t.readUint8Array(B),length:B})}}}),s.createFullBoxCtor("vvnC",function(t){var e=strm.readUint8();this.lengthSizeMinusOne=e&3}),s.SampleEntry.prototype.isVideo=function(){return!1},s.SampleEntry.prototype.isAudio=function(){return!1},s.SampleEntry.prototype.isSubtitle=function(){return!1},s.SampleEntry.prototype.isMetadata=function(){return!1},s.SampleEntry.prototype.isHint=function(){return!1},s.SampleEntry.prototype.getCodec=function(){return this.type.replace(".","")},s.SampleEntry.prototype.getWidth=function(){return""},s.SampleEntry.prototype.getHeight=function(){return""},s.SampleEntry.prototype.getChannelCount=function(){return""},s.SampleEntry.prototype.getSampleRate=function(){return""},s.SampleEntry.prototype.getSampleSize=function(){return""},s.VisualSampleEntry.prototype.isVideo=function(){return!0},s.VisualSampleEntry.prototype.getWidth=function(){return this.width},s.VisualSampleEntry.prototype.getHeight=function(){return this.height},s.AudioSampleEntry.prototype.isAudio=function(){return!0},s.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count},s.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate},s.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize},s.SubtitleSampleEntry.prototype.isSubtitle=function(){return!0},s.MetadataSampleEntry.prototype.isMetadata=function(){return!0},s.decimalToHex=function(t,e){var r=Number(t).toString(16);for(e=typeof e>"u"||e===null?e=2:e;r.length<e;)r="0"+r;return r},s.avc1SampleEntry.prototype.getCodec=s.avc2SampleEntry.prototype.getCodec=s.avc3SampleEntry.prototype.getCodec=s.avc4SampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this);return this.avcC?t+"."+s.decimalToHex(this.avcC.AVCProfileIndication)+s.decimalToHex(this.avcC.profile_compatibility)+s.decimalToHex(this.avcC.AVCLevelIndication):t},s.hev1SampleEntry.prototype.getCodec=s.hvc1SampleEntry.prototype.getCodec=function(){var t,e=s.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){switch(e+=".",this.hvcC.general_profile_space){case 0:e+="";break;case 1:e+="A";break;case 2:e+="B";break;case 3:e+="C";break}e+=this.hvcC.general_profile_idc,e+=".";var r=this.hvcC.general_profile_compatibility,n=0;for(t=0;t<32&&(n|=r&1,t!=31);t++)n<<=1,r>>=1;e+=s.decimalToHex(n,0),e+=".",this.hvcC.general_tier_flag===0?e+="L":e+="H",e+=this.hvcC.general_level_idc;var a=!1,u="";for(t=5;t>=0;t--)(this.hvcC.general_constraint_indicator[t]||a)&&(u="."+s.decimalToHex(this.hvcC.general_constraint_indicator[t],0)+u,a=!0);e+=u}return e},s.vvc1SampleEntry.prototype.getCodec=s.vvi1SampleEntry.prototype.getCodec=function(){var t,e=s.SampleEntry.prototype.getCodec.call(this);if(this.vvcC){e+="."+this.vvcC.general_profile_idc,this.vvcC.general_tier_flag?e+=".H":e+=".L",e+=this.vvcC.general_level_idc;var r="";if(this.vvcC.general_constraint_info){var n=[],a=0;a|=this.vvcC.ptl_frame_only_constraint<<7,a|=this.vvcC.ptl_multilayer_enabled<<6;var u;for(t=0;t<this.vvcC.general_constraint_info.length;++t)a|=this.vvcC.general_constraint_info[t]>>2&63,n.push(a),a&&(u=t),a=this.vvcC.general_constraint_info[t]>>2&3;if(u===void 0)r=".CA";else{r=".C";var p="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",_=0,U=0;for(t=0;t<=u;++t)for(_=_<<8|n[t],U+=8;U>=5;){var S=_>>U-5&31;r+=p[S],U-=5,_&=(1<<U)-1}U&&(_<<=5-U,r+=p[_&31])}}e+=r}return e},s.mp4aSampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var e=this.esds.esd.getOTI(),r=this.esds.esd.getAudioConfig();return t+"."+s.decimalToHex(e)+(r?"."+r:"")}else return t},s.stxtSampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this);return this.mime_format?t+"."+this.mime_format:t},s.vp08SampleEntry.prototype.getCodec=s.vp09SampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this),e=this.vpcC.level;e==0&&(e="00");var r=this.vpcC.bitDepth;return r==8&&(r="08"),t+".0"+this.vpcC.profile+"."+e+"."+r},s.av01SampleEntry.prototype.getCodec=function(){var t=s.SampleEntry.prototype.getCodec.call(this),e=this.av1C.seq_level_idx_0;e<10&&(e="0"+e);var r;return this.av1C.seq_profile===2&&this.av1C.high_bitdepth===1?r=this.av1C.twelve_bit===1?"12":"10":this.av1C.seq_profile<=2&&(r=this.av1C.high_bitdepth===1?"10":"08"),t+"."+this.av1C.seq_profile+"."+e+(this.av1C.seq_tier_0?"H":"M")+"."+r},s.Box.prototype.writeHeader=function(t,e){this.size+=8,this.size>d&&(this.size+=8),this.type==="uuid"&&(this.size+=16),f.debug("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+t.getPosition()+(e||"")),this.size>d?t.writeUint32(1):(this.sizePosition=t.getPosition(),t.writeUint32(this.size)),t.writeString(this.type,null,4),this.type==="uuid"&&t.writeUint8Array(this.uuid),this.size>d&&t.writeUint64(this.size)},s.FullBox.prototype.writeHeader=function(t){this.size+=4,s.Box.prototype.writeHeader.call(this,t," v="+this.version+" f="+this.flags),t.writeUint8(this.version),t.writeUint24(this.flags)},s.Box.prototype.write=function(t){this.type==="mdat"?this.data&&(this.size=this.data.length,this.writeHeader(t),t.writeUint8Array(this.data)):(this.size=this.data?this.data.length:0,this.writeHeader(t),this.data&&t.writeUint8Array(this.data))},s.ContainerBox.prototype.write=function(t){this.size=0,this.writeHeader(t);for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&(this.boxes[e].write(t),this.size+=this.boxes[e].size);f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.TrackReferenceTypeBox.prototype.write=function(t){this.size=this.track_ids.length*4,this.writeHeader(t),t.writeUint32Array(this.track_ids)},s.avcCBox.prototype.write=function(t){var e;for(this.size=7,e=0;e<this.SPS.length;e++)this.size+=2+this.SPS[e].length;for(e=0;e<this.PPS.length;e++)this.size+=2+this.PPS[e].length;for(this.ext&&(this.size+=this.ext.length),this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8(this.AVCProfileIndication),t.writeUint8(this.profile_compatibility),t.writeUint8(this.AVCLevelIndication),t.writeUint8(this.lengthSizeMinusOne+252),t.writeUint8(this.SPS.length+224),e=0;e<this.SPS.length;e++)t.writeUint16(this.SPS[e].length),t.writeUint8Array(this.SPS[e].nalu);for(t.writeUint8(this.PPS.length),e=0;e<this.PPS.length;e++)t.writeUint16(this.PPS[e].length),t.writeUint8Array(this.PPS[e].nalu);this.ext&&t.writeUint8Array(this.ext)},s.co64Box.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),e=0;e<this.chunk_offsets.length;e++)t.writeUint64(this.chunk_offsets[e])},s.cslgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*5,this.writeHeader(t),t.writeInt32(this.compositionToDTSShift),t.writeInt32(this.leastDecodeToDisplayDelta),t.writeInt32(this.greatestDecodeToDisplayDelta),t.writeInt32(this.compositionStartTime),t.writeInt32(this.compositionEndTime)},s.cttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),this.version===1?t.writeInt32(this.sample_offsets[e]):t.writeUint32(this.sample_offsets[e])},s.drefBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.elngBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.extended_language.length,this.writeHeader(t),t.writeString(this.extended_language)},s.elstBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+12*this.entries.length,this.writeHeader(t),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeUint32(r.segment_duration),t.writeInt32(r.media_time),t.writeInt16(r.media_rate_integer),t.writeInt16(r.media_rate_fraction)}},s.emsgBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*4+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)},s.ftypBox.prototype.write=function(t){this.size=8+4*this.compatible_brands.length,this.writeHeader(t),t.writeString(this.major_brand,null,4),t.writeUint32(this.minor_version);for(var e=0;e<this.compatible_brands.length;e++)t.writeString(this.compatible_brands[e],null,4)},s.hdlrBox.prototype.write=function(t){this.size=5*4+this.name.length+1,this.version=0,this.flags=0,this.writeHeader(t),t.writeUint32(0),t.writeString(this.handler,null,4),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeCString(this.name)},s.hvcCBox.prototype.write=function(t){var e,r;for(this.size=23,e=0;e<this.nalu_arrays.length;e++)for(this.size+=3,r=0;r<this.nalu_arrays[e].length;r++)this.size+=2+this.nalu_arrays[e][r].data.length;for(this.writeHeader(t),t.writeUint8(this.configurationVersion),t.writeUint8((this.general_profile_space<<6)+(this.general_tier_flag<<5)+this.general_profile_idc),t.writeUint32(this.general_profile_compatibility),t.writeUint8Array(this.general_constraint_indicator),t.writeUint8(this.general_level_idc),t.writeUint16(this.min_spatial_segmentation_idc+(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),e=0;e<this.nalu_arrays.length;e++)for(t.writeUint8((this.nalu_arrays[e].completeness<<7)+this.nalu_arrays[e].nalu_type),t.writeUint16(this.nalu_arrays[e].length),r=0;r<this.nalu_arrays[e].length;r++)t.writeUint16(this.nalu_arrays[e][r].data.length),t.writeUint8Array(this.nalu_arrays[e][r].data)},s.kindBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=this.schemeURI.length+1+(this.value.length+1),this.writeHeader(t),t.writeCString(this.schemeURI),t.writeCString(this.value)},s.mdhdBox.prototype.write=function(t){this.size=4*4+2*2,this.flags=0,this.version=0,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint16(this.language),t.writeUint16(0)},s.mehdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.fragment_duration)},s.mfhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4,this.writeHeader(t),t.writeUint32(this.sequence_number)},s.mvhdBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=23*4+2*2,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.timescale),t.writeUint32(this.duration),t.writeUint32(this.rate),t.writeUint16(this.volume<<8),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32Array(this.matrix),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(this.next_track_id)},s.SampleEntry.prototype.writeHeader=function(t){this.size=8,s.Box.prototype.writeHeader.call(this,t),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint8(0),t.writeUint16(this.data_reference_index)},s.SampleEntry.prototype.writeFooter=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t),this.size+=this.boxes[e].size;f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.SampleEntry.prototype.write=function(t){this.writeHeader(t),t.writeUint8Array(this.data),this.size+=this.data.length,f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.VisualSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=2*7+6*4+32,t.writeUint16(0),t.writeUint16(0),t.writeUint32(0),t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint32(this.horizresolution),t.writeUint32(this.vertresolution),t.writeUint32(0),t.writeUint16(this.frame_count),t.writeUint8(Math.min(31,this.compressorname.length)),t.writeString(this.compressorname,null,31),t.writeUint16(this.depth),t.writeInt16(-1),this.writeFooter(t)},s.AudioSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=2*4+3*4,t.writeUint32(0),t.writeUint32(0),t.writeUint16(this.channel_count),t.writeUint16(this.samplesize),t.writeUint16(0),t.writeUint16(0),t.writeUint32(this.samplerate<<16),this.writeFooter(t)},s.stppSampleEntry.prototype.write=function(t){this.writeHeader(t),this.size+=this.namespace.length+1+this.schema_location.length+1+this.auxiliary_mime_types.length+1,t.writeCString(this.namespace),t.writeCString(this.schema_location),t.writeCString(this.auxiliary_mime_types),this.writeFooter(t)},s.SampleGroupEntry.prototype.write=function(t){t.writeUint8Array(this.data)},s.sbgpBox.prototype.write=function(t){this.version=1,this.flags=0,this.size=12+8*this.entries.length,this.writeHeader(t),t.writeString(this.grouping_type,null,4),t.writeUint32(this.grouping_type_parameter),t.writeUint32(this.entries.length);for(var e=0;e<this.entries.length;e++){var r=this.entries[e];t.writeInt32(r.sample_count),t.writeInt32(r.group_description_index)}},s.sgpdBox.prototype.write=function(t){var e,r;for(this.flags=0,this.size=12,e=0;e<this.entries.length;e++)r=this.entries[e],this.version===1&&(this.default_length===0&&(this.size+=4),this.size+=r.data.length);for(this.writeHeader(t),t.writeString(this.grouping_type,null,4),this.version===1&&t.writeUint32(this.default_length),this.version>=2&&t.writeUint32(this.default_sample_description_index),t.writeUint32(this.entries.length),e=0;e<this.entries.length;e++)r=this.entries[e],this.version===1&&this.default_length===0&&t.writeUint32(r.description_length),r.write(t)},s.sidxBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*4+2+2+12*this.references.length,this.writeHeader(t),t.writeUint32(this.reference_ID),t.writeUint32(this.timescale),t.writeUint32(this.earliest_presentation_time),t.writeUint32(this.first_offset),t.writeUint16(0),t.writeUint16(this.references.length);for(var e=0;e<this.references.length;e++){var r=this.references[e];t.writeUint32(r.reference_type<<31|r.referenced_size),t.writeUint32(r.subsegment_duration),t.writeUint32(r.starts_with_SAP<<31|r.SAP_type<<28|r.SAP_delta_time)}},s.smhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=4,this.writeHeader(t),t.writeUint16(this.balance),t.writeUint16(0)},s.stcoBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.chunk_offsets.length,this.writeHeader(t),t.writeUint32(this.chunk_offsets.length),t.writeUint32Array(this.chunk_offsets)},s.stscBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+12*this.first_chunk.length,this.writeHeader(t),t.writeUint32(this.first_chunk.length),e=0;e<this.first_chunk.length;e++)t.writeUint32(this.first_chunk[e]),t.writeUint32(this.samples_per_chunk[e]),t.writeUint32(this.sample_description_index[e])},s.stsdBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=0,this.writeHeader(t),t.writeUint32(this.entries.length),this.size+=4,e=0;e<this.entries.length;e++)this.entries[e].write(t),this.size+=this.entries[e].size;f.debug("BoxWriter","Adjusting box "+this.type+" with new size "+this.size),t.adjustUint32(this.sizePosition,this.size)},s.stshBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.shadowed_sample_numbers.length,this.writeHeader(t),t.writeUint32(this.shadowed_sample_numbers.length),e=0;e<this.shadowed_sample_numbers.length;e++)t.writeUint32(this.shadowed_sample_numbers[e]),t.writeUint32(this.sync_sample_numbers[e])},s.stssBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4+4*this.sample_numbers.length,this.writeHeader(t),t.writeUint32(this.sample_numbers.length),t.writeUint32Array(this.sample_numbers)},s.stszBox.prototype.write=function(t){var e,r=!0;if(this.version=0,this.flags=0,this.sample_sizes.length>0)for(e=0;e+1<this.sample_sizes.length;)if(this.sample_sizes[e+1]!==this.sample_sizes[0]){r=!1;break}else e++;else r=!1;this.size=8,r||(this.size+=4*this.sample_sizes.length),this.writeHeader(t),r?t.writeUint32(this.sample_sizes[0]):t.writeUint32(0),t.writeUint32(this.sample_sizes.length),r||t.writeUint32Array(this.sample_sizes)},s.sttsBox.prototype.write=function(t){var e;for(this.version=0,this.flags=0,this.size=4+8*this.sample_counts.length,this.writeHeader(t),t.writeUint32(this.sample_counts.length),e=0;e<this.sample_counts.length;e++)t.writeUint32(this.sample_counts[e]),t.writeUint32(this.sample_deltas[e])},s.tfdtBox.prototype.write=function(t){var e=Math.pow(2,32)-1;this.version=this.baseMediaDecodeTime>e?1:0,this.flags=0,this.size=4,this.version===1&&(this.size+=4),this.writeHeader(t),this.version===1?t.writeUint64(this.baseMediaDecodeTime):t.writeUint32(this.baseMediaDecodeTime)},s.tfhdBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&s.TFHD_FLAG_BASE_DATA_OFFSET&&(this.size+=8),this.flags&s.TFHD_FLAG_SAMPLE_DESC&&(this.size+=4),this.flags&s.TFHD_FLAG_SAMPLE_DUR&&(this.size+=4),this.flags&s.TFHD_FLAG_SAMPLE_SIZE&&(this.size+=4),this.flags&s.TFHD_FLAG_SAMPLE_FLAGS&&(this.size+=4),this.writeHeader(t),t.writeUint32(this.track_id),this.flags&s.TFHD_FLAG_BASE_DATA_OFFSET&&t.writeUint64(this.base_data_offset),this.flags&s.TFHD_FLAG_SAMPLE_DESC&&t.writeUint32(this.default_sample_description_index),this.flags&s.TFHD_FLAG_SAMPLE_DUR&&t.writeUint32(this.default_sample_duration),this.flags&s.TFHD_FLAG_SAMPLE_SIZE&&t.writeUint32(this.default_sample_size),this.flags&s.TFHD_FLAG_SAMPLE_FLAGS&&t.writeUint32(this.default_sample_flags)},s.tkhdBox.prototype.write=function(t){this.version=0,this.size=4*18+2*4,this.writeHeader(t),t.writeUint32(this.creation_time),t.writeUint32(this.modification_time),t.writeUint32(this.track_id),t.writeUint32(0),t.writeUint32(this.duration),t.writeUint32(0),t.writeUint32(0),t.writeInt16(this.layer),t.writeInt16(this.alternate_group),t.writeInt16(this.volume<<8),t.writeUint16(0),t.writeInt32Array(this.matrix),t.writeUint32(this.width),t.writeUint32(this.height)},s.trexBox.prototype.write=function(t){this.version=0,this.flags=0,this.size=4*5,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)},s.trunBox.prototype.write=function(t){this.version=0,this.size=4,this.flags&s.TRUN_FLAGS_DATA_OFFSET&&(this.size+=4),this.flags&s.TRUN_FLAGS_FIRST_FLAG&&(this.size+=4),this.flags&s.TRUN_FLAGS_DURATION&&(this.size+=4*this.sample_duration.length),this.flags&s.TRUN_FLAGS_SIZE&&(this.size+=4*this.sample_size.length),this.flags&s.TRUN_FLAGS_FLAGS&&(this.size+=4*this.sample_flags.length),this.flags&s.TRUN_FLAGS_CTS_OFFSET&&(this.size+=4*this.sample_composition_time_offset.length),this.writeHeader(t),t.writeUint32(this.sample_count),this.flags&s.TRUN_FLAGS_DATA_OFFSET&&(this.data_offset_position=t.getPosition(),t.writeInt32(this.data_offset)),this.flags&s.TRUN_FLAGS_FIRST_FLAG&&t.writeUint32(this.first_sample_flags);for(var e=0;e<this.sample_count;e++)this.flags&s.TRUN_FLAGS_DURATION&&t.writeUint32(this.sample_duration[e]),this.flags&s.TRUN_FLAGS_SIZE&&t.writeUint32(this.sample_size[e]),this.flags&s.TRUN_FLAGS_FLAGS&&t.writeUint32(this.sample_flags[e]),this.flags&s.TRUN_FLAGS_CTS_OFFSET&&(this.version===0?t.writeUint32(this.sample_composition_time_offset[e]):t.writeInt32(this.sample_composition_time_offset[e]))},s["url Box"].prototype.write=function(t){this.version=0,this.location?(this.flags=0,this.size=this.location.length+1):(this.flags=1,this.size=0),this.writeHeader(t),this.location&&t.writeCString(this.location)},s["urn Box"].prototype.write=function(t){this.version=0,this.flags=0,this.size=this.name.length+1+(this.location?this.location.length+1:0),this.writeHeader(t),t.writeCString(this.name),this.location&&t.writeCString(this.location)},s.vmhdBox.prototype.write=function(t){this.version=0,this.flags=1,this.size=8,this.writeHeader(t),t.writeUint16(this.graphicsmode),t.writeUint16Array(this.opcolor)},s.cttsBox.prototype.unpack=function(t){var e,r,n;for(n=0,e=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)t[n].pts=t[n].dts+this.sample_offsets[e],n++},s.sttsBox.prototype.unpack=function(t){var e,r,n;for(n=0,e=0;e<this.sample_counts.length;e++)for(r=0;r<this.sample_counts[e];r++)n===0?t[n].dts=0:t[n].dts=t[n-1].dts+this.sample_deltas[e],n++},s.stcoBox.prototype.unpack=function(t){var e;for(e=0;e<this.chunk_offsets.length;e++)t[e].offset=this.chunk_offsets[e]},s.stscBox.prototype.unpack=function(t){var e,r,n,a,u;for(a=0,u=0,e=0;e<this.first_chunk.length;e++)for(r=0;r<(e+1<this.first_chunk.length?this.first_chunk[e+1]:1/0);r++)for(u++,n=0;n<this.samples_per_chunk[e];n++){if(t[a])t[a].description_index=this.sample_description_index[e],t[a].chunk_index=u;else return;a++}},s.stszBox.prototype.unpack=function(t){var e;for(e=0;e<this.sample_sizes.length;e++)t[e].size=this.sample_sizes[e]},s.DIFF_BOXES_PROP_NAMES=["boxes","entries","references","subsamples","items","item_infos","extents","associations","subsegments","ranges","seekLists","seekPoints","esd","levels"],s.DIFF_PRIMITIVE_ARRAY_PROP_NAMES=["compatible_brands","matrix","opcolor","sample_counts","sample_counts","sample_deltas","first_chunk","samples_per_chunk","sample_sizes","chunk_offsets","sample_offsets","sample_description_index","sample_duration"],s.boxEqualFields=function(t,e){if(t&&!e)return!1;var r;for(r in t)if(!(s.DIFF_BOXES_PROP_NAMES.indexOf(r)>-1)){if(t[r]instanceof s.Box||e[r]instanceof s.Box)continue;if(typeof t[r]>"u"||typeof e[r]>"u")continue;if(typeof t[r]=="function"||typeof e[r]=="function")continue;if(t.subBoxNames&&t.subBoxNames.indexOf(r.slice(0,4))>-1||e.subBoxNames&&e.subBoxNames.indexOf(r.slice(0,4))>-1)continue;if(r==="data"||r==="start"||r==="size"||r==="creation_time"||r==="modification_time")continue;if(s.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(r)>-1)continue;if(t[r]!==e[r])return!1}return!0},s.boxEqual=function(t,e){if(!s.boxEqualFields(t,e))return!1;for(var r=0;r<s.DIFF_BOXES_PROP_NAMES.length;r++){var n=s.DIFF_BOXES_PROP_NAMES[r];if(t[n]&&e[n]&&!s.boxEqual(t[n],e[n]))return!1}return!0};var x=function(){};x.prototype.parseSample=function(t){var e,r,n=new h(t.buffer);for(e=[];!n.isEos();)r=s.parseOneBox(n,!1),r.code===s.OK&&r.box.type==="vttc"&&e.push(r.box);return e},x.prototype.getText=function(t,e,r){function n(S,b,E){return E=E||"0",S=S+"",S.length>=b?S:new Array(b-S.length+1).join(E)+S}function a(S){var b=Math.floor(S/3600),E=Math.floor((S-b*3600)/60),B=Math.floor(S-b*3600-E*60),F=Math.floor((S-b*3600-E*60-B)*1e3);return""+n(b,2)+":"+n(E,2)+":"+n(B,2)+"."+n(F,3)}for(var u=this.parseSample(r),p="",_=0;_<u.length;_++){var U=u[_];p+=a(t)+" --> "+a(e)+\`\\r
|
|
2
2
|
\`,p+=U.payl.text}return p};var m=function(){};m.prototype.parseSample=function(t){var e={},r;e.resources=[];var n=new h(t.data.buffer);if(!t.subsamples||t.subsamples.length===0)e.documentString=n.readString(t.data.length);else if(e.documentString=n.readString(t.subsamples[0].size),t.subsamples.length>1)for(r=1;r<t.subsamples.length;r++)e.resources[r]=n.readUint8Array(t.subsamples[r].size);return typeof DOMParser<"u"&&(e.document=new DOMParser().parseFromString(e.documentString,"application/xml")),e};var w=function(){};w.prototype.parseSample=function(t){var e,r=new h(t.data.buffer);return e=r.readString(t.data.length),e},w.prototype.parseConfig=function(t){var e,r=new h(t.buffer);return r.readUint32(),e=r.readCString(),e},C.VTTin4Parser=x,C.XMLSubtitlein4Parser=m,C.Textin4Parser=w;var y=function(t){this.stream=t||new l,this.boxes=[],this.mdats=[],this.moofs=[],this.isProgressive=!1,this.moovStartFound=!1,this.onMoovStart=null,this.moovStartSent=!1,this.onReady=null,this.readySent=!1,this.onSegment=null,this.onSamples=null,this.onError=null,this.sampleListBuilt=!1,this.fragmentedTracks=[],this.extractedTracks=[],this.isFragmentationInitialized=!1,this.sampleProcessingStarted=!1,this.nextMoofNumber=0,this.itemListBuilt=!1,this.items=[],this.entity_groups=[],this.onSidx=null,this.sidxSent=!1};y.prototype.setSegmentOptions=function(t,e,r){var n=this.getTrackById(t);if(n){var a={};this.fragmentedTracks.push(a),a.id=t,a.user=e,a.trak=n,n.nextSample=0,a.segmentStream=null,a.nb_samples=1e3,a.rapAlignement=!0,r&&(r.nbSamples&&(a.nb_samples=r.nbSamples),r.rapAlignement&&(a.rapAlignement=r.rapAlignement))}},y.prototype.unsetSegmentOptions=function(t){for(var e=-1,r=0;r<this.fragmentedTracks.length;r++){var n=this.fragmentedTracks[r];n.id==t&&(e=r)}e>-1&&this.fragmentedTracks.splice(e,1)},y.prototype.setExtractionOptions=function(t,e,r){var n=this.getTrackById(t);if(n){var a={};this.extractedTracks.push(a),a.id=t,a.user=e,a.trak=n,n.nextSample=0,a.nb_samples=1e3,a.samples=[],r&&r.nbSamples&&(a.nb_samples=r.nbSamples)}},y.prototype.unsetExtractionOptions=function(t){for(var e=-1,r=0;r<this.extractedTracks.length;r++){var n=this.extractedTracks[r];n.id==t&&(e=r)}e>-1&&this.extractedTracks.splice(e,1)},y.prototype.parse=function(){var t,e,r=!1;if(!(this.restoreParsePosition&&!this.restoreParsePosition()))for(;;)if(this.hasIncompleteMdat&&this.hasIncompleteMdat()){if(this.processIncompleteMdat())continue;return}else if(this.saveParsePosition&&this.saveParsePosition(),t=s.parseOneBox(this.stream,r),t.code===s.ERR_NOT_ENOUGH_DATA)if(this.processIncompleteBox){if(this.processIncompleteBox(t))continue;return}else return;else{var n;switch(e=t.box,n=e.type!=="uuid"?e.type:e.uuid,this.boxes.push(e),n){case"mdat":this.mdats.push(e);break;case"moof":this.moofs.push(e);break;case"moov":this.moovStartFound=!0,this.mdats.length===0&&(this.isProgressive=!0);default:this[n]!==void 0&&f.warn("ISOFile","Duplicate Box of type: "+n+", overriding previous occurrence"),this[n]=e;break}this.updateUsedBytes&&this.updateUsedBytes(e,t)}},y.prototype.checkBuffer=function(t){if(t==null)throw"Buffer must be defined and non empty";if(t.fileStart===void 0)throw"Buffer must have a fileStart property";return t.byteLength===0?(f.warn("ISOFile","Ignoring empty buffer (fileStart: "+t.fileStart+")"),this.stream.logBufferLevel(),!1):(f.info("ISOFile","Processing buffer (fileStart: "+t.fileStart+")"),t.usedBytes=0,this.stream.insertBuffer(t),this.stream.logBufferLevel(),this.stream.initialized()?!0:(f.warn("ISOFile","Not ready to start parsing"),!1))},y.prototype.appendBuffer=function(t,e){var r;if(this.checkBuffer(t))return this.parse(),this.moovStartFound&&!this.moovStartSent&&(this.moovStartSent=!0,this.onMoovStart&&this.onMoovStart()),this.moov?(this.sampleListBuilt||(this.buildSampleLists(),this.sampleListBuilt=!0),this.updateSampleLists(),this.onReady&&!this.readySent&&(this.readySent=!0,this.onReady(this.getInfo())),this.processSamples(e),this.nextSeekPosition?(r=this.nextSeekPosition,this.nextSeekPosition=void 0):r=this.nextParsePosition,this.stream.getEndFilePositionAfter&&(r=this.stream.getEndFilePositionAfter(r))):this.nextParsePosition?r=this.nextParsePosition:r=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&&(f.info("ISOFile","Done processing buffer (fileStart: "+t.fileStart+") - next buffer to fetch should have a fileStart position of "+r),this.stream.logBufferLevel(),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0),f.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize())),r},y.prototype.getInfo=function(){var t,e,r={},n,a,u,p,_=new Date("1904-01-01T00:00:00Z").getTime();if(this.moov)for(r.hasMoov=!0,r.duration=this.moov.mvhd.duration,r.timescale=this.moov.mvhd.timescale,r.isFragmented=this.moov.mvex!=null,r.isFragmented&&this.moov.mvex.mehd&&(r.fragment_duration=this.moov.mvex.mehd.fragment_duration),r.isProgressive=this.isProgressive,r.hasIOD=this.moov.iods!=null,r.brands=[],r.brands.push(this.ftyp.major_brand),r.brands=r.brands.concat(this.ftyp.compatible_brands),r.created=new Date(_+this.moov.mvhd.creation_time*1e3),r.modified=new Date(_+this.moov.mvhd.modification_time*1e3),r.tracks=[],r.audioTracks=[],r.videoTracks=[],r.subtitleTracks=[],r.metadataTracks=[],r.hintTracks=[],r.otherTracks=[],t=0;t<this.moov.traks.length;t++){if(n=this.moov.traks[t],p=n.mdia.minf.stbl.stsd.entries[0],a={},r.tracks.push(a),a.id=n.tkhd.track_id,a.name=n.mdia.hdlr.name,a.references=[],n.tref)for(e=0;e<n.tref.boxes.length;e++)u={},a.references.push(u),u.type=n.tref.boxes[e].type,u.track_ids=n.tref.boxes[e].track_ids;n.edts&&(a.edits=n.edts.elst.entries),a.created=new Date(_+n.tkhd.creation_time*1e3),a.modified=new Date(_+n.tkhd.modification_time*1e3),a.movie_duration=n.tkhd.duration,a.movie_timescale=r.timescale,a.layer=n.tkhd.layer,a.alternate_group=n.tkhd.alternate_group,a.volume=n.tkhd.volume,a.matrix=n.tkhd.matrix,a.track_width=n.tkhd.width/65536,a.track_height=n.tkhd.height/65536,a.timescale=n.mdia.mdhd.timescale,a.cts_shift=n.mdia.minf.stbl.cslg,a.duration=n.mdia.mdhd.duration,a.samples_duration=n.samples_duration,a.codec=p.getCodec(),a.kind=n.udta&&n.udta.kinds.length?n.udta.kinds[0]:{schemeURI:"",value:""},a.language=n.mdia.elng?n.mdia.elng.extended_language:n.mdia.mdhd.languageString,a.nb_samples=n.samples.length,a.size=n.samples_size,a.bitrate=a.size*8*a.timescale/a.samples_duration,p.isAudio()?(a.type="audio",r.audioTracks.push(a),a.audio={},a.audio.sample_rate=p.getSampleRate(),a.audio.channel_count=p.getChannelCount(),a.audio.sample_size=p.getSampleSize()):p.isVideo()?(a.type="video",r.videoTracks.push(a),a.video={},a.video.width=p.getWidth(),a.video.height=p.getHeight()):p.isSubtitle()?(a.type="subtitles",r.subtitleTracks.push(a)):p.isHint()?(a.type="metadata",r.hintTracks.push(a)):p.isMetadata()?(a.type="metadata",r.metadataTracks.push(a)):(a.type="metadata",r.otherTracks.push(a))}else r.hasMoov=!1;if(r.mime="",r.hasMoov&&r.tracks){for(r.videoTracks&&r.videoTracks.length>0?r.mime+='video/mp4; codecs="':r.audioTracks&&r.audioTracks.length>0?r.mime+='audio/mp4; codecs="':r.mime+='application/mp4; codecs="',t=0;t<r.tracks.length;t++)t!==0&&(r.mime+=","),r.mime+=r.tracks[t].codec;r.mime+='"; profiles="',r.mime+=this.ftyp.compatible_brands.join(),r.mime+='"'}return r},y.prototype.setNextSeekPositionFromSample=function(t){t&&(this.nextSeekPosition?this.nextSeekPosition=Math.min(t.offset+t.alreadyRead,this.nextSeekPosition):this.nextSeekPosition=t.offset+t.alreadyRead)},y.prototype.processSamples=function(t){var e,r;if(this.sampleProcessingStarted){if(this.isFragmentationInitialized&&this.onSegment!==null)for(e=0;e<this.fragmentedTracks.length;e++){var n=this.fragmentedTracks[e];for(r=n.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){f.debug("ISOFile","Creating media fragment on track #"+n.id+" for sample "+r.nextSample);var a=this.createFragment(n.id,r.nextSample,n.segmentStream);if(a)n.segmentStream=a,r.nextSample++;else break;if((r.nextSample%n.nb_samples===0||t||r.nextSample>=r.samples.length)&&(f.info("ISOFile","Sending fragmented data on track #"+n.id+" for samples ["+Math.max(0,r.nextSample-n.nb_samples)+","+(r.nextSample-1)+"]"),f.info("ISOFile","Sample data size in memory: "+this.getAllocatedSampleDataSize()),this.onSegment&&this.onSegment(n.id,n.user,n.segmentStream.buffer,r.nextSample,t||r.nextSample>=r.samples.length),n.segmentStream=null,n!==this.fragmentedTracks[e]))break}}if(this.onSamples!==null)for(e=0;e<this.extractedTracks.length;e++){var u=this.extractedTracks[e];for(r=u.trak;r.nextSample<r.samples.length&&this.sampleProcessingStarted;){f.debug("ISOFile","Exporting on track #"+u.id+" sample #"+r.nextSample);var p=this.getSample(r,r.nextSample);if(p)r.nextSample++,u.samples.push(p);else{this.setNextSeekPositionFromSample(r.samples[r.nextSample]);break}if((r.nextSample%u.nb_samples===0||r.nextSample>=r.samples.length)&&(f.debug("ISOFile","Sending samples on track #"+u.id+" for sample "+r.nextSample),this.onSamples&&this.onSamples(u.id,u.user,u.samples),u.samples=[],u!==this.extractedTracks[e]))break}}}},y.prototype.getBox=function(t){var e=this.getBoxes(t,!0);return e.length?e[0]:null},y.prototype.getBoxes=function(t,e){var r=[];return y._sweep.call(this,t,r,e),r},y._sweep=function(t,e,r){this.type&&this.type==t&&e.push(this);for(var n in this.boxes){if(e.length&&r)return;y._sweep.call(this.boxes[n],t,e,r)}},y.prototype.getTrackSamplesInfo=function(t){var e=this.getTrackById(t);if(e)return e.samples},y.prototype.getTrackSample=function(t,e){var r=this.getTrackById(t),n=this.getSample(r,e);return n},y.prototype.releaseUsedSamples=function(t,e){var r=0,n=this.getTrackById(t);n.lastValidSample||(n.lastValidSample=0);for(var a=n.lastValidSample;a<e;a++)r+=this.releaseSample(n,a);f.info("ISOFile","Track #"+t+" released samples up to "+e+" (released size: "+r+", remaining: "+this.samplesDataSize+")"),n.lastValidSample=e},y.prototype.start=function(){this.sampleProcessingStarted=!0,this.processSamples(!1)},y.prototype.stop=function(){this.sampleProcessingStarted=!1},y.prototype.flush=function(){f.info("ISOFile","Flushing remaining samples"),this.updateSampleLists(),this.processSamples(!0),this.stream.cleanBuffers(),this.stream.logBufferLevel(!0)},y.prototype.seekTrack=function(t,e,r){var n,a,u=1/0,p=0,_=0,U;if(r.samples.length===0)return f.info("ISOFile","No sample in track, cannot seek! Using time "+f.getDurationString(0,1)+" and offset: 0"),{offset:0,time:0};for(n=0;n<r.samples.length;n++){if(a=r.samples[n],n===0)_=0,U=a.timescale;else if(a.cts>t*a.timescale){_=n-1;break}e&&a.is_sync&&(p=n)}for(e&&(_=p),t=r.samples[_].cts,r.nextSample=_;r.samples[_].alreadyRead===r.samples[_].size&&r.samples[_+1];)_++;return u=r.samples[_].offset+r.samples[_].alreadyRead,f.info("ISOFile","Seeking to "+(e?"RAP":"")+" sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+f.getDurationString(t,U)+" and offset: "+u),{offset:u,time:t/U}},y.prototype.getTrackDuration=function(t){var e;return t.samples?(e=t.samples[t.samples.length-1],(e.cts+e.duration)/e.timescale):1/0},y.prototype.seek=function(t,e){var r=this.moov,n,a,u,p={offset:1/0,time:1/0};if(this.moov){for(u=0;u<r.traks.length;u++)n=r.traks[u],!(t>this.getTrackDuration(n))&&(a=this.seekTrack(t,e,n),a.offset<p.offset&&(p.offset=a.offset),a.time<p.time&&(p.time=a.time));return f.info("ISOFile","Seeking at time "+f.getDurationString(p.time,1)+" needs a buffer with a fileStart position of "+p.offset),p.offset===1/0?p={offset:this.nextParsePosition,time:0}:p.offset=this.stream.getEndFilePositionAfter(p.offset),f.info("ISOFile","Adjusted seek position (after checking data already in buffer): "+p.offset),p}else throw"Cannot seek: moov not received!"},y.prototype.equal=function(t){for(var e=0;e<this.boxes.length&&e<t.boxes.length;){var r=this.boxes[e],n=t.boxes[e];if(!s.boxEqual(r,n))return!1;e++}return!0},C.ISOFile=y,y.prototype.lastBoxStartPosition=0,y.prototype.parsingMdat=null,y.prototype.nextParsePosition=0,y.prototype.discardMdatData=!1,y.prototype.processIncompleteBox=function(t){var e,r,n;return t.type==="mdat"?(e=new s[t.type+"Box"](t.size),this.parsingMdat=e,this.boxes.push(e),this.mdats.push(e),e.start=t.start,e.hdr_size=t.hdr_size,this.stream.addUsedBytes(e.hdr_size),this.lastBoxStartPosition=e.start+e.size,n=this.stream.seek(e.start+e.size,!1,this.discardMdatData),n?(this.parsingMdat=null,!0):(this.moovStartFound?this.nextParsePosition=this.stream.findEndContiguousBuf():this.nextParsePosition=e.start+e.size,!1)):(t.type==="moov"&&(this.moovStartFound=!0,this.mdats.length===0&&(this.isProgressive=!0)),r=this.stream.mergeNextBuffer?this.stream.mergeNextBuffer():!1,r?(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))},y.prototype.hasIncompleteMdat=function(){return this.parsingMdat!==null},y.prototype.processIncompleteMdat=function(){var t,e;return t=this.parsingMdat,e=this.stream.seek(t.start+t.size,!1,this.discardMdatData),e?(f.debug("ISOFile","Found 'mdat' end in buffered data"),this.parsingMdat=null,!0):(this.nextParsePosition=this.stream.findEndContiguousBuf(),!1)},y.prototype.restoreParsePosition=function(){return this.stream.seek(this.lastBoxStartPosition,!0,this.discardMdatData)},y.prototype.saveParsePosition=function(){this.lastBoxStartPosition=this.stream.getPosition()},y.prototype.updateUsedBytes=function(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))},y.prototype.add=s.Box.prototype.add,y.prototype.addBox=s.Box.prototype.addBox,y.prototype.init=function(t){var e=t||{};this.add("ftyp").set("major_brand",e.brands&&e.brands[0]||"iso4").set("minor_version",0).set("compatible_brands",e.brands||["iso4"]);var r=this.add("moov");return r.add("mvhd").set("timescale",e.timescale||600).set("rate",e.rate||65536).set("creation_time",0).set("modification_time",0).set("duration",e.duration||0).set("volume",e.width?0:256).set("matrix",[65536,0,0,0,65536,0,0,0,1073741824]).set("next_track_id",1),r.add("mvex"),this},y.prototype.addTrack=function(t){this.moov||this.init(t);var e=t||{};e.width=e.width||320,e.height=e.height||320,e.id=e.id||this.moov.mvhd.next_track_id,e.type=e.type||"avc1";var r=this.moov.add("trak");this.moov.mvhd.next_track_id=e.id+1,r.add("tkhd").set("flags",s.TKHD_FLAG_ENABLED|s.TKHD_FLAG_IN_MOVIE|s.TKHD_FLAG_IN_PREVIEW).set("creation_time",0).set("modification_time",0).set("track_id",e.id).set("duration",e.duration||0).set("layer",e.layer||0).set("alternate_group",0).set("volume",1).set("matrix",[0,0,0,0,0,0,0,0,0]).set("width",e.width<<16).set("height",e.height<<16);var n=r.add("mdia");n.add("mdhd").set("creation_time",0).set("modification_time",0).set("timescale",e.timescale||1).set("duration",e.media_duration||0).set("language",e.language||"und"),n.add("hdlr").set("handler",e.hdlr||"vide").set("name",e.name||"Track created with MP4Box.js"),n.add("elng").set("extended_language",e.language||"fr-FR");var a=n.add("minf");if(s[e.type+"SampleEntry"]!==void 0){var u=new s[e.type+"SampleEntry"];u.data_reference_index=1;var p="";for(var _ in s.sampleEntryCodes)for(var U=s.sampleEntryCodes[_],S=0;S<U.length;S++)if(U.indexOf(e.type)>-1){p=_;break}switch(p){case"Visual":if(a.add("vmhd").set("graphicsmode",0).set("opcolor",[0,0,0]),u.set("width",e.width).set("height",e.height).set("horizresolution",72<<16).set("vertresolution",72<<16).set("frame_count",1).set("compressorname",e.type+" Compressor").set("depth",24),e.avcDecoderConfigRecord){var b=new s.avcCBox;b.parse(new h(e.avcDecoderConfigRecord)),u.addBox(b)}else if(e.hevcDecoderConfigRecord){var E=new s.hvcCBox;E.parse(new h(e.hevcDecoderConfigRecord)),u.addBox(E)}break;case"Audio":a.add("smhd").set("balance",e.balance||0),u.set("channel_count",e.channel_count||2).set("samplesize",e.samplesize||16).set("samplerate",e.samplerate||65536);break;case"Hint":a.add("hmhd");break;case"Subtitle":switch(a.add("sthd"),e.type){case"stpp":u.set("namespace",e.namespace||"nonamespace").set("schema_location",e.schema_location||"").set("auxiliary_mime_types",e.auxiliary_mime_types||"");break}break;case"Metadata":a.add("nmhd");break;case"System":a.add("nmhd");break;default:a.add("nmhd");break}e.description&&u.addBox(e.description),e.description_boxes&&e.description_boxes.forEach(function(F){u.addBox(F)}),a.add("dinf").add("dref").addEntry(new s["url Box"]().set("flags",1));var B=a.add("stbl");return B.add("stsd").addEntry(u),B.add("stts").set("sample_counts",[]).set("sample_deltas",[]),B.add("stsc").set("first_chunk",[]).set("samples_per_chunk",[]).set("sample_description_index",[]),B.add("stco").set("chunk_offsets",[]),B.add("stsz").set("sample_sizes",[]),this.moov.mvex.add("trex").set("track_id",e.id).set("default_sample_description_index",e.default_sample_description_index||1).set("default_sample_duration",e.default_sample_duration||0).set("default_sample_size",e.default_sample_size||0).set("default_sample_flags",e.default_sample_flags||0),this.buildTrakSampleLists(r),e.id}},s.Box.prototype.computeSize=function(t){var e=t||new o;e.endianness=o.BIG_ENDIAN,this.write(e)},y.prototype.addSample=function(t,e,r){var n=r||{},a={},u=this.getTrackById(t);if(u!==null){a.number=u.samples.length,a.track_id=u.tkhd.track_id,a.timescale=u.mdia.mdhd.timescale,a.description_index=n.sample_description_index?n.sample_description_index-1:0,a.description=u.mdia.minf.stbl.stsd.entries[a.description_index],a.data=e,a.size=e.byteLength,a.alreadyRead=a.size,a.duration=n.duration||1,a.cts=n.cts||0,a.dts=n.dts||0,a.is_sync=n.is_sync||!1,a.is_leading=n.is_leading||0,a.depends_on=n.depends_on||0,a.is_depended_on=n.is_depended_on||0,a.has_redundancy=n.has_redundancy||0,a.degradation_priority=n.degradation_priority||0,a.offset=0,a.subsamples=n.subsamples,u.samples.push(a),u.samples_size+=a.size,u.samples_duration+=a.duration,u.first_dts===void 0&&(u.first_dts=n.dts),this.processSamples();var p=this.createSingleSampleMoof(a);return this.addBox(p),p.computeSize(),p.trafs[0].truns[0].data_offset=p.size+8,this.add("mdat").data=new Uint8Array(e),a}},y.prototype.createSingleSampleMoof=function(t){var e=0;t.is_sync?e=1<<25:e=65536;var r=new s.moofBox;r.add("mfhd").set("sequence_number",this.nextMoofNumber),this.nextMoofNumber++;var n=r.add("traf"),a=this.getTrackById(t.track_id);return n.add("tfhd").set("track_id",t.track_id).set("flags",s.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),n.add("tfdt").set("baseMediaDecodeTime",t.dts-(a.first_dts||0)),n.add("trun").set("flags",s.TRUN_FLAGS_DATA_OFFSET|s.TRUN_FLAGS_DURATION|s.TRUN_FLAGS_SIZE|s.TRUN_FLAGS_FLAGS|s.TRUN_FLAGS_CTS_OFFSET).set("data_offset",0).set("first_sample_flags",0).set("sample_count",1).set("sample_duration",[t.duration]).set("sample_size",[t.size]).set("sample_flags",[e]).set("sample_composition_time_offset",[t.cts-t.dts]),r},y.prototype.lastMoofIndex=0,y.prototype.samplesDataSize=0,y.prototype.resetTables=function(){var t,e,r,n,a,u,p,_;for(this.initial_duration=this.moov.mvhd.duration,this.moov.mvhd.duration=0,t=0;t<this.moov.traks.length;t++){e=this.moov.traks[t],e.tkhd.duration=0,e.mdia.mdhd.duration=0,r=e.mdia.minf.stbl.stco||e.mdia.minf.stbl.co64,r.chunk_offsets=[],n=e.mdia.minf.stbl.stsc,n.first_chunk=[],n.samples_per_chunk=[],n.sample_description_index=[],a=e.mdia.minf.stbl.stsz||e.mdia.minf.stbl.stz2,a.sample_sizes=[],u=e.mdia.minf.stbl.stts,u.sample_counts=[],u.sample_deltas=[],p=e.mdia.minf.stbl.ctts,p&&(p.sample_counts=[],p.sample_offsets=[]),_=e.mdia.minf.stbl.stss;var U=e.mdia.minf.stbl.boxes.indexOf(_);U!=-1&&(e.mdia.minf.stbl.boxes[U]=null)}},y.initSampleGroups=function(t,e,r,n,a){var u,p,_,U;function S(b,E,B){this.grouping_type=b,this.grouping_type_parameter=E,this.sbgp=B,this.last_sample_in_run=-1,this.entry_index=-1}for(e&&(e.sample_groups_info=[]),t.sample_groups_info||(t.sample_groups_info=[]),p=0;p<r.length;p++){for(U=r[p].grouping_type+"/"+r[p].grouping_type_parameter,_=new S(r[p].grouping_type,r[p].grouping_type_parameter,r[p]),e&&(e.sample_groups_info[U]=_),t.sample_groups_info[U]||(t.sample_groups_info[U]=_),u=0;u<n.length;u++)n[u].grouping_type===r[p].grouping_type&&(_.description=n[u],_.description.used=!0);if(a)for(u=0;u<a.length;u++)a[u].grouping_type===r[p].grouping_type&&(_.fragment_description=a[u],_.fragment_description.used=!0,_.is_fragment=!0)}if(e){if(a)for(p=0;p<a.length;p++)!a[p].used&&a[p].version>=2&&(U=a[p].grouping_type+"/0",_=new S(a[p].grouping_type,0),_.is_fragment=!0,e.sample_groups_info[U]||(e.sample_groups_info[U]=_))}else for(p=0;p<n.length;p++)!n[p].used&&n[p].version>=2&&(U=n[p].grouping_type+"/0",_=new S(n[p].grouping_type,0),t.sample_groups_info[U]||(t.sample_groups_info[U]=_))},y.setSampleGroupProperties=function(t,e,r,n){var a,u;e.sample_groups=[];for(a in n)if(e.sample_groups[a]={},e.sample_groups[a].grouping_type=n[a].grouping_type,e.sample_groups[a].grouping_type_parameter=n[a].grouping_type_parameter,r>=n[a].last_sample_in_run&&(n[a].last_sample_in_run<0&&(n[a].last_sample_in_run=0),n[a].entry_index++,n[a].entry_index<=n[a].sbgp.entries.length-1&&(n[a].last_sample_in_run+=n[a].sbgp.entries[n[a].entry_index].sample_count)),n[a].entry_index<=n[a].sbgp.entries.length-1?e.sample_groups[a].group_description_index=n[a].sbgp.entries[n[a].entry_index].group_description_index:e.sample_groups[a].group_description_index=-1,e.sample_groups[a].group_description_index!==0){var p;n[a].fragment_description?p=n[a].fragment_description:p=n[a].description,e.sample_groups[a].group_description_index>0?(e.sample_groups[a].group_description_index>65535?u=(e.sample_groups[a].group_description_index>>16)-1:u=e.sample_groups[a].group_description_index-1,p&&u>=0&&(e.sample_groups[a].description=p.entries[u])):p&&p.version>=2&&p.default_group_description_index>0&&(e.sample_groups[a].description=p.entries[p.default_group_description_index-1])}},y.process_sdtp=function(t,e,r){e&&(t?(e.is_leading=t.is_leading[r],e.depends_on=t.sample_depends_on[r],e.is_depended_on=t.sample_is_depended_on[r],e.has_redundancy=t.sample_has_redundancy[r]):(e.is_leading=0,e.depends_on=0,e.is_depended_on=0,e.has_redundancy=0))},y.prototype.buildSampleLists=function(){var t,e;for(t=0;t<this.moov.traks.length;t++)e=this.moov.traks[t],this.buildTrakSampleLists(e)},y.prototype.buildTrakSampleLists=function(t){var e,r,n,a,u,p,_,U,S,b,E,B,F,I,z,M,G,k,P,N,Y,j,R,O;if(t.samples=[],t.samples_duration=0,t.samples_size=0,r=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64,n=t.mdia.minf.stbl.stsc,a=t.mdia.minf.stbl.stsz||t.mdia.minf.stbl.stz2,u=t.mdia.minf.stbl.stts,p=t.mdia.minf.stbl.ctts,_=t.mdia.minf.stbl.stss,U=t.mdia.minf.stbl.stsd,S=t.mdia.minf.stbl.subs,B=t.mdia.minf.stbl.stdp,b=t.mdia.minf.stbl.sbgps,E=t.mdia.minf.stbl.sgpds,k=-1,P=-1,N=-1,Y=-1,j=0,R=0,O=0,y.initSampleGroups(t,null,b,E),!(typeof a>"u")){for(e=0;e<a.sample_sizes.length;e++){var T={};T.number=e,T.track_id=t.tkhd.track_id,T.timescale=t.mdia.mdhd.timescale,T.alreadyRead=0,t.samples[e]=T,T.size=a.sample_sizes[e],t.samples_size+=T.size,e===0?(I=1,F=0,T.chunk_index=I,T.chunk_run_index=F,G=n.samples_per_chunk[F],M=0,F+1<n.first_chunk.length?z=n.first_chunk[F+1]-1:z=1/0):e<G?(T.chunk_index=I,T.chunk_run_index=F):(I++,T.chunk_index=I,M=0,I<=z||(F++,F+1<n.first_chunk.length?z=n.first_chunk[F+1]-1:z=1/0),T.chunk_run_index=F,G+=n.samples_per_chunk[F]),T.description_index=n.sample_description_index[T.chunk_run_index]-1,T.description=U.entries[T.description_index],T.offset=r.chunk_offsets[T.chunk_index-1]+M,M+=T.size,e>k&&(P++,k<0&&(k=0),k+=u.sample_counts[P]),e>0?(t.samples[e-1].duration=u.sample_deltas[P],t.samples_duration+=t.samples[e-1].duration,T.dts=t.samples[e-1].dts+t.samples[e-1].duration):T.dts=0,p?(e>=N&&(Y++,N<0&&(N=0),N+=p.sample_counts[Y]),T.cts=t.samples[e].dts+p.sample_offsets[Y]):T.cts=T.dts,_?(e==_.sample_numbers[j]-1?(T.is_sync=!0,j++):(T.is_sync=!1,T.degradation_priority=0),S&&S.entries[R].sample_delta+O==e+1&&(T.subsamples=S.entries[R].subsamples,O+=S.entries[R].sample_delta,R++)):T.is_sync=!0,y.process_sdtp(t.mdia.minf.stbl.sdtp,T,T.number),B?T.degradation_priority=B.priority[e]:T.degradation_priority=0,S&&S.entries[R].sample_delta+O==e&&(T.subsamples=S.entries[R].subsamples,O+=S.entries[R].sample_delta),(b.length>0||E.length>0)&&y.setSampleGroupProperties(t,T,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)}},y.prototype.updateSampleLists=function(){var t,e,r,n,a,u,p,_,U,S,b,E,B,F,I;if(this.moov!==void 0){for(;this.lastMoofIndex<this.moofs.length;)if(U=this.moofs[this.lastMoofIndex],this.lastMoofIndex++,U.type=="moof")for(S=U,t=0;t<S.trafs.length;t++){for(b=S.trafs[t],E=this.getTrackById(b.tfhd.track_id),B=this.getTrexById(b.tfhd.track_id),b.tfhd.flags&s.TFHD_FLAG_SAMPLE_DESC?n=b.tfhd.default_sample_description_index:n=B?B.default_sample_description_index:1,b.tfhd.flags&s.TFHD_FLAG_SAMPLE_DUR?a=b.tfhd.default_sample_duration:a=B?B.default_sample_duration:0,b.tfhd.flags&s.TFHD_FLAG_SAMPLE_SIZE?u=b.tfhd.default_sample_size:u=B?B.default_sample_size:0,b.tfhd.flags&s.TFHD_FLAG_SAMPLE_FLAGS?p=b.tfhd.default_sample_flags:p=B?B.default_sample_flags:0,b.sample_number=0,b.sbgps.length>0&&y.initSampleGroups(E,b,b.sbgps,E.mdia.minf.stbl.sgpds,b.sgpds),e=0;e<b.truns.length;e++){var z=b.truns[e];for(r=0;r<z.sample_count;r++){F={},F.moof_number=this.lastMoofIndex,F.number_in_traf=b.sample_number,b.sample_number++,F.number=E.samples.length,b.first_sample_index=E.samples.length,E.samples.push(F),F.track_id=E.tkhd.track_id,F.timescale=E.mdia.mdhd.timescale,F.description_index=n-1,F.description=E.mdia.minf.stbl.stsd.entries[F.description_index],F.size=u,z.flags&s.TRUN_FLAGS_SIZE&&(F.size=z.sample_size[r]),E.samples_size+=F.size,F.duration=a,z.flags&s.TRUN_FLAGS_DURATION&&(F.duration=z.sample_duration[r]),E.samples_duration+=F.duration,E.first_traf_merged||r>0?F.dts=E.samples[E.samples.length-2].dts+E.samples[E.samples.length-2].duration:(b.tfdt?F.dts=b.tfdt.baseMediaDecodeTime:F.dts=0,E.first_traf_merged=!0),F.cts=F.dts,z.flags&s.TRUN_FLAGS_CTS_OFFSET&&(F.cts=F.dts+z.sample_composition_time_offset[r]),I=p,z.flags&s.TRUN_FLAGS_FLAGS?I=z.sample_flags[r]:r===0&&z.flags&s.TRUN_FLAGS_FIRST_FLAG&&(I=z.first_sample_flags),F.is_sync=!(I>>16&1),F.is_leading=I>>26&3,F.depends_on=I>>24&3,F.is_depended_on=I>>22&3,F.has_redundancy=I>>20&3,F.degradation_priority=I&65535;var M=!!(b.tfhd.flags&s.TFHD_FLAG_BASE_DATA_OFFSET),G=!!(b.tfhd.flags&s.TFHD_FLAG_DEFAULT_BASE_IS_MOOF),k=!!(z.flags&s.TRUN_FLAGS_DATA_OFFSET),P=0;M?P=b.tfhd.base_data_offset:G||e===0?P=S.start:P=_,e===0&&r===0?k?F.offset=P+z.data_offset:F.offset=P:F.offset=_,_=F.offset+F.size,(b.sbgps.length>0||b.sgpds.length>0||E.mdia.minf.stbl.sbgps.length>0||E.mdia.minf.stbl.sgpds.length>0)&&y.setSampleGroupProperties(E,F,F.number_in_traf,b.sample_groups_info)}}if(b.subs){E.has_fragment_subsamples=!0;var N=b.first_sample_index;for(e=0;e<b.subs.entries.length;e++)N+=b.subs.entries[e].sample_delta,F=E.samples[N-1],F.subsamples=b.subs.entries[e].subsamples}}}},y.prototype.getSample=function(t,e){var r,n=t.samples[e];if(!this.moov)return null;if(!n.data)n.data=new Uint8Array(n.size),n.alreadyRead=0,this.samplesDataSize+=n.size,f.debug("ISOFile","Allocating sample #"+e+" on track #"+t.tkhd.track_id+" of size "+n.size+" (total: "+this.samplesDataSize+")");else if(n.alreadyRead==n.size)return n;for(;;){var a=this.stream.findPosition(!0,n.offset+n.alreadyRead,!1);if(a>-1){r=this.stream.buffers[a];var u=r.byteLength-(n.offset+n.alreadyRead-r.fileStart);if(n.size-n.alreadyRead<=u)return f.debug("ISOFile","Getting sample #"+e+" data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-r.fileStart)+" read size: "+(n.size-n.alreadyRead)+" full size: "+n.size+")"),o.memcpy(n.data.buffer,n.alreadyRead,r,n.offset+n.alreadyRead-r.fileStart,n.size-n.alreadyRead),r.usedBytes+=n.size-n.alreadyRead,this.stream.logBufferLevel(),n.alreadyRead=n.size,n;if(u===0)return null;f.debug("ISOFile","Getting sample #"+e+" partial data (alreadyRead: "+n.alreadyRead+" offset: "+(n.offset+n.alreadyRead-r.fileStart)+" read size: "+u+" full size: "+n.size+")"),o.memcpy(n.data.buffer,n.alreadyRead,r,n.offset+n.alreadyRead-r.fileStart,u),n.alreadyRead+=u,r.usedBytes+=u,this.stream.logBufferLevel()}else return null}},y.prototype.releaseSample=function(t,e){var r=t.samples[e];return r.data?(this.samplesDataSize-=r.size,r.data=null,r.alreadyRead=0,r.size):0},y.prototype.getAllocatedSampleDataSize=function(){return this.samplesDataSize},y.prototype.getCodecs=function(){var t,e="";for(t=0;t<this.moov.traks.length;t++){var r=this.moov.traks[t];t>0&&(e+=","),e+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return e},y.prototype.getTrexById=function(t){var e;if(!this.moov||!this.moov.mvex)return null;for(e=0;e<this.moov.mvex.trexs.length;e++){var r=this.moov.mvex.trexs[e];if(r.track_id==t)return r}return null},y.prototype.getTrackById=function(t){if(this.moov===void 0)return null;for(var e=0;e<this.moov.traks.length;e++){var r=this.moov.traks[e];if(r.tkhd.track_id==t)return r}return null},y.prototype.itemsDataSize=0,y.prototype.flattenItemInfo=function(){var t=this.items,e=this.entity_groups,r,n,a,u=this.meta;if(u!=null&&u.hdlr!==void 0&&u.iinf!==void 0){for(r=0;r<u.iinf.item_infos.length;r++)a={},a.id=u.iinf.item_infos[r].item_ID,t[a.id]=a,a.ref_to=[],a.name=u.iinf.item_infos[r].item_name,u.iinf.item_infos[r].protection_index>0&&(a.protection=u.ipro.protections[u.iinf.item_infos[r].protection_index-1]),u.iinf.item_infos[r].item_type?a.type=u.iinf.item_infos[r].item_type:a.type="mime",a.content_type=u.iinf.item_infos[r].content_type,a.content_encoding=u.iinf.item_infos[r].content_encoding;if(u.grpl)for(r=0;r<u.grpl.boxes.length;r++)entity_group={},entity_group.id=u.grpl.boxes[r].group_id,entity_group.entity_ids=u.grpl.boxes[r].entity_ids,entity_group.type=u.grpl.boxes[r].type,e[entity_group.id]=entity_group;if(u.iloc)for(r=0;r<u.iloc.items.length;r++){var p=u.iloc.items[r];switch(a=t[p.item_ID],p.data_reference_index!==0&&(f.warn("Item storage with reference to other files: not supported"),a.source=u.dinf.boxes[p.data_reference_index-1]),p.construction_method){case 0:break;case 1:break;case 2:f.warn("Item storage with construction_method : not supported");break}for(a.extents=[],a.size=0,n=0;n<p.extents.length;n++)a.extents[n]={},a.extents[n].offset=p.extents[n].extent_offset+p.base_offset,p.construction_method==1&&(a.extents[n].offset+=u.idat.start+u.idat.hdr_size),a.extents[n].length=p.extents[n].extent_length,a.extents[n].alreadyRead=0,a.size+=a.extents[n].length}if(u.pitm&&(t[u.pitm.item_id].primary=!0),u.iref)for(r=0;r<u.iref.references.length;r++){var _=u.iref.references[r];for(n=0;n<_.references.length;n++)t[_.from_item_ID].ref_to.push({type:_.type,id:_.references[n]})}if(u.iprp)for(var U=0;U<u.iprp.ipmas.length;U++){var S=u.iprp.ipmas[U];for(r=0;r<S.associations.length;r++){var b=S.associations[r];if(a=t[b.id],a||(a=e[b.id]),a)for(a.properties===void 0&&(a.properties={},a.properties.boxes=[]),n=0;n<b.props.length;n++){var E=b.props[n];if(E.property_index>0&&E.property_index-1<u.iprp.ipco.boxes.length){var B=u.iprp.ipco.boxes[E.property_index-1];a.properties[B.type]=B,a.properties.boxes.push(B)}}}}}},y.prototype.getItem=function(t){var e,r;if(!this.meta)return null;if(r=this.items[t],!r.data&&r.size)r.data=new Uint8Array(r.size),r.alreadyRead=0,this.itemsDataSize+=r.size,f.debug("ISOFile","Allocating item #"+t+" of size "+r.size+" (total: "+this.itemsDataSize+")");else if(r.alreadyRead===r.size)return r;for(var n=0;n<r.extents.length;n++){var a=r.extents[n];if(a.alreadyRead!==a.length){var u=this.stream.findPosition(!0,a.offset+a.alreadyRead,!1);if(u>-1){e=this.stream.buffers[u];var p=e.byteLength-(a.offset+a.alreadyRead-e.fileStart);if(a.length-a.alreadyRead<=p)f.debug("ISOFile","Getting item #"+t+" extent #"+n+" data (alreadyRead: "+a.alreadyRead+" offset: "+(a.offset+a.alreadyRead-e.fileStart)+" read size: "+(a.length-a.alreadyRead)+" full extent size: "+a.length+" full item size: "+r.size+")"),o.memcpy(r.data.buffer,r.alreadyRead,e,a.offset+a.alreadyRead-e.fileStart,a.length-a.alreadyRead),e.usedBytes+=a.length-a.alreadyRead,this.stream.logBufferLevel(),r.alreadyRead+=a.length-a.alreadyRead,a.alreadyRead=a.length;else return f.debug("ISOFile","Getting item #"+t+" extent #"+n+" partial data (alreadyRead: "+a.alreadyRead+" offset: "+(a.offset+a.alreadyRead-e.fileStart)+" read size: "+p+" full extent size: "+a.length+" full item size: "+r.size+")"),o.memcpy(r.data.buffer,r.alreadyRead,e,a.offset+a.alreadyRead-e.fileStart,p),a.alreadyRead+=p,r.alreadyRead+=p,e.usedBytes+=p,this.stream.logBufferLevel(),null}else return null}}return r.alreadyRead===r.size?r:null},y.prototype.releaseItem=function(t){var e=this.items[t];if(e.data){this.itemsDataSize-=e.size,e.data=null,e.alreadyRead=0;for(var r=0;r<e.extents.length;r++){var n=e.extents[r];n.alreadyRead=0}return e.size}else return 0},y.prototype.processItems=function(t){for(var e in this.items){var r=this.items[e];this.getItem(r.id),t&&!r.sent&&(t(r),r.sent=!0,r.data=null)}},y.prototype.hasItem=function(t){for(var e in this.items){var r=this.items[e];if(r.name===t)return r.id}return-1},y.prototype.getMetaHandler=function(){return this.meta?this.meta.hdlr.handler:null},y.prototype.getPrimaryItem=function(){return!this.meta||!this.meta.pitm?null:this.getItem(this.meta.pitm.item_id)},y.prototype.itemToFragmentedTrackFile=function(t){var e=t||{},r=null;if(e.itemId?r=this.getItem(e.itemId):r=this.getPrimaryItem(),r==null)return null;var n=new y;n.discardMdatData=!1;var a={type:r.type,description_boxes:r.properties.boxes};r.properties.ispe&&(a.width=r.properties.ispe.image_width,a.height=r.properties.ispe.image_height);var u=n.addTrack(a);return u?(n.addSample(u,r.data),n):null},y.prototype.write=function(t){for(var e=0;e<this.boxes.length;e++)this.boxes[e].write(t)},y.prototype.createFragment=function(t,e,r){var n=this.getTrackById(t),a=this.getSample(n,e);if(a==null)return this.setNextSeekPositionFromSample(n.samples[e]),null;var u=r||new o;u.endianness=o.BIG_ENDIAN;var p=this.createSingleSampleMoof(a);p.write(u),p.trafs[0].truns[0].data_offset=p.size+8,f.debug("MP4Box","Adjusting data_offset with new value "+p.trafs[0].truns[0].data_offset),u.adjustUint32(p.trafs[0].truns[0].data_offset_position,p.trafs[0].truns[0].data_offset);var _=new s.mdatBox;return _.data=a.data,_.write(u),u},y.writeInitializationSegment=function(t,e,r,n){var a;f.debug("ISOFile","Generating initialization segment");var u=new o;u.endianness=o.BIG_ENDIAN,t.write(u);var p=e.add("mvex");for(r&&p.add("mehd").set("fragment_duration",r),a=0;a<e.traks.length;a++)p.add("trex").set("track_id",e.traks[a].tkhd.track_id).set("default_sample_description_index",1).set("default_sample_duration",n).set("default_sample_size",0).set("default_sample_flags",65536);return e.write(u),u.buffer},y.prototype.save=function(t){var e=new o;e.endianness=o.BIG_ENDIAN,this.write(e),e.save(t)},y.prototype.getBuffer=function(){var t=new o;return t.endianness=o.BIG_ENDIAN,this.write(t),t.buffer},y.prototype.initializeSegmentation=function(){var t,e,r,n;for(this.onSegment===null&&f.warn("MP4Box","No segmentation callback set!"),this.isFragmentationInitialized||(this.isFragmentationInitialized=!0,this.nextMoofNumber=0,this.resetTables()),e=[],t=0;t<this.fragmentedTracks.length;t++){var a=new s.moovBox;a.mvhd=this.moov.mvhd,a.boxes.push(a.mvhd),r=this.getTrackById(this.fragmentedTracks[t].id),a.boxes.push(r),a.traks.push(r),n={},n.id=r.tkhd.track_id,n.user=this.fragmentedTracks[t].user,n.buffer=y.writeInitializationSegment(this.ftyp,a,this.moov.mvex&&this.moov.mvex.mehd?this.moov.mvex.mehd.fragment_duration:void 0,this.moov.traks[t].samples.length>0?this.moov.traks[t].samples[0].duration:0),e.push(n)}return e},s.Box.prototype.printHeader=function(t){this.size+=8,this.size>d&&(this.size+=8),this.type==="uuid"&&(this.size+=16),t.log(t.indent+"size:"+this.size),t.log(t.indent+"type:"+this.type)},s.FullBox.prototype.printHeader=function(t){this.size+=4,s.Box.prototype.printHeader.call(this,t),t.log(t.indent+"version:"+this.version),t.log(t.indent+"flags:"+this.flags)},s.Box.prototype.print=function(t){this.printHeader(t)},s.ContainerBox.prototype.print=function(t){this.printHeader(t);for(var e=0;e<this.boxes.length;e++)if(this.boxes[e]){var r=t.indent;t.indent+=" ",this.boxes[e].print(t),t.indent=r}},y.prototype.print=function(t){t.indent="";for(var e=0;e<this.boxes.length;e++)this.boxes[e]&&this.boxes[e].print(t)},s.mvhdBox.prototype.print=function(t){s.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"timescale: "+this.timescale),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"rate: "+this.rate),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"next_track_id: "+this.next_track_id)},s.tkhdBox.prototype.print=function(t){s.FullBox.prototype.printHeader.call(this,t),t.log(t.indent+"creation_time: "+this.creation_time),t.log(t.indent+"modification_time: "+this.modification_time),t.log(t.indent+"track_id: "+this.track_id),t.log(t.indent+"duration: "+this.duration),t.log(t.indent+"volume: "+(this.volume>>8)),t.log(t.indent+"matrix: "+this.matrix.join(", ")),t.log(t.indent+"layer: "+this.layer),t.log(t.indent+"alternate_group: "+this.alternate_group),t.log(t.indent+"width: "+this.width),t.log(t.indent+"height: "+this.height)};var A={};A.createFile=function(t,e){var r=t!==void 0?t:!0,n=new y(e);return n.discardMdatData=!r,n},C.createFile=A.createFile}(K)),K}var Z=et(),it=X(Z),W={exports:{}},$;function rt(){return $||($=1,function(C){var f={};C.exports=f,f.parse=function(h,o){for(var d=f.bin.readUshort,l=f.bin.readUint,v=0,c={},s=new Uint8Array(h),g=s.length-4;l(s,g)!=101010256;)g--;var v=g;v+=4,v+=4;var x=d(s,v);v+=2,d(s,v),v+=2;var m=l(s,v);v+=4;var w=l(s,v);v+=4,v=w;for(var y=0;y<x;y++){l(s,v),v+=4,v+=4,v+=4,v+=4,l(s,v),v+=4;var m=l(s,v);v+=4;var A=l(s,v);v+=4;var t=d(s,v),e=d(s,v+2),r=d(s,v+4);v+=6,v+=8;var n=l(s,v);v+=4,v+=t+e+r,f._readLocal(s,n,c,m,A,o)}return c},f._readLocal=function(h,o,d,l,c,s){var g=f.bin.readUshort,v=f.bin.readUint;v(h,o),o+=4,g(h,o),o+=2,g(h,o),o+=2;var x=g(h,o);o+=2,v(h,o),o+=4,v(h,o),o+=4,o+=8;var m=g(h,o);o+=2;var w=g(h,o);o+=2;var y=f.bin.readUTF8(h,o,m);if(o+=m,o+=w,s){d[y]={size:c,csize:l};return}var A=new Uint8Array(h.buffer,o);if(x==0)d[y]=new Uint8Array(A.buffer.slice(o,o+l));else if(x==8){var t=new Uint8Array(c);f.inflateRaw(A,t),d[y]=t}else throw"unknown compression method: "+x},f.inflateRaw=function(h,o){return f.F.inflate(h,o)},f.inflate=function(h,o){return h[0],h[1],f.inflateRaw(new Uint8Array(h.buffer,h.byteOffset+2,h.length-6),o)},f.deflate=function(h,o){o==null&&(o={level:6});var d=0,l=new Uint8Array(50+Math.floor(h.length*1.1));l[d]=120,l[d+1]=156,d+=2,d=f.F.deflateRaw(h,l,d,o.level);var c=f.adler(h,0,h.length);return l[d+0]=c>>>24&255,l[d+1]=c>>>16&255,l[d+2]=c>>>8&255,l[d+3]=c>>>0&255,new Uint8Array(l.buffer,0,d+4)},f.deflateRaw=function(h,o){o==null&&(o={level:6});var d=new Uint8Array(50+Math.floor(h.length*1.1)),l=f.F.deflateRaw(h,d,l,o.level);return new Uint8Array(d.buffer,0,l)},f.encode=function(h,o){o==null&&(o=!1);var d=0,l=f.bin.writeUint,c=f.bin.writeUshort,s={};for(var g in h){var v=!f._noNeed(g)&&!o,x=h[g],m=f.crc.crc(x,0,x.length);s[g]={cpr:v,usize:x.length,crc:m,file:v?f.deflateRaw(x):x}}for(var g in s)d+=s[g].file.length+30+46+2*f.bin.sizeUTF8(g);d+=22;var w=new Uint8Array(d),y=0,A=[];for(var g in s){var t=s[g];A.push(y),y=f._writeHeader(w,y,g,t,0)}var e=0,r=y;for(var g in s){var t=s[g];A.push(y),y=f._writeHeader(w,y,g,t,1,A[e++])}var n=y-r;return l(w,y,101010256),y+=4,y+=4,c(w,y,e),y+=2,c(w,y,e),y+=2,l(w,y,n),y+=4,l(w,y,r),y+=4,y+=2,w.buffer},f._noNeed=function(h){var o=h.split(".").pop().toLowerCase();return"png,jpg,jpeg,zip".indexOf(o)!=-1},f._writeHeader=function(h,o,d,l,c,s){var g=f.bin.writeUint,v=f.bin.writeUshort,x=l.file;g(h,o,c==0?67324752:33639248),o+=4,c==1&&(o+=2),v(h,o,20),o+=2,v(h,o,0),o+=2,v(h,o,l.cpr?8:0),o+=2,g(h,o,0),o+=4,g(h,o,l.crc),o+=4,g(h,o,x.length),o+=4,g(h,o,l.usize),o+=4,v(h,o,f.bin.sizeUTF8(d)),o+=2,v(h,o,0),o+=2,c==1&&(o+=2,o+=2,o+=6,g(h,o,s),o+=4);var m=f.bin.writeUTF8(h,o,d);return o+=m,c==0&&(h.set(x,o),o+=x.length),o},f.crc={table:function(){for(var h=new Uint32Array(256),o=0;o<256;o++){for(var d=o,l=0;l<8;l++)d&1?d=3988292384^d>>>1:d=d>>>1;h[o]=d}return h}(),update:function(h,o,d,l){for(var c=0;c<l;c++)h=f.crc.table[(h^o[d+c])&255]^h>>>8;return h},crc:function(h,o,d){return f.crc.update(4294967295,h,o,d)^4294967295}},f.adler=function(h,o,d){for(var l=1,c=0,s=o,g=o+d;s<g;){for(var v=Math.min(s+5552,g);s<v;)l+=h[s++],c+=l;l=l%65521,c=c%65521}return c<<16|l},f.bin={readUshort:function(h,o){return h[o]|h[o+1]<<8},writeUshort:function(h,o,d){h[o]=d&255,h[o+1]=d>>8&255},readUint:function(h,o){return h[o+3]*(256*256*256)+(h[o+2]<<16|h[o+1]<<8|h[o])},writeUint:function(h,o,d){h[o]=d&255,h[o+1]=d>>8&255,h[o+2]=d>>16&255,h[o+3]=d>>24&255},readASCII:function(h,o,d){for(var l="",c=0;c<d;c++)l+=String.fromCharCode(h[o+c]);return l},writeASCII:function(h,o,d){for(var l=0;l<d.length;l++)h[o+l]=d.charCodeAt(l)},pad:function(h){return h.length<2?"0"+h:h},readUTF8:function(h,o,d){for(var l="",c,s=0;s<d;s++)l+="%"+f.bin.pad(h[o+s].toString(16));try{c=decodeURIComponent(l)}catch{return f.bin.readASCII(h,o,d)}return c},writeUTF8:function(h,o,d){for(var l=d.length,c=0,s=0;s<l;s++){var g=d.charCodeAt(s);if(!(g&4294967168))h[o+c]=g,c++;else if(!(g&4294965248))h[o+c]=192|g>>6,h[o+c+1]=128|g>>0&63,c+=2;else if(!(g&4294901760))h[o+c]=224|g>>12,h[o+c+1]=128|g>>6&63,h[o+c+2]=128|g>>0&63,c+=3;else if(!(g&4294967295-(1<<21)+1))h[o+c]=240|g>>18,h[o+c+1]=128|g>>12&63,h[o+c+2]=128|g>>6&63,h[o+c+3]=128|g>>0&63,c+=4;else throw"e"}return c},sizeUTF8:function(h){for(var o=h.length,d=0,l=0;l<o;l++){var c=h.charCodeAt(l);if(!(c&4294967168))d++;else if(!(c&4294965248))d+=2;else if(!(c&4294901760))d+=3;else if(!(c&4294967295-(1<<21)+1))d+=4;else throw"e"}return d}},f.F={},f.F.deflateRaw=function(h,o,d,l){var c=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]],s=c[l],g=f.F.U,v=f.F._goodIndex;f.F._hash;var x=f.F._putsE,m=0,w=d<<3,y=0,A=h.length;if(l==0){for(;m<A;){var t=Math.min(65535,A-m);x(o,w,m+t==A?1:0),w=f.F._copyExact(h,m,t,o,w+8),m+=t}return w>>>3}var e=g.lits,r=g.strt,n=g.prev,a=0,u=0,p=0,_=0,U=0,S=0;for(A>2&&(S=f.F._hash(h,0),r[S]=0),m=0;m<A;m++){if(U=S,m+1<A-2){S=f.F._hash(h,m+1);var b=m+1&32767;n[b]=r[S],r[S]=b}if(y<=m){(a>14e3||u>26697)&&A-m>100&&(y<m&&(e[a]=m-y,a+=2,y=m),w=f.F._writeBlock(m==A-1||y==A?1:0,e,a,_,h,p,m-p,o,w),a=u=_=0,p=m);var E=0;m<A-2&&(E=f.F._bestMatch(h,m,n,U,Math.min(s[2],A-m),s[3]));var t=E>>>16,B=E&65535;if(E!=0){var t=E>>>16,B=E&65535,F=v(t,g.of0);g.lhst[257+F]++;var I=v(B,g.df0);g.dhst[I]++,_+=g.exb[F]+g.dxb[I],e[a]=t<<23|m-y,e[a+1]=B<<16|F<<8|I,a+=2,y=m+t}else g.lhst[h[m]]++;u++}}for((p!=m||h.length==0)&&(y<m&&(e[a]=m-y,a+=2,y=m),w=f.F._writeBlock(1,e,a,_,h,p,m-p,o,w),a=0,u=0,a=u=_=0,p=m);w&7;)w++;return w>>>3},f.F._bestMatch=function(h,o,d,l,c,s){var g=o&32767,v=d[g],x=g-v+32768&32767;if(v==g||l!=f.F._hash(h,o-x))return 0;for(var m=0,w=0,y=Math.min(32767,o);x<=y&&--s!=0&&v!=g;){if(m==0||h[o+m]==h[o+m-x]){var A=f.F._howLong(h,o,x);if(A>m){if(m=A,w=x,m>=c)break;x+2<A&&(A=x+2);for(var t=0,e=0;e<A-2;e++){var r=o-x+e+32768&32767,n=d[r],a=r-n+32768&32767;a>t&&(t=a,v=r)}}}g=v,v=d[g],x+=g-v+32768&32767}return m<<16|w},f.F._howLong=function(h,o,d){if(h[o]!=h[o-d]||h[o+1]!=h[o+1-d]||h[o+2]!=h[o+2-d])return 0;var l=o,c=Math.min(h.length,o+258);for(o+=3;o<c&&h[o]==h[o-d];)o++;return o-l},f.F._hash=function(h,o){return(h[o]<<8|h[o+1])+(h[o+2]<<4)&65535},f.saved=0,f.F._writeBlock=function(h,o,d,l,c,s,g,v,x){var m=f.F.U,w=f.F._putsF,y=f.F._putsE,A,t,e,r,n,a,u,p,_;m.lhst[256]++,A=f.F.getTrees(),t=A[0],e=A[1],r=A[2],n=A[3],a=A[4],u=A[5],p=A[6],_=A[7];var U=(x+3&7?8-(x+3&7):0)+32+(g<<3),S=l+f.F.contSize(m.fltree,m.lhst)+f.F.contSize(m.fdtree,m.dhst),b=l+f.F.contSize(m.ltree,m.lhst)+f.F.contSize(m.dtree,m.dhst);b+=14+3*u+f.F.contSize(m.itree,m.ihst)+(m.ihst[16]*2+m.ihst[17]*3+m.ihst[18]*7);for(var E=0;E<286;E++)m.lhst[E]=0;for(var E=0;E<30;E++)m.dhst[E]=0;for(var E=0;E<19;E++)m.ihst[E]=0;var B=U<S&&U<b?0:S<b?1:2;if(w(v,x,h),w(v,x+1,B),x+=3,B==0){for(;x&7;)x++;x=f.F._copyExact(c,s,g,v,x)}else{var F,I;if(B==1&&(F=m.fltree,I=m.fdtree),B==2){f.F.makeCodes(m.ltree,t),f.F.revCodes(m.ltree,t),f.F.makeCodes(m.dtree,e),f.F.revCodes(m.dtree,e),f.F.makeCodes(m.itree,r),f.F.revCodes(m.itree,r),F=m.ltree,I=m.dtree,y(v,x,n-257),x+=5,y(v,x,a-1),x+=5,y(v,x,u-4),x+=4;for(var z=0;z<u;z++)y(v,x+z*3,m.itree[(m.ordr[z]<<1)+1]);x+=3*u,x=f.F._codeTiny(p,m.itree,v,x),x=f.F._codeTiny(_,m.itree,v,x)}for(var M=s,G=0;G<d;G+=2){for(var k=o[G],P=k>>>23,N=M+(k&(1<<23)-1);M<N;)x=f.F._writeLit(c[M++],F,v,x);if(P!=0){var Y=o[G+1],j=Y>>16,R=Y>>8&255,O=Y&255;x=f.F._writeLit(257+R,F,v,x),y(v,x,P-m.of0[R]),x+=m.exb[R],x=f.F._writeLit(O,I,v,x),w(v,x,j-m.df0[O]),x+=m.dxb[O],M+=P}}x=f.F._writeLit(256,F,v,x)}return x},f.F._copyExact=function(h,o,d,l,c){var s=c>>>3;return l[s]=d,l[s+1]=d>>>8,l[s+2]=255-l[s],l[s+3]=255-l[s+1],s+=4,l.set(new Uint8Array(h.buffer,o,d),s),c+(d+4<<3)},f.F.getTrees=function(){for(var h=f.F.U,o=f.F._hufTree(h.lhst,h.ltree,15),d=f.F._hufTree(h.dhst,h.dtree,15),l=[],c=f.F._lenCodes(h.ltree,l),s=[],g=f.F._lenCodes(h.dtree,s),v=0;v<l.length;v+=2)h.ihst[l[v]]++;for(var v=0;v<s.length;v+=2)h.ihst[s[v]]++;for(var x=f.F._hufTree(h.ihst,h.itree,7),m=19;m>4&&h.itree[(h.ordr[m-1]<<1)+1]==0;)m--;return[o,d,x,c,g,m,l,s]},f.F.getSecond=function(h){for(var o=[],d=0;d<h.length;d+=2)o.push(h[d+1]);return o},f.F.nonZero=function(h){for(var o="",d=0;d<h.length;d+=2)h[d+1]!=0&&(o+=(d>>1)+",");return o},f.F.contSize=function(h,o){for(var d=0,l=0;l<o.length;l++)d+=o[l]*h[(l<<1)+1];return d},f.F._codeTiny=function(h,o,d,l){for(var c=0;c<h.length;c+=2){var s=h[c],g=h[c+1];l=f.F._writeLit(s,o,d,l);var v=s==16?2:s==17?3:7;s>15&&(f.F._putsE(d,l,g,v),l+=v)}return l},f.F._lenCodes=function(h,o){for(var d=h.length;d!=2&&h[d-1]==0;)d-=2;for(var l=0;l<d;l+=2){var c=h[l+1],s=l+3<d?h[l+3]:-1,g=l+5<d?h[l+5]:-1,v=l==0?-1:h[l-1];if(c==0&&s==c&&g==c){for(var x=l+5;x+2<d&&h[x+2]==c;)x+=2;var m=Math.min(x+1-l>>>1,138);m<11?o.push(17,m-3):o.push(18,m-11),l+=m*2-2}else if(c==v&&s==c&&g==c){for(var x=l+5;x+2<d&&h[x+2]==c;)x+=2;var m=Math.min(x+1-l>>>1,6);o.push(16,m-3),l+=m*2-2}else o.push(c,0)}return d>>>1},f.F._hufTree=function(h,o,d){var l=[],c=h.length,s=o.length,g=0;for(g=0;g<s;g+=2)o[g]=0,o[g+1]=0;for(g=0;g<c;g++)h[g]!=0&&l.push({lit:g,f:h[g]});var v=l.length,x=l.slice(0);if(v==0)return 0;if(v==1){var m=l[0].lit,x=m==0?1:0;return o[(m<<1)+1]=1,o[(x<<1)+1]=1,1}l.sort(function(n,a){return n.f-a.f});var w=l[0],y=l[1],A=0,t=1,e=2;for(l[0]={lit:-1,f:w.f+y.f,l:w,r:y,d:0};t!=v-1;)A!=t&&(e==v||l[A].f<l[e].f)?w=l[A++]:w=l[e++],A!=t&&(e==v||l[A].f<l[e].f)?y=l[A++]:y=l[e++],l[t++]={lit:-1,f:w.f+y.f,l:w,r:y};var r=f.F.setDepth(l[t-1],0);for(r>d&&(f.F.restrictDepth(x,d,r),r=d),g=0;g<v;g++)o[(x[g].lit<<1)+1]=x[g].d;return r},f.F.setDepth=function(h,o){return h.lit!=-1?(h.d=o,o):Math.max(f.F.setDepth(h.l,o+1),f.F.setDepth(h.r,o+1))},f.F.restrictDepth=function(h,o,d){var l=0,c=1<<d-o,s=0;for(h.sort(function(v,x){return x.d==v.d?v.f-x.f:x.d-v.d}),l=0;l<h.length&&h[l].d>o;l++){var g=h[l].d;h[l].d=o,s+=c-(1<<d-g)}for(s=s>>>d-o;s>0;){var g=h[l].d;g<o?(h[l].d++,s-=1<<o-g-1):l++}for(;l>=0;l--)h[l].d==o&&s<0&&(h[l].d--,s++);s!=0&&console.log("debt left")},f.F._goodIndex=function(h,o){var d=0;return o[d|16]<=h&&(d|=16),o[d|8]<=h&&(d|=8),o[d|4]<=h&&(d|=4),o[d|2]<=h&&(d|=2),o[d|1]<=h&&(d|=1),d},f.F._writeLit=function(h,o,d,l){return f.F._putsF(d,l,o[h<<1]),l+o[(h<<1)+1]},f.F.inflate=function(h,o){var d=Uint8Array;if(h[0]==3&&h[1]==0)return o||new d(0);var l=f.F,c=l._bitsF,s=l._bitsE,g=l._decodeTiny,v=l.makeCodes,x=l.codes2map,m=l._get17,w=l.U,y=o==null;y&&(o=new d(h.length>>>2<<3));for(var A=0,t=0,e=0,r=0,n=0,a=0,u=0,p=0,_=0,U,S;A==0;){if(A=c(h,_,1),t=c(h,_+1,2),_+=3,t==0){_&7&&(_+=8-(_&7));var b=(_>>>3)+4,E=h[b-4]|h[b-3]<<8;y&&(o=f.F._check(o,p+E)),o.set(new d(h.buffer,h.byteOffset+b,E),p),_=b+E<<3,p+=E;continue}if(y&&(o=f.F._check(o,p+(1<<17))),t==1&&(U=w.flmap,S=w.fdmap,a=511,u=31),t==2){e=s(h,_,5)+257,r=s(h,_+5,5)+1,n=s(h,_+10,4)+4,_+=14;for(var B=0;B<38;B+=2)w.itree[B]=0,w.itree[B+1]=0;for(var F=1,B=0;B<n;B++){var I=s(h,_+B*3,3);w.itree[(w.ordr[B]<<1)+1]=I,I>F&&(F=I)}_+=3*n,v(w.itree,F),x(w.itree,F,w.imap),U=w.lmap,S=w.dmap,_=g(w.imap,(1<<F)-1,e+r,h,_,w.ttree);var z=l._copyOut(w.ttree,0,e,w.ltree);a=(1<<z)-1;var M=l._copyOut(w.ttree,e,r,w.dtree);u=(1<<M)-1,v(w.ltree,z),x(w.ltree,z,U),v(w.dtree,M),x(w.dtree,M,S)}for(;;){var G=U[m(h,_)&a];_+=G&15;var k=G>>>4;if(!(k>>>8))o[p++]=k;else{if(k==256)break;var P=p+k-254;if(k>264){var N=w.ldef[k-257];P=p+(N>>>3)+s(h,_,N&7),_+=N&7}var Y=S[m(h,_)&u];_+=Y&15;var j=Y>>>4,R=w.ddef[j],O=(R>>>4)+c(h,_,R&15);for(_+=R&15,y&&(o=f.F._check(o,p+(1<<17)));p<P;)o[p]=o[p++-O],o[p]=o[p++-O],o[p]=o[p++-O],o[p]=o[p++-O];p=P}}}return o.length==p?o:o.slice(0,p)},f.F._check=function(h,o){var d=h.length;if(o<=d)return h;var l=new Uint8Array(Math.max(d<<1,o));return l.set(h,0),l},f.F._decodeTiny=function(h,o,d,l,c,s){for(var g=f.F._bitsE,v=f.F._get17,x=0;x<d;){var m=h[v(l,c)&o];c+=m&15;var w=m>>>4;if(w<=15)s[x]=w,x++;else{var y=0,A=0;w==16?(A=3+g(l,c,2),c+=2,y=s[x-1]):w==17?(A=3+g(l,c,3),c+=3):w==18&&(A=11+g(l,c,7),c+=7);for(var t=x+A;x<t;)s[x]=y,x++}}return c},f.F._copyOut=function(h,o,d,l){for(var c=0,s=0,g=l.length>>>1;s<d;){var v=h[s+o];l[s<<1]=0,l[(s<<1)+1]=v,v>c&&(c=v),s++}for(;s<g;)l[s<<1]=0,l[(s<<1)+1]=0,s++;return c},f.F.makeCodes=function(h,o){for(var d=f.F.U,l=h.length,c,s,g,v,x,m=d.bl_count,v=0;v<=o;v++)m[v]=0;for(v=1;v<l;v+=2)m[h[v]]++;var w=d.next_code;for(c=0,m[0]=0,s=1;s<=o;s++)c=c+m[s-1]<<1,w[s]=c;for(g=0;g<l;g+=2)x=h[g+1],x!=0&&(h[g]=w[x],w[x]++)},f.F.codes2map=function(h,o,d){for(var l=h.length,c=f.F.U,s=c.rev15,g=0;g<l;g+=2)if(h[g+1]!=0)for(var v=g>>1,x=h[g+1],m=v<<4|x,w=o-x,y=h[g]<<w,A=y+(1<<w);y!=A;){var t=s[y]>>>15-o;d[t]=m,y++}},f.F.revCodes=function(h,o){for(var d=f.F.U.rev15,l=15-o,c=0;c<h.length;c+=2){var s=h[c]<<o-h[c+1];h[c]=d[s]>>>l}},f.F._putsE=function(h,o,d){d=d<<(o&7);var l=o>>>3;h[l]|=d,h[l+1]|=d>>>8},f.F._putsF=function(h,o,d){d=d<<(o&7);var l=o>>>3;h[l]|=d,h[l+1]|=d>>>8,h[l+2]|=d>>>16},f.F._bitsE=function(h,o,d){return(h[o>>>3]|h[(o>>>3)+1]<<8)>>>(o&7)&(1<<d)-1},f.F._bitsF=function(h,o,d){return(h[o>>>3]|h[(o>>>3)+1]<<8|h[(o>>>3)+2]<<16)>>>(o&7)&(1<<d)-1},f.F._get17=function(h,o){return(h[o>>>3]|h[(o>>>3)+1]<<8|h[(o>>>3)+2]<<16)>>>(o&7)},f.F._get25=function(h,o){return(h[o>>>3]|h[(o>>>3)+1]<<8|h[(o>>>3)+2]<<16|h[(o>>>3)+3]<<24)>>>(o&7)},f.F.U=function(){var h=Uint16Array,o=Uint32Array;return{next_code:new h(16),bl_count:new h(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new h(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new o(32),flmap:new h(512),fltree:[],fdmap:new h(32),fdtree:[],lmap:new h(32768),ltree:[],ttree:[],dmap:new h(32768),dtree:[],imap:new h(512),itree:[],rev15:new h(32768),lhst:new o(286),dhst:new o(30),ihst:new o(19),lits:new o(15e3),strt:new h(65536),prev:new h(32768)}}(),function(){for(var h=f.F.U,o=32768,d=0;d<o;d++){var l=d;l=(l&2863311530)>>>1|(l&1431655765)<<1,l=(l&3435973836)>>>2|(l&858993459)<<2,l=(l&4042322160)>>>4|(l&252645135)<<4,l=(l&4278255360)>>>8|(l&16711935)<<8,h.rev15[d]=(l>>>16|l<<16)>>>17}function c(s,g,v){for(;g--!=0;)s.push(0,v)}for(var d=0;d<32;d++)h.ldef[d]=h.of0[d]<<3|h.exb[d],h.ddef[d]=h.df0[d]<<4|h.dxb[d];c(h.fltree,144,8),c(h.fltree,112,9),c(h.fltree,24,7),c(h.fltree,8,8),f.F.makeCodes(h.fltree,9),f.F.codes2map(h.fltree,9,h.flmap),f.F.revCodes(h.fltree,9),c(h.fdtree,32,5),f.F.makeCodes(h.fdtree,5),f.F.codes2map(h.fdtree,5,h.fdmap),f.F.revCodes(h.fdtree,5),c(h.itree,19,0),c(h.ltree,286,0),c(h.dtree,30,0),c(h.ttree,320,0)}()}(W)),W.exports}var st=rt(),nt=X(st);const D=class D{constructor(f,h,o,d,l){this.copy=()=>new D(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const c=":";let s=("0"+this.h).slice(-2)+c+("0"+this.m).slice(-2)+c+("0"+this.s).slice(-2)+c+("0"+this.f).slice(-2);return s+="."+(this.field?"1":"2"),s},this.toZipTimeCodeString=()=>{const c=this.copy();return c.f=0,c.s=c.s%2===0?c.s:c.s-1,c.field=0,D.toStr(c)},this.toFrames=c=>{let s=60,g=0;Math.floor(c)==60?(s=60,g=0):Math.floor(c)==59?(s=60,g=4):Math.floor(c)==30?(s=30,g=0):Math.floor(c)==29&&(s=30,g=2);let v=this.h,x=this.m,m=this.s,w=this.f,y=this.field;const A=v*60+x,e=(A-Math.floor(A/10))*g;return v*(s*3600)+x*(s*60)+m*s+(w*2+y)-e},this.addSeconds=c=>{let s=this.copy();return s.s+=c,s.s>=60&&(s.s=0,s.m++,s.m>=60&&(s.m=0,s.h++)),s},this.addFrames=(c,s)=>{let g=this.toFrames(s);return g+=c,D.fromFrames(g,s)},this.subtractFrames=(c,s)=>this.addFrames(-c,s),this.h=f||0,this.m=h||0,this.s=o||0,this.f=d||0,this.field=l||0}static compare(f,h){return f.h!==h.h?f.h<h.h?-1:1:f.m!==h.m?f.m<h.m?-1:1:f.s!==h.s?f.s<h.s?-1:1:f.f!==h.f?f.f<h.f?-1:1:f.field!==h.field?f.field<h.field?-1:1:0}static generateTimecodeRange(f,h,o){const d=[];let l=f;for(;D.compare(l,h)<=0;)d.push(l),l=l.addSeconds(o);return d}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(f){return this.toFrames(f)*1e3/f}};D.calculateCurrentTimeCode=f=>{var m;if(!f.video||!f.clocker||!f.gameParams)throw new Error("OTTPlayer is not initialized");const h=f.video,o=f.clocker,d=o.videoFPScalculator.getFPS(),s=(h.currentTime-o.syncPoint.playerTime)%(60*60*24)*d+o.syncPoint.frame;if(s===0||d===0)throw new Error("Current frame is 0 or fps is 0");const g=D.calculateCurrentOffset(s,(m=f.gameParams)==null?void 0:m.offsets);if(g===void 0)throw new Error("Offset is undefined");let v=Math.floor(s-g);return v<0&&(v+=5178816),v>=5178816&&(v-=5178816),D.fromFrames(v,d)},D.calculateCurrentOffset=(f,h)=>{for(let o=1;o<h.length;o++)if(f<h[o].frame)return h[o-1].offset;return h[h.length-1].offset},D.fromFrames=(f,h)=>{let o=60,d=0;Math.floor(h)==60?(o=60,d=0):Math.floor(h)==59?(o=60,d=4):Math.floor(h)==30?(o=30,d=0):Math.floor(h)==29&&(o=30,d=2);let l=Math.floor(h*60),c=Math.floor(h*60*10),s=c*6,g=f,v=Math.floor(g/s);g-=v*s;let x=Math.floor(g/c);g-=x*c,g>=o*60&&(g+=d*(Math.floor((g-o*60)/l)+1));let m=Math.floor(g/(o*60));g-=m*(o*60);let w=Math.floor(g/o);g-=w*o;let y=g;m+=x*10;let A=0;return A=y%2,y=Math.floor(y/2),new D(v,m,w,y,A)},D.toStr=f=>{const h="_";let o=("0"+f.h).slice(-2)+h+("0"+f.m).slice(-2)+h+("0"+f.s).slice(-2)+h+("0"+f.f).slice(-2);return f.field&&(o+="_1"),o},D.fromStr=f=>{const o=f.split("_").map(Number);if(o.length==4){const[d,l,c,s]=o;return new D(d,l,c,s,0)}else if(o.length==5){const[d,l,c,s,g]=o;return new D(d,l,c,s,g)}else throw new Error("Invalid timecode format: "+f)},D.fromMetadata=f=>{const h=/^(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d))?$/,o=f.timecode.match(h);if(!o)throw new Error("Invalid timecode format: "+f.timecode);const[,d,l,c,s,g]=o,v=Number(d),x=Number(l),m=Number(c),w=Number(s),y=g?Number(g):0;return new D(v,x,m,w,y)};let H=D;class ot{constructor(f,h){this.videoDecoder=null,this.reservedVideoDecoder=null,this.currentTimecode="",this.fps=0,this.unchunkedJobs=[],this.jobChunking=null,this.jobsQueue=[],this.chunksQueue=[],this.chunksForDecodingFrames=[],this.processedMetadata=[],this.videoDecoderConfigured=!1,this.reservedVideoDecoderConfigured=!1,this.addJob=(o,d)=>{const{alphaMp4:l,metadataList:c}=this.parseZipAndMetadata(d);if(!l){this.options&&L(this.options,"Decoder")&&console.log("[Decoder] No alpha.mp4 found, no decoding needed.");return}const s={timeCode:o,alphaMp4:l,metadata:c,chunks:[],totalFrameCount:c.length,framesProcessed:0,framesSentToDecoder:0,useReserveDecoder:c.length<3};this.jobChunking?this.unchunkedJobs.push(s):(this.jobChunking=s,this.chunkJob(s)),this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Added job:",s)},this.clearOldJobsAndChunks=o=>{const l=H.fromStr(this.currentTimecode).totalMilliseconds(this.fps)-o;this.unchunkedJobs=this.unchunkedJobs.filter(c=>H.fromStr(c.timeCode).totalMilliseconds(this.fps)>l),this.jobsQueue=this.jobsQueue.filter(c=>H.fromStr(c.timeCode).totalMilliseconds(this.fps)>l),this.chunksQueue=this.chunksQueue.filter(c=>H.fromStr(c.timeCode).totalMilliseconds(this.fps)>l)},this.updateCurrentTimecode=(o,d)=>{this.currentTimecode=o,this.fps=59.94,this.clearOldJobsAndChunks(2100),this.decodeUpcomingChunks()},this.setupMP4Box=(o=!1)=>{const d=it.createFile();return d.onError=l=>{this.options&&L(this.options,"Errors")&&console.error("[Decoder] MP4 parsing error:",l)},d.onReady=l=>{const c=l.tracks.find(s=>s.type==="video");if(c){if(!(o?this.reservedVideoDecoderConfigured:this.videoDecoderConfigured)){this.options&&L(this.options,"Decoder")&&console.error("[Decoder] Starting a new VideoDecoder");let g;o?(this.reservedVideoDecoder=new VideoDecoder({output:this.onFrameDecoded,error:this.onDecoderError}),g=this.reservedVideoDecoder):(this.videoDecoder=new VideoDecoder({output:this.onFrameDecoded,error:this.onDecoderError}),g=this.videoDecoder),g.configure({codec:c.codec,codedWidth:c.video.width,codedHeight:c.video.height,description:this.getDescription(d.getTrackById(c.id)),hardwareAcceleration:"prefer-hardware",optimizeForLatency:!0}),o?this.reservedVideoDecoderConfigured=!0:this.videoDecoderConfigured=!0}d.setExtractionOptions(c.id),d.start()}},d.onSamples=async(l,c,s)=>{const g=[];for(const v of s){const x=new EncodedVideoChunk({type:v.is_sync?"key":"delta",timestamp:v.cts,data:new Uint8Array(v.data)});g.push(x)}this.storeChunks(g)},d},this.chunkJob=async o=>{this.mp4boxfile=this.setupMP4Box(o.useReserveDecoder);const l=await new Blob([o.alphaMp4],{type:"video/mp4"}).arrayBuffer();l.fileStart=0,this.mp4boxfile.appendBuffer(l)},this.storeChunks=o=>{this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Storing chunks:",o);const d=this.jobChunking;if(this.unchunkedJobs.length>0){const c=this.unchunkedJobs.shift();this.jobChunking=c,this.chunkJob(c)}else this.jobChunking=null;const l=d==null?void 0:d.metadata.map((c,s)=>({timeCode:c.timecode,chunk:o[s],metadata:c,job:d,cancelled:!1}));d.chunks=l,this.chunksQueue.push(...l),this.jobsQueue.push(d),this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Jobs Queue:",this.jobsQueue),this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Chunks Queue:",this.chunksQueue)},this.onFrameDecoded=o=>{this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Frame decoded:",o);const d=this.chunksForDecodingFrames.shift();if(!d){this.options&&L(this.options,"Errors")&&console.error("[Decoder] No current chunk for a processed frame");return}if(d.cancelled){this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Skipping cancelled chunk:",d.timeCode),o.close();return}const l=d.metadata;d.job.framesProcessed++,l.alphaMask=o,this.processedMetadata.push(l),(this.processedMetadata.length>=this.options.DECODER_FRAME_BATCH_SIZE||d.job.framesProcessed>=d.job.totalFrameCount)&&(this.postBatchToRenderer(this.processedMetadata),this.processedMetadata.forEach(c=>c.alphaMask.close()),this.processedMetadata=[])},this.onDecoderError=o=>{this.options&&L(this.options,"Errors")&&console.error("[Decoder] VideoDecoder error:",o),this.videoDecoderConfigured=!1,this.reservedVideoDecoderConfigured=!1;const d=this.chunksForDecodingFrames.shift();if(!d){this.options&&L(this.options,"Errors")&&console.error("[Decoder] No broken chunk for an error");return}const l=d.job;l&&l.chunks.forEach(c=>c.cancelled=!0)},this.parseZipAndMetadata=o=>{const d=nt.parse(o),l=d["alpha.mp4"]||null,c=Object.keys(d).filter(s=>s.endsWith(".json")).sort(this.numericFileComparator).map(s=>{const g=JSON.parse(new TextDecoder().decode(d[s]));return g.timecode=H.toStr(H.fromMetadata(g)),g}).filter(s=>s.placeholders);return{alphaMp4:l,metadataList:c}},this.numericFileComparator=(o,d)=>{const l=/^(\\d{2})_(\\d{2})_(\\d{2})_(\\d{2})(?:\\.(\\d+))?\\.(.+)$/,c=o.match(l),s=d.match(l);if(!c||!s)return 0;const[,g,v,x,m,w="0",y]=c,[,A,t,e,r,n="0",a]=s;return parseInt(g,10)-parseInt(A,10)||parseInt(v,10)-parseInt(t,10)||parseInt(x,10)-parseInt(e,10)||parseInt(m,10)-parseInt(r,10)||parseInt(w,10)-parseInt(n,10)||y.localeCompare(a)},this.getDescription=o=>{for(const d of o.mdia.minf.stbl.stsd.entries){const l=d.avcC||d.hvcC||d.vpcC||d.av1C;if(l){const c=new Z.DataStream(void 0,0,Z.DataStream.BIG_ENDIAN);return l.write(c),new Uint8Array(c.buffer,8)}}return null},this.postBatchToRenderer=f,this.options=h,this.mp4boxfile=this.setupMP4Box()}decodeUpcomingChunks(){const f=H.fromStr(this.currentTimecode).totalMilliseconds(this.fps),h=f+this.options.DECODER_LEAD_TIME_MILLIS,o=this.chunksQueue.filter(l=>{const c=H.fromStr(l.timeCode).totalMilliseconds(this.fps);return c>=f&&c<=h&&!l.decoded});o.sort((l,c)=>{const s=H.fromStr(l.timeCode).totalMilliseconds(this.fps),g=H.fromStr(c.timeCode).totalMilliseconds(this.fps);return s-g});const d=o.slice(0,this.options.DECODER_FRAME_BATCH_SIZE);for(const l of d){if(l.cancelled){this.options&&L(this.options,"Decoder")&&console.log("[Decoder] Skipping cancelled chunk:",l.timeCode);continue}const c=l.job.useReserveDecoder?this.reservedVideoDecoder:this.videoDecoder;if(!c||c.state==="closed"){this.options&&L(this.options,"Errors")&&console.error("[Decoder] No VideoDecoder available");continue}try{this.chunksForDecodingFrames.push(l),c.decode(l.chunk)}catch(s){this.options&&L(this.options,"Errors")&&console.error("[Decoder] Error decoding chunk:",s),this.videoDecoderConfigured=!1,this.reservedVideoDecoderConfigured=!1,c.flush(),l.job.chunks.forEach(v=>v.cancelled=!0)}finally{if(l.decoded=!0,l.job.framesSentToDecoder++,l.job.framesSentToDecoder>=l.job.totalFrameCount){c.flush(),l.job.useReserveDecoder&&(this.reservedVideoDecoderConfigured=!1);continue}}}}}let tt=null,q=null,J,V;self.onmessage=async C=>{const{data:f}=C;f.type==="SET_DOWNLOADER_PORT"&&(tt=f.port,tt.onmessage=at),f.type==="SET_RENDERER_PORT"&&(q=f.port,q.onmessage=ht),f.type==="SET_OPTIONS"&&(V=f.options,J=new ot(ft,V))};function at(C){const{data:f}=C;if(f.type==="DECODER_INPUT"){const{timeCode:h,arrayBuffer:o}=f;V&&L(V,"Decoder")&&console.log("[DecoderWorker] Received ArrayBuffer from Downloader, timeCode =",h),J.addJob(h,o)}}function ht(C){const{data:f}=C;if(f.type==="DECODER_REQUEST"){const{timeCode:h,fps:o}=f;V&&L(V,"Decoder")&&console.log("[DecoderWorker] Received TimeCode request from Renderer, timeCode =",h),J.updateCurrentTimecode(h,o)}}function ft(C){if(!q)return;V&&L(V,"Decoder")&&console.log(\`[DecoderWorker] Posting a batch of \${C.length} frames to Renderer\`);const f=C.map(h=>h.alphaMask).filter(h=>h!==void 0);try{const h=new Set(f);q.postMessage({type:"RENDERER_INPUT",batch:C},[...h]),f.forEach(o=>o.close())}catch(h){console.error("[DecoderWorker] Error posting batch to Renderer:",h),f.forEach(o=>o.close());return}}self.onunhandledrejection=C=>{console.error("[Worker] Unhandled rejection:",C.reason)}})();
|
|
3
|
-
`,
|
|
3
|
+
`,I=typeof self<"u"&&self.Blob&&new Blob([M],{type:"text/javascript;charset=utf-8"});function K(s){let t;try{if(t=I&&(self.URL||self.webkitURL).createObjectURL(I),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(M),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const L=`(function(){"use strict";const u=(c,o)=>!c.debug||!c.debug.on?!1:c.debug[\`log\${o}\`],f=class f{constructor(o,a,e,t,i){this.copy=()=>new f(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const r=":";let s=("0"+this.h).slice(-2)+r+("0"+this.m).slice(-2)+r+("0"+this.s).slice(-2)+r+("0"+this.f).slice(-2);return s+="."+(this.field?"1":"2"),s},this.toZipTimeCodeString=()=>{const r=this.copy();return r.f=0,r.s=r.s%2===0?r.s:r.s-1,r.field=0,f.toStr(r)},this.toFrames=r=>{let s=60,n=0;Math.floor(r)==60?(s=60,n=0):Math.floor(r)==59?(s=60,n=4):Math.floor(r)==30?(s=30,n=0):Math.floor(r)==29&&(s=30,n=2);let l=this.h,h=this.m,d=this.s,R=this.f,p=this.field;const E=l*60+h,x=(E-Math.floor(E/10))*n;return l*(s*3600)+h*(s*60)+d*s+(R*2+p)-x},this.addSeconds=r=>{let s=this.copy();return s.s+=r,s.s>=60&&(s.s=0,s.m++,s.m>=60&&(s.m=0,s.h++)),s},this.addFrames=(r,s)=>{let n=this.toFrames(s);return n+=r,f.fromFrames(n,s)},this.subtractFrames=(r,s)=>this.addFrames(-r,s),this.h=o||0,this.m=a||0,this.s=e||0,this.f=t||0,this.field=i||0}static compare(o,a){return o.h!==a.h?o.h<a.h?-1:1:o.m!==a.m?o.m<a.m?-1:1:o.s!==a.s?o.s<a.s?-1:1:o.f!==a.f?o.f<a.f?-1:1:o.field!==a.field?o.field<a.field?-1:1:0}static generateTimecodeRange(o,a,e){const t=[];let i=o;for(;f.compare(i,a)<=0;)t.push(i),i=i.addSeconds(e);return t}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(o){return this.toFrames(o)*1e3/o}};f.calculateCurrentTimeCode=o=>{var d;if(!o.video||!o.clocker||!o.gameParams)throw new Error("OTTPlayer is not initialized");const a=o.video,e=o.clocker,t=e.videoFPScalculator.getFPS(),s=(a.currentTime-e.syncPoint.playerTime)%(60*60*24)*t+e.syncPoint.frame;if(s===0||t===0)throw new Error("Current frame is 0 or fps is 0");const n=f.calculateCurrentOffset(s,(d=o.gameParams)==null?void 0:d.offsets);if(n===void 0)throw new Error("Offset is undefined");let l=Math.floor(s-n);return l<0&&(l+=5178816),l>=5178816&&(l-=5178816),f.fromFrames(l,t)},f.calculateCurrentOffset=(o,a)=>{for(let e=1;e<a.length;e++)if(o<a[e].frame)return a[e-1].offset;return a[a.length-1].offset},f.fromFrames=(o,a)=>{let e=60,t=0;Math.floor(a)==60?(e=60,t=0):Math.floor(a)==59?(e=60,t=4):Math.floor(a)==30?(e=30,t=0):Math.floor(a)==29&&(e=30,t=2);let i=Math.floor(a*60),r=Math.floor(a*60*10),s=r*6,n=o,l=Math.floor(n/s);n-=l*s;let h=Math.floor(n/r);n-=h*r,n>=e*60&&(n+=t*(Math.floor((n-e*60)/i)+1));let d=Math.floor(n/(e*60));n-=d*(e*60);let R=Math.floor(n/e);n-=R*e;let p=n;d+=h*10;let E=0;return E=p%2,p=Math.floor(p/2),new f(l,d,R,p,E)},f.toStr=o=>{const a="_";let e=("0"+o.h).slice(-2)+a+("0"+o.m).slice(-2)+a+("0"+o.s).slice(-2)+a+("0"+o.f).slice(-2);return o.field&&(e+="_1"),e},f.fromStr=o=>{const e=o.split("_").map(Number);if(e.length==4){const[t,i,r,s]=e;return new f(t,i,r,s,0)}else if(e.length==5){const[t,i,r,s,n]=e;return new f(t,i,r,s,n)}else throw new Error("Invalid timecode format: "+o)},f.fromMetadata=o=>{const a=/^(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d))?$/,e=o.timecode.match(a);if(!e)throw new Error("Invalid timecode format: "+o.timecode);const[,t,i,r,s,n]=e,l=Number(t),h=Number(i),d=Number(r),R=Number(s),p=n?Number(n):0;return new f(l,h,d,R,p)};let D=f;const N=\`
|
|
4
4
|
attribute vec2 a_position;
|
|
5
5
|
attribute vec2 a_uv;
|
|
6
6
|
|
|
@@ -134,5 +134,5 @@ void main() {
|
|
|
134
134
|
}\`).join(\`
|
|
135
135
|
\`)}
|
|
136
136
|
}
|
|
137
|
-
\`;class F{constructor(o,a){this.adTextures=new Map,this.allPlaceholders=[],this.setAllPlaceholders=e=>{this.allPlaceholders=e},this.initShadersAlphaMask=e=>{const t=this.compileShader(e,e.VERTEX_SHADER,N),i=this.compileShader(e,e.FRAGMENT_SHADER,O),r=e.createProgram();return e.attachShader(r,t),e.attachShader(r,i),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.error("Could not link shaders:",e.getProgramInfoLog(r)),null)},this.initShadersAugmentation=e=>{const t=this.compileShader(e,e.VERTEX_SHADER,k),i=this.compileShader(e,e.FRAGMENT_SHADER,G(this.allPlaceholders)),r=e.createProgram();return e.attachShader(r,t),e.attachShader(r,i),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.error("Could not link shaders:",e.getProgramInfoLog(r)),null)},this.compileShader=(e,t,i)=>{const r=e.createShader(t);return e.shaderSource(r,i),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(\`Error compiling shader: \${e.getShaderInfoLog(r)}\`),e.deleteShader(r),null)},this.createTextureFromVideoFrame=e=>{const t=this.gl,i=t.createTexture();return t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.bindTexture(t.TEXTURE_2D,i),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.bindTexture(t.TEXTURE_2D,null),i},this.deleteTexture=e=>{this.gl.deleteTexture(e)},this.drawAlphaMask=e=>{if(!this.program){this.options&&m(this.options,"Errors")&&console.error("[Renderer] Program not initialized");return}(!this.positionBuffer||!this.uvBuffer)&&this.options&&m(this.options,"Errors")&&console.error("[Renderer] Buffers not initialized");const t=this.gl,i=this.program,r=t.getAttribLocation(i,"a_position"),s=t.getAttribLocation(i,"a_uv"),n=t.getUniformLocation(i,"u_alphaMask");t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),t.uniform1i(n,0),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.uvBuffer),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),t.clear(t.COLOR_BUFFER_BIT);let l=t.TRIANGLES;t.drawArrays(l,0,6)},this.drawAugmentation=(e,t)=>{if(!this.program){this.options&&m(this.options,"Errors")&&console.error("[Renderer] Program not initialized");return}const i=this.gl,r=this.program;if(!this.allPlaceholders){this.options&&m(this.options,"Errors")&&console.error("[Renderer] Placeholder names not initialized");return}i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,e);let s=i.getUniformLocation(r,"u_alphaMask");s&&i.uniform1i(s,0);let n=0;const l=Object.keys(t).map(R=>t[R]),h=l.map(R=>R.name);this.allPlaceholders.forEach(R=>{if(h.includes(R)&&this.adTextures.has(R)){const v=l.filter(Z=>Z.name===R)[0],C=this.adTextures.get(R);i.activeTexture(i.TEXTURE1+n),i.bindTexture(i.TEXTURE_2D,C);let I=i.getUniformLocation(r,"u_ad"+R);I&&i.uniform1i(I,n+1);let Q="u_hasLogo"+R,K=i.getUniformLocation(r,Q);i.uniform1i(K,1);let J="u_matrix"+R,q=i.getUniformLocation(r,J);i.uniformMatrix3fv(q,!1,v.tranform),n++}else{let v="u_hasLogo"+R,C=i.getUniformLocation(r,v);i.uniform1i(C,0)}});const d=i.getAttribLocation(r,"a_position"),E=i.getAttribLocation(r,"a_uv"),u=i.getUniformLocation(r,"u_resolution");i.uniform2f(u,i.canvas.width,i.canvas.height),i.bindBuffer(i.ARRAY_BUFFER,this.positionBuffer),i.enableVertexAttribArray(d),i.vertexAttribPointer(d,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.uvBuffer),i.enableVertexAttribArray(E),i.vertexAttribPointer(E,2,i.FLOAT,!1,0,0),i.viewport(0,0,i.canvas.width,i.canvas.height),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let g=i.TRIANGLES;i.drawArrays(g,0,6)},this.setRectangle=(e,t,i,r,s)=>{const n=t,l=i,h=t+r,d=i+s;e.bufferData(e.ARRAY_BUFFER,new Float32Array([n,l,h,l,n,d,n,d,h,l,h,d]),e.STATIC_DRAW)},this.generateAdTexture=(e,t,i)=>{const r=this.gl;if(!this.program){this.options&&m(this.options,"Errors")&&console.error("[Renderer] Program not initialized");return}r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,i);const n=r.createTexture();if(r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.bindTexture(r.TEXTURE_2D,null),!n){this.options&&m(this.options,"Errors")&&console.error("[Renderer] Failed to create texture");return}this.adTextures.set(e,n)},this.isPowerOf2=e=>(e&e-1)==0,this.setUVs=e=>{e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW)},this.options=a,this.renderer=o,this.gl=o.glContext}init(){const o=this.gl;this.renderer.RENDER_ALPHAMASK?this.program=this.initShadersAlphaMask(o):this.program=this.initShadersAugmentation(o),o.useProgram(this.program);const a=o.getUniformLocation(this.program,"u_resolution");o.uniform2f(a,o.canvas.width,o.canvas.height),this.initGeometryBuffers()}initGeometryBuffers(){const o=this.gl;this.positionBuffer=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,this.positionBuffer),this.setRectangle(o,0,0,o.canvas.width,o.canvas.height),this.uvBuffer=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,this.uvBuffer),this.setUVs(o),o.bindBuffer(o.ARRAY_BUFFER,null)}updateGeometryBuffers(){const o=this.gl;if(!this.positionBuffer||!this.uvBuffer){this.options&&m(this.options,"Errors")&&console.error("[Renderer] Buffers not initialized");return}o.bindBuffer(o.ARRAY_BUFFER,this.positionBuffer),this.setRectangle(o,0,0,o.canvas.width,o.canvas.height),o.bindBuffer(o.ARRAY_BUFFER,this.uvBuffer),this.setUVs(o),o.bindBuffer(o.ARRAY_BUFFER,null)}cleanGL(){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}const S=["LeftTop","MidTopLeft","MidTopRight","RightTop","LeftBottom","MidBottomLeft","MidBottomRight","RightBottom"];class w{constructor(o,a){this.ads=[],this.getAds=async()=>{const t=await(await fetch("https://www.virtualott.com/ads/"+this.options.augmentation.channelName)).json(),i=t.filter(l=>l.name.indexOf(".json")>-1)[0].url,n=(await(await fetch(i)).json()).urls;for(const l of t){const h=await this.loadAdvImage(l);if(!h)continue;const d={name:l.name,imageUrl:l.url,image:h,adUrl:n[l.name]};this.ads.push(d)}this.setAd("LeftTop",3),this.setAd("RightBottom",4),this.uploadAdTextures()},this.loadAdvImage=async e=>{const t=\`#\${e.name}\`,i=e.url;if(t.indexOf(".json")>-1)return;const s=await(await fetch(i)).blob();return await createImageBitmap(s)},this.setAd=(e,t)=>{this.adMap.set(e,this.ads[t])},this.uploadAdTextures=()=>{this.adMap.forEach((e,t)=>{!e||!e.image||this.webgl.generateAdTexture(t,e.image,!0)})},this.getAdURLAtCoord=(e,t,i)=>{let r;return Object.keys(e).forEach(s=>{const n=e[s].corners.map(l=>({x:l.x/t.width,y:l.y/t.height}));if(this.isPointInPlaceholder(n,i)){const l=e[s].name,h=this.adMap.get(l);console.log("ad: ",h),h&&(console.log("ad.url: ",h.adUrl),r=h.adUrl)}}),r},this.isPointInPlaceholder=(e,t)=>{console.log("polygon: ",e),console.log("coord: ",t);let i=!1;const{x:r,y:s}=t,n=e.length;for(let l=0,h=n-1;l<n;h=l++){const d=e[l].x,E=e[l].y,u=e[h].x,g=e[h].y;E>s!=g>s&&r<(u-d)*(s-E)/(g-E)+d&&(i=!i)}return console.log("inside: ",i),i},this.placeholderNames=S,this.webgl=o,this.options=a,this.adMap=new Map,S.forEach(e=>{this.adMap.set(e,void 0)}),this.webgl.setAllPlaceholders(S),console.log("channelName: ",this.options.augmentation.channelName),this.getAds()}}class W{constructor(o,a){this.RENDER_ALPHAMASK=!1,this.renderDataMap=new Map,this.setWebGLEventListeners=()=>{const e=this.glContext.canvas;e.addEventListener("webglcontextlost",t=>{console.warn("Context lost:",t),t.preventDefault()}),e.addEventListener("webglcontextrestored",()=>{console.log("Context restored!"),this.webgl=new F(this,this.options),this.ads=new w(this.webgl,this.options),this.webgl.init()})},this.addMetadataBatch=e=>{e.forEach(t=>{if(!(!t.alphaMask||!t.isLive)){this.options&&m(this.options,"Renderer")&&console.log(\`[RendererWorker] Creating texture for timeCode=\${t.timecode}\`);try{const i=this.webgl.createTextureFromVideoFrame(t.alphaMask),r=t.timecode,s={width:t.processingWidth,height:t.processingHeight},n={alphaMask:i,placeholders:t.placeholders,processingSize:s};this.renderDataMap.set(r,n)}catch{this.options&&m(this.options,"Errors")&&console.error(\`[RendererWorker] Error creating texture for timeCode=\${t.timecode}\`)}finally{t.alphaMask.close()}}})},this.handleRenderDraw=(e,t)=>{var n,l,h,d,E;if(!this.streamData||this.streamData.ottActions&&!this.streamData.ottActions.toggle.web)return;const i=(n=this.renderDataMap.get(e))==null?void 0:n.alphaMask,r=(l=this.renderDataMap.get(e))==null?void 0:l.placeholders,s=(h=this.renderDataMap.get(e))==null?void 0:h.processingSize;if(!(!i||!r||!s||!this.streamData)){if((this.glContext.canvas.width!==s.width||this.glContext.canvas.height!==s.height)&&(this.glContext.canvas.width=s.width,this.glContext.canvas.height=s.height,this.webgl.updateGeometryBuffers()),t!=0)if(t>0){console.log("frameCorrection:"+t);const u=x.fromStr(e).addFrames(1,this.streamData.fps);console.log("thisFrameTimeCode:"+e),console.log("nextFrameTimeCode:"+x.toStr(u));const g=(d=this.renderDataMap.get(x.toStr(u)))==null?void 0:d.placeholders;g&&(console.log("nextPlaceholder:"+g),Object.keys(g).forEach(A=>{A in r&&(console.log("key:"+A),r[A].tranform=r[A].tranform.map((D,R)=>D*(1-t)+g[A].tranform[R]*t))}))}else{const u=Math.abs(t),g=x.fromStr(e).subtractFrames(1,this.streamData.fps),A=(E=this.renderDataMap.get(x.toStr(g)))==null?void 0:E.placeholders;A&&Object.keys(A).forEach(D=>{D in r&&(r[D].tranform=r[D].tranform.map((R,v)=>A[D].tranform[v]*(1-u)+R*u))})}this.options&&m(this.options,"Renderer")&&console.log(\`[Renderer] Render logic: binding texture for \${e}\`),this.RENDER_ALPHAMASK?this.webgl.drawAlphaMask(i):this.webgl.drawAugmentation(i,r)}},this.getAdURLByCoord=e=>{var n,l;if(console.log("clickData: ",e),!this.ads||!this.streamData||!this.streamData.timeCode||!this.renderDataMap)return null;const t=this.streamData.timeCode,i=(n=this.renderDataMap.get(t))==null?void 0:n.placeholders,r=(l=this.renderDataMap.get(t))==null?void 0:l.processingSize;if(!i||!r)return null;console.log("placeholders: ",i);const s=this.ads.getAdURLAtCoord(i,r,e);return console.log("url: ",s),s},this.deleteTexture=e=>{var i;const t=(i=this.renderDataMap.get(e))==null?void 0:i.alphaMask;t&&(this.webgl.deleteTexture(t),this.renderDataMap.delete(e))},this.deleteOldTextures=e=>{if(!this.streamData)return;const t=59.94,i=x.fromStr(e).totalMilliseconds(t);this.renderDataMap.forEach((r,s)=>{x.fromStr(s).totalMilliseconds(t)<i-100&&(this.options&&m(this.options,"Renderer")&&console.log(\`[Renderer] Deleting old texture for timeCode=\${s}\`),this.webgl.deleteTexture(r.alphaMask),this.renderDataMap.delete(s))})},this.cleanGL=()=>{this.webgl.cleanGL()},this.updateStreamData=e=>{this.streamData=e},this.glContext=o,this.webgl=new F(this,a),this.options=a,this.ads=new w(this.webgl,a),this.webgl.init()}}let L=null,M=null,U=null,b=null,_=null,p;const T={timeCode:"",frameCorrection:0,fps:0,cloudFrontURL:"",bucketName:"",offsets:[]};let P=0,B=0;self.onmessage=c=>{const{data:o}=c;if(o.type==="INIT_OFFSCREEN"){const a=o.offscreen;if(p=o.options,b=a.getContext("webgl"),p&&m(p,"Renderer")&&console.log("[RendererWorker] Initializing OffscreenCanvas"),!b){p&&m(p,"Errors")&&console.error("[RendererWorker] Failed to acquire WebGL context");return}_=new W(b,p),p&&m(p,"Renderer")&&console.log("[RendererWorker] OffscreenCanvas initialized, gl context acquired")}if(o.type==="SET_DOWNLOADER_PORT"&&(L=o.port,L.onmessage=j),o.type==="SET_DECODER_PORT"&&(M=o.port,M.onmessage=z),o.type==="SET_ADAPTER_PORT"&&(U=o.port,U.onmessage=H),(o.type==="RENDERER_DRAW"||o.type==="RENDERER_CLEAR")&&y(o),o.type==="VIDEO_CLICK"&&_){const a=_.getAdURLByCoord(o.clickData);postMessage({type:"OPEN_URL",url:a})}};function X(){L&&L.postMessage({type:"DOWNLOADER_INPUT",streamData:T})}function Y(){M&&M.postMessage({type:"DECODER_REQUEST",timeCode:T.timeCode,fps:T.fps})}function y(c){V(c.streamData),_?(_.updateStreamData(T),_.cleanGL(),c.type==="RENDERER_DRAW"&&(_.handleRenderDraw(c.streamData.timeCode,c.streamData.frameCorrection),_.deleteOldTextures(c.streamData.timeCode))):p&&m(p,"Errors")&&console.error("[RendererWorker] WebGL context is not initialized."),$()}function $(){if(!p)return;const c=performance.now();c-P>p.DOWNLOADER_UPDATE_FREQUENCY&&(X(),P=c),c-B>p.DECODER_UPDATE_FREQUENCY&&(Y(),B=c)}function z(c){const{data:o}=c;if(o.type==="RENDERER_INPUT"){const a=o.batch;p&&m(p,"Renderer")&&console.log(\`[RendererWorker] Received a batch of \${a.length} frames\`),_&&_.addMetadataBatch(a)}}function j(c){const{data:o}=c;if(p&&m(p,"Renderer")&&console.log("[RendererWorker] Message from Downloader:",c.data),o.type==="OTT_ACTIONS"){const a=o.ottActions;T.ottActions=a}}function H(c){const{data:o}=c;(o.type==="RENDERER_DRAW"||o.type==="RENDERER_CLEAR")&&y(o)}function V(c){T.timeCode=c.timeCode,T.frameCorrection=c.frameCorrection,T.fps=c.fps,T.cloudFrontURL=c.cloudFrontURL,T.bucketName=c.bucketName,T.offsets=c.offsets}})();
|
|
138
|
-
`,z=typeof self<"u"&&self.Blob&&new Blob([L],{type:"text/javascript;charset=utf-8"});function J(s){let t;try{if(t=z&&(self.URL||self.webkitURL).createObjectURL(z),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(L),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const O='(function(){"use strict";const w=(s,e)=>!s.debug||!s.debug.on?!1:s.debug[`log${e}`],V=s=>Math.abs(s-59.94005994005994)<20?59.94:Math.abs(s-29.97002997002997)<10?29.97:Math.abs(s-14.985014985014985)<8?14.98:0,x=(()=>{const s=()=>{const c=navigator.userAgent;return/windows/i.test(c)?"Windows":/android/i.test(c)?"Android":/iphone|ipad|ipod/i.test(c)?"iOS":/mac/i.test(c)?"Mac":/ipad/i.test(c)?"iPad":"Something else"},e=()=>s()==="Mac",r=()=>s()==="iPad",t=()=>s()==="iOS",n=()=>{const c=s();return c==="iOS"||c==="Mac"||c==="iPad"},l=()=>s()==="Windows",a=()=>s()==="Android",i=()=>{switch(s()){case"Windows":return"a Windows PC";case"Android":return"an Android phone";case"iOS":return"an iPhone";case"Mac":return"a Mac";case"iPad":return"an iPad";default:return"an Unknown device"}},o=()=>({header:[navigator.platform,navigator.userAgent,navigator.appVersion,navigator.vendor,window.opera],dataos:[{name:"Windows Phone",value:"Windows Phone",version:"OS"},{name:"Windows",value:"Win",version:"NT"},{name:"iPhone",value:"iPhone",version:"OS"},{name:"iPad",value:"iPad",version:"OS"},{name:"Kindle",value:"Silk",version:"Silk"},{name:"Android",value:"Android",version:"Android"},{name:"PlayBook",value:"PlayBook",version:"OS"},{name:"BlackBerry",value:"BlackBerry",version:"/"},{name:"Macintosh",value:"Mac",version:"OS X"},{name:"Linux",value:"Linux",version:"rv"},{name:"Palm",value:"Palm",version:"PalmOS"}],databrowser:[{name:"Chrome",value:"Chrome",version:"Chrome"},{name:"Firefox",value:"Firefox",version:"Firefox"},{name:"Safari",value:"Safari",version:"Version"},{name:"Internet Explorer",value:"MSIE",version:"MSIE"},{name:"Opera",value:"Opera",version:"Opera"},{name:"BlackBerry",value:"CLDC",version:"CLDC"},{name:"Mozilla",value:"Mozilla",version:"Mozilla"}],init(){const C=this.header.join(" ");return this.matchItem(C,this.dataos)},matchItem(C,P){for(let A=0;A<P.length;A+=1)if(new RegExp(P[A].value,"i").test(C))return P[A].name;return"unknown"}}).init(),u=()=>{const c=navigator.userAgent;return c.indexOf("Chrome")>-1&&c.indexOf("Edge")===-1?"Chrome":c.indexOf("Safari")>-1&&c.indexOf("Chrome")===-1?"Safari":c.indexOf("Firefox")>-1?"Firefox":c.indexOf("MSIE")>-1||c.indexOf("Trident")>-1?"Internet Explorer":c.indexOf("Edge")>-1?"Edge":"Unknown"};return{getCurrentPlatform:s,isMac:e,isiPad:r,isiPhone:t,isApple:n,isWindows:l,isAndroid:a,getDeviceDescription:i,getDeviceName:o,getBrowserName:u,isSafariMac:()=>e()&&u()==="Safari",isChromeMac:()=>e()&&u()==="Chrome",isChromeWin:()=>l()&&u()==="Chrome"}})(),f=class f{constructor(e,r,t,n,l){this.copy=()=>new f(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const a=":";let i=("0"+this.h).slice(-2)+a+("0"+this.m).slice(-2)+a+("0"+this.s).slice(-2)+a+("0"+this.f).slice(-2);return i+="."+(this.field?"1":"2"),i},this.toZipTimeCodeString=()=>{const a=this.copy();return a.f=0,a.s=a.s%2===0?a.s:a.s-1,a.field=0,f.toStr(a)},this.toFrames=a=>{let i=60,o=0;Math.floor(a)==60?(i=60,o=0):Math.floor(a)==59?(i=60,o=4):Math.floor(a)==30?(i=30,o=0):Math.floor(a)==29&&(i=30,o=2);let u=this.h,p=this.m,h=this.s,M=this.f,S=this.field;const c=u*60+p,C=(c-Math.floor(c/10))*o;return u*(i*3600)+p*(i*60)+h*i+(M*2+S)-C},this.addSeconds=a=>{let i=this.copy();return i.s+=a,i.s>=60&&(i.s=0,i.m++,i.m>=60&&(i.m=0,i.h++)),i},this.addFrames=(a,i)=>{let o=this.toFrames(i);return o+=a,f.fromFrames(o,i)},this.subtractFrames=(a,i)=>this.addFrames(-a,i),this.h=e||0,this.m=r||0,this.s=t||0,this.f=n||0,this.field=l||0}static compare(e,r){return e.h!==r.h?e.h<r.h?-1:1:e.m!==r.m?e.m<r.m?-1:1:e.s!==r.s?e.s<r.s?-1:1:e.f!==r.f?e.f<r.f?-1:1:e.field!==r.field?e.field<r.field?-1:1:0}static generateTimecodeRange(e,r,t){const n=[];let l=e;for(;f.compare(l,r)<=0;)n.push(l),l=l.addSeconds(t);return n}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(e){return this.toFrames(e)*1e3/e}};f.calculateCurrentTimeCode=e=>{var h;if(!e.video||!e.clocker||!e.gameParams)throw new Error("OTTPlayer is not initialized");const r=e.video,t=e.clocker,n=t.videoFPScalculator.getFPS(),i=(r.currentTime-t.syncPoint.playerTime)%(60*60*24)*n+t.syncPoint.frame;if(i===0||n===0)throw new Error("Current frame is 0 or fps is 0");const o=f.calculateCurrentOffset(i,(h=e.gameParams)==null?void 0:h.offsets);if(o===void 0)throw new Error("Offset is undefined");let u=Math.floor(i-o);return u<0&&(u+=5178816),u>=5178816&&(u-=5178816),f.fromFrames(u,n)},f.calculateCurrentOffset=(e,r)=>{for(let t=1;t<r.length;t++)if(e<r[t].frame)return r[t-1].offset;return r[r.length-1].offset},f.fromFrames=(e,r)=>{let t=60,n=0;Math.floor(r)==60?(t=60,n=0):Math.floor(r)==59?(t=60,n=4):Math.floor(r)==30?(t=30,n=0):Math.floor(r)==29&&(t=30,n=2);let l=Math.floor(r*60),a=Math.floor(r*60*10),i=a*6,o=e,u=Math.floor(o/i);o-=u*i;let p=Math.floor(o/a);o-=p*a,o>=t*60&&(o+=n*(Math.floor((o-t*60)/l)+1));let h=Math.floor(o/(t*60));o-=h*(t*60);let M=Math.floor(o/t);o-=M*t;let S=o;h+=p*10;let c=0;return c=S%2,S=Math.floor(S/2),new f(u,h,M,S,c)},f.toStr=e=>{const r="_";let t=("0"+e.h).slice(-2)+r+("0"+e.m).slice(-2)+r+("0"+e.s).slice(-2)+r+("0"+e.f).slice(-2);return e.field&&(t+="_1"),t},f.fromStr=e=>{const t=e.split("_").map(Number);if(t.length==4){const[n,l,a,i]=t;return new f(n,l,a,i,0)}else if(t.length==5){const[n,l,a,i,o]=t;return new f(n,l,a,i,o)}else throw new Error("Invalid timecode format: "+e)},f.fromMetadata=e=>{const r=/^(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d))?$/,t=e.timecode.match(r);if(!t)throw new Error("Invalid timecode format: "+e.timecode);const[,n,l,a,i,o]=t,u=Number(n),p=Number(l),h=Number(a),M=Number(i),S=o?Number(o):0;return new f(u,p,h,M,S)};let g=f;class O{constructor(){this.start=0,this.end=0,this.startTimeoutForSeconds=e=>{this.start=performance.now(),this.end=this.start+e*1e3},this.isTimeout=()=>{const e=performance.now()>=this.end;return e&&(this.start=0,this.end=0),!e}}}const d={lastRendererFrameSent:0,isRAFSeen:!1,isRVFCSeen:!1,RVFCmissed:!1,RVFCframeExpected:0,compensationMode:!1,compensationCounter:0,frameCorrection:0,lastMessageSent:""};let R=null,F,m,D=new O;self.onmessage=async s=>{const{data:e}=s;e.type==="SET_RENDERER_PORT"&&(R=e.port,R.onmessage=k),e.type==="ADAPTER_UPDATE_DATA"&&(m=e.data,T()),e.type==="SET_OPTIONS"&&(F=e.options)};function k(s){F&&w(F,"Adapter")&&console.log("[AdapterWorker] Message from Renderer:",s.data)}const T=()=>{!m||m.siData.isVideoPaused||(x.isChromeMac()?b():x.isSafariMac()&&W())},b=()=>{if(!m||m.siData.isVideoPaused||!m.vfcData.lastFrameMetadata)return;const{siData:s,vfcData:e,afData:r}=m;if(e.videoFPS>30){if(s.isRAFSeen&&s.isRVFCSeen)return;if(!s.isRAFSeen)if(s.RVFCmissed&&(d.RVFCframeExpected=e.lastCalculatedMediaTimeVideoFrame+1),e.lastCalculatedMediaTimeVideoFrame<d.RVFCframeExpected){d.compensationMode=!0,v(e.lastCalculatedMediaTimeVideoFrame+1),d.compensationCounter<10?(d.RVFCframeExpected++,d.compensationCounter++):(d.compensationCounter=0,d.frameCorrection=1,console.error("RVFC frame compensation limit reached"));return}else d.compensationMode&&(d.compensationMode=!1),d.compensationCounter=0;if(!s.isRVFCSeen){let t=0;d.frameCorrection>0&&(t=d.frameCorrection,d.frameCorrection=Math.max(d.frameCorrection-.2,0)),v(e.lastCalculatedMediaTimeVideoFrame,t)}}else if(e.videoFPS>15){if(e.lastCalculatedMediaTimeVideoFrame==d.lastRendererFrameSent)return;d.lastRendererFrameSent=e.lastCalculatedMediaTimeVideoFrame,e.lastFrameMetadata.expectedDisplayTime-e.lastFrameNow>5?setTimeout(v,20,e.lastCalculatedMediaTimeVideoFrame+1):setTimeout(v,5,e.lastCalculatedMediaTimeVideoFrame+1)}else e.videoFPS>10},W=()=>{if(!m||m.siData.isVideoPaused||!m.vfcData.lastFrameMetadata)return;const{siData:s,vfcData:e,afData:r}=m;let t=e.lastCalculatedPlayerTimeFraction;const n=e.previousCalculatedPlayerTimeFraction;t<.3&&t>.1&&n<.3&&n>.1&&(t=Math.min(t,n));let l=0;t<.1?l=0:t>.1&&t<.3?l=(t-.1)/(.3-.1):l=1;let a=e.lastCalculatedPlayerTimeVideoFrame;l==1&&(a++,l=0),v(a,l)},v=(s,e)=>{if(!m)return;m.siData.workingFps;const r=g.fromFrames(s,6e4/1001);if(D.isTimeout())E(r);else{const t=m.vfcData.videoFPS;if(t<=15||t>70){console.error("Video FPS is out of supported range: "+t),D.startTimeoutForSeconds(3),E(r);return}const n=m.afData.animationFPS;if(n<=30||n>70){console.error("Animation FPS is out of supported range: "+n),D.startTimeoutForSeconds(3),E(r);return}N(r,e)}},N=(s,e)=>{const r=g.toStr(s);r!=d.lastMessageSent&&(d.lastMessageSent=r,F&&w(F,"Adapter")&&console.log(`[AdapterWorker] Rendering augmentation for timecode: ${r} , ${s}`),y(r,e))},E=s=>{const e=g.toStr(s);F&&w(F,"Adapter")&&console.log("[AdapterWorker] Clearing augmentation"),y(e,0,!0)},y=(s,e,r)=>{if(!R||!m)return;const t=s;F&&w(F,"Adapter")&&console.log(`[AdapterWorker] Sending current time code to the Renderer: ${t}`);const n={timeCode:t,frameCorrection:e||0,fps:V(m.siData.workingFps),cloudFrontURL:m.cloudFrontURL,bucketName:m.bucketName,offsets:m.offsets},a={type:r?"RENDERER_CLEAR":"RENDERER_DRAW",streamData:n};R.postMessage(a)};setInterval(T,2)})();\n',N=typeof self<"u"&&self.Blob&&new Blob([O],{type:"text/javascript;charset=utf-8"});function Z(s){let t;try{if(t=N&&(self.URL||self.webkitURL).createObjectURL(N),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(O),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}class Q{constructor(t){this.canPlayListner=()=>this.setupCanvas(),this.clickListner=e=>{this.clicker.click(e)},this.mediaTime=0,this.timecodeChecker=new $(0),this.OTTPlayer=t,this.options=t.options,this.downloaderWorker=new q,this.decoderWorker=new K,this.rendererWorker=new J,this.adapterWorker=new Z,this.rendererToDownloader=new MessageChannel,this.downloaderToDecoder=new MessageChannel,this.decoderToRenderer=new MessageChannel,this.adapterToRenderer=new MessageChannel,this.setupWorkers(),this.canvas=document.createElement("canvas"),this.OTTPlayer.video.readyState>=3?this.setupCanvas():this.OTTPlayer.video.addEventListener("canplay",this.canPlayListner,{once:!0}),this.processedTimecodes=[],this.clicker=new X(this.OTTPlayer.video,this.rendererWorker),this.segmentFirstFrameTimecode=new u,this.syncPoint={frame:0,playerTime:0,stringTime:""},this.cacheStarted=!1,this.animationFPScalculator=new C(20),this.videoFPScalculator=new C(20),this.startAnimationFrameLoop(),this.startVideoFrameCallbackLoop()}onNewMetadata(t){const e=v(this.videoFPScalculator.getFPS());this.segmentFirstFrameTimecode=V(t),this.metadataReportedFrameTimecode=H(t),this.metadataReportedFrameTimecode&&e&&!this.cacheStarted&&(this.syncPoint=W(t,e,this.metadataReportedFrameTimecode),this.cacheStarted=!0)}async onNewSegment(t){const e=v(this.videoFPScalculator.getFPS());this.segmentFirstFrameTimecode&&e&&(this.syncPoint=Y(t,e,this.segmentFirstFrameTimecode))}startAnimationFrameLoop(){const t=()=>{var e;this.animationFPScalculator.addTimestamp(performance.now()/1e3),(e=this.OTTPlayer.gameParams)!=null&&e.bucketName&&this.OTTPlayer.gameParams.offsets&&this.cacheStarted&&!this.OTTPlayer.RUN_ADAPTER&&this.callRendererWorker(),this.OTTPlayer.RUN_PIXEL_TICKERS&&this.OTTPlayer.pixelTickers.forEach(i=>{i.update()}),this.animationFPScalculator.getFPS(),this.animationFrameLoopId=requestAnimationFrame(t)};this.animationFrameLoopId=requestAnimationFrame(t)}startVideoFrameCallbackLoop(){const t=(e,i)=>{this.mediaTime=i.mediaTime,this.videoFPScalculator.addTimestamp(i.mediaTime),this.videoFrameCallbackLoopId=this.OTTPlayer.video.requestVideoFrameCallback(t)};this.videoFrameCallbackLoopId=this.OTTPlayer.video.requestVideoFrameCallback(t)}setupCanvas(){const t=this.OTTPlayer.video,e=t.parentElement;this.canvas.width=t.videoWidth,this.canvas.height=t.videoHeight,this.canvas.style.zIndex="3000",this.canvas.style.position="absolute",this.canvas.style.top="50%",this.canvas.style.transform="translateY(-50%)",this.canvas.style.left="0",this.canvas.style.width=e.style.width,this.canvas.style.height=e.style.height,this.canvas.style.pointerEvents="none",e.addEventListener("click",this.clickListner),e.style.position="relative",e.appendChild(this.canvas);const i=this.canvas.transferControlToOffscreen(),r={type:"INIT_OFFSCREEN",offscreen:i,options:this.options};this.rendererWorker.postMessage(r,[i])}setupWorkers(){this.rendererWorker.postMessage({type:"SET_DOWNLOADER_PORT",port:this.rendererToDownloader.port1},[this.rendererToDownloader.port1]),this.downloaderWorker.postMessage({type:"SET_RENDERER_PORT",port:this.rendererToDownloader.port2},[this.rendererToDownloader.port2]),this.downloaderWorker.postMessage({type:"SET_DECODER_PORT",port:this.downloaderToDecoder.port1},[this.downloaderToDecoder.port1]),this.decoderWorker.postMessage({type:"SET_DOWNLOADER_PORT",port:this.downloaderToDecoder.port2},[this.downloaderToDecoder.port2]),this.decoderWorker.postMessage({type:"SET_RENDERER_PORT",port:this.decoderToRenderer.port1},[this.decoderToRenderer.port1]),this.rendererWorker.postMessage({type:"SET_DECODER_PORT",port:this.decoderToRenderer.port2},[this.decoderToRenderer.port2]),this.adapterWorker.postMessage({type:"SET_RENDERER_PORT",port:this.adapterToRenderer.port1},[this.adapterToRenderer.port1]),this.rendererWorker.postMessage({type:"SET_ADAPTER_PORT",port:this.adapterToRenderer.port2},[this.adapterToRenderer.port2]),this.downloaderWorker.postMessage({type:"SET_OPTIONS",options:this.options}),this.decoderWorker.postMessage({type:"SET_OPTIONS",options:this.options}),this.adapterWorker.postMessage({type:"SET_OPTIONS",options:this.options})}callAdapterWorker(t){this.adapterWorker.postMessage({type:"ADAPTER_UPDATE_DATA",data:t})}callRendererWorker(t,e,i){var h,l;let r=t;if(!r){const f=u.calculateCurrentTimeCode(this.OTTPlayer);r=u.toStr(f)}this.options&&m(this.options,"Clocker")&&console.log(`[Clocker] Sending current time code to the Renderer: ${r}`);const n={timeCode:r,frameCorrection:e||0,fps:v(this.videoFPScalculator.getFPS()),cloudFrontURL:this.OTTPlayer.options.cloudFrontURL,bucketName:((h=this.OTTPlayer.gameParams)==null?void 0:h.bucketName)||"",offsets:((l=this.OTTPlayer.gameParams)==null?void 0:l.offsets)||[]},a={type:i?"RENDERER_CLEAR":"RENDERER_DRAW",streamData:n};this.rendererWorker.postMessage(a)}delete(){const t=this.OTTPlayer.video,e=t.parentElement;e.removeChild(this.canvas),this.rendererWorker.terminate(),this.downloaderWorker.terminate(),this.decoderWorker.terminate(),this.adapterWorker.terminate(),this.animationFrameLoopId&&cancelAnimationFrame(this.animationFrameLoopId),this.videoFrameCallbackLoopId&&t.cancelVideoFrameCallback(this.videoFrameCallbackLoopId),t.removeEventListener("canplay",this.canPlayListner),e.removeEventListener("click",this.clickListner)}}class tt{constructor(t){this.fetchGameParams=async(e,i)=>{const r=`${e}/${i}.json`;this.options&&m(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching GameParams from ${r}`);const n=await fetch(r);if(!n.ok)throw new Error(`HTTP error! Status: ${n.status}`);const o=await n.json();return o.hasOwnProperty("bucketName")&&o.hasOwnProperty("offsets")?o:(this.options&&m(this.options,"Errors")&&console.error(`[Fetcher] Game params for ${i} not found in JSON.`),n)},this.fetchMetadata=async(e,i,r,n)=>{const a=`${`${e}/${i}`}/manifests/59.94/${n}.zip`;this.options&&m(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching metadata from ${a}`);const h=await fetch(a),l=h.headers.get("x-tgi-ott-actions");let f;if(l?f=JSON.parse(l):f={toggle:{ios:!0,android:!0,web:!0}},!h.ok)throw new Error(`HTTP error! Status: ${h.status}`);return{arrayBuffer:await h.arrayBuffer(),ottActions:f}},this.options=t}}class et{constructor(){this.metrics=new Map,this.containers=[],this.createContainer=()=>{const t=document.createElement("div");t.style.display="flex",t.style.gap="10px",t.style.marginBottom="10px";const e={div:t,metrics:[]};return this.containers.push(e),document.body.appendChild(t),e},this.createMetric=(t,e)=>{const i=document.createElement("span"),r={name:t,value:"",span:i};return e.metrics.push(r),i.textContent=`${t}: ${r.value}`,e.div.appendChild(i),this.metrics.set(t,r),r},this.updateMetric=(t,e)=>{const i=this.metrics.get(t);if(!i){console.error("Metric does not exist");return}typeof e=="boolean"?i.value=e?"true":"false":i.value=e,i.span.textContent=`${t}: ${i.value}`}}delete(){this.containers.forEach(t=>{t.div.remove()})}}const x=s=>s.toString().padStart(2,"0"),F=":",it=(s,t,e=!1)=>{let i="";return Array.isArray(s)?(i=[x(s[0]),x(s[1]),x(s[2]),x(s[3])].join(":"),e==!0?s[4]==1&&t?i+=".2":i+=".1":s[4]==1&&t&&(i+=".1")):(i=("0"+s.h).slice(-2)+F+("0"+s.m).slice(-2)+F+("0"+s.s).slice(-2)+F+("0"+s.f).slice(-2),i+="."+(s.field?"1":"2")),i},rt=(s,t,e)=>{let i=60,r=0;Math.floor(t)==60?(i=60,r=0):Math.floor(t)==59?(i=60,r=4):Math.floor(t)==30?(i=30,r=0):Math.floor(t)==29&&(i=30,r=2);let n=0,a=Math.floor(t*60*10)*6,h=s[0],l=s[1],f=s[2],c=s[3],_=s[4];return n+=h*a,n+=l*(i*60),n+=f*i,n+=c*2+_,n-=r*l,n+=r*Math.floor(l/10),n};class st{constructor(){this.start=0,this.end=0,this.startTimeoutForSeconds=t=>{this.start=performance.now(),this.end=this.start+t*1e3},this.isTimeout=()=>{const t=performance.now()>=this.end;return t&&(this.start=0,this.end=0),!t}}}class nt{constructor(t){if(this.firstFrameTimecode=[0,0,0,0,0],this.timeout=new st,this.metrics=new et,this.afData={counter:0,lastTimestamp:0,timeFromLastRVFC:0,animationFPS:0},this.vfcData={counter:0,lastTimestamp:0,timeFromLastRAF:0,videoFPS:0,lastFrameMetadata:null,lastFrameNow:0,lastCalculatedMediaTimeVideoFrame:0,lastCalculatedPlayerTimeVideoFrame:0,lastCalculatedPlayerTimeFraction:0,previousCalculatedPlayerTimeFraction:2},this.siData={counter:0,lastTimestamp:0,timeFromLastRAF:0,timeFromLastRVFC:0,lastSeenRAFCount:0,lastSeenRVFCCount:0,isRAFSeen:!1,isRVFCSeen:!1,isVideoPaused:!0,workingFps:0,RVFCmissed:0,RVFCframeExpected:0,lastCallback:null,lastCalculatedFrame:0,lastRendererFrameSent:0,lastMessageSent:"",compensationMode:!1,compensationCounter:0,frameCorrection:0,determineFramesTimestamps:[],determineFramesIntervals:[]},this.tcTimeStamp=0,this.timecode_offset=0,this.onAnimationFrame=()=>{if(this.video.paused||!this.OTTPlayer.clocker){window.requestAnimationFrame(this.onAnimationFrame);return}this.afData.counter++,this.afData.lastTimestamp=performance.now(),this.afData.timeFromLastRVFC=this.afData.lastTimestamp-this.vfcData.lastTimestamp,this.afData.animationFPS=this.OTTPlayer.clocker.animationFPScalculator.getPerciseFPS(),this.siData.lastCallback=="RAF"&&this.siData.RVFCmissed++,this.siData.lastCallback="RAF",this.debug&&(this.metrics.updateMetric("RAF calls",this.afData.counter),this.metrics.updateMetric("Last RAF call",this.afData.lastTimestamp.toFixed(2)),this.metrics.updateMetric("RAF - RVFC dif",this.afData.timeFromLastRVFC.toFixed(2))),window.requestAnimationFrame(this.onAnimationFrame),this.determineFrameUpdate()},this.onVideoFrame=(e,i)=>{if(this.video.paused||!this.OTTPlayer.clocker||!this.OTTPlayer.gameParams){this.video.requestVideoFrameCallback(this.onVideoFrame);return}this.vfcData.counter++,this.vfcData.lastTimestamp=performance.now(),this.vfcData.timeFromLastRAF=this.vfcData.lastTimestamp-this.afData.lastTimestamp,this.siData.RVFCmissed=0,this.vfcData.videoFPS=this.OTTPlayer.clocker.videoFPScalculator.getPerciseFPS(),this.siData.lastCallback="RVFC";const r=(this.video.currentTime-this.syncPoint.playerTime)%(60*60*24)*(6e4/1001),n=Math.floor(r)+this.syncPoint.frame,o=u.calculateCurrentOffset(n,this.OTTPlayer.gameParams.offsets);let a=n-o;a<0&&(a+=5178816),a>=5178816&&(a-=5178816),a++,this.vfcData.lastCalculatedPlayerTimeVideoFrame=a,this.vfcData.previousCalculatedPlayerTimeFraction=this.vfcData.lastCalculatedPlayerTimeFraction,this.vfcData.lastCalculatedPlayerTimeFraction=r-Math.floor(r);const h=(i.mediaTime-this.syncPoint.playerTime)%(60*60*24)*(6e4/1001),l=Math.floor(h+.1)+this.syncPoint.frame,f=u.calculateCurrentOffset(l,this.OTTPlayer.gameParams.offsets);let c=l-f;c<0&&(c+=5178816),c>=5178816&&(c-=5178816),c++,this.vfcData.lastCalculatedMediaTimeVideoFrame=c,this.vfcData.lastFrameMetadata=i,this.vfcData.lastFrameNow=e,this.debug&&(this.metrics.updateMetric("Last metadata media time frame",this.vfcData.lastCalculatedMediaTimeVideoFrame),this.metrics.updateMetric("Last metadata player time frame",this.vfcData.lastCalculatedPlayerTimeVideoFrame),this.metrics.updateMetric("Last calculated player time fraction",this.vfcData.lastCalculatedPlayerTimeFraction.toFixed(4)),this.metrics.updateMetric("RVFC calls",this.vfcData.counter),this.metrics.updateMetric("Last RVFC call",this.vfcData.lastTimestamp.toFixed(2))),this.video.requestVideoFrameCallback(this.onVideoFrame),this.determineFrameUpdate()},this.determineFrameUpdate=()=>{var e,i;if(!(!this.OTTPlayer.clocker||!this.vfcData.lastFrameMetadata)){if(this.siData.counter++,this.siData.isVideoPaused=this.video.paused,this.siData.isRAFSeen=this.siData.lastSeenRAFCount==this.afData.counter,this.siData.isRVFCSeen=this.siData.lastSeenRVFCCount==this.vfcData.counter,this.siData.lastTimestamp=performance.now(),this.siData.timeFromLastRAF=this.siData.lastTimestamp-this.afData.lastTimestamp,this.siData.timeFromLastRVFC=this.siData.lastTimestamp-this.vfcData.lastTimestamp,this.siData.lastSeenRAFCount=this.afData.counter,this.siData.lastSeenRVFCCount=this.vfcData.counter,this.siData.workingFps=this.OTTPlayer.clocker.videoFPScalculator.getFPS(),this.debug){const r=performance.now();if(this.siData.determineFramesTimestamps||(this.siData.determineFramesTimestamps=[]),this.siData.determineFramesTimestamps.length>0){const n=r-this.siData.determineFramesTimestamps[this.siData.determineFramesTimestamps.length-1];this.siData.determineFramesIntervals||(this.siData.determineFramesIntervals=[]),this.siData.determineFramesIntervals.push(n.toFixed(2)),this.siData.determineFramesIntervals.length>10&&this.siData.determineFramesIntervals.shift(),this.metrics.updateMetric("Determine frames intervals",this.siData.determineFramesIntervals.join(", "))}this.siData.determineFramesTimestamps.push(r),this.metrics.updateMetric("RVFC missed",this.siData.RVFCmissed)}if(!this.OTTPlayer.options.ADAPTER_RUN_IN_WORKER)this.platformSpecificFrameUpdate();else{const r={siData:this.siData,vfcData:this.vfcData,afData:this.afData,cloudFrontURL:this.OTTPlayer.options.cloudFrontURL,bucketName:((e=this.OTTPlayer.gameParams)==null?void 0:e.bucketName)||"",offsets:((i=this.OTTPlayer.gameParams)==null?void 0:i.offsets)||[]};this.OTTPlayer.clocker.callAdapterWorker(r)}}},this.determineFrameUpdateChromeMac=()=>{if(!(this.video.paused||!this.OTTPlayer.clocker||!this.vfcData.lastFrameMetadata))if(this.vfcData.videoFPS>30){if(this.siData.isRAFSeen&&this.siData.isRVFCSeen)return;if(!this.siData.isRAFSeen)if(this.siData.RVFCmissed&&(this.siData.RVFCframeExpected=this.vfcData.lastCalculatedMediaTimeVideoFrame+1),this.vfcData.lastCalculatedMediaTimeVideoFrame<this.siData.RVFCframeExpected){this.siData.compensationMode=!0,this.debug&&this.metrics.updateMetric("Compensation","+1"),this.callRenderer(this.vfcData.lastCalculatedMediaTimeVideoFrame+1),this.siData.compensationCounter<10?(this.siData.RVFCframeExpected++,this.siData.compensationCounter++,this.debug&&this.metrics.updateMetric("Drop frame compensation",!1)):(this.siData.compensationCounter=0,this.siData.frameCorrection=1,console.error("RVFC frame compensation limit reached"),this.debug&&this.metrics.updateMetric("Drop frame compensation",!0));return}else this.siData.compensationMode&&(this.siData.compensationMode=!1),this.siData.compensationCounter=0;if(!this.siData.isRVFCSeen){let e=0;this.siData.frameCorrection>0&&(e=this.siData.frameCorrection,this.siData.frameCorrection=Math.max(this.siData.frameCorrection-.2,0),this.debug&&this.metrics.updateMetric("Drop frame compensation",this.siData.frameCorrection.toFixed(2))),this.debug&&this.metrics.updateMetric("Compensation",0),this.callRenderer(this.vfcData.lastCalculatedMediaTimeVideoFrame,e)}}else if(this.vfcData.videoFPS>15){if(this.vfcData.lastCalculatedMediaTimeVideoFrame==this.siData.lastRendererFrameSent)return;this.siData.lastRendererFrameSent=this.vfcData.lastCalculatedMediaTimeVideoFrame,this.vfcData.lastFrameMetadata.expectedDisplayTime-this.vfcData.lastFrameNow>5?setTimeout(this.callRenderer,20,this.vfcData.lastCalculatedMediaTimeVideoFrame+1):setTimeout(this.callRenderer,5,this.vfcData.lastCalculatedMediaTimeVideoFrame+1)}else this.vfcData.videoFPS>10},this.determineFrameUpdateSifariMac=()=>{if(this.video.paused||!this.OTTPlayer.clocker||!this.vfcData.lastFrameMetadata)return;let e=this.vfcData.lastCalculatedPlayerTimeFraction;const i=this.vfcData.previousCalculatedPlayerTimeFraction;e<.3&&e>.1&&i<.3&&i>.1&&(e=Math.min(e,i));let r=0;e<.1?r=0:e>.1&&e<.3?r=(e-.1)/(.3-.1):r=1,this.debug&&this.metrics.updateMetric("Compensation",r.toFixed(4));let n=this.vfcData.lastCalculatedPlayerTimeVideoFrame;r==1&&(n++,r=0),this.callRenderer(n,r)},this.callRenderer=(e,i)=>{if(!this.OTTPlayer.clocker||!this.OTTPlayer)return;this.debug&&this.metrics.updateMetric("Last sent frame",e);const r=this.OTTPlayer.clocker.videoFPScalculator.getFPS();this.debug&&this.metrics.updateMetric("FPS",r.toFixed(2));const n=u.fromFrames(e,6e4/1001);if(this.timeout.isTimeout())this.clearAugmentation(n);else{const o=this.OTTPlayer.clocker.videoFPScalculator.getPerciseFPS();if(o<=15||o>70){console.error("Video FPS is out of supported range: "+o),this.timeout.startTimeoutForSeconds(3),this.clearAugmentation(n);return}const a=this.OTTPlayer.clocker.animationFPScalculator.getPerciseFPS();if(a<=30||a>70){console.error("Animation FPS is out of supported range: "+a),this.timeout.startTimeoutForSeconds(3),this.clearAugmentation(n);return}this.renderAugmentation(n,i)}},this.renderAugmentation=(e,i)=>{if(!this.OTTPlayer||!this.OTTPlayer.clocker)throw new Error("OTTPlayer is not initialized");const r=u.toStr(e);r!=this.siData.lastMessageSent&&(this.siData.lastMessageSent=r,this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log(`Rendering augmentation for timecode: ${r} , ${e}`),this.debug&&this.metrics.updateMetric("Last sent timecode",r),this.OTTPlayer.clocker.callRendererWorker(r,i))},this.clearAugmentation=e=>{if(!this.OTTPlayer||!this.OTTPlayer.clocker)throw new Error("OTTPlayer is not initialized");const i=u.toStr(e);this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("Clearing augmentation"),this.OTTPlayer.clocker.callRendererWorker(i,0,!0)},this.OTTPlayer=t,this.playerOptions=t.options,this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("Adapter is initialized",this.OTTPlayer),this.video=t.video,this.debug=this.playerOptions.debug?this.playerOptions.debug.on:!1,this.syncPoint={frame:0,playerTime:0,stringTime:""},this.OTTPlayer.video.readyState>=3?this.setupAdapter():this.OTTPlayer.video.addEventListener("canplay",()=>this.setupAdapter(),{once:!0}),y.isChromeMac())this.platformSpecificFrameUpdate=this.determineFrameUpdateChromeMac;else if(y.isSafariMac())this.platformSpecificFrameUpdate=this.determineFrameUpdateSifariMac;else{this.platformSpecificFrameUpdate=()=>{};const e=y.getCurrentPlatform(),i=y.getBrowserName();console.error("Unsupported platform: "+e+" "+i);return}if(this.debug){const e=this.metrics.createContainer(),i=this.metrics.createContainer(),r=this.metrics.createContainer(),n=this.metrics.createContainer(),o=this.metrics.createContainer();this.metrics.createMetric("RAF calls",e),this.metrics.createMetric("RVFC calls",e),this.metrics.createMetric("RVFC missed",e),this.metrics.createMetric("Last sent frame",e),this.metrics.createMetric("Last sent timecode",e),this.metrics.createMetric("Last metadata media time frame",i),this.metrics.createMetric("Last metadata player time frame",i),this.metrics.createMetric("Last calculated player time fraction",i),this.metrics.createMetric("FPS",r),this.metrics.createMetric("Last RAF call",r),this.metrics.createMetric("Last RVFC call",r),this.metrics.createMetric("RAF - RVFC dif",r),this.metrics.createMetric("Determine frames intervals",n),this.metrics.createMetric("Compensation",o),this.metrics.createMetric("Drop frame compensation",o)}}setupAdapter(){const t=this.video;this.animationFrameLoopId=window.requestAnimationFrame(this.onAnimationFrame),this.videoFrameCallbackLoopId=t.requestVideoFrameCallback(this.onVideoFrame)}onNewSegmentForMetadata(t){let e={frame:0,playerTime:0,stringTime:""};e.frame=rt(this.firstFrameTimecode,6e4/1001),e.stringTime=it(this.firstFrameTimecode,!0,!0),this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("New segment ("+t.url+"): "+e.stringTime+" ("+e.frame+") playing at "+t.playbackTime),e.playerTime=t.playbackTime,this.syncPoint=e,t.mimeType.includes("video")&&this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("url: "+t.url)}onNewMetadata(t){if(t&&t.metadata&&t.metadata.id==0||y.isSafariMac()){if(t.metadata.messageData)t.metadata.messageData=this.processTimedMetadata(t.metadata.messageData,t.metadata.presentationTime);else if(t.metadata.frames&&t.metadata.frames.length&&t.metadata.frames[0].key&&t.metadata.frames[0].key.toLowerCase()==="priv"){const e=t.metadata.frames.filter(i=>i.info&&i.info.toLowerCase().includes("ntc"));if(e.length){const i=`${e[e.length-1].info}\0${String.fromCharCode(...e[e.length-1].data)}`;t.metadata.messageData=this.processTimedMetadata(i,t.metadata.presentationTime)}}if(t.metadata.id==0||y.isSafariMac()&&this.timecode_offset==0){t.metadata.presentationTime*1e3;const e=new Date(this.tcTimeStamp-this.timecode_offset);let i=Math.round(e.getUTCMilliseconds()*30*2/1001)/2;const r=i%1;let n=1;r==.5&&(i=Math.floor(i),n=2),this.firstFrameTimecode=[e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),Math.floor(i),n==1?0:1]}}}processTimedMetadata(t,e){let i="";if(t&&t.includes("www.mediakind.com/NTC")){const r=t.replace(/.*NTC./,"");let n=0;for(;n+8<=r.length;){const o=r.substring(n,n+4),a=((r.charCodeAt(n+4)*256+r.charCodeAt(n+5))*256+r.charCodeAt(n+6))*256+r.charCodeAt(n+7);if(n+8+a>r.length)break;const h=r.substring(n+8,n+8+a);o=="utc_"&&new Date(parseInt(h)).getTime()/1e3,o=="tc__"&&(this.tcTimeStamp=new Date(parseInt(h)).getTime()),o==="offs"&&(this.timecode_offset=parseInt(h)/90),n+=8+a}}return i}delete(){this.animationFrameLoopId&&cancelAnimationFrame(this.animationFrameLoopId),this.videoFrameCallbackLoopId&&this.video.cancelVideoFrameCallback(this.videoFrameCallbackLoopId),this.intervalLoopId&&clearInterval(this.intervalLoopId),this.metrics.delete()}}class S{constructor(t,e){this.size=1,this.positionElement=()=>{let r=0,n=0;this.corner=="left-top"?(this.element.style.top=`${r}px`,this.element.style.left=`${n}px`):this.corner=="right-top"?(this.element.style.top=`${r}px`,this.element.style.left=`${n+this.video.offsetWidth-this.size}px`):this.corner=="right-bottom"?(this.element.style.top=`${r+this.video.offsetHeight-this.size}px`,this.element.style.left=`${n+this.video.offsetWidth-this.size}px`):this.corner=="left-bottom"&&(this.element.style.top=`${r+this.video.offsetHeight-this.size}px`,this.element.style.left=`${n}px`)},this.video=e,this.container=e.parentElement,this.corner=t;const i=document.createElement("div");i.style.position="absolute",i.style.width=`${this.size}px`,i.style.height=`${this.size}px`,i.style.transition="background-color 0s",i.style.zIndex="100000",this.element=i,this.container.appendChild(i),this.positionElement()}getRandomColor(){return`#${Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}`}update(){this.element.style.backgroundColor=this.getRandomColor(),this.positionElement()}delete(){this.container.removeChild(this.element)}static createInAllCorners(t){return[new S("left-top",t),new S("right-top",t),new S("right-bottom",t),new S("left-bottom",t)]}static updateAll(t){t.forEach(e=>e.update())}static deleteAll(t){t.forEach(e=>e.delete())}}class G{constructor(t,e,i){this.RUN_ADAPTER=!0,this.RUN_PIXEL_TICKERS=!0,this.pixelTickers=[],this.fetchGameParams=async()=>{if(this.fetcher)try{m(this.options,"OTTPlayer")&&console.log("[OTTPlayer] GameId: ",this.options.gameId);const r=await this.fetcher.fetchGameParams(this.options.cloudFrontURL,this.options.gameId);if(r instanceof Response)throw console.log("gameParams: ",r),new Error("Error fetching game params:"+r.type);this.gameParams=r}catch(r){m(this.options,"Errors")&&console.error("[OTTPlayer] Error fetching game params:",r)}},this.video=t,this.options={...i,cloudFrontURL:"https://d1ze2lfw5ong7.cloudfront.net",augmentation:{channelName:"nba"},ADAPTER_RUN_IN_WORKER:!1,DOWNLOADER_UPDATE_FREQUENCY:1e3,DOWNLOADER_ZIP_START_OFFSET:2,DOWNLOADER_ZIP_END_OFFSET:4,DOWNLOADER_ZIP_LENGTH_SECONDS:2,DECODER_UPDATE_FREQUENCY:40,DECODER_FRAME_BATCH_SIZE:5,DECODER_LEAD_TIME_MILLIS:400},j(this.options).then(()=>{this.clocker=new Q(this),this.fetcher=new tt(this.options),this.RUN_ADAPTER&&(this.adapter=new nt(this)),this.RUN_PIXEL_TICKERS&&(this.pixelTickers=S.createInAllCorners(this.video)),this.fetchGameParams(),window.BB.instances.length>0&&window.BB.instances.forEach(r=>{r.delete()}),window.BB.instances.push(this),console.log(window.BB.instances.length)})}onNewMetadata(t){if(this.RUN_ADAPTER){if(!this.adapter)return;this.adapter.onNewMetadata(t)}else{if(!this.clocker)return;this.clocker.onNewMetadata(t)}}onNewSegment(t){if(this.RUN_ADAPTER){if(!this.adapter)return;this.adapter.onNewSegmentForMetadata(t)}else{if(!this.clocker)return;this.clocker.onNewSegment(t)}}delete(){var e;const t=window.BB.instances.indexOf(this);t>=0&&window.BB.instances.splice(t,1),(e=this.clocker)==null||e.delete(),this.clocker=void 0,this.fetcher=void 0,this.adapter&&(this.adapter.delete(),this.adapter=void 0),S.deleteAll(this.pixelTickers),this.pixelTickers=[]}toggle(t){this.options.enabled=t}}return window.BB={OTTPlayer:G,instances:[]},G});
|
|
137
|
+
\`;class F{constructor(o,a){this.adTextures=new Map,this.allPlaceholders=[],this.setAllPlaceholders=e=>{this.allPlaceholders=e},this.initShadersAlphaMask=e=>{const t=this.compileShader(e,e.VERTEX_SHADER,N),i=this.compileShader(e,e.FRAGMENT_SHADER,O),r=e.createProgram();return e.attachShader(r,t),e.attachShader(r,i),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.error("Could not link shaders:",e.getProgramInfoLog(r)),null)},this.initShadersAugmentation=e=>{const t=this.compileShader(e,e.VERTEX_SHADER,k),i=this.compileShader(e,e.FRAGMENT_SHADER,G(this.allPlaceholders)),r=e.createProgram();return e.attachShader(r,t),e.attachShader(r,i),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.error("Could not link shaders:",e.getProgramInfoLog(r)),null)},this.compileShader=(e,t,i)=>{const r=e.createShader(t);return e.shaderSource(r,i),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error(\`Error compiling shader: \${e.getShaderInfoLog(r)}\`),e.deleteShader(r),null)},this.createTextureFromVideoFrame=e=>{const t=this.gl,i=t.createTexture();return t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!0),t.bindTexture(t.TEXTURE_2D,i),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.bindTexture(t.TEXTURE_2D,null),i},this.deleteTexture=e=>{this.gl.deleteTexture(e)},this.drawAlphaMask=e=>{if(!this.program){this.options&&u(this.options,"Errors")&&console.error("[Renderer] Program not initialized");return}(!this.positionBuffer||!this.uvBuffer)&&this.options&&u(this.options,"Errors")&&console.error("[Renderer] Buffers not initialized");const t=this.gl,i=this.program,r=t.getAttribLocation(i,"a_position"),s=t.getAttribLocation(i,"a_uv"),n=t.getUniformLocation(i,"u_alphaMask");t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),t.uniform1i(n,0),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.uvBuffer),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,2,t.FLOAT,!1,0,0),t.clear(t.COLOR_BUFFER_BIT);let l=t.TRIANGLES;t.drawArrays(l,0,6)},this.drawAugmentation=(e,t)=>{if(!this.program){this.options&&u(this.options,"Errors")&&console.error("[Renderer] Program not initialized");return}const i=this.gl,r=this.program;if(!this.allPlaceholders){this.options&&u(this.options,"Errors")&&console.error("[Renderer] Placeholder names not initialized");return}i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,e);let s=i.getUniformLocation(r,"u_alphaMask");s&&i.uniform1i(s,0);let n=0;const l=Object.keys(t).map(g=>t[g]),h=l.map(g=>g.name);this.allPlaceholders.forEach(g=>{if(h.includes(g)&&this.adTextures.has(g)){const v=l.filter(Z=>Z.name===g)[0],C=this.adTextures.get(g);i.activeTexture(i.TEXTURE1+n),i.bindTexture(i.TEXTURE_2D,C);let I=i.getUniformLocation(r,"u_ad"+g);I&&i.uniform1i(I,n+1);let Q="u_hasLogo"+g,K=i.getUniformLocation(r,Q);i.uniform1i(K,1);let J="u_matrix"+g,q=i.getUniformLocation(r,J);i.uniformMatrix3fv(q,!1,v.tranform),n++}else{let v="u_hasLogo"+g,C=i.getUniformLocation(r,v);i.uniform1i(C,0)}});const d=i.getAttribLocation(r,"a_position"),R=i.getAttribLocation(r,"a_uv"),p=i.getUniformLocation(r,"u_resolution");i.uniform2f(p,i.canvas.width,i.canvas.height),i.bindBuffer(i.ARRAY_BUFFER,this.positionBuffer),i.enableVertexAttribArray(d),i.vertexAttribPointer(d,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.uvBuffer),i.enableVertexAttribArray(R),i.vertexAttribPointer(R,2,i.FLOAT,!1,0,0),i.viewport(0,0,i.canvas.width,i.canvas.height),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT);let E=i.TRIANGLES;i.drawArrays(E,0,6)},this.setRectangle=(e,t,i,r,s)=>{const n=t,l=i,h=t+r,d=i+s;e.bufferData(e.ARRAY_BUFFER,new Float32Array([n,l,h,l,n,d,n,d,h,l,h,d]),e.STATIC_DRAW)},this.generateAdTexture=(e,t,i)=>{const r=this.gl;if(!this.program){this.options&&u(this.options,"Errors")&&console.error("[Renderer] Program not initialized");return}r.pixelStorei(r.UNPACK_ALIGNMENT,4),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,i);const n=r.createTexture();if(r.bindTexture(r.TEXTURE_2D,n),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.bindTexture(r.TEXTURE_2D,null),!n){this.options&&u(this.options,"Errors")&&console.error("[Renderer] Failed to create texture");return}this.adTextures.set(e,n)},this.isPowerOf2=e=>(e&e-1)==0,this.setUVs=e=>{e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW)},this.options=a,this.renderer=o,this.gl=o.glContext}init(){const o=this.gl;this.renderer.RENDER_ALPHAMASK?this.program=this.initShadersAlphaMask(o):this.program=this.initShadersAugmentation(o),o.useProgram(this.program);const a=o.getUniformLocation(this.program,"u_resolution");o.uniform2f(a,o.canvas.width,o.canvas.height),this.initGeometryBuffers()}initGeometryBuffers(){const o=this.gl;this.positionBuffer=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,this.positionBuffer),this.setRectangle(o,0,0,o.canvas.width,o.canvas.height),this.uvBuffer=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,this.uvBuffer),this.setUVs(o),o.bindBuffer(o.ARRAY_BUFFER,null)}updateGeometryBuffers(){const o=this.gl;if(!this.positionBuffer||!this.uvBuffer){this.options&&u(this.options,"Errors")&&console.error("[Renderer] Buffers not initialized");return}o.bindBuffer(o.ARRAY_BUFFER,this.positionBuffer),this.setRectangle(o,0,0,o.canvas.width,o.canvas.height),o.bindBuffer(o.ARRAY_BUFFER,this.uvBuffer),this.setUVs(o),o.bindBuffer(o.ARRAY_BUFFER,null)}cleanGL(){this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}const b=["LeftTop","MidTopLeft","MidTopRight","RightTop","LeftBottom","MidBottomLeft","MidBottomRight","RightBottom"];class w{constructor(o,a){this.ads=[],this.getAds=async()=>{const t=await(await fetch("https://www.virtualott.com/ads/"+this.options.augmentation.channelName)).json(),i=t.filter(l=>l.name.indexOf(".json")>-1)[0].url,n=(await(await fetch(i)).json()).urls;for(const l of t){const h=await this.loadAdvImage(l);if(!h)continue;const d={name:l.name,imageUrl:l.url,image:h,adUrl:n[l.name]};this.ads.push(d)}this.setAd("LeftTop",3),this.setAd("RightBottom",4),this.uploadAdTextures()},this.loadAdvImage=async e=>{const t=\`#\${e.name}\`,i=e.url;if(t.indexOf(".json")>-1)return;const s=await(await fetch(i)).blob();return await createImageBitmap(s)},this.setAd=(e,t)=>{this.adMap.set(e,this.ads[t])},this.uploadAdTextures=()=>{this.adMap.forEach((e,t)=>{!e||!e.image||this.webgl.generateAdTexture(t,e.image,!0)})},this.getAdURLAtCoord=(e,t,i)=>{let r;return Object.keys(e).forEach(s=>{const n=e[s].corners.map(l=>({x:l.x/t.width,y:l.y/t.height}));if(this.isPointInPlaceholder(n,i)){const l=e[s].name,h=this.adMap.get(l);console.log("ad: ",h),h&&(console.log("ad.url: ",h.adUrl),r=h.adUrl)}}),r},this.isPointInPlaceholder=(e,t)=>{console.log("polygon: ",e),console.log("coord: ",t);let i=!1;const{x:r,y:s}=t,n=e.length;for(let l=0,h=n-1;l<n;h=l++){const d=e[l].x,R=e[l].y,p=e[h].x,E=e[h].y;R>s!=E>s&&r<(p-d)*(s-R)/(E-R)+d&&(i=!i)}return console.log("inside: ",i),i},this.placeholderNames=b,this.webgl=o,this.options=a,this.adMap=new Map,b.forEach(e=>{this.adMap.set(e,void 0)}),this.webgl.setAllPlaceholders(b),console.log("channelName: ",this.options.augmentation.channelName),this.getAds()}}class W{constructor(o,a){this.RENDER_ALPHAMASK=!1,this.renderDataMap=new Map,this.setWebGLEventListeners=()=>{const e=this.glContext.canvas;e.addEventListener("webglcontextlost",t=>{console.warn("Context lost:",t),t.preventDefault()}),e.addEventListener("webglcontextrestored",()=>{console.log("Context restored!"),this.webgl=new F(this,this.options),this.ads=new w(this.webgl,this.options),this.webgl.init()})},this.addMetadataBatch=e=>{e.forEach(t=>{if(!(!t.alphaMask||!t.isLive)){this.options&&u(this.options,"Renderer")&&console.log(\`[RendererWorker] Creating texture for timeCode=\${t.timecode}\`);try{const i=this.webgl.createTextureFromVideoFrame(t.alphaMask),r=t.timecode,s={width:t.processingWidth,height:t.processingHeight},n={alphaMask:i,placeholders:t.placeholders,processingSize:s};this.renderDataMap.set(r,n)}catch{this.options&&u(this.options,"Errors")&&console.error(\`[RendererWorker] Error creating texture for timeCode=\${t.timecode}\`)}finally{t.alphaMask.close()}}})},this.handleRenderDraw=(e,t)=>{var n,l,h,d,R;if(!this.streamData||this.streamData.ottActions&&!this.streamData.ottActions.toggle.web)return;const i=(n=this.renderDataMap.get(e))==null?void 0:n.alphaMask,r=(l=this.renderDataMap.get(e))==null?void 0:l.placeholders,s=(h=this.renderDataMap.get(e))==null?void 0:h.processingSize;if(!(!i||!r||!s||!this.streamData)){if((this.glContext.canvas.width!==s.width||this.glContext.canvas.height!==s.height)&&(this.glContext.canvas.width=s.width,this.glContext.canvas.height=s.height,this.webgl.updateGeometryBuffers()),t!=0)if(t>0){const p=D.fromStr(e).addFrames(1,this.streamData.fps),E=(d=this.renderDataMap.get(D.toStr(p)))==null?void 0:d.placeholders;E&&Object.keys(E).forEach(T=>{T in r&&(r[T].tranform=r[T].tranform.map((x,g)=>x*(1-t)+E[T].tranform[g]*t))})}else{const p=Math.abs(t),E=D.fromStr(e).subtractFrames(1,this.streamData.fps),T=(R=this.renderDataMap.get(D.toStr(E)))==null?void 0:R.placeholders;T&&Object.keys(T).forEach(x=>{x in r&&(r[x].tranform=r[x].tranform.map((g,v)=>T[x].tranform[v]*(1-p)+g*p))})}this.options&&u(this.options,"Renderer")&&console.log(\`[Renderer] Render logic: binding texture for \${e}\`),this.RENDER_ALPHAMASK?this.webgl.drawAlphaMask(i):this.webgl.drawAugmentation(i,r)}},this.getAdURLByCoord=e=>{var n,l;if(!this.ads||!this.streamData||!this.streamData.timeCode||!this.renderDataMap)return null;const t=this.streamData.timeCode,i=(n=this.renderDataMap.get(t))==null?void 0:n.placeholders,r=(l=this.renderDataMap.get(t))==null?void 0:l.processingSize;if(!i||!r)return null;console.log("placeholders: ",i);const s=this.ads.getAdURLAtCoord(i,r,e);return console.log("url: ",s),s},this.deleteTexture=e=>{var i;const t=(i=this.renderDataMap.get(e))==null?void 0:i.alphaMask;t&&(this.webgl.deleteTexture(t),this.renderDataMap.delete(e))},this.deleteOldTextures=e=>{if(!this.streamData)return;const t=59.94,i=D.fromStr(e).totalMilliseconds(t);this.renderDataMap.forEach((r,s)=>{D.fromStr(s).totalMilliseconds(t)<i-100&&(this.options&&u(this.options,"Renderer")&&console.log(\`[Renderer] Deleting old texture for timeCode=\${s}\`),this.webgl.deleteTexture(r.alphaMask),this.renderDataMap.delete(s))})},this.cleanGL=()=>{this.webgl.cleanGL()},this.updateStreamData=e=>{this.streamData=e},this.glContext=o,this.webgl=new F(this,a),this.options=a,this.ads=new w(this.webgl,a),this.webgl.init()}}let L=null,M=null,U=null,S=null,_=null,m;const A={timeCode:"",frameCorrection:0,fps:0,cloudFrontURL:"",bucketName:"",offsets:[]};let P=0,B=0;self.onmessage=c=>{const{data:o}=c;if(o.type==="INIT_OFFSCREEN"){const a=o.offscreen;if(m=o.options,S=a.getContext("webgl"),m&&u(m,"Renderer")&&console.log("[RendererWorker] Initializing OffscreenCanvas"),!S){m&&u(m,"Errors")&&console.error("[RendererWorker] Failed to acquire WebGL context");return}_=new W(S,m),m&&u(m,"Renderer")&&console.log("[RendererWorker] OffscreenCanvas initialized, gl context acquired")}if(o.type==="SET_DOWNLOADER_PORT"&&(L=o.port,L.onmessage=j),o.type==="SET_DECODER_PORT"&&(M=o.port,M.onmessage=z),o.type==="SET_ADAPTER_PORT"&&(U=o.port,U.onmessage=H),(o.type==="RENDERER_DRAW"||o.type==="RENDERER_CLEAR")&&y(o),o.type==="VIDEO_CLICK"&&_){const a=_.getAdURLByCoord(o.clickData);postMessage({type:"OPEN_URL",url:a})}};function X(){L&&L.postMessage({type:"DOWNLOADER_INPUT",streamData:A})}function Y(){M&&M.postMessage({type:"DECODER_REQUEST",timeCode:A.timeCode,fps:A.fps})}function y(c){V(c.streamData),_?(_.updateStreamData(A),_.cleanGL(),c.type==="RENDERER_DRAW"&&(_.handleRenderDraw(c.streamData.timeCode,c.streamData.frameCorrection),_.deleteOldTextures(c.streamData.timeCode))):m&&u(m,"Errors")&&console.error("[RendererWorker] WebGL context is not initialized."),$()}function $(){if(!m)return;const c=performance.now();c-P>m.DOWNLOADER_UPDATE_FREQUENCY&&(X(),P=c),c-B>m.DECODER_UPDATE_FREQUENCY&&(Y(),B=c)}function z(c){const{data:o}=c;if(o.type==="RENDERER_INPUT"){const a=o.batch;m&&u(m,"Renderer")&&console.log(\`[RendererWorker] Received a batch of \${a.length} frames\`),_&&_.addMetadataBatch(a)}}function j(c){const{data:o}=c;if(m&&u(m,"Renderer")&&console.log("[RendererWorker] Message from Downloader:",c.data),o.type==="OTT_ACTIONS"){const a=o.ottActions;A.ottActions=a}}function H(c){const{data:o}=c;(o.type==="RENDERER_DRAW"||o.type==="RENDERER_CLEAR")&&y(o)}function V(c){A.timeCode=c.timeCode,A.frameCorrection=c.frameCorrection,A.fps=c.fps,A.cloudFrontURL=c.cloudFrontURL,A.bucketName=c.bucketName,A.offsets=c.offsets}})();
|
|
138
|
+
`,z=typeof self<"u"&&self.Blob&&new Blob([L],{type:"text/javascript;charset=utf-8"});function J(s){let t;try{if(t=z&&(self.URL||self.webkitURL).createObjectURL(z),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(L),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}const O='(function(){"use strict";const w=(s,e)=>!s.debug||!s.debug.on?!1:s.debug[`log${e}`],V=s=>Math.abs(s-59.94005994005994)<20?59.94:Math.abs(s-29.97002997002997)<10?29.97:Math.abs(s-14.985014985014985)<8?14.98:0,x=(()=>{const s=()=>{const c=navigator.userAgent;return/windows/i.test(c)?"Windows":/android/i.test(c)?"Android":/iphone|ipad|ipod/i.test(c)?"iOS":/mac/i.test(c)?"Mac":/ipad/i.test(c)?"iPad":"Something else"},e=()=>s()==="Mac",t=()=>s()==="iPad",r=()=>s()==="iOS",n=()=>{const c=s();return c==="iOS"||c==="Mac"||c==="iPad"},l=()=>s()==="Windows",a=()=>s()==="Android",i=()=>{switch(s()){case"Windows":return"a Windows PC";case"Android":return"an Android phone";case"iOS":return"an iPhone";case"Mac":return"a Mac";case"iPad":return"an iPad";default:return"an Unknown device"}},o=()=>({header:[navigator.platform,navigator.userAgent,navigator.appVersion,navigator.vendor,window.opera],dataos:[{name:"Windows Phone",value:"Windows Phone",version:"OS"},{name:"Windows",value:"Win",version:"NT"},{name:"iPhone",value:"iPhone",version:"OS"},{name:"iPad",value:"iPad",version:"OS"},{name:"Kindle",value:"Silk",version:"Silk"},{name:"Android",value:"Android",version:"Android"},{name:"PlayBook",value:"PlayBook",version:"OS"},{name:"BlackBerry",value:"BlackBerry",version:"/"},{name:"Macintosh",value:"Mac",version:"OS X"},{name:"Linux",value:"Linux",version:"rv"},{name:"Palm",value:"Palm",version:"PalmOS"}],databrowser:[{name:"Chrome",value:"Chrome",version:"Chrome"},{name:"Firefox",value:"Firefox",version:"Firefox"},{name:"Safari",value:"Safari",version:"Version"},{name:"Internet Explorer",value:"MSIE",version:"MSIE"},{name:"Opera",value:"Opera",version:"Opera"},{name:"BlackBerry",value:"CLDC",version:"CLDC"},{name:"Mozilla",value:"Mozilla",version:"Mozilla"}],init(){const C=this.header.join(" ");return this.matchItem(C,this.dataos)},matchItem(C,P){for(let A=0;A<P.length;A+=1)if(new RegExp(P[A].value,"i").test(C))return P[A].name;return"unknown"}}).init(),u=()=>{const c=navigator.userAgent;return c.indexOf("Chrome")>-1&&c.indexOf("Edge")===-1?"Chrome":c.indexOf("Safari")>-1&&c.indexOf("Chrome")===-1?"Safari":c.indexOf("Firefox")>-1?"Firefox":c.indexOf("MSIE")>-1||c.indexOf("Trident")>-1?"Internet Explorer":c.indexOf("Edge")>-1?"Edge":"Unknown"};return{getCurrentPlatform:s,isMac:e,isiPad:t,isiPhone:r,isApple:n,isWindows:l,isAndroid:a,getDeviceDescription:i,getDeviceName:o,getBrowserName:u,isSafariMac:()=>e()&&u()==="Safari",isChromeMac:()=>e()&&u()==="Chrome",isChromeWin:()=>l()&&u()==="Chrome"}})(),f=class f{constructor(e,t,r,n,l){this.copy=()=>new f(this.h,this.m,this.s,this.f,this.field),this.print=()=>{const a=":";let i=("0"+this.h).slice(-2)+a+("0"+this.m).slice(-2)+a+("0"+this.s).slice(-2)+a+("0"+this.f).slice(-2);return i+="."+(this.field?"1":"2"),i},this.toZipTimeCodeString=()=>{const a=this.copy();return a.f=0,a.s=a.s%2===0?a.s:a.s-1,a.field=0,f.toStr(a)},this.toFrames=a=>{let i=60,o=0;Math.floor(a)==60?(i=60,o=0):Math.floor(a)==59?(i=60,o=4):Math.floor(a)==30?(i=30,o=0):Math.floor(a)==29&&(i=30,o=2);let u=this.h,p=this.m,h=this.s,M=this.f,S=this.field;const c=u*60+p,C=(c-Math.floor(c/10))*o;return u*(i*3600)+p*(i*60)+h*i+(M*2+S)-C},this.addSeconds=a=>{let i=this.copy();return i.s+=a,i.s>=60&&(i.s=0,i.m++,i.m>=60&&(i.m=0,i.h++)),i},this.addFrames=(a,i)=>{let o=this.toFrames(i);return o+=a,f.fromFrames(o,i)},this.subtractFrames=(a,i)=>this.addFrames(-a,i),this.h=e||0,this.m=t||0,this.s=r||0,this.f=n||0,this.field=l||0}static compare(e,t){return e.h!==t.h?e.h<t.h?-1:1:e.m!==t.m?e.m<t.m?-1:1:e.s!==t.s?e.s<t.s?-1:1:e.f!==t.f?e.f<t.f?-1:1:e.field!==t.field?e.field<t.field?-1:1:0}static generateTimecodeRange(e,t,r){const n=[];let l=e;for(;f.compare(l,t)<=0;)n.push(l),l=l.addSeconds(r);return n}totalSeconds(){return this.h*3600+this.m*60+this.s}totalMilliseconds(e){return this.toFrames(e)*1e3/e}};f.calculateCurrentTimeCode=e=>{var h;if(!e.video||!e.clocker||!e.gameParams)throw new Error("OTTPlayer is not initialized");const t=e.video,r=e.clocker,n=r.videoFPScalculator.getFPS(),i=(t.currentTime-r.syncPoint.playerTime)%(60*60*24)*n+r.syncPoint.frame;if(i===0||n===0)throw new Error("Current frame is 0 or fps is 0");const o=f.calculateCurrentOffset(i,(h=e.gameParams)==null?void 0:h.offsets);if(o===void 0)throw new Error("Offset is undefined");let u=Math.floor(i-o);return u<0&&(u+=5178816),u>=5178816&&(u-=5178816),f.fromFrames(u,n)},f.calculateCurrentOffset=(e,t)=>{for(let r=1;r<t.length;r++)if(e<t[r].frame)return t[r-1].offset;return t[t.length-1].offset},f.fromFrames=(e,t)=>{let r=60,n=0;Math.floor(t)==60?(r=60,n=0):Math.floor(t)==59?(r=60,n=4):Math.floor(t)==30?(r=30,n=0):Math.floor(t)==29&&(r=30,n=2);let l=Math.floor(t*60),a=Math.floor(t*60*10),i=a*6,o=e,u=Math.floor(o/i);o-=u*i;let p=Math.floor(o/a);o-=p*a,o>=r*60&&(o+=n*(Math.floor((o-r*60)/l)+1));let h=Math.floor(o/(r*60));o-=h*(r*60);let M=Math.floor(o/r);o-=M*r;let S=o;h+=p*10;let c=0;return c=S%2,S=Math.floor(S/2),new f(u,h,M,S,c)},f.toStr=e=>{const t="_";let r=("0"+e.h).slice(-2)+t+("0"+e.m).slice(-2)+t+("0"+e.s).slice(-2)+t+("0"+e.f).slice(-2);return e.field&&(r+="_1"),r},f.fromStr=e=>{const r=e.split("_").map(Number);if(r.length==4){const[n,l,a,i]=r;return new f(n,l,a,i,0)}else if(r.length==5){const[n,l,a,i,o]=r;return new f(n,l,a,i,o)}else throw new Error("Invalid timecode format: "+e)},f.fromMetadata=e=>{const t=/^(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d))?$/,r=e.timecode.match(t);if(!r)throw new Error("Invalid timecode format: "+e.timecode);const[,n,l,a,i,o]=r,u=Number(n),p=Number(l),h=Number(a),M=Number(i),S=o?Number(o):0;return new f(u,p,h,M,S)};let g=f;class O{constructor(){this.start=0,this.end=0,this.startTimeoutForSeconds=e=>{this.start=performance.now(),this.end=this.start+e*1e3},this.isTimeout=()=>{const e=performance.now()>=this.end;return e&&(this.start=0,this.end=0),!e}}}const d={lastRendererFrameSent:0,isRAFSeen:!1,isRVFCSeen:!1,RVFCmissed:!1,RVFCframeExpected:0,compensationMode:!1,compensationCounter:0,frameCorrection:0,lastMessageSent:""};let R=null,F,m,D=new O;self.onmessage=async s=>{const{data:e}=s;e.type==="SET_RENDERER_PORT"&&(R=e.port,R.onmessage=k),e.type==="ADAPTER_UPDATE_DATA"&&(m=e.data,T()),e.type==="SET_OPTIONS"&&(F=e.options)};function k(s){F&&w(F,"Adapter")&&console.log("[AdapterWorker] Message from Renderer:",s.data)}const T=()=>{!m||m.siData.isVideoPaused||(x.isChromeMac()?b():x.isSafariMac()&&W())},b=()=>{if(!m||m.siData.isVideoPaused||!m.vfcData.lastFrameMetadata)return;const{siData:s,vfcData:e,afData:t}=m;if(e.videoFPS>30){if(s.isRAFSeen&&s.isRVFCSeen)return;if(!s.isRAFSeen)if(s.RVFCmissed&&(d.RVFCframeExpected=e.lastCalculatedMediaTimeVideoFrame+1),e.lastCalculatedMediaTimeVideoFrame<d.RVFCframeExpected){d.compensationMode=!0,v(e.lastCalculatedMediaTimeVideoFrame+1),d.compensationCounter<10?(d.RVFCframeExpected++,d.compensationCounter++):(d.compensationCounter=0,d.frameCorrection=1,console.error("RVFC frame compensation limit reached"));return}else d.compensationMode&&(d.compensationMode=!1),d.compensationCounter=0;if(!s.isRVFCSeen){let r=0;d.frameCorrection>0&&(r=d.frameCorrection,d.frameCorrection=Math.max(d.frameCorrection-.2,0)),v(e.lastCalculatedMediaTimeVideoFrame,r)}}else if(e.videoFPS>15){if(e.lastCalculatedMediaTimeVideoFrame==d.lastRendererFrameSent)return;d.lastRendererFrameSent=e.lastCalculatedMediaTimeVideoFrame,e.lastFrameMetadata.expectedDisplayTime-e.lastFrameNow>5?setTimeout(v,20,e.lastCalculatedMediaTimeVideoFrame+1):setTimeout(v,5,e.lastCalculatedMediaTimeVideoFrame+1)}else e.videoFPS>10},W=()=>{if(!m||m.siData.isVideoPaused||!m.vfcData.lastFrameMetadata)return;const{siData:s,vfcData:e,afData:t}=m;let r=t.lastCalculatedPlayerTimeFraction;const n=t.previousCalculatedPlayerTimeFraction;r<.3&&r>.1&&n<.3&&n>.1&&(r=Math.min(r,n));let l=0;r<.1?l=0:r>.1&&r<.3?l=(r-.1)/(.3-.1):l=1;let a=t.lastCalculatedPlayerTimeVideoFrame;l==1&&(a++,l=0),v(a,l)},v=(s,e)=>{if(!m)return;m.siData.workingFps;const t=g.fromFrames(s,6e4/1001);if(D.isTimeout())E(t);else{const r=m.vfcData.videoFPS;if(r<=15||r>70){console.error("Video FPS is out of supported range: "+r),D.startTimeoutForSeconds(3),E(t);return}const n=m.afData.animationFPS;if(n<=30||n>70){console.error("Animation FPS is out of supported range: "+n),D.startTimeoutForSeconds(3),E(t);return}N(t,e)}},N=(s,e)=>{const t=g.toStr(s);t!=d.lastMessageSent&&(d.lastMessageSent=t,F&&w(F,"Adapter")&&console.log(`[AdapterWorker] Rendering augmentation for timecode: ${t} , ${s}`),y(t,e))},E=s=>{const e=g.toStr(s);F&&w(F,"Adapter")&&console.log("[AdapterWorker] Clearing augmentation"),y(e,0,!0)},y=(s,e,t)=>{if(!R||!m)return;const r=s;F&&w(F,"Adapter")&&console.log(`[AdapterWorker] Sending current time code to the Renderer: ${r}`);const n={timeCode:r,frameCorrection:e||0,fps:V(m.siData.workingFps),cloudFrontURL:m.cloudFrontURL,bucketName:m.bucketName,offsets:m.offsets},a={type:t?"RENDERER_CLEAR":"RENDERER_DRAW",streamData:n};R.postMessage(a)};setInterval(T,2)})();\n',N=typeof self<"u"&&self.Blob&&new Blob([O],{type:"text/javascript;charset=utf-8"});function Z(s){let t;try{if(t=N&&(self.URL||self.webkitURL).createObjectURL(N),!t)throw"";const e=new Worker(t,{name:s==null?void 0:s.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(O),{name:s==null?void 0:s.name})}finally{t&&(self.URL||self.webkitURL).revokeObjectURL(t)}}class Q{constructor(t){this.canPlayListner=()=>this.setupCanvas(),this.clickListner=e=>{this.clicker.click(e)},this.mediaTime=0,this.timecodeChecker=new $(0),this.OTTPlayer=t,this.options=t.options,this.downloaderWorker=new q,this.decoderWorker=new K,this.rendererWorker=new J,this.adapterWorker=new Z,this.rendererToDownloader=new MessageChannel,this.downloaderToDecoder=new MessageChannel,this.decoderToRenderer=new MessageChannel,this.adapterToRenderer=new MessageChannel,this.setupWorkers(),this.canvas=document.createElement("canvas"),this.OTTPlayer.video.readyState>=3?this.setupCanvas():this.OTTPlayer.video.addEventListener("canplay",this.canPlayListner,{once:!0}),this.processedTimecodes=[],this.clicker=new X(this.OTTPlayer.video,this.rendererWorker),this.segmentFirstFrameTimecode=new p,this.syncPoint={frame:0,playerTime:0,stringTime:""},this.cacheStarted=!1,this.animationFPScalculator=new C(20),this.videoFPScalculator=new C(20),this.startAnimationFrameLoop(),this.startVideoFrameCallbackLoop()}onNewMetadata(t){const e=v(this.videoFPScalculator.getFPS());this.segmentFirstFrameTimecode=V(t),this.metadataReportedFrameTimecode=H(t),this.metadataReportedFrameTimecode&&e&&!this.cacheStarted&&(this.syncPoint=W(t,e,this.metadataReportedFrameTimecode),this.cacheStarted=!0)}async onNewSegment(t){const e=v(this.videoFPScalculator.getFPS());this.segmentFirstFrameTimecode&&e&&(this.syncPoint=Y(t,e,this.segmentFirstFrameTimecode))}startAnimationFrameLoop(){const t=()=>{var e;this.animationFPScalculator.addTimestamp(performance.now()/1e3),(e=this.OTTPlayer.gameParams)!=null&&e.bucketName&&this.OTTPlayer.gameParams.offsets&&this.cacheStarted&&!this.OTTPlayer.RUN_ADAPTER&&this.callRendererWorker(),this.OTTPlayer.RUN_PIXEL_TICKERS&&this.OTTPlayer.pixelTickers.forEach(i=>{i.update()}),this.animationFPScalculator.getFPS(),this.animationFrameLoopId=requestAnimationFrame(t)};this.animationFrameLoopId=requestAnimationFrame(t)}startVideoFrameCallbackLoop(){const t=(e,i)=>{this.mediaTime=i.mediaTime,this.videoFPScalculator.addTimestamp(i.mediaTime),this.videoFrameCallbackLoopId=this.OTTPlayer.video.requestVideoFrameCallback(t)};this.videoFrameCallbackLoopId=this.OTTPlayer.video.requestVideoFrameCallback(t)}setupCanvas(){const t=this.OTTPlayer.video,e=t.parentElement;this.canvas.width=t.videoWidth,this.canvas.height=t.videoHeight,this.canvas.style.zIndex="3000",this.canvas.style.position="absolute",this.canvas.style.top="50%",this.canvas.style.transform="translateY(-50%)",this.canvas.style.left="0",this.canvas.style.width=e.style.width,this.canvas.style.height=e.style.height,this.canvas.style.pointerEvents="none",e.addEventListener("click",this.clickListner),e.style.position="relative",e.appendChild(this.canvas);const i=this.canvas.transferControlToOffscreen(),r={type:"INIT_OFFSCREEN",offscreen:i,options:this.options};this.rendererWorker.postMessage(r,[i])}setupWorkers(){this.rendererWorker.postMessage({type:"SET_DOWNLOADER_PORT",port:this.rendererToDownloader.port1},[this.rendererToDownloader.port1]),this.downloaderWorker.postMessage({type:"SET_RENDERER_PORT",port:this.rendererToDownloader.port2},[this.rendererToDownloader.port2]),this.downloaderWorker.postMessage({type:"SET_DECODER_PORT",port:this.downloaderToDecoder.port1},[this.downloaderToDecoder.port1]),this.decoderWorker.postMessage({type:"SET_DOWNLOADER_PORT",port:this.downloaderToDecoder.port2},[this.downloaderToDecoder.port2]),this.decoderWorker.postMessage({type:"SET_RENDERER_PORT",port:this.decoderToRenderer.port1},[this.decoderToRenderer.port1]),this.rendererWorker.postMessage({type:"SET_DECODER_PORT",port:this.decoderToRenderer.port2},[this.decoderToRenderer.port2]),this.adapterWorker.postMessage({type:"SET_RENDERER_PORT",port:this.adapterToRenderer.port1},[this.adapterToRenderer.port1]),this.rendererWorker.postMessage({type:"SET_ADAPTER_PORT",port:this.adapterToRenderer.port2},[this.adapterToRenderer.port2]),this.downloaderWorker.postMessage({type:"SET_OPTIONS",options:this.options}),this.decoderWorker.postMessage({type:"SET_OPTIONS",options:this.options}),this.adapterWorker.postMessage({type:"SET_OPTIONS",options:this.options})}callAdapterWorker(t){this.adapterWorker.postMessage({type:"ADAPTER_UPDATE_DATA",data:t})}callRendererWorker(t,e,i){var h,l;let r=t;if(!r){const f=p.calculateCurrentTimeCode(this.OTTPlayer);r=p.toStr(f)}this.options&&m(this.options,"Clocker")&&console.log(`[Clocker] Sending current time code to the Renderer: ${r}`);const n={timeCode:r,frameCorrection:e||0,fps:v(this.videoFPScalculator.getFPS()),cloudFrontURL:this.OTTPlayer.options.cloudFrontURL,bucketName:((h=this.OTTPlayer.gameParams)==null?void 0:h.bucketName)||"",offsets:((l=this.OTTPlayer.gameParams)==null?void 0:l.offsets)||[]},a={type:i?"RENDERER_CLEAR":"RENDERER_DRAW",streamData:n};this.rendererWorker.postMessage(a)}delete(){const t=this.OTTPlayer.video,e=t.parentElement;e.removeChild(this.canvas),this.rendererWorker.terminate(),this.downloaderWorker.terminate(),this.decoderWorker.terminate(),this.adapterWorker.terminate(),this.animationFrameLoopId&&cancelAnimationFrame(this.animationFrameLoopId),this.videoFrameCallbackLoopId&&t.cancelVideoFrameCallback(this.videoFrameCallbackLoopId),t.removeEventListener("canplay",this.canPlayListner),e.removeEventListener("click",this.clickListner)}}class tt{constructor(t){this.fetchGameParams=async(e,i)=>{const r=`${e}/${i}.json`;this.options&&m(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching GameParams from ${r}`);const n=await fetch(r);if(!n.ok)throw new Error(`HTTP error! Status: ${n.status}`);const o=await n.json();return o.hasOwnProperty("bucketName")&&o.hasOwnProperty("offsets")?o:(this.options&&m(this.options,"Errors")&&console.error(`[Fetcher] Game params for ${i} not found in JSON.`),n)},this.fetchMetadata=async(e,i,r,n)=>{const a=`${`${e}/${i}`}/manifests/59.94/${n}.zip`;this.options&&m(this.options,"Fetcher")&&console.log(`[Fetcher] Fetching metadata from ${a}`);const h=await fetch(a),l=h.headers.get("x-tgi-ott-actions");let f;if(l?f=JSON.parse(l):f={toggle:{ios:!0,android:!0,web:!0}},!h.ok)throw new Error(`HTTP error! Status: ${h.status}`);return{arrayBuffer:await h.arrayBuffer(),ottActions:f}},this.options=t}}class et{constructor(){this.metrics=new Map,this.containers=[],this.createContainer=()=>{const t=document.createElement("div");t.style.display="flex",t.style.gap="10px",t.style.marginBottom="5px",t.style.fontSize="14px";const e={div:t,metrics:[]};return this.containers.push(e),document.body.appendChild(t),e},this.createMetric=(t,e)=>{const i=document.createElement("span"),r={name:t,value:"",span:i};return e.metrics.push(r),i.textContent=`${t}: ${r.value}`,e.div.appendChild(i),this.metrics.set(t,r),r},this.updateMetric=(t,e)=>{const i=this.metrics.get(t);if(!i){console.error("Metric does not exist");return}typeof e=="boolean"?i.value=e?"true":"false":i.value=e,i.span.textContent=`${t}: ${i.value}`}}delete(){this.containers.forEach(t=>{t.div.remove()})}}const x=s=>s.toString().padStart(2,"0"),F=":",it=(s,t,e=!1)=>{let i="";return Array.isArray(s)?(i=[x(s[0]),x(s[1]),x(s[2]),x(s[3])].join(":"),e==!0?s[4]==1&&t?i+=".2":i+=".1":s[4]==1&&t&&(i+=".1")):(i=("0"+s.h).slice(-2)+F+("0"+s.m).slice(-2)+F+("0"+s.s).slice(-2)+F+("0"+s.f).slice(-2),i+="."+(s.field?"1":"2")),i},rt=(s,t,e)=>{let i=60,r=0;Math.floor(t)==60?(i=60,r=0):Math.floor(t)==59?(i=60,r=4):Math.floor(t)==30?(i=30,r=0):Math.floor(t)==29&&(i=30,r=2);let n=0,a=Math.floor(t*60*10)*6,h=s[0],l=s[1],f=s[2],u=s[3],_=s[4];return n+=h*a,n+=l*(i*60),n+=f*i,n+=u*2+_,n-=r*l,n+=r*Math.floor(l/10),n};class st{constructor(){this.start=0,this.end=0,this.startTimeoutForSeconds=t=>{this.start=performance.now(),this.end=this.start+t*1e3},this.isTimeout=()=>{const t=performance.now()>=this.end;return t&&(this.start=0,this.end=0),!t}}}class nt{constructor(t){if(this.platformSupported=!0,this.firstFrameTimecode=[0,0,0,0,0],this.timeout=new st,this.metrics=new et,this.afData={counter:0,lastTimestamp:0,timeFromLastRVFC:0,animationFPS:0,lastCalculatedPlayerTimeVideoFrame:0,lastCalculatedPlayerTimeFraction:0,previousCalculatedPlayerTimeFraction:2},this.vfcData={counter:0,lastTimestamp:0,timeFromLastRAF:0,videoFPS:0,lastFrameMetadata:null,lastFrameNow:0,lastCalculatedMediaTimeVideoFrame:0},this.siData={counter:0,lastTimestamp:0,timeFromLastRAF:0,timeFromLastRVFC:0,lastSeenRAFCount:0,lastSeenRVFCCount:0,isRAFSeen:!1,isRVFCSeen:!1,isVideoPaused:!0,workingFps:0,RVFCmissed:0,RVFCframeExpected:0,lastCallback:null,lastCalculatedFrame:0,lastRendererFrameSent:0,lastMessageSent:"",compensationMode:!1,compensationCounter:0,frameCorrection:0,determineFramesTimestamps:[],determineFramesIntervals:[]},this.tcTimeStamp=0,this.timecode_offset=0,this.onAnimationFrame=()=>{if(this.video.paused||!this.OTTPlayer.clocker||!this.OTTPlayer.gameParams){window.requestAnimationFrame(this.onAnimationFrame);return}this.afData.counter++,this.afData.lastTimestamp=performance.now(),this.afData.timeFromLastRVFC=this.afData.lastTimestamp-this.vfcData.lastTimestamp,this.afData.animationFPS=this.OTTPlayer.clocker.animationFPScalculator.getPerciseFPS(),this.siData.lastCallback=="RAF"&&this.siData.RVFCmissed++,this.siData.lastCallback="RAF";const e=(this.video.currentTime-this.syncPoint.playerTime)%(60*60*24)*(6e4/1001),i=Math.floor(e)+this.syncPoint.frame,r=p.calculateCurrentOffset(i,this.OTTPlayer.gameParams.offsets);let n=i-r;n<0&&(n+=5178816),n>=5178816&&(n-=5178816),n++,this.afData.lastCalculatedPlayerTimeVideoFrame=n,this.afData.previousCalculatedPlayerTimeFraction=this.afData.lastCalculatedPlayerTimeFraction,this.afData.lastCalculatedPlayerTimeFraction=e-Math.floor(e),this.debug&&(this.metrics.updateMetric("RAF calls",this.afData.counter),this.metrics.updateMetric("Last player time",this.video.currentTime.toFixed(4)),this.metrics.updateMetric("Last player time frame",this.afData.lastCalculatedPlayerTimeVideoFrame),this.metrics.updateMetric("Last player time fraction",this.afData.lastCalculatedPlayerTimeFraction.toFixed(4)),this.metrics.updateMetric("Last player time double frame",e.toFixed(5)),this.metrics.updateMetric("Last RAF call",this.afData.lastTimestamp.toFixed(2)),this.metrics.updateMetric("RAF - RVFC dif",this.afData.timeFromLastRVFC.toFixed(2)),this.metrics.updateMetric("Sync point to RAF time",(this.afData.lastTimestamp-this.syncPoint.lastUpdate).toFixed(2))),window.requestAnimationFrame(this.onAnimationFrame),this.determineFrameUpdate()},this.onVideoFrame=(e,i)=>{if(this.video.paused||!this.OTTPlayer.clocker||!this.OTTPlayer.gameParams){this.video.requestVideoFrameCallback(this.onVideoFrame);return}this.vfcData.counter++,this.vfcData.lastTimestamp=performance.now(),this.vfcData.timeFromLastRAF=this.vfcData.lastTimestamp-this.afData.lastTimestamp,this.siData.RVFCmissed=0,this.vfcData.videoFPS=this.OTTPlayer.clocker.videoFPScalculator.getPerciseFPS(),this.siData.lastCallback="RVFC";const r=(i.mediaTime-this.syncPoint.playerTime)%(60*60*24)*(6e4/1001),n=Math.floor(r+.1)+this.syncPoint.frame,o=p.calculateCurrentOffset(n,this.OTTPlayer.gameParams.offsets);let a=n-o;a<0&&(a+=5178816),a>=5178816&&(a-=5178816),a++,this.vfcData.lastCalculatedMediaTimeVideoFrame=a,this.vfcData.lastFrameMetadata=i,this.vfcData.lastFrameNow=e,this.debug&&(this.metrics.updateMetric("RVFC calls",this.vfcData.counter),this.metrics.updateMetric("Last metadata media time",i.mediaTime.toFixed(4)),this.metrics.updateMetric("Last metadata media time frame",this.vfcData.lastCalculatedMediaTimeVideoFrame),this.metrics.updateMetric("Last media time double frame",r.toFixed(5)),this.metrics.updateMetric("Time to expected display time",(i.expectedDisplayTime-e).toFixed(4)),this.metrics.updateMetric("Last RVFC call",this.vfcData.lastTimestamp.toFixed(2)),this.metrics.updateMetric("Sync point to RVFC time",(i.mediaTime-this.syncPoint.playerTime).toFixed(2))),this.video.requestVideoFrameCallback(this.onVideoFrame),this.determineFrameUpdate()},this.determineFrameUpdate=()=>{var e,i;if(!(!this.OTTPlayer.clocker||!this.vfcData.lastFrameMetadata)){if(this.siData.counter++,this.siData.isVideoPaused=this.video.paused,this.siData.isRAFSeen=this.siData.lastSeenRAFCount==this.afData.counter,this.siData.isRVFCSeen=this.siData.lastSeenRVFCCount==this.vfcData.counter,this.siData.lastTimestamp=performance.now(),this.siData.timeFromLastRAF=this.siData.lastTimestamp-this.afData.lastTimestamp,this.siData.timeFromLastRVFC=this.siData.lastTimestamp-this.vfcData.lastTimestamp,this.siData.lastSeenRAFCount=this.afData.counter,this.siData.lastSeenRVFCCount=this.vfcData.counter,this.siData.workingFps=this.OTTPlayer.clocker.videoFPScalculator.getFPS(),this.debug){const r=performance.now();if(this.siData.determineFramesTimestamps||(this.siData.determineFramesTimestamps=[]),this.siData.determineFramesTimestamps.length>0){const n=r-this.siData.determineFramesTimestamps[this.siData.determineFramesTimestamps.length-1];this.siData.determineFramesIntervals||(this.siData.determineFramesIntervals=[]),this.siData.determineFramesIntervals.push(n.toFixed(2)),this.siData.determineFramesIntervals.length>10&&this.siData.determineFramesIntervals.shift(),this.metrics.updateMetric("Determine frames intervals",this.siData.determineFramesIntervals.join(", "))}this.siData.determineFramesTimestamps.push(r),this.metrics.updateMetric("RVFC missed",this.siData.RVFCmissed)}if(!this.OTTPlayer.options.ADAPTER_RUN_IN_WORKER)this.platformSpecificFrameUpdate();else{const r={siData:this.siData,vfcData:this.vfcData,afData:this.afData,cloudFrontURL:this.OTTPlayer.options.cloudFrontURL,bucketName:((e=this.OTTPlayer.gameParams)==null?void 0:e.bucketName)||"",offsets:((i=this.OTTPlayer.gameParams)==null?void 0:i.offsets)||[]};this.OTTPlayer.clocker.callAdapterWorker(r)}}},this.determineFrameUpdateChromeMac=()=>{if(!(this.video.paused||!this.OTTPlayer.clocker||!this.vfcData.lastFrameMetadata))if(this.vfcData.videoFPS>30){if(this.siData.isRAFSeen&&this.siData.isRVFCSeen)return;if(!this.siData.isRAFSeen)if(this.siData.RVFCmissed&&(this.siData.RVFCframeExpected=this.vfcData.lastCalculatedMediaTimeVideoFrame+1),this.vfcData.lastCalculatedMediaTimeVideoFrame<this.siData.RVFCframeExpected){this.siData.compensationMode=!0,this.debug&&this.metrics.updateMetric("Compensation","+1"),this.callRenderer(this.vfcData.lastCalculatedMediaTimeVideoFrame+1),this.siData.compensationCounter<10?(this.siData.RVFCframeExpected++,this.siData.compensationCounter++,this.debug&&this.metrics.updateMetric("Drop frame compensation",!1)):(this.siData.compensationCounter=0,this.siData.frameCorrection=1,console.error("RVFC frame compensation limit reached"),this.debug&&this.metrics.updateMetric("Drop frame compensation",!0));return}else this.siData.compensationMode&&(this.siData.compensationMode=!1),this.siData.compensationCounter=0;if(!this.siData.isRVFCSeen){let e=0;this.siData.frameCorrection>0&&(e=this.siData.frameCorrection,this.siData.frameCorrection=Math.max(this.siData.frameCorrection-.2,0),this.debug&&this.metrics.updateMetric("Drop frame compensation",this.siData.frameCorrection.toFixed(2))),this.debug&&this.metrics.updateMetric("Compensation",0),this.callRenderer(this.vfcData.lastCalculatedMediaTimeVideoFrame,e)}}else if(this.vfcData.videoFPS>15){if(this.vfcData.lastCalculatedMediaTimeVideoFrame==this.siData.lastRendererFrameSent)return;this.siData.lastRendererFrameSent=this.vfcData.lastCalculatedMediaTimeVideoFrame,this.vfcData.lastFrameMetadata.expectedDisplayTime-this.vfcData.lastFrameNow>5?setTimeout(this.callRenderer,20,this.vfcData.lastCalculatedMediaTimeVideoFrame+1):setTimeout(this.callRenderer,5,this.vfcData.lastCalculatedMediaTimeVideoFrame+1)}else this.vfcData.videoFPS>10},this.determineFrameUpdateSifariMac=()=>{if(this.video.paused||!this.OTTPlayer.clocker||!this.vfcData.lastFrameMetadata)return;let e=this.afData.lastCalculatedPlayerTimeFraction;const i=this.afData.previousCalculatedPlayerTimeFraction;e<.3&&e>.1&&i<.3&&i>.1&&(e=Math.min(e,i));let r=0;e<.1?r=0:e>.1&&e<.3?r=(e-.1)/(.3-.1):r=1,this.debug&&this.metrics.updateMetric("Compensation",r.toFixed(4));let n=this.afData.lastCalculatedPlayerTimeVideoFrame;r==1&&(n++,r=0),this.callRenderer(n)},this.callRenderer=(e,i)=>{if(!this.OTTPlayer.clocker||!this.OTTPlayer)return;this.debug&&this.metrics.updateMetric("Last sent frame",e);const r=this.OTTPlayer.clocker.videoFPScalculator.getFPS();this.debug&&this.metrics.updateMetric("FPS",r.toFixed(2));const n=p.fromFrames(e,6e4/1001);if(this.timeout.isTimeout())this.clearAugmentation(n);else{const o=this.OTTPlayer.clocker.videoFPScalculator.getPerciseFPS();if(o<=15||o>70){console.error("Video FPS is out of supported range: "+o),this.timeout.startTimeoutForSeconds(3),this.clearAugmentation(n);return}const a=this.OTTPlayer.clocker.animationFPScalculator.getPerciseFPS();if(a<=30||a>70){console.error("Animation FPS is out of supported range: "+a),this.timeout.startTimeoutForSeconds(3),this.clearAugmentation(n);return}this.renderAugmentation(n,i)}},this.renderAugmentation=(e,i)=>{if(!this.OTTPlayer||!this.OTTPlayer.clocker)throw new Error("OTTPlayer is not initialized");const r=p.toStr(e);r!=this.siData.lastMessageSent&&(this.siData.lastMessageSent=r,this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log(`Rendering augmentation for timecode: ${r} , ${e}`),this.debug&&this.metrics.updateMetric("Last sent timecode",r),this.OTTPlayer.clocker.callRendererWorker(r,i))},this.clearAugmentation=e=>{if(!this.OTTPlayer||!this.OTTPlayer.clocker)throw new Error("OTTPlayer is not initialized");const i=p.toStr(e);this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("Clearing augmentation"),this.OTTPlayer.clocker.callRendererWorker(i,0,!0)},this.OTTPlayer=t,this.playerOptions=t.options,this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("Adapter is initialized",this.OTTPlayer),this.video=t.video,this.debug=this.playerOptions.debug?this.playerOptions.debug.on:!1,this.syncPoint={frame:0,playerTime:0,stringTime:"",lastUpdate:0},y.isChromeMac())this.platformSpecificFrameUpdate=this.determineFrameUpdateChromeMac;else{y.isSafariMac();{this.platformSpecificFrameUpdate=()=>{};const e=y.getCurrentPlatform(),i=y.getBrowserName();console.error("Unsupported platform: "+e+" "+i),this.platformSupported=!1;return}}if(this.platformSupported&&(this.OTTPlayer.video.readyState>=3?this.setupAdapter():this.OTTPlayer.video.addEventListener("canplay",()=>this.setupAdapter(),{once:!0})),this.debug){const e=this.metrics.createContainer(),i=this.metrics.createContainer(),r=this.metrics.createContainer(),n=this.metrics.createContainer(),o=this.metrics.createContainer(),a=this.metrics.createContainer(),h=this.metrics.createContainer(),l=this.metrics.createContainer();this.metrics.createMetric("RAF calls",e),this.metrics.createMetric("RVFC calls",e),this.metrics.createMetric("RVFC missed",e),this.metrics.createMetric("Last sent frame",e),this.metrics.createMetric("Last sent timecode",e),this.metrics.createMetric("Last metadata media time",i),this.metrics.createMetric("Last player time",i),this.metrics.createMetric("Time to expected display time",i),this.metrics.createMetric("Last metadata media time frame",r),this.metrics.createMetric("Last player time frame",r),this.metrics.createMetric("Last player time fraction",r),this.metrics.createMetric("Last media time double frame",n),this.metrics.createMetric("Last player time double frame",n),this.metrics.createMetric("Sync point frame",o),this.metrics.createMetric("Sync point player time",o),this.metrics.createMetric("Sync point to RVFC time",o),this.metrics.createMetric("Sync point to RAF time",o),this.metrics.createMetric("FPS",a),this.metrics.createMetric("Last RAF call",a),this.metrics.createMetric("Last RVFC call",a),this.metrics.createMetric("RAF - RVFC dif",a),this.metrics.createMetric("Determine frames intervals",h),this.metrics.createMetric("Compensation",l),this.metrics.createMetric("Drop frame compensation",l)}}setupAdapter(){const t=this.video;this.animationFrameLoopId=window.requestAnimationFrame(this.onAnimationFrame),this.videoFrameCallbackLoopId=t.requestVideoFrameCallback(this.onVideoFrame)}onNewSegmentForMetadata(t){const e=rt(this.firstFrameTimecode,59.94005994005994),i=it(this.firstFrameTimecode,!0,!0);this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("New segment ("+t.url+"): "+i+" ("+e+") playing at "+t.playbackTime);const r=t.playbackTime,n={frame:e,playerTime:r,stringTime:i,lastUpdate:performance.now()};this.syncPoint=n,this.debug&&(this.metrics.updateMetric("Sync point frame",n.frame),this.metrics.updateMetric("Sync point player time",n.playerTime)),t.mimeType.includes("video")&&this.playerOptions&&m(this.playerOptions,"Clocker")&&console.log("url: "+t.url)}onNewMetadata(t){if(t&&t.metadata&&t.metadata.id==0||y.isSafariMac()){if(t.metadata.messageData)t.metadata.messageData=this.processTimedMetadata(t.metadata.messageData,t.metadata.presentationTime);else if(t.metadata.frames&&t.metadata.frames.length&&t.metadata.frames[0].key&&t.metadata.frames[0].key.toLowerCase()==="priv"){const e=t.metadata.frames.filter(i=>i.info&&i.info.toLowerCase().includes("ntc"));if(e.length){const i=`${e[e.length-1].info}\0${String.fromCharCode(...e[e.length-1].data)}`;t.metadata.messageData=this.processTimedMetadata(i,t.metadata.presentationTime)}}if(t.metadata.id==0||y.isSafariMac()&&this.timecode_offset==0){t.metadata.presentationTime*1e3;const e=new Date(this.tcTimeStamp-this.timecode_offset);let i=Math.round(e.getUTCMilliseconds()*30*2/1001)/2;const r=i%1;let n=1;r==.5&&(i=Math.floor(i),n=2),this.firstFrameTimecode=[e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),Math.floor(i),n==1?0:1]}}}processTimedMetadata(t,e){let i="";if(t&&t.includes("www.mediakind.com/NTC")){const r=t.replace(/.*NTC./,"");let n=0;for(;n+8<=r.length;){const o=r.substring(n,n+4),a=((r.charCodeAt(n+4)*256+r.charCodeAt(n+5))*256+r.charCodeAt(n+6))*256+r.charCodeAt(n+7);if(n+8+a>r.length)break;const h=r.substring(n+8,n+8+a);o=="utc_"&&new Date(parseInt(h)).getTime()/1e3,o=="tc__"&&(this.tcTimeStamp=new Date(parseInt(h)).getTime()),o==="offs"&&(this.timecode_offset=parseInt(h)/90),n+=8+a}}return i}delete(){this.animationFrameLoopId&&cancelAnimationFrame(this.animationFrameLoopId),this.videoFrameCallbackLoopId&&this.video.cancelVideoFrameCallback(this.videoFrameCallbackLoopId),this.intervalLoopId&&clearInterval(this.intervalLoopId),this.metrics.delete()}}class S{constructor(t,e){this.size=1,this.positionElement=()=>{let r=0,n=0;this.corner=="left-top"?(this.element.style.top=`${r}px`,this.element.style.left=`${n}px`):this.corner=="right-top"?(this.element.style.top=`${r}px`,this.element.style.left=`${n+this.video.offsetWidth-this.size}px`):this.corner=="right-bottom"?(this.element.style.top=`${r+this.video.offsetHeight-this.size}px`,this.element.style.left=`${n+this.video.offsetWidth-this.size}px`):this.corner=="left-bottom"&&(this.element.style.top=`${r+this.video.offsetHeight-this.size}px`,this.element.style.left=`${n}px`)},this.video=e,this.container=e.parentElement,this.corner=t;const i=document.createElement("div");i.style.position="absolute",i.style.width=`${this.size}px`,i.style.height=`${this.size}px`,i.style.transition="background-color 0s",i.style.zIndex="100000",this.element=i,this.container.appendChild(i),this.positionElement()}getRandomColor(){const i=Math.floor(Math.random()*11)+0;return`rgb(${i},${i},${i})`}update(){this.element.style.backgroundColor=this.getRandomColor(),this.positionElement()}delete(){this.container.removeChild(this.element)}static createInAllCorners(t){return[new S("left-top",t),new S("right-top",t),new S("right-bottom",t),new S("left-bottom",t)]}static updateAll(t){t.forEach(e=>e.update())}static deleteAll(t){t.forEach(e=>e.delete())}}class G{constructor(t,e,i){this.RUN_ADAPTER=!0,this.RUN_PIXEL_TICKERS=!0,this.pixelTickers=[],this.fetchGameParams=async()=>{if(this.fetcher)try{m(this.options,"OTTPlayer")&&console.log("[OTTPlayer] GameId: ",this.options.gameId);const r=await this.fetcher.fetchGameParams(this.options.cloudFrontURL,this.options.gameId);if(r instanceof Response)throw console.log("gameParams: ",r),new Error("Error fetching game params:"+r.type);this.gameParams=r}catch(r){m(this.options,"Errors")&&console.error("[OTTPlayer] Error fetching game params:",r)}},this.video=t,this.options={...i,cloudFrontURL:"https://d1ze2lfw5ong7.cloudfront.net",augmentation:{channelName:"nba"},ADAPTER_RUN_IN_WORKER:!1,DOWNLOADER_UPDATE_FREQUENCY:1e3,DOWNLOADER_ZIP_START_OFFSET:2,DOWNLOADER_ZIP_END_OFFSET:4,DOWNLOADER_ZIP_LENGTH_SECONDS:2,DECODER_UPDATE_FREQUENCY:40,DECODER_FRAME_BATCH_SIZE:5,DECODER_LEAD_TIME_MILLIS:400},j(this.options).then(()=>{this.clocker=new Q(this),this.fetcher=new tt(this.options),this.RUN_ADAPTER&&(this.adapter=new nt(this)),this.RUN_PIXEL_TICKERS&&(this.pixelTickers=S.createInAllCorners(this.video)),this.fetchGameParams(),window.BB.instances.length>0&&window.BB.instances.forEach(r=>{r.delete()}),window.BB.instances.push(this)})}onNewMetadata(t){if(this.RUN_ADAPTER){if(!this.adapter)return;this.adapter.onNewMetadata(t)}else{if(!this.clocker)return;this.clocker.onNewMetadata(t)}}onNewSegment(t){if(this.RUN_ADAPTER){if(!this.adapter)return;this.adapter.onNewSegmentForMetadata(t)}else{if(!this.clocker)return;this.clocker.onNewSegment(t)}}delete(){var e;const t=window.BB.instances.indexOf(this);t>=0&&window.BB.instances.splice(t,1),(e=this.clocker)==null||e.delete(),this.clocker=void 0,this.fetcher=void 0,this.adapter&&(this.adapter.delete(),this.adapter=void 0),S.deleteAll(this.pixelTickers),this.pixelTickers=[]}toggle(t){this.options.enabled=t}}return window.BB={OTTPlayer:G,instances:[]},G});
|