1 |
- class t{canvas=null;ctx=null;getShowData=null;storage=[];constructor(t,e,s,a){this.canvas=t,this.ctx=t.getContext("2d"),this.getShowData=e,this.outputLayer=s,this.cropFullInfo=JSON.parse(a)}#t(t,e){return t.length===e.length&&t.every((function(t,s){return t===e[s]}))}#e(t){if(t.length)for(let e=0;e<t.length;e++)if(this.ctx.strokeStyle="red",this.ctx.lineWidth=10,this.outputLayer){let[s,a,i,h]=[t[e].x*this.outputLayer.WidthRatio,t[e].y*this.outputLayer.HeightRatio,t[e].w*this.outputLayer.WidthRatio,t[e].h*this.outputLayer.HeightRatio];this.ctx.strokeRect(s,a,i,h),this.storage=[s,a,i,h]}else this.ctx.strokeRect(t[e].x,t[e].y,t[e].w,t[e].h),this.storage=[t[e].x,t[e].y,t[e].w,t[e].h];else{let[t,e,s,a]=this.storage;this.ctx.strokeStyle="transparent",this.ctx.lineWidth=10,this.ctx.strokeRect(t,e,s,a)}}temp=null;draw(t){switch(this.cropFullInfo.UseCrop?(this.canvas.width=this.cropFullInfo.W,this.canvas.height=this.cropFullInfo.H):(this.canvas.width=t.displayWidth,this.canvas.height=t.displayHeight),this.ctx.translate(this.canvas.width/2,this.canvas.height/2),this.cropFullInfo.UseRotate?this.ctx.rotate(this.cropFullInfo.Rotate/90*1.57):(this.ctx.rotate(0),this.cropFullInfo.Rotate=0),this.cropFullInfo.Rotate){case 0:case 180:this.ctx.drawImage(t,this.cropFullInfo.UseCrop?-this.canvas.width/2-this.cropFullInfo.X:-this.canvas.width/2,this.cropFullInfo.UseCrop?-this.canvas.height/2-this.cropFullInfo.Y:-this.canvas.height/2,t.displayWidth,t.displayHeight);break;case 90:case 270:this.ctx.drawImage(t,this.cropFullInfo.UseCrop?-this.canvas.height/2-this.cropFullInfo.Y:-this.canvas.height/2,this.cropFullInfo.UseCrop?-this.canvas.width/2-this.cropFullInfo.X:-this.canvas.width/2,t.displayWidth,t.displayHeight)}self.GetImg&&(this.ctx.canvas.convertToBlob().then((t=>{self.postMessage({img:t,type:"img"})})),self.GetImg=!1);const e=this.getShowData();e&&this.#e(e),t.close()}}self.GetImg=!1;let e=null,s=null;var a=new class{constructor(){this._items=[]}enqueue(t){this._items.push(t)}dequeue(){return this._items.shift()}head(){return this._items[0]}tail(){return this._items[this._items.length-1]}isEmpty(){return!this._items.length}size(){return this._items.length}clear(){this._items=[]}};const i=new VideoDecoder({output(t){!function(t){a.enqueue(t)}(t)},error(t){console.error(t)}});function h(){return s}setInterval((function(){a.size()>0&&e.draw(a.dequeue())}),39);var o=0,r="";self.addEventListener("message",(a=>{let{canvas:n,device:l,url:c,type:d}=a.data;if("jt"===d&&(self.GetImg=!0),"Opt"===a.data.DataType&&(r=a.data.data),"Start"===a.data.DataType&&(e=new t(n,h,null,r),!VideoDecoder))throw new Error("The current browser does not support the VideoDecoder API");if("Track"===a.data.DataType&&(i.configure({codec:a.data.codec,codedHeight:a.data.codedHeight,codedWidth:a.data.codedWidth,description:a.data.description}),console.log(a.data)),"Samples"===a.data.DataType)if(s=a.data.showData||null,i.decode(new EncodedVideoChunk({type:a.data.type,timestamp:a.data.timestamp,duration:a.data.duration,data:a.data.data})),3===o){self.postMessage(!0),o=4}else{if(4===o)return;o++}}));
|