@mediabunny/prores 1.66.2 → 1.66.4

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.
@@ -5,7 +5,7 @@
5
5
  * License, v. 2.0. If a copy of the MPL was not distributed with this
6
6
  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
7
  */
8
- "use strict";var MediabunnyProres=(()=>{var ar=Object.create;var I=Object.defineProperty;var Br=Object.getOwnPropertyDescriptor;var lr=Object.getOwnPropertyNames;var cr=Object.getPrototypeOf,dr=Object.prototype.hasOwnProperty;var ur=(t,e,r)=>e in t?I(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var fr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),mr=(t,e)=>{for(var r in e)I(t,r,{get:e[r],enumerable:!0})},V=(t,e,r,A)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of lr(e))!dr.call(t,n)&&n!==r&&I(t,n,{get:()=>e[n],enumerable:!(A=Br(e,n))||A.enumerable});return t};var hr=(t,e,r)=>(r=t!=null?ar(cr(t)):{},V(e||!t||!t.__esModule?I(r,"default",{value:t,enumerable:!0}):r,t)),pr=t=>V(I({},"__esModule",{value:!0}),t);var i=(t,e,r)=>ur(t,typeof e!="symbol"?e+"":e,r);var L=fr((Fr,Q)=>{Q.exports=Mediabunny});var kr={};mr(kr,{registerProresDecoder:()=>Pr});var m=hr(L());var g=class extends Error{constructor(e="The decoder ran out of memory."){super(e),this.name="OutOfMemoryError"}},O=class extends Error{constructor(e="Invalid data: the packet ended before the decoder expected it to."){super(e),this.name="UnexpectedEofError"}},E=class extends Error{constructor(e="The packet contains invalid data."){super(e),this.name="InvalidDataError"}},P=class extends Error{constructor(e="The packet uses a feature that is not supported."){super(e),this.name="NotSupportedError"}},R=class extends Error{constructor(e="The decoder is in an invalid internal state. This should never happen! Please report."){super(e),this.name="InvalidStateError"}},_=class extends Error{constructor(e="The decoder has been closed."){super(e),this.name="DecoderClosedError"}},k=class extends Error{constructor(e="The frame is locked by an in-flight decoding operation."){super(e),this.name="FrameLockedError"}},er=(t,e)=>{switch(t){case-1:return new g(e);case-2:return new O(e);case-3:return new E(e);case-4:return new P(e);case-5:return new R(e);case-6:return new E(e??"Unexpected integer overflow.");default:throw new Error(`Unhandled error code: ${t}`)}};function f(t){if(!t)throw new Error("Assertion failed.")}var tr=t=>{let e=0,r="";for(;e<t.length;){let A=t[e++];if(A>127)if(A>191&&A<224){if(e>=t.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");A=(A&31)<<6|t[e++]&63}else if(A>223&&A<240){if(e+1>=t.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");A=(A&15)<<12|(t[e++]&63)<<6|t[e++]&63}else if(A>239&&A<248){if(e+2>=t.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");A=(A&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+A.toString(16)+" at index "+(e-1));if(A<=65535)r+=String.fromCharCode(A);else if(A<=1114111)A-=65536,r+=String.fromCharCode(A>>10|55296),r+=String.fromCharCode(A&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+A.toString(16)+" exceeds UTF-16 reach")}return r},y=class{constructor(){i(this,"currentPromise",Promise.resolve());i(this,"pending",0)}async acquire(){let e,r=new Promise(n=>{let o=!1;e=()=>{o||(n(),this.pending--,o=!0)}}),A=this.currentPromise;return this.currentPromise=r,this.pending++,await A,e}},Z=typeof SharedArrayBuffer<"u",Ar=t=>t;Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");var p=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"],gr={1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020",12:"smpte432"},br={1:"bt709",6:"smpte170m",8:"linear",13:"iec61966-2-1",16:"pq",18:"hlg"},yr={0:"rgb",1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020-ncl"},S=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeFrame(e)}),v=class{constructor(){i(this,"frameData",null);i(this,"codedWidth",null);i(this,"codedHeight",null);i(this,"visibleWidth",null);i(this,"visibleHeight",null);i(this,"pixelFormat",null);i(this,"originalPixelFormat",null);i(this,"pixelAspectRatio",null);i(this,"colorPrimaries",null);i(this,"colorTransfer",null);i(this,"colorMatrix",null);i(this,"colorRangeFull",null);i(this,"scanType",null);i(this,"_runtime",null);i(this,"_ptr",null);i(this,"_buffer",null);i(this,"_locked",!1)}get colorPrimariesString(){return this.colorPrimaries===null?void 0:gr[this.colorPrimaries]}get colorTransferString(){return this.colorTransfer===null?void 0:br[this.colorTransfer]}get colorMatrixString(){return this.colorMatrix===null?void 0:yr[this.colorMatrix]}get isLocked(){return this._locked}get isFilled(){return this.frameData!==null&&this.codedWidth!==null&&this.codedHeight!==null&&this.visibleWidth!==null&&this.visibleHeight!==null&&this.pixelFormat!==null&&this.pixelAspectRatio!==null&&this.colorPrimaries!==null&&this.colorTransfer!==null&&this.colorMatrix!==null&&this.colorRangeFull!==null&&this.scanType!==null}toFilled(){return this.isFilled?this:null}clear(){if(this._locked)throw new k;this._ptr!==null&&(f(this._runtime),S.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null),this._buffer=null,this._reset()}[Symbol.dispose](){this.clear()}_ensureWasmFrame(e){if(this._runtime===e)return!0;this._runtime&&(S.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null);let r=e.exports.createFrame();return r===0?!1:(this._runtime=e,this._ptr=r,S.register(this,{runtime:e,ptr:r},this),!0)}_reset(){this.frameData=null,this.codedWidth=null,this.codedHeight=null,this.visibleWidth=null,this.visibleHeight=null,this.pixelFormat=null,this.pixelAspectRatio=null,this.colorPrimaries=null,this.colorTransfer=null,this.colorMatrix=null,this.colorRangeFull=null,this.scanType=null}_populate(e){this.frameData=e.frameData,this.codedWidth=e.codedWidth,this.codedHeight=e.codedHeight,this.visibleWidth=e.visibleWidth,this.visibleHeight=e.visibleHeight,this.pixelFormat=e.pixelFormat,this.originalPixelFormat=e.originalPixelFormat,this.pixelAspectRatio=e.pixelAspectRatio,this.colorPrimaries=e.colorPrimaries,this.colorTransfer=e.colorTransfer,this.colorMatrix=e.colorMatrix,this.colorRangeFull=e.colorRangeFull,this.scanType=e.scanType}},xr=(t,e,r,A)=>{let n=t.getFrameDataPtr(r),o=t.getFrameDataSize(r),s=new Uint8Array(e.buffer,n,o),j=p[t.getFramePixelFormat(r)];f(j!==void 0);let B=p[t.getOriginalPixelFormat(A)];f(B!==void 0);let a=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][t.getScanType(r)];return f(a!==void 0),{frameData:s,codedWidth:t.getCodedWidth(r),codedHeight:t.getCodedHeight(r),visibleWidth:t.getVisibleWidth(r),visibleHeight:t.getVisibleHeight(r),pixelFormat:j,originalPixelFormat:B,pixelAspectRatio:{num:t.getAspectRatioNum(r),den:t.getAspectRatioDen(r)},colorPrimaries:t.getColorPrimaries(r),colorTransfer:t.getColorTransfer(r),colorMatrix:t.getColorMatrix(r),colorRangeFull:!1,scanType:a}},u=(t=>(t[t.SharedMemoryInit=0]="SharedMemoryInit",t[t.MessagePassingInit=1]="MessagePassingInit",t[t.CreateDecoder=2]="CreateDecoder",t[t.CloseDecoder=3]="CloseDecoder",t[t.Decode=4]="Decode",t[t.Ready=5]="Ready",t[t.InitOutOfMemoryError=6]="InitOutOfMemoryError",t[t.Decoded=7]="Decoded",t[t.DecodeError=8]="DecodeError",t))(u||{}),D=`\0asm\0\0\0\x99\`\x7F\x7F\x7F\x7F\x7F\`\x7F\x7F\x7F\x7F\x7F\0\`\x7F\0\`\0\0\`\x7F\x7F\x7F\x7F\x7F\x7F\x7F\`
8
+ "use strict";var MediabunnyProres=(()=>{var lr=Object.create;var T=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var ur=Object.getPrototypeOf,fr=Object.prototype.hasOwnProperty;var mr=(t,e,r)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var hr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),pr=(t,e)=>{for(var r in e)T(t,r,{get:e[r],enumerable:!0})},Q=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let A of dr(e))!fr.call(t,A)&&A!==r&&T(t,A,{get:()=>e[A],enumerable:!(n=cr(e,A))||n.enumerable});return t};var gr=(t,e,r)=>(r=t!=null?lr(ur(t)):{},Q(e||!t||!t.__esModule?T(r,"default",{value:t,enumerable:!0}):r,t)),br=t=>Q(T({},"__esModule",{value:!0}),t);var s=(t,e,r)=>mr(t,typeof e!="symbol"?e+"":e,r);var Z=hr((Sr,L)=>{L.exports=Mediabunny});var Fr={};pr(Fr,{registerProresDecoder:()=>Cr});var h=gr(Z());var b=class extends Error{constructor(e="The decoder ran out of memory."){super(e),this.name="OutOfMemoryError"}},O=class extends Error{constructor(e="Invalid data: the packet ended before the decoder expected it to."){super(e),this.name="UnexpectedEofError"}},k=class extends Error{constructor(e="The packet contains invalid data."){super(e),this.name="InvalidDataError"}},P=class extends Error{constructor(e="The packet uses a feature that is not supported."){super(e),this.name="NotSupportedError"}},_=class extends Error{constructor(e="The decoder is in an invalid internal state. This should never happen! Please report."){super(e),this.name="InvalidStateError"}},M=class extends Error{constructor(e="The decoder has been closed."){super(e),this.name="DecoderClosedError"}},C=class extends Error{constructor(e="The frame is locked by an in-flight decoding operation."){super(e),this.name="FrameLockedError"}},m=class extends Error{constructor(e="A worker failed to start."){super(e),this.name="WorkerStartError"}},tr=(t,e)=>{switch(t){case-1:return new b(e);case-2:return new O(e);case-3:return new k(e);case-4:return new P(e);case-5:return new _(e);case-6:return new k(e??"Unexpected integer overflow.");default:throw new Error(`Unhandled error code: ${t}`)}};function f(t){if(!t)throw new Error("Assertion failed.")}var nr=t=>{let e=0,r="";for(;e<t.length;){let n=t[e++];if(n>127)if(n>191&&n<224){if(e>=t.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");n=(n&31)<<6|t[e++]&63}else if(n>223&&n<240){if(e+1>=t.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");n=(n&15)<<12|(t[e++]&63)<<6|t[e++]&63}else if(n>239&&n<248){if(e+2>=t.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");n=(n&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+n.toString(16)+" at index "+(e-1));if(n<=65535)r+=String.fromCharCode(n);else if(n<=1114111)n-=65536,r+=String.fromCharCode(n>>10|55296),r+=String.fromCharCode(n&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+n.toString(16)+" exceeds UTF-16 reach")}return r},x=class{constructor(){s(this,"currentPromise",Promise.resolve());s(this,"pending",0)}async acquire(){let e,r=new Promise(A=>{let o=!1;e=()=>{o||(A(),this.pending--,o=!0)}}),n=this.currentPromise;return this.currentPromise=r,this.pending++,await n,e}},X=typeof SharedArrayBuffer<"u",Ar=t=>t;Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");var g=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"],yr={1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020",12:"smpte432"},xr={1:"bt709",6:"smpte170m",8:"linear",13:"iec61966-2-1",16:"pq",18:"hlg"},Ir={0:"rgb",1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020-ncl"},D=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeFrame(e)}),v=class{constructor(){s(this,"frameData",null);s(this,"codedWidth",null);s(this,"codedHeight",null);s(this,"visibleWidth",null);s(this,"visibleHeight",null);s(this,"pixelFormat",null);s(this,"originalPixelFormat",null);s(this,"pixelAspectRatio",null);s(this,"colorPrimaries",null);s(this,"colorTransfer",null);s(this,"colorMatrix",null);s(this,"colorRangeFull",null);s(this,"scanType",null);s(this,"_runtime",null);s(this,"_ptr",null);s(this,"_buffer",null);s(this,"_locked",!1)}get colorPrimariesString(){return this.colorPrimaries===null?void 0:yr[this.colorPrimaries]}get colorTransferString(){return this.colorTransfer===null?void 0:xr[this.colorTransfer]}get colorMatrixString(){return this.colorMatrix===null?void 0:Ir[this.colorMatrix]}get isLocked(){return this._locked}get isFilled(){return this.frameData!==null&&this.codedWidth!==null&&this.codedHeight!==null&&this.visibleWidth!==null&&this.visibleHeight!==null&&this.pixelFormat!==null&&this.pixelAspectRatio!==null&&this.colorPrimaries!==null&&this.colorTransfer!==null&&this.colorMatrix!==null&&this.colorRangeFull!==null&&this.scanType!==null}toFilled(){return this.isFilled?this:null}clear(){if(this._locked)throw new C;this._ptr!==null&&(f(this._runtime),D.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null),this._buffer=null,this._reset()}[Symbol.dispose](){this.clear()}_ensureWasmFrame(e){if(this._runtime===e)return!0;this._runtime&&(D.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null);let r=e.exports.createFrame();return r===0?!1:(this._runtime=e,this._ptr=r,D.register(this,{runtime:e,ptr:r},this),!0)}_reset(){this.frameData=null,this.codedWidth=null,this.codedHeight=null,this.visibleWidth=null,this.visibleHeight=null,this.pixelFormat=null,this.pixelAspectRatio=null,this.colorPrimaries=null,this.colorTransfer=null,this.colorMatrix=null,this.colorRangeFull=null,this.scanType=null}_populate(e){this.frameData=e.frameData,this.codedWidth=e.codedWidth,this.codedHeight=e.codedHeight,this.visibleWidth=e.visibleWidth,this.visibleHeight=e.visibleHeight,this.pixelFormat=e.pixelFormat,this.originalPixelFormat=e.originalPixelFormat,this.pixelAspectRatio=e.pixelAspectRatio,this.colorPrimaries=e.colorPrimaries,this.colorTransfer=e.colorTransfer,this.colorMatrix=e.colorMatrix,this.colorRangeFull=e.colorRangeFull,this.scanType=e.scanType}},Tr=(t,e,r,n)=>{let A=t.getFrameDataPtr(r),o=t.getFrameDataSize(r),i=new Uint8Array(e.buffer,A,o),j=g[t.getFramePixelFormat(r)];f(j!==void 0);let B=g[t.getOriginalPixelFormat(n)];f(B!==void 0);let a=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][t.getScanType(r)];return f(a!==void 0),{frameData:i,codedWidth:t.getCodedWidth(r),codedHeight:t.getCodedHeight(r),visibleWidth:t.getVisibleWidth(r),visibleHeight:t.getVisibleHeight(r),pixelFormat:j,originalPixelFormat:B,pixelAspectRatio:{num:t.getAspectRatioNum(r),den:t.getAspectRatioDen(r)},colorPrimaries:t.getColorPrimaries(r),colorTransfer:t.getColorTransfer(r),colorMatrix:t.getColorMatrix(r),colorRangeFull:!1,scanType:a}},d=(t=>(t[t.SharedMemoryInit=0]="SharedMemoryInit",t[t.MessagePassingInit=1]="MessagePassingInit",t[t.CreateDecoder=2]="CreateDecoder",t[t.CloseDecoder=3]="CloseDecoder",t[t.Decode=4]="Decode",t[t.Ready=5]="Ready",t[t.InitOutOfMemoryError=6]="InitOutOfMemoryError",t[t.InitError=7]="InitError",t[t.Decoded=8]="Decoded",t[t.DecodeError=9]="DecodeError",t))(d||{}),R=`\0asm\0\0\0\x99\`\x7F\x7F\x7F\x7F\x7F\`\x7F\x7F\x7F\x7F\x7F\0\`\x7F\0\`\0\0\`\x7F\x7F\x7F\x7F\x7F\x7F\x7F\`
9
9
  \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\`\x7F\x7F\`\x7F\x7F\x7F\x7F{{{{{{{{{{{{{{{{\x7F\x7F\x7F\x7F\0\`\x7F\x7F\x7F\x7F{{{{{{{{{{{{{{{{\x7F\x7F\x7F\0\` \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\0\`\x7F\x7F\0\`\x7F\x7F\x7F\x7F\`\x7F\x7F\x7F\x7F\0\`\x7F\x7F\x7F\`\x7F\x7F\x7F\0\`\0\x7Fenvmemory\x80\x80ML\x07\x07\b\b\b\b\b\b\b\b\b\b
10
10
  \0\v\f\v\r\0\r\v\v\v\r\r\f\f\v\vp \x7FA\x80\x80\xC0\0\v\x7FA\0\v\x7F\0A\x90\b\v\x7F\0A\v\x07\xE1!__stack_pointer\0
11
11
  __tls_base
@@ -908,9 +908,9 @@ lkA\bt rA\xB0\xE0\0r;\0\0 Aj!\v \0 Aj jA! k\xBD\x80\x80\x80\0! A0j$\x
908
908
  \0\0\0\xE0\xFF\xFF\xFF\f\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0Packet is smaller than the picture data size indicated in the picture header.\0Packet is smaller than the frame size indicated in the frame header.\0Invalid DC code stream.\0Invalid AC code stream.\0Picture header size too small.\0Frame header size too small.\0Slice header size too small.\0Frame size too small.\0Invalid packet header frame type.\0Invalid frame type.\0Invalid alpha info header field.\0Invalid aspect ratio information header field.\0Version > 1 is not supported.\0Slice widths larger than 128 are not supported.\0Only slice heights of 1 are supported.\0Picture header extends past the picture data.\0Slice data extends past the bounds of the picture data.\0Frame header extends past the frame data.\0Channel data planes too large to fit into slice data.\0\0\xA0\0\xA0\b\0\xA0\b\0\xA0\v\0\xA0\v\0\xA0\f\0\xA0\f\0\0\0\0\0\xA0\0\xA0\0\xA0\0\xA0\0\xA0\0\xA0 \0\xA0 \0\xA0 \0\xA0 \0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0
909
909
  \0\xA0\0\xA0\x07\0\xA0\0\xA0\0\xA0\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0
910
910
  \0\0\0\0\0\0\0\0\x90\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\b\0\0\0
911
- \0\0\0\f\0\0\0Frame dimensions (x) exceed the maximum supported size of 16384x16384.\0\0\0\0\0\0\0\0\x07\0\0\0\b\0\0\0Unexpected slice count: expected , found .\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0`,Ir=async(t,e)=>{let{instance:r}=await WebAssembly.instantiate(t,{env:{memory:e,externPrint:(A,n)=>{let o=new Uint8Array(e.buffer,A,n);console.log(tr(o))}}});return r.exports},X=`"use strict";var I=(e=>(e[e.OutOfMemory=-1]="OutOfMemory",e[e.UnexpectedEof=-2]="UnexpectedEof",e[e.InvalidData=-3]="InvalidData",e[e.NotSupported=-4]="NotSupported",e[e.InvalidState=-5]="InvalidState",e[e.Overflow=-6]="Overflow",e))(I||{});function f(e){if(!e)throw new Error("Assertion failed.")}const O=e=>{let t=0,r="";for(;t<e.length;){let o=e[t++];if(o>127)if(o>191&&o<224){if(t>=e.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");o=(o&31)<<6|e[t++]&63}else if(o>223&&o<240){if(t+1>=e.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");o=(o&15)<<12|(e[t++]&63)<<6|e[t++]&63}else if(o>239&&o<248){if(t+2>=e.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");o=(o&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+o.toString(16)+" at index "+(t-1));if(o<=65535)r+=String.fromCharCode(o);else if(o<=1114111)o-=65536,r+=String.fromCharCode(o>>10|55296),r+=String.fromCharCode(o&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+o.toString(16)+" exceeds UTF-16 reach")}return r};Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");const S=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"];new FinalizationRegistry(({runtime:e,ptr:t})=>{e.exports.closeFrame(t)});const _=(e,t,r,o)=>{const i=e.getFrameDataPtr(r),a=e.getFrameDataSize(r),w=new Uint8Array(t.buffer,i,a),u=S[e.getFramePixelFormat(r)];f(u!==void 0);const l=S[e.getOriginalPixelFormat(o)];f(l!==void 0);const c=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][e.getScanType(r)];return f(c!==void 0),{frameData:w,codedWidth:e.getCodedWidth(r),codedHeight:e.getCodedHeight(r),visibleWidth:e.getVisibleWidth(r),visibleHeight:e.getVisibleHeight(r),pixelFormat:u,originalPixelFormat:l,pixelAspectRatio:{num:e.getAspectRatioNum(r),den:e.getAspectRatioDen(r)},colorPrimaries:e.getColorPrimaries(r),colorTransfer:e.getColorTransfer(r),colorMatrix:e.getColorMatrix(r),colorRangeFull:!1,scanType:c}};var n=(e=>(e[e.SharedMemoryInit=0]="SharedMemoryInit",e[e.MessagePassingInit=1]="MessagePassingInit",e[e.CreateDecoder=2]="CreateDecoder",e[e.CloseDecoder=3]="CloseDecoder",e[e.Decode=4]="Decode",e[e.Ready=5]="Ready",e[e.InitOutOfMemoryError=6]="InitOutOfMemoryError",e[e.Decoded=7]="Decoded",e[e.DecodeError=8]="DecodeError",e))(n||{});const A=async(e,t)=>{const{instance:r}=await WebAssembly.instantiate(e,{env:{memory:t,externPrint:(o,i)=>{const a=new Uint8Array(t.buffer,o,i);console.log(O(a))}}});return r.exports};let s=null;const F=async e=>{switch(e.type){case n.SharedMemoryInit:{const t=await A(e.wasmBinary,e.memory);throw t.__stack_pointer.value=e.stackPointer,t.__wasm_init_tls(e.tlsPointer),t.setIsBrowserMainThread(0),t.startWorker(),new Error("Unexpected worker termination.")}case n.MessagePassingInit:{const t=new WebAssembly.Memory({initial:32,maximum:8192,shared:!0}),r=await A(e.wasmBinary,t),o=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(o===0){d({type:n.InitOutOfMemoryError,message:"Failed to allocate thread-local state."});return}r.__wasm_init_tls(o),r.setIsBrowserMainThread(0);const i=r.createFrame();if(i===0){d({type:n.InitOutOfMemoryError,message:"Failed to create frame."});return}s={exports:r,memory:t,decoders:new Map,frame:i},d({type:n.Ready});return}case n.CreateDecoder:{f(s);const{exports:t}=s,{decoderId:r,bitDepth:o,allowedOutputFormats:i}=e,a=t.createDecoder(0,o,i);if(a===0)return;s.decoders.set(r,a);return}case n.CloseDecoder:{f(s);const{exports:t,decoders:r}=s,o=r.get(e.decoderId);o!==void 0&&(t.closeDecoder(o),r.delete(e.decoderId));return}case n.Decode:{f(s);const{exports:t,memory:r,decoders:o,frame:i}=s,{id:a,decoderId:w,packet:u,frameBuffer:l}=e,c=o.get(w);if(c===void 0){d({type:n.DecodeError,id:a,code:I.OutOfMemory});return}const g=t.allocatePacket(c,u.byteLength,0);if(g===0){d({type:n.DecodeError,id:a,code:I.OutOfMemory});return}new Uint8Array(r.buffer).set(u,g);const D=t.decodePacket(c,i,0);if(D<0){let v;const P=t.getErrorMessagePtr(c);if(P!==0){const b=t.getErrorMessageSize(c);v=O(new Uint8Array(r.buffer,P,b))}d({type:n.DecodeError,id:a,code:D,message:v});return}const m=_(t,r,i,c),y=l&&l.byteLength===m.frameData.byteLength?l:new ArrayBuffer(m.frameData.byteLength),p=new Uint8Array(y);p.set(m.frameData),m.frameData=p,d({type:n.Decoded,id:a,contents:m},[y]);return}}},d=(e,t)=>{h?h.postMessage(e,t??[]):self.postMessage(e,{transfer:t??[]})};let h=null;try{h=require("node:worker_threads").parentPort}catch{}h?h.on("message",F):self.addEventListener("message",e=>void F(e.data));
912
- `,T=null,M=()=>{if(T)return T;T=new Uint8Array(D.length);for(let t=0;t<D.length;t++)T[t]=D.charCodeAt(t);return T},nr=async()=>{if(typeof Worker<"u"&&!("Bun"in globalThis)){let e=new Blob([X],{type:"text/javascript"}),r=URL.createObjectURL(e),A=new Worker(r,{type:"module"});return new C(A,null)}let t=await import("node:"+Ar("worker_threads"));return new C(null,new t.Worker(X,{eval:!0}))},C=class{constructor(e,r){i(this,"wrappedListeners",new Map);this.webWorker=e,this.nodeWorker=r}postMessage(e,r){this.webWorker?this.webWorker.postMessage(e,{transfer:r??[]}):this.nodeWorker.postMessage(e,r??[])}addEventListener(e,r,A){if(this.webWorker)this.webWorker.addEventListener(e,r,A);else{let n=o=>r({data:o});this.wrappedListeners.set(r,n),A?.once?this.nodeWorker.once(e,n):this.nodeWorker.on(e,n)}}removeEventListener(e,r){this.webWorker?this.webWorker.removeEventListener(e,r):(this.nodeWorker.off(e,this.wrappedListeners.get(r)),this.wrappedListeners.delete(r))}terminate(){this.webWorker?this.webWorker.terminate():this.nodeWorker.terminate()}},Y=new FinalizationRegistry(t=>{for(let e of t)e.terminate()}),Tr=async()=>{if(typeof navigator<"u"&&navigator.hardwareConcurrency)return navigator.hardwareConcurrency;let t=await import("node:"+Ar("os"));return t.availableParallelism?.()??t.cpus().length},w=null,vr=new y,wr=async()=>{let t=await vr.acquire();try{if(w){let r=w.deref();if(r)return r}let e=await U.init();return w=new WeakRef(e),e}finally{t()}},$=null,Er=()=>{let t=$?.deref();return t||(t=new N,$=new WeakRef(t)),t},F=class{constructor(){i(this,"workers",[]);i(this,"refCount",0);Y.register(this,this.workers,this)}ref(){this.refCount++}unref(){this.refCount--,!(typeof window<"u"&&typeof document<"u")&&this.refCount===0&&this.destroy()}destroy(){for(let e of this.workers)e.terminate();this.workers.length=0,Y.unregister(this)}},U=class t extends F{constructor(e,r){super(),this.memory=e,this.exports=r}static async init(){let e=new WebAssembly.Memory({initial:32,maximum:65536,shared:!0}),r=await Ir(M(),e),A=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(A===0)throw new Error("Failed to allocate thread-local state.");r.__wasm_init_tls(A);let n=typeof window<"u"&&typeof document<"u"&&self===window;return r.setIsBrowserMainThread(Number(n)),new t(e,r)}async ensureWorkers(e){for(;this.workers.length<e;){let r=this.exports.allocateWorkerStack(),A=this.exports.allocateThreadLocalState(this.exports.__tls_size.value,this.exports.__tls_align.value);if(r===0||A===0)throw new Error("Failed to allocate worker stack or thread-local state.");let n=await nr();n.postMessage({type:u.SharedMemoryInit,wasmBinary:M(),memory:this.memory,stackPointer:r,tlsPointer:A}),this.workers.push(n)}}destroy(){super.destroy(),w=null}},N=class extends F{constructor(){super(...arguments);i(this,"workerLoad",[]);i(this,"nextRequestId",0);i(this,"nextDecoderId",0);i(this,"registeredDecoders",new Map)}registerDecoder(r,A,n){this.registeredDecoders.set(r,{bitDepth:A,allowedOutputFormats:n});for(let o of this.workers)o.postMessage({type:u.CreateDecoder,decoderId:r,bitDepth:A,allowedOutputFormats:n})}unregisterDecoder(r){this.registeredDecoders.delete(r);for(let A of this.workers)A.postMessage({type:u.CloseDecoder,decoderId:r})}async ensureWorkers(r){let A=r-this.workers.length;if(A<=0)return;let n=await Promise.all(Array.from({length:A},async()=>{let s=await nr(),j=await new Promise(B=>{s.postMessage({type:u.MessagePassingInit,wasmBinary:M()}),s.addEventListener("message",a=>B(a.data),{once:!0})});return j.type===u.InitOutOfMemoryError?(s.terminate(),new g(j.message)):s})),o=n.find(s=>s instanceof Error);if(o){for(let s of n)s instanceof Error||s.terminate();return o}for(let s of n){this.workers.push(s),this.workerLoad.push(0);for(let[j,{bitDepth:B,allowedOutputFormats:a}]of this.registeredDecoders)s.postMessage({type:u.CreateDecoder,decoderId:j,bitDepth:B,allowedOutputFormats:a})}}destroy(){super.destroy(),$=null}},J=["ap4x","ap4h","apch","apcn","apcs","apco"],b=class{constructor(){i(this,"_closed",!1);i(this,"_queue",Promise.resolve());i(this,"_decodeQueueSize",0);i(this,"_dequeuedResolve");i(this,"_dequeued",new Promise(e=>{this._dequeuedResolve=e}))}get decodeQueueSize(){return this._decodeQueueSize}get desiredSize(){return this._highWaterMark-this._decodeQueueSize}get dequeued(){return this._dequeued}_markDequeued(){this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(e=>{this._dequeuedResolve=e})}static async create(e){if(typeof e!="object"||!e)throw new TypeError("options must be an object.");if(!J.includes(e.proresFourCc))throw new TypeError(`options.proresFourCc must be one of ${J.join(", ")}.`);if(typeof e.useSharedMemory!="boolean")throw new TypeError("options.useSharedMemory must be a boolean.");if(e.concurrency!==void 0&&(!Number.isInteger(e.concurrency)||e.concurrency<0))throw new TypeError("options.concurrency, when provided, must be a non-negative integer.");if(e.allowedOutputFormats&&!(Array.isArray(e.allowedOutputFormats)&&e.allowedOutputFormats.length>0&&e.allowedOutputFormats.every(o=>p.includes(o))))throw new TypeError(`options.allowedOutputFormats, when provided, must be a non-empty array containing any of: ${p.join(", ")}.`);if(e.useSharedMemory&&!Z)return new P(`Shared memory is not available in this environment, so useSharedMemory: true cannot be used.
911
+ \0\0\0\f\0\0\0Frame dimensions (x) exceed the maximum supported size of 16384x16384.\0\0\0\0\0\0\0\0\x07\0\0\0\b\0\0\0Unexpected slice count: expected , found .\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0`,wr=async(t,e)=>{let{instance:r}=await WebAssembly.instantiate(t,{env:{memory:e,externPrint:(n,A)=>{let o=new Uint8Array(e.buffer,n,A);console.log(nr(o))}}});return r.exports},Y=`"use strict";var w=(e=>(e[e.OutOfMemory=-1]="OutOfMemory",e[e.UnexpectedEof=-2]="UnexpectedEof",e[e.InvalidData=-3]="InvalidData",e[e.NotSupported=-4]="NotSupported",e[e.InvalidState=-5]="InvalidState",e[e.Overflow=-6]="Overflow",e))(w||{});function f(e){if(!e)throw new Error("Assertion failed.")}const O=e=>{let t=0,r="";for(;t<e.length;){let o=e[t++];if(o>127)if(o>191&&o<224){if(t>=e.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");o=(o&31)<<6|e[t++]&63}else if(o>223&&o<240){if(t+1>=e.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");o=(o&15)<<12|(e[t++]&63)<<6|e[t++]&63}else if(o>239&&o<248){if(t+2>=e.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");o=(o&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+o.toString(16)+" at index "+(t-1));if(o<=65535)r+=String.fromCharCode(o);else if(o<=1114111)o-=65536,r+=String.fromCharCode(o>>10|55296),r+=String.fromCharCode(o&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+o.toString(16)+" exceeds UTF-16 reach")}return r};Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");const v=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"];new FinalizationRegistry(({runtime:e,ptr:t})=>{e.exports.closeFrame(t)});const _=(e,t,r,o)=>{const i=e.getFrameDataPtr(r),a=e.getFrameDataSize(r),I=new Uint8Array(t.buffer,i,a),m=v[e.getFramePixelFormat(r)];f(m!==void 0);const l=v[e.getOriginalPixelFormat(o)];f(l!==void 0);const c=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][e.getScanType(r)];return f(c!==void 0),{frameData:I,codedWidth:e.getCodedWidth(r),codedHeight:e.getCodedHeight(r),visibleWidth:e.getVisibleWidth(r),visibleHeight:e.getVisibleHeight(r),pixelFormat:m,originalPixelFormat:l,pixelAspectRatio:{num:e.getAspectRatioNum(r),den:e.getAspectRatioDen(r)},colorPrimaries:e.getColorPrimaries(r),colorTransfer:e.getColorTransfer(r),colorMatrix:e.getColorMatrix(r),colorRangeFull:!1,scanType:c}};var n=(e=>(e[e.SharedMemoryInit=0]="SharedMemoryInit",e[e.MessagePassingInit=1]="MessagePassingInit",e[e.CreateDecoder=2]="CreateDecoder",e[e.CloseDecoder=3]="CloseDecoder",e[e.Decode=4]="Decode",e[e.Ready=5]="Ready",e[e.InitOutOfMemoryError=6]="InitOutOfMemoryError",e[e.InitError=7]="InitError",e[e.Decoded=8]="Decoded",e[e.DecodeError=9]="DecodeError",e))(n||{});const U=async(e,t)=>{const{instance:r}=await WebAssembly.instantiate(e,{env:{memory:t,externPrint:(o,i)=>{const a=new Uint8Array(t.buffer,o,i);console.log(O(a))}}});return r.exports};let d=null;const F=async e=>{switch(e.type){case n.SharedMemoryInit:{const t=await A(e.wasmBinary,e.memory);if(!t)return;throw t.__stack_pointer.value=e.stackPointer,t.__wasm_init_tls(e.tlsPointer),t.setIsBrowserMainThread(0),s({type:n.Ready}),t.startWorker(),new Error("Unexpected worker termination.")}case n.MessagePassingInit:{const t=new WebAssembly.Memory({initial:32,maximum:8192,shared:!0}),r=await A(e.wasmBinary,t);if(!r)return;const o=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(o===0){s({type:n.InitOutOfMemoryError,message:"Failed to allocate thread-local state."});return}r.__wasm_init_tls(o),r.setIsBrowserMainThread(0);const i=r.createFrame();if(i===0){s({type:n.InitOutOfMemoryError,message:"Failed to create frame."});return}d={exports:r,memory:t,decoders:new Map,frame:i},s({type:n.Ready});return}case n.CreateDecoder:{f(d);const{exports:t}=d,{decoderId:r,bitDepth:o,allowedOutputFormats:i}=e,a=t.createDecoder(0,o,i);if(a===0)return;d.decoders.set(r,a);return}case n.CloseDecoder:{f(d);const{exports:t,decoders:r}=d,o=r.get(e.decoderId);o!==void 0&&(t.closeDecoder(o),r.delete(e.decoderId));return}case n.Decode:{f(d);const{exports:t,memory:r,decoders:o,frame:i}=d,{id:a,decoderId:I,packet:m,frameBuffer:l}=e,c=o.get(I);if(c===void 0){s({type:n.DecodeError,id:a,code:w.OutOfMemory});return}const g=t.allocatePacket(c,m.byteLength,0);if(g===0){s({type:n.DecodeError,id:a,code:w.OutOfMemory});return}new Uint8Array(r.buffer).set(m,g);const D=t.decodePacket(c,i,0);if(D<0){let S;const P=t.getErrorMessagePtr(c);if(P!==0){const b=t.getErrorMessageSize(c);S=O(new Uint8Array(r.buffer,P,b))}s({type:n.DecodeError,id:a,code:D,message:S});return}const h=_(t,r,i,c),y=l&&l.byteLength===h.frameData.byteLength?l:new ArrayBuffer(h.frameData.byteLength),p=new Uint8Array(y);p.set(h.frameData),h.frameData=p,s({type:n.Decoded,id:a,contents:h},[y]);return}}},A=async(e,t)=>{try{return await U(e,t)}catch(r){return s({type:n.InitError,message:String(r)}),null}},s=(e,t)=>{u?u.postMessage(e,t??[]):self.postMessage(e,{transfer:t??[]})};let u=null;try{u=require("node:worker_threads").parentPort}catch{"WorkerGlobalScope"in globalThis||(u=process.getBuiltinModule("node:worker_threads").parentPort)}u?u.on("message",F):self.addEventListener("message",e=>void F(e.data));
912
+ `,w=null,$=()=>{if(w)return w;w=new Uint8Array(R.length);for(let t=0;t<R.length;t++)w[t]=R.charCodeAt(t);return w},or=async()=>{let t=globalThis[Symbol.for("turbores:workerUrl")];if(t!==void 0&&typeof t!="string"&&!(t instanceof URL))throw new TypeError("globalThis[Symbol.for('turbores:workerUrl')], when provided, must be a string or URL.");if(typeof Worker<"u"&&!("Bun"in globalThis)){let r=t;if(r===void 0){let n=new Blob([Y],{type:"text/javascript"});r=URL.createObjectURL(n)}try{return new F(new Worker(r,{type:"module"}),null)}catch(n){return new m(`A worker failed to start: ${String(n)}`)}}let e=await import("node:"+Ar("worker_threads"));try{return new F(null,t!==void 0?new e.Worker(t):new e.Worker(Y,{eval:!0}))}catch(r){return new m(`A worker failed to start: ${String(r)}`)}},F=class{constructor(e,r){s(this,"wrappedListeners",new Map);this.webWorker=e,this.nodeWorker=r}postMessage(e,r){this.webWorker?this.webWorker.postMessage(e,{transfer:r??[]}):this.nodeWorker.postMessage(e,r??[])}addEventListener(e,r,n){if(this.webWorker)this.webWorker.addEventListener(e,r,n);else{let A=o=>r({data:o});this.wrappedListeners.set(r,A),n?.once?this.nodeWorker.once(e,A):this.nodeWorker.on(e,A)}}onError(e){this.webWorker?this.webWorker.addEventListener("error",r=>e(r.message)):this.nodeWorker.on("error",r=>e(r.message))}removeEventListener(e,r){this.webWorker?this.webWorker.removeEventListener(e,r):(this.nodeWorker.off(e,this.wrappedListeners.get(r)),this.wrappedListeners.delete(r))}terminate(){this.webWorker?this.webWorker.terminate():this.nodeWorker.terminate()}},J=new FinalizationRegistry(t=>{for(let e of t)e.terminate()}),vr=async()=>{if(typeof navigator<"u"&&navigator.hardwareConcurrency)return navigator.hardwareConcurrency;let t=await import("node:"+Ar("os"));return t.availableParallelism?.()??t.cpus().length},E=null,Er=new x,kr=async()=>{let t=await Er.acquire();try{if(E){let r=E.deref();if(r)return r}let e=await N.init();return E=new WeakRef(e),e}finally{t()}},U=null,Pr=()=>{let t=U?.deref();return t||(t=new W,U=new WeakRef(t)),t},q=class{constructor(){s(this,"workers",[]);s(this,"refCount",0);J.register(this,this.workers,this)}ref(){this.refCount++}unref(){this.refCount--,!(typeof window<"u"&&typeof document<"u")&&this.refCount===0&&this.destroy()}destroy(){for(let e of this.workers)e.terminate();this.workers.length=0,J.unregister(this)}},N=class t extends q{constructor(e,r){super(),this.memory=e,this.exports=r}static async init(){let e=new WebAssembly.Memory({initial:32,maximum:65536,shared:!0}),r=await wr($(),e),n=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(n===0)throw new Error("Failed to allocate thread-local state.");r.__wasm_init_tls(n);let A=typeof window<"u"&&typeof document<"u"&&self===window;return r.setIsBrowserMainThread(Number(A)),new t(e,r)}async ensureWorkers(e){let r=[],n=null;for(;this.workers.length+r.length<e;){let A=this.exports.allocateWorkerStack(),o=this.exports.allocateThreadLocalState(this.exports.__tls_size.value,this.exports.__tls_align.value);if(A===0||o===0)throw new Error("Failed to allocate worker stack or thread-local state.");let i=await or();if(i instanceof m){n=i;break}i.postMessage({type:d.SharedMemoryInit,wasmBinary:$(),memory:this.memory,stackPointer:A,tlsPointer:o}),r.push({worker:i,reply:ir(i)})}for(let{worker:A,reply:o}of r){let i=await o;i instanceof m?(A.terminate(),n=i):(f(i.type===d.Ready),this.workers.push(A))}return n}destroy(){super.destroy(),E=null}},W=class extends q{constructor(){super(...arguments);s(this,"workerLoad",[]);s(this,"nextRequestId",0);s(this,"nextDecoderId",0);s(this,"registeredDecoders",new Map)}registerDecoder(r,n,A){this.registeredDecoders.set(r,{bitDepth:n,allowedOutputFormats:A});for(let o of this.workers)o.postMessage({type:d.CreateDecoder,decoderId:r,bitDepth:n,allowedOutputFormats:A})}unregisterDecoder(r){this.registeredDecoders.delete(r);for(let n of this.workers)n.postMessage({type:d.CloseDecoder,decoderId:r})}async ensureWorkers(r){let n=r-this.workers.length;if(n<=0)return;let A=await Promise.all(Array.from({length:n},async()=>{let i=await or();if(i instanceof m)return i;i.postMessage({type:d.MessagePassingInit,wasmBinary:$()});let j=await ir(i);return j instanceof m?(i.terminate(),j):j.type===d.InitOutOfMemoryError?(i.terminate(),new b(j.message)):i})),o=A.find(i=>i instanceof Error);if(o){for(let i of A)i instanceof Error||i.terminate();return o}for(let i of A){this.workers.push(i),this.workerLoad.push(0);for(let[j,{bitDepth:B,allowedOutputFormats:a}]of this.registeredDecoders)i.postMessage({type:d.CreateDecoder,decoderId:j,bitDepth:B,allowedOutputFormats:a})}}destroy(){super.destroy(),U=null}},ir=t=>new Promise(e=>{t.addEventListener("message",r=>{let n=r.data;n.type===d.InitError?e(new m(`A worker failed to start: ${n.message}`)):e(n)},{once:!0}),t.onError(r=>{e(new m(r?`A worker failed to start: ${r}`:void 0))})}),z=["ap4x","ap4h","apch","apcn","apcs","apco"],y=class{constructor(){s(this,"_closed",!1);s(this,"_queue",Promise.resolve());s(this,"_decodeQueueSize",0);s(this,"_dequeuedResolve");s(this,"_dequeued",new Promise(e=>{this._dequeuedResolve=e}))}get decodeQueueSize(){return this._decodeQueueSize}get desiredSize(){return this._highWaterMark-this._decodeQueueSize}get dequeued(){return this._dequeued}_markDequeued(){this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(e=>{this._dequeuedResolve=e})}static async create(e){if(typeof e!="object"||!e)throw new TypeError("options must be an object.");if(!z.includes(e.proresFourCc))throw new TypeError(`options.proresFourCc must be one of ${z.join(", ")}.`);if(typeof e.useSharedMemory!="boolean")throw new TypeError("options.useSharedMemory must be a boolean.");if(e.concurrency!==void 0&&(!Number.isInteger(e.concurrency)||e.concurrency<0))throw new TypeError("options.concurrency, when provided, must be a non-negative integer.");if(e.allowedOutputFormats&&!(Array.isArray(e.allowedOutputFormats)&&e.allowedOutputFormats.length>0&&e.allowedOutputFormats.every(o=>g.includes(o))))throw new TypeError(`options.allowedOutputFormats, when provided, must be a non-empty array containing any of: ${g.join(", ")}.`);if(e.useSharedMemory&&!X)return new P(`Shared memory is not available in this environment, so useSharedMemory: true cannot be used.
913
913
  Since it provides way better performance, you should enable it by serving the page cross-origin isolated by setting the Cross-Origin-Opener-Policy header to 'same-origin' and the Cross-Origin-Embedder-Policy header to 'credentialless' or 'require-corp' (only the latter is supported by Safari).
914
- Otherwise, pass useSharedMemory: false to use a slower, worker-based fallback.`);let r;if(e.allowedOutputFormats){r=0;for(let o of e.allowedOutputFormats)r|=1<<p.indexOf(o)}else r=4294967295;let A=e.proresFourCc==="ap4h"||e.proresFourCc==="ap4x"?12:10,n=e.concurrency??await Tr();if(e.useSharedMemory||n===0){let o=await wr();o.ref(),await o.ensureWorkers(n);let s=o.exports.createDecoder(n,A,r);return s===0?(o.unref(),new g):new W(o,s,n)}else{let o=Er();o.ref();let s=await o.ensureWorkers(n);return s?(o.unref(),s):new H(o,n,A,r)}}static canUseSharedMemory(){return Z}async decode(e,r,A={}){if(!(e instanceof Uint8Array))throw new TypeError("packetData must be a Uint8Array.");if(!(r instanceof v))throw new TypeError("frame must be a Frame.");if(typeof A!="object"||!A)throw new TypeError("options must be an object.");if(A.transfer!==void 0&&typeof A.transfer!="boolean")throw new TypeError("options.transfer, when provided, must be a boolean.");if(this._closed)return new _;if(r._locked)return new k;r._reset(),r._locked=!0,this._decodeQueueSize++;let n=this._runDecode(e,r,A);n.catch(()=>{});let o=this._queue.then(()=>n).finally(()=>{r._locked=!1,queueMicrotask(()=>{this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(s=>{this._dequeuedResolve=s})})});return this._queue=o.catch(()=>{}),o}close(){if(this._closed)return this._queue;this._closed=!0;let e=this._queue.then(()=>this._runClose());return this._queue=e.catch(()=>{}),e}get isClosed(){return this._closed}[Symbol.dispose](){this.close()}[Symbol.asyncDispose](){return this.close()}},z=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeDecoder(e),t.unref()}),W=class extends b{constructor(r,A,n){super();i(this,"_runtime");i(this,"_decoderPtr");i(this,"_taskStateOffset");i(this,"_decodeMutex",new y);i(this,"_nextPacketSlot",0);i(this,"_packetSlotMutexes",[new y,new y]);i(this,"_highWaterMark");i(this,"useSharedMemory",!0);i(this,"concurrency");this._highWaterMark=n===0?1:2,this._runtime=r,this._decoderPtr=A,this._taskStateOffset=r.exports.getTaskStateAddress(A)/4,this.concurrency=n,z.register(this,{runtime:r,ptr:A},this)}_runClose(){f(this._runtime),z.unregister(this),this._runtime.exports.closeDecoder(this._decoderPtr),this._runtime.unref(),this._runtime=null}async _runDecode(r,A,n){f(this._runtime);let{exports:o,memory:s}=this._runtime;if(!A._ensureWasmFrame(this._runtime))return new g;let j=A._ptr;n.transfer&&(r=structuredClone(r,{transfer:[r.buffer]}));let B=this._nextPacketSlot;this._nextPacketSlot=this._nextPacketSlot+1&1;let a=await this._packetSlotMutexes[B].acquire();try{let c=o.allocatePacket(this._decoderPtr,r.byteLength,B);if(c===0)return new g;new Uint8Array(s.buffer).set(r,c);let l=await this._decodeMutex.acquire();try{let d=o.decodePacket(this._decoderPtr,j,B);if(d<0)return this._createError(d);if(this.concurrency>0&&(await Atomics.waitAsync(new Int32Array(s.buffer),this._taskStateOffset,1).value,d=o.finalizePacketDecoding(this._decoderPtr),d<0))return this._createError(d);A._populate(xr(o,s,j,this._decoderPtr))}finally{l()}}finally{a()}return A}_createError(r){f(this._runtime);let{exports:A,memory:n}=this._runtime,o,s=A.getErrorMessagePtr(this._decoderPtr);if(s!==0){let j=A.getErrorMessageSize(this._decoderPtr);o=tr(new Uint8Array(n.buffer,s,j))}return er(r,o)}},rr=new FinalizationRegistry(t=>{t.unref()}),H=class extends b{constructor(r,A,n,o){super();i(this,"_runtime");i(this,"_decoderId");i(this,"_highWaterMark");i(this,"useSharedMemory",!1);i(this,"concurrency");this._highWaterMark=Math.max(A,1),this._runtime=r,this.concurrency=A,this._decoderId=r.nextDecoderId++,r.registerDecoder(this._decoderId,n,o),rr.register(this,r,this)}_runClose(){f(this._runtime),this._runtime.unregisterDecoder(this._decoderId),rr.unregister(this),this._runtime.unref(),this._runtime=null}_runDecode(r,A,n){f(this._runtime);let o=this._runtime,s=n.transfer?r:r.slice(),j=0;for(let l=1;l<o.workerLoad.length;l++)o.workerLoad[l]<o.workerLoad[j]&&(j=l);let B=o.workers[j];o.workerLoad[j]=o.workerLoad[j]+1;let a=o.nextRequestId++,c=A._buffer;return A._buffer=null,new Promise(l=>{B.postMessage({type:u.Decode,id:a,decoderId:this._decoderId,packet:s,frameBuffer:c},c?[s.buffer,c]:[s.buffer]);let d=jr=>{let h=jr.data;h.type!==u.Decoded&&h.type!==u.DecodeError||h.id===a&&(B.removeEventListener("message",d),o.workerLoad[j]--,h.type===u.DecodeError?l(er(h.code,h.message)):(A._buffer=h.contents.frameData.buffer,A._populate(h.contents),l(A)))};B.addEventListener("message",d)})}};function q(t){if(!t)throw new Error("Assertion failed.")}var Dr=Math.PI/180,Or=180/Math.PI;var Rr=1e6*(1+Number.EPSILON);var G=null,or=()=>G!==null?G:G=!!(typeof navigator<"u"&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));var sr=Symbol.for("@mediabunny/prores loaded");globalThis[sr]&&m.Logging._error(`[WARNING]
915
- @mediabunny/prores was loaded twice. This will likely cause the decoder not to work correctly. Check if multiple dependencies are importing different versions of @mediabunny/prores, or if something is being bundled incorrectly.`);globalThis[sr]=!0;var x=class x extends m.CustomVideoDecoder{constructor(){super(...arguments);this.decoder=null;this.framePool=[];this.lastDecodePromise=Promise.resolve()}static supports(r,A){return r==="prores"}static _determineSupportedVideoFrameFormats(){let r=[],A=new Uint8Array(32);for(let n of p)try{new VideoFrame(A,{format:n,codedWidth:2,codedHeight:2,timestamp:0,duration:0}).close(),r.push(n)}catch{}return r}async init(){typeof VideoFrame<"u"&&(x._supportedVideoFrameFormats??=x._determineSupportedVideoFrameFormats());let r=await b.create({proresFourCc:this.config.codec,useSharedMemory:b.canUseSharedMemory(),allowedOutputFormats:x._supportedVideoFrameFormats??void 0});if(r instanceof Error)throw r;this.decoder=r}async decode(r){for(q(this.decoder);this.decoder.desiredSize<=0;)await this.decoder.dequeued;this.lastDecodePromise=this.runDecode(r).catch(A=>this.onError(A))}async runDecode(r){q(this.decoder);let A;this.framePool.length>0?A=this.framePool.shift():A=new v;let n=await this.decoder.decode(r.data,A);if(this.framePool.push(A),n instanceof Error)throw n;n.visibleHeight<n.codedHeight&&or()&&this.trimCodedHeightToVisibleHeight(n);let o=this.config.colorSpace,s={primaries:o?.primaries??n.colorPrimariesString,matrix:o?.matrix??n.colorMatrixString,transfer:o?.transfer??n.colorTransferString,fullRange:o?.fullRange??n.colorRangeFull},j=n.pixelAspectRatio;this.config.displayAspectWidth!==void 0&&this.config.displayAspectHeight!==void 0&&(j={num:this.config.displayAspectWidth*n.visibleHeight,den:this.config.displayAspectHeight*n.visibleWidth});let B=n.visibleWidth,a=n.visibleHeight;j.num>j.den?B=Math.round(n.visibleWidth*j.num/j.den):a=Math.round(n.visibleHeight*j.den/j.num);let c;if(typeof VideoFrame<"u"){let l=new VideoFrame(n.frameData,{format:n.pixelFormat,codedWidth:n.codedWidth,codedHeight:n.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{x:0,y:0,width:n.visibleWidth,height:n.visibleHeight},timestamp:r.microsecondTimestamp,duration:r.microsecondDuration,colorSpace:s});c=new m.VideoSample(l,{timestamp:r.timestamp,duration:r.duration})}else c=new m.VideoSample(n.frameData,{format:n.pixelFormat,codedWidth:n.codedWidth,codedHeight:n.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{left:0,top:0,width:n.visibleWidth,height:n.visibleHeight},timestamp:r.timestamp,duration:r.duration,colorSpace:s});this.onSample(c)}trimCodedHeightToVisibleHeight(r){let A=r.pixelFormat.includes("P")?2:1,n=r.pixelFormat.includes("444")?1:2,o=r.pixelFormat.includes("420")?2:1,s=r.codedWidth/n,j=r.codedHeight/o,B=Math.ceil(r.visibleHeight/o),a=r.codedWidth*r.codedHeight,c=r.codedWidth*r.visibleHeight,l=s*j,d=s*B;r.frameData.set(r.frameData.subarray(A*a,A*(a+l)),A*c),r.frameData.set(r.frameData.subarray(A*(a+l),A*(a+2*l)),A*(c+d)),r.pixelFormat.includes("A")&&r.frameData.set(r.frameData.subarray(A*(a+2*l),A*(2*a+2*l)),A*(c+2*d)),r.codedHeight=r.visibleHeight}async flush(){await this.lastDecodePromise}async close(){q(this.decoder),await this.decoder.close();for(let r of this.framePool)r.clear()}};x._supportedVideoFrameFormats=null;var K=x,ir=!1,Pr=()=>{ir||(ir=!0,(0,m.registerDecoder)(K))};return pr(kr);})();
914
+ Otherwise, pass useSharedMemory: false to use a slower, worker-based fallback.`);let r;if(e.allowedOutputFormats){r=0;for(let o of e.allowedOutputFormats)r|=1<<g.indexOf(o)}else r=4294967295;let n=e.proresFourCc==="ap4h"||e.proresFourCc==="ap4x"?12:10,A=e.concurrency??await vr();if(e.useSharedMemory||A===0){let o=await kr();o.ref();let i=await o.ensureWorkers(A);if(i)return o.unref(),i;let j=o.exports.createDecoder(A,n,r);return j===0?(o.unref(),new b):new H(o,j,A)}else{let o=Pr();o.ref();let i=await o.ensureWorkers(A);return i?(o.unref(),i):new K(o,A,n,r)}}static canUseSharedMemory(){return X}async decode(e,r,n={}){if(!(e instanceof Uint8Array))throw new TypeError("packetData must be a Uint8Array.");if(!(r instanceof v))throw new TypeError("frame must be a Frame.");if(typeof n!="object"||!n)throw new TypeError("options must be an object.");if(n.transfer!==void 0&&typeof n.transfer!="boolean")throw new TypeError("options.transfer, when provided, must be a boolean.");if(this._closed)return new M;if(r._locked)return new C;r._reset(),r._locked=!0,this._decodeQueueSize++;let A=this._runDecode(e,r,n);A.catch(()=>{});let o=this._queue.then(()=>A).finally(()=>{r._locked=!1,queueMicrotask(()=>{this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(i=>{this._dequeuedResolve=i})})});return this._queue=o.catch(()=>{}),o}close(){if(this._closed)return this._queue;this._closed=!0;let e=this._queue.then(()=>this._runClose());return this._queue=e.catch(()=>{}),e}get isClosed(){return this._closed}[Symbol.dispose](){this.close()}[Symbol.asyncDispose](){return this.close()}},rr=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeDecoder(e),t.unref()}),H=class extends y{constructor(r,n,A){super();s(this,"_runtime");s(this,"_decoderPtr");s(this,"_taskStateOffset");s(this,"_decodeMutex",new x);s(this,"_nextPacketSlot",0);s(this,"_packetSlotMutexes",[new x,new x]);s(this,"_highWaterMark");s(this,"useSharedMemory",!0);s(this,"concurrency");this._highWaterMark=A===0?1:2,this._runtime=r,this._decoderPtr=n,this._taskStateOffset=r.exports.getTaskStateAddress(n)/4,this.concurrency=A,rr.register(this,{runtime:r,ptr:n},this)}_runClose(){f(this._runtime),rr.unregister(this),this._runtime.exports.closeDecoder(this._decoderPtr),this._runtime.unref(),this._runtime=null}async _runDecode(r,n,A){f(this._runtime);let{exports:o,memory:i}=this._runtime;if(!n._ensureWasmFrame(this._runtime))return new b;let j=n._ptr;A.transfer&&(r=structuredClone(r,{transfer:[r.buffer]}));let B=this._nextPacketSlot;this._nextPacketSlot=this._nextPacketSlot+1&1;let a=await this._packetSlotMutexes[B].acquire();try{let c=o.allocatePacket(this._decoderPtr,r.byteLength,B);if(c===0)return new b;new Uint8Array(i.buffer).set(r,c);let l=await this._decodeMutex.acquire();try{let u=o.decodePacket(this._decoderPtr,j,B);if(u<0)return this._createError(u);if(this.concurrency>0&&(await Atomics.waitAsync(new Int32Array(i.buffer),this._taskStateOffset,1).value,u=o.finalizePacketDecoding(this._decoderPtr),u<0))return this._createError(u);n._populate(Tr(o,i,j,this._decoderPtr))}finally{l()}}finally{a()}return n}_createError(r){f(this._runtime);let{exports:n,memory:A}=this._runtime,o,i=n.getErrorMessagePtr(this._decoderPtr);if(i!==0){let j=n.getErrorMessageSize(this._decoderPtr);o=nr(new Uint8Array(A.buffer,i,j))}return tr(r,o)}},er=new FinalizationRegistry(t=>{t.unref()}),K=class extends y{constructor(r,n,A,o){super();s(this,"_runtime");s(this,"_decoderId");s(this,"_highWaterMark");s(this,"useSharedMemory",!1);s(this,"concurrency");this._highWaterMark=Math.max(n,1),this._runtime=r,this.concurrency=n,this._decoderId=r.nextDecoderId++,r.registerDecoder(this._decoderId,A,o),er.register(this,r,this)}_runClose(){f(this._runtime),this._runtime.unregisterDecoder(this._decoderId),er.unregister(this),this._runtime.unref(),this._runtime=null}_runDecode(r,n,A){f(this._runtime);let o=this._runtime,i=A.transfer?r:r.slice(),j=0;for(let l=1;l<o.workerLoad.length;l++)o.workerLoad[l]<o.workerLoad[j]&&(j=l);let B=o.workers[j];o.workerLoad[j]=o.workerLoad[j]+1;let a=o.nextRequestId++,c=n._buffer;return n._buffer=null,new Promise(l=>{B.postMessage({type:d.Decode,id:a,decoderId:this._decoderId,packet:i,frameBuffer:c},c?[i.buffer,c]:[i.buffer]);let u=Br=>{let p=Br.data;p.type!==d.Decoded&&p.type!==d.DecodeError||p.id===a&&(B.removeEventListener("message",u),o.workerLoad[j]--,p.type===d.DecodeError?l(tr(p.code,p.message)):(n._buffer=p.contents.frameData.buffer,n._populate(p.contents),l(n)))};B.addEventListener("message",u)})}};function S(t){if(!t)throw new Error("Assertion failed.")}var Or=Math.PI/180,_r=180/Math.PI;var Mr=1e6*(1+Number.EPSILON);var G=null,sr=()=>G!==null?G:G=!!(typeof navigator<"u"&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));var ar=Symbol.for("@mediabunny/prores loaded");globalThis[ar]&&h.Logging._error(`[WARNING]
915
+ @mediabunny/prores was loaded twice. This will likely cause the decoder not to work correctly. Check if multiple dependencies are importing different versions of @mediabunny/prores, or if something is being bundled incorrectly.`);globalThis[ar]=!0;var I=class I extends h.CustomVideoDecoder{constructor(){super(...arguments);this.decoder=null;this.framePool=[];this.lastDecodePromise=Promise.resolve()}static supports(r,n){return r==="prores"}static _determineSupportedVideoFrameFormats(){let r=[],n=new Uint8Array(32);for(let A of g)try{new VideoFrame(n,{format:A,codedWidth:2,codedHeight:2,timestamp:0,duration:0}).close(),r.push(A)}catch{}return r}async init(){typeof VideoFrame<"u"&&(I._supportedVideoFrameFormats??=I._determineSupportedVideoFrameFormats());let r=await y.create({proresFourCc:this.config.codec,useSharedMemory:y.canUseSharedMemory(),allowedOutputFormats:I._supportedVideoFrameFormats??void 0});if(r instanceof Error)throw r;this.decoder=r}async decode(r){for(S(this.decoder);this.decoder.desiredSize<=0;)await this.decoder.dequeued;this.lastDecodePromise=this.runDecode(r).catch(n=>this.onError(n))}async runDecode(r){S(this.decoder);let n;this.framePool.length>0?n=this.framePool.shift():n=new v;let A=await this.decoder.decode(r.data,n);if(this.framePool.push(n),A instanceof Error)throw A;A.visibleHeight<A.codedHeight&&sr()&&this.trimCodedHeightToVisibleHeight(A);let o=this.config.colorSpace,i={primaries:o?.primaries??A.colorPrimariesString,matrix:o?.matrix??A.colorMatrixString,transfer:o?.transfer??A.colorTransferString,fullRange:o?.fullRange??A.colorRangeFull},j=A.pixelAspectRatio;this.config.displayAspectWidth!==void 0&&this.config.displayAspectHeight!==void 0&&(j={num:this.config.displayAspectWidth*A.visibleHeight,den:this.config.displayAspectHeight*A.visibleWidth});let B=A.visibleWidth,a=A.visibleHeight;j.num>j.den?B=Math.round(A.visibleWidth*j.num/j.den):a=Math.round(A.visibleHeight*j.den/j.num);let c;if(typeof VideoFrame<"u"){let l=new VideoFrame(A.frameData,{format:A.pixelFormat,codedWidth:A.codedWidth,codedHeight:A.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{x:0,y:0,width:A.visibleWidth,height:A.visibleHeight},timestamp:r.microsecondTimestamp,duration:r.microsecondDuration,colorSpace:i});c=new h.VideoSample(l,{timestamp:r.timestamp,duration:r.duration})}else c=new h.VideoSample(A.frameData,{format:A.pixelFormat,codedWidth:A.codedWidth,codedHeight:A.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{left:0,top:0,width:A.visibleWidth,height:A.visibleHeight},timestamp:r.timestamp,duration:r.duration,colorSpace:i});this.onSample(c)}trimCodedHeightToVisibleHeight(r){let n=r.pixelFormat.includes("P")?2:1,A=r.pixelFormat.includes("444")?1:2,o=r.pixelFormat.includes("420")?2:1,i=r.codedWidth/A,j=r.codedHeight/o,B=Math.ceil(r.visibleHeight/o),a=r.codedWidth*r.codedHeight,c=r.codedWidth*r.visibleHeight,l=i*j,u=i*B;r.frameData.set(r.frameData.subarray(n*a,n*(a+l)),n*c),r.frameData.set(r.frameData.subarray(n*(a+l),n*(a+2*l)),n*(c+u)),r.pixelFormat.includes("A")&&r.frameData.set(r.frameData.subarray(n*(a+2*l),n*(2*a+2*l)),n*(c+2*u)),r.codedHeight=r.visibleHeight}async flush(){await this.lastDecodePromise}async close(){S(this.decoder),await this.decoder.close();for(let r of this.framePool)r.clear()}};I._supportedVideoFrameFormats=null;var V=I,jr=!1,Cr=()=>{jr||(jr=!0,(0,h.registerDecoder)(V))};return br(Fr);})();
916
916
  if (typeof module === "object" && typeof module.exports === "object") Object.assign(module.exports, MediabunnyProres)
@@ -5,7 +5,7 @@
5
5
  * License, v. 2.0. If a copy of the MPL was not distributed with this
6
6
  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
7
  */
8
- var or=Object.defineProperty;var ir=(t,e,r)=>e in t?or(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var i=(t,e,r)=>ir(t,typeof e!="symbol"?e+"":e,r);import{CustomVideoDecoder as mr,Logging as hr,registerDecoder as pr,VideoSample as er}from"mediabunny";var p=class extends Error{constructor(e="The decoder ran out of memory."){super(e),this.name="OutOfMemoryError"}},S=class extends Error{constructor(e="Invalid data: the packet ended before the decoder expected it to."){super(e),this.name="UnexpectedEofError"}},v=class extends Error{constructor(e="The packet contains invalid data."){super(e),this.name="InvalidDataError"}},w=class extends Error{constructor(e="The packet uses a feature that is not supported."){super(e),this.name="NotSupportedError"}},D=class extends Error{constructor(e="The decoder is in an invalid internal state. This should never happen! Please report."){super(e),this.name="InvalidStateError"}},O=class extends Error{constructor(e="The decoder has been closed."){super(e),this.name="DecoderClosedError"}},E=class extends Error{constructor(e="The frame is locked by an in-flight decoding operation."){super(e),this.name="FrameLockedError"}},X=(t,e)=>{switch(t){case-1:return new p(e);case-2:return new S(e);case-3:return new v(e);case-4:return new w(e);case-5:return new D(e);case-6:return new v(e??"Unexpected integer overflow.");default:throw new Error(`Unhandled error code: ${t}`)}};function f(t){if(!t)throw new Error("Assertion failed.")}var Y=t=>{let e=0,r="";for(;e<t.length;){let A=t[e++];if(A>127)if(A>191&&A<224){if(e>=t.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");A=(A&31)<<6|t[e++]&63}else if(A>223&&A<240){if(e+1>=t.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");A=(A&15)<<12|(t[e++]&63)<<6|t[e++]&63}else if(A>239&&A<248){if(e+2>=t.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");A=(A&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+A.toString(16)+" at index "+(e-1));if(A<=65535)r+=String.fromCharCode(A);else if(A<=1114111)A-=65536,r+=String.fromCharCode(A>>10|55296),r+=String.fromCharCode(A&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+A.toString(16)+" exceeds UTF-16 reach")}return r},b=class{constructor(){i(this,"currentPromise",Promise.resolve());i(this,"pending",0)}async acquire(){let e,r=new Promise(n=>{let o=!1;e=()=>{o||(n(),this.pending--,o=!0)}}),A=this.currentPromise;return this.currentPromise=r,this.pending++,await A,e}},G=typeof SharedArrayBuffer<"u",J=t=>t;Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");var h=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"],sr={1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020",12:"smpte432"},jr={1:"bt709",6:"smpte170m",8:"linear",13:"iec61966-2-1",16:"pq",18:"hlg"},ar={0:"rgb",1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020-ncl"},F=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeFrame(e)}),I=class{constructor(){i(this,"frameData",null);i(this,"codedWidth",null);i(this,"codedHeight",null);i(this,"visibleWidth",null);i(this,"visibleHeight",null);i(this,"pixelFormat",null);i(this,"originalPixelFormat",null);i(this,"pixelAspectRatio",null);i(this,"colorPrimaries",null);i(this,"colorTransfer",null);i(this,"colorMatrix",null);i(this,"colorRangeFull",null);i(this,"scanType",null);i(this,"_runtime",null);i(this,"_ptr",null);i(this,"_buffer",null);i(this,"_locked",!1)}get colorPrimariesString(){return this.colorPrimaries===null?void 0:sr[this.colorPrimaries]}get colorTransferString(){return this.colorTransfer===null?void 0:jr[this.colorTransfer]}get colorMatrixString(){return this.colorMatrix===null?void 0:ar[this.colorMatrix]}get isLocked(){return this._locked}get isFilled(){return this.frameData!==null&&this.codedWidth!==null&&this.codedHeight!==null&&this.visibleWidth!==null&&this.visibleHeight!==null&&this.pixelFormat!==null&&this.pixelAspectRatio!==null&&this.colorPrimaries!==null&&this.colorTransfer!==null&&this.colorMatrix!==null&&this.colorRangeFull!==null&&this.scanType!==null}toFilled(){return this.isFilled?this:null}clear(){if(this._locked)throw new E;this._ptr!==null&&(f(this._runtime),F.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null),this._buffer=null,this._reset()}[Symbol.dispose](){this.clear()}_ensureWasmFrame(e){if(this._runtime===e)return!0;this._runtime&&(F.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null);let r=e.exports.createFrame();return r===0?!1:(this._runtime=e,this._ptr=r,F.register(this,{runtime:e,ptr:r},this),!0)}_reset(){this.frameData=null,this.codedWidth=null,this.codedHeight=null,this.visibleWidth=null,this.visibleHeight=null,this.pixelFormat=null,this.pixelAspectRatio=null,this.colorPrimaries=null,this.colorTransfer=null,this.colorMatrix=null,this.colorRangeFull=null,this.scanType=null}_populate(e){this.frameData=e.frameData,this.codedWidth=e.codedWidth,this.codedHeight=e.codedHeight,this.visibleWidth=e.visibleWidth,this.visibleHeight=e.visibleHeight,this.pixelFormat=e.pixelFormat,this.originalPixelFormat=e.originalPixelFormat,this.pixelAspectRatio=e.pixelAspectRatio,this.colorPrimaries=e.colorPrimaries,this.colorTransfer=e.colorTransfer,this.colorMatrix=e.colorMatrix,this.colorRangeFull=e.colorRangeFull,this.scanType=e.scanType}},Br=(t,e,r,A)=>{let n=t.getFrameDataPtr(r),o=t.getFrameDataSize(r),s=new Uint8Array(e.buffer,n,o),j=h[t.getFramePixelFormat(r)];f(j!==void 0);let B=h[t.getOriginalPixelFormat(A)];f(B!==void 0);let a=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][t.getScanType(r)];return f(a!==void 0),{frameData:s,codedWidth:t.getCodedWidth(r),codedHeight:t.getCodedHeight(r),visibleWidth:t.getVisibleWidth(r),visibleHeight:t.getVisibleHeight(r),pixelFormat:j,originalPixelFormat:B,pixelAspectRatio:{num:t.getAspectRatioNum(r),den:t.getAspectRatioDen(r)},colorPrimaries:t.getColorPrimaries(r),colorTransfer:t.getColorTransfer(r),colorMatrix:t.getColorMatrix(r),colorRangeFull:!1,scanType:a}},u=(t=>(t[t.SharedMemoryInit=0]="SharedMemoryInit",t[t.MessagePassingInit=1]="MessagePassingInit",t[t.CreateDecoder=2]="CreateDecoder",t[t.CloseDecoder=3]="CloseDecoder",t[t.Decode=4]="Decode",t[t.Ready=5]="Ready",t[t.InitOutOfMemoryError=6]="InitOutOfMemoryError",t[t.Decoded=7]="Decoded",t[t.DecodeError=8]="DecodeError",t))(u||{}),q=`\0asm\0\0\0\x99\`\x7F\x7F\x7F\x7F\x7F\`\x7F\x7F\x7F\x7F\x7F\0\`\x7F\0\`\0\0\`\x7F\x7F\x7F\x7F\x7F\x7F\x7F\`
8
+ var sr=Object.defineProperty;var jr=(t,e,r)=>e in t?sr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var s=(t,e,r)=>jr(t,typeof e!="symbol"?e+"":e,r);import{CustomVideoDecoder as pr,Logging as gr,registerDecoder as br,VideoSample as nr}from"mediabunny";var g=class extends Error{constructor(e="The decoder ran out of memory."){super(e),this.name="OutOfMemoryError"}},D=class extends Error{constructor(e="Invalid data: the packet ended before the decoder expected it to."){super(e),this.name="UnexpectedEofError"}},v=class extends Error{constructor(e="The packet contains invalid data."){super(e),this.name="InvalidDataError"}},E=class extends Error{constructor(e="The packet uses a feature that is not supported."){super(e),this.name="NotSupportedError"}},R=class extends Error{constructor(e="The decoder is in an invalid internal state. This should never happen! Please report."){super(e),this.name="InvalidStateError"}},O=class extends Error{constructor(e="The decoder has been closed."){super(e),this.name="DecoderClosedError"}},k=class extends Error{constructor(e="The frame is locked by an in-flight decoding operation."){super(e),this.name="FrameLockedError"}},m=class extends Error{constructor(e="A worker failed to start."){super(e),this.name="WorkerStartError"}},Y=(t,e)=>{switch(t){case-1:return new g(e);case-2:return new D(e);case-3:return new v(e);case-4:return new E(e);case-5:return new R(e);case-6:return new v(e??"Unexpected integer overflow.");default:throw new Error(`Unhandled error code: ${t}`)}};function f(t){if(!t)throw new Error("Assertion failed.")}var J=t=>{let e=0,r="";for(;e<t.length;){let n=t[e++];if(n>127)if(n>191&&n<224){if(e>=t.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");n=(n&31)<<6|t[e++]&63}else if(n>223&&n<240){if(e+1>=t.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");n=(n&15)<<12|(t[e++]&63)<<6|t[e++]&63}else if(n>239&&n<248){if(e+2>=t.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");n=(n&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+n.toString(16)+" at index "+(e-1));if(n<=65535)r+=String.fromCharCode(n);else if(n<=1114111)n-=65536,r+=String.fromCharCode(n>>10|55296),r+=String.fromCharCode(n&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+n.toString(16)+" exceeds UTF-16 reach")}return r},y=class{constructor(){s(this,"currentPromise",Promise.resolve());s(this,"pending",0)}async acquire(){let e,r=new Promise(A=>{let o=!1;e=()=>{o||(A(),this.pending--,o=!0)}}),n=this.currentPromise;return this.currentPromise=r,this.pending++,await n,e}},G=typeof SharedArrayBuffer<"u",z=t=>t;Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");var p=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"],ar={1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020",12:"smpte432"},Br={1:"bt709",6:"smpte170m",8:"linear",13:"iec61966-2-1",16:"pq",18:"hlg"},lr={0:"rgb",1:"bt709",5:"bt470bg",6:"smpte170m",9:"bt2020-ncl"},q=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeFrame(e)}),T=class{constructor(){s(this,"frameData",null);s(this,"codedWidth",null);s(this,"codedHeight",null);s(this,"visibleWidth",null);s(this,"visibleHeight",null);s(this,"pixelFormat",null);s(this,"originalPixelFormat",null);s(this,"pixelAspectRatio",null);s(this,"colorPrimaries",null);s(this,"colorTransfer",null);s(this,"colorMatrix",null);s(this,"colorRangeFull",null);s(this,"scanType",null);s(this,"_runtime",null);s(this,"_ptr",null);s(this,"_buffer",null);s(this,"_locked",!1)}get colorPrimariesString(){return this.colorPrimaries===null?void 0:ar[this.colorPrimaries]}get colorTransferString(){return this.colorTransfer===null?void 0:Br[this.colorTransfer]}get colorMatrixString(){return this.colorMatrix===null?void 0:lr[this.colorMatrix]}get isLocked(){return this._locked}get isFilled(){return this.frameData!==null&&this.codedWidth!==null&&this.codedHeight!==null&&this.visibleWidth!==null&&this.visibleHeight!==null&&this.pixelFormat!==null&&this.pixelAspectRatio!==null&&this.colorPrimaries!==null&&this.colorTransfer!==null&&this.colorMatrix!==null&&this.colorRangeFull!==null&&this.scanType!==null}toFilled(){return this.isFilled?this:null}clear(){if(this._locked)throw new k;this._ptr!==null&&(f(this._runtime),q.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null),this._buffer=null,this._reset()}[Symbol.dispose](){this.clear()}_ensureWasmFrame(e){if(this._runtime===e)return!0;this._runtime&&(q.unregister(this),this._runtime.exports.closeFrame(this._ptr),this._runtime=null,this._ptr=null);let r=e.exports.createFrame();return r===0?!1:(this._runtime=e,this._ptr=r,q.register(this,{runtime:e,ptr:r},this),!0)}_reset(){this.frameData=null,this.codedWidth=null,this.codedHeight=null,this.visibleWidth=null,this.visibleHeight=null,this.pixelFormat=null,this.pixelAspectRatio=null,this.colorPrimaries=null,this.colorTransfer=null,this.colorMatrix=null,this.colorRangeFull=null,this.scanType=null}_populate(e){this.frameData=e.frameData,this.codedWidth=e.codedWidth,this.codedHeight=e.codedHeight,this.visibleWidth=e.visibleWidth,this.visibleHeight=e.visibleHeight,this.pixelFormat=e.pixelFormat,this.originalPixelFormat=e.originalPixelFormat,this.pixelAspectRatio=e.pixelAspectRatio,this.colorPrimaries=e.colorPrimaries,this.colorTransfer=e.colorTransfer,this.colorMatrix=e.colorMatrix,this.colorRangeFull=e.colorRangeFull,this.scanType=e.scanType}},cr=(t,e,r,n)=>{let A=t.getFrameDataPtr(r),o=t.getFrameDataSize(r),i=new Uint8Array(e.buffer,A,o),j=p[t.getFramePixelFormat(r)];f(j!==void 0);let B=p[t.getOriginalPixelFormat(n)];f(B!==void 0);let a=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][t.getScanType(r)];return f(a!==void 0),{frameData:i,codedWidth:t.getCodedWidth(r),codedHeight:t.getCodedHeight(r),visibleWidth:t.getVisibleWidth(r),visibleHeight:t.getVisibleHeight(r),pixelFormat:j,originalPixelFormat:B,pixelAspectRatio:{num:t.getAspectRatioNum(r),den:t.getAspectRatioDen(r)},colorPrimaries:t.getColorPrimaries(r),colorTransfer:t.getColorTransfer(r),colorMatrix:t.getColorMatrix(r),colorRangeFull:!1,scanType:a}},d=(t=>(t[t.SharedMemoryInit=0]="SharedMemoryInit",t[t.MessagePassingInit=1]="MessagePassingInit",t[t.CreateDecoder=2]="CreateDecoder",t[t.CloseDecoder=3]="CloseDecoder",t[t.Decode=4]="Decode",t[t.Ready=5]="Ready",t[t.InitOutOfMemoryError=6]="InitOutOfMemoryError",t[t.InitError=7]="InitError",t[t.Decoded=8]="Decoded",t[t.DecodeError=9]="DecodeError",t))(d||{}),S=`\0asm\0\0\0\x99\`\x7F\x7F\x7F\x7F\x7F\`\x7F\x7F\x7F\x7F\x7F\0\`\x7F\0\`\0\0\`\x7F\x7F\x7F\x7F\x7F\x7F\x7F\`
9
9
  \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\`\x7F\x7F\`\x7F\x7F\x7F\x7F{{{{{{{{{{{{{{{{\x7F\x7F\x7F\x7F\0\`\x7F\x7F\x7F\x7F{{{{{{{{{{{{{{{{\x7F\x7F\x7F\0\` \x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\0\`\x7F\x7F\0\`\x7F\x7F\x7F\x7F\`\x7F\x7F\x7F\x7F\0\`\x7F\x7F\x7F\`\x7F\x7F\x7F\0\`\0\x7Fenvmemory\x80\x80ML\x07\x07\b\b\b\b\b\b\b\b\b\b
10
10
  \0\v\f\v\r\0\r\v\v\v\r\r\f\f\v\vp \x7FA\x80\x80\xC0\0\v\x7FA\0\v\x7F\0A\x90\b\v\x7F\0A\v\x07\xE1!__stack_pointer\0
11
11
  __tls_base
@@ -908,8 +908,8 @@ lkA\bt rA\xB0\xE0\0r;\0\0 Aj!\v \0 Aj jA! k\xBD\x80\x80\x80\0! A0j$\x
908
908
  \0\0\0\xE0\xFF\xFF\xFF\f\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\0\0\0\xE0\xFF\xFF\xFF\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0\xFF\0\0\0\0\0\0\0Packet is smaller than the picture data size indicated in the picture header.\0Packet is smaller than the frame size indicated in the frame header.\0Invalid DC code stream.\0Invalid AC code stream.\0Picture header size too small.\0Frame header size too small.\0Slice header size too small.\0Frame size too small.\0Invalid packet header frame type.\0Invalid frame type.\0Invalid alpha info header field.\0Invalid aspect ratio information header field.\0Version > 1 is not supported.\0Slice widths larger than 128 are not supported.\0Only slice heights of 1 are supported.\0Picture header extends past the picture data.\0Slice data extends past the bounds of the picture data.\0Frame header extends past the frame data.\0Channel data planes too large to fit into slice data.\0\0\xA0\0\xA0\b\0\xA0\b\0\xA0\v\0\xA0\v\0\xA0\f\0\xA0\f\0\0\0\0\0\xA0\0\xA0\0\xA0\0\xA0\0\xA0\0\xA0 \0\xA0 \0\xA0 \0\xA0 \0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0
909
909
  \0\xA0\0\xA0\x07\0\xA0\0\xA0\0\xA0\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0\b\0\xA0
910
910
  \0\0\0\0\0\0\0\0\x90\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\b\0\0\0
911
- \0\0\0\f\0\0\0Frame dimensions (x) exceed the maximum supported size of 16384x16384.\0\0\0\0\0\0\0\0\x07\0\0\0\b\0\0\0Unexpected slice count: expected , found .\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0`,lr=async(t,e)=>{let{instance:r}=await WebAssembly.instantiate(t,{env:{memory:e,externPrint:(A,n)=>{let o=new Uint8Array(e.buffer,A,n);console.log(Y(o))}}});return r.exports},K=`"use strict";var I=(e=>(e[e.OutOfMemory=-1]="OutOfMemory",e[e.UnexpectedEof=-2]="UnexpectedEof",e[e.InvalidData=-3]="InvalidData",e[e.NotSupported=-4]="NotSupported",e[e.InvalidState=-5]="InvalidState",e[e.Overflow=-6]="Overflow",e))(I||{});function f(e){if(!e)throw new Error("Assertion failed.")}const O=e=>{let t=0,r="";for(;t<e.length;){let o=e[t++];if(o>127)if(o>191&&o<224){if(t>=e.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");o=(o&31)<<6|e[t++]&63}else if(o>223&&o<240){if(t+1>=e.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");o=(o&15)<<12|(e[t++]&63)<<6|e[t++]&63}else if(o>239&&o<248){if(t+2>=e.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");o=(o&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+o.toString(16)+" at index "+(t-1));if(o<=65535)r+=String.fromCharCode(o);else if(o<=1114111)o-=65536,r+=String.fromCharCode(o>>10|55296),r+=String.fromCharCode(o&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+o.toString(16)+" exceeds UTF-16 reach")}return r};Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");const S=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"];new FinalizationRegistry(({runtime:e,ptr:t})=>{e.exports.closeFrame(t)});const _=(e,t,r,o)=>{const i=e.getFrameDataPtr(r),a=e.getFrameDataSize(r),w=new Uint8Array(t.buffer,i,a),u=S[e.getFramePixelFormat(r)];f(u!==void 0);const l=S[e.getOriginalPixelFormat(o)];f(l!==void 0);const c=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][e.getScanType(r)];return f(c!==void 0),{frameData:w,codedWidth:e.getCodedWidth(r),codedHeight:e.getCodedHeight(r),visibleWidth:e.getVisibleWidth(r),visibleHeight:e.getVisibleHeight(r),pixelFormat:u,originalPixelFormat:l,pixelAspectRatio:{num:e.getAspectRatioNum(r),den:e.getAspectRatioDen(r)},colorPrimaries:e.getColorPrimaries(r),colorTransfer:e.getColorTransfer(r),colorMatrix:e.getColorMatrix(r),colorRangeFull:!1,scanType:c}};var n=(e=>(e[e.SharedMemoryInit=0]="SharedMemoryInit",e[e.MessagePassingInit=1]="MessagePassingInit",e[e.CreateDecoder=2]="CreateDecoder",e[e.CloseDecoder=3]="CloseDecoder",e[e.Decode=4]="Decode",e[e.Ready=5]="Ready",e[e.InitOutOfMemoryError=6]="InitOutOfMemoryError",e[e.Decoded=7]="Decoded",e[e.DecodeError=8]="DecodeError",e))(n||{});const A=async(e,t)=>{const{instance:r}=await WebAssembly.instantiate(e,{env:{memory:t,externPrint:(o,i)=>{const a=new Uint8Array(t.buffer,o,i);console.log(O(a))}}});return r.exports};let s=null;const F=async e=>{switch(e.type){case n.SharedMemoryInit:{const t=await A(e.wasmBinary,e.memory);throw t.__stack_pointer.value=e.stackPointer,t.__wasm_init_tls(e.tlsPointer),t.setIsBrowserMainThread(0),t.startWorker(),new Error("Unexpected worker termination.")}case n.MessagePassingInit:{const t=new WebAssembly.Memory({initial:32,maximum:8192,shared:!0}),r=await A(e.wasmBinary,t),o=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(o===0){d({type:n.InitOutOfMemoryError,message:"Failed to allocate thread-local state."});return}r.__wasm_init_tls(o),r.setIsBrowserMainThread(0);const i=r.createFrame();if(i===0){d({type:n.InitOutOfMemoryError,message:"Failed to create frame."});return}s={exports:r,memory:t,decoders:new Map,frame:i},d({type:n.Ready});return}case n.CreateDecoder:{f(s);const{exports:t}=s,{decoderId:r,bitDepth:o,allowedOutputFormats:i}=e,a=t.createDecoder(0,o,i);if(a===0)return;s.decoders.set(r,a);return}case n.CloseDecoder:{f(s);const{exports:t,decoders:r}=s,o=r.get(e.decoderId);o!==void 0&&(t.closeDecoder(o),r.delete(e.decoderId));return}case n.Decode:{f(s);const{exports:t,memory:r,decoders:o,frame:i}=s,{id:a,decoderId:w,packet:u,frameBuffer:l}=e,c=o.get(w);if(c===void 0){d({type:n.DecodeError,id:a,code:I.OutOfMemory});return}const g=t.allocatePacket(c,u.byteLength,0);if(g===0){d({type:n.DecodeError,id:a,code:I.OutOfMemory});return}new Uint8Array(r.buffer).set(u,g);const D=t.decodePacket(c,i,0);if(D<0){let v;const P=t.getErrorMessagePtr(c);if(P!==0){const b=t.getErrorMessageSize(c);v=O(new Uint8Array(r.buffer,P,b))}d({type:n.DecodeError,id:a,code:D,message:v});return}const m=_(t,r,i,c),y=l&&l.byteLength===m.frameData.byteLength?l:new ArrayBuffer(m.frameData.byteLength),p=new Uint8Array(y);p.set(m.frameData),m.frameData=p,d({type:n.Decoded,id:a,contents:m},[y]);return}}},d=(e,t)=>{h?h.postMessage(e,t??[]):self.postMessage(e,{transfer:t??[]})};let h=null;try{h=require("node:worker_threads").parentPort}catch{}h?h.on("message",F):self.addEventListener("message",e=>void F(e.data));
912
- `,x=null,R=()=>{if(x)return x;x=new Uint8Array(q.length);for(let t=0;t<q.length;t++)x[t]=q.charCodeAt(t);return x},z=async()=>{if(typeof Worker<"u"&&!("Bun"in globalThis)){let e=new Blob([K],{type:"text/javascript"}),r=URL.createObjectURL(e),A=new Worker(r,{type:"module"});return new P(A,null)}let t=await import("node:"+J("worker_threads"));return new P(null,new t.Worker(K,{eval:!0}))},P=class{constructor(e,r){i(this,"wrappedListeners",new Map);this.webWorker=e,this.nodeWorker=r}postMessage(e,r){this.webWorker?this.webWorker.postMessage(e,{transfer:r??[]}):this.nodeWorker.postMessage(e,r??[])}addEventListener(e,r,A){if(this.webWorker)this.webWorker.addEventListener(e,r,A);else{let n=o=>r({data:o});this.wrappedListeners.set(r,n),A?.once?this.nodeWorker.once(e,n):this.nodeWorker.on(e,n)}}removeEventListener(e,r){this.webWorker?this.webWorker.removeEventListener(e,r):(this.nodeWorker.off(e,this.wrappedListeners.get(r)),this.wrappedListeners.delete(r))}terminate(){this.webWorker?this.webWorker.terminate():this.nodeWorker.terminate()}},V=new FinalizationRegistry(t=>{for(let e of t)e.terminate()}),cr=async()=>{if(typeof navigator<"u"&&navigator.hardwareConcurrency)return navigator.hardwareConcurrency;let t=await import("node:"+J("os"));return t.availableParallelism?.()??t.cpus().length},T=null,dr=new b,ur=async()=>{let t=await dr.acquire();try{if(T){let r=T.deref();if(r)return r}let e=await M.init();return T=new WeakRef(e),e}finally{t()}},_=null,fr=()=>{let t=_?.deref();return t||(t=new $,_=new WeakRef(t)),t},k=class{constructor(){i(this,"workers",[]);i(this,"refCount",0);V.register(this,this.workers,this)}ref(){this.refCount++}unref(){this.refCount--,!(typeof window<"u"&&typeof document<"u")&&this.refCount===0&&this.destroy()}destroy(){for(let e of this.workers)e.terminate();this.workers.length=0,V.unregister(this)}},M=class t extends k{constructor(e,r){super(),this.memory=e,this.exports=r}static async init(){let e=new WebAssembly.Memory({initial:32,maximum:65536,shared:!0}),r=await lr(R(),e),A=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(A===0)throw new Error("Failed to allocate thread-local state.");r.__wasm_init_tls(A);let n=typeof window<"u"&&typeof document<"u"&&self===window;return r.setIsBrowserMainThread(Number(n)),new t(e,r)}async ensureWorkers(e){for(;this.workers.length<e;){let r=this.exports.allocateWorkerStack(),A=this.exports.allocateThreadLocalState(this.exports.__tls_size.value,this.exports.__tls_align.value);if(r===0||A===0)throw new Error("Failed to allocate worker stack or thread-local state.");let n=await z();n.postMessage({type:u.SharedMemoryInit,wasmBinary:R(),memory:this.memory,stackPointer:r,tlsPointer:A}),this.workers.push(n)}}destroy(){super.destroy(),T=null}},$=class extends k{constructor(){super(...arguments);i(this,"workerLoad",[]);i(this,"nextRequestId",0);i(this,"nextDecoderId",0);i(this,"registeredDecoders",new Map)}registerDecoder(r,A,n){this.registeredDecoders.set(r,{bitDepth:A,allowedOutputFormats:n});for(let o of this.workers)o.postMessage({type:u.CreateDecoder,decoderId:r,bitDepth:A,allowedOutputFormats:n})}unregisterDecoder(r){this.registeredDecoders.delete(r);for(let A of this.workers)A.postMessage({type:u.CloseDecoder,decoderId:r})}async ensureWorkers(r){let A=r-this.workers.length;if(A<=0)return;let n=await Promise.all(Array.from({length:A},async()=>{let s=await z(),j=await new Promise(B=>{s.postMessage({type:u.MessagePassingInit,wasmBinary:R()}),s.addEventListener("message",a=>B(a.data),{once:!0})});return j.type===u.InitOutOfMemoryError?(s.terminate(),new p(j.message)):s})),o=n.find(s=>s instanceof Error);if(o){for(let s of n)s instanceof Error||s.terminate();return o}for(let s of n){this.workers.push(s),this.workerLoad.push(0);for(let[j,{bitDepth:B,allowedOutputFormats:a}]of this.registeredDecoders)s.postMessage({type:u.CreateDecoder,decoderId:j,bitDepth:B,allowedOutputFormats:a})}}destroy(){super.destroy(),_=null}},Q=["ap4x","ap4h","apch","apcn","apcs","apco"],g=class{constructor(){i(this,"_closed",!1);i(this,"_queue",Promise.resolve());i(this,"_decodeQueueSize",0);i(this,"_dequeuedResolve");i(this,"_dequeued",new Promise(e=>{this._dequeuedResolve=e}))}get decodeQueueSize(){return this._decodeQueueSize}get desiredSize(){return this._highWaterMark-this._decodeQueueSize}get dequeued(){return this._dequeued}_markDequeued(){this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(e=>{this._dequeuedResolve=e})}static async create(e){if(typeof e!="object"||!e)throw new TypeError("options must be an object.");if(!Q.includes(e.proresFourCc))throw new TypeError(`options.proresFourCc must be one of ${Q.join(", ")}.`);if(typeof e.useSharedMemory!="boolean")throw new TypeError("options.useSharedMemory must be a boolean.");if(e.concurrency!==void 0&&(!Number.isInteger(e.concurrency)||e.concurrency<0))throw new TypeError("options.concurrency, when provided, must be a non-negative integer.");if(e.allowedOutputFormats&&!(Array.isArray(e.allowedOutputFormats)&&e.allowedOutputFormats.length>0&&e.allowedOutputFormats.every(o=>h.includes(o))))throw new TypeError(`options.allowedOutputFormats, when provided, must be a non-empty array containing any of: ${h.join(", ")}.`);if(e.useSharedMemory&&!G)return new w(`Shared memory is not available in this environment, so useSharedMemory: true cannot be used.
911
+ \0\0\0\f\0\0\0Frame dimensions (x) exceed the maximum supported size of 16384x16384.\0\0\0\0\0\0\0\0\x07\0\0\0\b\0\0\0Unexpected slice count: expected , found .\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0`,dr=async(t,e)=>{let{instance:r}=await WebAssembly.instantiate(t,{env:{memory:e,externPrint:(n,A)=>{let o=new Uint8Array(e.buffer,n,A);console.log(J(o))}}});return r.exports},V=`"use strict";var w=(e=>(e[e.OutOfMemory=-1]="OutOfMemory",e[e.UnexpectedEof=-2]="UnexpectedEof",e[e.InvalidData=-3]="InvalidData",e[e.NotSupported=-4]="NotSupported",e[e.InvalidState=-5]="InvalidState",e[e.Overflow=-6]="Overflow",e))(w||{});function f(e){if(!e)throw new Error("Assertion failed.")}const O=e=>{let t=0,r="";for(;t<e.length;){let o=e[t++];if(o>127)if(o>191&&o<224){if(t>=e.length)throw new Error("UTF-8 decode: incomplete 2-byte sequence");o=(o&31)<<6|e[t++]&63}else if(o>223&&o<240){if(t+1>=e.length)throw new Error("UTF-8 decode: incomplete 3-byte sequence");o=(o&15)<<12|(e[t++]&63)<<6|e[t++]&63}else if(o>239&&o<248){if(t+2>=e.length)throw new Error("UTF-8 decode: incomplete 4-byte sequence");o=(o&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63}else throw new Error("UTF-8 decode: unknown multibyte start 0x"+o.toString(16)+" at index "+(t-1));if(o<=65535)r+=String.fromCharCode(o);else if(o<=1114111)o-=65536,r+=String.fromCharCode(o>>10|55296),r+=String.fromCharCode(o&1023|56320);else throw new Error("UTF-8 decode: code point 0x"+o.toString(16)+" exceeds UTF-16 reach")}return r};Symbol.dispose??=Symbol("dispose");Symbol.asyncDispose??=Symbol("asyncDispose");const v=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12"];new FinalizationRegistry(({runtime:e,ptr:t})=>{e.exports.closeFrame(t)});const _=(e,t,r,o)=>{const i=e.getFrameDataPtr(r),a=e.getFrameDataSize(r),I=new Uint8Array(t.buffer,i,a),m=v[e.getFramePixelFormat(r)];f(m!==void 0);const l=v[e.getOriginalPixelFormat(o)];f(l!==void 0);const c=["progressive","interlaced-top-field-first","interlaced-bottom-field-first"][e.getScanType(r)];return f(c!==void 0),{frameData:I,codedWidth:e.getCodedWidth(r),codedHeight:e.getCodedHeight(r),visibleWidth:e.getVisibleWidth(r),visibleHeight:e.getVisibleHeight(r),pixelFormat:m,originalPixelFormat:l,pixelAspectRatio:{num:e.getAspectRatioNum(r),den:e.getAspectRatioDen(r)},colorPrimaries:e.getColorPrimaries(r),colorTransfer:e.getColorTransfer(r),colorMatrix:e.getColorMatrix(r),colorRangeFull:!1,scanType:c}};var n=(e=>(e[e.SharedMemoryInit=0]="SharedMemoryInit",e[e.MessagePassingInit=1]="MessagePassingInit",e[e.CreateDecoder=2]="CreateDecoder",e[e.CloseDecoder=3]="CloseDecoder",e[e.Decode=4]="Decode",e[e.Ready=5]="Ready",e[e.InitOutOfMemoryError=6]="InitOutOfMemoryError",e[e.InitError=7]="InitError",e[e.Decoded=8]="Decoded",e[e.DecodeError=9]="DecodeError",e))(n||{});const U=async(e,t)=>{const{instance:r}=await WebAssembly.instantiate(e,{env:{memory:t,externPrint:(o,i)=>{const a=new Uint8Array(t.buffer,o,i);console.log(O(a))}}});return r.exports};let d=null;const F=async e=>{switch(e.type){case n.SharedMemoryInit:{const t=await A(e.wasmBinary,e.memory);if(!t)return;throw t.__stack_pointer.value=e.stackPointer,t.__wasm_init_tls(e.tlsPointer),t.setIsBrowserMainThread(0),s({type:n.Ready}),t.startWorker(),new Error("Unexpected worker termination.")}case n.MessagePassingInit:{const t=new WebAssembly.Memory({initial:32,maximum:8192,shared:!0}),r=await A(e.wasmBinary,t);if(!r)return;const o=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(o===0){s({type:n.InitOutOfMemoryError,message:"Failed to allocate thread-local state."});return}r.__wasm_init_tls(o),r.setIsBrowserMainThread(0);const i=r.createFrame();if(i===0){s({type:n.InitOutOfMemoryError,message:"Failed to create frame."});return}d={exports:r,memory:t,decoders:new Map,frame:i},s({type:n.Ready});return}case n.CreateDecoder:{f(d);const{exports:t}=d,{decoderId:r,bitDepth:o,allowedOutputFormats:i}=e,a=t.createDecoder(0,o,i);if(a===0)return;d.decoders.set(r,a);return}case n.CloseDecoder:{f(d);const{exports:t,decoders:r}=d,o=r.get(e.decoderId);o!==void 0&&(t.closeDecoder(o),r.delete(e.decoderId));return}case n.Decode:{f(d);const{exports:t,memory:r,decoders:o,frame:i}=d,{id:a,decoderId:I,packet:m,frameBuffer:l}=e,c=o.get(I);if(c===void 0){s({type:n.DecodeError,id:a,code:w.OutOfMemory});return}const g=t.allocatePacket(c,m.byteLength,0);if(g===0){s({type:n.DecodeError,id:a,code:w.OutOfMemory});return}new Uint8Array(r.buffer).set(m,g);const D=t.decodePacket(c,i,0);if(D<0){let S;const P=t.getErrorMessagePtr(c);if(P!==0){const b=t.getErrorMessageSize(c);S=O(new Uint8Array(r.buffer,P,b))}s({type:n.DecodeError,id:a,code:D,message:S});return}const h=_(t,r,i,c),y=l&&l.byteLength===h.frameData.byteLength?l:new ArrayBuffer(h.frameData.byteLength),p=new Uint8Array(y);p.set(h.frameData),h.frameData=p,s({type:n.Decoded,id:a,contents:h},[y]);return}}},A=async(e,t)=>{try{return await U(e,t)}catch(r){return s({type:n.InitError,message:String(r)}),null}},s=(e,t)=>{u?u.postMessage(e,t??[]):self.postMessage(e,{transfer:t??[]})};let u=null;try{u=require("node:worker_threads").parentPort}catch{"WorkerGlobalScope"in globalThis||(u=process.getBuiltinModule("node:worker_threads").parentPort)}u?u.on("message",F):self.addEventListener("message",e=>void F(e.data));
912
+ `,I=null,_=()=>{if(I)return I;I=new Uint8Array(S.length);for(let t=0;t<S.length;t++)I[t]=S.charCodeAt(t);return I},rr=async()=>{let t=globalThis[Symbol.for("turbores:workerUrl")];if(t!==void 0&&typeof t!="string"&&!(t instanceof URL))throw new TypeError("globalThis[Symbol.for('turbores:workerUrl')], when provided, must be a string or URL.");if(typeof Worker<"u"&&!("Bun"in globalThis)){let r=t;if(r===void 0){let n=new Blob([V],{type:"text/javascript"});r=URL.createObjectURL(n)}try{return new P(new Worker(r,{type:"module"}),null)}catch(n){return new m(`A worker failed to start: ${String(n)}`)}}let e=await import("node:"+z("worker_threads"));try{return new P(null,t!==void 0?new e.Worker(t):new e.Worker(V,{eval:!0}))}catch(r){return new m(`A worker failed to start: ${String(r)}`)}},P=class{constructor(e,r){s(this,"wrappedListeners",new Map);this.webWorker=e,this.nodeWorker=r}postMessage(e,r){this.webWorker?this.webWorker.postMessage(e,{transfer:r??[]}):this.nodeWorker.postMessage(e,r??[])}addEventListener(e,r,n){if(this.webWorker)this.webWorker.addEventListener(e,r,n);else{let A=o=>r({data:o});this.wrappedListeners.set(r,A),n?.once?this.nodeWorker.once(e,A):this.nodeWorker.on(e,A)}}onError(e){this.webWorker?this.webWorker.addEventListener("error",r=>e(r.message)):this.nodeWorker.on("error",r=>e(r.message))}removeEventListener(e,r){this.webWorker?this.webWorker.removeEventListener(e,r):(this.nodeWorker.off(e,this.wrappedListeners.get(r)),this.wrappedListeners.delete(r))}terminate(){this.webWorker?this.webWorker.terminate():this.nodeWorker.terminate()}},Q=new FinalizationRegistry(t=>{for(let e of t)e.terminate()}),ur=async()=>{if(typeof navigator<"u"&&navigator.hardwareConcurrency)return navigator.hardwareConcurrency;let t=await import("node:"+z("os"));return t.availableParallelism?.()??t.cpus().length},w=null,fr=new y,mr=async()=>{let t=await fr.acquire();try{if(w){let r=w.deref();if(r)return r}let e=await $.init();return w=new WeakRef(e),e}finally{t()}},M=null,hr=()=>{let t=M?.deref();return t||(t=new U,M=new WeakRef(t)),t},C=class{constructor(){s(this,"workers",[]);s(this,"refCount",0);Q.register(this,this.workers,this)}ref(){this.refCount++}unref(){this.refCount--,!(typeof window<"u"&&typeof document<"u")&&this.refCount===0&&this.destroy()}destroy(){for(let e of this.workers)e.terminate();this.workers.length=0,Q.unregister(this)}},$=class t extends C{constructor(e,r){super(),this.memory=e,this.exports=r}static async init(){let e=new WebAssembly.Memory({initial:32,maximum:65536,shared:!0}),r=await dr(_(),e),n=r.allocateThreadLocalState(r.__tls_size.value,r.__tls_align.value);if(n===0)throw new Error("Failed to allocate thread-local state.");r.__wasm_init_tls(n);let A=typeof window<"u"&&typeof document<"u"&&self===window;return r.setIsBrowserMainThread(Number(A)),new t(e,r)}async ensureWorkers(e){let r=[],n=null;for(;this.workers.length+r.length<e;){let A=this.exports.allocateWorkerStack(),o=this.exports.allocateThreadLocalState(this.exports.__tls_size.value,this.exports.__tls_align.value);if(A===0||o===0)throw new Error("Failed to allocate worker stack or thread-local state.");let i=await rr();if(i instanceof m){n=i;break}i.postMessage({type:d.SharedMemoryInit,wasmBinary:_(),memory:this.memory,stackPointer:A,tlsPointer:o}),r.push({worker:i,reply:er(i)})}for(let{worker:A,reply:o}of r){let i=await o;i instanceof m?(A.terminate(),n=i):(f(i.type===d.Ready),this.workers.push(A))}return n}destroy(){super.destroy(),w=null}},U=class extends C{constructor(){super(...arguments);s(this,"workerLoad",[]);s(this,"nextRequestId",0);s(this,"nextDecoderId",0);s(this,"registeredDecoders",new Map)}registerDecoder(r,n,A){this.registeredDecoders.set(r,{bitDepth:n,allowedOutputFormats:A});for(let o of this.workers)o.postMessage({type:d.CreateDecoder,decoderId:r,bitDepth:n,allowedOutputFormats:A})}unregisterDecoder(r){this.registeredDecoders.delete(r);for(let n of this.workers)n.postMessage({type:d.CloseDecoder,decoderId:r})}async ensureWorkers(r){let n=r-this.workers.length;if(n<=0)return;let A=await Promise.all(Array.from({length:n},async()=>{let i=await rr();if(i instanceof m)return i;i.postMessage({type:d.MessagePassingInit,wasmBinary:_()});let j=await er(i);return j instanceof m?(i.terminate(),j):j.type===d.InitOutOfMemoryError?(i.terminate(),new g(j.message)):i})),o=A.find(i=>i instanceof Error);if(o){for(let i of A)i instanceof Error||i.terminate();return o}for(let i of A){this.workers.push(i),this.workerLoad.push(0);for(let[j,{bitDepth:B,allowedOutputFormats:a}]of this.registeredDecoders)i.postMessage({type:d.CreateDecoder,decoderId:j,bitDepth:B,allowedOutputFormats:a})}}destroy(){super.destroy(),M=null}},er=t=>new Promise(e=>{t.addEventListener("message",r=>{let n=r.data;n.type===d.InitError?e(new m(`A worker failed to start: ${n.message}`)):e(n)},{once:!0}),t.onError(r=>{e(new m(r?`A worker failed to start: ${r}`:void 0))})}),L=["ap4x","ap4h","apch","apcn","apcs","apco"],b=class{constructor(){s(this,"_closed",!1);s(this,"_queue",Promise.resolve());s(this,"_decodeQueueSize",0);s(this,"_dequeuedResolve");s(this,"_dequeued",new Promise(e=>{this._dequeuedResolve=e}))}get decodeQueueSize(){return this._decodeQueueSize}get desiredSize(){return this._highWaterMark-this._decodeQueueSize}get dequeued(){return this._dequeued}_markDequeued(){this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(e=>{this._dequeuedResolve=e})}static async create(e){if(typeof e!="object"||!e)throw new TypeError("options must be an object.");if(!L.includes(e.proresFourCc))throw new TypeError(`options.proresFourCc must be one of ${L.join(", ")}.`);if(typeof e.useSharedMemory!="boolean")throw new TypeError("options.useSharedMemory must be a boolean.");if(e.concurrency!==void 0&&(!Number.isInteger(e.concurrency)||e.concurrency<0))throw new TypeError("options.concurrency, when provided, must be a non-negative integer.");if(e.allowedOutputFormats&&!(Array.isArray(e.allowedOutputFormats)&&e.allowedOutputFormats.length>0&&e.allowedOutputFormats.every(o=>p.includes(o))))throw new TypeError(`options.allowedOutputFormats, when provided, must be a non-empty array containing any of: ${p.join(", ")}.`);if(e.useSharedMemory&&!G)return new E(`Shared memory is not available in this environment, so useSharedMemory: true cannot be used.
913
913
  Since it provides way better performance, you should enable it by serving the page cross-origin isolated by setting the Cross-Origin-Opener-Policy header to 'same-origin' and the Cross-Origin-Embedder-Policy header to 'credentialless' or 'require-corp' (only the latter is supported by Safari).
914
- Otherwise, pass useSharedMemory: false to use a slower, worker-based fallback.`);let r;if(e.allowedOutputFormats){r=0;for(let o of e.allowedOutputFormats)r|=1<<h.indexOf(o)}else r=4294967295;let A=e.proresFourCc==="ap4h"||e.proresFourCc==="ap4x"?12:10,n=e.concurrency??await cr();if(e.useSharedMemory||n===0){let o=await ur();o.ref(),await o.ensureWorkers(n);let s=o.exports.createDecoder(n,A,r);return s===0?(o.unref(),new p):new U(o,s,n)}else{let o=fr();o.ref();let s=await o.ensureWorkers(n);return s?(o.unref(),s):new N(o,n,A,r)}}static canUseSharedMemory(){return G}async decode(e,r,A={}){if(!(e instanceof Uint8Array))throw new TypeError("packetData must be a Uint8Array.");if(!(r instanceof I))throw new TypeError("frame must be a Frame.");if(typeof A!="object"||!A)throw new TypeError("options must be an object.");if(A.transfer!==void 0&&typeof A.transfer!="boolean")throw new TypeError("options.transfer, when provided, must be a boolean.");if(this._closed)return new O;if(r._locked)return new E;r._reset(),r._locked=!0,this._decodeQueueSize++;let n=this._runDecode(e,r,A);n.catch(()=>{});let o=this._queue.then(()=>n).finally(()=>{r._locked=!1,queueMicrotask(()=>{this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(s=>{this._dequeuedResolve=s})})});return this._queue=o.catch(()=>{}),o}close(){if(this._closed)return this._queue;this._closed=!0;let e=this._queue.then(()=>this._runClose());return this._queue=e.catch(()=>{}),e}get isClosed(){return this._closed}[Symbol.dispose](){this.close()}[Symbol.asyncDispose](){return this.close()}},L=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeDecoder(e),t.unref()}),U=class extends g{constructor(r,A,n){super();i(this,"_runtime");i(this,"_decoderPtr");i(this,"_taskStateOffset");i(this,"_decodeMutex",new b);i(this,"_nextPacketSlot",0);i(this,"_packetSlotMutexes",[new b,new b]);i(this,"_highWaterMark");i(this,"useSharedMemory",!0);i(this,"concurrency");this._highWaterMark=n===0?1:2,this._runtime=r,this._decoderPtr=A,this._taskStateOffset=r.exports.getTaskStateAddress(A)/4,this.concurrency=n,L.register(this,{runtime:r,ptr:A},this)}_runClose(){f(this._runtime),L.unregister(this),this._runtime.exports.closeDecoder(this._decoderPtr),this._runtime.unref(),this._runtime=null}async _runDecode(r,A,n){f(this._runtime);let{exports:o,memory:s}=this._runtime;if(!A._ensureWasmFrame(this._runtime))return new p;let j=A._ptr;n.transfer&&(r=structuredClone(r,{transfer:[r.buffer]}));let B=this._nextPacketSlot;this._nextPacketSlot=this._nextPacketSlot+1&1;let a=await this._packetSlotMutexes[B].acquire();try{let c=o.allocatePacket(this._decoderPtr,r.byteLength,B);if(c===0)return new p;new Uint8Array(s.buffer).set(r,c);let l=await this._decodeMutex.acquire();try{let d=o.decodePacket(this._decoderPtr,j,B);if(d<0)return this._createError(d);if(this.concurrency>0&&(await Atomics.waitAsync(new Int32Array(s.buffer),this._taskStateOffset,1).value,d=o.finalizePacketDecoding(this._decoderPtr),d<0))return this._createError(d);A._populate(Br(o,s,j,this._decoderPtr))}finally{l()}}finally{a()}return A}_createError(r){f(this._runtime);let{exports:A,memory:n}=this._runtime,o,s=A.getErrorMessagePtr(this._decoderPtr);if(s!==0){let j=A.getErrorMessageSize(this._decoderPtr);o=Y(new Uint8Array(n.buffer,s,j))}return X(r,o)}},Z=new FinalizationRegistry(t=>{t.unref()}),N=class extends g{constructor(r,A,n,o){super();i(this,"_runtime");i(this,"_decoderId");i(this,"_highWaterMark");i(this,"useSharedMemory",!1);i(this,"concurrency");this._highWaterMark=Math.max(A,1),this._runtime=r,this.concurrency=A,this._decoderId=r.nextDecoderId++,r.registerDecoder(this._decoderId,n,o),Z.register(this,r,this)}_runClose(){f(this._runtime),this._runtime.unregisterDecoder(this._decoderId),Z.unregister(this),this._runtime.unref(),this._runtime=null}_runDecode(r,A,n){f(this._runtime);let o=this._runtime,s=n.transfer?r:r.slice(),j=0;for(let l=1;l<o.workerLoad.length;l++)o.workerLoad[l]<o.workerLoad[j]&&(j=l);let B=o.workers[j];o.workerLoad[j]=o.workerLoad[j]+1;let a=o.nextRequestId++,c=A._buffer;return A._buffer=null,new Promise(l=>{B.postMessage({type:u.Decode,id:a,decoderId:this._decoderId,packet:s,frameBuffer:c},c?[s.buffer,c]:[s.buffer]);let d=nr=>{let m=nr.data;m.type!==u.Decoded&&m.type!==u.DecodeError||m.id===a&&(B.removeEventListener("message",d),o.workerLoad[j]--,m.type===u.DecodeError?l(X(m.code,m.message)):(A._buffer=m.contents.frameData.buffer,A._populate(m.contents),l(A)))};B.addEventListener("message",d)})}};function C(t){if(!t)throw new Error("Assertion failed.")}var xr=Math.PI/180,Ir=180/Math.PI;var Tr=1e6*(1+Number.EPSILON);var W=null,rr=()=>W!==null?W:W=!!(typeof navigator<"u"&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));var Ar=Symbol.for("@mediabunny/prores loaded");globalThis[Ar]&&hr._error(`[WARNING]
915
- @mediabunny/prores was loaded twice. This will likely cause the decoder not to work correctly. Check if multiple dependencies are importing different versions of @mediabunny/prores, or if something is being bundled incorrectly.`);globalThis[Ar]=!0;var y=class y extends mr{constructor(){super(...arguments);this.decoder=null;this.framePool=[];this.lastDecodePromise=Promise.resolve()}static supports(r,A){return r==="prores"}static _determineSupportedVideoFrameFormats(){let r=[],A=new Uint8Array(32);for(let n of h)try{new VideoFrame(A,{format:n,codedWidth:2,codedHeight:2,timestamp:0,duration:0}).close(),r.push(n)}catch{}return r}async init(){typeof VideoFrame<"u"&&(y._supportedVideoFrameFormats??=y._determineSupportedVideoFrameFormats());let r=await g.create({proresFourCc:this.config.codec,useSharedMemory:g.canUseSharedMemory(),allowedOutputFormats:y._supportedVideoFrameFormats??void 0});if(r instanceof Error)throw r;this.decoder=r}async decode(r){for(C(this.decoder);this.decoder.desiredSize<=0;)await this.decoder.dequeued;this.lastDecodePromise=this.runDecode(r).catch(A=>this.onError(A))}async runDecode(r){C(this.decoder);let A;this.framePool.length>0?A=this.framePool.shift():A=new I;let n=await this.decoder.decode(r.data,A);if(this.framePool.push(A),n instanceof Error)throw n;n.visibleHeight<n.codedHeight&&rr()&&this.trimCodedHeightToVisibleHeight(n);let o=this.config.colorSpace,s={primaries:o?.primaries??n.colorPrimariesString,matrix:o?.matrix??n.colorMatrixString,transfer:o?.transfer??n.colorTransferString,fullRange:o?.fullRange??n.colorRangeFull},j=n.pixelAspectRatio;this.config.displayAspectWidth!==void 0&&this.config.displayAspectHeight!==void 0&&(j={num:this.config.displayAspectWidth*n.visibleHeight,den:this.config.displayAspectHeight*n.visibleWidth});let B=n.visibleWidth,a=n.visibleHeight;j.num>j.den?B=Math.round(n.visibleWidth*j.num/j.den):a=Math.round(n.visibleHeight*j.den/j.num);let c;if(typeof VideoFrame<"u"){let l=new VideoFrame(n.frameData,{format:n.pixelFormat,codedWidth:n.codedWidth,codedHeight:n.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{x:0,y:0,width:n.visibleWidth,height:n.visibleHeight},timestamp:r.microsecondTimestamp,duration:r.microsecondDuration,colorSpace:s});c=new er(l,{timestamp:r.timestamp,duration:r.duration})}else c=new er(n.frameData,{format:n.pixelFormat,codedWidth:n.codedWidth,codedHeight:n.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{left:0,top:0,width:n.visibleWidth,height:n.visibleHeight},timestamp:r.timestamp,duration:r.duration,colorSpace:s});this.onSample(c)}trimCodedHeightToVisibleHeight(r){let A=r.pixelFormat.includes("P")?2:1,n=r.pixelFormat.includes("444")?1:2,o=r.pixelFormat.includes("420")?2:1,s=r.codedWidth/n,j=r.codedHeight/o,B=Math.ceil(r.visibleHeight/o),a=r.codedWidth*r.codedHeight,c=r.codedWidth*r.visibleHeight,l=s*j,d=s*B;r.frameData.set(r.frameData.subarray(A*a,A*(a+l)),A*c),r.frameData.set(r.frameData.subarray(A*(a+l),A*(a+2*l)),A*(c+d)),r.pixelFormat.includes("A")&&r.frameData.set(r.frameData.subarray(A*(a+2*l),A*(2*a+2*l)),A*(c+2*d)),r.codedHeight=r.visibleHeight}async flush(){await this.lastDecodePromise}async close(){C(this.decoder),await this.decoder.close();for(let r of this.framePool)r.clear()}};y._supportedVideoFrameFormats=null;var H=y,tr=!1,Sr=()=>{tr||(tr=!0,pr(H))};export{Sr as registerProresDecoder};
914
+ Otherwise, pass useSharedMemory: false to use a slower, worker-based fallback.`);let r;if(e.allowedOutputFormats){r=0;for(let o of e.allowedOutputFormats)r|=1<<p.indexOf(o)}else r=4294967295;let n=e.proresFourCc==="ap4h"||e.proresFourCc==="ap4x"?12:10,A=e.concurrency??await ur();if(e.useSharedMemory||A===0){let o=await mr();o.ref();let i=await o.ensureWorkers(A);if(i)return o.unref(),i;let j=o.exports.createDecoder(A,n,r);return j===0?(o.unref(),new g):new N(o,j,A)}else{let o=hr();o.ref();let i=await o.ensureWorkers(A);return i?(o.unref(),i):new W(o,A,n,r)}}static canUseSharedMemory(){return G}async decode(e,r,n={}){if(!(e instanceof Uint8Array))throw new TypeError("packetData must be a Uint8Array.");if(!(r instanceof T))throw new TypeError("frame must be a Frame.");if(typeof n!="object"||!n)throw new TypeError("options must be an object.");if(n.transfer!==void 0&&typeof n.transfer!="boolean")throw new TypeError("options.transfer, when provided, must be a boolean.");if(this._closed)return new O;if(r._locked)return new k;r._reset(),r._locked=!0,this._decodeQueueSize++;let A=this._runDecode(e,r,n);A.catch(()=>{});let o=this._queue.then(()=>A).finally(()=>{r._locked=!1,queueMicrotask(()=>{this._decodeQueueSize--,this._dequeuedResolve(),this._dequeued=new Promise(i=>{this._dequeuedResolve=i})})});return this._queue=o.catch(()=>{}),o}close(){if(this._closed)return this._queue;this._closed=!0;let e=this._queue.then(()=>this._runClose());return this._queue=e.catch(()=>{}),e}get isClosed(){return this._closed}[Symbol.dispose](){this.close()}[Symbol.asyncDispose](){return this.close()}},Z=new FinalizationRegistry(({runtime:t,ptr:e})=>{t.exports.closeDecoder(e),t.unref()}),N=class extends b{constructor(r,n,A){super();s(this,"_runtime");s(this,"_decoderPtr");s(this,"_taskStateOffset");s(this,"_decodeMutex",new y);s(this,"_nextPacketSlot",0);s(this,"_packetSlotMutexes",[new y,new y]);s(this,"_highWaterMark");s(this,"useSharedMemory",!0);s(this,"concurrency");this._highWaterMark=A===0?1:2,this._runtime=r,this._decoderPtr=n,this._taskStateOffset=r.exports.getTaskStateAddress(n)/4,this.concurrency=A,Z.register(this,{runtime:r,ptr:n},this)}_runClose(){f(this._runtime),Z.unregister(this),this._runtime.exports.closeDecoder(this._decoderPtr),this._runtime.unref(),this._runtime=null}async _runDecode(r,n,A){f(this._runtime);let{exports:o,memory:i}=this._runtime;if(!n._ensureWasmFrame(this._runtime))return new g;let j=n._ptr;A.transfer&&(r=structuredClone(r,{transfer:[r.buffer]}));let B=this._nextPacketSlot;this._nextPacketSlot=this._nextPacketSlot+1&1;let a=await this._packetSlotMutexes[B].acquire();try{let c=o.allocatePacket(this._decoderPtr,r.byteLength,B);if(c===0)return new g;new Uint8Array(i.buffer).set(r,c);let l=await this._decodeMutex.acquire();try{let u=o.decodePacket(this._decoderPtr,j,B);if(u<0)return this._createError(u);if(this.concurrency>0&&(await Atomics.waitAsync(new Int32Array(i.buffer),this._taskStateOffset,1).value,u=o.finalizePacketDecoding(this._decoderPtr),u<0))return this._createError(u);n._populate(cr(o,i,j,this._decoderPtr))}finally{l()}}finally{a()}return n}_createError(r){f(this._runtime);let{exports:n,memory:A}=this._runtime,o,i=n.getErrorMessagePtr(this._decoderPtr);if(i!==0){let j=n.getErrorMessageSize(this._decoderPtr);o=J(new Uint8Array(A.buffer,i,j))}return Y(r,o)}},X=new FinalizationRegistry(t=>{t.unref()}),W=class extends b{constructor(r,n,A,o){super();s(this,"_runtime");s(this,"_decoderId");s(this,"_highWaterMark");s(this,"useSharedMemory",!1);s(this,"concurrency");this._highWaterMark=Math.max(n,1),this._runtime=r,this.concurrency=n,this._decoderId=r.nextDecoderId++,r.registerDecoder(this._decoderId,A,o),X.register(this,r,this)}_runClose(){f(this._runtime),this._runtime.unregisterDecoder(this._decoderId),X.unregister(this),this._runtime.unref(),this._runtime=null}_runDecode(r,n,A){f(this._runtime);let o=this._runtime,i=A.transfer?r:r.slice(),j=0;for(let l=1;l<o.workerLoad.length;l++)o.workerLoad[l]<o.workerLoad[j]&&(j=l);let B=o.workers[j];o.workerLoad[j]=o.workerLoad[j]+1;let a=o.nextRequestId++,c=n._buffer;return n._buffer=null,new Promise(l=>{B.postMessage({type:d.Decode,id:a,decoderId:this._decoderId,packet:i,frameBuffer:c},c?[i.buffer,c]:[i.buffer]);let u=ir=>{let h=ir.data;h.type!==d.Decoded&&h.type!==d.DecodeError||h.id===a&&(B.removeEventListener("message",u),o.workerLoad[j]--,h.type===d.DecodeError?l(Y(h.code,h.message)):(n._buffer=h.contents.frameData.buffer,n._populate(h.contents),l(n)))};B.addEventListener("message",u)})}};function F(t){if(!t)throw new Error("Assertion failed.")}var Tr=Math.PI/180,wr=180/Math.PI;var vr=1e6*(1+Number.EPSILON);var H=null,tr=()=>H!==null?H:H=!!(typeof navigator<"u"&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));var or=Symbol.for("@mediabunny/prores loaded");globalThis[or]&&gr._error(`[WARNING]
915
+ @mediabunny/prores was loaded twice. This will likely cause the decoder not to work correctly. Check if multiple dependencies are importing different versions of @mediabunny/prores, or if something is being bundled incorrectly.`);globalThis[or]=!0;var x=class x extends pr{constructor(){super(...arguments);this.decoder=null;this.framePool=[];this.lastDecodePromise=Promise.resolve()}static supports(r,n){return r==="prores"}static _determineSupportedVideoFrameFormats(){let r=[],n=new Uint8Array(32);for(let A of p)try{new VideoFrame(n,{format:A,codedWidth:2,codedHeight:2,timestamp:0,duration:0}).close(),r.push(A)}catch{}return r}async init(){typeof VideoFrame<"u"&&(x._supportedVideoFrameFormats??=x._determineSupportedVideoFrameFormats());let r=await b.create({proresFourCc:this.config.codec,useSharedMemory:b.canUseSharedMemory(),allowedOutputFormats:x._supportedVideoFrameFormats??void 0});if(r instanceof Error)throw r;this.decoder=r}async decode(r){for(F(this.decoder);this.decoder.desiredSize<=0;)await this.decoder.dequeued;this.lastDecodePromise=this.runDecode(r).catch(n=>this.onError(n))}async runDecode(r){F(this.decoder);let n;this.framePool.length>0?n=this.framePool.shift():n=new T;let A=await this.decoder.decode(r.data,n);if(this.framePool.push(n),A instanceof Error)throw A;A.visibleHeight<A.codedHeight&&tr()&&this.trimCodedHeightToVisibleHeight(A);let o=this.config.colorSpace,i={primaries:o?.primaries??A.colorPrimariesString,matrix:o?.matrix??A.colorMatrixString,transfer:o?.transfer??A.colorTransferString,fullRange:o?.fullRange??A.colorRangeFull},j=A.pixelAspectRatio;this.config.displayAspectWidth!==void 0&&this.config.displayAspectHeight!==void 0&&(j={num:this.config.displayAspectWidth*A.visibleHeight,den:this.config.displayAspectHeight*A.visibleWidth});let B=A.visibleWidth,a=A.visibleHeight;j.num>j.den?B=Math.round(A.visibleWidth*j.num/j.den):a=Math.round(A.visibleHeight*j.den/j.num);let c;if(typeof VideoFrame<"u"){let l=new VideoFrame(A.frameData,{format:A.pixelFormat,codedWidth:A.codedWidth,codedHeight:A.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{x:0,y:0,width:A.visibleWidth,height:A.visibleHeight},timestamp:r.microsecondTimestamp,duration:r.microsecondDuration,colorSpace:i});c=new nr(l,{timestamp:r.timestamp,duration:r.duration})}else c=new nr(A.frameData,{format:A.pixelFormat,codedWidth:A.codedWidth,codedHeight:A.codedHeight,displayWidth:B,displayHeight:a,visibleRect:{left:0,top:0,width:A.visibleWidth,height:A.visibleHeight},timestamp:r.timestamp,duration:r.duration,colorSpace:i});this.onSample(c)}trimCodedHeightToVisibleHeight(r){let n=r.pixelFormat.includes("P")?2:1,A=r.pixelFormat.includes("444")?1:2,o=r.pixelFormat.includes("420")?2:1,i=r.codedWidth/A,j=r.codedHeight/o,B=Math.ceil(r.visibleHeight/o),a=r.codedWidth*r.codedHeight,c=r.codedWidth*r.visibleHeight,l=i*j,u=i*B;r.frameData.set(r.frameData.subarray(n*a,n*(a+l)),n*c),r.frameData.set(r.frameData.subarray(n*(a+l),n*(a+2*l)),n*(c+u)),r.pixelFormat.includes("A")&&r.frameData.set(r.frameData.subarray(n*(a+2*l),n*(2*a+2*l)),n*(c+2*u)),r.codedHeight=r.visibleHeight}async flush(){await this.lastDecodePromise}async close(){F(this.decoder),await this.decoder.close();for(let r of this.framePool)r.clear()}};x._supportedVideoFrameFormats=null;var K=x,Ar=!1,Rr=()=>{Ar||(Ar=!0,br(K))};export{Rr as registerProresDecoder};