1159cl/lib/icecast-metadata-player-1.17.3.mediasource.min.js
Mario1159 5b6b79892c
Some checks failed
Release / test (push) Failing after 51s
Release / push-docker-image (push) Has been skipped
2024 new version
2024-12-06 20:38:18 -03:00

22 lines
10 KiB
JavaScript

/*!
* Copyright 2021-2023 Ethan Halsall
* https://github.com/eshaz/icecast-metadata-js
*
* This file is part of icecast-metadata-player.
*
* icecast-metadata-player free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* icecast-metadata-player distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>
*/
"use strict";(self.webpackChunkIcecastMetadataPlayer=self.webpackChunkIcecastMetadataPlayer||[]).push([[762],{448:(t,e,n)=>{n.r(e),n.d(e,{default:()=>Z});var s=n(317);const i="webm",r="mp3",c="mp4a.40.2",h="flac",o="vorbis",a="opus",w="audio/",d=";codecs=",l=w+"mp4"+d,u=w+i+d,g="mse-audio-wrapper";class m{constructor({name:t,contents:e=[],children:n=[]}){this.t=t,this.i=e,this.h=n}static stringToByteArray(t){return[...t].map((t=>t.charCodeAt(0)))}static getFloat64(t){const e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t),e}static getUint64(t){const e=new Uint8Array(8);return new DataView(e.buffer).setBigUint64(0,BigInt(t)),e}static getUint32(t){const e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t),e}static getUint16(t){const e=new Uint8Array(2);return new DataView(e.buffer).setUint16(0,t),e}static getInt16(t){const e=new Uint8Array(2);return new DataView(e.buffer).setInt16(0,t),e}static*flatten(t){for(const e of t)Array.isArray(e)?yield*m.flatten(e):yield e}get contents(){const t=new Uint8Array(this.length),e=this.o();let n=0;for(const s of m.flatten(e))"object"!=typeof s?(t[n]=s,n++):(t.set(s,n),n+=s.length);return t}get length(){return this.l()}o(){return[this.i,...this.h.map((t=>t.o()))]}l(){let t;return t=Array.isArray(this.i)?this.i.reduce(((t,e)=>t+(void 0===e.length?1:e.length)),0):void 0===this.i.length?1:this.i.length,t+this.h.reduce(((t,e)=>t+e.length),0)}addChild(t){this.h.push(t)}}class f extends m{constructor(t,{contents:e,children:n}={}){super({name:t,contents:e,children:n})}o(){return[...this.u,...m.stringToByteArray(this.t),...super.o()]}l(){return this.m||(this.m=4+this.t.length+super.l(),this.u=m.getUint32(this.m)),this.m}}class p extends m{constructor(t,{contents:e,tags:n}={}){super({name:t,contents:e,children:n})}static getLength(t){const e=m.getUint32(t);return e.every(((t,e,n)=>0===t&&(n[e]=128,!0))),e}o(){return[this.t,...this.u,...super.o()]}l(){if(!this.m){const t=super.l();this.u=p.getLength(t),this.m=1+t+this.u.length}return this.m}addTag(t){this.addChild(t)}}class y{constructor(t){this.p=t}getCodecBox(t){switch(this.p){case r:return this.getMp4a(t,107);case c:return this.getMp4a(t,64);case a:return this.getOpus(t);case h:return this.getFlaC(t)}}getOpus(t){return new f("Opus",{contents:[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channels,0,t.bitDepth,0,0,0,0,f.getUint16(t.sampleRate),0,0],children:[new f("dOps",{contents:[0,t.channels,f.getUint16(t.preSkip),f.getUint32(t.inputSampleRate),f.getInt16(t.outputGain),t.channelMappingFamily,0!==t.channelMappingFamily?[t.streamCount,t.coupledStreamCount,t.channelMappingTable]:[]]})]})}getFlaC(t){return new f("fLaC",{contents:[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channels,0,t.bitDepth,0,0,0,0,f.getUint16(t.sampleRate),0,0],children:[new f("dfLa",{contents:[0,0,0,0,...t.streamInfo||[128,0,0,34,f.getUint16(t.blockSize),f.getUint16(t.blockSize),0,0,0,0,0,0,f.getUint32(t.sampleRate<<12|t.channels<<8|t.bitDepth-1<<4),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]})]})}getMp4a(t,e){const n=new p(4,{contents:[e,21,0,0,0,0,0,0,0,0,0,0,0]});return 64===e&&n.addTag(new p(5,{contents:t.audioSpecificConfig})),new f("mp4a",{contents:[0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channels,0,16,0,0,0,0,f.getUint16(t.sampleRate),0,0],children:[new f("esds",{contents:[0,0,0,0],children:[new p(3,{contents:[0,1,0],tags:[n,new p(6,{contents:2})]})]})]})}getInitializationSegment({header:t,samples:e}){return new m({children:[new f("ftyp",{contents:[f.stringToByteArray("iso5"),0,0,2,0,f.stringToByteArray("iso6mp41")]}),new f("moov",{children:[new f("mvhd",{contents:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,232,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2]}),new f("trak",{children:[new f("tkhd",{contents:[0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0]}),new f("mdia",{children:[new f("mdhd",{contents:[0,0,0,0,0,0,0,0,0,0,0,0,f.getUint32(t.sampleRate),0,0,0,0,85,196,0,0]}),new f("hdlr",{contents:[0,0,0,0,f.stringToByteArray("mhlr"),f.stringToByteArray("soun"),0,0,0,0,0,0,0,0,0,0,0,0,0]}),new f("minf",{children:[new f("stbl",{children:[new f("stsd",{contents:[0,0,0,0,0,0,0,1],children:[this.getCodecBox(t)]}),new f("stts",{contents:[0,0,0,0,0,0,0,0]}),new f("stsc",{contents:[0,0,0,0,0,0,0,0]}),new f("stsz",{contents:[0,0,0,0,0,0,0,0,0,0,0,0]}),new f("stco",{contents:[0,0,0,0,0,0,0,0]})]})]})]})]}),new f("mvex",{children:[new f("trex",{contents:[0,0,0,0,0,0,0,1,0,0,0,1,f.getUint32(e),0,0,0,0,0,0,0,0]})]})]})]}).contents}getSamplesPerFrame(t){return this.p===c?t.map((({data:t,header:e})=>f.getUint32(t.length-e.length))):t.map((({data:t})=>f.getUint32(t.length)))}getFrameData(t){return this.p===c?t.map((({data:t,header:e})=>t.subarray(e.length))):t.map((({data:t})=>t))}getMediaSegment(t){return new m({children:[new f("moof",{children:[new f("mfhd",{contents:[0,0,0,0,0,0,0,0]}),new f("traf",{children:[new f("tfhd",{contents:[0,2,0,0,0,0,0,1]}),new f("tfdt",{contents:[0,0,0,0,0,0,0,0]}),new f("trun",{contents:[0,0,2,1,f.getUint32(t.length),f.getUint32(92+4*t.length),...this.getSamplesPerFrame(t)]})]})]}),new f("mdat",{contents:this.getFrameData(t)})]}).contents}}const b=(...t)=>t.flatMap((t=>{const e=[];for(let n=t.length;n>=0;n-=255)e.push(n>=255?255:n);return e}));class U extends m{constructor(t,{contents:e,children:n,isUnknownLength:s=!1}={}){super({name:t,contents:e,children:n}),this.U=s}static getUintVariable(t){let e;if(t<127)e=[128|t];else if(t<16383)e=m.getUint16(t),e[0]|=64;else if(t<2097151)e=m.getUint32(t).subarray(1),e[0]|=32;else if(t<268435455)e=m.getUint32(t),e[0]|=16;else if(t<34359738367)e=m.getUint64(t).subarray(3),e[0]|=8;else if(t<4398046511103)e=m.getUint64(t).subarray(2),e[0]|=4;else if(t<562949953421311)e=m.getUint64(t).subarray(1),e[0]|=2;else if(t<72057594037927940)e=m.getUint64(t),e[0]|=1;else if("number"!=typeof t||isNaN(t))throw((...t)=>{console.error(g,t.reduce(((t,e)=>t+"\n "+e),""))})(`EBML Variable integer must be a number, instead received ${t}`),new Error(g+": Unable to encode WEBM");return e}o(){return[...this.t,...this.u,...super.o()]}l(){return this.m||(this.A=super.l(),this.u=this.U?[1,255,255,255,255,255,255,255]:U.getUintVariable(this.A),this.m=this.t.length+this.u.length+this.A),this.m}}const A=[225],C=[98,100],$=[159],_=[31,67,182,117],L=[86,170],v=[134],M=[99,162],S=[66,130],V=[66,133],F=[66,135],x=[26,69,223,163],B=[66,242],D=[66,243],k=[66,247],I=[66,134],O=[156],T=[21,73,169,102],z=[77,128],E=[181],N=[86,187],P=[24,83,128,103],R=[163],j=[231],W=[42,215,177],q=[174],G=[215],H=[22,84,174,107],J=[131],K=[115,197],Q=[87,65];class X{constructor(t){switch(t){case a:this.C="A_OPUS",this.$=t=>[new U(L,{contents:U.getUint32(Math.round(t.preSkip*this._))}),new U(N,{contents:U.getUint32(Math.round(3840*this._))}),new U(M,{contents:t.data})];break;case o:this.C="A_VORBIS",this.$=t=>[new U(M,{contents:[2,b(t.data,t.vorbisComments),t.data,t.vorbisComments,t.vorbisSetup]})]}}getInitializationSegment({header:t}){return this._=1e9/t.sampleRate,new m({children:[new U(x,{children:[new U(I,{contents:1}),new U(k,{contents:1}),new U(B,{contents:4}),new U(D,{contents:8}),new U(S,{contents:U.stringToByteArray(i)}),new U(F,{contents:4}),new U(V,{contents:2})]}),new U(P,{isUnknownLength:!0,children:[new U(T,{children:[new U(W,{contents:U.getUint32(Math.floor(this._))}),new U(z,{contents:U.stringToByteArray(g)}),new U(Q,{contents:U.stringToByteArray(g)})]}),new U(H,{children:[new U(q,{children:[new U(G,{contents:1}),new U(K,{contents:1}),new U(O,{contents:0}),new U(v,{contents:U.stringToByteArray(this.C)}),new U(J,{contents:2}),new U(A,{children:[new U($,{contents:t.channels}),new U(E,{contents:U.getFloat64(t.sampleRate)}),new U(C,{contents:t.bitDepth})]}),...this.$(t)]})]})]})]}).contents}getMediaSegment(t){const e=t[0].totalSamples;return new U(_,{children:[new U(j,{contents:U.getUintVariable(e)}),...t.map((({data:t,totalSamples:n})=>new U(R,{contents:[129,U.getInt16(n-e),128,t]})))]}).contents}}const Y=()=>{};class Z{constructor(t,e={}){this.L=t,this.PREFERRED_CONTAINER=e.preferredContainer||i,this.MIN_FRAMES=e.minFramesPerSegment||4,this.MAX_FRAMES=e.maxFramesPerSegment||50,this.MIN_FRAMES_LENGTH=e.minBytesPerSegment||1022,this.MAX_SAMPLES_PER_SEGMENT=1/0,this.v=e.onMimeType||Y,e.codec&&(this.M=this.S(e.codec),this.v(this.V)),this.F=[],this.B=new s.Ay(t,{onCodec:t=>{this.M=this.S(t),this.v(this.V)},onCodecUpdate:e.onCodecUpdate,enableLogging:e.enableLogging,enableFrameCRC32:!1})}get mimeType(){return this.V}get inputMimeType(){return this.L}*iterator(t){t.constructor===Uint8Array?yield*this.D([...this.B.parseChunk(t)].flatMap((t=>t.codecFrames||t))):Array.isArray(t)&&(yield*this.D(t))}*D(t){if(this.F.push(...t),this.F.length){const t=this.k();if(t.length){this.I||(this.I=!0,yield this.M.getInitializationSegment(t[0][0]));for(const e of t)yield this.M.getMediaSegment(e)}}}k(){const t=[[]];let e=t[0],n=0;for(const s of this.F)(e.length===this.MAX_FRAMES||n>=this.MAX_SAMPLES_PER_SEGMENT)&&(n=0,t.push(e=[])),e.push(s),n+=s.samples;return this.F=e.length<this.MIN_FRAMES||e.reduce(((t,e)=>t+e.data.length),0)<this.MIN_FRAMES_LENGTH?t.pop():[],t}S(t){switch(t){case"mpeg":return this.V=`${l}"${r}"`,new y(r);case"aac":return this.V=`${l}"${c}"`,new y(c);case"flac":return this.V=`${l}"${h}"`,new y(h);case"vorbis":return this.V=`${u}"${o}"`,this.MAX_SAMPLES_PER_SEGMENT=32767,new X(o);case"opus":return this.PREFERRED_CONTAINER===i?(this.V=`${u}"${a}"`,this.MAX_SAMPLES_PER_SEGMENT=32767,new X(a)):(this.V=`${l}"${a}"`,new y(a))}}}}}]);
//# sourceMappingURL=icecast-metadata-player-1.17.3.mediasource.min.js.map