mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
fix(build): update cpy options to use flat for output directory
This commit is contained in:
1 parent
699bf09577
commit
3bf0707faa
95 files changed
+29
-90819
No files matched your search
@@ -4,218 +4,4 @@
|
||||
* (c) 2017-2026 Harvey Zhao
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t){"object"===typeof exports&&"undefined"!==typeof module?module.exports=t():"function"==typeof define&&define.amd?(t.ArtplayerProxyMediabunny=t(),define(function(){return t.ArtplayerProxyMediabunny})):(e="undefined"!==typeof globalThis?globalThis:e||self).ArtplayerProxyMediabunny=t()}(this,function(){"use strict";class e{constructor(){this.listeners=new Map}addEventListener(e,t){this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t)}removeEventListener(e,t){const r=this.listeners.get(e);if(!r)return;const i=r.indexOf(t);i>=0&&r.splice(i,1)}emit(e,t){const r=new Event(e);r.detail=t;const i=this.listeners.get(e);i&&i.forEach(e=>e(r))}}
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/function t(e){if(!e)throw new Error("Assertion failed.")}const r=e=>{const t=(e%360+360)%360;if(0===t||90===t||180===t||270===t)return t;throw new Error(`Invalid rotation ${e}.`)},i=e=>e&&e[e.length-1];class a{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){const e=Math.floor(this.pos/8),t=this.bytes[e]??0,r=7-(7&this.pos),i=(t&1<<r)>>r;return this.pos++,i}readBits(e){if(1===e)return this.readBit();let t=0;for(let r=0;r<e;r++)t<<=1,t|=this.readBit();return t}writeBits(e,t){const r=this.pos+e;for(let i=this.pos;i<r;i++){const e=Math.floor(i/8);let a=this.bytes[e];const s=7-(7&i);a&=~(1<<s),a|=(t&1<<r-i-1)>>r-i-1<<s,this.bytes[e]=a}this.pos=r}readAlignedByte(){if(this.pos%8!==0)throw new Error("Bitstream is not byte-aligned.");const e=this.pos/8,t=this.bytes[e]??0;return this.pos+=8,t}skipBits(e){this.pos+=e}getBitsLeft(){return 8*this.bytes.length-this.pos}clone(){const e=new a(this.bytes);return e.pos=this.pos,e}}const s=e=>{let t=0;for(;0===e.readBits(1)&&t<32;)t++;if(t>=32)throw new Error("Invalid exponential-Golomb code.");return(1<<t)-1+e.readBits(t)},n=e=>{const t=s(e);return 0===(1&t)?-(t>>1):t+1>>1},o=e=>e.constructor===Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),c=e=>e.constructor===DataView?e:ArrayBuffer.isView(e)?new DataView(e.buffer,e.byteOffset,e.byteLength):new DataView(e),l=new TextDecoder,d=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e])),u={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},h=d(u),m={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},f=d(m),p={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},g=d(p),k=e=>e instanceof ArrayBuffer||"undefined"!==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e);class b{constructor(){this.currentPromise=Promise.resolve()}async acquire(){let e;const t=new Promise(t=>{e=t}),r=this.currentPromise;return this.currentPromise=t,await r,e}}const T=e=>[...e].map(e=>e.toString(16).padStart(2,"0")).join(""),y=e=>(e=(e=(e=(e=(e=e>>1&1431655765|(1431655765&e)<<1)>>2&858993459|(858993459&e)<<2)>>4&252645135|(252645135&e)<<4)>>8&16711935|(16711935&e)<<8)>>16&65535|(65535&e)<<16)>>>0,w=(e,t,r)=>{let i=0,a=e.length-1,s=-1;for(;i<=a;){const n=i+a>>1,o=r(e[n]);o===t?(s=n,a=n-1):o<t?i=n+1:a=n-1}return s},S=(e,t,r)=>{let i=0,a=e.length-1,s=-1;for(;i<=a;){const n=i+(a-i+1)/2|0;r(e[n])<=t?(s=n,i=n+1):a=n-1}return s},I=(e,t,r)=>{const i=S(e,r(t),r);e.splice(i+1,0,t)},v=()=>{let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}},P=(e,t)=>{for(let r=e.length-1;r>=0;r--)if(t(e[r]))return e[r]},x=(e,t)=>{for(let r=e.length-1;r>=0;r--)if(t(e[r]))return r;return-1},C=e=>{throw new Error(`Unexpected value: ${e}`)},_=(e,t,r)=>{const i=e.getUint8(t),a=e.getUint8(t+1),s=e.getUint8(t+2);return r?i|a<<8|s<<16:i<<16|a<<8|s},B=(e,t,r,i)=>{r>>>=0,r&=16777215,e.setUint8(t,r>>>16&255),e.setUint8(t+1,r>>>8&255),e.setUint8(t+2,255&r)},E=(e,t)=>({async next(){const r=await e.next();return r.done?{value:void 0,done:!0}:{value:t(r.value),done:!1}},return:()=>e.return(),throw:t=>e.throw(t),[Symbol.asyncIterator](){return this}}),F=(e,t,r)=>Math.max(t,Math.min(r,e)),D="und",A=e=>{const t=Math.round(e);return Math.abs(e/t-1)<10*Number.EPSILON?t:e},R=/^[a-z]{3}$/,M=e=>R.test(e),N=1e6*(1+Number.EPSILON),z=(e,t)=>{const r={...e,...t};if(e.headers||t.headers){const i=e.headers?O(e.headers):{},a=t.headers?O(t.headers):{},s={...i};Object.entries(a).forEach(([e,t])=>{const r=Object.keys(s).find(t=>t.toLowerCase()===e.toLowerCase());r&&delete s[r],s[e]=t}),r.headers=s}return r},O=e=>{if(e instanceof Headers){const t={};return e.forEach((e,r)=>{t[r]=e}),t}if(Array.isArray(e)){const t={};return e.forEach(([e,r])=>{t[e]=r}),t}return e},L=async(e,t,r,i,a)=>{let s=0;for(;;)try{return await e(t,r)}catch(n){if(a())throw n;s++;const e=i(s,n,t);if(null===e)throw n;if(console.error("Retrying failed fetch. Error:",n),!Number.isFinite(e)||e<0)throw new TypeError("Retry delay must be a non-negative finite number.");if(e>0&&await new Promise(t=>setTimeout(t,1e3*e)),a())throw n}};class U{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}}let V=null;const q=()=>null!==V?V:V=!("undefined"===typeof navigator||!(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));let H=null;const W=()=>null!==H?H:H="undefined"!==typeof navigator&&navigator.userAgent?.includes("Firefox");let j=null;const K=()=>null!==j?j:j=!("undefined"===typeof navigator||!navigator.vendor?.includes("Google Inc")&&!/Chrome/.test(navigator.userAgent));let $=null;const Q=(e,t)=>-1!==e?e:t,G=(e,t,r,i)=>e<=i&&r<=t,X=e=>{const t=atob(e),r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t.charCodeAt(i);return r},Y=()=>{Symbol.dispose??(Symbol.dispose=Symbol("Symbol.dispose"))},J=e=>"number"===typeof e&&!NumLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
class Z{constructor(e,t){if(this.data=e,this.mimeType=t,!(e instanceof Uint8Array))throw new TypeError("data must be a Uint8Array.");if("string"!==typeof t)throw new TypeError("mimeType must be a string.")}}class ee{constructor(e,t,r,i){if(this.data=e,this.mimeType=t,this.name=r,this.description=i,!(e instanceof Uint8Array))throw new TypeError("data must be a Uint8Array.");if(void 0!==t&&"string"!==typeof t)throw new TypeError("mimeType, when provided, must be a string.");if(void 0!==r&&"string"!==typeof r)throw new TypeError("name, when provided, must be a string.");if(void 0!==i&&"string"!==typeof i)throw new TypeError("description, when provided, must be a string.")}}const te={default:!0,forced:!1,original:!1,commentary:!1,hearingImpaired:!1,visuallyImpaired:!1},re=["pcm-s16","pcm-s16be","pcm-s24","pcm-s24be","pcm-s32","pcm-s32be","pcm-f32","pcm-f32be","pcm-f64","pcm-f64be","pcm-u8","pcm-s8","ulaw","alaw"],ie=[{maxPictureSize:36864,maxBitrate:2e5,level:10},{maxPictureSize:73728,maxBitrate:8e5,level:11},{maxPictureSize:122880,maxBitrate:18e5,level:20},{maxPictureSize:245760,maxBitrate:36e5,level:21},{maxPictureSize:552960,maxBitrate:72e5,level:30},{maxPictureSize:983040,maxBitrate:12e6,level:31},{maxPictureSize:2228224,maxBitrate:18e6,level:40},{maxPictureSize:2228224,maxBitrate:3e7,level:41},{maxPictureSize:8912896,maxBitrate:6e7,level:50},{maxPictureSize:8912896,maxBitrate:12e7,level:51},{maxPictureSize:8912896,maxBitrate:18e7,level:52},{maxPictureSize:35651584,maxBitrate:18e7,level:60},{maxPictureSize:35651584,maxBitrate:24e7,level:61},{maxPictureSize:35651584,maxBitrate:48e7,level:62}],ae=".01.01.01.01.00",se=".0.110.01.01.01.0",ne=e=>{const{codec:r,codecDescription:a,colorSpace:s,avcCodecInfo:n,hevcCodecInfo:o,vp9CodecInfo:l,av1CodecInfo:d}=e;if("avc"===r){if(t(null!==e.avcType),n){const t=new Uint8Array([n.avcProfileIndication,n.profileCompatibility,n.avcLevelIndication]);return`avc${e.avcType}.${T(t)}`}if(!a||a.byteLength<4)throw new TypeError("AVC decoder description is not provided or is not at least 4 bytes long.");return`avc${e.avcType}.${T(a.subarray(1,4))}`}if("hevc"===r){let e,t,r,i,s,n;if(o)e=o.generalProfileSpace,t=o.generalProfileIdc,r=y(o.generalProfileCompatibilityFlags),i=o.generalTierFlag,s=o.generalLevelIdc,n=[...o.generalConstraintIndicatorFlags];else{if(!a||a.byteLength<23)throw new TypeError("HEVC decoder description is not provided or is not at least 23 bytes long.");const o=c(a),l=o.getUint8(1);e=l>>6&3,t=31&l,r=y(o.getUint32(2)),i=l>>5&1,s=o.getUint8(12),n=[];for(let e=0;e<6;e++)n.push(o.getUint8(6+e))}let l="hev1.";for(l+=["","A","B","C"][e]+t,l+=".",l+=r.toString(16).toUpperCase(),l+=".",l+=0===i?"L":"H",l+=s;n.length>0&&0===n[n.length-1];)n.pop();return n.length>0&&(l+=".",l+=n.map(e=>e.toString(16).toUpperCase()).join(".")),l}if("vp8"===r)return"vp8";if("vp9"===r){if(!l){const t=e.width*e.height;let r=i(ie).level;for(const e of ie)if(t<=e.maxPictureSize){r=e.level;break}return`vp09.00.${r.toString().padStart(2,"0")}.08`}let t=`vp09.${l.profile.toString().padStart(2,"0")}.${l.level.toString().padStart(2,"0")}.${l.bitDepth.toString().padStart(2,"0")}.${l.chromaSubsampling.toString().padStart(2,"0")}`;return t+=`.${l.colourPrimaries.toString().padStart(2,"0")}.${l.transferCharacteristics.toString().padStart(2,"0")}.${l.matrixCoefficients.toString().padStart(2,"0")}.${l.videoFullRangeFlag.toString().padStart(2,"0")}`,t.endsWith(ae)&&(t=t.slice(0,-15)),t}if("av1"===r){if(!d){const t=e.width*e.height;let r=i(ie).level;for(const e of ie)if(t<=e.maxPictureSize){r=e.level;break}return`av01.0.${r.toString().padStart(2,"0")}M.08`}const t=d.profile,r=d.level.toString().padStart(2,"0"),a=d.tier?"H":"M",n=d.bitDepth.toString().padStart(2,"0"),o=d.monochrome?"1":"0",c=100*d.chromaSubsamplingX+10*d.chromaSubsamplingY+1*(d.chromaSubsamplingX&&d.chromaSubsamplingY?d.chromaSamplePosition:0),l=s?.primaries?u[s.primaries]:1,h=s?.transfer?m[s.transfer]:1,f=s?.matrix?p[s.matrix]:1,g=s?.fullRange?1:0;let k=`av01.${t}.${r}${a}.${n}`;return k+=`.${o}.${c.toString().padStart(3,"0")}`,k+=`.${l.toString().padStart(2,"0")}`,k+=`.${h.toString().padStart(2,"0")}`,k+=`.${f.toString().padStart(2,"0")}`,k+=`.${g}`,k.endsWith(se)&&(k=k.slice(0,-17)),k}throw new TypeError(`Unhandled codec '${r}'.`)},oe=e=>{const{codec:t,codecDescription:r,aacCodecInfo:i}=e;if("aac"===t){if(!i)throw new TypeError("AAC codec info must be provided.");if(i.isMpeg2)return"mp4a.67";return`mp4a.40.${de(r).objectType}`}if("mp3"===t)return"mp3";if("opus"===t)return"opus";if("vorbis"===t)return"vorbis";if("flac"===t)return"flac";if(t&&re.includes(t))return t;throw new TypeError(`Unhandled codec '${t}'.`)},ce=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],le=[-1,1,2,3,4,5,6,8],de=e=>{if(!e||e.byteLength<2)throw new TypeError("AAC description must be at least 2 bytes long.");const t=new a(e);let r=t.readBits(5);31===r&&(r=32+t.readBits(6));const i=t.readBits(4);let s=null;15===i?s=t.readBits(24):i<ce.length&&(s=ce[Line truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
var fe,pe,ge,ke;(pe=fe||(fe={}))[pe.IDR=5]="IDR",pe[pe.SEI=6]="SEI",pe[pe.SPS=7]="SPS",pe[pe.PPS=8]="PPS",pe[pe.SPS_EXT=13]="SPS_EXT",(ke=ge||(ge={}))[ke.RASL_N=8]="RASL_N",ke[ke.RASL_R=9]="RASL_R",ke[ke.BLA_W_LP=16]="BLA_W_LP",ke[ke.RSV_IRAP_VCL23=23]="RSV_IRAP_VCL23",ke[ke.VPS_NUT=32]="VPS_NUT",ke[ke.SPS_NUT=33]="SPS_NUT",ke[ke.PPS_NUT=34]="PPS_NUT",ke[ke.PREFIX_SEI_NUT=39]="PREFIX_SEI_NUT",ke[ke.SUFFIX_SEI_NUT=40]="SUFFIX_SEI_NUT";const be=e=>{const t=[];let r=0;for(;r<e.length;){let i=-1,a=0;for(let t=r;t<e.length-3;t++){if(0===e[t]&&0===e[t+1]&&1===e[t+2]){i=t,a=3;break}if(t<e.length-4&&0===e[t]&&0===e[t+1]&&0===e[t+2]&&1===e[t+3]){i=t,a=4;break}}if(-1===i)break;if(r>0&&i>r){const a=e.subarray(r,i);a.length>0&&t.push(a)}r=i+a}if(r<e.length){const i=e.subarray(r);i.length>0&&t.push(i)}return t},Te=(e,r)=>{const i=[];let a=0;const s=new DataView(e.buffer,e.byteOffset,e.byteLength);for(;a+r<=e.length;){let n;1===r?n=s.getUint8(a):2===r?n=s.getUint16(a,!1):3===r?n=_(s,a,!1):4===r?n=s.getUint32(a,!1):(C(r),t(!1)),a+=r;const o=e.subarray(a,a+n);i.push(o),a+=n}return i},ye=e=>{const t=[],r=e.length;for(let i=0;i<r;i++)i+2<r&&0===e[i]&&0===e[i+1]&&3===e[i+2]?(t.push(0,0),i+=2):t.push(e[i]);return new Uint8Array(t)},we=new Uint8Array([0,0,0,1]),Se=(e,t)=>{if(t.description){const r=3&o(t.description)[4];return Te(e,r+1)}return be(e)},Ie=(e,t)=>{if(t.description){return((e,t)=>{const r=e.reduce((e,r)=>e+t+r.byteLength,0),i=new Uint8Array(r);let a=0;for(const s of e){const e=new DataView(i.buffer,i.byteOffset,i.byteLength);switch(t){case 1:e.setUint8(a,s.byteLength);break;case 2:e.setUint16(a,s.byteLength,!1);break;case 3:B(e,a,s.byteLength);break;case 4:e.setUint32(a,s.byteLength,!1)}a+=t,i.set(s,a),a+=s.byteLength}return i})(e,(3&o(t.description)[4])+1)}return(e=>{const t=e.reduce((e,t)=>e+we.byteLength+t.byteLength,0),r=new Uint8Array(t);let i=0;for(const a of e)r.set(we,i),i+=we.byteLength,r.set(a,i),i+=a.byteLength;return r})(e)},ve=e=>31&e[0],Pe=e=>{try{const r=be(e),i=r.filter(e=>ve(e)===fe.SPS),a=r.filter(e=>ve(e)===fe.PPS),s=r.filter(e=>ve(e)===fe.SPS_EXT);if(0===i.length)return null;if(0===a.length)return null;const n=i[0],o=xe(n);t(null!==o);const c=100===o.profileIdc||110===o.profileIdc||122===o.profileIdc||144===o.profileIdc;return{configurationVersion:1,avcProfileIndication:o.profileIdc,profileCompatibility:o.constraintFlags,avcLevelIndication:o.levelIdc,lengthSizeMinusOne:3,sequenceParameterSets:i,pictureParameterSets:a,chromaFormat:c?o.chromaFormatIdc:null,bitDepthLumaMinus8:c?o.bitDepthLumaMinus8:null,bitDepthChromaMinus8:c?o.bitDepthChromaMinus8:null,sequenceParameterSetExt:c?s:null}}catch(r){return console.error("Error building AVC Decoder Configuration Record:",r),null}},xe=e=>{try{const t=new a(ye(e));t.skipBits(1),t.skipBits(2);if(7!==t.readBits(5))return null;const r=t.readAlignedByte(),i=t.readAlignedByte(),o=t.readAlignedByte();s(t);let c=null,l=null,d=null;if(100===r||110===r||122===r||244===r||44===r||83===r||86===r||118===r||128===r){c=s(t),3===c&&t.skipBits(1),l=s(t),d=s(t),t.skipBits(1);if(t.readBits(1))for(let e=0;e<(3!==c?8:12);e++){if(t.readBits(1)){const r=e<6?16:64;let i=8,a=8;for(let e=0;e<r;e++){if(0!==a){a=(i+n(t)+256)%256}i=0===a?i:a}}}}s(t);const u=s(t);if(0===u)s(t);else if(1===u){t.skipBits(1),n(t),n(t);const e=s(t);for(let r=0;r<e;r++)n(t)}s(t),t.skipBits(1),s(t),s(t);return{profileIdc:r,constraintFlags:i,levelIdc:o,frameMbsOnlyFlag:t.readBits(1),chromaFormatIdc:c,bitDepthLumaMinus8:l,bitDepthChromaMinus8:d}}catch(t){return console.error("Error parsing AVC SPS:",t),null}},Ce=(e,t)=>{if(t.description){const r=3&o(t.description)[21];return Te(e,r+1)}return be(e)},_e=e=>e[0]>>1&63,Be=e=>{try{const t=be(e),r=t.filter(e=>_e(e)===ge.VPS_NUT),i=t.filter(e=>_e(e)===ge.SPS_NUT),o=t.filter(e=>_e(e)===ge.PPS_NUT),c=t.filter(e=>_e(e)===ge.PREFIX_SEI_NUT||_e(e)===ge.SUFFIX_SEI_NUT);if(0===i.length||0===o.length)return null;const l=i[0],d=new a(ye(l));d.skipBits(16),d.readBits(4);const u=d.readBits(3),h=d.readBits(1),{general_profile_space:m,general_tier_flag:f,general_profile_idc:p,general_profile_compatibility_flags:g,general_constraint_indicator_flags:k,general_level_idc:b}=Ee(d,u);s(d);const T=s(d);3===T&&d.skipBits(1),s(d),s(d),d.readBits(1)&&(s(d),s(d),s(d),s(d));const y=s(d),w=s(d);s(d);const S=d.readBits(1);for(let e=S?0:u;e<=u;e++)s(d),s(d),s(d);s(d),s(d),s(d),s(d),s(d),s(d),d.readBits(1)&&d.readBits(1)&&Fe(d),d.skipBits(1),d.skipBits(1),d.readBits(1)&&(d.skipBits(4),d.skipBits(4),s(d),s(d),d.skipBits(1));const I=s(d);if(De(d,I),d.readBits(1)){const e=s(d);for(let t=0;t<e;t++)s(d),d.skipBits(1)}d.skipBits(1),d.skipBits(1);let v=0;d.readBits(1)&&(v=Re(d,u));let P=0;if(o.length>0){const e=o[0],t=new a(ye(e));t.skipBits(16),s(t),s(t),t.skipBits(1),t.skipBits(1),t.skipBits(3),t.skipBits(1),t.skipBits(1),s(t),s(t),n(t),t.skipBits(1),t.skipBits(1),t.readBits(1)&&s(t),n(t),n(t),t.skipBits(1),t.skipBits(1),t.skipBits(1),t.skipBits(1);const r=t.readBits(1),i=t.readBits(1);P=r||i?r&&!iLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/class Ke{constructor(e){this.input=e}}
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/const $e=[],Qe=[],Ge=new Uint8Array(0);class Xe{constructor(e,t,r,i,a=-1,s,n){if(this.data=e,this.type=t,this.timestamp=r,this.duration=i,this.sequenceNumber=a,e===Ge&&void 0===s)throw new Error("Internal error: byteLength must be explicitly provided when constructing metadata-only packets.");if(void 0===s&&(s=e.byteLength),!(e instanceof Uint8Array))throw new TypeError("data must be a Uint8Array.");if("key"!==t&&"delta"!==t)throw new TypeError('type must be either "key" or "delta".');if(!Number.isFinite(r))throw new TypeError("timestamp must be a number.");if(!Number.isFinite(i)||i<0)throw new TypeError("duration must be a non-negative number.");if(!Number.isFinite(a))throw new TypeError("sequenceNumber must be a number.");if(!Number.isInteger(s)||s<0)throw new TypeError("byteLength must be a non-negative integer.");if(void 0!==n&&("object"!==typeof n||!n))throw new TypeError("sideData, when provided, must be an object.");if(void 0!==n?.alpha&&!(n.alpha instanceof Uint8Array))throw new TypeError("sideData.alpha, when provided, must be a Uint8Array.");if(void 0!==n?.alphaByteLength&&(!Number.isInteger(n.alphaByteLength)||n.alphaByteLength<0))throw new TypeError("sideData.alphaByteLength, when provided, must be a non-negative integer.");this.byteLength=s,this.sideData=n??{},this.sideData.alpha&&void 0===this.sideData.alphaByteLength&&(this.sideData.alphaByteLength=this.sideData.alpha.byteLength)}get isMetadataOnly(){return this.data===Ge}get microsecondTimestamp(){return Math.trunc(N*this.timestamp)}get microsecondDuration(){return Math.trunc(N*this.duration)}toEncodedVideoChunk(){if(this.isMetadataOnly)throw new TypeError("Metadata-only packets cannot be converted to a video chunk.");if("undefined"===typeof EncodedVideoChunk)throw new Error("Your browser does not support EncodedVideoChunk.");return new EncodedVideoChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}alphaToEncodedVideoChunk(e=this.type){if(!this.sideData.alpha)throw new TypeError("This packet does not contain alpha side data.");if(this.isMetadataOnly)throw new TypeError("Metadata-only packets cannot be converted to a video chunk.");if("undefined"===typeof EncodedVideoChunk)throw new Error("Your browser does not support EncodedVideoChunk.");return new EncodedVideoChunk({data:this.sideData.alpha,type:e,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}toEncodedAudioChunk(){if(this.isMetadataOnly)throw new TypeError("Metadata-only packets cannot be converted to an audio chunk.");if("undefined"===typeof EncodedAudioChunk)throw new Error("Your browser does not support EncodedAudioChunk.");return new EncodedAudioChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}static fromEncodedChunk(e,t){if(!(e instanceof EncodedVideoChunk||e instanceof EncodedAudioChunk))throw new TypeError("chunk must be an EncodedVideoChunk or EncodedAudioChunk.");const r=new Uint8Array(e.byteLength);return e.copyTo(r),new Xe(r,e.type,e.timestamp/1e6,(e.duration??0)/1e6,void 0,void 0,t)}clone(e){if(void 0!==e&&("object"!==typeof e||null===e))throw new TypeError("options, when provided, must be an object.");if(void 0!==e?.timestamp&&!Number.isFinite(e.timestamp))throw new TypeError("options.timestamp, when provided, must be a number.");if(void 0!==e?.duration&&!Number.isFinite(e.duration))throw new TypeError("options.duration, when provided, must be a number.");return new Xe(this.data,this.type,e?.timestamp??this.timestamp,e?.duration??this.duration,this.sequenceNumber,this.byteLength)}}
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
Y();let Ye=-1/0,Je=-1/0,Ze=null;"undefined"!==typeof FinalizationRegistry&&(Ze=new FinalizationRegistry(e=>{const t=Date.now();"video"===e.type?(t-Ye>=1e3&&(console.error("A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them."),Ye=t),"undefined"!==typeof VideoFrame&&e.data instanceof VideoFrame&&e.data.close()):(t-Je>=1e3&&(console.error("An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them."),Je=t),"undefined"!==typeof AudioData&&e.data instanceof AudioData&&e.data.close())}));const et=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12","NV12","RGBA","RGBX","BGRA","BGRX"],tt=new Set(et);class rt{get displayWidth(){return this.rotation%180===0?this.codedWidth:this.codedHeight}get displayHeight(){return this.rotation%180===0?this.codedHeight:this.codedWidth}get microsecondTimestamp(){return Math.trunc(N*this.timestamp)}get microsecondDuration(){return Math.trunc(N*this.duration)}get hasAlpha(){return this.format&&this.format.includes("A")}constructor(e,r){if(this._closed=!1,e instanceof ArrayBuffer||"undefined"!==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e)){if(!r||"object"!==typeof r)throw new TypeError("init must be an object.");if(void 0===r.format||!tt.has(r.format))throw new TypeError("init.format must be one of: "+et.join(", "));if(!Number.isInteger(r.codedWidth)||r.codedWidth<=0)throw new TypeError("init.codedWidth must be a positive integer.");if(!Number.isInteger(r.codedHeight)||r.codedHeight<=0)throw new TypeError("init.codedHeight must be a positive integer.");if(void 0!==r.rotation&&![0,90,180,270].includes(r.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(!Number.isFinite(r.timestamp))throw new TypeError("init.timestamp must be a number.");if(void 0!==r.duration&&(!Number.isFinite(r.duration)||r.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");this._data=o(e).slice(),this._layout=r.layout??ct(r.format,r.codedWidth,r.codedHeight),this.format=r.format,this.codedWidth=r.codedWidth,this.codedHeight=r.codedHeight,this.rotation=r.rotation??0,this.timestamp=r.timestamp,this.duration=r.duration??0,this.colorSpace=new it(r.colorSpace)}else if("undefined"!==typeof VideoFrame&&e instanceof VideoFrame){if(void 0!==r?.rotation&&![0,90,180,270].includes(r.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(void 0!==r?.timestamp&&!Number.isFinite(r?.timestamp))throw new TypeError("init.timestamp, when provided, must be a number.");if(void 0!==r?.duration&&(!Number.isFinite(r.duration)||r.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");this._data=e,this._layout=null,this.format=e.format,this.codedWidth=e.displayWidth,this.codedHeight=e.displayHeight,this.rotation=r?.rotation??0,this.timestamp=r?.timestamp??e.timestamp/1e6,this.duration=r?.duration??(e.duration??0)/1e6,this.colorSpace=new it(e.colorSpace)}else{if(!("undefined"!==typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!==typeof SVGImageElement&&e instanceof SVGImageElement||"undefined"!==typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!==typeof HTMLVideoElement&&e instanceof HTMLVideoElement||"undefined"!==typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!==typeof OffscreenCanvas&&e instanceof OffscreenCanvas))throw new TypeError("Invalid data type: Must be a BufferSource or CanvasImageSource.");{if(!r||"object"!==typeof r)throw new TypeError("init must be an object.");if(void 0!==r.rotation&&![0,90,180,270].includes(r.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(!Number.isFinite(r.timestamp))throw new TypeError("init.timestamp must be a number.");if(void 0!==r.duration&&(!Number.isFinite(r.duration)||r.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");if("undefined"!==typeof VideoFrame)return new rt(new VideoFrame(e,{timestamp:Math.trunc(r.timestamp*N),duration:Math.trunc((r.duration??0)*N)||void 0}),r);let i=0,a=0;if("naturalWidth"in e?(i=e.naturalWidth,a=e.naturalHeight):"videoWidth"in e?(i=e.videoWidth,a=e.videoHeight):"width"in e&&(i=Number(e.width),a=Number(e.height)),!i||!a)throw new TypeError("Could not determine dimensions.");const s=new OffscreenCanvas(i,a),n=s.getContext("2d",{alpha:W(),willReadFrequently:!0});t(n),n.drawImage(e,0,0),this._data=s,this._layout=null,this.format="RGBX",this.codedWidth=i,this.codedHeight=a,this.rotation=r.rotation??0,this.timestamp=r.timestamp,this.duration=r.duration??0,this.colorSpace=neLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/class At{constructor(e,t){this.input=e,this._backing=t}isVideoTrack(){return this instanceof Rt}isAudioTrack(){return this instanceof Mt}get id(){return this._backing.getId()}get internalCodecId(){return this._backing.getInternalCodecId()}get languageCode(){return this._backing.getLanguageCode()}get name(){return this._backing.getName()}get timeResolution(){return this._backing.getTimeResolution()}get disposition(){return this._backing.getDisposition()}getFirstTimestamp(){return this._backing.getFirstTimestamp()}computeDuration(){return this._backing.computeDuration()}async computePacketStats(e=1/0){const t=new wt(this);let r=1/0,i=-1/0,a=0,s=0;for await(const n of t.packets(void 0,void 0,{metadataOnly:!0})){if(a>=e&&n.timestamp>=i)break;r=Math.min(r,n.timestamp),i=Math.max(i,n.timestamp+n.duration),a++,s+=n.byteLength}return{packetCount:a,averagePacketRate:a?Number((a/(i-r)).toPrecision(16)):0,averageBitrate:a?Number((8*s/(i-r)).toPrecision(16)):0}}}class Rt extends At{constructor(e,t){super(e,t),this._backing=t}get type(){return"video"}get codec(){return this._backing.getCodec()}get codedWidth(){return this._backing.getCodedWidth()}get codedHeight(){return this._backing.getCodedHeight()}get rotation(){return this._backing.getRotation()}get displayWidth(){return this._backing.getRotation()%180===0?this._backing.getCodedWidth():this._backing.getCodedHeight()}get displayHeight(){return this._backing.getRotation()%180===0?this._backing.getCodedHeight():this._backing.getCodedWidth()}getColorSpace(){return this._backing.getColorSpace()}async hasHighDynamicRange(){const e=await this._backing.getColorSpace();return"bt2020"===e.primaries||"smpte432"===e.primaries||"pg"===e.transfer||"hlg"===e.transfer||"bt2020-ncl"===e.matrix}canBeTransparent(){return this._backing.canBeTransparent()}getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){const e=await this._backing.getDecoderConfig();return e?.codec??null}async canDecode(){try{const e=await this._backing.getDecoderConfig();if(!e)return!1;const r=this._backing.getCodec();if(t(null!==r),$e.some(t=>t.supports(r,e)))return!0;if("undefined"===typeof VideoDecoder)return!1;return!0===(await VideoDecoder.isConfigSupported(e)).supported}catch(e){return console.error("Error during decodability check:",e),!1}}async determinePacketType(e){if(!(e instanceof Xe))throw new TypeError("packet must be an EncodedPacket.");if(e.isMetadataOnly)throw new TypeError("packet must not be metadata-only to determine its type.");if(null===this.codec)return null;const r=await this.getDecoderConfig();return t(r),qe(this.codec,r,e.data)}}class Mt extends At{constructor(e,t){super(e,t),this._backing=t}get type(){return"audio"}get codec(){return this._backing.getCodec()}get numberOfChannels(){return this._backing.getNumberOfChannels()}get sampleRate(){return this._backing.getSampleRate()}getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){const e=await this._backing.getDecoderConfig();return e?.codec??null}async canDecode(){try{const e=await this._backing.getDecoderConfig();if(!e)return!1;const r=this._backing.getCodec();if(t(null!==r),Qe.some(t=>t.supports(r,e)))return!0;if(e.codec.startsWith("pcm-"))return!0;if("undefined"===typeof AudioDecoder)return!1;return!0===(await AudioDecoder.isConfigSupported(e)).supported}catch(e){return console.error("Error during decodability check:",e),!1}}async determinePacketType(e){if(!(e instanceof Xe))throw new TypeError("packet must be an EncodedPacket.");return null===this.codec?null:"key"}}
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/const Nt=e=>{let t=ua(e);const r=ya(e,4);let i=8;1===t&&(t=pa(e),i=16);const a=t-i;return a<0?null:{name:r,totalSize:t,headerSize:i,contentSize:a}},zt=e=>ma(e)/65536,Ot=e=>ma(e)/1073741824,Lt=e=>{let t=0;for(let r=0;r<4;r++){t<<=7;const r=sa(e);if(t|=127&r,0===(128&r))break}return t},Ut=e=>{let t=oa(e);return e.skip(2),t=Math.min(t,e.remainingLength),l.decode(aa(e,t))},Vt=e=>{const t=Nt(e);if(!t||"data"!==t.name)return null;if(e.remainingLength<8)return null;const r=ua(e);e.skip(4);const i=aa(e,t.contentSize-8);switch(r){case 1:return l.decode(i);case 2:return new TextDecoder("utf-16be").decode(i);case 13:return new Z(i,"image/jpeg");case 14:return new Z(i,"image/png");case 27:return new Z(i,"image/bmp");default:return i}};
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
class qt extends Ke{constructor(e){super(e),this.moovSlice=null,this.currentTrack=null,this.tracks=[],this.metadataPromise=null,this.movieTimescale=-1,this.movieDurationInTimescale=-1,this.isQuickTime=!1,this.metadataTags={},this.currentMetadataKeys=null,this.isFragmented=!1,this.fragmentTrackDefaults=[],this.currentFragment=null,this.lastReadFragment=null,this.reader=e._reader}async computeDuration(){const e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getTracks(){return await this.readMetadata(),this.tracks.map(e=>e.inputTrack)}async getMimeType(){await this.readMetadata();const e=await Promise.all(this.tracks.map(e=>e.inputTrack.getCodecParameterString()));return(e=>{let t=(e.hasVideo?"video/":e.hasAudio?"audio/":"application/")+(e.isQuickTime?"quicktime":"mp4");e.codecStrings.length>0&&(t+=`; codecs="${[...new Set(e.codecStrings)].join(", ")}"`);return t})({isQuickTime:this.isQuickTime,hasVideo:this.tracks.some(e=>"video"===e.info?.type),hasAudio:this.tracks.some(e=>"audio"===e.info?.type),codecStrings:e.filter(Boolean)})}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}readMetadata(){return this.metadataPromise??(this.metadataPromise=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,8,16);if(t instanceof Promise&&(t=await t),!t)break;const r=e,i=Nt(t);if(!i)break;if("ftyp"===i.name){const e=ya(t,4);this.isQuickTime="qt "===e}else if("moov"===i.name){let e=this.reader.requestSlice(t.filePos,i.contentSize);if(e instanceof Promise&&(e=await e),!e)break;this.moovSlice=e,this.readContiguousBoxes(this.moovSlice),this.tracks.sort((e,t)=>Number(t.disposition.default)-Number(e.disposition.default));for(const t of this.tracks){const e=t.editListPreviousSegmentDurations/this.movieTimescale;t.editListOffset-=Math.round(e*t.timescale)}break}e=r+i.totalSize}if(this.isFragmented&&null!==this.reader.fileSize){let e=this.reader.requestSlice(this.reader.fileSize-4,4);e instanceof Promise&&(e=await e),t(e);const r=ua(e),i=this.reader.fileSize-r;if(i>=0&&i<=this.reader.fileSize-16){let e=this.reader.requestSliceRange(i,8,16);if(e instanceof Promise&&(e=await e),e){const t=Nt(e);if(t&&"mfra"===t.name){let r=this.reader.requestSlice(e.filePos,t.contentSize);r instanceof Promise&&(r=await r),r&&this.readContiguousBoxes(r)}}}}})())}getSampleTableForTrack(e){if(e.sampleTable)return e.sampleTable;const r={sampleTimingEntries:[],sampleCompositionTimeOffsets:[],sampleSizes:[],keySampleIndices:null,chunkOffsets:[],sampleToChunk:[],presentationTimestamps:null,presentationTimestampIndexMap:null};e.sampleTable=r,t(this.moovSlice);const a=this.moovSlice.slice(e.sampleTableByteOffset);this.currentTrack=e,this.traverseBox(a),this.currentTrack=null;if("audio"===e.info?.type&&e.info.codec&&re.includes(e.info.codec)&&0===r.sampleCompositionTimeOffsets.length){t("audio"===e.info?.type);const a=me(e.info.codec),s=[],n=[];for(let t=0;t<r.sampleToChunk.length;t++){const o=r.sampleToChunk[t],c=r.sampleToChunk[t+1],l=(c?c.startChunkIndex:r.chunkOffsets.length)-o.startChunkIndex;for(let t=0;t<l;t++){const c=o.startSampleIndex+t*o.samplesPerChunk,l=c+o.samplesPerChunk,d=S(r.sampleTimingEntries,c,e=>e.startIndex),u=r.sampleTimingEntries[d],h=S(r.sampleTimingEntries,l,e=>e.startIndex),m=r.sampleTimingEntries[h],f=u.startDecodeTimestamp+(c-u.startIndex)*u.delta,p=m.startDecodeTimestamp+(l-m.startIndex)*m.delta-f,g=i(s);g&&g.delta===p?g.count++:s.push({startIndex:o.startChunkIndex+t,startDecodeTimestamp:f,count:1,delta:p});const k=o.samplesPerChunk*a.sampleSize*e.info.numberOfChannels;n.push(k)}o.startSampleIndex=o.startChunkIndex,o.samplesPerChunk=1}r.sampleTimingEntries=s,r.sampleSizes=n}if(r.sampleCompositionTimeOffsets.length>0){r.presentationTimestamps=[];for(const e of r.sampleTimingEntries)for(let t=0;t<e.count;t++)r.presentationTimestamps.push({presentationTimestamp:e.startDecodeTimestamp+t*e.delta,sampleIndex:e.startIndex+t});for(const e of r.sampleCompositionTimeOffsets)for(let t=0;t<e.count;t++){const i=e.startIndex+t,a=r.presentationTimestamps[i];a&&(a.presentationTimestamp+=e.offset)}r.presentationTimestamps.sort((e,t)=>e.presentationTimestamp-t.presentationTimestamp),r.presentationTimestampIndexMap=Array(r.presentationTimestamps.length).fill(-1);for(let e=0;e<r.presentationTimestamps.length;e++)r.presentationTimestampIndexMap[r.presentationTimestamps[e].sampleIndex]=e}return r}async readFragment(e){if(this.lastReadFragment?.moofOffset===e)return this.lastReadFragment;let r=this.reader.requestSliceRange(e,8,16);r instanceof Promise&&(r=await r),t(r);const i=Nt(r);t("moof"===i?.name);let a=this.reader.requestSlice(e,i.totalSize);a instanceof Promise&&(a=await a),t(a),this.traverseBox(a);const s=this.lastReadFragment;t(s&&s.moofOffset===e);for(const[,t]of s.trackData){const e=t.track,{fragmentPositionCache:r}=e;if(!t.startTimestampIsFinal){const i=e.fragmentLookupTable.find(e=>e.moofOffset===s.moofOffset);if(i)Xt(t,i.timestamp);else{const eLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
var Zt,er;(er=Zt||(Zt={}))[er.EBML=440786851]="EBML",er[er.EBMLVersion=17030]="EBMLVersion",er[er.EBMLReadVersion=17143]="EBMLReadVersion",er[er.EBMLMaxIDLength=17138]="EBMLMaxIDLength",er[er.EBMLMaxSizeLength=17139]="EBMLMaxSizeLength",er[er.DocType=17026]="DocType",er[er.DocTypeVersion=17031]="DocTypeVersion",er[er.DocTypeReadVersion=17029]="DocTypeReadVersion",er[er.Void=236]="Void",er[er.Segment=408125543]="Segment",er[er.SeekHead=290298740]="SeekHead",er[er.Seek=19899]="Seek",er[er.SeekID=21419]="SeekID",er[er.SeekPosition=21420]="SeekPosition",er[er.Duration=17545]="Duration",er[er.Info=357149030]="Info",er[er.TimestampScale=2807729]="TimestampScale",er[er.MuxingApp=19840]="MuxingApp",er[er.WritingApp=22337]="WritingApp",er[er.Tracks=374648427]="Tracks",er[er.TrackEntry=174]="TrackEntry",er[er.TrackNumber=215]="TrackNumber",er[er.TrackUID=29637]="TrackUID",er[er.TrackType=131]="TrackType",er[er.FlagEnabled=185]="FlagEnabled",er[er.FlagDefault=136]="FlagDefault",er[er.FlagForced=21930]="FlagForced",er[er.FlagOriginal=21934]="FlagOriginal",er[er.FlagHearingImpaired=21931]="FlagHearingImpaired",er[er.FlagVisualImpaired=21932]="FlagVisualImpaired",er[er.FlagCommentary=21935]="FlagCommentary",er[er.FlagLacing=156]="FlagLacing",er[er.Name=21358]="Name",er[er.Language=2274716]="Language",er[er.LanguageBCP47=2274717]="LanguageBCP47",er[er.CodecID=134]="CodecID",er[er.CodecPrivate=25506]="CodecPrivate",er[er.CodecDelay=22186]="CodecDelay",er[er.SeekPreRoll=22203]="SeekPreRoll",er[er.DefaultDuration=2352003]="DefaultDuration",er[er.Video=224]="Video",er[er.PixelWidth=176]="PixelWidth",er[er.PixelHeight=186]="PixelHeight",er[er.AlphaMode=21440]="AlphaMode",er[er.Audio=225]="Audio",er[er.SamplingFrequency=181]="SamplingFrequency",er[er.Channels=159]="Channels",er[er.BitDepth=25188]="BitDepth",er[er.SimpleBlock=163]="SimpleBlock",er[er.BlockGroup=160]="BlockGroup",er[er.Block=161]="Block",er[er.BlockAdditions=30113]="BlockAdditions",er[er.BlockMore=166]="BlockMore",er[er.BlockAdditional=165]="BlockAdditional",er[er.BlockAddID=238]="BlockAddID",er[er.BlockDuration=155]="BlockDuration",er[er.ReferenceBlock=251]="ReferenceBlock",er[er.Cluster=524531317]="Cluster",er[er.Timestamp=231]="Timestamp",er[er.Cues=475249515]="Cues",er[er.CuePoint=187]="CuePoint",er[er.CueTime=179]="CueTime",er[er.CueTrackPositions=183]="CueTrackPositions",er[er.CueTrack=247]="CueTrack",er[er.CueClusterPosition=241]="CueClusterPosition",er[er.Colour=21936]="Colour",er[er.MatrixCoefficients=21937]="MatrixCoefficients",er[er.TransferCharacteristics=21946]="TransferCharacteristics",er[er.Primaries=21947]="Primaries",er[er.Range=21945]="Range",er[er.Projection=30320]="Projection",er[er.ProjectionType=30321]="ProjectionType",er[er.ProjectionPoseRoll=30325]="ProjectionPoseRoll",er[er.Attachments=423732329]="Attachments",er[er.AttachedFile=24999]="AttachedFile",er[er.FileDescription=18046]="FileDescription",er[er.FileName=18030]="FileName",er[er.FileMediaType=18016]="FileMediaType",er[er.FileData=18012]="FileData",er[er.FileUID=18094]="FileUID",er[er.Chapters=272869232]="Chapters",er[er.Tags=307544935]="Tags",er[er.Tag=29555]="Tag",er[er.Targets=25536]="Targets",er[er.TargetTypeValue=26826]="TargetTypeValue",er[er.TargetType=25546]="TargetType",er[er.TagTrackUID=25541]="TagTrackUID",er[er.TagEditionUID=25545]="TagEditionUID",er[er.TagChapterUID=25540]="TagChapterUID",er[er.TagAttachmentUID=25542]="TagAttachmentUID",er[er.SimpleTag=26568]="SimpleTag",er[er.TagName=17827]="TagName",er[er.TagLanguage=17530]="TagLanguage",er[er.TagString=17543]="TagString",er[er.TagBinary=17541]="TagBinary",er[er.ContentEncodings=28032]="ContentEncodings",er[er.ContentEncoding=25152]="ContentEncoding",er[er.ContentEncodingOrder=20529]="ContentEncodingOrder",er[er.ContentEncodingScope=20530]="ContentEncodingScope",er[er.ContentCompression=20532]="ContentCompression",er[er.ContentCompAlgo=16980]="ContentCompAlgo",er[er.ContentCompSettings=16981]="ContentCompSettings",er[er.ContentEncryption=20533]="ContentEncryption";const tr=[Zt.EBML,Zt.Segment],rr=[Zt.SeekHead,Zt.Info,Zt.Cluster,Zt.Tracks,Zt.Cues,Zt.Attachments,Zt.Chapters,Zt.Tags],ir=[...tr,...rr],ar=16,sr=e=>{if(e.remainingLength<1)return null;const t=sa(e);if(e.skip(-1),0===t)return null;let r=1,i=128;for(;0===(t&i);)r++,i>>=1;return e.remainingLength<r?null:r},nr=e=>{if(e.remainingLength<1)return null;const t=sa(e);if(0===t)return null;let r=1,i=128;for(;0===(t&i);)r++,i>>=1;if(e.remainingLength<r-1)return null;let a=t&i-1;for(let s=1;s<r;s++)a*=256,a+=sa(e);return a},or=(e,t)=>{if(t<1||t>8)throw new Error("Bad unsigned int size "+t);let r=0;for(let i=0;i<t;i++)r*=256,r+=sa(e);return r},cr=e=>{const t=sr(e);if(null===t)return null;if(e.remainingLength<t)return null;return or(e,t)},lr=e=>{if(e.remainingLength<1)return null;if(255===sa(e))return;e.skip(-1);const t=nr(e);return null===t?null:72057594037927940!==t?t:void 0},dr=e=>{t(e.remainingLength>=2);const r=cr(e);if(null===r)return null;const i=lr(e);return null==Line truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
var Cr,_r,Br,Er,Fr,Dr;(_r=Cr||(Cr={}))[_r.None=0]="None",_r[_r.Xiph=1]="Xiph",_r[_r.FixedSize=2]="FixedSize",_r[_r.Ebml=3]="Ebml",(Er=Br||(Br={}))[Er.Block=1]="Block",Er[Er.Private=2]="Private",Er[Er.Next=4]="Next",(Dr=Fr||(Fr={}))[Dr.Zlib=0]="Zlib",Dr[Dr.Bzlib=1]="Bzlib",Dr[Dr.lzo1x=2]="lzo1x",Dr[Dr.HeaderStripping=3]="HeaderStripping";const Ar=[{id:Zt.SeekHead,flag:"seekHeadSeen"},{id:Zt.Info,flag:"infoSeen"},{id:Zt.Tracks,flag:"tracksSeen"},{id:Zt.Cues,flag:"cuesSeen"}],Rr=10485760;class Mr extends Ke{constructor(e){super(e),this.readMetadataPromise=null,this.segments=[],this.currentSegment=null,this.currentTrack=null,this.currentCluster=null,this.currentBlock=null,this.currentBlockAdditional=null,this.currentCueTime=null,this.currentDecodingInstruction=null,this.currentTagTargetIsMovie=!0,this.currentSimpleTagName=null,this.currentAttachedFile=null,this.isWebM=!1,this.reader=e._reader}async computeDuration(){const e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getTracks(){return await this.readMetadata(),this.segments.flatMap(e=>e.tracks.map(e=>e.inputTrack))}async getMimeType(){await this.readMetadata();const e=await this.getTracks(),t=await Promise.all(e.map(e=>e.getCodecParameterString()));return(e=>{let t=(e.hasVideo?"video/":e.hasAudio?"audio/":"application/")+(e.isWebM?"webm":"x-matroska");e.codecStrings.length>0&&(t+=`; codecs="${[...new Set(e.codecStrings.filter(Boolean))].join(", ")}"`);return t})({isWebM:this.isWebM,hasVideo:this.segments.some(e=>e.tracks.some(e=>"video"===e.info?.type)),hasAudio:this.segments.some(e=>e.tracks.some(e=>"audio"===e.info?.type)),codecStrings:t.filter(Boolean)})}async getMetadataTags(){await this.readMetadata();for(const t of this.segments)t.metadataTagsCollected||(null!==this.reader.fileSize&&await this.loadSegmentMetadata(t),t.metadataTagsCollected=!0);let e={};for(const t of this.segments)e={...e,...t.metadataTags};return e}readMetadata(){return this.readMetadataPromise??(this.readMetadataPromise=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,2,ar);if(t instanceof Promise&&(t=await t),!t)break;const r=dr(t);if(!r)break;const a=r.id;let s=r.size;const n=t.filePos;if(a===Zt.EBML){xr(s);let e=this.reader.requestSlice(n,s);if(e instanceof Promise&&(e=await e),!e)break;this.readContiguousElements(e)}else if(a===Zt.Segment){if(await this.readSegment(n,s),void 0===s)break;if(null===this.reader.fileSize)break}else if(a===Zt.Cluster){if(null===this.reader.fileSize)break;if(void 0===s){s=(await fr(this.reader,n,ir,this.reader.fileSize)).pos-n}const e=i(this.segments);e&&(e.elementEndPos=n+s)}xr(s),e=n+s}})())}async readSegment(e,t){this.currentSegment={seekHeadSeen:!1,infoSeen:!1,tracksSeen:!1,cuesSeen:!1,tagsSeen:!1,attachmentsSeen:!1,timestampScale:-1,timestampFactor:-1,duration:-1,seekEntries:[],tracks:[],cuePoints:[],dataStartPos:e,elementEndPos:void 0===t?null:e+t,clusterSeekStartPos:e,lastReadCluster:null,metadataTags:{},metadataTagsCollected:!1},this.segments.push(this.currentSegment);let r=e;for(;null===this.currentSegment.elementEndPos||r<this.currentSegment.elementEndPos;){let e=this.reader.requestSliceRange(r,2,ar);if(e instanceof Promise&&(e=await e),!e)break;const t=r,i=dr(e);if(!i||!rr.includes(i.id)&&i.id!==Zt.Void){const e=await pr(this.reader,t,rr,Math.min(this.currentSegment.elementEndPos??1/0,t+Rr));if(e){r=e;continue}break}const{id:a,size:s}=i,n=e.filePos,o=Ar.findIndex(e=>e.id===a);if(-1!==o){const e=Ar[o].flag;this.currentSegment[e]=!0,xr(s);let t=this.reader.requestSlice(n,s);t instanceof Promise&&(t=await t),t&&this.readContiguousElements(t)}else if(a===Zt.Tags||a===Zt.Attachments){a===Zt.Tags?this.currentSegment.tagsSeen=!0:this.currentSegment.attachmentsSeen=!0,xr(s);let e=this.reader.requestSlice(n,s);e instanceof Promise&&(e=await e),e&&this.readContiguousElements(e)}else if(a===Zt.Cluster){this.currentSegment.clusterSeekStartPos=t;break}if(void 0===s)break;r=n+s}if(this.currentSegment.seekEntries.sort((e,t)=>e.segmentPosition-t.segmentPosition),null!==this.reader.fileSize)for(const n of this.currentSegment.seekEntries){const t=Ar.find(e=>e.id===n.id);if(!t)continue;if(this.currentSegment[t.flag])continue;let r=this.reader.requestSliceRange(e+n.segmentPosition,2,ar);if(r instanceof Promise&&(r=await r),!r)continue;const i=dr(r);if(!i)continue;const{id:a,size:s}=i;if(a!==t.id)continue;xr(s),this.currentSegment[t.flag]=!0;let o=this.reader.requestSlice(r.filePos,s);o instanceof Promise&&(o=await o),o&&this.readContiguousElements(o)}-1===this.currentSegment.timestampScale&&(this.currentSegment.timestampScale=1e6,this.currentSegment.timestampFactor=1e3);for(const n of this.currentSegment.tracks)null!==n.defaultDurationNs&&(n.defaultDuration=this.currentSegment.timestampFactor*n.defaultDurationNs/1e9);this.currentSegment.tracks.sort((e,t)=>Number(t.disposition.default)-Number(e.disposition.default));const i=new Map(this.currentSegment.tracks.map(e=>[e.id,e]));for(const n
Line truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/const Lr=[44100,48e3,32e3],Ur=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1,-1,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1,-1,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,32,48,56,64,80,96,112,128,144,160,176,192,224,256,-1],Vr=(e,t)=>{const r=e>>>24,i=e>>>16&255,a=e>>>8&255,s=255&e;if(255!==r&&255!==i&&255!==a&&255!==s)return{header:null,bytesAdvanced:4};if(255!==r)return{header:null,bytesAdvanced:1};if(224!==(224&i))return{header:null,bytesAdvanced:1};let n=0,o=0;16&i?n=8&i?0:1:(n=1,o=1);const c=i>>3&3,l=i>>1&3,d=(a>>2&3)%3,u=s>>6&3,h=s>>4&3,m=s>>3&1,f=s>>2&1,p=3&s,g=Ur[16*n*4+16*l+(a>>4&15)];if(-1===g)return{header:null,bytesAdvanced:1};const k=1e3*g,b=Lr[d]>>n+o,T=((e,t,r,i,a)=>0===t?0:1===t?Math.floor(144*r/(i<<e))+a:2===t?Math.floor(144*r/i)+a:4*(Math.floor(12*r/i)+a))(n,l,k,b,a>>1&1);if(null!==t&&t<T)return{header:null,bytesAdvanced:1};let y;return y=3===c?3===l?384:1152:3===l?384:2===l?1152:576,{header:{totalSize:T,mpegVersionId:c,layer:l,bitrate:k,frequencyIndex:d,sampleRate:b,channel:u,modeExtension:h,copyright:m,original:f,emphasis:p,audioSamplesInFrame:y},bytesAdvanced:1}},qr=e=>{let t=2130706432,r=0;for(;0!==t;)r>>=1,r|=e&t,t>>=8;return r};
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
var Hr,Wr,jr,Kr;(Wr=Hr||(Hr={}))[Wr.Unsynchronisation=128]="Unsynchronisation",Wr[Wr.ExtendedHeader=64]="ExtendedHeader",Wr[Wr.ExperimentalIndicator=32]="ExperimentalIndicator",Wr[Wr.Footer=16]="Footer",(Kr=jr||(jr={}))[Kr.ISO_8859_1=0]="ISO_8859_1",Kr[Kr.UTF_16_WITH_BOM=1]="UTF_16_WITH_BOM",Kr[Kr.UTF_16_BE_NO_BOM=2]="UTF_16_BE_NO_BOM",Kr[Kr.UTF_8=3]="UTF_8";const $r=128,Qr=["Blues","Classic rock","Country","Dance","Disco","Funk","Grunge","Hip-hop","Jazz","Metal","New age","Oldies","Other","Pop","Rhythm and blues","Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska","Death metal","Pranks","Soundtrack","Euro-techno","Ambient","Trip-hop","Vocal","Jazz & funk","Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound clip","Gospel","Noise","Alternative rock","Bass","Soul","Punk","Space","Meditative","Instrumental pop","Instrumental rock","Ethnic","Gothic","Darkwave","Techno-industrial","Electronic","Pop-folk","Eurodance","Dream","Southern rock","Comedy","Cult","Gangsta","Top 40","Christian rap","Pop/funk","Jungle music","Native US","Cabaret","New wave","Psychedelic","Rave","Showtunes","Trailer","Lo-fi","Tribal","Acid punk","Acid jazz","Polka","Retro","Musical","Rock 'n' roll","Hard rock","Folk","Folk rock","National folk","Swing","Fast fusion","Bebop","Latin","Revival","Celtic","Bluegrass","Avantgarde","Gothic rock","Progressive rock","Psychedelic rock","Symphonic rock","Slow rock","Big band","Chorus","Easy listening","Acoustic","Humour","Speech","Chanson","Opera","Chamber music","Sonata","Symphony","Booty bass","Primus","Porn groove","Satire","Slow jam","Club","Tango","Samba","Folklore","Ballad","Power ballad","Rhythmic Soul","Freestyle","Duet","Punk rock","Drum solo","A cappella","Euro-house","Dance hall","Goa music","Drum & bass","Club-house","Hardcore techno","Terror","Indie","Britpop","Negerpunk","Polsk punk","Beat","Christian gangsta rap","Heavy metal","Black metal","Crossover","Contemporary Christian","Christian rock","Merengue","Salsa","Thrash metal","Anime","Jpop","Synthpop","Christmas","Art rock","Baroque","Bhangra","Big beat","Breakbeat","Chillout","Downtempo","Dub","EBM","Eclectic","Electro","Electroclash","Emo","Experimental","Garage","Global","IDM","Illbient","Industro-Goth","Jam Band","Krautrock","Leftfield","Lounge","Math rock","New romantic","Nu-breakz","Post-punk","Post-rock","Psytrance","Shoegaze","Space rock","Trop rock","World music","Neoclassical","Audiobook","Audio theatre","Neue Deutsche Welle","Podcast","Indie rock","G-Funk","Dubstep","Garage rock","Psybient"],Gr=(e,t)=>{const r=aa(e,t),i=Q(r.indexOf(0),r.length),a=r.subarray(0,i);let s="";for(let n=0;n<a.length;n++)s+=String.fromCharCode(a[n]);return s.trimEnd()},Xr=e=>{const t=e.filePos,r=ya(e,3),i=sa(e),a=sa(e),s=sa(e),n=ua(e);if("ID3"!==r||255===i||255===a||0!==(2155905152&n))return e.filePos=t,null;return{majorVersion:i,revision:a,flags:s,size:qr(n)}},Yr=(e,t,r)=>{var i,a,s,n;if(![2,3,4].includes(t.majorVersion))return void console.warn(`Unsupported ID3v2 major version: ${t.majorVersion}`);const o=aa(e,t.size),c=new Jr(t,o);if(t.flags&Hr.Footer&&c.removeFooter(),t.flags&Hr.Unsynchronisation&&3===t.majorVersion&&c.ununsynchronizeAll(),t.flags&Hr.ExtendedHeader){const e=c.readU32();3===t.majorVersion?c.pos+=e:c.pos+=e-4}for(;c.pos<=c.bytes.length-c.frameHeaderSize();){const e=c.readId3V2Frame();if(!e)break;const o=c.pos,l=c.pos+e.size;let d=!1,u=!1,h=!1;if(3===t.majorVersion?(d=!!(64&e.flags),u=!!(128&e.flags)):4===t.majorVersion&&(d=!!(4&e.flags),u=!!(8&e.flags),h=!!(2&e.flags)||!!(t.flags&Hr.Unsynchronisation)),d)console.warn(`Skipping encrypted ID3v2 frame ${e.id}`),c.pos=l;else if(u)console.warn(`Skipping compressed ID3v2 frame ${e.id}`),c.pos=l;else{switch(h&&c.ununsynchronizeRegion(c.pos,l),r.raw??(r.raw={}),"T"===e.id[0]?(i=r.raw)[a=e.id]??(i[a]=c.readId3V2EncodingAndText(l)):(s=r.raw)[n=e.id]??(s[n]=c.readBytes(e.size)),c.pos=o,e.id){case"TIT2":case"TT2":r.title??(r.title=c.readId3V2EncodingAndText(l));break;case"TIT3":case"TT3":r.description??(r.description=c.readId3V2EncodingAndText(l));break;case"TPE1":case"TP1":r.artist??(r.artist=c.readId3V2EncodingAndText(l));break;case"TALB":case"TAL":r.album??(r.album=c.readId3V2EncodingAndText(l));break;case"TPE2":case"TP2":r.albumArtist??(r.albumArtist=c.readId3V2EncodingAndText(l));break;case"TRCK":case"TRK":{const e=c.readId3V2EncodingAndText(l).split("/"),t=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(r.trackNumber??(r.trackNumber=t)),i&&Number.isInteger(i)&&i>0&&(r.tracksTotal??(r.tracksTotal=i))}break;case"TPOS":case"TPA":{const e=c.readId3V2EncodingAndText(l).split("/"),t=Number.parseInt(e[0],10),i=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&(r.discNumber??(r.discNumber=t)),i&&Number.isInteger(i)&&i>0&&(r.discsTotal??(r.discsTotal=i))}break;case"TCON":case"TCO":{const e=c.readId3V2EncodingAndText(l);let t=/^\((\d+)\)/.exec(e);if(t){const e=Number.parseInt(t[1]);if(void 0!==Qr[e]){r.genre??(r.genrLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/const Zr=async(e,t,r)=>{let i=t;for(;null===r||i<r;){let t=e.requestSlice(i,4);if(t instanceof Promise&&(t=await t),!t)break;const r=ua(t),a=Vr(r,null!==e.fileSize?e.fileSize-i:null);if(a.header)return{header:a.header,startPos:i};i+=a.bytesAdvanced}return null};
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/class ei extends Ke{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.tracks=[],this.readingMutex=new b,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??(this.metadataPromise=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();if(!this.firstFrameHeader)throw new Error("No valid MP3 frame found.");this.tracks=[new Mt(this.input,new ti(this))]})())}async advanceReader(){if(0===this.lastLoadedPos)for(;;){let e=this.reader.requestSlice(this.lastLoadedPos,10);if(e instanceof Promise&&(e=await e),!e)return void(this.lastSampleLoaded=!0);const t=Xr(e);if(!t)break;this.lastLoadedPos=e.filePos+t.size}const e=await Zr(this.reader,this.lastLoadedPos,this.reader.fileSize);if(!e)return void(this.lastSampleLoaded=!0);const t=e.header;this.lastLoadedPos=e.startPos+t.totalSize-1;const r=(i=t.mpegVersionId,a=t.channel,3===i?3===a?21:36:3===a?13:21);var i,a;let s=this.reader.requestSlice(e.startPos+r,4);if(s instanceof Promise&&(s=await s),s){const e=ua(s);if(1483304551===e||1231971951===e)return}this.firstFrameHeader||(this.firstFrameHeader=t),t.sampleRate!==this.firstFrameHeader.sampleRate&&console.warn(`MP3 changed sample rate mid-file: ${this.firstFrameHeader.sampleRate} Hz to ${t.sampleRate} Hz. Might be a bug, so please report this file.`);const n=t.audioSamplesInFrame/this.firstFrameHeader.sampleRate,o={timestamp:this.nextTimestampInSamples/this.firstFrameHeader.sampleRate,duration:n,dataStart:e.startPos,dataSize:t.totalSize};this.loadedSamples.push(o),this.nextTimestampInSamples+=t.audioSamplesInFrame}async getMimeType(){return"audio/mpeg"}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){await this.readMetadata();const e=this.tracks[0];return t(e),e.computeDuration()}async getMetadataTags(){const e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let e=0,r=!1;for(;;){let t=this.reader.requestSlice(e,10);if(t instanceof Promise&&(t=await t),!t)break;const i=Xr(t);if(!i)break;r=!0;let a=this.reader.requestSlice(t.filePos,i.size);if(a instanceof Promise&&(a=await a),!a)break;Yr(a,i,this.metadataTags),e=t.filePos+i.size}if(!r&&null!==this.reader.fileSize&&this.reader.fileSize>=$r){let e=this.reader.requestSlice(this.reader.fileSize-$r,$r);e instanceof Promise&&(e=await e),t(e);"TAG"===ya(e,3)&&((e,t)=>{var r;const i=e.filePos;t.raw??(t.raw={}),(r=t.raw).TAG??(r.TAG=aa(e,125)),e.filePos=i;const a=Gr(e,30);a&&(t.title??(t.title=a));const s=Gr(e,30);s&&(t.artist??(t.artist=s));const n=Gr(e,30);n&&(t.album??(t.album=n));const o=Gr(e,4),c=Number.parseInt(o,10);Number.isInteger(c)&&c>0&&(t.date??(t.date=new Date(c,0,1)));const l=aa(e,30);let d;if(0===l[28]&&0!==l[29]){const r=l[29];r>0&&(t.trackNumber??(t.trackNumber=r)),e.skip(-30),d=Gr(e,28),e.skip(2)}else e.skip(-30),d=Gr(e,30);d&&(t.comment??(t.comment=d));const u=sa(e);u<Qr.length&&(t.genre??(t.genre=Qr[u]))})(e,this.metadataTags)}return this.metadataTags}finally{e()}}}class ti{constructor(e){this.demuxer=e}getId(){return 1}async getFirstTimestamp(){return 0}getTimeResolution(){return t(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate/this.demuxer.firstFrameHeader.audioSamplesInFrame}async computeDuration(){const e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return null}getLanguageCode(){return D}getCodec(){return"mp3"}getInternalCodecId(){return null}getNumberOfChannels(){return t(this.demuxer.firstFrameHeader),3===this.demuxer.firstFrameHeader.channel?1:2}getSampleRate(){return t(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate}getDisposition(){return{...te}}async getDecoderConfig(){return t(this.demuxer.firstFrameHeader),{codec:"mp3",numberOfChannels:3===this.demuxer.firstFrameHeader.channel?1:2,sampleRate:this.demuxer.firstFrameHeader.sampleRate}}async getPacketAtIndex(e,t){if(-1===e)return null;const r=this.demuxer.loadedSamples[e];if(!r)return null;let i;if(t.metadataOnly)i=Ge;else{let e=this.demuxer.reader.requestSlice(r.dataStart,r.dataSize);if(e instanceof Promise&&(e=await e),!e)return null;i=aa(e,r.dataSize)}return new Xe(i,"key",r.timestamp,r.duration,e,r.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,t){const r=await this.demuxer.readingMutex.acquire();try{const r=w(this.demuxer.loadedSamples,e.timestamp,e=>e.timestamp);if(-1===r)throw new Error("Packet was not created from this track.");const i=r+1;for(;i>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(i,t)}finally{r()}}async getPacket(e,t){const r=await this.demuxer.readingMutex.acquire();try{for(;;){const r=S(this.demuxer.loadedSamples,e,e=>e.timestamp);if(-Line truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/const ri=1399285583,ii=new Uint32Array(256);for(let xa=0;xa<256;xa++){let e=xa<<24;for(let t=0;t<8;t++)e=2147483648&e?e<<1^79764919:e<<1;ii[xa]=e>>>0&4294967295}const ai=e=>{const t=c(e),r=t.getUint32(22,!0);t.setUint32(22,0,!0);let i=0;for(let a=0;a<e.length;a++){const t=e[a];i=(i<<8^ii[i>>>24^t])>>>0}return t.setUint32(22,r,!0),i},si=(e,r,i)=>{let a=0,s=null;if(e.length>0)if("vorbis"===r.codec){t(r.vorbisInfo);const n=(1<<(e=>{let t=0;for(;e;)t++,e>>=1;return t})(r.vorbisInfo.modeBlockflags.length-1))-1<<1,o=(e[0]&n)>>1;if(o>=r.vorbisInfo.modeBlockflags.length)throw new Error("Invalid mode number.");let c=i;const l=r.vorbisInfo.modeBlockflags[o];if(s=r.vorbisInfo.blocksizes[l],1===l){const t=1+(1|n),i=e[0]&t?1:0;c=r.vorbisInfo.blocksizes[i]}a=null!==c?c+s>>2:0}else if("opus"===r.codec){a=(e=>{const t=e[0]>>3;return{durationInSamples:Ue[t]}})(e).durationInSamples}return{durationInSamples:a,vorbisBlockSize:s}},ni=27,oi=282,ci=e=>{const t=e.filePos;if(ha(e)!==ri)return null;e.skip(1);const r=sa(e),i=ka(e),a=ha(e),s=ha(e),n=ha(e),o=sa(e),c=new Uint8Array(o);for(let u=0;u<o;u++)c[u]=sa(e);const l=27+o,d=c.reduce((e,t)=>e+t,0);return{headerStartPos:t,totalSize:l+d,dataStartPos:t+l,dataSize:d,headerType:r,granulePosition:i,serialNumber:a,sequenceNumber:s,checksum:n,lacingValues:c}},li=(e,t)=>{for(;e.filePos<t-3;){const t=ha(e),r=79;if((255&t)===r||(t>>>8&255)===r||(t>>>16&255)===r||(t>>>24&255)===r){if(e.skip(-4),t===ri)return!0;e.skip(1)}}return!1};
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
class di extends Ke{constructor(e){super(e),this.metadataPromise=null,this.bitstreams=[],this.tracks=[],this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??(this.metadataPromise=(async()=>{let e=0;for(;;){let t=this.reader.requestSliceRange(e,ni,oi);if(t instanceof Promise&&(t=await t),!t)break;const r=ci(t);if(!r)break;if(!!!(2&r.headerType))break;this.bitstreams.push({serialNumber:r.serialNumber,bosPage:r,description:null,numberOfChannels:-1,sampleRate:-1,codecInfo:{codec:null,vorbisInfo:null,opusInfo:null},lastMetadataPacket:null}),e=r.headerStartPos+r.totalSize}for(const t of this.bitstreams){const e=await this.readPacket(t.bosPage,0);e&&(e.data.byteLength>=7&&1===e.data[0]&&118===e.data[1]&&111===e.data[2]&&114===e.data[3]&&98===e.data[4]&&105===e.data[5]&&115===e.data[6]?await this.readVorbisMetadata(e,t):e.data.byteLength>=8&&79===e.data[0]&&112===e.data[1]&&117===e.data[2]&&115===e.data[3]&&72===e.data[4]&&101===e.data[5]&&97===e.data[6]&&100===e.data[7]&&await this.readOpusMetadata(e,t),null!==t.codecInfo.codec&&this.tracks.push(new Mt(this.input,new ui(t,this))))}})())}async readVorbisMetadata(e,t){let r=await this.findNextPacketStart(e);if(!r)return;const i=await this.readPacket(r.startPage,r.startSegmentIndex);if(!i)return;if(r=await this.findNextPacketStart(i),!r)return;const a=await this.readPacket(r.startPage,r.startSegmentIndex);if(!a)return;if(3!==i.data[0]||5!==a.data[0])return;const s=[],n=e=>{for(;s.push(Math.min(255,e)),!(e<255);)e-=255};n(e.data.length),n(i.data.length);const o=new Uint8Array(1+s.length+e.data.length+i.data.length+a.data.length);o[0]=2,o.set(s,1),o.set(e.data,1+s.length),o.set(i.data,1+s.length+e.data.length),o.set(a.data,1+s.length+e.data.length+i.data.length),t.codecInfo.codec="vorbis",t.description=o,t.lastMetadataPacket=a;const l=c(e.data);t.numberOfChannels=l.getUint8(11),t.sampleRate=l.getUint32(12,!0);const d=l.getUint8(28);t.codecInfo.vorbisInfo={blocksizes:[1<<(15&d),1<<(d>>4)],modeBlockflags:Ve(a.data).modeBlockflags},je(i.data.subarray(7),this.metadataTags)}async readOpusMetadata(e,t){const r=await this.findNextPacketStart(e);if(!r)return;const i=await this.readPacket(r.startPage,r.startSegmentIndex);if(!i)return;t.codecInfo.codec="opus",t.description=e.data,t.lastMetadataPacket=i;const a=(e=>{const t=c(e),r=t.getUint8(9),i=t.getUint16(10,!0),a=t.getUint32(12,!0),s=t.getInt16(16,!0),n=t.getUint8(18);let o=null;return n&&(o=e.subarray(19,21+r)),{outputChannelCount:r,preSkip:i,inputSampleRate:a,outputGain:s,channelMappingFamily:n,channelMappingTable:o}})(e.data);t.numberOfChannels=a.outputChannelCount,t.sampleRate=ue,t.codecInfo.opusInfo={preSkip:a.preSkip},je(i.data.subarray(8),this.metadataTags)}async readPacket(e,r){t(r<e.lacingValues.length);let i=0;for(let t=0;t<r;t++)i+=e.lacingValues[t];let a=e,s=i,n=r;const o=[];e:for(;;){let r=this.reader.requestSlice(a.dataStartPos,a.dataSize);r instanceof Promise&&(r=await r),t(r);const c=aa(r,a.dataSize);for(;;){if(n===a.lacingValues.length){o.push(c.subarray(i,s));break}const e=a.lacingValues[n];if(s+=e,e<255){o.push(c.subarray(i,s));break e}n++}let l=a.headerStartPos+a.totalSize;for(;;){let t=this.reader.requestSliceRange(l,ni,oi);if(t instanceof Promise&&(t=await t),!t)return null;const r=ci(t);if(!r)return null;if(a=r,a.serialNumber===e.serialNumber)break;l=a.headerStartPos+a.totalSize}i=0,s=0,n=0}const c=o.reduce((e,t)=>e+t.length,0);if(0===c)return null;const l=new Uint8Array(c);let d=0;for(let t=0;t<o.length;t++){const e=o[t];l.set(e,d),d+=e.length}return{data:l,endPage:a,endSegmentIndex:n}}async findNextPacketStart(e){if(e.endSegmentIndex<e.endPage.lacingValues.length-1)return{startPage:e.endPage,startSegmentIndex:e.endSegmentIndex+1};if(!!(4&e.endPage.headerType))return null;let t=e.endPage.headerStartPos+e.endPage.totalSize;for(;;){let r=this.reader.requestSliceRange(t,ni,oi);if(r instanceof Promise&&(r=await r),!r)return null;const i=ci(r);if(!i)return null;if(i.serialNumber===e.endPage.serialNumber)return{startPage:i,startSegmentIndex:0};t=i.headerStartPos+i.totalSize}}async getMimeType(){await this.readMetadata();return(e=>{let t="audio/ogg";e.codecStrings&&(t+=`; codecs="${[...new Set(e.codecStrings)].join(", ")}"`);return t})({codecStrings:(await Promise.all(this.tracks.map(e=>e.getCodecParameterString()))).filter(Boolean)})}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){const e=await this.getTracks(),t=await Promise.all(e.map(e=>e.computeDuration()));return Math.max(0,...t)}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}}class ui{constructor(e,t){this.bitstream=e,this.demuxer=t,this.encodedPacketToMetadata=new WeakMap,this.sequentialScanCache=[],this.sequentialScanMutex=new b,this.internalSampleRate="opus"===e.codecInfo.codec?ue:e.sampleRate}getId(){return this.bitstream.serialNumber}getNumberOfChannels(){return this.bitstream.numberOfChannels}getSampleRate(){return this.bitstream.sampleRateLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
var fi,pi;(pi=fi||(fi={}))[pi.PCM=1]="PCM",pi[pi.IEEE_FLOAT=3]="IEEE_FLOAT",pi[pi.ALAW=6]="ALAW",pi[pi.MULAW=7]="MULAW",pi[pi.EXTENSIBLE=65534]="EXTENSIBLE";class gi extends Ke{constructor(e){super(e),this.metadataPromise=null,this.dataStart=-1,this.dataSize=-1,this.audioInfo=null,this.tracks=[],this.lastKnownPacketIndex=0,this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??(this.metadataPromise=(async()=>{let e=this.reader.requestSlice(0,12);e instanceof Promise&&(e=await e),t(e);const r=ya(e,4),i="RIFX"!==r,a="RF64"===r,s=da(e,i);let n=a?this.reader.fileSize:Math.min(s+8,this.reader.fileSize??1/0);if("WAVE"!==ya(e,4))throw new Error("Invalid WAVE file - wrong format");let o=0,c=null,l=e.filePos;for(;null===n||l<n;){let e=this.reader.requestSlice(l,8);if(e instanceof Promise&&(e=await e),!e)break;const t=ya(e,4),r=da(e,i),s=e.filePos;if(a&&0===o&&"ds64"!==t)throw new Error('Invalid RF64 file: First chunk must be "ds64".');if("fmt "===t)await this.parseFmtChunk(s,r,i);else if("data"===t){if(c??(c=r),this.dataStart=e.filePos,this.dataSize=Math.min(c,(n??1/0)-this.dataStart),null===this.reader.fileSize)break}else if("ds64"===t){let e=this.reader.requestSlice(s,r);if(e instanceof Promise&&(e=await e),!e)break;const t=fa(e,i);c=fa(e,i),n=Math.min(t+8,this.reader.fileSize??1/0)}else"LIST"===t?await this.parseListChunk(s,r,i):"ID3 "!==t&&"id3 "!==t||await this.parseId3Chunk(s,r);l=s+r+(1&r),o++}if(!this.audioInfo)throw new Error('Invalid WAVE file - missing "fmt " chunk');if(-1===this.dataStart)throw new Error('Invalid WAVE file - missing "data" chunk');const d=this.audioInfo.blockSizeInBytes;this.dataSize=Math.floor(this.dataSize/d)*d,this.tracks.push(new Mt(this.input,new bi(this)))})())}async parseFmtChunk(e,t,r){let i=this.reader.requestSlice(e,t);if(i instanceof Promise&&(i=await i),!i)return;let a=na(i,r);const s=na(i,r),n=da(i,r);i.skip(4);const o=na(i,r);let c;if(c=14===t?8:na(i,r),t>=18&&357!==a){const e=na(i,r),s=t-18;if(Math.min(s,e)>=22&&a===fi.EXTENSIBLE){i.skip(6);const e=aa(i,16);a=e[0]|e[1]<<8}}a!==fi.MULAW&&a!==fi.ALAW||(c=8),this.audioInfo={format:a,numberOfChannels:s,sampleRate:n,sampleSizeInBytes:Math.ceil(c/8),blockSizeInBytes:o}}async parseListChunk(e,t,r){var i,a,s,n,o,c,l,d,u,h,m;let f=this.reader.requestSlice(e,t);if(f instanceof Promise&&(f=await f),!f)return;const p=ya(f,4);if("INFO"!==p&&"INF0"!==p)return;let g=f.filePos;for(;g<=e+t-8;){f.filePos=g;const e=ya(f,4),t=da(f,r),p=aa(f,t);let k=0;for(let r=0;r<p.length&&0!==p[r];r++)k++;const b=String.fromCharCode(...p.subarray(0,k));switch((i=this.metadataTags).raw??(i.raw={}),this.metadataTags.raw[e]=b,e){case"INAM":case"TITL":(a=this.metadataTags).title??(a.title=b);break;case"TIT3":(s=this.metadataTags).description??(s.description=b);break;case"IART":(n=this.metadataTags).artist??(n.artist=b);break;case"IPRD":(o=this.metadataTags).album??(o.album=b);break;case"IPRT":case"ITRK":case"TRCK":{const e=b.split("/"),t=Number.parseInt(e[0],10),r=e[1]&&Number.parseInt(e[1],10);Number.isInteger(t)&&t>0&&((c=this.metadataTags).trackNumber??(c.trackNumber=t)),r&&Number.isInteger(r)&&r>0&&((l=this.metadataTags).tracksTotal??(l.tracksTotal=r))}break;case"ICRD":case"IDIT":{const e=new Date(b);Number.isNaN(e.getTime())||((d=this.metadataTags).date??(d.date=e))}break;case"YEAR":{const e=Number.parseInt(b,10);Number.isInteger(e)&&e>0&&((u=this.metadataTags).date??(u.date=new Date(e,0,1)))}break;case"IGNR":case"GENR":(h=this.metadataTags).genre??(h.genre=b);break;case"ICMT":case"CMNT":case"COMM":(m=this.metadataTags).comment??(m.comment=b)}g+=8+t+(1&t)}}async parseId3Chunk(e,t){let r=this.reader.requestSlice(e,t);if(r instanceof Promise&&(r=await r),!r)return;const i=Xr(r);if(i){const t=r.slice(e+10,i.size);Yr(t,i,this.metadataTags)}}getCodec(){if(t(this.audioInfo),this.audioInfo.format===fi.MULAW)return"ulaw";if(this.audioInfo.format===fi.ALAW)return"alaw";if(this.audioInfo.format===fi.PCM){if(1===this.audioInfo.sampleSizeInBytes)return"pcm-u8";if(2===this.audioInfo.sampleSizeInBytes)return"pcm-s16";if(3===this.audioInfo.sampleSizeInBytes)return"pcm-s24";if(4===this.audioInfo.sampleSizeInBytes)return"pcm-s32"}return this.audioInfo.format===fi.IEEE_FLOAT&&4===this.audioInfo.sampleSizeInBytes?"pcm-f32":null}async getMimeType(){return"audio/wav"}async computeDuration(){await this.readMetadata();const e=this.tracks[0];return t(e),e.computeDuration()}async getTracks(){return await this.readMetadata(),this.tracks}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}}const ki=2048;class bi{constructor(e){this.demuxer=e}getId(){return 1}getCodec(){return this.demuxer.getCodec()}getInternalCodecId(){return t(this.demuxer.audioInfo),this.demuxer.audioInfo.format}async getDecoderConfig(){const e=this.demuxer.getCodec();return e?(t(this.demuxer.audioInfo),{codec:e,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate}):null}async computeDuration(){const e=Line truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/const Ti=e=>{const t=e.filePos,r=aa(e,9),i=new a(r);if(4095!==i.readBits(12))return null;i.skipBits(1);if(0!==i.readBits(2))return null;const s=i.readBits(1),n=i.readBits(2)+1,o=i.readBits(4);if(15===o)return null;i.skipBits(1);const c=i.readBits(3);if(0===c)throw new Error("ADTS frames with channel configuration 0 are not supported.");i.skipBits(1),i.skipBits(1),i.skipBits(1),i.skipBits(1);const l=i.readBits(13);i.skipBits(11);const d=i.readBits(2)+1;if(1!==d)throw new Error("ADTS frames with more than one AAC frame are not supported.");let u=null;return 1===s?e.filePos-=2:u=i.readBits(16),{objectType:n,samplingFrequencyIndex:o,channelConfiguration:c,frameLength:l,numberOfAacFrames:d,crcCheck:u,startPos:t}},yi=1024;class wi extends Ke{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.tracks=[],this.readingMutex=new b,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??(this.metadataPromise=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();t(this.firstFrameHeader),this.tracks=[new Mt(this.input,new Si(this))]})())}async advanceReader(){let e=this.reader.requestSliceRange(this.lastLoadedPos,7,9);if(e instanceof Promise&&(e=await e),!e)return void(this.lastSampleLoaded=!0);const r=Ti(e);if(!r)return void(this.lastSampleLoaded=!0);if(null!==this.reader.fileSize&&r.startPos+r.frameLength>this.reader.fileSize)return void(this.lastSampleLoaded=!0);this.firstFrameHeader||(this.firstFrameHeader=r);const i=ce[r.samplingFrequencyIndex];t(void 0!==i);const a=yi/i,s=r.crcCheck?9:7,n={timestamp:this.nextTimestampInSamples/i,duration:a,dataStart:r.startPos+s,dataSize:r.frameLength-s};this.loadedSamples.push(n),this.nextTimestampInSamples+=yi,this.lastLoadedPos=r.startPos+r.frameLength}async getMimeType(){return"audio/aac"}async getTracks(){return await this.readMetadata(),this.tracks}async computeDuration(){await this.readMetadata();const e=this.tracks[0];return t(e),e.computeDuration()}async getMetadataTags(){return{}}}class Si{constructor(e){this.demuxer=e}getId(){return 1}async getFirstTimestamp(){return 0}getTimeResolution(){return this.getSampleRate()/yi}async computeDuration(){const e=await this.getPacket(1/0,{metadataOnly:!0});return(e?.timestamp??0)+(e?.duration??0)}getName(){return null}getLanguageCode(){return D}getCodec(){return"aac"}getInternalCodecId(){return t(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.objectType}getNumberOfChannels(){t(this.demuxer.firstFrameHeader);const e=le[this.demuxer.firstFrameHeader.channelConfiguration];return t(void 0!==e),e}getSampleRate(){t(this.demuxer.firstFrameHeader);const e=ce[this.demuxer.firstFrameHeader.samplingFrequencyIndex];return t(void 0!==e),e}getDisposition(){return{...te}}async getDecoderConfig(){t(this.demuxer.firstFrameHeader);const e=new Uint8Array(3),r=new a(e),{objectType:i,samplingFrequencyIndex:s,channelConfiguration:n}=this.demuxer.firstFrameHeader;return i>31?(r.writeBits(5,31),r.writeBits(6,i-32)):r.writeBits(5,i),r.writeBits(4,s),r.writeBits(4,n),{codec:`mp4a.40.${this.demuxer.firstFrameHeader.objectType}`,numberOfChannels:this.getNumberOfChannels(),sampleRate:this.getSampleRate(),description:e.subarray(0,Math.ceil((r.pos-1)/8))}}async getPacketAtIndex(e,t){if(-1===e)return null;const r=this.demuxer.loadedSamples[e];if(!r)return null;let i;if(t.metadataOnly)i=Ge;else{let e=this.demuxer.reader.requestSlice(r.dataStart,r.dataSize);if(e instanceof Promise&&(e=await e),!e)return null;i=aa(e,r.dataSize)}return new Xe(i,"key",r.timestamp,r.duration,e,r.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,t){const r=await this.demuxer.readingMutex.acquire();try{const r=w(this.demuxer.loadedSamples,e.timestamp,e=>e.timestamp);if(-1===r)throw new Error("Packet was not created from this track.");const i=r+1;for(;i>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(i,t)}finally{r()}}async getPacket(e,t){const r=await this.demuxer.readingMutex.acquire();try{for(;;){const r=S(this.demuxer.loadedSamples,e,e=>e.timestamp);if(-1===r&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded)return this.getPacketAtIndex(r,t);if(r>=0&&r+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(r,t);await this.demuxer.advanceReader()}}finally{r()}}getKeyPacket(e,t){return this.getPacket(e,t)}getNextKeyPacket(e,t){return this.getNextPacket(e,t)}}
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
class Ii extends Ke{constructor(e){super(e),this.loadedSamples=[],this.metadataPromise=null,this.track=null,this.metadataTags={},this.audioInfo=null,this.lastLoadedPos=null,this.blockingBit=null,this.readingMutex=new b,this.lastSampleLoaded=!1,this.reader=e._reader}async computeDuration(){return await this.readMetadata(),t(this.track),this.track.computeDuration()}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}async getTracks(){return await this.readMetadata(),t(this.track),[this.track]}async getMimeType(){return"audio/flac"}async readMetadata(){let e=4;return this.metadataPromise??(this.metadataPromise=(async()=>{for(var r;null===this.reader.fileSize||e<this.reader.fileSize;){let i=this.reader.requestSlice(e,4);if(i instanceof Promise&&(i=await i),e+=4,null===i)throw new Error(`Metadata block at position ${e} is too small! Corrupted file.`);t(i);const s=sa(i),n=ca(i),o=0!==(128&s);switch(127&s){case He.STREAMINFO:{let r=this.reader.requestSlice(e,n);if(r instanceof Promise&&(r=await r),t(r),null===r)throw new Error(`StreamInfo block at position ${e} is too small! Corrupted file.`);const i=aa(r,34),s=new a(i),o=s.readBits(16),c=s.readBits(16),l=s.readBits(24),d=s.readBits(24),u=s.readBits(20),h=s.readBits(3)+1;s.readBits(5);const m=s.readBits(36);s.skipBits(128);const f=new Uint8Array(42);f.set(new Uint8Array([102,76,97,67]),0),f.set(new Uint8Array([128,0,0,34]),4),f.set(i,8),this.audioInfo={numberOfChannels:h,sampleRate:u,totalSamples:m,minimumBlockSize:o,maximumBlockSize:c,minimumFrameSize:l,maximumFrameSize:d,description:f},this.track=new Mt(this.input,new vi(this));break}case He.VORBIS_COMMENT:{let r=this.reader.requestSlice(e,n);r instanceof Promise&&(r=await r),t(r),je(aa(r,n),this.metadataTags);break}case He.PICTURE:{let i=this.reader.requestSlice(e,n);i instanceof Promise&&(i=await i),t(i);const a=ua(i),s=ua(i),o=l.decode(aa(i,s)),c=ua(i),d=l.decode(aa(i,c));i.skip(16);const u=ua(i),h=aa(i,u);(r=this.metadataTags).images??(r.images=[]),this.metadataTags.images.push({data:h,mimeType:o,kind:3===a?"coverFront":4===a?"coverBack":"unknown",description:d});break}}if(e+=n,o){this.lastLoadedPos=e;break}}})())}async readNextFlacFrame({startPos:e,isFirstPacket:r}){t(this.audioInfo);const i=this.audioInfo.maximumFrameSize+16,a=await this.reader.requestSliceRange(e,this.audioInfo.minimumFrameSize,i);if(!a)return null;const s=this.readFlacFrameHeader({slice:a,isFirstPacket:r});if(!s)return null;for(a.filePos=e+this.audioInfo.minimumFrameSize;;){if(a.filePos>a.end-6)return{num:s.num,blockSize:s.blockSize,sampleRate:s.sampleRate,size:a.end-e,isLastFrame:!0};if(255===sa(a)){const t=a.filePos;if(sa(a)!==(1===this.blockingBit?249:248)){a.filePos=t;continue}a.skip(-2);const r=a.filePos-e,i=this.readFlacFrameHeader({slice:a,isFirstPacket:!1});if(!i){a.filePos=t;continue}if(0===this.blockingBit){if(i.num-s.num!==1){a.filePos=t;continue}}else if(i.num-s.num!==s.blockSize){a.filePos=t;continue}return{num:s.num,blockSize:s.blockSize,sampleRate:s.sampleRate,size:r,isLastFrame:!1}}}}readFlacFrameHeader({slice:e,isFirstPacket:r}){const i=e.filePos,s=aa(e,4),n=new a(s);if(32764!==n.readBits(15))return null;if(null===this.blockingBit){t(r);const e=n.readBits(1);this.blockingBit=e}else if(1===this.blockingBit){t(!r);if(1!==n.readBits(1))return null}else{if(0!==this.blockingBit)throw new Error("Invalid blocking bit");t(!r);if(0!==n.readBits(1))return null}const o=(e=>0===e?null:1===e?192:e>=2&&e<=5?144*2**e:6===e?"uncommon-u8":7===e?"uncommon-u16":e>=8&&e<=15?2**e:null)(n.readBits(4));if(!o)return null;t(this.audioInfo);const c=((e,t)=>{switch(e){case 0:return t;case 1:return 88200;case 2:return 176400;case 3:return 192e3;case 4:return 8e3;case 5:return 16e3;case 6:return 22050;case 7:return 24e3;case 8:return 32e3;case 9:return 44100;case 10:return 48e3;case 11:return 96e3;case 12:return"uncommon-u8";case 13:return"uncommon-u16";case 14:return"uncommon-u16-10";default:return null}})(n.readBits(4),this.audioInfo.sampleRate);if(!c)return null;n.readBits(4),n.readBits(3);if(0!==n.readBits(1))return null;const l=(e=>{let t=0;const r=new a(aa(e,1));for(;1===r.readBits(1);)t++;if(0===t)return r.readBits(7);const i=[],s=t-1,n=new a(aa(e,s)),o=8-t-1;for(let a=0;a<o;a++)i.unshift(r.readBits(1));for(let a=0;a<s;a++)for(let e=0;e<8;e++){const t=n.readBits(1);e<2||i.unshift(t)}return i.reduce((e,t,r)=>e|t<<r,0)})(e),d=((e,r)=>"uncommon-u16"===r?oa(e)+1:"uncommon-u8"===r?sa(e)+1:"number"===typeof r?r:(C(r),void t(!1)))(e,o),u=((e,t)=>"uncommon-u16"===t?oa(e):"uncommon-u16-10"===t?10*oa(e):"uncommon-u8"===t?sa(e):"number"===typeof t?t:null)(e,c);if(null===u)return null;if(u!==this.audioInfo.sampleRate)return null;const h=e.filePos-i,m=sa(e);e.skip(-h),e.skip(-1);const f=(e=>{let t=0;for(const r of e){t^=r;for(let e=0;e<8;e++)0!==(128&t)?t=t<<1^7:t<<=1,t&=255}return t})(aa(e,h));return m!==f?null:{num:l,blockSize:d,sampleRate:u}}async advanceReader(){await this.readMetadata(),t(null!==this.lastLoadedPos),t(this.audiLine truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/class Pi{}class xi extends Pi{async _getMajorBrand(e){let t=e._reader.requestSlice(0,12);if(t instanceof Promise&&(t=await t),!t)return null;t.skip(4);return"ftyp"!==ya(t,4)?null:ya(t,4)}_createDemuxer(e){return new qt(e)}}class Ci extends xi{async _canReadInput(e){const t=await this._getMajorBrand(e);return!!t&&"qt "!==t}get name(){return"MP4"}get mimeType(){return"video/mp4"}}class _i extends xi{async _canReadInput(e){return"qt "===await this._getMajorBrand(e)}get name(){return"QuickTime File Format"}get mimeType(){return"video/quicktime"}}class Bi extends Pi{async isSupportedEBMLOfDocType(e,t){let r=e._reader.requestSlice(0,ar);if(r instanceof Promise&&(r=await r),!r)return!1;const i=sr(r);if(null===i)return!1;if(i<1||i>8)return!1;if(or(r,i)!==Zt.EBML)return!1;const a=lr(r);if("number"!==typeof a)return!1;let s=e._reader.requestSlice(r.filePos,a);if(s instanceof Promise&&(s=await s),!s)return!1;const n=r.filePos;for(;s.filePos<=n+a-2;){const e=dr(s);if(!e)break;const{id:r,size:i}=e,a=s.filePos;if(void 0===i)return!1;switch(r){case Zt.EBMLVersion:if(1!==or(s,i))return!1;break;case Zt.EBMLReadVersion:if(1!==or(s,i))return!1;break;case Zt.DocType:if(ur(s,i)!==t)return!1;break;case Zt.DocTypeVersion:if(or(s,i)>4)return!1}s.filePos=a+i}return!0}_canReadInput(e){return this.isSupportedEBMLOfDocType(e,"matroska")}_createDemuxer(e){return new Mr(e)}get name(){return"Matroska"}get mimeType(){return"video/x-matroska"}}class Ei extends Bi{_canReadInput(e){return this.isSupportedEBMLOfDocType(e,"webm")}get name(){return"WebM"}get mimeType(){return"video/webm"}}class Fi extends Pi{async _canReadInput(e){let t=e._reader.requestSlice(0,10);if(t instanceof Promise&&(t=await t),!t)return!1;let r=0,i=!1;for(;;){let t=e._reader.requestSlice(r,10);if(t instanceof Promise&&(t=await t),!t)break;const a=Xr(t);if(!a)break;i=!0,r=t.filePos+a.size}const a=await Zr(e._reader,r,r+4096);if(!a)return!1;if(i)return!0;r=a.startPos+a.header.totalSize;const s=await Zr(e._reader,r,r+4);if(!s)return!1;const n=a.header,o=s.header;return n.channel===o.channel&&n.sampleRate===o.sampleRate}_createDemuxer(e){return new ei(e)}get name(){return"MP3"}get mimeType(){return"audio/mpeg"}}class Di extends Pi{async _canReadInput(e){let t=e._reader.requestSlice(0,12);if(t instanceof Promise&&(t=await t),!t)return!1;const r=ya(t,4);if("RIFF"!==r&&"RIFX"!==r&&"RF64"!==r)return!1;t.skip(4);return"WAVE"===ya(t,4)}_createDemuxer(e){return new gi(e)}get name(){return"WAVE"}get mimeType(){return"audio/wav"}}class Ai extends Pi{async _canReadInput(e){let t=e._reader.requestSlice(0,4);return t instanceof Promise&&(t=await t),!!t&&"OggS"===ya(t,4)}_createDemuxer(e){return new di(e)}get name(){return"Ogg"}get mimeType(){return"application/ogg"}}class Ri extends Pi{async _canReadInput(e){let t=e._reader.requestSlice(0,4);return t instanceof Promise&&(t=await t),!!t&&"fLaC"===ya(t,4)}get name(){return"FLAC"}get mimeType(){return"audio/flac"}_createDemuxer(e){return new Ii(e)}}class Mi extends Pi{async _canReadInput(e){let t=e._reader.requestSliceRange(0,7,9);if(t instanceof Promise&&(t=await t),!t)return!1;const r=Ti(t);if(!r)return!1;if(t=e._reader.requestSliceRange(r.frameLength,7,9),t instanceof Promise&&(t=await t),!t)return!1;const i=Ti(t);return!!i&&(r.objectType===i.objectType&&r.samplingFrequencyIndex===i.samplingFrequencyIndex&&r.channelConfiguration===i.channelConfiguration)}_createDemuxer(e){return new wi(e)}get name(){return"ADTS"}get mimeType(){return"audio/aac"}}const Ni=new Ci,zi=new _i,Oi=new Bi,Li=new Ei,Ui=new Fi,Vi=new Di,qi=new Ai,Hi=new Mi,Wi=[Ni,zi,Oi,Li,Vi,qi,new Ri,Ui,Hi];
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
class ji{constructor(){this._disposed=!1,this._sizePromise=null,this.onread=null}async getSizeOrNull(){if(this._disposed)throw new ea;return this._sizePromise??(this._sizePromise=Promise.resolve(this._retrieveSize()))}async getSize(){if(this._disposed)throw new ea;const e=await this.getSizeOrNull();if(null===e)throw new Error("Cannot determine the size of an unsized source.");return e}}class Ki extends ji{constructor(e,t={}){if(!(e instanceof Blob))throw new TypeError("blob must be a Blob.");if(!t||"object"!==typeof t)throw new TypeError("options must be an object.");if(void 0!==t.maxCacheSize&&(!J(t.maxCacheSize)||t.maxCacheSize<0))throw new TypeError("options.maxCacheSize, when provided, must be a non-negative number.");super(),this._readers=new WeakMap,this._blob=e,this._orchestrator=new Ji({maxCacheSize:t.maxCacheSize??8388608,maxWorkerCount:4,runWorker:this._runWorker.bind(this),prefetchProfile:Yi.fileSystem})}_retrieveSize(){const e=this._blob.size;return this._orchestrator.fileSize=e,e}_read(e,t){return this._orchestrator.read(e,t)}async _runWorker(e){let t=this._readers.get(e);if(void 0===t){if("stream"in this._blob&&!q()){t=this._blob.slice(e.currentPos).stream().getReader()}else t=null;this._readers.set(e,t)}for(;e.currentPos<e.targetPos&&!e.aborted;)if(t){const{done:r,value:i}=await t.read();if(r)throw this._orchestrator.forgetWorker(e),new Error("Blob reader stopped unexpectedly before all requested data was read.");if(e.aborted)break;this.onread?.(e.currentPos,e.currentPos+i.length),this._orchestrator.supplyWorkerData(e,i)}else{const t=await this._blob.slice(e.currentPos,e.targetPos).arrayBuffer();if(e.aborted)break;this.onread?.(e.currentPos,e.currentPos+t.byteLength),this._orchestrator.supplyWorkerData(e,new Uint8Array(t))}e.running=!1,e.aborted&&await(t?.cancel())}_dispose(){this._orchestrator.dispose()}}const $i=524288,Qi=(e,t,r)=>{if(t instanceof Error&&(t.message.includes("Failed to fetch")||t.message.includes("Load failed")||t.message.includes("NetworkError when attempting to fetch resource"))){let e=null;try{"undefined"!==typeof window&&"undefined"!==typeof window.location&&(e=new URL(r instanceof Request?r.url:r,window.location.href).origin)}catch{}if(("undefined"===typeof navigator||"boolean"!==typeof navigator.onLine||navigator.onLine)&&null!==e&&e!==window.location.origin)return console.warn("Request will not be retried because a CORS error was suspected due to different origins. You can modify this behavior by providing your own function for the 'getRetryDelay' option."),null}return Math.min(2**(e-2),16)};class Gi extends ji{constructor(e,t={}){if("string"!==typeof e&&!(e instanceof URL)&&!("undefined"!==typeof Request&&e instanceof Request))throw new TypeError("url must be a string, URL or Request.");if(!t||"object"!==typeof t)throw new TypeError("options must be an object.");if(void 0!==t.requestInit&&(!t.requestInit||"object"!==typeof t.requestInit))throw new TypeError("options.requestInit, when provided, must be an object.");if(void 0!==t.getRetryDelay&&"function"!==typeof t.getRetryDelay)throw new TypeError("options.getRetryDelay, when provided, must be a function.");if(void 0!==t.maxCacheSize&&(!J(t.maxCacheSize)||t.maxCacheSize<0))throw new TypeError("options.maxCacheSize, when provided, must be a non-negative number.");if(void 0!==t.fetchFn&&"function"!==typeof t.fetchFn)throw new TypeError("options.fetchFn, when provided, must be a function.");super(),this._existingResponses=new WeakMap,this._url=e,this._options=t,this._getRetryDelay=t.getRetryDelay??Qi,this._orchestrator=new Ji({maxCacheSize:t.maxCacheSize??67108864,maxWorkerCount:2,runWorker:this._runWorker.bind(this),prefetchProfile:Yi.network})}async _retrieveSize(){const e=new AbortController,t=await L(this._options.fetchFn??fetch,this._url,z(this._options.requestInit??{},{headers:{Range:"bytes=0-"},signal:e.signal}),this._getRetryDelay,()=>this._disposed);if(!t.ok)throw new Error(`Error fetching ${String(this._url)}: ${t.status} ${t.statusText}`);let r,i;if(206===t.status)i=this._getTotalLengthFromRangeResponse(t),r=this._orchestrator.createWorker(0,Math.min(i,$i));else{const e=t.headers.get("Content-Length");if(!e)throw new Error(`HTTP response (status ${t.status}) must surface Content-Length header.`);i=Number(e),r=this._orchestrator.createWorker(0,i),this._orchestrator.options.maxCacheSize=1/0,console.warn("HTTP server did not respond with 206 Partial Content, meaning the entire remote resource now has to be downloaded. For efficient media file streaming across a network, please make sure your server supports range requests.")}return this._orchestrator.fileSize=i,this._existingResponses.set(r,{response:t,abortController:e}),this._orchestrator.runWorker(r),i}_read(e,t){return this._orchestrator.read(e,t)}async _runWorker(e){for(;;){const i=this._existingResponses.get(e);this._existingResponses.delete(e);let a=i?.abortController,s=i?.response;if(a||(a=new AbortController,s=await L(this._options.fetchFn??fetch,this.Line truncated
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/Y();class Zi{get disposed(){return this._disposed}constructor(e){if(this._demuxerPromise=null,this._format=null,this._disposed=!1,!e||"object"!==typeof e)throw new TypeError("options must be an object.");if(!Array.isArray(e.formats)||e.formats.some(e=>!(e instanceof Pi)))throw new TypeError("options.formats must be an array of InputFormat.");if(!(e.source instanceof ji))throw new TypeError("options.source must be a Source.");if(e.source._disposed)throw new Error("options.source must not be disposed.");this._formats=e.formats,this._source=e.source,this._reader=new ta(e.source)}_getDemuxer(){return this._demuxerPromise??(this._demuxerPromise=(async()=>{this._reader.fileSize=await this._source.getSizeOrNull();for(const e of this._formats){if(await e._canReadInput(this))return this._format=e,e._createDemuxer(this)}throw new Error("Input has an unsupported or unrecognizable format.")})())}get source(){return this._source}async getFormat(){return await this._getDemuxer(),t(this._format),this._format}async computeDuration(){return(await this._getDemuxer()).computeDuration()}async getTracks(){return(await this._getDemuxer()).getTracks()}async getVideoTracks(){return(await this.getTracks()).filter(e=>e.isVideoTrack())}async getAudioTracks(){return(await this.getTracks()).filter(e=>e.isAudioTrack())}async getPrimaryVideoTrack(){return(await this.getTracks()).find(e=>e.isVideoTrack())??null}async getPrimaryAudioTrack(){return(await this.getTracks()).find(e=>e.isAudioTrack())??null}async getMimeType(){return(await this._getDemuxer()).getMimeType()}async getMetadataTags(){return(await this._getDemuxer()).getMetadataTags()}dispose(){this._disposed||(this._disposed=!0,this._source._disposed=!0,this._source._dispose())}[Symbol.dispose](){this.dispose()}}class ea extends Error{constructor(e="Input has been disposed."){super(e),this.name="InputDisposedError"}}
|
||||
/*!
|
||||
* Copyright (c) 2025-present, Vanilagy and contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/class ta{constructor(e){this.source=e}requestSlice(e,t){if(this.source._disposed)throw new ea;if(null!==this.fileSize&&e+t>this.fileSize)return null;const r=e+t,i=this.source._read(e,r);return i instanceof Promise?i.then(t=>t?new ra(t.bytes,t.view,t.offset,e,r):null):i?new ra(i.bytes,i.view,i.offset,e,r):null}requestSliceRange(e,r,i){if(this.source._disposed)throw new ea;if(null!==this.fileSize)return this.requestSlice(e,F(this.fileSize-e,r,i));{const a=this.requestSlice(e,i),s=a=>{if(a)return a;const s=a=>(t(null!==a),this.requestSlice(e,F(a-e,r,i))),n=this.source._retrieveSize();return n instanceof Promise?n.then(s):s(n)};return a instanceof Promise?a.then(s):s(a)}}}class ra{constructor(e,t,r,i,a){this.bytes=e,this.view=t,this.offset=r,this.start=i,this.end=a,this.bufferPos=i-r}static tempFromBytes(e){return new ra(e,c(e),0,0,e.length)}get length(){return this.end-this.start}get filePos(){return this.offset+this.bufferPos}set filePos(e){this.bufferPos=e-this.offset}get remainingLength(){return Math.max(this.end-this.filePos,0)}skip(e){this.bufferPos+=e}slice(e,t=this.end-e){if(e<this.start||e+t>this.end)throw new RangeError("Slicing outside of original slice.");return new ra(this.bytes,this.view,this.offset,e,e+t)}}const ia=(e,t)=>{if(e.filePos<e.start||e.filePos+t>e.end)throw new RangeError(`Tried reading [${e.filePos}, ${e.filePos+t}), but slice is [${e.start}, ${e.end}). This is likely an internal error, please report it alongside the file that caused it.`)},aa=(e,t)=>{ia(e,t);const r=e.bytes.subarray(e.bufferPos,e.bufferPos+t);return e.bufferPos+=t,r},sa=e=>(ia(e,1),e.view.getUint8(e.bufferPos++)),na=(e,t)=>{ia(e,2);const r=e.view.getUint16(e.bufferPos,t);return e.bufferPos+=2,r},oa=e=>{ia(e,2);const t=e.view.getUint16(e.bufferPos,!1);return e.bufferPos+=2,t},ca=e=>{ia(e,3);const t=_(e.view,e.bufferPos,!1);return e.bufferPos+=3,t},la=e=>{ia(e,2);const t=e.view.getInt16(e.bufferPos,!1);return e.bufferPos+=2,t},da=(e,t)=>{ia(e,4);const r=e.view.getUint32(e.bufferPos,t);return e.bufferPos+=4,r},ua=e=>{ia(e,4);const t=e.view.getUint32(e.bufferPos,!1);return e.bufferPos+=4,t},ha=e=>{ia(e,4);const t=e.view.getUint32(e.bufferPos,!0);return e.bufferPos+=4,t},ma=e=>{ia(e,4);const t=e.view.getInt32(e.bufferPos,!1);return e.bufferPos+=4,t},fa=(e,t)=>{let r,i;return t?(r=da(e,!0),i=da(e,!0)):(i=da(e,!1),r=da(e,!1)),4294967296*i+r},pa=e=>4294967296*ua(e)+ua(e),ga=e=>4294967296*ma(e)+ua(e),ka=e=>{const t=ha(e),r=(e=>{ia(e,4);const t=e.view.getInt32(e.bufferPos,!0);return e.bufferPos+=4,t})(e);return 4294967296*r+t},ba=e=>{ia(e,4);const t=e.view.getFloat32(e.bufferPos,!1);return e.bufferPos+=4,t},Ta=e=>{ia(e,8);const t=e.view.getFloat64(e.bufferPos,!1);return e.bufferPos+=8,t},ya=(e,t)=>{ia(e,t);let r="";for(let i=0;i<t;i++)r+=String.fromCharCode(e.bytes[e.bufferPos++]);return r};class wa{constructor(e){this.events=e,this.input=null,this.audioSink=null,this.audioIterator=null,this.audioContext=null,this.gainNode=null,this.audioContextStartTime=0,this.playbackTimeAtStart=0,this.latestScheduledEndTime=0,this.duration=Number.NaN,this.paused=!0,this.volume=.7,this.muted=!1,this.playbackRate=1,this.asyncId=0,this.queuedNodes=new Set}get currentTime(){return this.paused?this.playbackTimeAtStart:(this.audioContext.currentTime-this.audioContextStartTime)*this.playbackRate+this.playbackTimeAtStart}normalizeSource(e){return"string"===typeof e?new Gi(e):e instanceof Blob?new Ki(e):"undefined"!==typeof ReadableStream&&e instanceof ReadableStream?new Xi(e):e}ensureAudioContext(e){if(this.audioContext)return;const t=window.AudioContext||window.webkitAudioContext;try{this.audioContext=new t({sampleRate:e})}catch{this.audioContext=new t}this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination),this.updateGain()}updateGain(){if(!this.gainNode)return;const e=this.muted?0:this.volume;this.gainNode.gain.value=e*e}stopQueuedNodes(){this.queuedNodes.forEach(e=>e.stop()),this.queuedNodes.clear()}async stopIterator(){await(this.audioIterator?.return()),this.audioIterator=null}async load(e,t){const r=++this.asyncId;await this.stopIterator(),this.stopQueuedNodes(),this.paused=!0,this.playbackTimeAtStart=0,this.audioContextStartTime=0;const i=this.normalizeSource(e);if(!i)return;if(this.input=new Zi({source:i,formats:Wi}),this.duration=await this.input.computeDuration(),r!==this.asyncId)return;const a=await this.input.getPrimaryAudioTrack();return a&&null!==a.codec&&await a.canDecode()?(this.ensureAudioContext(a.sampleRate),this.audioSink=new Dt(a),void t?.()):(this.audioSink=null,this.ensureAudioContext(),void t?.())}async runIterator(e){if(this.audioSink)for(await this.stopIterator(),this.audioIterator=this.audioSink.buffers(this.currentTime);;){if(e!==this.asyncId||this.paused)return;const r=this.audioIterator.next(),i=setInterval(()=>{e!==this.asyncId||this.paused?clearInterval(i):"running"===this.audioContext.state&&this.audioContext.currentTime>=this.latestScheduledEndTime-.2&&(this.audioConLine truncated
|
||||
!function(e,t){"object"===typeof exports&&"undefined"!==typeof module?module.exports=t():"function"==typeof define&&define.amd?(t.ArtplayerProxyMediabunny=t(),define(function(){return t.ArtplayerProxyMediabunny})):(e="undefined"!==typeof globalThis?globalThis:e||self).ArtplayerProxyMediabunny=t()}(this,function(){"use strict";class e{constructor(){this.listeners=new Map}addEventListener(e,t){this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t)}removeEventListener(e,t){const r=this.listeners.get(e);if(!r)return;const i=r.indexOf(t);i>=0&&r.splice(i,1)}emit(e,t){const r=new Event(e);r.detail=t;const i=this.listeners.get(e);i&&i.forEach(e=>e(r))}}function t(e){if(!e)throw new Error("Assertion failed.")}const r=e=>{const t=(e%360+360)%360;if(0===t||90===t||180===t||270===t)return t;throw new Error(`Invalid rotation ${e}.`)},i=e=>e&&e[e.length-1];class a{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){const e=Math.floor(this.pos/8),t=this.bytes[e]??0,r=7-(7&this.pos),i=(t&1<<r)>>r;return this.pos++,i}readBits(e){if(1===e)return this.readBit();let t=0;for(let r=0;r<e;r++)t<<=1,t|=this.readBit();return t}writeBits(e,t){const r=this.pos+e;for(let i=this.pos;i<r;i++){const e=Math.floor(i/8);let a=this.bytes[e];const s=7-(7&i);a&=~(1<<s),a|=(t&1<<r-i-1)>>r-i-1<<s,this.bytes[e]=a}this.pos=r}readAlignedByte(){if(this.pos%8!==0)throw new Error("Bitstream is not byte-aligned.");const e=this.pos/8,t=this.bytes[e]??0;return this.pos+=8,t}skipBits(e){this.pos+=e}getBitsLeft(){return 8*this.bytes.length-this.pos}clone(){const e=new a(this.bytes);return e.pos=this.pos,e}}const s=e=>{let t=0;for(;0===e.readBits(1)&&t<32;)t++;if(t>=32)throw new Error("Invalid exponential-Golomb code.");return(1<<t)-1+e.readBits(t)},n=e=>{const t=s(e);return 0===(1&t)?-(t>>1):t+1>>1},o=e=>e.constructor===Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),c=e=>e.constructor===DataView?e:ArrayBuffer.isView(e)?new DataView(e.buffer,e.byteOffset,e.byteLength):new DataView(e),l=new TextDecoder,d=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[t,e])),u={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},h=d(u),m={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},f=d(m),p={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},g=d(p),k=e=>e instanceof ArrayBuffer||"undefined"!==typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e);class b{constructor(){this.currentPromise=Promise.resolve()}async acquire(){let e;const t=new Promise(t=>{e=t}),r=this.currentPromise;return this.currentPromise=t,await r,e}}const T=e=>[...e].map(e=>e.toString(16).padStart(2,"0")).join(""),y=e=>(e=(e=(e=(e=(e=e>>1&1431655765|(1431655765&e)<<1)>>2&858993459|(858993459&e)<<2)>>4&252645135|(252645135&e)<<4)>>8&16711935|(16711935&e)<<8)>>16&65535|(65535&e)<<16)>>>0,w=(e,t,r)=>{let i=0,a=e.length-1,s=-1;for(;i<=a;){const n=i+a>>1,o=r(e[n]);o===t?(s=n,a=n-1):o<t?i=n+1:a=n-1}return s},S=(e,t,r)=>{let i=0,a=e.length-1,s=-1;for(;i<=a;){const n=i+(a-i+1)/2|0;r(e[n])<=t?(s=n,i=n+1):a=n-1}return s},I=(e,t,r)=>{const i=S(e,r(t),r);e.splice(i+1,0,t)},v=()=>{let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}},P=(e,t)=>{for(let r=e.length-1;r>=0;r--)if(t(e[r]))return e[r]},x=(e,t)=>{for(let r=e.length-1;r>=0;r--)if(t(e[r]))return r;return-1},C=e=>{throw new Error(`Unexpected value: ${e}`)},_=(e,t,r)=>{const i=e.getUint8(t),a=e.getUint8(t+1),s=e.getUint8(t+2);return r?i|a<<8|s<<16:i<<16|a<<8|s},B=(e,t,r,i)=>{r>>>=0,r&=16777215,e.setUint8(t,r>>>16&255),e.setUint8(t+1,r>>>8&255),e.setUint8(t+2,255&r)},E=(e,t)=>({async next(){const r=await e.next();return r.done?{value:void 0,done:!0}:{value:t(r.value),done:!1}},return:()=>e.return(),throw:t=>e.throw(t),[Symbol.asyncIterator](){return this}}),F=(e,t,r)=>Math.max(t,Math.min(r,e)),D="und",A=e=>{const t=Math.round(e);return Math.abs(e/t-1)<10*Number.EPSILON?t:e},R=/^[a-z]{3}$/,M=e=>R.test(e),N=1e6*(1+Number.EPSILON),z=(e,t)=>{const r={...e,...t};if(e.headers||t.headers){const i=e.headers?O(e.headers):{},a=t.headers?O(t.headers):{},s={...i};Object.entries(a).forEach(([e,t])=>{const r=Object.keys(s).find(t=>t.toLowerCase()===e.toLowerCase());r&&delete s[r],s[e]=t}),r.headers=s}return r},O=e=>{if(e instanceof Headers){const t={};return e.forEach((e,r)=>{t[r]=e}),t}if(Array.isArray(e)){const t={};return e.forEach(([e,r])=>{t[e]=r}),t}return e},L=async(e,t,r,i,a)=>{let s=0;for(;;)try{return await e(t,r)}catch(n){if(a())throw n;s++;const e=i(s,n,t);if(null===e)throw n;if(console.error("Retrying failed fetch. Error:",n),!Number.isFinite(e)||e<0)throw new TypeError("Retry delay must be a non-negative finite number.");if(e>0&&await new Promise(t=>setTimeout(t,1e3*e)),a())throw n}};class U{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}}let V=null;const q=()=>null!==V?V:V=!("undefined"===typeof navigator||!(navigator.vendor?Line truncated
|
||||
Reference in new issue
Block a user