pr-player 0.1.6 → 0.1.8

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 CHANGED
@@ -1,5 +1,5 @@
1
- const D = '(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>1e3&&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),8))}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=(_,m)=>{let b=BigInt(0);b|=BigInt(_.getUint16(m))<<25n,b|=BigInt(_.getUint16(m+1))<<17n,b|=BigInt(_.getUint16(m+2))<<9n,b|=BigInt(_.getUint16(m+3))<<1n,b|=BigInt(_.getUint16(m+4)>>7);const S=(_.getUint16(m+4)&1)<<8|_.getUint16(m+5);return b=b*300n+BigInt(S),b};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){const r=s.getUint8(e);if(e+=1,r===255){const g=s.getUint8(e),p=s.getUint8(e+1),h=p>>2&3,d=(g&248)>>3&3,u=p>>6&3,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][h],_=`mp4a.40.${d}`,m=u===3?1:2;this.audioConfig={kind:"audio",codec:_,sampleRate:U,numberOfChannels:m},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,pes_payload:a}}};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 O{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-2,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&248)>>3,f=(h&7)<<1|d>>7,U=(d&120)>>3,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],m=`mp4a.40.${u}`,b=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,audioObjectType:u,samplingFrequencyIndex:f,channelConfiguration:U,codec:m,sampleRate:b}}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 L{pattern;cacher=new P;isParseing=!1;offset=0;on={};parser;constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new O;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 L;A.on.debug=y=>postMessage({action:"onDebug",data:y}),A.on.info=y=>postMessage({action:"onInfo",data:y}),A.on.config=y=>postMessage({action:"onConfig",data:y}),A.on.chunk=y=>postMessage({action:"onChunk",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', v = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", D], { type: "text/javascript;charset=utf-8" });
2
- function B(l) {
1
+ const D = '(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>1e3&&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 l=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:l,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:h,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:l=[]}=this.pat||{};if(l.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(l=>l.elementary_pid===o);if(p){if(h===1){const l=this.payloadMap.get(o);if(l){switch(p.kind){case"audio":{const d=await this.parseAudio(l);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(l);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),8))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const l=this.payloadMap.get(o),d=new Uint8Array(l.byteLength+r.byteLength);d.set(l,0),d.set(r,l.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),h=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=(h&192)>>6,l=h>>4&3,d=h&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:l,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const h=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 l=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:h,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:l,last_section_number:d}}const a=[];{const h=n.section_length-5-4,i=e+h;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 h=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 l=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:h,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:l,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const h=n.section_length-9-4,i=e+h;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,h;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),l=!!(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),l&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,h=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:l,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:h}};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 h=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,l;{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,l=(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:h,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:l,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig){const r=s.getUint8(e);if(e+=1,r===255){const g=s.getUint8(e),p=s.getUint8(e+1),l=(g&248)>>3&3,d=p>>6&3,u=48e3,f=`mp4a.40.${l}`,U=d===3?1:2;this.audioConfig={kind:"audio",codec:f,sampleRate:u,numberOfChannels:U},this.on.config&&this.on.config(this.audioConfig)}}const{dts:o=0,pts:h=0}=n,i=h-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:h,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 h=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,l;{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,l=(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:h,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:l,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let l,d;if(l=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),l&&d){const u=I(l,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:l,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const h=[];let i="delta";for(const l of o){const{type:d,nalu:u}=l;switch(d){case 6:case 9:h.push(u);break;case 1:i="delta",h.push(u);break;case 5:i="key",h.push(u);break}}const c=C(h),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:h}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),h=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(h)&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 h=t.slice(n,n+o),i=M(h);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 O{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:h}=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",l=r===void 0?void 0:r+h;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:h,pts:l,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:l}=i;this.videoConfig={kind:"video",codec:r,description:l,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:l}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+h;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:h,pts:u,cts:g,data:p,nalus:l})}}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,h;{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),h=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:h}};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 h=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(h)||"")!=="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,h=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e-2,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const l=t.getUint8(n),d=t.getUint8(n+1),u=(l&248)>>3,f=(l&7)<<1|d>>7,U=(d&120)>>3,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:h,soundSize:i,soundType:c,accPacketType:r,data:p,audioObjectType:u,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:h,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,h=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(h){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:h,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],l=n+e-5;for(;!(n+4>l);){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:h,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:h,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 l=this.getAMFValue(t,n,p);n=n+l.length,a[g]=l.value,o=2+r+1+l.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 L{pattern;cacher=new P;isParseing=!1;offset=0;on={};parser;constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new O;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 L;A.on.debug=y=>postMessage({action:"onDebug",data:y}),A.on.info=y=>postMessage({action:"onInfo",data:y}),A.on.config=y=>postMessage({action:"onConfig",data:y}),A.on.chunk=y=>postMessage({action:"onChunk",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n', v = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", D], { type: "text/javascript;charset=utf-8" });
2
+ function R(l) {
3
3
  let t;
4
4
  try {
5
5
  if (t = v && (self.URL || self.webkitURL).createObjectURL(v), !t) throw "";
@@ -19,7 +19,7 @@ function B(l) {
19
19
  }
20
20
  }
21
21
  class L {
22
- worker = new B();
22
+ worker = new R();
23
23
  on = {};
24
24
  constructor() {
25
25
  this.worker.onmessage = (t) => {
@@ -584,7 +584,7 @@ class et {
584
584
  this.decoderWorker = new N(), this.decoderWorker.on.audio.decode = (t) => {
585
585
  this.audioPlayer?.push(t), this.on.decoder.audio && this.on.decoder.audio(t);
586
586
  }, this.decoderWorker.on.audio.error = (t) => {
587
- this.stop(), this.on.error && this.on.error(t);
587
+ console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m", "color:#0097ff;", "------->Breathe: e", t), this.on.error && this.on.error(t);
588
588
  }, this.decoderWorker.on.video.decode = async (t) => {
589
589
  this.renderWorker?.push(t);
590
590
  const s = [...this.cutRenders.keys()];
@@ -872,11 +872,11 @@ class Z {
872
872
  let e = s, n, i, r, c;
873
873
  const o = t.getUint8(e), d = !!(o & 128), a = !!(o & 64), h = !!(o & 32), p = !!(o & 16), u = !!(o & 8), g = !!(o & 4), f = !!(o & 2), m = !!(o & 1);
874
874
  e += 1;
875
- const k = (b, U) => {
876
- let w = BigInt(0);
877
- w |= BigInt(b.getUint16(U)) << 25n, w |= BigInt(b.getUint16(U + 1)) << 17n, w |= BigInt(b.getUint16(U + 2)) << 9n, w |= BigInt(b.getUint16(U + 3)) << 1n, w |= BigInt(b.getUint16(U + 4) >> 7);
878
- const R = (b.getUint16(U + 4) & 1) << 8 | b.getUint16(U + 5);
879
- return w = w * 300n + BigInt(R), w;
875
+ const k = (b, w) => {
876
+ let U = BigInt(0);
877
+ U |= BigInt(b.getUint16(w)) << 25n, U |= BigInt(b.getUint16(w + 1)) << 17n, U |= BigInt(b.getUint16(w + 2)) << 9n, U |= BigInt(b.getUint16(w + 3)) << 1n, U |= BigInt(b.getUint16(w + 4) >> 7);
878
+ const B = (b.getUint16(w + 4) & 1) << 8 | b.getUint16(w + 5);
879
+ return U = U * 300n + BigInt(B), U;
880
880
  };
881
881
  if (p && (n = k(t, e), e += 6), u && (i = k(t, e), e += 6), g && (r = t.getInt8(e), e += 1), f) {
882
882
  const b = t.getUint8(e);
@@ -914,12 +914,12 @@ class Z {
914
914
  if (!this.audioConfig) {
915
915
  const a = s.getUint8(e);
916
916
  if (e += 1, a === 255) {
917
- const h = s.getUint8(e), p = s.getUint8(e + 1), u = p >> 2 & 3, g = (h & 248) >> 3 & 3, f = p >> 6 & 3, k = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350][u], b = `mp4a.40.${g}`, U = f === 3 ? 1 : 2;
918
- this.audioConfig = { kind: "audio", codec: b, sampleRate: k, numberOfChannels: U }, this.on.config && this.on.config(this.audioConfig);
917
+ const h = s.getUint8(e), p = s.getUint8(e + 1), u = (h & 248) >> 3 & 3, g = p >> 6 & 3, f = 48e3, m = `mp4a.40.${u}`, k = g === 3 ? 1 : 2;
918
+ this.audioConfig = { kind: "audio", codec: m, sampleRate: f, numberOfChannels: k }, this.on.config && this.on.config(this.audioConfig);
919
919
  }
920
920
  }
921
921
  const { dts: r = 0, pts: c = 0 } = n, o = c - r, d = i.slice(7);
922
- return { kind: "audio", type: "key", dts: r, pts: c, cts: o, data: d, pes_payload: i };
922
+ return { kind: "audio", type: "key", dts: r, pts: c, cts: o, data: d };
923
923
  }
924
924
  };
925
925
  parseVideo = async (t) => {
@@ -1147,8 +1147,8 @@ class tt {
1147
1147
  n = n + 1;
1148
1148
  const h = e - 2, p = new Uint8Array(t.buffer.slice(n, n + h));
1149
1149
  if (r === 10 && a === 0) {
1150
- const u = t.getUint8(n), g = t.getUint8(n + 1), f = (u & 248) >> 3, m = (u & 7) << 1 | g >> 7, k = (g & 120) >> 3, b = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350], U = `mp4a.40.${f}`, w = b[m];
1151
- return { soundFormat: r, soundRate: c, soundSize: o, soundType: d, accPacketType: a, data: p, audioObjectType: f, samplingFrequencyIndex: m, channelConfiguration: k, codec: U, sampleRate: w };
1150
+ const u = t.getUint8(n), g = t.getUint8(n + 1), f = (u & 248) >> 3, m = (u & 7) << 1 | g >> 7, k = (g & 120) >> 3, b = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350], w = `mp4a.40.${f}`, U = b[m];
1151
+ return { soundFormat: r, soundRate: c, soundSize: o, soundType: d, accPacketType: a, data: p, audioObjectType: f, samplingFrequencyIndex: m, channelConfiguration: k, codec: w, sampleRate: U };
1152
1152
  }
1153
1153
  return { soundFormat: r, soundRate: c, soundSize: o, soundType: d, accPacketType: a, data: p };
1154
1154
  };
@@ -1,4 +1,4 @@
1
- (function(U,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(U=typeof globalThis<"u"?globalThis:U||self,T(U["pr-player"]={}))})(this,(function(U){"use strict";const T='(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>1e3&&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),8))}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=(_,m)=>{let b=BigInt(0);b|=BigInt(_.getUint16(m))<<25n,b|=BigInt(_.getUint16(m+1))<<17n,b|=BigInt(_.getUint16(m+2))<<9n,b|=BigInt(_.getUint16(m+3))<<1n,b|=BigInt(_.getUint16(m+4)>>7);const S=(_.getUint16(m+4)&1)<<8|_.getUint16(m+5);return b=b*300n+BigInt(S),b};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){const r=s.getUint8(e);if(e+=1,r===255){const g=s.getUint8(e),p=s.getUint8(e+1),h=p>>2&3,d=(g&248)>>3&3,u=p>>6&3,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][h],_=`mp4a.40.${d}`,m=u===3?1:2;this.audioConfig={kind:"audio",codec:_,sampleRate:U,numberOfChannels:m},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,pes_payload:a}}};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 O{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-2,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&248)>>3,f=(h&7)<<1|d>>7,U=(d&120)>>3,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],m=`mp4a.40.${u}`,b=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,audioObjectType:u,samplingFrequencyIndex:f,channelConfiguration:U,codec:m,sampleRate:b}}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 L{pattern;cacher=new P;isParseing=!1;offset=0;on={};parser;constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new O;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 L;A.on.debug=y=>postMessage({action:"onDebug",data:y}),A.on.info=y=>postMessage({action:"onInfo",data:y}),A.on.config=y=>postMessage({action:"onConfig",data:y}),A.on.chunk=y=>postMessage({action:"onChunk",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n',x=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",T],{type:"text/javascript;charset=utf-8"});function N(l){let t;try{if(t=x&&(self.URL||self.webkitURL).createObjectURL(x),!t)throw"";const s=new Worker(t,{name:l?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(T),{name:l?.name})}}class A{worker=new N;on={};constructor(){this.worker.onmessage=t=>{const{action:s,data:e}=t.data;switch(s){case"onInfo":this.on.info&&this.on.info(e);break;case"onConfig":this.on.config&&this.on.config(e);break;case"onDebug":this.on.debug&&this.on.debug(e);break;case"onChunk":this.on.chunk&&this.on.chunk(e);break}}}init=t=>this.worker.postMessage({action:"init",data:t});push=t=>this.worker.postMessage({action:"push",data:t});destroy=()=>{this.worker.postMessage({action:"destroy",data:{}}),this.worker.terminate()}}const C=`(function(){"use strict";class r{audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;on={audio:{},video:{}};constructor(){}audio={init:i=>{this.audio.destroy(),this.audioDecoderConfig={...i},this.audioDecoder=new AudioDecoder({output:e=>{this.on.audio.decode&&this.on.audio.decode(e)},error:e=>{this.on.audio.error&&this.on.audio.error(e)}}),this.audioDecoder.configure(this.audioDecoderConfig)},decode:i=>{if(!this.audioDecoder)return;const e=new EncodedAudioChunk(i);this.audioDecoder.decode(e)},flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={init:i=>{this.video.destroy(),this.videoDecoderConfig={...i},this.videoDecoder=new VideoDecoder({output:async e=>{const d=await createImageBitmap(e),s=e.timestamp;e.close(),d.width>0&&d.height>0?this.on.video.decode&&this.on.video.decode({timestamp:s,bitmap:d}):d.close()},error:e=>{console.log("\\x1B[38;2;0;151;255m%c%s\\x1B[0m","color:#0097ff;","------->Breathe: e",e),this.on.video.error&&this.on.video.error(e)}}),this.videoDecoder.configure(this.videoDecoderConfig)},decode:i=>{if(this.videoDecoder&&(i.type==="key"&&(this.hasKeyFrame=!0),this.hasKeyFrame&&this.videoDecoder.decodeQueueSize<2)){const e=new EncodedVideoChunk(i);this.videoDecoder.decode(e)}},flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}const t=new r;t.on.audio.decode=o=>postMessage({type:"audio",action:"onDecode",data:o}),t.on.audio.error=o=>postMessage({type:"audio",action:"onError",data:o}),t.on.video.decode=o=>postMessage({type:"video",action:"onDecode",data:o}),t.on.video.error=o=>postMessage({type:"video",action:"onError",data:o}),onmessage=o=>{const{type:i,action:e,data:d}=o.data,s=t[i][e];s&&s(d)}})();
2
- `,D=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",C],{type:"text/javascript;charset=utf-8"});function E(l){let t;try{if(t=D&&(self.URL||self.webkitURL).createObjectURL(D),!t)throw"";const s=new Worker(t,{name:l?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(C),{name:l?.name})}}class M{worker=new E;on={audio:{},video:{}};constructor(){this.worker.onmessage=t=>{const{type:s,action:e,data:n}=t.data;switch(s){case"audio":e==="onDecode"&&this.on.audio.decode&&this.on.audio.decode(n),e==="onError"&&this.on.audio.error&&this.on.audio.error(n);break;case"video":e==="onDecode"&&this.on.video.decode&&this.on.video.decode(n),e==="onError"&&this.on.video.error&&this.on.video.error(n);break}}}audio={init:t=>this.worker.postMessage({type:"audio",action:"init",data:t}),decode:t=>this.worker.postMessage({type:"audio",action:"decode",data:t}),flush:()=>this.worker.postMessage({type:"audio",action:"flush"}),destroy:()=>{this.worker.postMessage({type:"audio",action:"destroy"})}};video={init:t=>this.worker.postMessage({type:"video",action:"init",data:t}),decode:t=>this.worker.postMessage({type:"video",action:"decode",data:t}),flush:()=>this.worker.postMessage({type:"video",action:"flush"}),destroy:()=>{this.worker.postMessage({type:"video",action:"destroy",data:{}})}};destroy=()=>{this.worker.postMessage({type:"audio",action:"destroy"}),this.worker.postMessage({type:"video",action:"destroy",data:{}}),this.worker.terminate()}}var G=Object.defineProperty,O=(l,t,s)=>t in l?G(l,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[t]=s,m=(l,t,s)=>O(l,typeof t!="symbol"?t+"":t,s);class W{constructor(t,s){m(this,"inputStream",new MediaStream),m(this,"outputStream",new MediaStream),m(this,"inputGain",1),m(this,"enhanceGain",1),m(this,"bgsGain",1),m(this,"bgmGain",1),m(this,"outputGain",1),m(this,"mixAudioMap",new Map),m(this,"audioContext",new AudioContext),m(this,"sourceNode"),m(this,"inputGainNode"),m(this,"enhanceGainNode"),m(this,"bgsGainNode"),m(this,"bgmGainNode"),m(this,"analyserNode"),m(this,"analyserArrayData"),m(this,"outputGainNode"),m(this,"destinationNode"),m(this,"filterStream",e=>e),m(this,"stop",()=>{{const e=this.inputStream.getTracks();for(const n of e)n.stop(),this.inputStream.removeTrack(n)}}),m(this,"getStream",()=>this.filterStream(this.outputStream)),m(this,"setMute",(e=!0)=>{e?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),m(this,"setInputGain",e=>{this.inputGain=e,this.inputGainNode.gain.setValueAtTime(e,this.audioContext.currentTime)}),m(this,"setEnhanceGain",async e=>{this.enhanceGain=e+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),m(this,"setBgsGain",e=>{this.bgsGain=e,this.bgsGainNode.gain.setValueAtTime(e,this.audioContext.currentTime)}),m(this,"setBgmGain",e=>{this.bgmGain=e,this.bgmGainNode.gain.setValueAtTime(e,this.audioContext.currentTime)}),m(this,"setOutputGain",e=>{this.outputGain=e,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),m(this,"getVolume",()=>{const{analyserNode:e,analyserArrayData:n}=this;e.getByteFrequencyData(n);let i=0;for(let r=0;r<n.length;r++)i+=n[r];return Math.ceil(i/n.length)}),m(this,"mixAudio",(e,n="bgm")=>new Promise(async(i,r)=>{try{{const d=this.mixAudioMap.get(n);d&&d.stop()}const c=n==="bgs"?this.bgsGainNode:this.bgmGainNode,o=this.audioContext.createBufferSource();this.mixAudioMap.set(n,o),o.buffer=e,o.connect(c),o.onended=()=>{o.disconnect(c),this.mixAudioMap.delete(n),i(!0)},o.start(0)}catch(c){r(c)}})),m(this,"mixAudioStop",e=>{const n=this.mixAudioMap.get(e);n?.stop()}),m(this,"changeMix",(e,n)=>{const i=e==="bgs"?this.bgsGainNode:this.bgmGainNode;n?i.connect(this.destinationNode):i.disconnect(this.destinationNode)}),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;{const{sourceNode:e,inputGainNode:n,enhanceGainNode:i,bgsGainNode:r,bgmGainNode:c,analyserNode:o,outputGainNode:d,destinationNode:a}=this;e.connect(n),n.connect(i),i.connect(o),r.connect(o),c.connect(o),i.connect(a),r.connect(a),c.connect(a),o.connect(d),d.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}const V=async(l,t)=>{try{const{format:s,numberOfChannels:e,numberOfFrames:n,sampleRate:i}=t,r=l.createBuffer(e,n,i);for(let c=0;c<e;c++){const o=t.allocationSize({planeIndex:c}),d=new Uint8Array(o);t.copyTo(d,{planeIndex:c});const a=new DataView(d.buffer),h=r.getChannelData(c);for(let p=0;p<n;p++){let u;switch(s){case"s16":case"s16-planar":u=a.getInt16(p*2,!0)/32768;break;case"f32":case"f32-planar":u=a.getFloat32(p*4,!0);break;case"u8":case"u8-planar":u=(a.getUint8(p)-128)/128;break;default:throw new Error(`Unsupported audio format: ${s}`)}h[p]=Math.max(-1,Math.min(1,u))}}return r}catch(s){throw console.error("Failed to convert AudioData to AudioBuffer:",s),s}};class j{prAudioStream;audioContext;destination;stream=new MediaStream;nextStartTime=0;pendingSources=[];constructor(){}init=t=>{t||(t=new(window.AudioContext||window.webkitAudioContext)),this.audioContext=t,this.destination=this.audioContext.createMediaStreamDestination(),this.stream=new MediaStream,this.stream.addTrack(this.destination.stream.getAudioTracks()[0]),this.prAudioStream=new W(this.stream,this.audioContext),this.nextStartTime=0,this.pendingSources=[]};async push(t){try{if(!this.audioContext||!this.destination)return;const s=await V(this.audioContext,t);if(!s)return;const e=this.audioContext.createBufferSource();e.buffer=s,e.connect(this.destination);const n=Math.max(this.nextStartTime,this.audioContext.currentTime);this.nextStartTime=n+s.duration,e.start(n),this.pendingSources.push(e),e.onended=()=>{this.pendingSources=this.pendingSources.filter(i=>i!==e)},this.audioContext.state==="suspended"&&await this.audioContext.resume()}finally{t.close()}}getStream=()=>this.prAudioStream?.getStream();destroy(){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=[]}}const S=`(function(){"use strict";class r{isRendering=!1;pendingFrames=[];offscreenCanvas;writable;writer;ctx;cutOption;baseTime=0;pause=!1;shader=["stream"];constructor(){}init=({offscreenCanvas:e,writable:t})=>{this.destroy(),this.offscreenCanvas=e,this.writable=t,this.writer=this.writable.getWriter(),this.ctx=this.offscreenCanvas.getContext("2d")};setBaseTime=e=>{this.baseTime=e};setShader=e=>{this.shader=e};setSize=({width:e,height:t})=>{this.offscreenCanvas&&(this.offscreenCanvas.width=e,this.offscreenCanvas.height=t)};destroy=()=>{this.isRendering=!1,this.pendingFrames=[],this.offscreenCanvas=void 0,this.ctx=void 0,this.baseTime=0};push=e=>{this.pendingFrames.push(e),this.isRendering===!1&&setTimeout(this.renderFrame,0)};setCut=e=>{this.cutOption=e};setPause=e=>{this.pause=e,this.isRendering===!1&&setTimeout(this.renderFrame,0)};calculateTimeUntilNextFrame=e=>{const t=performance.timeOrigin+performance.now(),i=this.baseTime+e/1e3-t;return Math.max(0,i)};renderFrame=async()=>{for(this.isRendering=!0;;){const e=this.pendingFrames.shift();if(!e)break;let{timestamp:t,bitmap:s}=e;if(this.cutOption){const{sx:a=0,sy:c=0,sw:m=s.width,sh:o=s.height}=this.cutOption;s=await createImageBitmap(s,a,c,m,o)}const i=this.calculateTimeUntilNextFrame(t);await new Promise(a=>setTimeout(()=>a(!0),i)),this.drawImage({timestamp:t,bitmap:s}),this.cutOption&&s.close()}this.isRendering=!1};drawImage=e=>{if(this.pause!==!0){if(this.shader.includes("stream")){const t=new VideoFrame(e.bitmap,{timestamp:e.timestamp});this.writer.write(t),t.close()}this.shader.includes("canvas")&&this.ctx&&this.offscreenCanvas&&this.ctx.drawImage(e.bitmap,0,0,this.offscreenCanvas.width,this.offscreenCanvas.height)}}}const h=new r;onmessage=n=>{const{action:e,data:t}=n.data,s=h[e];s&&s(t)}})();
3
- `,P=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",S],{type:"text/javascript;charset=utf-8"});function z(l){let t;try{if(t=P&&(self.URL||self.webkitURL).createObjectURL(P),!t)throw"";const s=new Worker(t,{name:l?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(S),{name:l?.name})}}class I{worker=new z;constructor(){}init=({offscreenCanvas:t,writable:s})=>this.worker.postMessage({action:"init",data:{offscreenCanvas:t,writable:s}},[t,s]);setShader=t=>this.worker.postMessage({action:"setShader",data:t});setBaseTime=t=>this.worker.postMessage({action:"setBaseTime",data:t});setSize=({width:t,height:s})=>this.worker.postMessage({action:"setSize",data:{width:t,height:s}});push=t=>this.worker.postMessage({action:"push",data:t});setCut=async t=>this.worker.postMessage({action:"setCut",data:t});setPause=t=>this.worker.postMessage({action:"setPause",data:t});destroy=()=>{this.worker.postMessage({action:"destroy",data:{}}),this.worker.terminate()}}const $=l=>{const t=l.toLowerCase();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"},R=l=>{const t=l?.getTracks()||[];for(const s of t)s.stop()},B=()=>{const l=new I,t=document.createElement("canvas"),s=t.transferControlToOffscreen(),e=new MediaStreamTrackGenerator({kind:"video"}),n=new MediaStream([e]),i=()=>{l.destroy(),R(n)};return l.init({offscreenCanvas:s,writable:e.writable}),{worker:l,canvas:t,stream:n,destroy:i}};class H{resolvesMap=new Map;index=0;constructor(){}add=(t,s=()=>!1,e=0)=>new Promise(n=>{if(s())return n(!0);this.resolvesMap.has(t)||this.resolvesMap.set(t,new Map),this.index++;const c=`${this.index}`;if(e=Math.max(0,e),e===0){this.resolvesMap.get(t)?.set(c,{resolve:n,timer:0});return}const o=window.setTimeout(()=>{this.emit(t)},e);this.resolvesMap.get(t)?.set(c,{resolve:n,timer:o})});emit=async t=>{const s=this.resolvesMap.get(t);if(!s)return;const e=[...s.keys()];for(const n of e){const i=s.get(n);i&&(clearTimeout(i.timer),i.resolve(),s.delete(n))}}}const q=(l,t)=>{const s=new Uint8Array(l),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let i=0;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},L=l=>{let t=0;const s=new DataView(l.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 i=s.getUint8(t)&255;t=t+1;const r=s.getUint8(t)&255;t=t+1;const d=`avc1.${Array.from([n,i,r],k=>k.toString(16).padStart(2,"0")).join("")}`,a=(s.getUint8(t)&3)-1;t=t+1;const h=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const u=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const g=s.getUint8(t)&31;t=t+1;const f=s.getUint16(t,!1);t=t+2;const y=new Uint8Array(s.buffer.slice(t,t+f));return t=t+f,{version:e,codec:d,profile:n,compatibility:i,level:r,lengthSizeMinusOne:a,numOfSequenceParameterSets:h,sequenceParameterSetLength:p,sps:u,numOfPictureParameterSets:g,pictureParameterSetLength:f,pps:y}},K=l=>{const t=new Uint8Array(4+l.length);return new DataView(t.buffer).setUint32(0,l.length,!1),t.set(l,4),t},X=l=>{let t=0;for(const n of l)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of l){const i=n;s.set(i,e),e+=i.length}return s},Y=l=>{const t=new DataView(l.buffer);let s=0,e,n,i;e=t.getUint32(s,!1),s+=4;{const r=t.getUint8(s),c=r>>7&1,o=r>>5&3,d=r&31;n={forbidden_zero_bit:c,nal_ref_idc:o,nal_unit_type:d},s+=1}{const r=e-1;i=new Uint8Array(t.buffer.slice(s,s+r))}return{size:e,header:n,data:i}};class F{#e={timeout:5*1e3,check:!1};#t;constructor(t={}){this.#e={...this.#e,...t}}check=(t,s)=>new Promise(async(e,n)=>{this.stop(),this.#t=new AbortController;const i=window.setTimeout(()=>{this.#t?.abort("Timeout."),n({status:"timeout",reason:""})},this.#e.timeout);try{const r=await fetch(t,{...s,method:"HEAD",signal:this.#t?.signal});r.status===200?e({status:"successed",reason:""}):n({status:"failed",reason:`${r.status}`})}catch(r){n({status:"error",reason:r.message})}clearTimeout(i)});request=async(t,s)=>new Promise(async(e,n)=>{try{this.#e.check&&await this.check(t,s),this.#t=new AbortController;const i=await fetch(t,{...s,signal:this.#t?.signal});e(i)}catch(i){this.stop(),n(i)}});stop=()=>{this.#t?.signal.aborted===!1&&this.#t.abort("Actively stop.")}}class Q{option={debug:!1};prFetch=new F;prResolves=new H;url="";demuxerWorker;decoderWorker;audioPlayer;renderWorker;renderBaseTime;stream;canvas;on={demuxer:{},decoder:{}};cutRenders=new Map;trackGenerator;constructor(t={}){const{debug:s=!1}=t;this.option.debug=s}init=()=>{this.initDecoder(),this.audioPlayer=new j,this.audioPlayer.init(),this.initRender()};start=async t=>{this.stop(),this.url=t,this.init();const s=$(t);if(s==="unknown")throw new Error("This address cannot be parsed.");switch(this.initDemuxer(s),s){case"flv":this.flv.start();break;case"hls":this.hls.start();break}};stop=async()=>{try{clearInterval(this.hls.getSegmentsTimer),this.prFetch.stop()}catch(s){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: error",s)}this.demuxerWorker?.destroy(),this.decoderWorker?.destroy(),this.renderWorker?.destroy(),R(this.stream);const t=[...this.cutRenders.keys()];for(const s of t)this.cut.remove(s);this.audioPlayer?.destroy(),this.renderBaseTime=void 0,this.canvas=void 0};getCanvas=()=>this.canvas;getStream=()=>this.stream;setPause=t=>{this.renderWorker?.setPause(t)};setShader=t=>{this.renderWorker?.setShader(t)};setMute=t=>this.audioPlayer?.prAudioStream?.setMute(t);isReady=()=>{const t=()=>this.stream?.active===!0;return this.prResolves.add("isReady",t)};cut={create:(t,s)=>{let e=this.cutRenders.get(t);return e?(e.worker.setCut(s),e.worker.setPause(!1),e):(e=B(),e.worker.setBaseTime(this.renderBaseTime||0),e.worker.setCut(s),this.cutRenders.set(t,e),e)},getCanvas:t=>this.cutRenders.get(t)?.canvas,getStream:t=>this.cutRenders.get(t)?.stream,setPause:(t,s)=>{this.cutRenders.get(t)?.worker.setPause(s)},setShader:(t,s)=>{this.cutRenders.get(t)?.worker.setShader(s)},remove:t=>{this.cutRenders.get(t)?.destroy(),this.cutRenders.delete(t)}};initDemuxer=t=>{this.demuxerWorker=new A,this.demuxerWorker.init(t),this.demuxerWorker.on.debug=s=>{this.option.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: debug",s)},this.demuxerWorker.on.info=s=>{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)},this.demuxerWorker.on.config=s=>{this.option.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: config",s),this.on.demuxer.config&&this.on.demuxer.config(s);const{kind:e}=s;switch(e){case"audio":{const{codec:n,sampleRate:i,numberOfChannels:r}=s;this.decoderWorker?.audio.init({codec:n,sampleRate:i,numberOfChannels:r})}break;case"video":{const{codec:n,description:i}=s;this.decoderWorker?.video.init({codec:n,description:i})}break}},this.demuxerWorker.on.chunk=s=>{if(this.on.demuxer.chunk&&this.on.demuxer.chunk(s),!this.decoderWorker)return;const{kind:e}=s;switch(e){case"audio":{const{type:n,dts:i,data:r}=s,c=i*1;this.decoderWorker.audio.decode({type:n,timestamp:c,data:r})}break;case"video":{const{type:n,dts:i,data:r,nalus:c=[]}=s;if(this.renderBaseTime===void 0){const d=new Date().getTime();this.renderBaseTime=d-i,this.renderWorker?.setBaseTime(this.renderBaseTime)}const o=i*1e3;this.decoderWorker.video.decode({type:n,timestamp:o,data:r});for(const d of c){if(d.byteLength<=4)continue;const{header:a,data:h}=Y(d),{nal_unit_type:p}=a;p===6&&this.on.demuxer.sei&&this.on.demuxer.sei(h)}}break}}};initDecoder=()=>{this.decoderWorker=new M,this.decoderWorker.on.audio.decode=t=>{this.audioPlayer?.push(t),this.on.decoder.audio&&this.on.decoder.audio(t)},this.decoderWorker.on.audio.error=t=>{this.stop(),this.on.error&&this.on.error(t)},this.decoderWorker.on.video.decode=async t=>{this.renderWorker?.push(t);const s=[...this.cutRenders.keys()];for(const e of s)this.cutRenders.get(e)?.worker.push(t);this.on.decoder.video&&this.on.decoder.video(t),t.bitmap.close()},this.decoderWorker.on.video.error=t=>{this.stop(),this.on.error&&this.on.error(t)}};initRender=()=>{const{worker:t,canvas:s,stream:e}=B();this.renderWorker=t,this.canvas=s,this.stream=e,this.renderWorker.setPause(!1)};flv={start:async()=>{try{const s=(await this.prFetch.request(this.url)).body?.getReader();if(!s)throw new Error("reader is error.");for(;;){const{done:e,value:n}=await s.read();if(n&&this.demuxerWorker?.push(n),e)break}}catch(t){if(t?.name!=="AbortError")throw Error(t)}}};hls={isLive:!1,urls:[],url:"",getSegmentsTimer:0,parse:async t=>{const n=new TextDecoder("utf-8").decode(t).split(`
4
- `).map(a=>a.replace("\r","")),i=this.url.substring(0,this.url.lastIndexOf("/")+1);let r=4,c=0,o=!1;const d=[];for(const a of n)a.startsWith("#EXTINF:")?r=parseFloat(a.split(":")[1].split(",")[0]):a.startsWith("#EXT-X-TARGETDURATION:")?c=parseInt(a.split(":")[1]):a.startsWith("#EXT-X-ENDLIST")?o=!1:a.startsWith("#EXT-X-MEDIA-SEQUENCE:")?o=!0:a.includes(".ts")&&!a.startsWith("#")&&d.push({url:a.startsWith("http")?a:i+a,duration:r,isLive:o});return{baseUrl:i,targetDuration:c,isLive:o,segments:d}},getSegments:async()=>{const e=(await new F().request(this.url)).body?.getReader();if(!e)throw new Error("reader is error.");for(;;){const{done:n,value:i}=await e.read();if(i){const r=await this.hls.parse(i),{segments:c=[],isLive:o=!1}=r;this.hls.isLive=o;let d=Array.from(c,h=>h.url);const a=d.findIndex(h=>h===this.hls.url);a!==-1&&(d=d.slice(a+1)),this.hls.urls=d}if(n)break}},getData:async()=>{},start:async()=>{try{for(await this.hls.getSegments(),this.hls.getSegmentsTimer=window.setInterval(this.hls.getSegments,1e3),this.hls.isLive===!1&&clearInterval(this.hls.getSegmentsTimer);;){const t=this.hls.urls.shift();if(t){this.hls.url=t;const e=(await this.prFetch.request(t)).body?.getReader();if(!e)throw new Error("segment reader is error.");for(;;){const{done:n,value:i}=await e.read();if(i&&this.demuxerWorker?.push(i),n)break}}await new Promise(s=>setTimeout(()=>s(!0),500))}}catch(t){if(t?.name!=="AbortError")throw Error(t)}}}}class J{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>1e3&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const Z=l=>{let t="unknown";switch(l){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 tt{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:i,pid:r,payload_unit_start_indicator:c,adaptation_field_control:o}=n;if(i===1||r===void 0)return;let d=184;if(o===2||o===3){const a=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=a,d-=a}if(o===3&&(d-=1),o===1||o===3){const a=new Uint8Array(t.buffer.slice(e,e+d));if(r===0)return this.parsePAT(t,e);{const{programs:u=[]}=this.pat||{};if(u.find(f=>f.pmt_pid===r))return this.parsePMT(t,e)}const{streams:h=[]}=this.pmt||{},p=h.find(u=>u.elementary_pid===r);if(p){if(c===1){const u=this.payloadMap.get(r);if(u){switch(p.kind){case"audio":{const g=await this.parseAudio(u);this.on.chunk&&this.on.chunk(g)}break;case"video":{const g=await this.parseVideo(u);this.on.chunk&&this.on.chunk(g),await new Promise(f=>setTimeout(()=>f(!0),8))}break}this.payloadMap.delete(r)}}{this.payloadMap.has(r)||this.payloadMap.set(r,new Uint8Array);const u=this.payloadMap.get(r),g=new Uint8Array(u.byteLength+a.byteLength);g.set(u,0),g.set(a,u.byteLength),this.payloadMap.set(r,g)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),i=t.getUint8(e+1),r=t.getUint8(e+2),c=t.getUint8(e+3),o=(i&128)>>7;if(o===1)return{sync_byte:n,transport_error_indicator:o};const d=(i&64)>>6,a=(i&32)>>5,h=(i&31)<<8|r,p=(c&192)>>6,u=c>>4&3,g=c&15;return{sync_byte:n,transport_error_indicator:o,payload_unit_start_indicator:d,transport_priority:a,pid:h,transport_scrambling_control:p,adaptation_field_control:u,continuity_counter:g}};parsePAT=(t,s)=>{let e=s,n;{const c=t.getUint8(e);e+=1;const o=t.getUint8(e);if(e+=1,o!==0)throw new Error("Invalid PAT table_id");const d=t.getUint16(e)&4095;e+=2;const a=t.getUint16(e);e+=2;const h=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const u=t.getUint8(e);e+=1;const g=t.getUint8(e);e+=1,n={pointer_field:c,table_id:o,section_length:d,transport_stream_id:a,version_number:h,current_next_indicator:p,section_number:u,last_section_number:g}}const i=[];{const c=n.section_length-5-4,o=e+c;for(;e<o;){const d=t.getUint16(e),a=t.getUint16(e+2)&8191;e+=4,d!==0&&a>=32&&a<=8190&&i.push({program_number:d,pmt_pid:a})}}const r=t.getUint32(e);this.pat={header:n,programs:i,crc32:r},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const c=t.getUint8(e);e+=1;const o=t.getUint8(e);if(e+=1,o!==2)throw new Error("Invalid PMT table_id");const d=t.getUint16(e)&4095;e+=2;const a=t.getUint16(e);e+=2;const h=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const u=t.getUint8(e);e+=1;const g=t.getUint8(e);e+=1;const f=t.getUint16(e)&8191;e+=2;const y=t.getUint16(e)&4095;e+=2,n={pointer_field:c,table_id:o,section_length:d,transport_stream_id:a,version_number:h,current_next_indicator:p,section_number:u,last_section_number:g,pcr_pid:f,program_info_length:y}}const i=[];{const c=n.section_length-9-4,o=e+c;for(;e<o;){const d=t.getUint8(e),a=Z(d),h=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,h<32||h>8190){console.warn(`Invalid elementary_pid: 0x${h.toString(16)}`);continue}i.push({kind:a,stream_type:d,elementary_pid:h,es_info_length:p})}}const r=t.getUint32(e);this.pmt={header:n,streams:i,crc32:r},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,i,r,c;const o=t.getUint8(e),d=!!(o&128),a=!!(o&64),h=!!(o&32),p=!!(o&16),u=!!(o&8),g=!!(o&4),f=!!(o&2),y=!!(o&1);e+=1;const k=(b,w)=>{let _=BigInt(0);_|=BigInt(b.getUint16(w))<<25n,_|=BigInt(b.getUint16(w+1))<<17n,_|=BigInt(b.getUint16(w+2))<<9n,_|=BigInt(b.getUint16(w+3))<<1n,_|=BigInt(b.getUint16(w+4)>>7);const ot=(b.getUint16(w+4)&1)<<8|b.getUint16(w+5);return _=_*300n+BigInt(ot),_};if(p&&(n=k(t,e),e+=6),u&&(i=k(t,e),e+=6),g&&(r=t.getInt8(e),e+=1),f){const b=t.getUint8(e);e+=1,c=new Uint8Array(t.buffer,e,b),e+=b}return{discontinuity_indicator:d,random_access_indicator:a,elementary_stream_priority_indicator:h,pcr_flag:p,opcr_flag:u,splicing_point_flag:g,transport_private_data_flag:f,adaptation_field_extension_flag:y,pcr:n,opcr:i,splice_countdown:r,transport_private_data:c}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,i;{const r=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!r)throw new Error("invalid ts audio payload.");const c=s.getUint8(e);e+=1;const o=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let d,a,h,p,u;{const y=s.getUint8(e);e+=1,d=y>>4&3,a=(y>>3&1)===1,h=(y>>2&1)===1,p=(y>>1&1)===1,u=(y&1)===1}let g,f;{const y=s.getUint8(e);e+=1;const k=y>>6,b=s.getUint8(e);e+=1,(k&2)===2&&(g=this.parsePtsDts(s,e)),(k&1)===1?f=this.parsePtsDts(s,e+5):f=g,e+=b}n={stream_id:c,pes_packet_length:o,scrambling_control:d,priority:a,data_alignment:h,copyright:p,original_copy:u,pts:g,dts:f}}i=t.slice(e);{if(!this.audioConfig){const a=s.getUint8(e);if(e+=1,a===255){const h=s.getUint8(e),p=s.getUint8(e+1),u=p>>2&3,g=(h&248)>>3&3,f=p>>6&3,k=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][u],b=`mp4a.40.${g}`,w=f===3?1:2;this.audioConfig={kind:"audio",codec:b,sampleRate:k,numberOfChannels:w},this.on.config&&this.on.config(this.audioConfig)}}const{dts:r=0,pts:c=0}=n,o=c-r,d=i.slice(7);return{kind:"audio",type:"key",dts:r,pts:c,cts:o,data:d,pes_payload:i}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,i;{const r=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!r)throw new Error("invalid ts video payload.");const c=s.getUint8(e);e+=1;const o=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let d,a,h,p,u;{const y=s.getUint8(e);e+=1,d=y>>4&3,a=(y>>3&1)===1,h=(y>>2&1)===1,p=(y>>1&1)===1,u=(y&1)===1}let g,f;{const y=s.getUint8(e);e+=1;const k=y>>6,b=s.getUint8(e);e+=1,(k&2)===2&&(g=this.parsePtsDts(s,e)),(k&1)===1?f=this.parsePtsDts(s,e+5):f=g,e+=b}n={stream_id:c,pes_packet_length:o,scrambling_control:d,priority:a,data_alignment:h,copyright:p,original_copy:u,pts:g,dts:f}}i=t.slice(e);{const r=this.getNalus(i);if(!this.videoConfig){let u,g;if(u=r.find(y=>y.type===7)?.nalu.slice(4),g=r.find(y=>y.type===8)?.nalu.slice(4),u&&g){const f=q(u,g),{codec:y}=L(f);this.videoConfig={kind:"video",codec:y,description:f,sps:u,pps:g},this.on.config&&this.on.config(this.videoConfig)}}const c=[];let o="delta";for(const u of r){const{type:g,nalu:f}=u;switch(g){case 6:case 9:c.push(f);break;case 1:o="delta",c.push(f);break;case 5:o="key",c.push(f);break}}const d=X(c),{dts:a=0,pts:h=0}=n,p=h-a;return{kind:"video",type:o,dts:a,pts:h,cts:p,data:d,nalus:c}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),i=t.getUint8(s+2),r=t.getUint8(s+3),c=t.getUint8(s+4),o=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(i)&0b11111110n)<<14n|(BigInt(r)&0b11111111n)<<7n|(BigInt(c)&0b11111110n)>>1n;return Number(o)/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 i=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 r=e-n;if(t[e-1]===0&&(r-=1),r!==0){const c=t.slice(n,n+r),o=K(c);s.push({type:i,nalu:o})}}return s}}const v=(l,t)=>l.getUint8(t)<<16|l.getUint8(t+1)<<8|l.getUint8(t+2);class et{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:i,dataSize:r,timestamp:c}=n;if(i){const o=this.parseTagBody(i,t,s+4+11,r);switch(i){case"script":this.on.info&&this.on.info(o);break;case"audio":{const{accPacketType:d}=o;if(d===0){const{codec:a,sampleRate:h,channelConfiguration:p}=o;this.audioConfig={kind:"audio",codec:a,sampleRate:h,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:a,data:h}=o,p="key",u=a===void 0?void 0:a+c;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:c,pts:u,cts:a,data:h})}}break;case"video":{const{avcPacketType:d}=o;if(d===0){const{codec:a,sps:h,pps:p,data:u}=o;this.videoConfig={kind:"video",codec:a,description:u,sps:h,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:a,cts:h,data:p,nalus:u}=o,g=a===1?"key":"delta",f=h===void 0?void 0:h+c;this.on.chunk&&this.on.chunk({kind:"video",type:g,dts:c,pts:f,cts:h,data:p,nalus:u})}}break}s=s+4+11+r}await new Promise(o=>setTimeout(()=>o(!0),8))}return s};parseHeader=(t,s)=>{let e,n,i,r;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const o=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,d,,a]=o;i={audio:a==="1",video:d==="1"}}r=t.getUint32(5),this.header={signature:e,version:n,flags:i,dataOffset:r}};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 i=v(t,s+4+1);s+4+11+i>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,i,r,c;{const o=t.getUint8(s);let d;switch(o){case 18:d="script";break;case 8:d="audio";break;case 9:d="video";break}e=d}return n=v(t,s+1),i=v(t,s+4),r=t.getUint8(s+7),c=v(t,s+8),{tagType:e,dataSize:n,timestamp:i,timestampExtended:r,streamID:c}};parseTagBody=(t,s,e,n)=>{let i;switch(t){case"script":i=this.parseMetaData(s,e);break;case"audio":i=this.parseAudio(s,e,n);break;case"video":i=this.parseVideo(s,e,n);break}return i};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 c=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(c)||"")!=="onMetaData")throw new Error("Expected 'onMetaData' string");e=e+n}const i=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,i).value};parseAudio=(t,s,e)=>{let n=s;const i=t.getUint8(n),r=i>>4&15,c=i>>2&3,o=i>>1&1,d=i&1;n=n+1;const a=t.getUint8(n);n=n+1;const h=e-2,p=new Uint8Array(t.buffer.slice(n,n+h));if(r===10&&a===0){const u=t.getUint8(n),g=t.getUint8(n+1),f=(u&248)>>3,y=(u&7)<<1|g>>7,k=(g&120)>>3,b=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],w=`mp4a.40.${f}`,_=b[y];return{soundFormat:r,soundRate:c,soundSize:o,soundType:d,accPacketType:a,data:p,audioObjectType:f,samplingFrequencyIndex:y,channelConfiguration:k,codec:w,sampleRate:_}}return{soundFormat:r,soundRate:c,soundSize:o,soundType:d,accPacketType:a,data:p}};parseVideo=(t,s,e)=>{let n=s;const i=t.getUint8(n),r=i>>4&15,c=i&15;n=n+1;const o=t.getUint8(n);n=n+1;const d=v(t,n);n=n+3;const a=e-5,h=new Uint8Array(t.buffer.slice(n,n+a));switch(c){case 7:if(o===0){const p=L(h);return{frameType:r,codecID:c,avcPacketType:o,cts:d,data:h,...p}}else if(o===1){const p=[],u=n+e-5;for(;!(n+4>u);){const g=t.getUint32(n,!1),f=new Uint8Array(t.buffer.slice(n,n+4+g));n+=4+g,p.push(f)}return{frameType:r,codecID:c,avcPacketType:o,cts:d,data:h,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:r,codecID:c,avcPacketType:o,cts:d,data:h}};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,i,r=0;switch(e){case 0:i=t.getFloat64(n,!1),r=8;break;case 1:i=!!t.getUint8(n),r=1;break;case 2:{i="";const o=t.getUint16(n,!1);n=n+2;const d=new Int8Array(t.buffer,n,o).filter(h=>h!==0);i=(this.textDecoder?.decode(d)||"").trim(),r=2+o}break;case 3:for(i={};n<t.byteLength;){const o=t.getUint16(n,!1);if(o===0)break;n=n+2;const d=this.getAMFName(t,n,o);n=n+o;const a=this.getAmfType(t,n);if(a===6)break;n=n+1;const h=this.getAMFValue(t,n,a);n=n+h.length,i[d]=h.value,r=2+o+1+h.length}break;case 8:{i={};const o=t.getUint32(n,!1);n=n+4;for(let d=0;d<o;d++){const a=t.getUint16(n,!1);n=n+2;const h=this.getAMFName(t,n,a);n=n+a;const p=this.getAmfType(t,n);n=n+1;const u=this.getAMFValue(t,n,p);n=n+u.length,i[h]=u.value,r=2+a+1+u.length}}break;case 10:{i=[];const o=t.getUint32(n,!1);n=n+4;for(let d=0;d<o;d++){const a=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,a);n=n+h.length,i.push(h.value),r=1+h.length}}break}return{amfType:e,length:r,value:i}}}class st{pattern;cacher=new J;isParseing=!1;offset=0;on={};parser;constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new et;break;case"hls":this.parser=new tt;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()}}}class nt{audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;on={audio:{},video:{}};constructor(){}audio={init:t=>{this.audio.destroy(),this.audioDecoderConfig={...t},this.audioDecoder=new AudioDecoder({output:s=>{this.on.audio.decode&&this.on.audio.decode(s)},error:s=>{this.on.audio.error&&this.on.audio.error(s)}}),this.audioDecoder.configure(this.audioDecoderConfig)},decode:t=>{if(!this.audioDecoder)return;const s=new EncodedAudioChunk(t);this.audioDecoder.decode(s)},flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={init:t=>{this.video.destroy(),this.videoDecoderConfig={...t},this.videoDecoder=new VideoDecoder({output:async s=>{const e=await createImageBitmap(s),n=s.timestamp;s.close(),e.width>0&&e.height>0?this.on.video.decode&&this.on.video.decode({timestamp:n,bitmap:e}):e.close()},error:s=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: e",s),this.on.video.error&&this.on.video.error(s)}}),this.videoDecoder.configure(this.videoDecoderConfig)},decode:t=>{if(this.videoDecoder&&(t.type==="key"&&(this.hasKeyFrame=!0),this.hasKeyFrame&&this.videoDecoder.decodeQueueSize<2)){const s=new EncodedVideoChunk(t);this.videoDecoder.decode(s)}},flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}class it{isRendering=!1;pendingFrames=[];offscreenCanvas;writable;writer;ctx;cutOption;baseTime=0;pause=!1;shader=["stream"];constructor(){}init=({offscreenCanvas:t,writable:s})=>{this.destroy(),this.offscreenCanvas=t,this.writable=s,this.writer=this.writable.getWriter(),this.ctx=this.offscreenCanvas.getContext("2d")};setBaseTime=t=>{this.baseTime=t};setShader=t=>{this.shader=t};setSize=({width:t,height:s})=>{this.offscreenCanvas&&(this.offscreenCanvas.width=t,this.offscreenCanvas.height=s)};destroy=()=>{this.isRendering=!1,this.pendingFrames=[],this.offscreenCanvas=void 0,this.ctx=void 0,this.baseTime=0};push=t=>{this.pendingFrames.push(t),this.isRendering===!1&&setTimeout(this.renderFrame,0)};setCut=t=>{this.cutOption=t};setPause=t=>{this.pause=t,this.isRendering===!1&&setTimeout(this.renderFrame,0)};calculateTimeUntilNextFrame=t=>{const s=performance.timeOrigin+performance.now(),n=this.baseTime+t/1e3-s;return Math.max(0,n)};renderFrame=async()=>{for(this.isRendering=!0;;){const t=this.pendingFrames.shift();if(!t)break;let{timestamp:s,bitmap:e}=t;if(this.cutOption){const{sx:i=0,sy:r=0,sw:c=e.width,sh:o=e.height}=this.cutOption;e=await createImageBitmap(e,i,r,c,o)}const n=this.calculateTimeUntilNextFrame(s);await new Promise(i=>setTimeout(()=>i(!0),n)),this.drawImage({timestamp:s,bitmap:e}),this.cutOption&&e.close()}this.isRendering=!1};drawImage=t=>{if(this.pause!==!0){if(this.shader.includes("stream")){const s=new VideoFrame(t.bitmap,{timestamp:t.timestamp});this.writer.write(s),s.close()}this.shader.includes("canvas")&&this.ctx&&this.offscreenCanvas&&this.ctx.drawImage(t.bitmap,0,0,this.offscreenCanvas.width,this.offscreenCanvas.height)}}}U.Decoder=nt,U.DecoderWorker=M,U.Demuxer=st,U.DemuxerWorker=A,U.PrPlayer=Q,U.Render=it,U.RenderWorker=I,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(U,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(U=typeof globalThis<"u"?globalThis:U||self,T(U["pr-player"]={}))})(this,(function(U){"use strict";const T='(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>1e3&&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 l=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:l,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:h,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:l=[]}=this.pat||{};if(l.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(l=>l.elementary_pid===o);if(p){if(h===1){const l=this.payloadMap.get(o);if(l){switch(p.kind){case"audio":{const d=await this.parseAudio(l);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(l);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),8))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const l=this.payloadMap.get(o),d=new Uint8Array(l.byteLength+r.byteLength);d.set(l,0),d.set(r,l.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),h=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=(h&192)>>6,l=h>>4&3,d=h&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:l,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const h=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 l=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:h,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:l,last_section_number:d}}const a=[];{const h=n.section_length-5-4,i=e+h;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 h=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 l=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:h,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:l,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const h=n.section_length-9-4,i=e+h;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,h;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),l=!!(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),l&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,h=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:l,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:h}};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 h=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,l;{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,l=(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:h,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:l,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig){const r=s.getUint8(e);if(e+=1,r===255){const g=s.getUint8(e),p=s.getUint8(e+1),l=(g&248)>>3&3,d=p>>6&3,u=48e3,f=`mp4a.40.${l}`,U=d===3?1:2;this.audioConfig={kind:"audio",codec:f,sampleRate:u,numberOfChannels:U},this.on.config&&this.on.config(this.audioConfig)}}const{dts:o=0,pts:h=0}=n,i=h-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:h,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 h=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,l;{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,l=(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:h,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:l,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let l,d;if(l=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),l&&d){const u=I(l,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:l,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const h=[];let i="delta";for(const l of o){const{type:d,nalu:u}=l;switch(d){case 6:case 9:h.push(u);break;case 1:i="delta",h.push(u);break;case 5:i="key",h.push(u);break}}const c=C(h),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:h}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),h=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(h)&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 h=t.slice(n,n+o),i=M(h);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 O{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:h}=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",l=r===void 0?void 0:r+h;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:h,pts:l,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:l}=i;this.videoConfig={kind:"video",codec:r,description:l,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:l}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+h;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:h,pts:u,cts:g,data:p,nalus:l})}}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,h;{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),h=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:h}};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 h=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(h)||"")!=="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,h=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e-2,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const l=t.getUint8(n),d=t.getUint8(n+1),u=(l&248)>>3,f=(l&7)<<1|d>>7,U=(d&120)>>3,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:h,soundSize:i,soundType:c,accPacketType:r,data:p,audioObjectType:u,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:h,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,h=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(h){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:h,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],l=n+e-5;for(;!(n+4>l);){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:h,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:h,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 l=this.getAMFValue(t,n,p);n=n+l.length,a[g]=l.value,o=2+r+1+l.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 L{pattern;cacher=new P;isParseing=!1;offset=0;on={};parser;constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new O;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 L;A.on.debug=y=>postMessage({action:"onDebug",data:y}),A.on.info=y=>postMessage({action:"onInfo",data:y}),A.on.config=y=>postMessage({action:"onConfig",data:y}),A.on.chunk=y=>postMessage({action:"onChunk",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n',x=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",T],{type:"text/javascript;charset=utf-8"});function N(l){let t;try{if(t=x&&(self.URL||self.webkitURL).createObjectURL(x),!t)throw"";const s=new Worker(t,{name:l?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(T),{name:l?.name})}}class A{worker=new N;on={};constructor(){this.worker.onmessage=t=>{const{action:s,data:e}=t.data;switch(s){case"onInfo":this.on.info&&this.on.info(e);break;case"onConfig":this.on.config&&this.on.config(e);break;case"onDebug":this.on.debug&&this.on.debug(e);break;case"onChunk":this.on.chunk&&this.on.chunk(e);break}}}init=t=>this.worker.postMessage({action:"init",data:t});push=t=>this.worker.postMessage({action:"push",data:t});destroy=()=>{this.worker.postMessage({action:"destroy",data:{}}),this.worker.terminate()}}const C=`(function(){"use strict";class r{audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;on={audio:{},video:{}};constructor(){}audio={init:i=>{this.audio.destroy(),this.audioDecoderConfig={...i},this.audioDecoder=new AudioDecoder({output:e=>{this.on.audio.decode&&this.on.audio.decode(e)},error:e=>{this.on.audio.error&&this.on.audio.error(e)}}),this.audioDecoder.configure(this.audioDecoderConfig)},decode:i=>{if(!this.audioDecoder)return;const e=new EncodedAudioChunk(i);this.audioDecoder.decode(e)},flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={init:i=>{this.video.destroy(),this.videoDecoderConfig={...i},this.videoDecoder=new VideoDecoder({output:async e=>{const d=await createImageBitmap(e),s=e.timestamp;e.close(),d.width>0&&d.height>0?this.on.video.decode&&this.on.video.decode({timestamp:s,bitmap:d}):d.close()},error:e=>{console.log("\\x1B[38;2;0;151;255m%c%s\\x1B[0m","color:#0097ff;","------->Breathe: e",e),this.on.video.error&&this.on.video.error(e)}}),this.videoDecoder.configure(this.videoDecoderConfig)},decode:i=>{if(this.videoDecoder&&(i.type==="key"&&(this.hasKeyFrame=!0),this.hasKeyFrame&&this.videoDecoder.decodeQueueSize<2)){const e=new EncodedVideoChunk(i);this.videoDecoder.decode(e)}},flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}const t=new r;t.on.audio.decode=o=>postMessage({type:"audio",action:"onDecode",data:o}),t.on.audio.error=o=>postMessage({type:"audio",action:"onError",data:o}),t.on.video.decode=o=>postMessage({type:"video",action:"onDecode",data:o}),t.on.video.error=o=>postMessage({type:"video",action:"onError",data:o}),onmessage=o=>{const{type:i,action:e,data:d}=o.data,s=t[i][e];s&&s(d)}})();
2
+ `,D=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",C],{type:"text/javascript;charset=utf-8"});function E(l){let t;try{if(t=D&&(self.URL||self.webkitURL).createObjectURL(D),!t)throw"";const s=new Worker(t,{name:l?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(C),{name:l?.name})}}class M{worker=new E;on={audio:{},video:{}};constructor(){this.worker.onmessage=t=>{const{type:s,action:e,data:n}=t.data;switch(s){case"audio":e==="onDecode"&&this.on.audio.decode&&this.on.audio.decode(n),e==="onError"&&this.on.audio.error&&this.on.audio.error(n);break;case"video":e==="onDecode"&&this.on.video.decode&&this.on.video.decode(n),e==="onError"&&this.on.video.error&&this.on.video.error(n);break}}}audio={init:t=>this.worker.postMessage({type:"audio",action:"init",data:t}),decode:t=>this.worker.postMessage({type:"audio",action:"decode",data:t}),flush:()=>this.worker.postMessage({type:"audio",action:"flush"}),destroy:()=>{this.worker.postMessage({type:"audio",action:"destroy"})}};video={init:t=>this.worker.postMessage({type:"video",action:"init",data:t}),decode:t=>this.worker.postMessage({type:"video",action:"decode",data:t}),flush:()=>this.worker.postMessage({type:"video",action:"flush"}),destroy:()=>{this.worker.postMessage({type:"video",action:"destroy",data:{}})}};destroy=()=>{this.worker.postMessage({type:"audio",action:"destroy"}),this.worker.postMessage({type:"video",action:"destroy",data:{}}),this.worker.terminate()}}var G=Object.defineProperty,O=(l,t,s)=>t in l?G(l,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[t]=s,y=(l,t,s)=>O(l,typeof t!="symbol"?t+"":t,s);class W{constructor(t,s){y(this,"inputStream",new MediaStream),y(this,"outputStream",new MediaStream),y(this,"inputGain",1),y(this,"enhanceGain",1),y(this,"bgsGain",1),y(this,"bgmGain",1),y(this,"outputGain",1),y(this,"mixAudioMap",new Map),y(this,"audioContext",new AudioContext),y(this,"sourceNode"),y(this,"inputGainNode"),y(this,"enhanceGainNode"),y(this,"bgsGainNode"),y(this,"bgmGainNode"),y(this,"analyserNode"),y(this,"analyserArrayData"),y(this,"outputGainNode"),y(this,"destinationNode"),y(this,"filterStream",e=>e),y(this,"stop",()=>{{const e=this.inputStream.getTracks();for(const n of e)n.stop(),this.inputStream.removeTrack(n)}}),y(this,"getStream",()=>this.filterStream(this.outputStream)),y(this,"setMute",(e=!0)=>{e?this.analyserNode.disconnect(this.outputGainNode):this.analyserNode.connect(this.outputGainNode)}),y(this,"setInputGain",e=>{this.inputGain=e,this.inputGainNode.gain.setValueAtTime(e,this.audioContext.currentTime)}),y(this,"setEnhanceGain",async e=>{this.enhanceGain=e+1,this.enhanceGainNode.gain.setValueAtTime(this.enhanceGain,this.audioContext.currentTime)}),y(this,"setBgsGain",e=>{this.bgsGain=e,this.bgsGainNode.gain.setValueAtTime(e,this.audioContext.currentTime)}),y(this,"setBgmGain",e=>{this.bgmGain=e,this.bgmGainNode.gain.setValueAtTime(e,this.audioContext.currentTime)}),y(this,"setOutputGain",e=>{this.outputGain=e,this.outputGainNode.gain.setValueAtTime(this.outputGain,this.audioContext.currentTime)}),y(this,"getVolume",()=>{const{analyserNode:e,analyserArrayData:n}=this;e.getByteFrequencyData(n);let i=0;for(let r=0;r<n.length;r++)i+=n[r];return Math.ceil(i/n.length)}),y(this,"mixAudio",(e,n="bgm")=>new Promise(async(i,r)=>{try{{const d=this.mixAudioMap.get(n);d&&d.stop()}const c=n==="bgs"?this.bgsGainNode:this.bgmGainNode,o=this.audioContext.createBufferSource();this.mixAudioMap.set(n,o),o.buffer=e,o.connect(c),o.onended=()=>{o.disconnect(c),this.mixAudioMap.delete(n),i(!0)},o.start(0)}catch(c){r(c)}})),y(this,"mixAudioStop",e=>{const n=this.mixAudioMap.get(e);n?.stop()}),y(this,"changeMix",(e,n)=>{const i=e==="bgs"?this.bgsGainNode:this.bgmGainNode;n?i.connect(this.destinationNode):i.disconnect(this.destinationNode)}),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;{const{sourceNode:e,inputGainNode:n,enhanceGainNode:i,bgsGainNode:r,bgmGainNode:c,analyserNode:o,outputGainNode:d,destinationNode:a}=this;e.connect(n),n.connect(i),i.connect(o),r.connect(o),c.connect(o),i.connect(a),r.connect(a),c.connect(a),o.connect(d),d.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}const V=async(l,t)=>{try{const{format:s,numberOfChannels:e,numberOfFrames:n,sampleRate:i}=t,r=l.createBuffer(e,n,i);for(let c=0;c<e;c++){const o=t.allocationSize({planeIndex:c}),d=new Uint8Array(o);t.copyTo(d,{planeIndex:c});const a=new DataView(d.buffer),h=r.getChannelData(c);for(let p=0;p<n;p++){let u;switch(s){case"s16":case"s16-planar":u=a.getInt16(p*2,!0)/32768;break;case"f32":case"f32-planar":u=a.getFloat32(p*4,!0);break;case"u8":case"u8-planar":u=(a.getUint8(p)-128)/128;break;default:throw new Error(`Unsupported audio format: ${s}`)}h[p]=Math.max(-1,Math.min(1,u))}}return r}catch(s){throw console.error("Failed to convert AudioData to AudioBuffer:",s),s}};class j{prAudioStream;audioContext;destination;stream=new MediaStream;nextStartTime=0;pendingSources=[];constructor(){}init=t=>{t||(t=new(window.AudioContext||window.webkitAudioContext)),this.audioContext=t,this.destination=this.audioContext.createMediaStreamDestination(),this.stream=new MediaStream,this.stream.addTrack(this.destination.stream.getAudioTracks()[0]),this.prAudioStream=new W(this.stream,this.audioContext),this.nextStartTime=0,this.pendingSources=[]};async push(t){try{if(!this.audioContext||!this.destination)return;const s=await V(this.audioContext,t);if(!s)return;const e=this.audioContext.createBufferSource();e.buffer=s,e.connect(this.destination);const n=Math.max(this.nextStartTime,this.audioContext.currentTime);this.nextStartTime=n+s.duration,e.start(n),this.pendingSources.push(e),e.onended=()=>{this.pendingSources=this.pendingSources.filter(i=>i!==e)},this.audioContext.state==="suspended"&&await this.audioContext.resume()}finally{t.close()}}getStream=()=>this.prAudioStream?.getStream();destroy(){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=[]}}const S=`(function(){"use strict";class r{isRendering=!1;pendingFrames=[];offscreenCanvas;writable;writer;ctx;cutOption;baseTime=0;pause=!1;shader=["stream"];constructor(){}init=({offscreenCanvas:e,writable:t})=>{this.destroy(),this.offscreenCanvas=e,this.writable=t,this.writer=this.writable.getWriter(),this.ctx=this.offscreenCanvas.getContext("2d")};setBaseTime=e=>{this.baseTime=e};setShader=e=>{this.shader=e};setSize=({width:e,height:t})=>{this.offscreenCanvas&&(this.offscreenCanvas.width=e,this.offscreenCanvas.height=t)};destroy=()=>{this.isRendering=!1,this.pendingFrames=[],this.offscreenCanvas=void 0,this.ctx=void 0,this.baseTime=0};push=e=>{this.pendingFrames.push(e),this.isRendering===!1&&setTimeout(this.renderFrame,0)};setCut=e=>{this.cutOption=e};setPause=e=>{this.pause=e,this.isRendering===!1&&setTimeout(this.renderFrame,0)};calculateTimeUntilNextFrame=e=>{const t=performance.timeOrigin+performance.now(),i=this.baseTime+e/1e3-t;return Math.max(0,i)};renderFrame=async()=>{for(this.isRendering=!0;;){const e=this.pendingFrames.shift();if(!e)break;let{timestamp:t,bitmap:s}=e;if(this.cutOption){const{sx:a=0,sy:c=0,sw:m=s.width,sh:o=s.height}=this.cutOption;s=await createImageBitmap(s,a,c,m,o)}const i=this.calculateTimeUntilNextFrame(t);await new Promise(a=>setTimeout(()=>a(!0),i)),this.drawImage({timestamp:t,bitmap:s}),this.cutOption&&s.close()}this.isRendering=!1};drawImage=e=>{if(this.pause!==!0){if(this.shader.includes("stream")){const t=new VideoFrame(e.bitmap,{timestamp:e.timestamp});this.writer.write(t),t.close()}this.shader.includes("canvas")&&this.ctx&&this.offscreenCanvas&&this.ctx.drawImage(e.bitmap,0,0,this.offscreenCanvas.width,this.offscreenCanvas.height)}}}const h=new r;onmessage=n=>{const{action:e,data:t}=n.data,s=h[e];s&&s(t)}})();
3
+ `,P=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",S],{type:"text/javascript;charset=utf-8"});function z(l){let t;try{if(t=P&&(self.URL||self.webkitURL).createObjectURL(P),!t)throw"";const s=new Worker(t,{name:l?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(S),{name:l?.name})}}class I{worker=new z;constructor(){}init=({offscreenCanvas:t,writable:s})=>this.worker.postMessage({action:"init",data:{offscreenCanvas:t,writable:s}},[t,s]);setShader=t=>this.worker.postMessage({action:"setShader",data:t});setBaseTime=t=>this.worker.postMessage({action:"setBaseTime",data:t});setSize=({width:t,height:s})=>this.worker.postMessage({action:"setSize",data:{width:t,height:s}});push=t=>this.worker.postMessage({action:"push",data:t});setCut=async t=>this.worker.postMessage({action:"setCut",data:t});setPause=t=>this.worker.postMessage({action:"setPause",data:t});destroy=()=>{this.worker.postMessage({action:"destroy",data:{}}),this.worker.terminate()}}const $=l=>{const t=l.toLowerCase();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"},R=l=>{const t=l?.getTracks()||[];for(const s of t)s.stop()},B=()=>{const l=new I,t=document.createElement("canvas"),s=t.transferControlToOffscreen(),e=new MediaStreamTrackGenerator({kind:"video"}),n=new MediaStream([e]),i=()=>{l.destroy(),R(n)};return l.init({offscreenCanvas:s,writable:e.writable}),{worker:l,canvas:t,stream:n,destroy:i}};class H{resolvesMap=new Map;index=0;constructor(){}add=(t,s=()=>!1,e=0)=>new Promise(n=>{if(s())return n(!0);this.resolvesMap.has(t)||this.resolvesMap.set(t,new Map),this.index++;const c=`${this.index}`;if(e=Math.max(0,e),e===0){this.resolvesMap.get(t)?.set(c,{resolve:n,timer:0});return}const o=window.setTimeout(()=>{this.emit(t)},e);this.resolvesMap.get(t)?.set(c,{resolve:n,timer:o})});emit=async t=>{const s=this.resolvesMap.get(t);if(!s)return;const e=[...s.keys()];for(const n of e){const i=s.get(n);i&&(clearTimeout(i.timer),i.resolve(),s.delete(n))}}}const q=(l,t)=>{const s=new Uint8Array(l),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let i=0;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},L=l=>{let t=0;const s=new DataView(l.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 i=s.getUint8(t)&255;t=t+1;const r=s.getUint8(t)&255;t=t+1;const d=`avc1.${Array.from([n,i,r],k=>k.toString(16).padStart(2,"0")).join("")}`,a=(s.getUint8(t)&3)-1;t=t+1;const h=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const u=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const g=s.getUint8(t)&31;t=t+1;const f=s.getUint16(t,!1);t=t+2;const m=new Uint8Array(s.buffer.slice(t,t+f));return t=t+f,{version:e,codec:d,profile:n,compatibility:i,level:r,lengthSizeMinusOne:a,numOfSequenceParameterSets:h,sequenceParameterSetLength:p,sps:u,numOfPictureParameterSets:g,pictureParameterSetLength:f,pps:m}},K=l=>{const t=new Uint8Array(4+l.length);return new DataView(t.buffer).setUint32(0,l.length,!1),t.set(l,4),t},X=l=>{let t=0;for(const n of l)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of l){const i=n;s.set(i,e),e+=i.length}return s},Y=l=>{const t=new DataView(l.buffer);let s=0,e,n,i;e=t.getUint32(s,!1),s+=4;{const r=t.getUint8(s),c=r>>7&1,o=r>>5&3,d=r&31;n={forbidden_zero_bit:c,nal_ref_idc:o,nal_unit_type:d},s+=1}{const r=e-1;i=new Uint8Array(t.buffer.slice(s,s+r))}return{size:e,header:n,data:i}};class F{#e={timeout:5*1e3,check:!1};#t;constructor(t={}){this.#e={...this.#e,...t}}check=(t,s)=>new Promise(async(e,n)=>{this.stop(),this.#t=new AbortController;const i=window.setTimeout(()=>{this.#t?.abort("Timeout."),n({status:"timeout",reason:""})},this.#e.timeout);try{const r=await fetch(t,{...s,method:"HEAD",signal:this.#t?.signal});r.status===200?e({status:"successed",reason:""}):n({status:"failed",reason:`${r.status}`})}catch(r){n({status:"error",reason:r.message})}clearTimeout(i)});request=async(t,s)=>new Promise(async(e,n)=>{try{this.#e.check&&await this.check(t,s),this.#t=new AbortController;const i=await fetch(t,{...s,signal:this.#t?.signal});e(i)}catch(i){this.stop(),n(i)}});stop=()=>{this.#t?.signal.aborted===!1&&this.#t.abort("Actively stop.")}}class Q{option={debug:!1};prFetch=new F;prResolves=new H;url="";demuxerWorker;decoderWorker;audioPlayer;renderWorker;renderBaseTime;stream;canvas;on={demuxer:{},decoder:{}};cutRenders=new Map;trackGenerator;constructor(t={}){const{debug:s=!1}=t;this.option.debug=s}init=()=>{this.initDecoder(),this.audioPlayer=new j,this.audioPlayer.init(),this.initRender()};start=async t=>{this.stop(),this.url=t,this.init();const s=$(t);if(s==="unknown")throw new Error("This address cannot be parsed.");switch(this.initDemuxer(s),s){case"flv":this.flv.start();break;case"hls":this.hls.start();break}};stop=async()=>{try{clearInterval(this.hls.getSegmentsTimer),this.prFetch.stop()}catch(s){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: error",s)}this.demuxerWorker?.destroy(),this.decoderWorker?.destroy(),this.renderWorker?.destroy(),R(this.stream);const t=[...this.cutRenders.keys()];for(const s of t)this.cut.remove(s);this.audioPlayer?.destroy(),this.renderBaseTime=void 0,this.canvas=void 0};getCanvas=()=>this.canvas;getStream=()=>this.stream;setPause=t=>{this.renderWorker?.setPause(t)};setShader=t=>{this.renderWorker?.setShader(t)};setMute=t=>this.audioPlayer?.prAudioStream?.setMute(t);isReady=()=>{const t=()=>this.stream?.active===!0;return this.prResolves.add("isReady",t)};cut={create:(t,s)=>{let e=this.cutRenders.get(t);return e?(e.worker.setCut(s),e.worker.setPause(!1),e):(e=B(),e.worker.setBaseTime(this.renderBaseTime||0),e.worker.setCut(s),this.cutRenders.set(t,e),e)},getCanvas:t=>this.cutRenders.get(t)?.canvas,getStream:t=>this.cutRenders.get(t)?.stream,setPause:(t,s)=>{this.cutRenders.get(t)?.worker.setPause(s)},setShader:(t,s)=>{this.cutRenders.get(t)?.worker.setShader(s)},remove:t=>{this.cutRenders.get(t)?.destroy(),this.cutRenders.delete(t)}};initDemuxer=t=>{this.demuxerWorker=new A,this.demuxerWorker.init(t),this.demuxerWorker.on.debug=s=>{this.option.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: debug",s)},this.demuxerWorker.on.info=s=>{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)},this.demuxerWorker.on.config=s=>{this.option.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: config",s),this.on.demuxer.config&&this.on.demuxer.config(s);const{kind:e}=s;switch(e){case"audio":{const{codec:n,sampleRate:i,numberOfChannels:r}=s;this.decoderWorker?.audio.init({codec:n,sampleRate:i,numberOfChannels:r})}break;case"video":{const{codec:n,description:i}=s;this.decoderWorker?.video.init({codec:n,description:i})}break}},this.demuxerWorker.on.chunk=s=>{if(this.on.demuxer.chunk&&this.on.demuxer.chunk(s),!this.decoderWorker)return;const{kind:e}=s;switch(e){case"audio":{const{type:n,dts:i,data:r}=s,c=i*1;this.decoderWorker.audio.decode({type:n,timestamp:c,data:r})}break;case"video":{const{type:n,dts:i,data:r,nalus:c=[]}=s;if(this.renderBaseTime===void 0){const d=new Date().getTime();this.renderBaseTime=d-i,this.renderWorker?.setBaseTime(this.renderBaseTime)}const o=i*1e3;this.decoderWorker.video.decode({type:n,timestamp:o,data:r});for(const d of c){if(d.byteLength<=4)continue;const{header:a,data:h}=Y(d),{nal_unit_type:p}=a;p===6&&this.on.demuxer.sei&&this.on.demuxer.sei(h)}}break}}};initDecoder=()=>{this.decoderWorker=new M,this.decoderWorker.on.audio.decode=t=>{this.audioPlayer?.push(t),this.on.decoder.audio&&this.on.decoder.audio(t)},this.decoderWorker.on.audio.error=t=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: e",t),this.on.error&&this.on.error(t)},this.decoderWorker.on.video.decode=async t=>{this.renderWorker?.push(t);const s=[...this.cutRenders.keys()];for(const e of s)this.cutRenders.get(e)?.worker.push(t);this.on.decoder.video&&this.on.decoder.video(t),t.bitmap.close()},this.decoderWorker.on.video.error=t=>{this.stop(),this.on.error&&this.on.error(t)}};initRender=()=>{const{worker:t,canvas:s,stream:e}=B();this.renderWorker=t,this.canvas=s,this.stream=e,this.renderWorker.setPause(!1)};flv={start:async()=>{try{const s=(await this.prFetch.request(this.url)).body?.getReader();if(!s)throw new Error("reader is error.");for(;;){const{done:e,value:n}=await s.read();if(n&&this.demuxerWorker?.push(n),e)break}}catch(t){if(t?.name!=="AbortError")throw Error(t)}}};hls={isLive:!1,urls:[],url:"",getSegmentsTimer:0,parse:async t=>{const n=new TextDecoder("utf-8").decode(t).split(`
4
+ `).map(a=>a.replace("\r","")),i=this.url.substring(0,this.url.lastIndexOf("/")+1);let r=4,c=0,o=!1;const d=[];for(const a of n)a.startsWith("#EXTINF:")?r=parseFloat(a.split(":")[1].split(",")[0]):a.startsWith("#EXT-X-TARGETDURATION:")?c=parseInt(a.split(":")[1]):a.startsWith("#EXT-X-ENDLIST")?o=!1:a.startsWith("#EXT-X-MEDIA-SEQUENCE:")?o=!0:a.includes(".ts")&&!a.startsWith("#")&&d.push({url:a.startsWith("http")?a:i+a,duration:r,isLive:o});return{baseUrl:i,targetDuration:c,isLive:o,segments:d}},getSegments:async()=>{const e=(await new F().request(this.url)).body?.getReader();if(!e)throw new Error("reader is error.");for(;;){const{done:n,value:i}=await e.read();if(i){const r=await this.hls.parse(i),{segments:c=[],isLive:o=!1}=r;this.hls.isLive=o;let d=Array.from(c,h=>h.url);const a=d.findIndex(h=>h===this.hls.url);a!==-1&&(d=d.slice(a+1)),this.hls.urls=d}if(n)break}},getData:async()=>{},start:async()=>{try{for(await this.hls.getSegments(),this.hls.getSegmentsTimer=window.setInterval(this.hls.getSegments,1e3),this.hls.isLive===!1&&clearInterval(this.hls.getSegmentsTimer);;){const t=this.hls.urls.shift();if(t){this.hls.url=t;const e=(await this.prFetch.request(t)).body?.getReader();if(!e)throw new Error("segment reader is error.");for(;;){const{done:n,value:i}=await e.read();if(i&&this.demuxerWorker?.push(i),n)break}}await new Promise(s=>setTimeout(()=>s(!0),500))}}catch(t){if(t?.name!=="AbortError")throw Error(t)}}}}class J{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>1e3&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const Z=l=>{let t="unknown";switch(l){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 tt{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:i,pid:r,payload_unit_start_indicator:c,adaptation_field_control:o}=n;if(i===1||r===void 0)return;let d=184;if(o===2||o===3){const a=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=a,d-=a}if(o===3&&(d-=1),o===1||o===3){const a=new Uint8Array(t.buffer.slice(e,e+d));if(r===0)return this.parsePAT(t,e);{const{programs:u=[]}=this.pat||{};if(u.find(f=>f.pmt_pid===r))return this.parsePMT(t,e)}const{streams:h=[]}=this.pmt||{},p=h.find(u=>u.elementary_pid===r);if(p){if(c===1){const u=this.payloadMap.get(r);if(u){switch(p.kind){case"audio":{const g=await this.parseAudio(u);this.on.chunk&&this.on.chunk(g)}break;case"video":{const g=await this.parseVideo(u);this.on.chunk&&this.on.chunk(g),await new Promise(f=>setTimeout(()=>f(!0),8))}break}this.payloadMap.delete(r)}}{this.payloadMap.has(r)||this.payloadMap.set(r,new Uint8Array);const u=this.payloadMap.get(r),g=new Uint8Array(u.byteLength+a.byteLength);g.set(u,0),g.set(a,u.byteLength),this.payloadMap.set(r,g)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),i=t.getUint8(e+1),r=t.getUint8(e+2),c=t.getUint8(e+3),o=(i&128)>>7;if(o===1)return{sync_byte:n,transport_error_indicator:o};const d=(i&64)>>6,a=(i&32)>>5,h=(i&31)<<8|r,p=(c&192)>>6,u=c>>4&3,g=c&15;return{sync_byte:n,transport_error_indicator:o,payload_unit_start_indicator:d,transport_priority:a,pid:h,transport_scrambling_control:p,adaptation_field_control:u,continuity_counter:g}};parsePAT=(t,s)=>{let e=s,n;{const c=t.getUint8(e);e+=1;const o=t.getUint8(e);if(e+=1,o!==0)throw new Error("Invalid PAT table_id");const d=t.getUint16(e)&4095;e+=2;const a=t.getUint16(e);e+=2;const h=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const u=t.getUint8(e);e+=1;const g=t.getUint8(e);e+=1,n={pointer_field:c,table_id:o,section_length:d,transport_stream_id:a,version_number:h,current_next_indicator:p,section_number:u,last_section_number:g}}const i=[];{const c=n.section_length-5-4,o=e+c;for(;e<o;){const d=t.getUint16(e),a=t.getUint16(e+2)&8191;e+=4,d!==0&&a>=32&&a<=8190&&i.push({program_number:d,pmt_pid:a})}}const r=t.getUint32(e);this.pat={header:n,programs:i,crc32:r},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const c=t.getUint8(e);e+=1;const o=t.getUint8(e);if(e+=1,o!==2)throw new Error("Invalid PMT table_id");const d=t.getUint16(e)&4095;e+=2;const a=t.getUint16(e);e+=2;const h=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const u=t.getUint8(e);e+=1;const g=t.getUint8(e);e+=1;const f=t.getUint16(e)&8191;e+=2;const m=t.getUint16(e)&4095;e+=2,n={pointer_field:c,table_id:o,section_length:d,transport_stream_id:a,version_number:h,current_next_indicator:p,section_number:u,last_section_number:g,pcr_pid:f,program_info_length:m}}const i=[];{const c=n.section_length-9-4,o=e+c;for(;e<o;){const d=t.getUint8(e),a=Z(d),h=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,h<32||h>8190){console.warn(`Invalid elementary_pid: 0x${h.toString(16)}`);continue}i.push({kind:a,stream_type:d,elementary_pid:h,es_info_length:p})}}const r=t.getUint32(e);this.pmt={header:n,streams:i,crc32:r},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,i,r,c;const o=t.getUint8(e),d=!!(o&128),a=!!(o&64),h=!!(o&32),p=!!(o&16),u=!!(o&8),g=!!(o&4),f=!!(o&2),m=!!(o&1);e+=1;const k=(b,_)=>{let w=BigInt(0);w|=BigInt(b.getUint16(_))<<25n,w|=BigInt(b.getUint16(_+1))<<17n,w|=BigInt(b.getUint16(_+2))<<9n,w|=BigInt(b.getUint16(_+3))<<1n,w|=BigInt(b.getUint16(_+4)>>7);const ot=(b.getUint16(_+4)&1)<<8|b.getUint16(_+5);return w=w*300n+BigInt(ot),w};if(p&&(n=k(t,e),e+=6),u&&(i=k(t,e),e+=6),g&&(r=t.getInt8(e),e+=1),f){const b=t.getUint8(e);e+=1,c=new Uint8Array(t.buffer,e,b),e+=b}return{discontinuity_indicator:d,random_access_indicator:a,elementary_stream_priority_indicator:h,pcr_flag:p,opcr_flag:u,splicing_point_flag:g,transport_private_data_flag:f,adaptation_field_extension_flag:m,pcr:n,opcr:i,splice_countdown:r,transport_private_data:c}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,i;{const r=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!r)throw new Error("invalid ts audio payload.");const c=s.getUint8(e);e+=1;const o=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let d,a,h,p,u;{const m=s.getUint8(e);e+=1,d=m>>4&3,a=(m>>3&1)===1,h=(m>>2&1)===1,p=(m>>1&1)===1,u=(m&1)===1}let g,f;{const m=s.getUint8(e);e+=1;const k=m>>6,b=s.getUint8(e);e+=1,(k&2)===2&&(g=this.parsePtsDts(s,e)),(k&1)===1?f=this.parsePtsDts(s,e+5):f=g,e+=b}n={stream_id:c,pes_packet_length:o,scrambling_control:d,priority:a,data_alignment:h,copyright:p,original_copy:u,pts:g,dts:f}}i=t.slice(e);{if(!this.audioConfig){const a=s.getUint8(e);if(e+=1,a===255){const h=s.getUint8(e),p=s.getUint8(e+1),u=(h&248)>>3&3,g=p>>6&3,f=48e3,m=`mp4a.40.${u}`,k=g===3?1:2;this.audioConfig={kind:"audio",codec:m,sampleRate:f,numberOfChannels:k},this.on.config&&this.on.config(this.audioConfig)}}const{dts:r=0,pts:c=0}=n,o=c-r,d=i.slice(7);return{kind:"audio",type:"key",dts:r,pts:c,cts:o,data:d}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,i;{const r=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!r)throw new Error("invalid ts video payload.");const c=s.getUint8(e);e+=1;const o=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let d,a,h,p,u;{const m=s.getUint8(e);e+=1,d=m>>4&3,a=(m>>3&1)===1,h=(m>>2&1)===1,p=(m>>1&1)===1,u=(m&1)===1}let g,f;{const m=s.getUint8(e);e+=1;const k=m>>6,b=s.getUint8(e);e+=1,(k&2)===2&&(g=this.parsePtsDts(s,e)),(k&1)===1?f=this.parsePtsDts(s,e+5):f=g,e+=b}n={stream_id:c,pes_packet_length:o,scrambling_control:d,priority:a,data_alignment:h,copyright:p,original_copy:u,pts:g,dts:f}}i=t.slice(e);{const r=this.getNalus(i);if(!this.videoConfig){let u,g;if(u=r.find(m=>m.type===7)?.nalu.slice(4),g=r.find(m=>m.type===8)?.nalu.slice(4),u&&g){const f=q(u,g),{codec:m}=L(f);this.videoConfig={kind:"video",codec:m,description:f,sps:u,pps:g},this.on.config&&this.on.config(this.videoConfig)}}const c=[];let o="delta";for(const u of r){const{type:g,nalu:f}=u;switch(g){case 6:case 9:c.push(f);break;case 1:o="delta",c.push(f);break;case 5:o="key",c.push(f);break}}const d=X(c),{dts:a=0,pts:h=0}=n,p=h-a;return{kind:"video",type:o,dts:a,pts:h,cts:p,data:d,nalus:c}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),i=t.getUint8(s+2),r=t.getUint8(s+3),c=t.getUint8(s+4),o=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(i)&0b11111110n)<<14n|(BigInt(r)&0b11111111n)<<7n|(BigInt(c)&0b11111110n)>>1n;return Number(o)/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 i=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 r=e-n;if(t[e-1]===0&&(r-=1),r!==0){const c=t.slice(n,n+r),o=K(c);s.push({type:i,nalu:o})}}return s}}const v=(l,t)=>l.getUint8(t)<<16|l.getUint8(t+1)<<8|l.getUint8(t+2);class et{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:i,dataSize:r,timestamp:c}=n;if(i){const o=this.parseTagBody(i,t,s+4+11,r);switch(i){case"script":this.on.info&&this.on.info(o);break;case"audio":{const{accPacketType:d}=o;if(d===0){const{codec:a,sampleRate:h,channelConfiguration:p}=o;this.audioConfig={kind:"audio",codec:a,sampleRate:h,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:a,data:h}=o,p="key",u=a===void 0?void 0:a+c;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:c,pts:u,cts:a,data:h})}}break;case"video":{const{avcPacketType:d}=o;if(d===0){const{codec:a,sps:h,pps:p,data:u}=o;this.videoConfig={kind:"video",codec:a,description:u,sps:h,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:a,cts:h,data:p,nalus:u}=o,g=a===1?"key":"delta",f=h===void 0?void 0:h+c;this.on.chunk&&this.on.chunk({kind:"video",type:g,dts:c,pts:f,cts:h,data:p,nalus:u})}}break}s=s+4+11+r}await new Promise(o=>setTimeout(()=>o(!0),8))}return s};parseHeader=(t,s)=>{let e,n,i,r;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const o=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,d,,a]=o;i={audio:a==="1",video:d==="1"}}r=t.getUint32(5),this.header={signature:e,version:n,flags:i,dataOffset:r}};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 i=v(t,s+4+1);s+4+11+i>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,i,r,c;{const o=t.getUint8(s);let d;switch(o){case 18:d="script";break;case 8:d="audio";break;case 9:d="video";break}e=d}return n=v(t,s+1),i=v(t,s+4),r=t.getUint8(s+7),c=v(t,s+8),{tagType:e,dataSize:n,timestamp:i,timestampExtended:r,streamID:c}};parseTagBody=(t,s,e,n)=>{let i;switch(t){case"script":i=this.parseMetaData(s,e);break;case"audio":i=this.parseAudio(s,e,n);break;case"video":i=this.parseVideo(s,e,n);break}return i};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 c=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(c)||"")!=="onMetaData")throw new Error("Expected 'onMetaData' string");e=e+n}const i=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,i).value};parseAudio=(t,s,e)=>{let n=s;const i=t.getUint8(n),r=i>>4&15,c=i>>2&3,o=i>>1&1,d=i&1;n=n+1;const a=t.getUint8(n);n=n+1;const h=e-2,p=new Uint8Array(t.buffer.slice(n,n+h));if(r===10&&a===0){const u=t.getUint8(n),g=t.getUint8(n+1),f=(u&248)>>3,m=(u&7)<<1|g>>7,k=(g&120)>>3,b=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],_=`mp4a.40.${f}`,w=b[m];return{soundFormat:r,soundRate:c,soundSize:o,soundType:d,accPacketType:a,data:p,audioObjectType:f,samplingFrequencyIndex:m,channelConfiguration:k,codec:_,sampleRate:w}}return{soundFormat:r,soundRate:c,soundSize:o,soundType:d,accPacketType:a,data:p}};parseVideo=(t,s,e)=>{let n=s;const i=t.getUint8(n),r=i>>4&15,c=i&15;n=n+1;const o=t.getUint8(n);n=n+1;const d=v(t,n);n=n+3;const a=e-5,h=new Uint8Array(t.buffer.slice(n,n+a));switch(c){case 7:if(o===0){const p=L(h);return{frameType:r,codecID:c,avcPacketType:o,cts:d,data:h,...p}}else if(o===1){const p=[],u=n+e-5;for(;!(n+4>u);){const g=t.getUint32(n,!1),f=new Uint8Array(t.buffer.slice(n,n+4+g));n+=4+g,p.push(f)}return{frameType:r,codecID:c,avcPacketType:o,cts:d,data:h,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:r,codecID:c,avcPacketType:o,cts:d,data:h}};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,i,r=0;switch(e){case 0:i=t.getFloat64(n,!1),r=8;break;case 1:i=!!t.getUint8(n),r=1;break;case 2:{i="";const o=t.getUint16(n,!1);n=n+2;const d=new Int8Array(t.buffer,n,o).filter(h=>h!==0);i=(this.textDecoder?.decode(d)||"").trim(),r=2+o}break;case 3:for(i={};n<t.byteLength;){const o=t.getUint16(n,!1);if(o===0)break;n=n+2;const d=this.getAMFName(t,n,o);n=n+o;const a=this.getAmfType(t,n);if(a===6)break;n=n+1;const h=this.getAMFValue(t,n,a);n=n+h.length,i[d]=h.value,r=2+o+1+h.length}break;case 8:{i={};const o=t.getUint32(n,!1);n=n+4;for(let d=0;d<o;d++){const a=t.getUint16(n,!1);n=n+2;const h=this.getAMFName(t,n,a);n=n+a;const p=this.getAmfType(t,n);n=n+1;const u=this.getAMFValue(t,n,p);n=n+u.length,i[h]=u.value,r=2+a+1+u.length}}break;case 10:{i=[];const o=t.getUint32(n,!1);n=n+4;for(let d=0;d<o;d++){const a=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,a);n=n+h.length,i.push(h.value),r=1+h.length}}break}return{amfType:e,length:r,value:i}}}class st{pattern;cacher=new J;isParseing=!1;offset=0;on={};parser;constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new et;break;case"hls":this.parser=new tt;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()}}}class nt{audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;on={audio:{},video:{}};constructor(){}audio={init:t=>{this.audio.destroy(),this.audioDecoderConfig={...t},this.audioDecoder=new AudioDecoder({output:s=>{this.on.audio.decode&&this.on.audio.decode(s)},error:s=>{this.on.audio.error&&this.on.audio.error(s)}}),this.audioDecoder.configure(this.audioDecoderConfig)},decode:t=>{if(!this.audioDecoder)return;const s=new EncodedAudioChunk(t);this.audioDecoder.decode(s)},flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={init:t=>{this.video.destroy(),this.videoDecoderConfig={...t},this.videoDecoder=new VideoDecoder({output:async s=>{const e=await createImageBitmap(s),n=s.timestamp;s.close(),e.width>0&&e.height>0?this.on.video.decode&&this.on.video.decode({timestamp:n,bitmap:e}):e.close()},error:s=>{console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: e",s),this.on.video.error&&this.on.video.error(s)}}),this.videoDecoder.configure(this.videoDecoderConfig)},decode:t=>{if(this.videoDecoder&&(t.type==="key"&&(this.hasKeyFrame=!0),this.hasKeyFrame&&this.videoDecoder.decodeQueueSize<2)){const s=new EncodedVideoChunk(t);this.videoDecoder.decode(s)}},flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}class it{isRendering=!1;pendingFrames=[];offscreenCanvas;writable;writer;ctx;cutOption;baseTime=0;pause=!1;shader=["stream"];constructor(){}init=({offscreenCanvas:t,writable:s})=>{this.destroy(),this.offscreenCanvas=t,this.writable=s,this.writer=this.writable.getWriter(),this.ctx=this.offscreenCanvas.getContext("2d")};setBaseTime=t=>{this.baseTime=t};setShader=t=>{this.shader=t};setSize=({width:t,height:s})=>{this.offscreenCanvas&&(this.offscreenCanvas.width=t,this.offscreenCanvas.height=s)};destroy=()=>{this.isRendering=!1,this.pendingFrames=[],this.offscreenCanvas=void 0,this.ctx=void 0,this.baseTime=0};push=t=>{this.pendingFrames.push(t),this.isRendering===!1&&setTimeout(this.renderFrame,0)};setCut=t=>{this.cutOption=t};setPause=t=>{this.pause=t,this.isRendering===!1&&setTimeout(this.renderFrame,0)};calculateTimeUntilNextFrame=t=>{const s=performance.timeOrigin+performance.now(),n=this.baseTime+t/1e3-s;return Math.max(0,n)};renderFrame=async()=>{for(this.isRendering=!0;;){const t=this.pendingFrames.shift();if(!t)break;let{timestamp:s,bitmap:e}=t;if(this.cutOption){const{sx:i=0,sy:r=0,sw:c=e.width,sh:o=e.height}=this.cutOption;e=await createImageBitmap(e,i,r,c,o)}const n=this.calculateTimeUntilNextFrame(s);await new Promise(i=>setTimeout(()=>i(!0),n)),this.drawImage({timestamp:s,bitmap:e}),this.cutOption&&e.close()}this.isRendering=!1};drawImage=t=>{if(this.pause!==!0){if(this.shader.includes("stream")){const s=new VideoFrame(t.bitmap,{timestamp:t.timestamp});this.writer.write(s),s.close()}this.shader.includes("canvas")&&this.ctx&&this.offscreenCanvas&&this.ctx.drawImage(t.bitmap,0,0,this.offscreenCanvas.width,this.offscreenCanvas.height)}}}U.Decoder=nt,U.DecoderWorker=M,U.Demuxer=st,U.DemuxerWorker=A,U.PrPlayer=Q,U.Render=it,U.RenderWorker=I,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pr-player",
3
3
  "description": "对 flv 格式的地址进行解析 并输出 canvas、stream,提供 SEI 回调,以及 cut 等相关能力,以支持根据业务层 SEI 对视频进行剪切渲染。",
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"