pr-player 0.3.1 → 0.3.2

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.
@@ -87,6 +87,15 @@ export declare class PrPlayer {
87
87
  sw: number;
88
88
  sh: number;
89
89
  }) => MediaStream;
90
+ /**
91
+ * 设置剪切
92
+ */
93
+ setCut: (key: string, cutOption: {
94
+ sx: number;
95
+ sy: number;
96
+ sw: number;
97
+ sh: number;
98
+ }) => void;
90
99
  /**
91
100
  * 获取媒体流
92
101
  */
package/dist/index.js CHANGED
@@ -509,6 +509,12 @@ class tt {
509
509
  const e = new MediaStreamTrackGenerator({ kind: "video" }), i = new MediaStream([e]);
510
510
  return this.renderWorker?.addCut({ key: t, writable: e.writable, option: s }), this.cutRenders.set(t, { stream: i }), i;
511
511
  },
512
+ /**
513
+ * 设置剪切
514
+ */
515
+ setCut: (t, s) => {
516
+ this.renderWorker?.setCut({ key: t, cutOption: s });
517
+ },
512
518
  /**
513
519
  * 获取媒体流
514
520
  */
@@ -1,4 +1,4 @@
1
1
  (function(U,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(U=typeof globalThis<"u"?globalThis:U||self,_(U["pr-player"]={}))})(this,(function(U){"use strict";const _='(function(){"use strict";class P{pendingPayloads=[];payload=new Uint8Array(0);chunks=[];push=t=>{this.pendingPayloads.push(t)};next=(t=0)=>{this.payload=this.payload.slice(t);const s=this.pendingPayloads.shift();if(!s)return!1;const e=new Uint8Array(this.payload.byteLength+s.byteLength);return e.set(this.payload,0),e.set(s,this.payload.byteLength),this.payload=e,new DataView(this.payload.buffer)};pushChunk=t=>{this.chunks.push(t),this.chunks.length>100&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const I=(y,t)=>{const s=new Uint8Array(y),e=new Uint8Array(t),n=new Uint8Array(11+s.length+e.length);let a=0;return n[a++]=1,n[a++]=s[1],n[a++]=s[2],n[a++]=s[3],n[a++]=255,n[a++]=225,n[a++]=s.length>>8&255,n[a++]=s.length&255,n.set(s,a),a+=s.length,n[a++]=1,n[a++]=e.length>>8&255,n[a++]=e.length&255,n.set(e,a),n},T=y=>{let t=0;const s=new DataView(y.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const n=s.getUint8(t)&255;t=t+1;const a=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const c=`avc1.${Array.from([n,a,o],U=>U.toString(16).padStart(2,"0")).join("")}`,r=(s.getUint8(t)&3)-1;t=t+1;const g=s.getUint8(t)&31;t=t+1;const p=s.getUint16(t,!1);t=t+2;const h=new Uint8Array(s.buffer.slice(t,t+p));t=t+p;const d=s.getUint8(t)&31;t=t+1;const u=s.getUint16(t,!1);t=t+2;const f=new Uint8Array(s.buffer.slice(t,t+u));return t=t+u,{version:e,codec:c,profile:n,compatibility:a,level:o,lengthSizeMinusOne:r,numOfSequenceParameterSets:g,sequenceParameterSetLength:p,sps:h,numOfPictureParameterSets:d,pictureParameterSetLength:u,pps:f}},M=y=>{const t=new Uint8Array(4+y.length);return new DataView(t.buffer).setUint32(0,y.length,!1),t.set(y,4),t},C=y=>{let t=0;for(const n of y)t+=n.length;const s=new Uint8Array(t);let e=0;for(const n of y){const a=n;s.set(a,e),e+=a.length}return s},D=y=>{let t="unknown";switch(y){case 1:case 2:case 27:case 36:t="video";break;case 3:case 4:case 15:t="audio";break;case 6:t="subtitle";break;case 134:t="ad";break}return t};class x{pat;pmt;audioConfig;videoConfig;payloadMap=new Map;on={};constructor(){}parse=async t=>{let s=0;for(;!(s+188>t.byteLength);){if(t.getInt8(s)!=71){s++;continue}await this.parsePacket(t,s),s+=188}return s};parsePacket=async(t,s)=>{if(s+188>t.byteLength)throw new Error("Invalid TS packet");if(t.getUint8(s)!==71)throw new Error("Invalid TS packet");let e=s;const n=this.parseHeader(t,e);e+=4;const{transport_error_indicator:a,pid:o,payload_unit_start_indicator:l,adaptation_field_control:i}=n;if(a===1||o===void 0)return;let c=184;if(i===2||i===3){const r=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=r,c-=r}if(i===3&&(c-=1),i===1||i===3){const r=new Uint8Array(t.buffer.slice(e,e+c));if(o===0)return this.parsePAT(t,e);{const{programs:h=[]}=this.pat||{};if(h.find(u=>u.pmt_pid===o))return this.parsePMT(t,e)}const{streams:g=[]}=this.pmt||{},p=g.find(h=>h.elementary_pid===o);if(p){if(l===1){const h=this.payloadMap.get(o);if(h){switch(p.kind){case"audio":{const d=await this.parseAudio(h);this.on.chunk&&this.on.chunk(d)}break;case"video":{const d=await this.parseVideo(h);this.on.chunk&&this.on.chunk(d),await new Promise(u=>setTimeout(()=>u(!0),0))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const h=this.payloadMap.get(o),d=new Uint8Array(h.byteLength+r.byteLength);d.set(h,0),d.set(r,h.byteLength),this.payloadMap.set(o,d)}}}};parseHeader=(t,s)=>{let e=s;const n=t.getUint8(e),a=t.getUint8(e+1),o=t.getUint8(e+2),l=t.getUint8(e+3),i=(a&128)>>7;if(i===1)return{sync_byte:n,transport_error_indicator:i};const c=(a&64)>>6,r=(a&32)>>5,g=(a&31)<<8|o,p=(l&192)>>6,h=l>>4&3,d=l&15;return{sync_byte:n,transport_error_indicator:i,payload_unit_start_indicator:c,transport_priority:r,pid:g,transport_scrambling_control:p,adaptation_field_control:h,continuity_counter:d}};parsePAT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==0)throw new Error("Invalid PAT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d}}const a=[];{const l=n.section_length-5-4,i=e+l;for(;e<i;){const c=t.getUint16(e),r=t.getUint16(e+2)&8191;e+=4,c!==0&&r>=32&&r<=8190&&a.push({program_number:c,pmt_pid:r})}}const o=t.getUint32(e);this.pat={header:n,programs:a,crc32:o},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,n;{const l=t.getUint8(e);e+=1;const i=t.getUint8(e);if(e+=1,i!==2)throw new Error("Invalid PMT table_id");const c=t.getUint16(e)&4095;e+=2;const r=t.getUint16(e);e+=2;const g=(t.getUint8(e)&62)>>1,p=t.getUint8(e)&1;e+=1;const h=t.getUint8(e);e+=1;const d=t.getUint8(e);e+=1;const u=t.getUint16(e)&8191;e+=2;const f=t.getUint16(e)&4095;e+=2,n={pointer_field:l,table_id:i,section_length:c,transport_stream_id:r,version_number:g,current_next_indicator:p,section_number:h,last_section_number:d,pcr_pid:u,program_info_length:f}}const a=[];{const l=n.section_length-9-4,i=e+l;for(;e<i;){const c=t.getUint8(e),r=D(c),g=t.getUint16(e+1)&8191,p=t.getUint16(e+3)&4095;if(e+=5,g<32||g>8190){console.warn(`Invalid elementary_pid: 0x${g.toString(16)}`);continue}a.push({kind:r,stream_type:c,elementary_pid:g,es_info_length:p})}}const o=t.getUint32(e);this.pmt={header:n,streams:a,crc32:o},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,n,a,o,l;const i=t.getUint8(e),c=!!(i&128),r=!!(i&64),g=!!(i&32),p=!!(i&16),h=!!(i&8),d=!!(i&4),u=!!(i&2),f=!!(i&1);e+=1;const U=(_,b)=>{let m=BigInt(0);m|=BigInt(_.getUint16(b))<<25n,m|=BigInt(_.getUint16(b+1))<<17n,m|=BigInt(_.getUint16(b+2))<<9n,m|=BigInt(_.getUint16(b+3))<<1n,m|=BigInt(_.getUint16(b+4)>>7);const S=(_.getUint16(b+4)&1)<<8|_.getUint16(b+5);return m=m*300n+BigInt(S),m};if(p&&(n=U(t,e),e+=6),h&&(a=U(t,e),e+=6),d&&(o=t.getInt8(e),e+=1),u){const _=t.getUint8(e);e+=1,l=new Uint8Array(t.buffer,e,_),e+=_}return{discontinuity_indicator:c,random_access_indicator:r,elementary_stream_priority_indicator:g,pcr_flag:p,opcr_flag:h,splicing_point_flag:d,transport_private_data_flag:u,adaptation_field_extension_flag:f,pcr:n,opcr:a,splice_countdown:o,transport_private_data:l}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts audio payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{if(!this.audioConfig&&s.getUint8(e)===255){const g=s.getUint8(e+2),p=s.getUint8(e+3);let h,d;d=g>>2&15,h=(g&1)<<2|p>>6;const u=`mp4a.40.${h}`,U=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][d];this.audioConfig={kind:"audio",codec:u,sampleRate:U,numberOfChannels:h},this.on.config&&this.on.config(this.audioConfig)}const{dts:o=0,pts:l=0}=n,i=l-o,c=a.slice(7);return{kind:"audio",type:"key",dts:o,pts:l,cts:i,data:c}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,n,a;{const o=s.getUint8(e)===0&&s.getUint8(e+1)===0&&s.getUint8(e+2)===1;if(e+=3,!o)throw new Error("invalid ts video payload.");const l=s.getUint8(e);e+=1;const i=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let c,r,g,p,h;{const f=s.getUint8(e);e+=1,c=f>>4&3,r=(f>>3&1)===1,g=(f>>2&1)===1,p=(f>>1&1)===1,h=(f&1)===1}let d,u;{const f=s.getUint8(e);e+=1;const U=f>>6,_=s.getUint8(e);e+=1,(U&2)===2&&(d=this.parsePtsDts(s,e)),(U&1)===1?u=this.parsePtsDts(s,e+5):u=d,e+=_}n={stream_id:l,pes_packet_length:i,scrambling_control:c,priority:r,data_alignment:g,copyright:p,original_copy:h,pts:d,dts:u}}a=t.slice(e);{const o=this.getNalus(a);if(!this.videoConfig){let h,d;if(h=o.find(f=>f.type===7)?.nalu.slice(4),d=o.find(f=>f.type===8)?.nalu.slice(4),h&&d){const u=I(h,d),{codec:f}=T(u);this.videoConfig={kind:"video",codec:f,description:u,sps:h,pps:d},this.on.config&&this.on.config(this.videoConfig)}}const l=[];let i="delta";for(const h of o){const{type:d,nalu:u}=h;switch(d){case 6:case 9:l.push(u);break;case 1:i="delta",l.push(u);break;case 5:i="key",l.push(u);break}}const c=C(l),{dts:r=0,pts:g=0}=n,p=g-r;return{kind:"video",type:i,dts:r,pts:g,cts:p,data:c,nalus:l}}};parsePtsDts(t,s){const e=t.getUint8(s),n=t.getUint8(s+1),a=t.getUint8(s+2),o=t.getUint8(s+3),l=t.getUint8(s+4),i=(BigInt(e)&0b00001110n)<<29n|(BigInt(n)&0b11111111n)<<22n|(BigInt(a)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(l)&0b11111110n)>>1n;return Number(i)/90}getNalus=t=>{const s=[];let e=0;for(;!(e+4>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}e+=3;let n=e;const a=t[e]&31;for(e+=1;!(e+1>t.byteLength);){if(t[e]!==0||t[e+1]!==0||t[e+2]!==1){e+=1;continue}break}let o=e-n;if(t[e-1]===0&&(o-=1),o!==0){const l=t.slice(n,n+o),i=M(l);s.push({type:a,nalu:i})}}return s}}const k=(y,t)=>y.getUint8(t)<<16|y.getUint8(t+1)<<8|y.getUint8(t+2);class L{audioConfig;videoConfig;header;textDecoder=new TextDecoder("utf-8");on={};constructor(){}parse=async t=>{let s=0;for(this.header||(this.parseHeader(t,s),s+=9);this.isSurplusTag(t,s)!==!1;){const n=this.parseTagHeader(t,s+4),{tagType:a,dataSize:o,timestamp:l}=n;if(a){const i=this.parseTagBody(a,t,s+4+11,o);switch(a){case"script":this.on.info&&this.on.info(i);break;case"audio":{const{accPacketType:c}=i;if(c===0){const{codec:r,sampleRate:g,channelConfiguration:p}=i;this.audioConfig={kind:"audio",codec:r,sampleRate:g,numberOfChannels:p},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:r,data:g}=i,p="key",h=r===void 0?void 0:r+l;this.on.chunk&&this.on.chunk({kind:"audio",type:p,dts:l,pts:h,cts:r,data:g})}}break;case"video":{const{avcPacketType:c}=i;if(c===0){const{codec:r,sps:g,pps:p,data:h}=i;this.videoConfig={kind:"video",codec:r,description:h,sps:g,pps:p},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:r,cts:g,data:p,nalus:h}=i,d=r===1?"key":"delta",u=g===void 0?void 0:g+l;this.on.chunk&&this.on.chunk({kind:"video",type:d,dts:l,pts:u,cts:g,data:p,nalus:h})}}break}s=s+4+11+o}await new Promise(i=>setTimeout(()=>i(!0),8))}return s};parseHeader=(t,s)=>{let e,n,a,o;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),n=t.getUint8(3);{const i=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,c,,r]=i;a={audio:r==="1",video:c==="1"}}o=t.getUint32(5),this.header={signature:e,version:n,flags:a,dataOffset:o}};isSurplusTag=(t,s)=>{let e=!0;const n=t.byteLength;if(s+4>n)e=!1;else if(s+4+11>n)e=!1;else{const a=k(t,s+4+1);s+4+11+a>n&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,n,a,o,l;{const i=t.getUint8(s);let c;switch(i){case 18:c="script";break;case 8:c="audio";break;case 9:c="video";break}e=c}return n=k(t,s+1),a=k(t,s+4),o=t.getUint8(s+7),l=k(t,s+8),{tagType:e,dataSize:n,timestamp:a,timestampExtended:o,streamID:l}};parseTagBody=(t,s,e,n)=>{let a;switch(t){case"script":a=this.parseMetaData(s,e);break;case"audio":a=this.parseAudio(s,e,n);break;case"video":a=this.parseVideo(s,e,n);break}return a};parseMetaData=(t,s)=>{let e=s;{if(t.getUint8(e)!==2)throw new Error("Invalid AMF type for onMetaData (expected 0x02)");e=e+1}const n=t.getUint16(e,!1);e=e+2;{const l=new Int8Array(t.buffer.slice(e,e+n));if((this.textDecoder?.decode(l)||"")!=="onMetaData")throw new Error("Expected \'onMetaData\' string");e=e+n}const a=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,a).value};parseAudio=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a>>2&3,i=a>>1&1,c=a&1;n=n+1;const r=t.getUint8(n);n=n+1;const g=e,p=new Uint8Array(t.buffer.slice(n,n+g));if(o===10&&r===0){const h=t.getUint8(n),d=t.getUint8(n+1),u=h>>3&31,f=(h&7)<<1|d>>7,U=d>>3&15,_=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],b=`mp4a.40.${u}`,m=_[f];return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p,samplingFrequencyIndex:f,channelConfiguration:U,codec:b,sampleRate:m}}return{soundFormat:o,soundRate:l,soundSize:i,soundType:c,accPacketType:r,data:p}};parseVideo=(t,s,e)=>{let n=s;const a=t.getUint8(n),o=a>>4&15,l=a&15;n=n+1;const i=t.getUint8(n);n=n+1;const c=k(t,n);n=n+3;const r=e-5,g=new Uint8Array(t.buffer.slice(n,n+r));switch(l){case 7:if(i===0){const p=T(g);return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,...p}}else if(i===1){const p=[],h=n+e-5;for(;!(n+4>h);){const d=t.getUint32(n,!1),u=new Uint8Array(t.buffer.slice(n,n+4+d));n+=4+d,p.push(u)}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g,nalus:p}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:l,avcPacketType:i,cts:c,data:g}};getAmfType=(t,s)=>t.getUint8(s);getAMFName=(t,s,e)=>{const n=new Uint8Array(t.buffer.slice(s,s+e));return this.textDecoder?.decode(n)||""};getAMFValue=(t,s,e)=>{let n=s,a,o=0;switch(e){case 0:a=t.getFloat64(n,!1),o=8;break;case 1:a=!!t.getUint8(n),o=1;break;case 2:{a="";const i=t.getUint16(n,!1);n=n+2;const c=new Int8Array(t.buffer,n,i).filter(g=>g!==0);a=(this.textDecoder?.decode(c)||"").trim(),o=2+i}break;case 3:for(a={};n<t.byteLength;){const i=t.getUint16(n,!1);if(i===0)break;n=n+2;const c=this.getAMFName(t,n,i);n=n+i;const r=this.getAmfType(t,n);if(r===6)break;n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a[c]=g.value,o=2+i+1+g.length}break;case 8:{a={};const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=t.getUint16(n,!1);n=n+2;const g=this.getAMFName(t,n,r);n=n+r;const p=this.getAmfType(t,n);n=n+1;const h=this.getAMFValue(t,n,p);n=n+h.length,a[g]=h.value,o=2+r+1+h.length}}break;case 10:{a=[];const i=t.getUint32(n,!1);n=n+4;for(let c=0;c<i;c++){const r=this.getAmfType(t,n);n=n+1;const g=this.getAMFValue(t,n,r);n=n+g.length,a.push(g.value),o=1+g.length}}break}return{amfType:e,length:o,value:a}}}class O{pattern;cacher=new P;isParseing=!1;offset=0;parser;on={};constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new L;break;case"hls":this.parser=new x;break;default:throw new Error("is error pattern.")}this.parser.on.debug=s=>this.on.debug&&this.on.debug(s),this.parser.on.info=s=>this.on.info&&this.on.info(s),this.parser.on.config=s=>this.on.config&&this.on.config(s),this.parser.on.chunk=s=>{this.cacher.pushChunk(s),this.on.chunk&&this.on.chunk(s)}};push=t=>{this.cacher.push(t),this.isParseing===!1&&this.parse()};destroy=()=>{this.cacher.destroy(),this.isParseing=!1,this.offset=0};parse=async()=>{try{if(this.isParseing=!0,!this.pattern)throw new Error("You need to set the pattern.");if(!this.parser)throw new Error("You need to init parser.");for(;;){const t=this.cacher.next(this.offset);if(this.offset=0,!t)break;this.offset=await this.parser.parse(t)}this.isParseing=!1}catch{this.destroy()}}}const A=new O;A.on.info=y=>postMessage({action:"on.info",data:y}),A.on.config=y=>postMessage({action:"on.config",data:y}),A.on.chunk=y=>postMessage({action:"on.chunk",data:y}),A.on.debug=y=>postMessage({action:"on.debug",data:y}),onmessage=y=>{const{action:t,data:s}=y.data,e=A[t];e&&e(s)}})();\n',v=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",_],{type:"text/javascript;charset=utf-8"});function L(p){let t;try{if(t=v&&(self.URL||self.webkitURL).createObjectURL(v),!t)throw"";const s=new Worker(t,{name:p?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(_),{name:p?.name})}}class A{worker=new L;on={};constructor(){this.worker.onmessage=t=>{const{action:s,data:e}=t.data;switch(s){case"on.info":this.on.info&&this.on.info(e);break;case"on.config":this.on.config&&this.on.config(e);break;case"on.chunk":this.on.chunk&&this.on.chunk(e);break;case"on.debug":this.on.debug&&this.on.debug(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 x=`(function(){"use strict";class r{pattern="flv";audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;baseTime=0;pendingChunks=[];currentChunk;isProcessing=!1;decodeTimer=0;frameTrack=!1;isFrameTrack=!1;fameTrackOption={flv:[30,50],hls:[200,300],dash:[50,100],rtmp:[50,100]};decodingSpeedRatio=1;maxDecodingSpeedRatio=2;decodingSpeed=16;fps=0;firstVideoChunkTimestamp;secondVideoChunkTimestamp;frameStartTime;lastRenderTime;nextRenderTime;on={audio:{},video:{}};constructor(){}init=e=>{this.destroy(),this.pattern=e,this.baseTime=new Date().getTime()-performance.now(),this.initDecodeInterval()};initAudio=e=>{this.audio.destroy(),this.audioDecoderConfig={...e},this.audioDecoder=new AudioDecoder({output:i=>{const t=this.decodingSpeedRatio;this.on.audio.decode&&this.on.audio.decode({audioData:i,playbackRate:t})},error:i=>{this.on.audio.error&&this.on.audio.error(i)}}),this.audioDecoder.configure(this.audioDecoderConfig)};initVideo=e=>{this.video.destroy(),this.videoDecoderConfig={...e},this.videoDecoder=new VideoDecoder({output:async i=>{this.frameStartTime||(this.frameStartTime=i.timestamp);const t=i.timestamp-this.frameStartTime+this.baseTime*1e3,s=await createImageBitmap(i);i.close(),s.width>0&&s.height>0?(this.on.video.decode&&this.on.video.decode({timestamp:t,bitmap:s}),this.currentChunk&&this.currentChunk.kind==="video"&&this.currentChunk.nalus&&this.on.nalus&&this.on.nalus(this.currentChunk.nalus)):s.close()},error:i=>{this.on.video.error&&this.on.video.error(i)}}),this.videoDecoder.configure(this.videoDecoderConfig)};setFrameTrack=e=>{this.frameTrack=e,this.frameTrack===!1&&(this.decodingSpeedRatio=1)};push=e=>{this.pendingChunks.push(e)};destroy=()=>{this.audio.destroy(),this.video.destroy(),this.pendingChunks=[],this.firstVideoChunkTimestamp=void 0,this.secondVideoChunkTimestamp=void 0,this.frameStartTime=void 0,this.lastRenderTime=void 0,this.nextRenderTime=void 0,clearInterval(this.decodeTimer)};initDecodeInterval=()=>{let e=this.decodingSpeed/this.decodingSpeedRatio;const i=this.baseTime+performance.now();if(this.lastRenderTime||(this.lastRenderTime=i),this.fps=Math.round(1e3/(i-this.lastRenderTime)),this.lastRenderTime=i,this.nextRenderTime){const t=this.lastRenderTime-this.nextRenderTime;e-=t}this.nextRenderTime=this.lastRenderTime+e,this.decodeTimer=setTimeout(()=>{this.decode(),this.initDecodeInterval()},e)};decode=()=>{if(this.isProcessing!==!0){for(this.isProcessing=!0;this.currentChunk=this.pendingChunks.shift(),!!this.currentChunk;){const e=this.pendingChunks.length;if(this.frameTrack){const[s,n]=this.fameTrackOption[this.pattern];if(e<=s&&(this.isFrameTrack=!1),e>=n&&(this.isFrameTrack=!0),this.isFrameTrack){const a=Math.min(1+(e-s)/100,this.maxDecodingSpeedRatio);this.decodingSpeedRatio=Number(a.toFixed(1))}else this.decodingSpeedRatio=1}if(this.on.analysis){const{decodingSpeed:s,decodingSpeedRatio:n,fps:a}=this;this.on.analysis({decodingSpeed:s,decodingSpeedRatio:n,fps:a,cacheLength:e})}const{kind:i,init:t}=this.currentChunk;switch(i){case"audio":this.decodeAudio(t);break;case"video":this.decodeVideo(t);break}if(i==="video")break}this.isProcessing=!1}};decodeAudio=e=>{if(!this.audioDecoder)return;const i=new EncodedAudioChunk(e);this.audioDecoder.decode(i)};decodeVideo=e=>{if(this.videoDecoder&&(e.type==="key"&&(this.hasKeyFrame=!0),this.firstVideoChunkTimestamp?this.secondVideoChunkTimestamp||(this.secondVideoChunkTimestamp=e.timestamp,this.decodingSpeed=(this.secondVideoChunkTimestamp-this.firstVideoChunkTimestamp)/1e3):this.firstVideoChunkTimestamp=e.timestamp,this.hasKeyFrame)){const i=new EncodedVideoChunk(e);this.videoDecoder.decode(i)}};audio={flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}const d=new r;d.on.audio.decode=o=>postMessage({action:"on.audio.decode",data:o},[o.audioData]),d.on.audio.error=o=>postMessage({action:"on.audio.error",data:o}),d.on.video.decode=o=>postMessage({action:"on.video.decode",data:o},[o.bitmap]),d.on.video.error=o=>postMessage({action:"on.video.error",data:o}),d.on.nalus=o=>postMessage({action:"on.nalus",data:o}),d.on.analysis=o=>postMessage({action:"on.analysis",data:o}),onmessage=o=>{const{action:e,data:i}=o.data,t=d[e];t&&t(i)}})();
2
2
  `,M=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",x],{type:"text/javascript;charset=utf-8"});function N(p){let t;try{if(t=M&&(self.URL||self.webkitURL).createObjectURL(M),!t)throw"";const s=new Worker(t,{name:p?.name});return s.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),s}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(x),{name:p?.name})}}class D{worker=new N;on={audio:{},video:{}};constructor(){this.worker.onmessage=t=>{const{action:s,data:e}=t.data;switch(s){case"on.audio.decode":this.on.audio.decode&&this.on.audio.decode(e);break;case"on.audio.error":this.on.audio.error&&this.on.audio.error(e);break;case"on.video.decode":this.on.video.decode&&this.on.video.decode(e);break;case"on.video.error":this.on.video.error&&this.on.video.error(e);break;case"on.nalus":this.on.nalus&&this.on.nalus(e);break;case"on.analysis":this.on.analysis&&this.on.analysis(e);break}}}init=t=>this.worker.postMessage({action:"init",data:t});initAudio=t=>this.worker.postMessage({action:"initAudio",data:t});initVideo=t=>this.worker.postMessage({action:"initVideo",data:t});push=t=>this.worker.postMessage({action:"push",data:t});setFrameTrack=t=>this.worker.postMessage({action:"setFrameTrack",data:t});destroy=()=>{this.worker.postMessage({action:"destroy"}),this.worker.terminate()}}const S=`(function(){"use strict";class h{renderMap=new Map;constructor(){}push=async t=>{const{timestamp:s}=t,{bitmap:e}=t;if(e.height===0||e.width===0)return e.close();const n=[...this.renderMap.keys()];for(const i of n){const a=this.renderMap.get(i);if(!a)continue;const{pause:f=!1,writer:c,option:d}=a;if(f!==!0)if(i==="default"||!d){const o=new VideoFrame(e,{timestamp:s});c.write(o),o.close()}else{const{sx:o=0,sy:w=0,sw:y=e.width,sh:M=e.height}=d,u=await createImageBitmap(e,o,w,y,M),p=new VideoFrame(u,{timestamp:s});u.close(),c.write(p),p.close()}}e.close()};addCut=t=>{const{key:s,writable:e,option:n}={key:"default",...t},i=e.getWriter();this.renderMap.set(s,{writable:e,writer:i,option:n,pause:!1})};delCut=t=>{this.renderMap.delete(t)};setCut=t=>{const{key:s,cutOption:e}={key:"default",...t},n=this.renderMap.get(s);n&&this.renderMap.set(s,{...n,option:e})};setPause=t=>{const{key:s,pause:e}={key:"default",...t},n=this.renderMap.get(s);n&&this.renderMap.set(s,{...n,pause:e})};destroy=()=>{this.renderMap=new Map}}const l=new h;onmessage=r=>{const{action:t,data:s}=r.data,e=l[t];e&&e(s)}})();
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 F(p){let t;try{if(t=P&&(self.URL||self.webkitURL).createObjectURL(P),!t)throw"";const s=new Worker(t,{name:p?.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:p?.name})}}class R{worker=new F;constructor(){}push=t=>this.worker.postMessage({action:"push",data:t},[t.bitmap]);addCut=t=>this.worker.postMessage({action:"addCut",data:t},[t.writable]);delCut=t=>this.worker.postMessage({action:"delCut",data:t});setCut=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()}}var B=Object.defineProperty,G=(p,t,s)=>t in p?B(p,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):p[t]=s,m=(p,t,s)=>G(p,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,"highPassNode"),m(this,"lowPassNode"),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 i of e)i.stop(),this.inputStream.removeTrack(i)}}),m(this,"pause",async e=>{const i=this.inputStream.getTracks();for(const n of i)n.enabled=!e}),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:i}=this;e.getByteFrequencyData(i);let n=0;for(let o=0;o<i.length;o++)n+=i[o];return Math.ceil(n/i.length)}),m(this,"mixAudio",(e,i="bgm")=>new Promise(async(n,o)=>{try{{const d=this.mixAudioMap.get(i);d&&d.stop()}const a=i==="bgs"?this.bgsGainNode:this.bgmGainNode,r=this.audioContext.createBufferSource();this.mixAudioMap.set(i,r),r.buffer=e,r.connect(a),r.onended=()=>{r.disconnect(a),this.mixAudioMap.delete(i),n(!0)},r.start(0)}catch(a){o(a)}})),m(this,"mixAudioStop",e=>{const i=this.mixAudioMap.get(e);i?.stop()}),m(this,"changeMix",(e,i)=>{const n=e==="bgs"?this.bgsGainNode:this.bgmGainNode;i?n.connect(this.destinationNode):n.disconnect(this.destinationNode)}),s&&(this.audioContext=s),this.inputStream=t,this.sourceNode=this.audioContext.createMediaStreamSource(this.inputStream),this.highPassNode=this.audioContext.createBiquadFilter(),this.highPassNode.type="highpass",this.highPassNode.frequency.value=100,this.lowPassNode=this.audioContext.createBiquadFilter(),this.lowPassNode.type="lowpass",this.lowPassNode.frequency.value=8e3,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,highPassNode:i,lowPassNode:n,inputGainNode:o,enhanceGainNode:a,bgsGainNode:r,bgmGainNode:d,analyserNode:c,outputGainNode:h,destinationNode:l}=this;e.connect(i),i.connect(n),n.connect(o),o.connect(a),a.connect(c),r.connect(c),d.connect(c),a.connect(l),r.connect(l),d.connect(l),c.connect(h),h.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}const E=async(p,t)=>{try{const{format:s,numberOfChannels:e,numberOfFrames:i,sampleRate:n}=t,o=p.createBuffer(e,i,n);for(let a=0;a<e;a++){const r=t.allocationSize({planeIndex:a}),d=new Uint8Array(r);t.copyTo(d,{planeIndex:a});const c=new DataView(d.buffer),h=o.getChannelData(a);for(let l=0;l<i;l++){let u;switch(s){case"s16":case"s16-planar":u=c.getInt16(l*2,!0)/32768;break;case"f32":case"f32-planar":u=c.getFloat32(l*4,!0);break;case"u8":case"u8-planar":u=(c.getUint8(l)-128)/128;break;default:throw new Error(`Unsupported audio format: ${s}`)}h[l]=Math.max(-1,Math.min(1,u))}}return o}catch(s){throw console.error("Failed to convert AudioData to AudioBuffer:",s),s}};class O{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){const{audioData:s,playbackRate:e=1}=t;if(!this.audioContext||!this.destination)return;let i=await E(this.audioContext,s);if(s.close(),!i)return;const n=this.audioContext.createBufferSource();n.buffer=i,n.playbackRate.value=e;const o=-1200*Math.log2(e);n.detune.value=o,n.connect(this.destination);const a=Math.max(this.nextStartTime,this.audioContext.currentTime),r=i.duration/e;this.nextStartTime=a+r,n.start(a),this.pendingSources.push(n),n.onended=()=>{this.pendingSources=this.pendingSources.filter(d=>d!==n)},this.audioContext.state==="suspended"&&await this.audioContext.resume()}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 j=p=>{const t=p.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"},z=p=>{const t=p?.getTracks()||[];for(const s of t)s.stop()};class q{resolvesMap=new Map;index=0;constructor(){}add=(t,s=()=>!1,e=0)=>new Promise(i=>{if(s())return i(!0);this.resolvesMap.has(t)||this.resolvesMap.set(t,new Map),this.index++;const a=`${this.index}`;if(e=Math.max(0,e),e===0){this.resolvesMap.get(t)?.set(a,{resolve:i,timer:0});return}const r=window.setTimeout(()=>{this.emit(t)},e);this.resolvesMap.get(t)?.set(a,{resolve:i,timer:r})});emit=async t=>{const s=this.resolvesMap.get(t);if(!s)return;const e=[...s.keys()];for(const i of e){const n=s.get(i);n&&(clearTimeout(n.timer),n.resolve(),s.delete(i))}}}const $=(p,t)=>{const s=new Uint8Array(p),e=new Uint8Array(t),i=new Uint8Array(11+s.length+e.length);let n=0;return i[n++]=1,i[n++]=s[1],i[n++]=s[2],i[n++]=s[3],i[n++]=255,i[n++]=225,i[n++]=s.length>>8&255,i[n++]=s.length&255,i.set(s,n),n+=s.length,i[n++]=1,i[n++]=e.length>>8&255,i[n++]=e.length&255,i.set(e,n),i},I=p=>{let t=0;const s=new DataView(p.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const i=s.getUint8(t)&255;t=t+1;const n=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const d=`avc1.${Array.from([i,n,o],b=>b.toString(16).padStart(2,"0")).join("")}`,c=(s.getUint8(t)&3)-1;t=t+1;const h=s.getUint8(t)&31;t=t+1;const l=s.getUint16(t,!1);t=t+2;const u=new Uint8Array(s.buffer.slice(t,t+l));t=t+l;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:i,compatibility:n,level:o,lengthSizeMinusOne:c,numOfSequenceParameterSets:h,sequenceParameterSetLength:l,sps:u,numOfPictureParameterSets:g,pictureParameterSetLength:f,pps:y}},H=p=>{const t=new Uint8Array(4+p.length);return new DataView(t.buffer).setUint32(0,p.length,!1),t.set(p,4),t},K=p=>{let t=0;for(const i of p)t+=i.length;const s=new Uint8Array(t);let e=0;for(const i of p){const n=i;s.set(n,e),e+=n.length}return s},X=p=>{const t=new DataView(p.buffer);let s=0,e,i,n;e=t.getUint32(s,!1),s+=4;{const o=t.getUint8(s),a=o>>7&1,r=o>>5&3,d=o&31;i={forbidden_zero_bit:a,nal_ref_idc:r,nal_unit_type:d},s+=1}{const o=e-1;n=new Uint8Array(t.buffer.slice(s,s+o))}return{size:e,header:i,data:n}};class V{#e={timeout:5*1e3,check:!1};#t=null;constructor(t={}){this.#e={...this.#e,...t}}#s=(t,s)=>new Promise(async e=>{this.#t=new AbortController;const{signal:i}=this.#t,n=this.#e.timeout,o=setTimeout(()=>{this.#t?.abort(`Timeout (${n}ms)`)},n);await fetch(t,{cache:"no-store",...s,method:"HEAD",signal:i}).then(a=>{clearTimeout(o),e({status:a.status===200?"successed":"failed",reason:a.status===200?"":`HTTP ${a.status}`})}).catch(a=>{if(clearTimeout(o),a.name==="AbortError"){const r=i.reason||"Actively stopped";e({status:r.includes("Timeout")?"timeout":"stopped",reason:r})}else e({status:"error",reason:a.message})})});request=(t,s)=>new Promise(async(e,i)=>{try{this.stop(),this.#e.check&&await this.#s(t),this.#t=new AbortController;const{signal:n}=this.#t,o=await fetch(t,{cache:"no-store",...s,signal:n});e(o)}catch(n){i(n)}});stop=()=>{if(this.#t?.signal.aborted===!1){const t=new Error("Actively stopped.");t.name="AbortError",this.#t.abort(t)}}}class Y{option={debug:!1,frameTrack:!1};prFetch=new V;getSegmentsFetch=new V;prResolves=new q;url="";start_resolve;demuxerWorker;decoderWorker;audioPlayer;renderWorker;stream;on={demuxer:{},decoder:{}};cutRenders=new Map;trackGenerator;constructor(t={}){const{debug:s=!1}=t;this.option.debug=s}start=async t=>{await this.stop(),this.url=t;const s=j(t);if(s==="unknown")throw new Error("This address cannot be parsed.");switch(this.init(s),s){case"flv":this.flv.start();break;case"hls":this.hls.start();break}};stop=async()=>{try{this.url="",clearInterval(this.hls.getSegmentsTimer),this.prFetch.stop(),this.getSegmentsFetch.stop()}catch(t){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: error",t)}this.demuxerWorker?.destroy(),this.decoderWorker?.destroy(),this.renderWorker?.destroy(),this.cutRenders=new Map,z(this.stream),this.audioPlayer?.destroy()};getStream=()=>this.stream;setPause=t=>{this.renderWorker?.setPause({pause:t})};setMute=t=>this.audioPlayer?.prAudioStream?.setMute(t);setOutputGain=t=>{this.audioPlayer?.prAudioStream?.setOutputGain(t)};setFrameTrack=t=>{this.option.frameTrack=t,this.decoderWorker?.setFrameTrack(t)};isReady=()=>{const t=()=>this.stream?.active===!0;return this.prResolves.add("isReady",t)};cut={create:(t,s)=>{const e=new MediaStreamTrackGenerator({kind:"video"}),i=new MediaStream([e]);return this.renderWorker?.addCut({key:t,writable:e.writable,option:s}),this.cutRenders.set(t,{stream:i}),i},getStream:t=>this.cutRenders.get(t)?.stream,remove:t=>{this.renderWorker?.delCut(t),this.cutRenders.delete(t)},setPause:(t,s)=>{this.renderWorker?.setPause({key:t,pause:s})}};init=t=>{this.initDecoder(t),this.initRender(),this.initDemuxer(t),this.audioPlayer=new O,this.audioPlayer.init()};initDemuxer=t=>{this.demuxerWorker=new A,this.demuxerWorker.init(t),this.demuxerWorker.on.debug=s=>{this.option.debug&&this.on.debug&&this.on.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:i,sampleRate:n,numberOfChannels:o}=s;this.decoderWorker?.initAudio({codec:i,sampleRate:n,numberOfChannels:o})}break;case"video":{const{codec:i,description:n}=s;this.decoderWorker?.initVideo({codec:i,description:n})}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:i,dts:n,data:o}=s,a=n*1e3;this.decoderWorker.push({kind:e,init:{type:i,timestamp:a,data:o}})}break;case"video":{const{type:i,dts:n,data:o,nalus:a=[]}=s,r=n*1e3;this.decoderWorker.push({kind:e,init:{type:i,timestamp:r,data:o},nalus:a})}break}}};initDecoder=t=>{this.decoderWorker=new D,this.decoderWorker.init(t);const{frameTrack:s=!1}=this.option;this.decoderWorker.setFrameTrack(s),this.decoderWorker.on.audio.decode=e=>{this.audioPlayer?.push(e),this.on.decoder.audio&&this.on.decoder.audio(e)},this.decoderWorker.on.audio.error=e=>{this.option.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: audio.error ",e),this.on.error&&this.on.error(e)},this.decoderWorker.on.video.decode=async e=>{this.start_resolve&&(this.start_resolve(!0),this.start_resolve=void 0),this.renderWorker?.push(e),this.on.decoder.video&&this.on.decoder.video(e)},this.decoderWorker.on.video.error=e=>{this.on.error&&this.on.error(e)},this.decoderWorker.on.nalus=async e=>{for(const i of e){if(i.byteLength<=4)continue;const{header:n,data:o}=X(i),{nal_unit_type:a}=n;a===6&&this.on.decoder.sei&&this.on.decoder.sei(o)}},this.decoderWorker.on.analysis=e=>{this.on.decoder.analysis&&this.on.decoder.analysis(e)}};initRender=()=>{this.renderWorker=new R;const t=new MediaStreamTrackGenerator({kind:"video"}),s=new MediaStream([t]);this.renderWorker?.addCut({writable:t.writable}),this.stream=s,this.renderWorker?.setPause({pause:!1})};flv={start:()=>new Promise(async(t,s)=>{try{this.start_resolve=t;let e,i=0;for(;;){i+=1;try{e=await this.prFetch.request(this.url)}catch(o){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: error",o)}if(e?.status===200||i===3)break;await new Promise(o=>setTimeout(()=>o(!0),500))}if(!e||e.status!==200)return s("request is error.");const n=e.body?.getReader();if(!n)return s("reader is error.");for(;;){const{done:o,value:a}=await n.read();if(a&&this.demuxerWorker?.push(a),o||this.url==="")break}}catch(e){e.name!=="AbortError"&&s(e)}})};hls={isLive:!1,urls:[],url:"",getSegmentsTimer:0,parse:async t=>{const i=new TextDecoder("utf-8").decode(t).split(`
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 F(p){let t;try{if(t=P&&(self.URL||self.webkitURL).createObjectURL(P),!t)throw"";const s=new Worker(t,{name:p?.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:p?.name})}}class R{worker=new F;constructor(){}push=t=>this.worker.postMessage({action:"push",data:t},[t.bitmap]);addCut=t=>this.worker.postMessage({action:"addCut",data:t},[t.writable]);delCut=t=>this.worker.postMessage({action:"delCut",data:t});setCut=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()}}var B=Object.defineProperty,G=(p,t,s)=>t in p?B(p,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):p[t]=s,m=(p,t,s)=>G(p,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,"highPassNode"),m(this,"lowPassNode"),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 i of e)i.stop(),this.inputStream.removeTrack(i)}}),m(this,"pause",async e=>{const i=this.inputStream.getTracks();for(const n of i)n.enabled=!e}),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:i}=this;e.getByteFrequencyData(i);let n=0;for(let o=0;o<i.length;o++)n+=i[o];return Math.ceil(n/i.length)}),m(this,"mixAudio",(e,i="bgm")=>new Promise(async(n,o)=>{try{{const d=this.mixAudioMap.get(i);d&&d.stop()}const a=i==="bgs"?this.bgsGainNode:this.bgmGainNode,r=this.audioContext.createBufferSource();this.mixAudioMap.set(i,r),r.buffer=e,r.connect(a),r.onended=()=>{r.disconnect(a),this.mixAudioMap.delete(i),n(!0)},r.start(0)}catch(a){o(a)}})),m(this,"mixAudioStop",e=>{const i=this.mixAudioMap.get(e);i?.stop()}),m(this,"changeMix",(e,i)=>{const n=e==="bgs"?this.bgsGainNode:this.bgmGainNode;i?n.connect(this.destinationNode):n.disconnect(this.destinationNode)}),s&&(this.audioContext=s),this.inputStream=t,this.sourceNode=this.audioContext.createMediaStreamSource(this.inputStream),this.highPassNode=this.audioContext.createBiquadFilter(),this.highPassNode.type="highpass",this.highPassNode.frequency.value=100,this.lowPassNode=this.audioContext.createBiquadFilter(),this.lowPassNode.type="lowpass",this.lowPassNode.frequency.value=8e3,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,highPassNode:i,lowPassNode:n,inputGainNode:o,enhanceGainNode:a,bgsGainNode:r,bgmGainNode:d,analyserNode:c,outputGainNode:h,destinationNode:l}=this;e.connect(i),i.connect(n),n.connect(o),o.connect(a),a.connect(c),r.connect(c),d.connect(c),a.connect(l),r.connect(l),d.connect(l),c.connect(h),h.connect(this.audioContext.destination)}this.setMute(!0),this.audioContext.resume()}}const E=async(p,t)=>{try{const{format:s,numberOfChannels:e,numberOfFrames:i,sampleRate:n}=t,o=p.createBuffer(e,i,n);for(let a=0;a<e;a++){const r=t.allocationSize({planeIndex:a}),d=new Uint8Array(r);t.copyTo(d,{planeIndex:a});const c=new DataView(d.buffer),h=o.getChannelData(a);for(let l=0;l<i;l++){let u;switch(s){case"s16":case"s16-planar":u=c.getInt16(l*2,!0)/32768;break;case"f32":case"f32-planar":u=c.getFloat32(l*4,!0);break;case"u8":case"u8-planar":u=(c.getUint8(l)-128)/128;break;default:throw new Error(`Unsupported audio format: ${s}`)}h[l]=Math.max(-1,Math.min(1,u))}}return o}catch(s){throw console.error("Failed to convert AudioData to AudioBuffer:",s),s}};class O{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){const{audioData:s,playbackRate:e=1}=t;if(!this.audioContext||!this.destination)return;let i=await E(this.audioContext,s);if(s.close(),!i)return;const n=this.audioContext.createBufferSource();n.buffer=i,n.playbackRate.value=e;const o=-1200*Math.log2(e);n.detune.value=o,n.connect(this.destination);const a=Math.max(this.nextStartTime,this.audioContext.currentTime),r=i.duration/e;this.nextStartTime=a+r,n.start(a),this.pendingSources.push(n),n.onended=()=>{this.pendingSources=this.pendingSources.filter(d=>d!==n)},this.audioContext.state==="suspended"&&await this.audioContext.resume()}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 j=p=>{const t=p.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"},z=p=>{const t=p?.getTracks()||[];for(const s of t)s.stop()};class q{resolvesMap=new Map;index=0;constructor(){}add=(t,s=()=>!1,e=0)=>new Promise(i=>{if(s())return i(!0);this.resolvesMap.has(t)||this.resolvesMap.set(t,new Map),this.index++;const a=`${this.index}`;if(e=Math.max(0,e),e===0){this.resolvesMap.get(t)?.set(a,{resolve:i,timer:0});return}const r=window.setTimeout(()=>{this.emit(t)},e);this.resolvesMap.get(t)?.set(a,{resolve:i,timer:r})});emit=async t=>{const s=this.resolvesMap.get(t);if(!s)return;const e=[...s.keys()];for(const i of e){const n=s.get(i);n&&(clearTimeout(n.timer),n.resolve(),s.delete(i))}}}const $=(p,t)=>{const s=new Uint8Array(p),e=new Uint8Array(t),i=new Uint8Array(11+s.length+e.length);let n=0;return i[n++]=1,i[n++]=s[1],i[n++]=s[2],i[n++]=s[3],i[n++]=255,i[n++]=225,i[n++]=s.length>>8&255,i[n++]=s.length&255,i.set(s,n),n+=s.length,i[n++]=1,i[n++]=e.length>>8&255,i[n++]=e.length&255,i.set(e,n),i},I=p=>{let t=0;const s=new DataView(p.buffer),e=s.getUint8(t);if(t=t+1,e!==1)throw new Error("Invalid AVC version");const i=s.getUint8(t)&255;t=t+1;const n=s.getUint8(t)&255;t=t+1;const o=s.getUint8(t)&255;t=t+1;const d=`avc1.${Array.from([i,n,o],b=>b.toString(16).padStart(2,"0")).join("")}`,c=(s.getUint8(t)&3)-1;t=t+1;const h=s.getUint8(t)&31;t=t+1;const l=s.getUint16(t,!1);t=t+2;const u=new Uint8Array(s.buffer.slice(t,t+l));t=t+l;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:i,compatibility:n,level:o,lengthSizeMinusOne:c,numOfSequenceParameterSets:h,sequenceParameterSetLength:l,sps:u,numOfPictureParameterSets:g,pictureParameterSetLength:f,pps:y}},H=p=>{const t=new Uint8Array(4+p.length);return new DataView(t.buffer).setUint32(0,p.length,!1),t.set(p,4),t},K=p=>{let t=0;for(const i of p)t+=i.length;const s=new Uint8Array(t);let e=0;for(const i of p){const n=i;s.set(n,e),e+=n.length}return s},X=p=>{const t=new DataView(p.buffer);let s=0,e,i,n;e=t.getUint32(s,!1),s+=4;{const o=t.getUint8(s),a=o>>7&1,r=o>>5&3,d=o&31;i={forbidden_zero_bit:a,nal_ref_idc:r,nal_unit_type:d},s+=1}{const o=e-1;n=new Uint8Array(t.buffer.slice(s,s+o))}return{size:e,header:i,data:n}};class V{#e={timeout:5*1e3,check:!1};#t=null;constructor(t={}){this.#e={...this.#e,...t}}#s=(t,s)=>new Promise(async e=>{this.#t=new AbortController;const{signal:i}=this.#t,n=this.#e.timeout,o=setTimeout(()=>{this.#t?.abort(`Timeout (${n}ms)`)},n);await fetch(t,{cache:"no-store",...s,method:"HEAD",signal:i}).then(a=>{clearTimeout(o),e({status:a.status===200?"successed":"failed",reason:a.status===200?"":`HTTP ${a.status}`})}).catch(a=>{if(clearTimeout(o),a.name==="AbortError"){const r=i.reason||"Actively stopped";e({status:r.includes("Timeout")?"timeout":"stopped",reason:r})}else e({status:"error",reason:a.message})})});request=(t,s)=>new Promise(async(e,i)=>{try{this.stop(),this.#e.check&&await this.#s(t),this.#t=new AbortController;const{signal:n}=this.#t,o=await fetch(t,{cache:"no-store",...s,signal:n});e(o)}catch(n){i(n)}});stop=()=>{if(this.#t?.signal.aborted===!1){const t=new Error("Actively stopped.");t.name="AbortError",this.#t.abort(t)}}}class Y{option={debug:!1,frameTrack:!1};prFetch=new V;getSegmentsFetch=new V;prResolves=new q;url="";start_resolve;demuxerWorker;decoderWorker;audioPlayer;renderWorker;stream;on={demuxer:{},decoder:{}};cutRenders=new Map;trackGenerator;constructor(t={}){const{debug:s=!1}=t;this.option.debug=s}start=async t=>{await this.stop(),this.url=t;const s=j(t);if(s==="unknown")throw new Error("This address cannot be parsed.");switch(this.init(s),s){case"flv":this.flv.start();break;case"hls":this.hls.start();break}};stop=async()=>{try{this.url="",clearInterval(this.hls.getSegmentsTimer),this.prFetch.stop(),this.getSegmentsFetch.stop()}catch(t){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: error",t)}this.demuxerWorker?.destroy(),this.decoderWorker?.destroy(),this.renderWorker?.destroy(),this.cutRenders=new Map,z(this.stream),this.audioPlayer?.destroy()};getStream=()=>this.stream;setPause=t=>{this.renderWorker?.setPause({pause:t})};setMute=t=>this.audioPlayer?.prAudioStream?.setMute(t);setOutputGain=t=>{this.audioPlayer?.prAudioStream?.setOutputGain(t)};setFrameTrack=t=>{this.option.frameTrack=t,this.decoderWorker?.setFrameTrack(t)};isReady=()=>{const t=()=>this.stream?.active===!0;return this.prResolves.add("isReady",t)};cut={create:(t,s)=>{const e=new MediaStreamTrackGenerator({kind:"video"}),i=new MediaStream([e]);return this.renderWorker?.addCut({key:t,writable:e.writable,option:s}),this.cutRenders.set(t,{stream:i}),i},setCut:(t,s)=>{this.renderWorker?.setCut({key:t,cutOption:s})},getStream:t=>this.cutRenders.get(t)?.stream,remove:t=>{this.renderWorker?.delCut(t),this.cutRenders.delete(t)},setPause:(t,s)=>{this.renderWorker?.setPause({key:t,pause:s})}};init=t=>{this.initDecoder(t),this.initRender(),this.initDemuxer(t),this.audioPlayer=new O,this.audioPlayer.init()};initDemuxer=t=>{this.demuxerWorker=new A,this.demuxerWorker.init(t),this.demuxerWorker.on.debug=s=>{this.option.debug&&this.on.debug&&this.on.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:i,sampleRate:n,numberOfChannels:o}=s;this.decoderWorker?.initAudio({codec:i,sampleRate:n,numberOfChannels:o})}break;case"video":{const{codec:i,description:n}=s;this.decoderWorker?.initVideo({codec:i,description:n})}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:i,dts:n,data:o}=s,a=n*1e3;this.decoderWorker.push({kind:e,init:{type:i,timestamp:a,data:o}})}break;case"video":{const{type:i,dts:n,data:o,nalus:a=[]}=s,r=n*1e3;this.decoderWorker.push({kind:e,init:{type:i,timestamp:r,data:o},nalus:a})}break}}};initDecoder=t=>{this.decoderWorker=new D,this.decoderWorker.init(t);const{frameTrack:s=!1}=this.option;this.decoderWorker.setFrameTrack(s),this.decoderWorker.on.audio.decode=e=>{this.audioPlayer?.push(e),this.on.decoder.audio&&this.on.decoder.audio(e)},this.decoderWorker.on.audio.error=e=>{this.option.debug&&console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->pr-player: audio.error ",e),this.on.error&&this.on.error(e)},this.decoderWorker.on.video.decode=async e=>{this.start_resolve&&(this.start_resolve(!0),this.start_resolve=void 0),this.renderWorker?.push(e),this.on.decoder.video&&this.on.decoder.video(e)},this.decoderWorker.on.video.error=e=>{this.on.error&&this.on.error(e)},this.decoderWorker.on.nalus=async e=>{for(const i of e){if(i.byteLength<=4)continue;const{header:n,data:o}=X(i),{nal_unit_type:a}=n;a===6&&this.on.decoder.sei&&this.on.decoder.sei(o)}},this.decoderWorker.on.analysis=e=>{this.on.decoder.analysis&&this.on.decoder.analysis(e)}};initRender=()=>{this.renderWorker=new R;const t=new MediaStreamTrackGenerator({kind:"video"}),s=new MediaStream([t]);this.renderWorker?.addCut({writable:t.writable}),this.stream=s,this.renderWorker?.setPause({pause:!1})};flv={start:()=>new Promise(async(t,s)=>{try{this.start_resolve=t;let e,i=0;for(;;){i+=1;try{e=await this.prFetch.request(this.url)}catch(o){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: error",o)}if(e?.status===200||i===3)break;await new Promise(o=>setTimeout(()=>o(!0),500))}if(!e||e.status!==200)return s("request is error.");const n=e.body?.getReader();if(!n)return s("reader is error.");for(;;){const{done:o,value:a}=await n.read();if(a&&this.demuxerWorker?.push(a),o||this.url==="")break}}catch(e){e.name!=="AbortError"&&s(e)}})};hls={isLive:!1,urls:[],url:"",getSegmentsTimer:0,parse:async t=>{const i=new TextDecoder("utf-8").decode(t).split(`
4
4
  `).map(c=>c.replace("\r","")),n=this.url.substring(0,this.url.lastIndexOf("/")+1);let o=4,a=0,r=!1;const d=[];for(const c of i)c.startsWith("#EXTINF:")?o=parseFloat(c.split(":")[1].split(",")[0]):c.startsWith("#EXT-X-TARGETDURATION:")?a=parseInt(c.split(":")[1]):c.startsWith("#EXT-X-ENDLIST")?r=!1:c.startsWith("#EXT-X-MEDIA-SEQUENCE:")?r=!0:c.includes(".ts")&&!c.startsWith("#")&&d.push({url:c.startsWith("http")?c:n+c,duration:o,isLive:r});return{baseUrl:n,targetDuration:a,isLive:r,segments:d}},getSegments:async()=>{try{let t,s=0;for(;;){s+=1;try{t=await this.getSegmentsFetch.request(this.url)}catch(i){console.log("\x1B[38;2;0;151;255m%c%s\x1B[0m","color:#0097ff;","------->Breathe: error",i)}if(t?.status===200||s===3)break;await new Promise(i=>setTimeout(()=>i(!0),500))}if(!t||t.status!==200)throw new Error("request is error.");const e=t.body?.getReader();if(!e)throw new Error("reader is error.");for(;;){const{done:i,value:n}=await e.read();if(n){const o=await this.hls.parse(n),{segments:a=[],isLive:r=!1}=o;this.hls.isLive=r,r===!1&&(this.option.frameTrack=!1);let d=Array.from(a,h=>h.url);const c=d.findIndex(h=>h===this.hls.url);c!==-1&&(d=d.slice(c+1)),this.hls.urls=d}if(i||this.url==="")break}}catch(t){t.name!=="AbortError"&&this.on.error&&this.on.error(t)}},start:()=>new Promise(async(t,s)=>{try{for(this.start_resolve=t,this.hls.url="",this.hls.urls=[],await this.hls.getSegments(),this.hls.getSegmentsTimer=window.setInterval(this.hls.getSegments,500),this.hls.isLive===!1&&(clearInterval(this.hls.getSegmentsTimer),this.decoderWorker?.setFrameTrack(!1));;){const e=this.hls.urls.shift();if(e){this.hls.url=e;const n=(await this.prFetch.request(e)).body?.getReader();if(!n)throw new Error("segment reader is error.");for(;;){const{done:o,value:a}=await n.read();if(a&&this.demuxerWorker?.push(a),o||this.url==="")break}}else await new Promise(i=>setTimeout(()=>i(!0),300))}}catch(e){e.name!=="AbortError"&&s(e)}})}}class Q{pendingPayloads=[];payload=new Uint8Array(0);chunks=[];push=t=>{this.pendingPayloads.push(t)};next=(t=0)=>{this.payload=this.payload.slice(t);const s=this.pendingPayloads.shift();if(!s)return!1;const e=new Uint8Array(this.payload.byteLength+s.byteLength);return e.set(this.payload,0),e.set(s,this.payload.byteLength),this.payload=e,new DataView(this.payload.buffer)};pushChunk=t=>{this.chunks.push(t),this.chunks.length>100&&this.chunks.shift()};destroy=()=>{this.pendingPayloads=[],this.payload=new Uint8Array(0),this.chunks=[]}}const J=p=>{let t="unknown";switch(p){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 Z{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 i=this.parseHeader(t,e);e+=4;const{transport_error_indicator:n,pid:o,payload_unit_start_indicator:a,adaptation_field_control:r}=i;if(n===1||o===void 0)return;let d=184;if(r===2||r===3){const c=t.getUint8(e);e+=1,this.parseAdaptationField(t,e),e+=c,d-=c}if(r===3&&(d-=1),r===1||r===3){const c=new Uint8Array(t.buffer.slice(e,e+d));if(o===0)return this.parsePAT(t,e);{const{programs:u=[]}=this.pat||{};if(u.find(f=>f.pmt_pid===o))return this.parsePMT(t,e)}const{streams:h=[]}=this.pmt||{},l=h.find(u=>u.elementary_pid===o);if(l){if(a===1){const u=this.payloadMap.get(o);if(u){switch(l.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),0))}break}this.payloadMap.delete(o)}}{this.payloadMap.has(o)||this.payloadMap.set(o,new Uint8Array);const u=this.payloadMap.get(o),g=new Uint8Array(u.byteLength+c.byteLength);g.set(u,0),g.set(c,u.byteLength),this.payloadMap.set(o,g)}}}};parseHeader=(t,s)=>{let e=s;const i=t.getUint8(e),n=t.getUint8(e+1),o=t.getUint8(e+2),a=t.getUint8(e+3),r=(n&128)>>7;if(r===1)return{sync_byte:i,transport_error_indicator:r};const d=(n&64)>>6,c=(n&32)>>5,h=(n&31)<<8|o,l=(a&192)>>6,u=a>>4&3,g=a&15;return{sync_byte:i,transport_error_indicator:r,payload_unit_start_indicator:d,transport_priority:c,pid:h,transport_scrambling_control:l,adaptation_field_control:u,continuity_counter:g}};parsePAT=(t,s)=>{let e=s,i;{const a=t.getUint8(e);e+=1;const r=t.getUint8(e);if(e+=1,r!==0)throw new Error("Invalid PAT table_id");const d=t.getUint16(e)&4095;e+=2;const c=t.getUint16(e);e+=2;const h=(t.getUint8(e)&62)>>1,l=t.getUint8(e)&1;e+=1;const u=t.getUint8(e);e+=1;const g=t.getUint8(e);e+=1,i={pointer_field:a,table_id:r,section_length:d,transport_stream_id:c,version_number:h,current_next_indicator:l,section_number:u,last_section_number:g}}const n=[];{const a=i.section_length-5-4,r=e+a;for(;e<r;){const d=t.getUint16(e),c=t.getUint16(e+2)&8191;e+=4,d!==0&&c>=32&&c<=8190&&n.push({program_number:d,pmt_pid:c})}}const o=t.getUint32(e);this.pat={header:i,programs:n,crc32:o},this.on.debug&&this.on.debug({pat:this.pat})};parsePMT=(t,s)=>{let e=s,i;{const a=t.getUint8(e);e+=1;const r=t.getUint8(e);if(e+=1,r!==2)throw new Error("Invalid PMT table_id");const d=t.getUint16(e)&4095;e+=2;const c=t.getUint16(e);e+=2;const h=(t.getUint8(e)&62)>>1,l=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,i={pointer_field:a,table_id:r,section_length:d,transport_stream_id:c,version_number:h,current_next_indicator:l,section_number:u,last_section_number:g,pcr_pid:f,program_info_length:y}}const n=[];{const a=i.section_length-9-4,r=e+a;for(;e<r;){const d=t.getUint8(e),c=J(d),h=t.getUint16(e+1)&8191,l=t.getUint16(e+3)&4095;if(e+=5,h<32||h>8190){console.warn(`Invalid elementary_pid: 0x${h.toString(16)}`);continue}n.push({kind:c,stream_type:d,elementary_pid:h,es_info_length:l})}}const o=t.getUint32(e);this.pmt={header:i,streams:n,crc32:o},this.on.debug&&this.on.debug({pmt:this.pmt})};parseAdaptationField=(t,s)=>{let e=s,i,n,o,a;const r=t.getUint8(e),d=!!(r&128),c=!!(r&64),h=!!(r&32),l=!!(r&16),u=!!(r&8),g=!!(r&4),f=!!(r&2),y=!!(r&1);e+=1;const b=(k,T)=>{let w=BigInt(0);w|=BigInt(k.getUint16(T))<<25n,w|=BigInt(k.getUint16(T+1))<<17n,w|=BigInt(k.getUint16(T+2))<<9n,w|=BigInt(k.getUint16(T+3))<<1n,w|=BigInt(k.getUint16(T+4)>>7);const nt=(k.getUint16(T+4)&1)<<8|k.getUint16(T+5);return w=w*300n+BigInt(nt),w};if(l&&(i=b(t,e),e+=6),u&&(n=b(t,e),e+=6),g&&(o=t.getInt8(e),e+=1),f){const k=t.getUint8(e);e+=1,a=new Uint8Array(t.buffer,e,k),e+=k}return{discontinuity_indicator:d,random_access_indicator:c,elementary_stream_priority_indicator:h,pcr_flag:l,opcr_flag:u,splicing_point_flag:g,transport_private_data_flag:f,adaptation_field_extension_flag:y,pcr:i,opcr:n,splice_countdown:o,transport_private_data:a}};parseAudio=async t=>{const s=new DataView(t.buffer);let e=0,i,n;{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 a=s.getUint8(e);e+=1;const r=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let d,c,h,l,u;{const y=s.getUint8(e);e+=1,d=y>>4&3,c=(y>>3&1)===1,h=(y>>2&1)===1,l=(y>>1&1)===1,u=(y&1)===1}let g,f;{const y=s.getUint8(e);e+=1;const b=y>>6,k=s.getUint8(e);e+=1,(b&2)===2&&(g=this.parsePtsDts(s,e)),(b&1)===1?f=this.parsePtsDts(s,e+5):f=g,e+=k}i={stream_id:a,pes_packet_length:r,scrambling_control:d,priority:c,data_alignment:h,copyright:l,original_copy:u,pts:g,dts:f}}n=t.slice(e);{if(!this.audioConfig&&s.getUint8(e)===255){const h=s.getUint8(e+2),l=s.getUint8(e+3);let u,g;g=h>>2&15,u=(h&1)<<2|l>>6;const f=`mp4a.40.${u}`,b=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][g];this.audioConfig={kind:"audio",codec:f,sampleRate:b,numberOfChannels:u},this.on.config&&this.on.config(this.audioConfig)}const{dts:o=0,pts:a=0}=i,r=a-o,d=n.slice(7);return{kind:"audio",type:"key",dts:o,pts:a,cts:r,data:d}}};parseVideo=async t=>{const s=new DataView(t.buffer);let e=0,i,n;{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 a=s.getUint8(e);e+=1;const r=s.getUint8(e)<<8|s.getUint8(e+1);e+=2;let d,c,h,l,u;{const y=s.getUint8(e);e+=1,d=y>>4&3,c=(y>>3&1)===1,h=(y>>2&1)===1,l=(y>>1&1)===1,u=(y&1)===1}let g,f;{const y=s.getUint8(e);e+=1;const b=y>>6,k=s.getUint8(e);e+=1,(b&2)===2&&(g=this.parsePtsDts(s,e)),(b&1)===1?f=this.parsePtsDts(s,e+5):f=g,e+=k}i={stream_id:a,pes_packet_length:r,scrambling_control:d,priority:c,data_alignment:h,copyright:l,original_copy:u,pts:g,dts:f}}n=t.slice(e);{const o=this.getNalus(n);if(!this.videoConfig){let u,g;if(u=o.find(y=>y.type===7)?.nalu.slice(4),g=o.find(y=>y.type===8)?.nalu.slice(4),u&&g){const f=$(u,g),{codec:y}=I(f);this.videoConfig={kind:"video",codec:y,description:f,sps:u,pps:g},this.on.config&&this.on.config(this.videoConfig)}}const a=[];let r="delta";for(const u of o){const{type:g,nalu:f}=u;switch(g){case 6:case 9:a.push(f);break;case 1:r="delta",a.push(f);break;case 5:r="key",a.push(f);break}}const d=K(a),{dts:c=0,pts:h=0}=i,l=h-c;return{kind:"video",type:r,dts:c,pts:h,cts:l,data:d,nalus:a}}};parsePtsDts(t,s){const e=t.getUint8(s),i=t.getUint8(s+1),n=t.getUint8(s+2),o=t.getUint8(s+3),a=t.getUint8(s+4),r=(BigInt(e)&0b00001110n)<<29n|(BigInt(i)&0b11111111n)<<22n|(BigInt(n)&0b11111110n)<<14n|(BigInt(o)&0b11111111n)<<7n|(BigInt(a)&0b11111110n)>>1n;return Number(r)/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 i=e;const n=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-i;if(t[e-1]===0&&(o-=1),o!==0){const a=t.slice(i,i+o),r=H(a);s.push({type:n,nalu:r})}}return s}}const C=(p,t)=>p.getUint8(t)<<16|p.getUint8(t+1)<<8|p.getUint8(t+2);class tt{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 i=this.parseTagHeader(t,s+4),{tagType:n,dataSize:o,timestamp:a}=i;if(n){const r=this.parseTagBody(n,t,s+4+11,o);switch(n){case"script":this.on.info&&this.on.info(r);break;case"audio":{const{accPacketType:d}=r;if(d===0){const{codec:c,sampleRate:h,channelConfiguration:l}=r;this.audioConfig={kind:"audio",codec:c,sampleRate:h,numberOfChannels:l},this.on.config&&this.on.config(this.audioConfig)}else{const{cts:c,data:h}=r,l="key",u=c===void 0?void 0:c+a;this.on.chunk&&this.on.chunk({kind:"audio",type:l,dts:a,pts:u,cts:c,data:h})}}break;case"video":{const{avcPacketType:d}=r;if(d===0){const{codec:c,sps:h,pps:l,data:u}=r;this.videoConfig={kind:"video",codec:c,description:u,sps:h,pps:l},this.on.config&&this.on.config(this.videoConfig)}else{const{frameType:c,cts:h,data:l,nalus:u}=r,g=c===1?"key":"delta",f=h===void 0?void 0:h+a;this.on.chunk&&this.on.chunk({kind:"video",type:g,dts:a,pts:f,cts:h,data:l,nalus:u})}}break}s=s+4+11+o}await new Promise(r=>setTimeout(()=>r(!0),8))}return s};parseHeader=(t,s)=>{let e,i,n,o;e=t.getUint8(s)<<16|t.getUint8(s+1)<<8|t.getUint8(s+2),i=t.getUint8(3);{const r=t.getUint8(0).toString(2).padStart(5,"0").split(""),[,,d,,c]=r;n={audio:c==="1",video:d==="1"}}o=t.getUint32(5),this.header={signature:e,version:i,flags:n,dataOffset:o}};isSurplusTag=(t,s)=>{let e=!0;const i=t.byteLength;if(s+4>i)e=!1;else if(s+4+11>i)e=!1;else{const n=C(t,s+4+1);s+4+11+n>i&&(e=!1)}return e};parseTagHeader=(t,s)=>{let e,i,n,o,a;{const r=t.getUint8(s);let d;switch(r){case 18:d="script";break;case 8:d="audio";break;case 9:d="video";break}e=d}return i=C(t,s+1),n=C(t,s+4),o=t.getUint8(s+7),a=C(t,s+8),{tagType:e,dataSize:i,timestamp:n,timestampExtended:o,streamID:a}};parseTagBody=(t,s,e,i)=>{let n;switch(t){case"script":n=this.parseMetaData(s,e);break;case"audio":n=this.parseAudio(s,e,i);break;case"video":n=this.parseVideo(s,e,i);break}return n};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 i=t.getUint16(e,!1);e=e+2;{const a=new Int8Array(t.buffer.slice(e,e+i));if((this.textDecoder?.decode(a)||"")!=="onMetaData")throw new Error("Expected 'onMetaData' string");e=e+i}const n=this.getAmfType(t,e);return e=e+1,this.getAMFValue(t,e,n).value};parseAudio=(t,s,e)=>{let i=s;const n=t.getUint8(i),o=n>>4&15,a=n>>2&3,r=n>>1&1,d=n&1;i=i+1;const c=t.getUint8(i);i=i+1;const h=e,l=new Uint8Array(t.buffer.slice(i,i+h));if(o===10&&c===0){const u=t.getUint8(i),g=t.getUint8(i+1),f=u>>3&31,y=(u&7)<<1|g>>7,b=g>>3&15,k=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],T=`mp4a.40.${f}`,w=k[y];return{soundFormat:o,soundRate:a,soundSize:r,soundType:d,accPacketType:c,data:l,samplingFrequencyIndex:y,channelConfiguration:b,codec:T,sampleRate:w}}return{soundFormat:o,soundRate:a,soundSize:r,soundType:d,accPacketType:c,data:l}};parseVideo=(t,s,e)=>{let i=s;const n=t.getUint8(i),o=n>>4&15,a=n&15;i=i+1;const r=t.getUint8(i);i=i+1;const d=C(t,i);i=i+3;const c=e-5,h=new Uint8Array(t.buffer.slice(i,i+c));switch(a){case 7:if(r===0){const l=I(h);return{frameType:o,codecID:a,avcPacketType:r,cts:d,data:h,...l}}else if(r===1){const l=[],u=i+e-5;for(;!(i+4>u);){const g=t.getUint32(i,!1),f=new Uint8Array(t.buffer.slice(i,i+4+g));i+=4+g,l.push(f)}return{frameType:o,codecID:a,avcPacketType:r,cts:d,data:h,nalus:l}}break;default:throw new Error("Unsupported codecID")}return{frameType:o,codecID:a,avcPacketType:r,cts:d,data:h}};getAmfType=(t,s)=>t.getUint8(s);getAMFName=(t,s,e)=>{const i=new Uint8Array(t.buffer.slice(s,s+e));return this.textDecoder?.decode(i)||""};getAMFValue=(t,s,e)=>{let i=s,n,o=0;switch(e){case 0:n=t.getFloat64(i,!1),o=8;break;case 1:n=!!t.getUint8(i),o=1;break;case 2:{n="";const r=t.getUint16(i,!1);i=i+2;const d=new Int8Array(t.buffer,i,r).filter(h=>h!==0);n=(this.textDecoder?.decode(d)||"").trim(),o=2+r}break;case 3:for(n={};i<t.byteLength;){const r=t.getUint16(i,!1);if(r===0)break;i=i+2;const d=this.getAMFName(t,i,r);i=i+r;const c=this.getAmfType(t,i);if(c===6)break;i=i+1;const h=this.getAMFValue(t,i,c);i=i+h.length,n[d]=h.value,o=2+r+1+h.length}break;case 8:{n={};const r=t.getUint32(i,!1);i=i+4;for(let d=0;d<r;d++){const c=t.getUint16(i,!1);i=i+2;const h=this.getAMFName(t,i,c);i=i+c;const l=this.getAmfType(t,i);i=i+1;const u=this.getAMFValue(t,i,l);i=i+u.length,n[h]=u.value,o=2+c+1+u.length}}break;case 10:{n=[];const r=t.getUint32(i,!1);i=i+4;for(let d=0;d<r;d++){const c=this.getAmfType(t,i);i=i+1;const h=this.getAMFValue(t,i,c);i=i+h.length,n.push(h.value),o=1+h.length}}break}return{amfType:e,length:o,value:n}}}class et{pattern;cacher=new Q;isParseing=!1;offset=0;parser;on={};constructor(){}init=t=>{switch(this.destroy(),this.pattern=t,this.pattern){case"flv":this.parser=new tt;break;case"hls":this.parser=new Z;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 st{pattern="flv";audioDecoderConfig;audioDecoder;videoDecoderConfig;videoDecoder;hasKeyFrame=!1;baseTime=0;pendingChunks=[];currentChunk;isProcessing=!1;decodeTimer=0;frameTrack=!1;isFrameTrack=!1;fameTrackOption={flv:[30,50],hls:[200,300],dash:[50,100],rtmp:[50,100]};decodingSpeedRatio=1;maxDecodingSpeedRatio=2;decodingSpeed=16;fps=0;firstVideoChunkTimestamp;secondVideoChunkTimestamp;frameStartTime;lastRenderTime;nextRenderTime;on={audio:{},video:{}};constructor(){}init=t=>{this.destroy(),this.pattern=t,this.baseTime=new Date().getTime()-performance.now(),this.initDecodeInterval()};initAudio=t=>{this.audio.destroy(),this.audioDecoderConfig={...t},this.audioDecoder=new AudioDecoder({output:s=>{const e=this.decodingSpeedRatio;this.on.audio.decode&&this.on.audio.decode({audioData:s,playbackRate:e})},error:s=>{this.on.audio.error&&this.on.audio.error(s)}}),this.audioDecoder.configure(this.audioDecoderConfig)};initVideo=t=>{this.video.destroy(),this.videoDecoderConfig={...t},this.videoDecoder=new VideoDecoder({output:async s=>{this.frameStartTime||(this.frameStartTime=s.timestamp);const e=s.timestamp-this.frameStartTime+this.baseTime*1e3,i=await createImageBitmap(s);s.close(),i.width>0&&i.height>0?(this.on.video.decode&&this.on.video.decode({timestamp:e,bitmap:i}),this.currentChunk&&this.currentChunk.kind==="video"&&this.currentChunk.nalus&&this.on.nalus&&this.on.nalus(this.currentChunk.nalus)):i.close()},error:s=>{this.on.video.error&&this.on.video.error(s)}}),this.videoDecoder.configure(this.videoDecoderConfig)};setFrameTrack=t=>{this.frameTrack=t,this.frameTrack===!1&&(this.decodingSpeedRatio=1)};push=t=>{this.pendingChunks.push(t)};destroy=()=>{this.audio.destroy(),this.video.destroy(),this.pendingChunks=[],this.firstVideoChunkTimestamp=void 0,this.secondVideoChunkTimestamp=void 0,this.frameStartTime=void 0,this.lastRenderTime=void 0,this.nextRenderTime=void 0,clearInterval(this.decodeTimer)};initDecodeInterval=()=>{let t=this.decodingSpeed/this.decodingSpeedRatio;const s=this.baseTime+performance.now();if(this.lastRenderTime||(this.lastRenderTime=s),this.fps=Math.round(1e3/(s-this.lastRenderTime)),this.lastRenderTime=s,this.nextRenderTime){const e=this.lastRenderTime-this.nextRenderTime;t-=e}this.nextRenderTime=this.lastRenderTime+t,this.decodeTimer=setTimeout(()=>{this.decode(),this.initDecodeInterval()},t)};decode=()=>{if(this.isProcessing!==!0){for(this.isProcessing=!0;this.currentChunk=this.pendingChunks.shift(),!!this.currentChunk;){const t=this.pendingChunks.length;if(this.frameTrack){const[i,n]=this.fameTrackOption[this.pattern];if(t<=i&&(this.isFrameTrack=!1),t>=n&&(this.isFrameTrack=!0),this.isFrameTrack){const o=Math.min(1+(t-i)/100,this.maxDecodingSpeedRatio);this.decodingSpeedRatio=Number(o.toFixed(1))}else this.decodingSpeedRatio=1}if(this.on.analysis){const{decodingSpeed:i,decodingSpeedRatio:n,fps:o}=this;this.on.analysis({decodingSpeed:i,decodingSpeedRatio:n,fps:o,cacheLength:t})}const{kind:s,init:e}=this.currentChunk;switch(s){case"audio":this.decodeAudio(e);break;case"video":this.decodeVideo(e);break}if(s==="video")break}this.isProcessing=!1}};decodeAudio=t=>{if(!this.audioDecoder)return;const s=new EncodedAudioChunk(t);this.audioDecoder.decode(s)};decodeVideo=t=>{if(this.videoDecoder&&(t.type==="key"&&(this.hasKeyFrame=!0),this.firstVideoChunkTimestamp?this.secondVideoChunkTimestamp||(this.secondVideoChunkTimestamp=t.timestamp,this.decodingSpeed=(this.secondVideoChunkTimestamp-this.firstVideoChunkTimestamp)/1e3):this.firstVideoChunkTimestamp=t.timestamp,this.hasKeyFrame)){const s=new EncodedVideoChunk(t);this.videoDecoder.decode(s)}};audio={flush:()=>{this.audioDecoder?.flush()},destroy:()=>{this.audioDecoderConfig=void 0,this.audioDecoder?.close(),this.audioDecoder=void 0}};video={flush:()=>{this.videoDecoder?.flush()},destroy:()=>{this.videoDecoderConfig=void 0,this.videoDecoder?.close(),this.videoDecoder=void 0,this.hasKeyFrame=!1}}}class it{renderMap=new Map;constructor(){}push=async t=>{const{timestamp:s}=t,{bitmap:e}=t;if(e.height===0||e.width===0)return e.close();const i=[...this.renderMap.keys()];for(const n of i){const o=this.renderMap.get(n);if(!o)continue;const{pause:a=!1,writer:r,option:d}=o;if(a!==!0)if(n==="default"||!d){const c=new VideoFrame(e,{timestamp:s});r.write(c),c.close()}else{const{sx:c=0,sy:h=0,sw:l=e.width,sh:u=e.height}=d,g=await createImageBitmap(e,c,h,l,u),f=new VideoFrame(g,{timestamp:s});g.close(),r.write(f),f.close()}}e.close()};addCut=t=>{const{key:s,writable:e,option:i}={key:"default",...t},n=e.getWriter();this.renderMap.set(s,{writable:e,writer:n,option:i,pause:!1})};delCut=t=>{this.renderMap.delete(t)};setCut=t=>{const{key:s,cutOption:e}={key:"default",...t},i=this.renderMap.get(s);i&&this.renderMap.set(s,{...i,option:e})};setPause=t=>{const{key:s,pause:e}={key:"default",...t},i=this.renderMap.get(s);i&&this.renderMap.set(s,{...i,pause:e})};destroy=()=>{this.renderMap=new Map}}U.Decoder=st,U.DecoderWorker=D,U.Demuxer=et,U.DemuxerWorker=A,U.PrPlayer=Y,U.Render=it,U.RenderWorker=R,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 hls 格式的地址进行解析 并输出 MediaStream,提供 demuxer 层(info、chunk)回调、 decoder 层(audio、video、sei)回调 ,提供 cut 等相关能力,以支持根据业务层 SEI 对视频进行剪切渲染。",
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"