pr-player 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +338 -209
- package/dist/index.umd.cjs +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
const A = '(function(){"use strict";class P{pendingPayloads=[];payload=new Uint8Array(0);chunks=[];push=t=>{this.pendingPayloads.push(t)};next=(t=0)=>{this.payload=this.payload.slice(t);const s=this.pendingPayloads.shift();if(!s)return!1;const e=new Uint8Array(this.payload.byteLength+s.byteLength);return e.set(this.payload,0),e.set(s,this.payload.byteLength),this.payload=e,new DataView(this.payload.buffer)};pushChunk=t=>{this.chunks.push(t),this.chunks.length>100&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const I=(y,t)=>{const s=new Uint8Array(y),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let a=0;return n[a++]=1,n[a++]=s[1],n[a++]=s[2],n[a++]=s[3],n[a++]=255,n[a++]=225,n[a++]=s.length>>8&255,n[a++]=s.length&255,n.set(s,a),a+=s.length,n[a++]=1,n[a++]=e.length>>8&255,n[a++]=e.length&255,n.set(e,a),n},T=y=>{let t=0;const s=new DataView(y.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const n=s.getUint8(t)&255;t=t+1;const a=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const c=`avc1.${Array.from([n,a,o],U=>U.toString(16).padStart(2,"0")).join("")}`,r=(s.getUint8(t)&3)-1;t=t+1;const g=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const h=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const d=s.getUint8(t)&31;t=t+1;const u=s.getUint16(t,!1);t=t+2;const f=new Uint8Array(s.buffer.slice(t,t+u));return t=t+u,{version:e,codec:c,profile:n,compatibility:a,level:o,lengthSizeMinusOne:r,numOfSequenceParameterSets:g,sequenceParameterSetLength:p,sps:h,numOfPictureParameterSets:d,pictureParameterSetLength:u,pps:f}},M=y=>{const t=new Uint8Array(4+y.length);return new DataView(t.buffer).setUint32(0,y.length,!1),t.set(y,4),t},C=y=>{let t=0;for(const n of y)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of y){const a=n;s.set(a,e),e+=a.length}return s},D=y=>{let t="unknown";switch(y){case 1:case 2:case 27:case 36:t="video";break;case 3:case 4:case 15:t="audio";break;case 6:t="subtitle";break;case 134:t="ad";break}return t};class x{pat;pmt;audioConfig;videoConfig;payloadMap=new Map;on={};constructor(){}parse=async t=>{let s=0;for(;!(s+188>t.byteLength);){if(t.getInt8(s)!=71){s++;continue}await this.parsePacket(t,s),s+=188}return s};parsePacket=async(t,s)=>{if(s+188>t.byteLength)throw new Error("Invalid TS packet");if(t.getUint8(s)!==71)throw new Error("Invalid TS packet");let e=s;const n=this.parseHeader(t,e);e+=4;const{transport_error_indicator:a,pid:o,payload_unit_start_indicator:l,adaptation_field_control:i}=n;if(a===1||o===void 0)return;let c=184;if(i===2||i===3){const r=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=r,c-=r}if(i===3&&(c-=1),i===1||i===3){const r=new Uint8Array(t.buffer.slice(e,e+c));if(o===0)return this.parsePAT(t,e);{const{programs:h=[]}=this.pat||{};if(h.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(h=>h.elementary_pid===o);if(p){if(l===1){const h=this.payloadMap.get(o);if(h){switch(p.kind){case"audio":{const d=await this.parseAudio(h);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(h);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),0))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const h=this.payloadMap.get(o),d=new Uint8Array(h.byteLength+r.byteLength);d.set(h,0),d.set(r,h.byteLength),this.payloadMap.set(o,d)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),a=t.getUint8(e+1),o=t.getUint8(e+2),l=t.getUint8(e+3),i=(a&128)>>7;if(i===1)return{sync_byte:n,transport_error_indicator:i};const c=(a&64)>>6,r=(a&32)>>5,g=(a&31)<<8|o,p=(l&192)>>6,h=l>>4&3,d=l&15;return{sync_byte:n,transport_error_indicator:i,payload_unit_start_indicator:c,transport_priority:r,pid:g,transport_scrambling_control:p,adaptation_field_control:h,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==0)throw new Error("Invalid PAT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d}}const a=[];{const l=n.section_length-5-4,i=e+l;for(;e<i;){const c=t.getUint16(e),r=t.getUint16(e+2)&8191;e+=4,c!==0&&r>=32&&r<=8190&&a.push({program_number:c,pmt_pid:r})}}const o=t.getUint32(e);this.pat={header:n,programs:a,crc32:o},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==2)throw new Error("Invalid PMT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1;const u=t.getUint16(e)&8191;e+=2;const f=t.getUint16(e)&4095;e+=2,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const l=n.section_length-9-4,i=e+l;for(;e<i;){const c=t.getUint8(e),r=D(c),g=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,g<32||g>8190){console.warn(`Invalid elementary_pid: 0x${g.toString(16)}`);continue}a.push({kind:r,stream_type:c,elementary_pid:g,es_info_length:p})}}const o=t.getUint32(e);this.pmt={header:n,streams:a,crc32:o},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,a,o,l;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),h=!!(i&8),d=!!(i&4),u=!!(i&2),f=!!(i&1);e+=1;const U=(_,b)=>{let m=BigInt(0);m|=BigInt(_.getUint16(b))<<25n,m|=BigInt(_.getUint16(b+1))<<17n,m|=BigInt(_.getUint16(b+2))<<9n,m|=BigInt(_.getUint16(b+3))<<1n,m|=BigInt(_.getUint16(b+4)>>7);const S=(_.getUint16(b+4)&1)<<8|_.getUint16(b+5);return m=m*300n+BigInt(S),m};if(p&&(n=U(t,e),e+=6),h&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,l=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:h,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:l}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts audio payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig&&s.getUint8(e)===255){const g=s.getUint8(e+2),p=s.getUint8(e+3);let h,d;d=g>>2&15,h=(g&1)<<2|p>>6;const u=`mp4a.40.${h}`,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][d];this.audioConfig={kind:"audio",codec:u,sampleRate:U,numberOfChannels:h},this.on.config&&this.on.config(this.audioConfig)}const{dts:o=0,pts:l=0}=n,i=l-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:l,cts:i,data:c}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts video payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let h,d;if(h=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),h&&d){const u=I(h,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:h,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const l=[];let i="delta";for(const h of o){const{type:d,nalu:u}=h;switch(d){case 6:case 9:l.push(u);break;case 1:i="delta",l.push(u);break;case 5:i="key",l.push(u);break}}const c=C(l),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:l}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),l=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(l)&0b11111110n)>>1n;return Number(i)/90}getNalus=t=>{const s=[];let e=0;for(;!(e+4>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}e+=3;let n=e;const a=t[e]&31;for(e+=1;!(e+1>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}break}let o=e-n;if(t[e-1]===0&&(o-=1),o!==0){const l=t.slice(n,n+o),i=M(l);s.push({type:a,nalu:i})}}return s}}const k=(y,t)=>y.getUint8(t)<<16|y.getUint8(t+1)<<8|y.getUint8(t+2);class L{audioConfig;videoConfig;header;textDecoder=new TextDecoder("utf-8");on={};constructor(){}parse=async t=>{let s=0;for(this.header||(this.parseHeader(t,s),s+=9);this.isSurplusTag(t,s)!==!1;){const n=this.parseTagHeader(t,s+4),{tagType:a,dataSize:o,timestamp:l}=n;if(a){const i=this.parseTagBody(a,t,s+4+11,o);switch(a){case"script":this.on.info&&this.on.info(i);break;case"audio":{const{accPacketType:c}=i;if(c===0){const{codec:r,sampleRate:g,channelConfiguration:p}=i;this.audioConfig={kind:"audio",codec:r,sampleRate:g,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:r,data:g}=i,p="key",h=r===void 0?void 0:r+l;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:l,pts:h,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:h}=i;this.videoConfig={kind:"video",codec:r,description:h,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:h}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+l;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:l,pts:u,cts:g,data:p,nalus:h})}}break}s=s+4+11+o}await new Promise(i=>setTimeout(()=>i(!0),8))}return s};parseHeader=(t,s)=>{let e,n,a,o;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const i=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,c,,r]=i;a={audio:r==="1",video:c==="1"}}o=t.getUint32(5),this.header={signature:e,version:n,flags:a,dataOffset:o}};isSurplusTag=(t,s)=>{let e=!0;const n=t.byteLength;if(s+4>n)e=!1;else if(s+4+11>n)e=!1;else{const a=k(t,s+4+1);s+4+11+a>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,a,o,l;{const i=t.getUint8(s);let c;switch(i){case 18:c="script";break;case 8:c="audio";break;case 9:c="video";break}e=c}return n=k(t,s+1),a=k(t,s+4),o=t.getUint8(s+7),l=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:l}};parseTagBody=(t,s,e,n)=>{let a;switch(t){case"script":a=this.parseMetaData(s,e);break;case"audio":a=this.parseAudio(s,e,n);break;case"video":a=this.parseVideo(s,e,n);break}return a};parseMetaData=(t,s)=>{let e=s;{if(t.getUint8(e)!==2)throw new Error("Invalid AMF type for onMetaData (expected 0x02)");e=e+1}const n=t.getUint16(e,!1);e=e+2;{const l=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(l)||"")!=="onMetaData")throw new Error("Expected \'onMetaData\' string");e=e+n}const a=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,a).value};parseAudio=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const h=t.getUint8(n),d=t.getUint8(n+1),u=h>>3&31,f=(h&7)<<1|d>>7,U=d>>3&15,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a&15;n=n+1;const i=t.getUint8(n);n=n+1;const c=k(t,n);n=n+3;const r=e-5,g=new Uint8Array(t.buffer.slice(n,n+r));switch(l){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],h=n+e-5;for(;!(n+4>h);){const d=t.getUint32(n,!1),u=new Uint8Array(t.buffer.slice(n,n+4+d));n+=4+d,p.push(u)}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g}};getAmfType=(t,s)=>t.getUint8(s);getAMFName=(t,s,e)=>{const n=new Uint8Array(t.buffer.slice(s,s+e));return this.textDecoder?.decode(n)||""};getAMFValue=(t,s,e)=>{let n=s,a,o=0;switch(e){case 0:a=t.getFloat64(n,!1),o=8;break;case 1:a=!!t.getUint8(n),o=1;break;case 2:{a="";const i=t.getUint16(n,!1);n=n+2;const c=new Int8Array(t.buffer,n,i).filter(g=>g!==0);a=(this.textDecoder?.decode(c)||"").trim(),o=2+i}break;case 3:for(a={};n<t.byteLength;){const i=t.getUint16(n,!1);if(i===0)break;n=n+2;const c=this.getAMFName(t,n,i);n=n+i;const r=this.getAmfType(t,n);if(r===6)break;n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a[c]=g.value,o=2+i+1+g.length}break;case 8:{a={};const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=t.getUint16(n,!1);n=n+2;const g=this.getAMFName(t,n,r);n=n+r;const p=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,p);n=n+h.length,a[g]=h.value,o=2+r+1+h.length}}break;case 10:{a=[];const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=this.getAmfType(t,n);n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a.push(g.value),o=1+g.length}}break}return{amfType:e,length:o,value:a}}}class O{pattern;cacher=new P;isParseing=!1;offset=0;parser;on={};constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new L;break;case"hls":this.parser=new x;break;default:throw new Error("is error pattern.")}this.parser.on.debug=s=>this.on.debug&&this.on.debug(s),this.parser.on.info=s=>this.on.info&&this.on.info(s),this.parser.on.config=s=>this.on.config&&this.on.config(s),this.parser.on.chunk=s=>{this.cacher.pushChunk(s),this.on.chunk&&this.on.chunk(s)}};push=t=>{this.cacher.push(t),this.isParseing===!1&&this.parse()};destroy=()=>{this.cacher.destroy(),this.isParseing=!1,this.offset=0};parse=async()=>{try{if(this.isParseing=!0,!this.pattern)throw new Error("You need to set the pattern.");if(!this.parser)throw new Error("You need to init parser.");for(;;){const t=this.cacher.next(this.offset);if(this.offset=0,!t)break;this.offset=await this.parser.parse(t)}this.isParseing=!1}catch{this.destroy()}}}const A=new O;A.on.info=y=>postMessage({action:"on.info",data:y}),A.on.config=y=>postMessage({action:"on.config",data:y}),A.on.chunk=y=>postMessage({action:"on.chunk",data:y}),A.on.debug=y=>postMessage({action:"on.debug",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', _ = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", A], { type: "text/javascript;charset=utf-8" });
|
|
2
|
-
function
|
|
1
|
+
const x = '(function(){"use strict";class P{pendingPayloads=[];payload=new Uint8Array(0);chunks=[];push=t=>{this.pendingPayloads.push(t)};next=(t=0)=>{this.payload=this.payload.slice(t);const s=this.pendingPayloads.shift();if(!s)return!1;const e=new Uint8Array(this.payload.byteLength+s.byteLength);return e.set(this.payload,0),e.set(s,this.payload.byteLength),this.payload=e,new DataView(this.payload.buffer)};pushChunk=t=>{this.chunks.push(t),this.chunks.length>100&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const I=(y,t)=>{const s=new Uint8Array(y),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let a=0;return n[a++]=1,n[a++]=s[1],n[a++]=s[2],n[a++]=s[3],n[a++]=255,n[a++]=225,n[a++]=s.length>>8&255,n[a++]=s.length&255,n.set(s,a),a+=s.length,n[a++]=1,n[a++]=e.length>>8&255,n[a++]=e.length&255,n.set(e,a),n},T=y=>{let t=0;const s=new DataView(y.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const n=s.getUint8(t)&255;t=t+1;const a=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const c=`avc1.${Array.from([n,a,o],U=>U.toString(16).padStart(2,"0")).join("")}`,r=(s.getUint8(t)&3)-1;t=t+1;const g=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const h=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const d=s.getUint8(t)&31;t=t+1;const u=s.getUint16(t,!1);t=t+2;const f=new Uint8Array(s.buffer.slice(t,t+u));return t=t+u,{version:e,codec:c,profile:n,compatibility:a,level:o,lengthSizeMinusOne:r,numOfSequenceParameterSets:g,sequenceParameterSetLength:p,sps:h,numOfPictureParameterSets:d,pictureParameterSetLength:u,pps:f}},M=y=>{const t=new Uint8Array(4+y.length);return new DataView(t.buffer).setUint32(0,y.length,!1),t.set(y,4),t},C=y=>{let t=0;for(const n of y)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of y){const a=n;s.set(a,e),e+=a.length}return s},D=y=>{let t="unknown";switch(y){case 1:case 2:case 27:case 36:t="video";break;case 3:case 4:case 15:t="audio";break;case 6:t="subtitle";break;case 134:t="ad";break}return t};class x{pat;pmt;audioConfig;videoConfig;payloadMap=new Map;on={};constructor(){}parse=async t=>{let s=0;for(;!(s+188>t.byteLength);){if(t.getInt8(s)!=71){s++;continue}await this.parsePacket(t,s),s+=188}return s};parsePacket=async(t,s)=>{if(s+188>t.byteLength)throw new Error("Invalid TS packet");if(t.getUint8(s)!==71)throw new Error("Invalid TS packet");let e=s;const n=this.parseHeader(t,e);e+=4;const{transport_error_indicator:a,pid:o,payload_unit_start_indicator:l,adaptation_field_control:i}=n;if(a===1||o===void 0)return;let c=184;if(i===2||i===3){const r=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=r,c-=r}if(i===3&&(c-=1),i===1||i===3){const r=new Uint8Array(t.buffer.slice(e,e+c));if(o===0)return this.parsePAT(t,e);{const{programs:h=[]}=this.pat||{};if(h.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(h=>h.elementary_pid===o);if(p){if(l===1){const h=this.payloadMap.get(o);if(h){switch(p.kind){case"audio":{const d=await this.parseAudio(h);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(h);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),0))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const h=this.payloadMap.get(o),d=new Uint8Array(h.byteLength+r.byteLength);d.set(h,0),d.set(r,h.byteLength),this.payloadMap.set(o,d)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),a=t.getUint8(e+1),o=t.getUint8(e+2),l=t.getUint8(e+3),i=(a&128)>>7;if(i===1)return{sync_byte:n,transport_error_indicator:i};const c=(a&64)>>6,r=(a&32)>>5,g=(a&31)<<8|o,p=(l&192)>>6,h=l>>4&3,d=l&15;return{sync_byte:n,transport_error_indicator:i,payload_unit_start_indicator:c,transport_priority:r,pid:g,transport_scrambling_control:p,adaptation_field_control:h,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==0)throw new Error("Invalid PAT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d}}const a=[];{const l=n.section_length-5-4,i=e+l;for(;e<i;){const c=t.getUint16(e),r=t.getUint16(e+2)&8191;e+=4,c!==0&&r>=32&&r<=8190&&a.push({program_number:c,pmt_pid:r})}}const o=t.getUint32(e);this.pat={header:n,programs:a,crc32:o},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==2)throw new Error("Invalid PMT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1;const u=t.getUint16(e)&8191;e+=2;const f=t.getUint16(e)&4095;e+=2,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const l=n.section_length-9-4,i=e+l;for(;e<i;){const c=t.getUint8(e),r=D(c),g=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,g<32||g>8190){console.warn(`Invalid elementary_pid: 0x${g.toString(16)}`);continue}a.push({kind:r,stream_type:c,elementary_pid:g,es_info_length:p})}}const o=t.getUint32(e);this.pmt={header:n,streams:a,crc32:o},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,a,o,l;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),h=!!(i&8),d=!!(i&4),u=!!(i&2),f=!!(i&1);e+=1;const U=(_,b)=>{let m=BigInt(0);m|=BigInt(_.getUint16(b))<<25n,m|=BigInt(_.getUint16(b+1))<<17n,m|=BigInt(_.getUint16(b+2))<<9n,m|=BigInt(_.getUint16(b+3))<<1n,m|=BigInt(_.getUint16(b+4)>>7);const S=(_.getUint16(b+4)&1)<<8|_.getUint16(b+5);return m=m*300n+BigInt(S),m};if(p&&(n=U(t,e),e+=6),h&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,l=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:h,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:l}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts audio payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig&&s.getUint8(e)===255){const g=s.getUint8(e+2),p=s.getUint8(e+3);let h,d;d=g>>2&15,h=(g&1)<<2|p>>6;const u=`mp4a.40.${h}`,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][d];this.audioConfig={kind:"audio",codec:u,sampleRate:U,numberOfChannels:h},this.on.config&&this.on.config(this.audioConfig)}const{dts:o=0,pts:l=0}=n,i=l-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:l,cts:i,data:c}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts video payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let h,d;if(h=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),h&&d){const u=I(h,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:h,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const l=[];let i="delta";for(const h of o){const{type:d,nalu:u}=h;switch(d){case 6:case 9:l.push(u);break;case 1:i="delta",l.push(u);break;case 5:i="key",l.push(u);break}}const c=C(l),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:l}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),l=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(l)&0b11111110n)>>1n;return Number(i)/90}getNalus=t=>{const s=[];let e=0;for(;!(e+4>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}e+=3;let n=e;const a=t[e]&31;for(e+=1;!(e+1>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}break}let o=e-n;if(t[e-1]===0&&(o-=1),o!==0){const l=t.slice(n,n+o),i=M(l);s.push({type:a,nalu:i})}}return s}}const k=(y,t)=>y.getUint8(t)<<16|y.getUint8(t+1)<<8|y.getUint8(t+2);class L{audioConfig;videoConfig;header;textDecoder=new TextDecoder("utf-8");on={};constructor(){}parse=async t=>{let s=0;for(this.header||(this.parseHeader(t,s),s+=9);this.isSurplusTag(t,s)!==!1;){const n=this.parseTagHeader(t,s+4),{tagType:a,dataSize:o,timestamp:l}=n;if(a){const i=this.parseTagBody(a,t,s+4+11,o);switch(a){case"script":this.on.info&&this.on.info(i);break;case"audio":{const{accPacketType:c}=i;if(c===0){const{codec:r,sampleRate:g,channelConfiguration:p}=i;this.audioConfig={kind:"audio",codec:r,sampleRate:g,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:r,data:g}=i,p="key",h=r===void 0?void 0:r+l;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:l,pts:h,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:h}=i;this.videoConfig={kind:"video",codec:r,description:h,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:h}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+l;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:l,pts:u,cts:g,data:p,nalus:h})}}break}s=s+4+11+o}await new Promise(i=>setTimeout(()=>i(!0),8))}return s};parseHeader=(t,s)=>{let e,n,a,o;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const i=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,c,,r]=i;a={audio:r==="1",video:c==="1"}}o=t.getUint32(5),this.header={signature:e,version:n,flags:a,dataOffset:o}};isSurplusTag=(t,s)=>{let e=!0;const n=t.byteLength;if(s+4>n)e=!1;else if(s+4+11>n)e=!1;else{const a=k(t,s+4+1);s+4+11+a>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,a,o,l;{const i=t.getUint8(s);let c;switch(i){case 18:c="script";break;case 8:c="audio";break;case 9:c="video";break}e=c}return n=k(t,s+1),a=k(t,s+4),o=t.getUint8(s+7),l=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:l}};parseTagBody=(t,s,e,n)=>{let a;switch(t){case"script":a=this.parseMetaData(s,e);break;case"audio":a=this.parseAudio(s,e,n);break;case"video":a=this.parseVideo(s,e,n);break}return a};parseMetaData=(t,s)=>{let e=s;{if(t.getUint8(e)!==2)throw new Error("Invalid AMF type for onMetaData (expected 0x02)");e=e+1}const n=t.getUint16(e,!1);e=e+2;{const l=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(l)||"")!=="onMetaData")throw new Error("Expected \'onMetaData\' string");e=e+n}const a=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,a).value};parseAudio=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const h=t.getUint8(n),d=t.getUint8(n+1),u=h>>3&31,f=(h&7)<<1|d>>7,U=d>>3&15,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a&15;n=n+1;const i=t.getUint8(n);n=n+1;const c=k(t,n);n=n+3;const r=e-5,g=new Uint8Array(t.buffer.slice(n,n+r));switch(l){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],h=n+e-5;for(;!(n+4>h);){const d=t.getUint32(n,!1),u=new Uint8Array(t.buffer.slice(n,n+4+d));n+=4+d,p.push(u)}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g}};getAmfType=(t,s)=>t.getUint8(s);getAMFName=(t,s,e)=>{const n=new Uint8Array(t.buffer.slice(s,s+e));return this.textDecoder?.decode(n)||""};getAMFValue=(t,s,e)=>{let n=s,a,o=0;switch(e){case 0:a=t.getFloat64(n,!1),o=8;break;case 1:a=!!t.getUint8(n),o=1;break;case 2:{a="";const i=t.getUint16(n,!1);n=n+2;const c=new Int8Array(t.buffer,n,i).filter(g=>g!==0);a=(this.textDecoder?.decode(c)||"").trim(),o=2+i}break;case 3:for(a={};n<t.byteLength;){const i=t.getUint16(n,!1);if(i===0)break;n=n+2;const c=this.getAMFName(t,n,i);n=n+i;const r=this.getAmfType(t,n);if(r===6)break;n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a[c]=g.value,o=2+i+1+g.length}break;case 8:{a={};const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=t.getUint16(n,!1);n=n+2;const g=this.getAMFName(t,n,r);n=n+r;const p=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,p);n=n+h.length,a[g]=h.value,o=2+r+1+h.length}}break;case 10:{a=[];const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=this.getAmfType(t,n);n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a.push(g.value),o=1+g.length}}break}return{amfType:e,length:o,value:a}}}class O{pattern;cacher=new P;isParseing=!1;offset=0;parser;on={};constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new L;break;case"hls":this.parser=new x;break;default:throw new Error("is error pattern.")}this.parser.on.debug=s=>this.on.debug&&this.on.debug(s),this.parser.on.info=s=>this.on.info&&this.on.info(s),this.parser.on.config=s=>this.on.config&&this.on.config(s),this.parser.on.chunk=s=>{this.cacher.pushChunk(s),this.on.chunk&&this.on.chunk(s)}};push=t=>{this.cacher.push(t),this.isParseing===!1&&this.parse()};destroy=()=>{this.cacher.destroy(),this.isParseing=!1,this.offset=0};parse=async()=>{try{if(this.isParseing=!0,!this.pattern)throw new Error("You need to set the pattern.");if(!this.parser)throw new Error("You need to init parser.");for(;;){const t=this.cacher.next(this.offset);if(this.offset=0,!t)break;this.offset=await this.parser.parse(t)}this.isParseing=!1}catch{this.destroy()}}}const A=new O;A.on.info=y=>postMessage({action:"on.info",data:y}),A.on.config=y=>postMessage({action:"on.config",data:y}),A.on.chunk=y=>postMessage({action:"on.chunk",data:y}),A.on.debug=y=>postMessage({action:"on.debug",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', T = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", x], { type: "text/javascript;charset=utf-8" });
|
|
2
|
+
function R(g) {
|
|
3
3
|
let t;
|
|
4
4
|
try {
|
|
5
|
-
if (t =
|
|
5
|
+
if (t = T && (self.URL || self.webkitURL).createObjectURL(T), !t) throw "";
|
|
6
6
|
const s = new Worker(t, {
|
|
7
|
-
name:
|
|
7
|
+
name: g?.name
|
|
8
8
|
});
|
|
9
9
|
return s.addEventListener("error", () => {
|
|
10
10
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
11
11
|
}), s;
|
|
12
12
|
} catch {
|
|
13
13
|
return new Worker(
|
|
14
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
14
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(x),
|
|
15
15
|
{
|
|
16
|
-
name:
|
|
16
|
+
name: g?.name
|
|
17
17
|
}
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
22
|
-
worker = new
|
|
21
|
+
class P {
|
|
22
|
+
worker = new R();
|
|
23
23
|
on = {};
|
|
24
24
|
constructor() {
|
|
25
25
|
this.worker.onmessage = (t) => {
|
|
@@ -46,29 +46,29 @@ class I {
|
|
|
46
46
|
this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
`,
|
|
51
|
-
function
|
|
49
|
+
const A = `(function(){"use strict";class a{pattern="flv";audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;baseTime=0;pendingChunks=[];currentChunk;isProcessing=!1;decodeTimer=0;frameTrack=!1;isFrameTrack=!1;fameTrackOption={flv:[30,50],hls:[200,300],dash:[50,100],rtmp:[50,100]};decodingSpeedRatio=1;maxDecodingSpeedRatio=2;decodingSpeed=16;fps=0;firstVideoChunkTimestamp;secondVideoChunkTimestamp;frameStartTime;lastRenderTime;nextRenderTime;on={audio:{},video:{}};constructor(){}init=e=>{this.destroy(),this.pattern=e,this.baseTime=new Date().getTime()-performance.now(),this.initDecodeInterval()};initAudio=e=>{this.audio.destroy(),this.audioDecoderConfig={...e},this.audioDecoder=new AudioDecoder({output:i=>{const o=this.decodingSpeedRatio;this.on.audio.decode&&this.on.audio.decode({audioData:i,playbackRate:o})},error:i=>{this.on.audio.error&&this.on.audio.error(i)}}),this.audioDecoder.configure(this.audioDecoderConfig)};initVideo=e=>{this.video.destroy(),this.videoDecoderConfig={...e},this.videoDecoder=new VideoDecoder({output:async i=>{this.frameStartTime||(this.frameStartTime=i.timestamp);try{const o=i.timestamp-this.frameStartTime+this.baseTime*1e3,s=await createImageBitmap(i);if(i.close(),!s.width||!s.height)return s.close();this.on.video.decode&&this.on.video.decode({timestamp:o,bitmap:s}),this.currentChunk&&this.currentChunk.kind==="video"&&this.currentChunk.nalus&&this.on.nalus&&this.on.nalus(this.currentChunk.nalus)}catch{i.close()}},error:i=>{this.on.video.error&&this.on.video.error(i)}}),this.videoDecoder.configure(this.videoDecoderConfig)};setFrameTrack=e=>{this.frameTrack=e,this.frameTrack===!1&&(this.decodingSpeedRatio=1)};push=e=>{this.pendingChunks.push(e)};destroy=()=>{this.audio.destroy(),this.video.destroy(),this.pendingChunks=[],this.firstVideoChunkTimestamp=void 0,this.secondVideoChunkTimestamp=void 0,this.frameStartTime=void 0,this.lastRenderTime=void 0,this.nextRenderTime=void 0,clearInterval(this.decodeTimer)};initDecodeInterval=()=>{let e=this.decodingSpeed/this.decodingSpeedRatio;const i=this.baseTime+performance.now();if(this.lastRenderTime||(this.lastRenderTime=i),this.fps=Math.round(1e3/(i-this.lastRenderTime)),this.lastRenderTime=i,this.nextRenderTime){const o=this.lastRenderTime-this.nextRenderTime;e-=o}this.nextRenderTime=this.lastRenderTime+e,this.decodeTimer=setTimeout(()=>{this.decode(),this.initDecodeInterval()},e)};decode=()=>{if(this.isProcessing!==!0){for(this.isProcessing=!0;this.currentChunk=this.pendingChunks.shift(),!!this.currentChunk;){const e=this.pendingChunks.length;if(this.frameTrack){const[s,n]=this.fameTrackOption[this.pattern];if(e<=s&&(this.isFrameTrack=!1),e>=n&&(this.isFrameTrack=!0),this.isFrameTrack){const r=Math.min(1+(e-s)/100,this.maxDecodingSpeedRatio);this.decodingSpeedRatio=Number(r.toFixed(1))}else this.decodingSpeedRatio=1}if(this.on.analysis){const{decodingSpeed:s,decodingSpeedRatio:n,fps:r}=this;this.on.analysis({decodingSpeed:s,decodingSpeedRatio:n,fps:r,cacheLength:e})}const{kind:i,init:o}=this.currentChunk;switch(i){case"audio":this.decodeAudio(o);break;case"video":this.decodeVideo(o);break}if(i==="video")break}this.isProcessing=!1}};decodeAudio=e=>{if(!this.audioDecoder)return;const i=new EncodedAudioChunk(e);this.audioDecoder.decode(i)};decodeVideo=e=>{if(this.videoDecoder&&(e.type==="key"&&(this.hasKeyFrame=!0),this.firstVideoChunkTimestamp?this.secondVideoChunkTimestamp||(this.secondVideoChunkTimestamp=e.timestamp,this.decodingSpeed=(this.secondVideoChunkTimestamp-this.firstVideoChunkTimestamp)/1e3):this.firstVideoChunkTimestamp=e.timestamp,this.hasKeyFrame)){const i=new EncodedVideoChunk(e);this.videoDecoder.decode(i)}};audio={flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}const d=new a;d.on.audio.decode=t=>postMessage({action:"on.audio.decode",data:t},[t.audioData]),d.on.audio.error=t=>postMessage({action:"on.audio.error",data:t}),d.on.video.decode=t=>postMessage({action:"on.video.decode",data:t},[t.bitmap]),d.on.video.error=t=>postMessage({action:"on.video.error",data:t}),d.on.nalus=t=>postMessage({action:"on.nalus",data:t}),d.on.analysis=t=>postMessage({action:"on.analysis",data:t}),onmessage=t=>{const{action:e,data:i}=t.data,o=d[e];o&&o(i)}})();
|
|
50
|
+
`, _ = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", A], { type: "text/javascript;charset=utf-8" });
|
|
51
|
+
function I(g) {
|
|
52
52
|
let t;
|
|
53
53
|
try {
|
|
54
|
-
if (t =
|
|
54
|
+
if (t = _ && (self.URL || self.webkitURL).createObjectURL(_), !t) throw "";
|
|
55
55
|
const s = new Worker(t, {
|
|
56
|
-
name:
|
|
56
|
+
name: g?.name
|
|
57
57
|
});
|
|
58
58
|
return s.addEventListener("error", () => {
|
|
59
59
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
60
60
|
}), s;
|
|
61
61
|
} catch {
|
|
62
62
|
return new Worker(
|
|
63
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(
|
|
63
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(A),
|
|
64
64
|
{
|
|
65
|
-
name:
|
|
65
|
+
name: g?.name
|
|
66
66
|
}
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
class
|
|
71
|
-
worker = new
|
|
70
|
+
class N {
|
|
71
|
+
worker = new I();
|
|
72
72
|
on = { audio: {}, video: {} };
|
|
73
73
|
constructor() {
|
|
74
74
|
this.worker.onmessage = (t) => {
|
|
@@ -105,13 +105,13 @@ class V {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
const S = `(function(){"use strict";class l{renderMap=new Map;constructor(){}push=async t=>{const{timestamp:s}=t,{bitmap:e}=t;if(e.height===0||e.width===0)return e.close();try{const n=[...this.renderMap.keys()];for(const i of n){const a=this.renderMap.get(i);if(!a)continue;const{pause:y=!1,writer:h,offscreen:c,option:u}=a;if(y===!0)continue;const f=r=>{if(h){const o=new VideoFrame(r,{timestamp:s});try{o&&h.write(o)}catch{}o.close()}else c&&(c.width=r.width,c.height=r.height,c?.getContext("2d")?.drawImage(r,0,0))};if(i==="default")f(e);else if(u){const{sx:r=0,sy:o=0,sw:p=e.width,sh:g=e.height}=u,M=await createImageBitmap(e,r,o,p,g);f(M)}}}catch{}e.close()};addCut=t=>{const{key:s,writable:e,offscreen:n,option:i}={key:"default",...t};if(e){const a=e.getWriter();this.renderMap.set(s,{writer:a,option:i,pause:!1})}else this.renderMap.set(s,{offscreen:n,option:i,pause:!1})};delCut=t=>{this.renderMap.delete(t)};setCut=t=>{const{key:s,cutOption:e}={key:"default",...t},n=this.renderMap.get(s);n&&this.renderMap.set(s,{...n,option:e})};setPause=t=>{const{key:s,pause:e}={key:"default",...t},n=this.renderMap.get(s);n&&this.renderMap.set(s,{...n,pause:e})};destroy=()=>{this.renderMap=new Map}}const w=new l;onmessage=d=>{const{action:t,data:s}=d.data,e=w[t];e&&e(s)}})();
|
|
108
|
-
`,
|
|
109
|
-
function
|
|
108
|
+
`, C = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", S], { type: "text/javascript;charset=utf-8" });
|
|
109
|
+
function L(g) {
|
|
110
110
|
let t;
|
|
111
111
|
try {
|
|
112
|
-
if (t =
|
|
112
|
+
if (t = C && (self.URL || self.webkitURL).createObjectURL(C), !t) throw "";
|
|
113
113
|
const s = new Worker(t, {
|
|
114
|
-
name:
|
|
114
|
+
name: g?.name
|
|
115
115
|
});
|
|
116
116
|
return s.addEventListener("error", () => {
|
|
117
117
|
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
@@ -120,13 +120,13 @@ function F(p) {
|
|
|
120
120
|
return new Worker(
|
|
121
121
|
"data:text/javascript;charset=utf-8," + encodeURIComponent(S),
|
|
122
122
|
{
|
|
123
|
-
name:
|
|
123
|
+
name: g?.name
|
|
124
124
|
}
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
class
|
|
129
|
-
worker = new
|
|
128
|
+
class V {
|
|
129
|
+
worker = new L();
|
|
130
130
|
constructor() {
|
|
131
131
|
}
|
|
132
132
|
push = (t) => this.worker.postMessage({ action: "push", data: t }, [t.bitmap]);
|
|
@@ -141,64 +141,191 @@ class B {
|
|
|
141
141
|
this.worker.postMessage({ action: "destroy", data: {} }), this.worker.terminate();
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
var N = Object.defineProperty, G = (p, t, s) => t in p ? N(p, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : p[t] = s, y = (p, t, s) => G(p, typeof t != "symbol" ? t + "" : t, s);
|
|
145
144
|
class W {
|
|
145
|
+
inputStream = new MediaStream();
|
|
146
|
+
// 输入音频流 (原始音频)
|
|
147
|
+
outputStream = new MediaStream();
|
|
148
|
+
// 输出音频流 (处理后音频)
|
|
149
|
+
inputGain = 1;
|
|
150
|
+
// 麦克风音量
|
|
151
|
+
enhanceGain = 1;
|
|
152
|
+
// 麦克风增强音量 1+x
|
|
153
|
+
bgsGain = 1;
|
|
154
|
+
// 音效音量
|
|
155
|
+
bgmGain = 1;
|
|
156
|
+
// 音乐音量
|
|
157
|
+
outputGain = 1;
|
|
158
|
+
// 扬声器音量
|
|
159
|
+
mixAudioMap = /* @__PURE__ */ new Map();
|
|
160
|
+
// 音频上下文实例
|
|
161
|
+
audioContext = new AudioContext();
|
|
162
|
+
// 输入节点(处理器的音频)
|
|
163
|
+
sourceNode;
|
|
164
|
+
// 音量输入控制节点 (麦克风输入)
|
|
165
|
+
inputGainNode;
|
|
166
|
+
// 音量输入增强节点 (麦克风增强)
|
|
167
|
+
enhanceGainNode;
|
|
168
|
+
// 音效控制节点 (音效音量)
|
|
169
|
+
bgsGainNode;
|
|
170
|
+
// 背景音乐控制节点 (背景音乐音量)
|
|
171
|
+
bgmGainNode;
|
|
172
|
+
// @ts-ignore 噪音过滤节点
|
|
173
|
+
rnnoiseNode;
|
|
174
|
+
// 音频分析节点
|
|
175
|
+
analyserNode;
|
|
176
|
+
// 缓冲区 存储分析节点的时域数据
|
|
177
|
+
analyserArrayData;
|
|
178
|
+
// 音量输出控制节点 (扬声器音量)
|
|
179
|
+
outputGainNode;
|
|
180
|
+
// 输出节点(处理后的音频)
|
|
181
|
+
destinationNode;
|
|
182
|
+
// 是否开启降噪
|
|
183
|
+
denoise = !1;
|
|
184
|
+
// 是否静音
|
|
185
|
+
mute = !0;
|
|
186
|
+
rnnoiseWorklet;
|
|
187
|
+
rnnoiseWorkletNode;
|
|
188
|
+
// 过滤流
|
|
189
|
+
filterStream = (t) => t;
|
|
146
190
|
constructor(t, s) {
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
const e = this.inputStream.getTracks();
|
|
150
|
-
for (const n of e)
|
|
151
|
-
n.stop(), this.inputStream.removeTrack(n);
|
|
152
|
-
}
|
|
153
|
-
}), y(this, "getStream", () => this.filterStream(this.outputStream)), y(this, "setMute", (e = !0) => {
|
|
154
|
-
e ? this.analyserNode.disconnect(this.outputGainNode) : this.analyserNode.connect(this.outputGainNode);
|
|
155
|
-
}), y(this, "setInputGain", (e) => {
|
|
156
|
-
this.inputGain = e, this.inputGainNode.gain.setValueAtTime(e, this.audioContext.currentTime);
|
|
157
|
-
}), y(this, "setEnhanceGain", async (e) => {
|
|
158
|
-
this.enhanceGain = e + 1, this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime);
|
|
159
|
-
}), y(this, "setBgsGain", (e) => {
|
|
160
|
-
this.bgsGain = e, this.bgsGainNode.gain.setValueAtTime(e, this.audioContext.currentTime);
|
|
161
|
-
}), y(this, "setBgmGain", (e) => {
|
|
162
|
-
this.bgmGain = e, this.bgmGainNode.gain.setValueAtTime(e, this.audioContext.currentTime);
|
|
163
|
-
}), y(this, "setOutputGain", (e) => {
|
|
164
|
-
this.outputGain = e, this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime);
|
|
165
|
-
}), y(this, "getVolume", () => {
|
|
166
|
-
const { analyserNode: e, analyserArrayData: n } = this;
|
|
167
|
-
e.getByteFrequencyData(n);
|
|
168
|
-
let i = 0;
|
|
169
|
-
for (let o = 0; o < n.length; o++)
|
|
170
|
-
i += n[o];
|
|
171
|
-
return Math.ceil(i / n.length);
|
|
172
|
-
}), y(this, "mixAudio", (e, n = "bgm") => new Promise(async (i, o) => {
|
|
173
|
-
try {
|
|
174
|
-
{
|
|
175
|
-
const d = this.mixAudioMap.get(n);
|
|
176
|
-
d && d.stop();
|
|
177
|
-
}
|
|
178
|
-
const a = n === "bgs" ? this.bgsGainNode : this.bgmGainNode, r = this.audioContext.createBufferSource();
|
|
179
|
-
this.mixAudioMap.set(n, r), r.buffer = e, r.connect(a), r.onended = () => {
|
|
180
|
-
r.disconnect(a), this.mixAudioMap.delete(n), i(!0);
|
|
181
|
-
}, r.start(0);
|
|
182
|
-
} catch (a) {
|
|
183
|
-
o(a);
|
|
184
|
-
}
|
|
185
|
-
})), y(this, "mixAudioStop", (e) => {
|
|
186
|
-
const n = this.mixAudioMap.get(e);
|
|
187
|
-
n?.stop();
|
|
188
|
-
}), y(this, "changeMix", (e, n) => {
|
|
189
|
-
const i = e === "bgs" ? this.bgsGainNode : this.bgmGainNode;
|
|
190
|
-
n ? i.connect(this.destinationNode) : i.disconnect(this.destinationNode);
|
|
191
|
-
}), s && (this.audioContext = s), this.inputStream = t, this.sourceNode = this.audioContext.createMediaStreamSource(this.inputStream), this.inputGainNode = this.audioContext.createGain(), this.inputGainNode.gain.setValueAtTime(this.inputGain, this.audioContext.currentTime), this.enhanceGainNode = this.audioContext.createGain(), this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime), this.bgsGainNode = this.audioContext.createGain(), this.bgsGainNode.gain.setValueAtTime(this.bgsGain, this.audioContext.currentTime), this.bgmGainNode = this.audioContext.createGain(), this.bgmGainNode.gain.setValueAtTime(this.bgmGain, this.audioContext.currentTime), this.analyserNode = this.audioContext.createAnalyser(), this.analyserNode.fftSize = 512, this.analyserArrayData = new Uint8Array(this.analyserNode.frequencyBinCount), this.outputGainNode = this.audioContext.createGain(), this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime), this.destinationNode = this.audioContext.createMediaStreamDestination(), this.outputStream = this.destinationNode.stream;
|
|
191
|
+
this.inputStream = t, s && (this.audioContext = s), this.sourceNode = this.audioContext.createMediaStreamSource(this.inputStream), this.inputGainNode = this.audioContext.createGain(), this.inputGainNode.gain.setValueAtTime(this.inputGain, this.audioContext.currentTime), this.enhanceGainNode = this.audioContext.createGain(), this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime), this.bgsGainNode = this.audioContext.createGain(), this.bgsGainNode.gain.setValueAtTime(this.bgsGain, this.audioContext.currentTime), this.bgmGainNode = this.audioContext.createGain(), this.bgmGainNode.gain.setValueAtTime(this.bgmGain, this.audioContext.currentTime), this.analyserNode = this.audioContext.createAnalyser(), this.analyserNode.fftSize = 512, this.analyserArrayData = new Uint8Array(this.analyserNode.frequencyBinCount), this.outputGainNode = this.audioContext.createGain(), this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime), this.destinationNode = this.audioContext.createMediaStreamDestination(), this.outputStream = this.destinationNode.stream;
|
|
192
192
|
{
|
|
193
193
|
const { sourceNode: e, inputGainNode: n, enhanceGainNode: i, bgsGainNode: o, bgmGainNode: a, analyserNode: r, outputGainNode: d, destinationNode: c } = this;
|
|
194
|
-
e.connect(n), n.connect(i), i.connect(r), o.connect(r), a.connect(r), i.connect(c), o.connect(c), a.connect(c),
|
|
194
|
+
e.connect(n), n.connect(i), i.connect(r), o.connect(r), a.connect(r), i.connect(c), o.connect(c), a.connect(c), d.connect(this.audioContext.destination);
|
|
195
195
|
}
|
|
196
|
-
this.
|
|
196
|
+
this.audioContext.resume();
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* 使用插件
|
|
200
|
+
*/
|
|
201
|
+
use = ({ rnnoise: t }) => {
|
|
202
|
+
this.rnnoiseWorklet = new t.RnnoiseWorklet();
|
|
203
|
+
};
|
|
204
|
+
_changeSource = () => {
|
|
205
|
+
this.sourceNode.disconnect(), this.sourceNode = this.audioContext.createMediaStreamSource(this.inputStream), this.sourceNode.connect(this.inputGainNode);
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* 替换轨道
|
|
209
|
+
* @param track MediaStreamTrack
|
|
210
|
+
*/
|
|
211
|
+
replaceTrack = (t) => {
|
|
212
|
+
const s = this.inputStream.getTracks();
|
|
213
|
+
for (const e of s)
|
|
214
|
+
this.inputStream.removeTrack(e);
|
|
215
|
+
this.inputStream.addTrack(t), this._changeSource();
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* 停止流
|
|
219
|
+
*/
|
|
220
|
+
stop = () => {
|
|
221
|
+
{
|
|
222
|
+
const t = this.inputStream.getTracks();
|
|
223
|
+
for (const s of t)
|
|
224
|
+
s.stop(), this.inputStream.removeTrack(s);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* 暂停
|
|
229
|
+
* @param pause
|
|
230
|
+
*/
|
|
231
|
+
pause = async (t) => {
|
|
232
|
+
const s = this.inputStream.getTracks();
|
|
233
|
+
for (const e of s)
|
|
234
|
+
e.enabled = !t;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* 获取数据流
|
|
238
|
+
*/
|
|
239
|
+
getStream = () => this.filterStream(this.outputStream);
|
|
240
|
+
/**
|
|
241
|
+
* 静音
|
|
242
|
+
* @param state 是否开启
|
|
243
|
+
*/
|
|
244
|
+
setMute = (t = !0) => {
|
|
245
|
+
this.mute = t, this.analyserNode.disconnect(), t === !1 && this.analyserNode.connect(this.outputGainNode);
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* 降噪
|
|
249
|
+
* @param state 是否开启
|
|
250
|
+
*/
|
|
251
|
+
setDenoise = async (t = !0) => {
|
|
252
|
+
this.rnnoiseWorklet && (this.inputGainNode.disconnect(), this.rnnoiseWorklet.destroy(), t ? (this.rnnoiseWorkletNode = await this.rnnoiseWorklet.createRnnoiseWorkletNode(this.audioContext), this.inputGainNode.connect(this.rnnoiseWorkletNode), this.rnnoiseWorkletNode.connect(this.enhanceGainNode)) : this.inputGainNode.connect(this.enhanceGainNode), this.denoise = t);
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* 设置麦克风输入音量
|
|
256
|
+
*/
|
|
257
|
+
setInputGain = (t) => {
|
|
258
|
+
this.inputGain = t, this.inputGainNode.gain.setValueAtTime(t, this.audioContext.currentTime);
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* 设置麦克风增强音量
|
|
262
|
+
*/
|
|
263
|
+
setEnhanceGain = async (t) => {
|
|
264
|
+
this.enhanceGain = t + 1, this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain, this.audioContext.currentTime);
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* 设置音效输入音量
|
|
268
|
+
*/
|
|
269
|
+
setBgsGain = (t) => {
|
|
270
|
+
this.bgsGain = t, this.bgsGainNode.gain.setValueAtTime(t, this.audioContext.currentTime);
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* 设置背景音乐输入音量
|
|
274
|
+
*/
|
|
275
|
+
setBgmGain = (t) => {
|
|
276
|
+
this.bgmGain = t, this.bgmGainNode.gain.setValueAtTime(t, this.audioContext.currentTime);
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* 设置扬声器音量
|
|
280
|
+
*/
|
|
281
|
+
setOutputGain = (t) => {
|
|
282
|
+
this.outputGain = t, this.outputGainNode.gain.setValueAtTime(this.outputGain, this.audioContext.currentTime);
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* 获取输入音量
|
|
286
|
+
*/
|
|
287
|
+
getVolume = () => {
|
|
288
|
+
const { analyserNode: t, analyserArrayData: s } = this;
|
|
289
|
+
t.getByteFrequencyData(s);
|
|
290
|
+
let e = 0;
|
|
291
|
+
for (let n = 0; n < s.length; n++)
|
|
292
|
+
e += s[n];
|
|
293
|
+
return Math.ceil(e / s.length);
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* 融合音频
|
|
297
|
+
*/
|
|
298
|
+
mixAudio = (t, s = "bgm") => new Promise(async (e, n) => {
|
|
299
|
+
try {
|
|
300
|
+
{
|
|
301
|
+
const a = this.mixAudioMap.get(s);
|
|
302
|
+
a && a.stop();
|
|
303
|
+
}
|
|
304
|
+
const i = s === "bgs" ? this.bgsGainNode : this.bgmGainNode, o = this.audioContext.createBufferSource();
|
|
305
|
+
this.mixAudioMap.set(s, o), o.buffer = t, o.connect(i), o.onended = () => {
|
|
306
|
+
o.disconnect(i), this.mixAudioMap.delete(s), e(!0);
|
|
307
|
+
}, o.start(0);
|
|
308
|
+
} catch (i) {
|
|
309
|
+
n(i);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
/**
|
|
313
|
+
* 停止融合音频
|
|
314
|
+
*/
|
|
315
|
+
mixAudioStop = (t) => {
|
|
316
|
+
this.mixAudioMap.get(t)?.stop();
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* 改变融合状态
|
|
320
|
+
*/
|
|
321
|
+
changeMix = (t, s) => {
|
|
322
|
+
const e = t === "bgs" ? this.bgsGainNode : this.bgmGainNode;
|
|
323
|
+
s ? e.connect(this.destinationNode) : e.disconnect(this.destinationNode);
|
|
324
|
+
};
|
|
198
325
|
}
|
|
199
|
-
const
|
|
326
|
+
const F = async (g, t) => {
|
|
200
327
|
try {
|
|
201
|
-
const { format: s, numberOfChannels: e, numberOfFrames: n, sampleRate: i } = t, o =
|
|
328
|
+
const { format: s, numberOfChannels: e, numberOfFrames: n, sampleRate: i } = t, o = g.createBuffer(e, n, i);
|
|
202
329
|
for (let a = 0; a < e; a++) {
|
|
203
330
|
const r = t.allocationSize({ planeIndex: a }), d = new Uint8Array(r);
|
|
204
331
|
t.copyTo(d, { planeIndex: a });
|
|
@@ -232,7 +359,7 @@ const E = async (p, t) => {
|
|
|
232
359
|
throw console.error("Failed to convert AudioData to AudioBuffer:", s), s;
|
|
233
360
|
}
|
|
234
361
|
};
|
|
235
|
-
class
|
|
362
|
+
class B {
|
|
236
363
|
prAudioStream;
|
|
237
364
|
audioContext;
|
|
238
365
|
destination;
|
|
@@ -247,7 +374,7 @@ class O {
|
|
|
247
374
|
async push(t) {
|
|
248
375
|
const { audioData: s, playbackRate: e = 1 } = t;
|
|
249
376
|
if (!this.audioContext || !this.destination) return;
|
|
250
|
-
let n = await
|
|
377
|
+
let n = await F(this.audioContext, s);
|
|
251
378
|
if (s.close(), !n) return;
|
|
252
379
|
const i = this.audioContext.createBufferSource();
|
|
253
380
|
i.buffer = n, i.playbackRate.value = e;
|
|
@@ -263,15 +390,15 @@ class O {
|
|
|
263
390
|
this.audioContext?.close(), this.audioContext = void 0, this.destination = void 0, this.nextStartTime = 0, this.prAudioStream?.stop(), this.pendingSources.forEach((t) => t.stop()), this.pendingSources = [];
|
|
264
391
|
}
|
|
265
392
|
}
|
|
266
|
-
const
|
|
267
|
-
const t =
|
|
393
|
+
const G = (g) => {
|
|
394
|
+
const t = g.toLowerCase();
|
|
268
395
|
return t.includes(".m3u8") || t.includes("hls") || t.includes("master.m3u8") || t.match(/index\d*\.m3u8/) ? "hls" : t.includes(".mpd") || t.includes("dash") ? "dash" : t.startsWith("rtmp://") || t.startsWith("rtmps://") ? "rtmp" : t.includes(".flv") || t.includes("flv") && !t.includes("flash") ? "flv" : "unknown";
|
|
269
|
-
},
|
|
270
|
-
const t =
|
|
396
|
+
}, E = (g) => {
|
|
397
|
+
const t = g?.getTracks() || [];
|
|
271
398
|
for (const s of t)
|
|
272
399
|
s.stop();
|
|
273
400
|
};
|
|
274
|
-
class
|
|
401
|
+
class O {
|
|
275
402
|
resolvesMap = /* @__PURE__ */ new Map();
|
|
276
403
|
index = 0;
|
|
277
404
|
constructor() {
|
|
@@ -306,13 +433,13 @@ class $ {
|
|
|
306
433
|
}
|
|
307
434
|
};
|
|
308
435
|
}
|
|
309
|
-
const
|
|
310
|
-
const s = new Uint8Array(
|
|
436
|
+
const j = (g, t) => {
|
|
437
|
+
const s = new Uint8Array(g), e = new Uint8Array(t), n = new Uint8Array(11 + s.length + e.length);
|
|
311
438
|
let i = 0;
|
|
312
439
|
return n[i++] = 1, n[i++] = s[1], n[i++] = s[2], n[i++] = s[3], n[i++] = 255, n[i++] = 225, n[i++] = s.length >> 8 & 255, n[i++] = s.length & 255, n.set(s, i), i += s.length, n[i++] = 1, n[i++] = e.length >> 8 & 255, n[i++] = e.length & 255, n.set(e, i), n;
|
|
313
|
-
},
|
|
440
|
+
}, M = (g) => {
|
|
314
441
|
let t = 0;
|
|
315
|
-
const s = new DataView(
|
|
442
|
+
const s = new DataView(g.buffer), e = s.getUint8(t);
|
|
316
443
|
if (t = t + 1, e !== 1) throw new Error("Invalid AVC version");
|
|
317
444
|
const n = s.getUint8(t) & 255;
|
|
318
445
|
t = t + 1;
|
|
@@ -320,7 +447,7 @@ const q = (p, t) => {
|
|
|
320
447
|
t = t + 1;
|
|
321
448
|
const o = s.getUint8(t) & 255;
|
|
322
449
|
t = t + 1;
|
|
323
|
-
const d = `avc1.${Array.from([n, i, o], (
|
|
450
|
+
const d = `avc1.${Array.from([n, i, o], (k) => k.toString(16).padStart(2, "0")).join("")}`, c = (s.getUint8(t) & 3) - 1;
|
|
324
451
|
t = t + 1;
|
|
325
452
|
const h = s.getUint8(t) & 31;
|
|
326
453
|
t = t + 1;
|
|
@@ -328,28 +455,28 @@ const q = (p, t) => {
|
|
|
328
455
|
t = t + 2;
|
|
329
456
|
const u = new Uint8Array(s.buffer.slice(t, t + l));
|
|
330
457
|
t = t + l;
|
|
331
|
-
const
|
|
458
|
+
const p = s.getUint8(t) & 31;
|
|
332
459
|
t = t + 1;
|
|
333
460
|
const f = s.getUint16(t, !1);
|
|
334
461
|
t = t + 2;
|
|
335
462
|
const m = new Uint8Array(s.buffer.slice(t, t + f));
|
|
336
|
-
return t = t + f, { version: e, codec: d, profile: n, compatibility: i, level: o, lengthSizeMinusOne: c, numOfSequenceParameterSets: h, sequenceParameterSetLength: l, sps: u, numOfPictureParameterSets:
|
|
337
|
-
},
|
|
338
|
-
const t = new Uint8Array(4 +
|
|
339
|
-
return new DataView(t.buffer).setUint32(0,
|
|
340
|
-
},
|
|
463
|
+
return t = t + f, { version: e, codec: d, profile: n, compatibility: i, level: o, lengthSizeMinusOne: c, numOfSequenceParameterSets: h, sequenceParameterSetLength: l, sps: u, numOfPictureParameterSets: p, pictureParameterSetLength: f, pps: m };
|
|
464
|
+
}, z = (g) => {
|
|
465
|
+
const t = new Uint8Array(4 + g.length);
|
|
466
|
+
return new DataView(t.buffer).setUint32(0, g.length, !1), t.set(g, 4), t;
|
|
467
|
+
}, $ = (g) => {
|
|
341
468
|
let t = 0;
|
|
342
|
-
for (const n of
|
|
469
|
+
for (const n of g)
|
|
343
470
|
t += n.length;
|
|
344
471
|
const s = new Uint8Array(t);
|
|
345
472
|
let e = 0;
|
|
346
|
-
for (const n of
|
|
473
|
+
for (const n of g) {
|
|
347
474
|
const i = n;
|
|
348
475
|
s.set(i, e), e += i.length;
|
|
349
476
|
}
|
|
350
477
|
return s;
|
|
351
|
-
},
|
|
352
|
-
const t = new DataView(
|
|
478
|
+
}, q = (g) => {
|
|
479
|
+
const t = new DataView(g.buffer);
|
|
353
480
|
let s = 0, e, n, i;
|
|
354
481
|
e = t.getUint32(s, !1), s += 4;
|
|
355
482
|
{
|
|
@@ -362,64 +489,66 @@ const q = (p, t) => {
|
|
|
362
489
|
}
|
|
363
490
|
return { size: e, header: n, data: i };
|
|
364
491
|
};
|
|
365
|
-
class
|
|
492
|
+
class v {
|
|
366
493
|
#e = {
|
|
367
494
|
timeout: 5 * 1e3,
|
|
368
495
|
check: !1
|
|
369
496
|
};
|
|
370
|
-
#t;
|
|
497
|
+
#t = null;
|
|
498
|
+
// 实例变量:统一管理当前请求的中止
|
|
371
499
|
constructor(t = {}) {
|
|
372
500
|
this.#e = { ...this.#e, ...t };
|
|
373
501
|
}
|
|
374
502
|
/**
|
|
375
|
-
*
|
|
376
|
-
* @param input string | URL | Request
|
|
377
|
-
* @param init RequestInit
|
|
503
|
+
* 检查资源可用性(HEAD 请求)—— 用实例变量控制器
|
|
378
504
|
*/
|
|
379
|
-
|
|
380
|
-
this
|
|
381
|
-
const i =
|
|
382
|
-
this.#t?.abort(
|
|
383
|
-
},
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
505
|
+
#s = (t, s) => new Promise(async (e) => {
|
|
506
|
+
this.#t = new AbortController();
|
|
507
|
+
const { signal: n } = this.#t, i = this.#e.timeout, o = setTimeout(() => {
|
|
508
|
+
this.#t?.abort(`Timeout (${i}ms)`);
|
|
509
|
+
}, i);
|
|
510
|
+
await fetch(t, { cache: "no-store", ...s, method: "HEAD", signal: n }).then((a) => {
|
|
511
|
+
clearTimeout(o), e({ status: a.status === 200 ? "successed" : "failed", reason: a.status === 200 ? "" : `HTTP ${a.status}` });
|
|
512
|
+
}).catch((a) => {
|
|
513
|
+
if (clearTimeout(o), a.name === "AbortError") {
|
|
514
|
+
const r = n.reason || "Actively stopped";
|
|
515
|
+
e({
|
|
516
|
+
status: r.includes("Timeout") ? "timeout" : "stopped",
|
|
517
|
+
reason: r
|
|
518
|
+
});
|
|
519
|
+
} else
|
|
520
|
+
e({ status: "error", reason: a.message });
|
|
521
|
+
});
|
|
391
522
|
});
|
|
392
523
|
/**
|
|
393
|
-
*
|
|
394
|
-
* @param input string | URL | Request
|
|
395
|
-
* @param init RequestInit
|
|
524
|
+
* 发起数据请求(GET/POST 等)—— 用实例变量控制器
|
|
396
525
|
*/
|
|
397
|
-
request =
|
|
526
|
+
request = (t, s) => new Promise(async (e, n) => {
|
|
398
527
|
try {
|
|
399
|
-
this.#e.check && await this
|
|
400
|
-
const i = await fetch(t, { ...s, signal:
|
|
401
|
-
e(
|
|
528
|
+
this.stop(), this.#e.check && await this.#s(t), this.#t = new AbortController();
|
|
529
|
+
const { signal: i } = this.#t, o = await fetch(t, { cache: "no-store", ...s, signal: i });
|
|
530
|
+
e(o);
|
|
402
531
|
} catch (i) {
|
|
403
|
-
|
|
532
|
+
n(i);
|
|
404
533
|
}
|
|
405
534
|
});
|
|
406
|
-
/**
|
|
407
|
-
* stop
|
|
408
|
-
*/
|
|
409
535
|
stop = () => {
|
|
410
|
-
this.#t?.signal.aborted === !1
|
|
536
|
+
if (this.#t?.signal.aborted === !1) {
|
|
537
|
+
const t = new Error("Actively stopped.");
|
|
538
|
+
t.name = "AbortError", this.#t.abort(t);
|
|
539
|
+
}
|
|
411
540
|
};
|
|
412
541
|
}
|
|
413
|
-
class
|
|
542
|
+
class Q {
|
|
414
543
|
option = {
|
|
415
544
|
debug: !1,
|
|
416
545
|
frameTrack: !1
|
|
417
546
|
};
|
|
418
547
|
converter = "MediaStreamTrackGenerator" in window ? "generator" : "canvas";
|
|
419
548
|
// 自动检测浏览器 使用哪一种模式转换生产视频流
|
|
420
|
-
prFetch = new
|
|
421
|
-
getSegmentsFetch = new
|
|
422
|
-
prResolves = new
|
|
549
|
+
prFetch = new v();
|
|
550
|
+
getSegmentsFetch = new v();
|
|
551
|
+
prResolves = new O();
|
|
423
552
|
url = "";
|
|
424
553
|
start_resolve;
|
|
425
554
|
demuxerWorker;
|
|
@@ -441,7 +570,7 @@ class tt {
|
|
|
441
570
|
*/
|
|
442
571
|
start = async (t) => {
|
|
443
572
|
await this.stop(), this.url = t;
|
|
444
|
-
const s =
|
|
573
|
+
const s = G(t);
|
|
445
574
|
if (s === "unknown") throw new Error("This address cannot be parsed.");
|
|
446
575
|
switch (this.init(s), s) {
|
|
447
576
|
case "flv":
|
|
@@ -457,7 +586,7 @@ class tt {
|
|
|
457
586
|
*/
|
|
458
587
|
stop = async () => {
|
|
459
588
|
try {
|
|
460
|
-
this.url = "", clearInterval(this.hls.getSegmentsTimer), this.prFetch.stop(), this.getSegmentsFetch.stop(), this.demuxerWorker?.destroy(), this.decoderWorker?.destroy(), this.renderWorker?.destroy(), this.cutRenders = /* @__PURE__ */ new Map(),
|
|
589
|
+
this.url = "", clearInterval(this.hls.getSegmentsTimer), this.prFetch.stop(), this.getSegmentsFetch.stop(), this.demuxerWorker?.destroy(), this.decoderWorker?.destroy(), this.renderWorker?.destroy(), this.cutRenders = /* @__PURE__ */ new Map(), E(this.stream), this.audioPlayer?.destroy();
|
|
461
590
|
} catch (t) {
|
|
462
591
|
console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: error", t);
|
|
463
592
|
}
|
|
@@ -539,13 +668,13 @@ class tt {
|
|
|
539
668
|
* 初始化
|
|
540
669
|
*/
|
|
541
670
|
init = (t) => {
|
|
542
|
-
this.initDecoder(t), this.initRender(), this.initDemuxer(t), this.audioPlayer = new
|
|
671
|
+
this.initDecoder(t), this.initRender(), this.initDemuxer(t), this.audioPlayer = new B(), this.audioPlayer.init();
|
|
543
672
|
};
|
|
544
673
|
/**
|
|
545
674
|
* 初始化解复器
|
|
546
675
|
*/
|
|
547
676
|
initDemuxer = (t) => {
|
|
548
|
-
this.demuxerWorker = new
|
|
677
|
+
this.demuxerWorker = new P(), this.demuxerWorker.init(t), this.demuxerWorker.on.debug = (s) => {
|
|
549
678
|
this.option.debug && this.on.debug && this.on.debug(s);
|
|
550
679
|
}, this.demuxerWorker.on.info = (s) => {
|
|
551
680
|
this.option.debug && console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->pr-player: info", s), this.on.demuxer.info && this.on.demuxer.info(s);
|
|
@@ -589,7 +718,7 @@ class tt {
|
|
|
589
718
|
* 初始化解码器
|
|
590
719
|
*/
|
|
591
720
|
initDecoder = (t) => {
|
|
592
|
-
this.decoderWorker = new
|
|
721
|
+
this.decoderWorker = new N(), this.decoderWorker.init(t);
|
|
593
722
|
const { frameTrack: s = !1 } = this.option;
|
|
594
723
|
this.decoderWorker.setFrameTrack(s), this.decoderWorker.on.audio.decode = (e) => {
|
|
595
724
|
this.audioPlayer?.push(e), this.on.decoder.audio && this.on.decoder.audio(e);
|
|
@@ -602,7 +731,7 @@ class tt {
|
|
|
602
731
|
}, this.decoderWorker.on.nalus = async (e) => {
|
|
603
732
|
for (const n of e) {
|
|
604
733
|
if (n.byteLength <= 4) continue;
|
|
605
|
-
const { header: i, data: o } =
|
|
734
|
+
const { header: i, data: o } = q(n), { nal_unit_type: a } = i;
|
|
606
735
|
a === 6 && this.on.decoder.sei && this.on.decoder.sei(o);
|
|
607
736
|
}
|
|
608
737
|
}, this.decoderWorker.on.analysis = (e) => {
|
|
@@ -613,7 +742,7 @@ class tt {
|
|
|
613
742
|
* 初始化渲染器
|
|
614
743
|
*/
|
|
615
744
|
initRender = () => {
|
|
616
|
-
if (this.renderWorker = new
|
|
745
|
+
if (this.renderWorker = new V(), this.converter === "generator") {
|
|
617
746
|
const t = new MediaStreamTrackGenerator({ kind: "video" }), s = new MediaStream([t]);
|
|
618
747
|
this.renderWorker?.addCut({ writable: t.writable }), this.stream = s;
|
|
619
748
|
} else {
|
|
@@ -719,7 +848,7 @@ class tt {
|
|
|
719
848
|
})
|
|
720
849
|
};
|
|
721
850
|
}
|
|
722
|
-
class
|
|
851
|
+
class H {
|
|
723
852
|
pendingPayloads = [];
|
|
724
853
|
// 所有原始分段数据
|
|
725
854
|
payload = new Uint8Array(0);
|
|
@@ -743,9 +872,9 @@ class Y {
|
|
|
743
872
|
this.pendingPayloads = [], this.payload = new Uint8Array(0), this.chunks = [];
|
|
744
873
|
};
|
|
745
874
|
}
|
|
746
|
-
const
|
|
875
|
+
const K = (g) => {
|
|
747
876
|
let t = "unknown";
|
|
748
|
-
switch (
|
|
877
|
+
switch (g) {
|
|
749
878
|
case 1:
|
|
750
879
|
case 2:
|
|
751
880
|
case 27:
|
|
@@ -766,7 +895,7 @@ const Q = (p) => {
|
|
|
766
895
|
}
|
|
767
896
|
return t;
|
|
768
897
|
};
|
|
769
|
-
class
|
|
898
|
+
class X {
|
|
770
899
|
pat;
|
|
771
900
|
pmt;
|
|
772
901
|
audioConfig;
|
|
@@ -816,14 +945,14 @@ class J {
|
|
|
816
945
|
switch (l.kind) {
|
|
817
946
|
case "audio":
|
|
818
947
|
{
|
|
819
|
-
const
|
|
820
|
-
this.on.chunk && this.on.chunk(
|
|
948
|
+
const p = await this.parseAudio(u);
|
|
949
|
+
this.on.chunk && this.on.chunk(p);
|
|
821
950
|
}
|
|
822
951
|
break;
|
|
823
952
|
case "video":
|
|
824
953
|
{
|
|
825
|
-
const
|
|
826
|
-
this.on.chunk && this.on.chunk(
|
|
954
|
+
const p = await this.parseVideo(u);
|
|
955
|
+
this.on.chunk && this.on.chunk(p), await new Promise((f) => setTimeout(() => f(!0), 0));
|
|
827
956
|
}
|
|
828
957
|
break;
|
|
829
958
|
}
|
|
@@ -832,8 +961,8 @@ class J {
|
|
|
832
961
|
}
|
|
833
962
|
{
|
|
834
963
|
this.payloadMap.has(o) || this.payloadMap.set(o, new Uint8Array());
|
|
835
|
-
const u = this.payloadMap.get(o),
|
|
836
|
-
|
|
964
|
+
const u = this.payloadMap.get(o), p = new Uint8Array(u.byteLength + c.byteLength);
|
|
965
|
+
p.set(u, 0), p.set(c, u.byteLength), this.payloadMap.set(o, p);
|
|
837
966
|
}
|
|
838
967
|
}
|
|
839
968
|
}
|
|
@@ -843,8 +972,8 @@ class J {
|
|
|
843
972
|
let e = s;
|
|
844
973
|
const n = t.getUint8(e), i = t.getUint8(e + 1), o = t.getUint8(e + 2), a = t.getUint8(e + 3), r = (i & 128) >> 7;
|
|
845
974
|
if (r === 1) return { sync_byte: n, transport_error_indicator: r };
|
|
846
|
-
const d = (i & 64) >> 6, c = (i & 32) >> 5, h = (i & 31) << 8 | o, l = (a & 192) >> 6, u = a >> 4 & 3,
|
|
847
|
-
return { sync_byte: n, transport_error_indicator: r, payload_unit_start_indicator: d, transport_priority: c, pid: h, transport_scrambling_control: l, adaptation_field_control: u, continuity_counter:
|
|
975
|
+
const d = (i & 64) >> 6, c = (i & 32) >> 5, h = (i & 31) << 8 | o, l = (a & 192) >> 6, u = a >> 4 & 3, p = a & 15;
|
|
976
|
+
return { sync_byte: n, transport_error_indicator: r, payload_unit_start_indicator: d, transport_priority: c, pid: h, transport_scrambling_control: l, adaptation_field_control: u, continuity_counter: p };
|
|
848
977
|
};
|
|
849
978
|
// PAT表
|
|
850
979
|
parsePAT = (t, s) => {
|
|
@@ -862,8 +991,8 @@ class J {
|
|
|
862
991
|
e += 1;
|
|
863
992
|
const u = t.getUint8(e);
|
|
864
993
|
e += 1;
|
|
865
|
-
const
|
|
866
|
-
e += 1, n = { pointer_field: a, table_id: r, section_length: d, transport_stream_id: c, version_number: h, current_next_indicator: l, section_number: u, last_section_number:
|
|
994
|
+
const p = t.getUint8(e);
|
|
995
|
+
e += 1, n = { pointer_field: a, table_id: r, section_length: d, transport_stream_id: c, version_number: h, current_next_indicator: l, section_number: u, last_section_number: p };
|
|
867
996
|
}
|
|
868
997
|
const i = [];
|
|
869
998
|
{
|
|
@@ -892,18 +1021,18 @@ class J {
|
|
|
892
1021
|
e += 1;
|
|
893
1022
|
const u = t.getUint8(e);
|
|
894
1023
|
e += 1;
|
|
895
|
-
const
|
|
1024
|
+
const p = t.getUint8(e);
|
|
896
1025
|
e += 1;
|
|
897
1026
|
const f = t.getUint16(e) & 8191;
|
|
898
1027
|
e += 2;
|
|
899
1028
|
const m = t.getUint16(e) & 4095;
|
|
900
|
-
e += 2, n = { pointer_field: a, table_id: r, section_length: d, transport_stream_id: c, version_number: h, current_next_indicator: l, section_number: u, last_section_number:
|
|
1029
|
+
e += 2, n = { pointer_field: a, table_id: r, section_length: d, transport_stream_id: c, version_number: h, current_next_indicator: l, section_number: u, last_section_number: p, pcr_pid: f, program_info_length: m };
|
|
901
1030
|
}
|
|
902
1031
|
const i = [];
|
|
903
1032
|
{
|
|
904
1033
|
const a = n.section_length - 9 - 4, r = e + a;
|
|
905
1034
|
for (; e < r; ) {
|
|
906
|
-
const d = t.getUint8(e), c =
|
|
1035
|
+
const d = t.getUint8(e), c = K(d), h = t.getUint16(e + 1) & 8191, l = t.getUint16(e + 3) & 4095;
|
|
907
1036
|
if (e += 5, h < 32 || h > 8190) {
|
|
908
1037
|
console.warn(`Invalid elementary_pid: 0x${h.toString(16)}`);
|
|
909
1038
|
continue;
|
|
@@ -917,19 +1046,19 @@ class J {
|
|
|
917
1046
|
// AdaptationField
|
|
918
1047
|
parseAdaptationField = (t, s) => {
|
|
919
1048
|
let e = s, n, i, o, a;
|
|
920
|
-
const r = t.getUint8(e), d = !!(r & 128), c = !!(r & 64), h = !!(r & 32), l = !!(r & 16), u = !!(r & 8),
|
|
1049
|
+
const r = t.getUint8(e), d = !!(r & 128), c = !!(r & 64), h = !!(r & 32), l = !!(r & 16), u = !!(r & 8), p = !!(r & 4), f = !!(r & 2), m = !!(r & 1);
|
|
921
1050
|
e += 1;
|
|
922
|
-
const
|
|
923
|
-
let
|
|
924
|
-
|
|
925
|
-
const
|
|
926
|
-
return
|
|
1051
|
+
const k = (y, U) => {
|
|
1052
|
+
let b = BigInt(0);
|
|
1053
|
+
b |= BigInt(y.getUint16(U)) << 25n, b |= BigInt(y.getUint16(U + 1)) << 17n, b |= BigInt(y.getUint16(U + 2)) << 9n, b |= BigInt(y.getUint16(U + 3)) << 1n, b |= BigInt(y.getUint16(U + 4) >> 7);
|
|
1054
|
+
const D = (y.getUint16(U + 4) & 1) << 8 | y.getUint16(U + 5);
|
|
1055
|
+
return b = b * 300n + BigInt(D), b;
|
|
927
1056
|
};
|
|
928
|
-
if (l && (n =
|
|
929
|
-
const
|
|
930
|
-
e += 1, a = new Uint8Array(t.buffer, e,
|
|
1057
|
+
if (l && (n = k(t, e), e += 6), u && (i = k(t, e), e += 6), p && (o = t.getInt8(e), e += 1), f) {
|
|
1058
|
+
const y = t.getUint8(e);
|
|
1059
|
+
e += 1, a = new Uint8Array(t.buffer, e, y), e += y;
|
|
931
1060
|
}
|
|
932
|
-
return { discontinuity_indicator: d, random_access_indicator: c, elementary_stream_priority_indicator: h, pcr_flag: l, opcr_flag: u, splicing_point_flag:
|
|
1061
|
+
return { discontinuity_indicator: d, random_access_indicator: c, elementary_stream_priority_indicator: h, pcr_flag: l, opcr_flag: u, splicing_point_flag: p, transport_private_data_flag: f, adaptation_field_extension_flag: m, pcr: n, opcr: i, splice_countdown: o, transport_private_data: a };
|
|
933
1062
|
};
|
|
934
1063
|
parseAudio = async (t) => {
|
|
935
1064
|
const s = new DataView(t.buffer);
|
|
@@ -947,23 +1076,23 @@ class J {
|
|
|
947
1076
|
const m = s.getUint8(e);
|
|
948
1077
|
e += 1, d = m >> 4 & 3, c = (m >> 3 & 1) === 1, h = (m >> 2 & 1) === 1, l = (m >> 1 & 1) === 1, u = (m & 1) === 1;
|
|
949
1078
|
}
|
|
950
|
-
let
|
|
1079
|
+
let p, f;
|
|
951
1080
|
{
|
|
952
1081
|
const m = s.getUint8(e);
|
|
953
1082
|
e += 1;
|
|
954
|
-
const
|
|
955
|
-
e += 1, (
|
|
1083
|
+
const k = m >> 6, y = s.getUint8(e);
|
|
1084
|
+
e += 1, (k & 2) === 2 && (p = this.parsePtsDts(s, e)), (k & 1) === 1 ? f = this.parsePtsDts(s, e + 5) : f = p, e += y;
|
|
956
1085
|
}
|
|
957
|
-
n = { stream_id: a, pes_packet_length: r, scrambling_control: d, priority: c, data_alignment: h, copyright: l, original_copy: u, pts:
|
|
1086
|
+
n = { stream_id: a, pes_packet_length: r, scrambling_control: d, priority: c, data_alignment: h, copyright: l, original_copy: u, pts: p, dts: f };
|
|
958
1087
|
}
|
|
959
1088
|
i = t.slice(e);
|
|
960
1089
|
{
|
|
961
1090
|
if (!this.audioConfig && s.getUint8(e) === 255) {
|
|
962
1091
|
const h = s.getUint8(e + 2), l = s.getUint8(e + 3);
|
|
963
|
-
let u,
|
|
964
|
-
|
|
965
|
-
const f = `mp4a.40.${u}`,
|
|
966
|
-
this.audioConfig = { kind: "audio", codec: f, sampleRate:
|
|
1092
|
+
let u, p;
|
|
1093
|
+
p = h >> 2 & 15, u = (h & 1) << 2 | l >> 6;
|
|
1094
|
+
const f = `mp4a.40.${u}`, k = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350][p];
|
|
1095
|
+
this.audioConfig = { kind: "audio", codec: f, sampleRate: k, numberOfChannels: u }, this.on.config && this.on.config(this.audioConfig);
|
|
967
1096
|
}
|
|
968
1097
|
const { dts: o = 0, pts: a = 0 } = n, r = a - o, d = i.slice(7);
|
|
969
1098
|
return { kind: "audio", type: "key", dts: o, pts: a, cts: r, data: d };
|
|
@@ -985,30 +1114,30 @@ class J {
|
|
|
985
1114
|
const m = s.getUint8(e);
|
|
986
1115
|
e += 1, d = m >> 4 & 3, c = (m >> 3 & 1) === 1, h = (m >> 2 & 1) === 1, l = (m >> 1 & 1) === 1, u = (m & 1) === 1;
|
|
987
1116
|
}
|
|
988
|
-
let
|
|
1117
|
+
let p, f;
|
|
989
1118
|
{
|
|
990
1119
|
const m = s.getUint8(e);
|
|
991
1120
|
e += 1;
|
|
992
|
-
const
|
|
993
|
-
e += 1, (
|
|
1121
|
+
const k = m >> 6, y = s.getUint8(e);
|
|
1122
|
+
e += 1, (k & 2) === 2 && (p = this.parsePtsDts(s, e)), (k & 1) === 1 ? f = this.parsePtsDts(s, e + 5) : f = p, e += y;
|
|
994
1123
|
}
|
|
995
|
-
n = { stream_id: a, pes_packet_length: r, scrambling_control: d, priority: c, data_alignment: h, copyright: l, original_copy: u, pts:
|
|
1124
|
+
n = { stream_id: a, pes_packet_length: r, scrambling_control: d, priority: c, data_alignment: h, copyright: l, original_copy: u, pts: p, dts: f };
|
|
996
1125
|
}
|
|
997
1126
|
i = t.slice(e);
|
|
998
1127
|
{
|
|
999
1128
|
const o = this.getNalus(i);
|
|
1000
1129
|
if (!this.videoConfig) {
|
|
1001
|
-
let u,
|
|
1002
|
-
if (u = o.find((m) => m.type === 7)?.nalu.slice(4),
|
|
1003
|
-
const f =
|
|
1004
|
-
this.videoConfig = { kind: "video", codec: m, description: f, sps: u, pps:
|
|
1130
|
+
let u, p;
|
|
1131
|
+
if (u = o.find((m) => m.type === 7)?.nalu.slice(4), p = o.find((m) => m.type === 8)?.nalu.slice(4), u && p) {
|
|
1132
|
+
const f = j(u, p), { codec: m } = M(f);
|
|
1133
|
+
this.videoConfig = { kind: "video", codec: m, description: f, sps: u, pps: p }, this.on.config && this.on.config(this.videoConfig);
|
|
1005
1134
|
}
|
|
1006
1135
|
}
|
|
1007
1136
|
const a = [];
|
|
1008
1137
|
let r = "delta";
|
|
1009
1138
|
for (const u of o) {
|
|
1010
|
-
const { type:
|
|
1011
|
-
switch (
|
|
1139
|
+
const { type: p, nalu: f } = u;
|
|
1140
|
+
switch (p) {
|
|
1012
1141
|
case 6:
|
|
1013
1142
|
// sei
|
|
1014
1143
|
case 9:
|
|
@@ -1022,7 +1151,7 @@ class J {
|
|
|
1022
1151
|
break;
|
|
1023
1152
|
}
|
|
1024
1153
|
}
|
|
1025
|
-
const d =
|
|
1154
|
+
const d = $(a), { dts: c = 0, pts: h = 0 } = n, l = h - c;
|
|
1026
1155
|
return { kind: "video", type: r, dts: c, pts: h, cts: l, data: d, nalus: a };
|
|
1027
1156
|
}
|
|
1028
1157
|
};
|
|
@@ -1053,15 +1182,15 @@ class J {
|
|
|
1053
1182
|
}
|
|
1054
1183
|
let o = e - n;
|
|
1055
1184
|
if (t[e - 1] === 0 && (o -= 1), o !== 0) {
|
|
1056
|
-
const a = t.slice(n, n + o), r =
|
|
1185
|
+
const a = t.slice(n, n + o), r = z(a);
|
|
1057
1186
|
s.push({ type: i, nalu: r });
|
|
1058
1187
|
}
|
|
1059
1188
|
}
|
|
1060
1189
|
return s;
|
|
1061
1190
|
};
|
|
1062
1191
|
}
|
|
1063
|
-
const
|
|
1064
|
-
class
|
|
1192
|
+
const w = (g, t) => g.getUint8(t) << 16 | g.getUint8(t + 1) << 8 | g.getUint8(t + 2);
|
|
1193
|
+
class Y {
|
|
1065
1194
|
audioConfig;
|
|
1066
1195
|
videoConfig;
|
|
1067
1196
|
header;
|
|
@@ -1099,8 +1228,8 @@ class Z {
|
|
|
1099
1228
|
const { codec: c, sps: h, pps: l, data: u } = r;
|
|
1100
1229
|
this.videoConfig = { kind: "video", codec: c, description: u, sps: h, pps: l }, this.on.config && this.on.config(this.videoConfig);
|
|
1101
1230
|
} else {
|
|
1102
|
-
const { frameType: c, cts: h, data: l, nalus: u } = r,
|
|
1103
|
-
this.on.chunk && this.on.chunk({ kind: "video", type:
|
|
1231
|
+
const { frameType: c, cts: h, data: l, nalus: u } = r, p = c === 1 ? "key" : "delta", f = h === void 0 ? void 0 : h + a;
|
|
1232
|
+
this.on.chunk && this.on.chunk({ kind: "video", type: p, dts: a, pts: f, cts: h, data: l, nalus: u });
|
|
1104
1233
|
}
|
|
1105
1234
|
}
|
|
1106
1235
|
break;
|
|
@@ -1130,7 +1259,7 @@ class Z {
|
|
|
1130
1259
|
else if (s + 4 + 11 > n)
|
|
1131
1260
|
e = !1;
|
|
1132
1261
|
else {
|
|
1133
|
-
const i =
|
|
1262
|
+
const i = w(t, s + 4 + 1);
|
|
1134
1263
|
s + 4 + 11 + i > n && (e = !1);
|
|
1135
1264
|
}
|
|
1136
1265
|
return e;
|
|
@@ -1153,7 +1282,7 @@ class Z {
|
|
|
1153
1282
|
}
|
|
1154
1283
|
e = d;
|
|
1155
1284
|
}
|
|
1156
|
-
return n =
|
|
1285
|
+
return n = w(t, s + 1), i = w(t, s + 4), o = t.getUint8(s + 7), a = w(t, s + 8), { tagType: e, dataSize: n, timestamp: i, timestampExtended: o, streamID: a };
|
|
1157
1286
|
};
|
|
1158
1287
|
parseTagBody = (t, s, e, n) => {
|
|
1159
1288
|
let i;
|
|
@@ -1194,8 +1323,8 @@ class Z {
|
|
|
1194
1323
|
n = n + 1;
|
|
1195
1324
|
const h = e, l = new Uint8Array(t.buffer.slice(n, n + h));
|
|
1196
1325
|
if (o === 10 && c === 0) {
|
|
1197
|
-
const u = t.getUint8(n),
|
|
1198
|
-
return { soundFormat: o, soundRate: a, soundSize: r, soundType: d, accPacketType: c, data: l, samplingFrequencyIndex: m, channelConfiguration:
|
|
1326
|
+
const u = t.getUint8(n), p = t.getUint8(n + 1), f = u >> 3 & 31, m = (u & 7) << 1 | p >> 7, k = p >> 3 & 15, y = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350], U = `mp4a.40.${f}`, b = y[m];
|
|
1327
|
+
return { soundFormat: o, soundRate: a, soundSize: r, soundType: d, accPacketType: c, data: l, samplingFrequencyIndex: m, channelConfiguration: k, codec: U, sampleRate: b };
|
|
1199
1328
|
}
|
|
1200
1329
|
return { soundFormat: o, soundRate: a, soundSize: r, soundType: d, accPacketType: c, data: l };
|
|
1201
1330
|
};
|
|
@@ -1205,19 +1334,19 @@ class Z {
|
|
|
1205
1334
|
n = n + 1;
|
|
1206
1335
|
const r = t.getUint8(n);
|
|
1207
1336
|
n = n + 1;
|
|
1208
|
-
const d =
|
|
1337
|
+
const d = w(t, n);
|
|
1209
1338
|
n = n + 3;
|
|
1210
1339
|
const c = e - 5, h = new Uint8Array(t.buffer.slice(n, n + c));
|
|
1211
1340
|
switch (a) {
|
|
1212
1341
|
case 7:
|
|
1213
1342
|
if (r === 0) {
|
|
1214
|
-
const l =
|
|
1343
|
+
const l = M(h);
|
|
1215
1344
|
return { frameType: o, codecID: a, avcPacketType: r, cts: d, data: h, ...l };
|
|
1216
1345
|
} else if (r === 1) {
|
|
1217
1346
|
const l = [], u = n + e - 5;
|
|
1218
1347
|
for (; !(n + 4 > u); ) {
|
|
1219
|
-
const
|
|
1220
|
-
n += 4 +
|
|
1348
|
+
const p = t.getUint32(n, !1), f = new Uint8Array(t.buffer.slice(n, n + 4 + p));
|
|
1349
|
+
n += 4 + p, l.push(f);
|
|
1221
1350
|
}
|
|
1222
1351
|
return { frameType: o, codecID: a, avcPacketType: r, cts: d, data: h, nalus: l };
|
|
1223
1352
|
}
|
|
@@ -1298,9 +1427,9 @@ class Z {
|
|
|
1298
1427
|
return { amfType: e, length: o, value: i };
|
|
1299
1428
|
};
|
|
1300
1429
|
}
|
|
1301
|
-
class
|
|
1430
|
+
class J {
|
|
1302
1431
|
pattern;
|
|
1303
|
-
cacher = new
|
|
1432
|
+
cacher = new H();
|
|
1304
1433
|
isParseing = !1;
|
|
1305
1434
|
offset = 0;
|
|
1306
1435
|
parser;
|
|
@@ -1310,10 +1439,10 @@ class et {
|
|
|
1310
1439
|
init = (t) => {
|
|
1311
1440
|
switch (this.destroy(), this.pattern = t, this.pattern) {
|
|
1312
1441
|
case "flv":
|
|
1313
|
-
this.parser = new
|
|
1442
|
+
this.parser = new Y();
|
|
1314
1443
|
break;
|
|
1315
1444
|
case "hls":
|
|
1316
|
-
this.parser = new
|
|
1445
|
+
this.parser = new X();
|
|
1317
1446
|
break;
|
|
1318
1447
|
default:
|
|
1319
1448
|
throw new Error("is error pattern.");
|
|
@@ -1345,7 +1474,7 @@ class et {
|
|
|
1345
1474
|
}
|
|
1346
1475
|
};
|
|
1347
1476
|
}
|
|
1348
|
-
class
|
|
1477
|
+
class Z {
|
|
1349
1478
|
pattern = "flv";
|
|
1350
1479
|
audioDecoderConfig;
|
|
1351
1480
|
audioDecoder;
|
|
@@ -1500,7 +1629,7 @@ class st {
|
|
|
1500
1629
|
}
|
|
1501
1630
|
};
|
|
1502
1631
|
}
|
|
1503
|
-
class
|
|
1632
|
+
class tt {
|
|
1504
1633
|
renderMap = /* @__PURE__ */ new Map();
|
|
1505
1634
|
constructor() {
|
|
1506
1635
|
}
|
|
@@ -1527,7 +1656,7 @@ class nt {
|
|
|
1527
1656
|
if (i === "default")
|
|
1528
1657
|
h(e);
|
|
1529
1658
|
else if (c) {
|
|
1530
|
-
const { sx: l = 0, sy: u = 0, sw:
|
|
1659
|
+
const { sx: l = 0, sy: u = 0, sw: p = e.width, sh: f = e.height } = c, m = await createImageBitmap(e, l, u, p, f);
|
|
1531
1660
|
h(m);
|
|
1532
1661
|
}
|
|
1533
1662
|
}
|
|
@@ -1571,11 +1700,11 @@ class nt {
|
|
|
1571
1700
|
};
|
|
1572
1701
|
}
|
|
1573
1702
|
export {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1703
|
+
Z as Decoder,
|
|
1704
|
+
N as DecoderWorker,
|
|
1705
|
+
J as Demuxer,
|
|
1706
|
+
P as DemuxerWorker,
|
|
1707
|
+
Q as PrPlayer,
|
|
1708
|
+
tt as Render,
|
|
1709
|
+
V as RenderWorker
|
|
1581
1710
|
};
|