@zoom/videosdk
Version:
Zoom Web Video SDK
2 lines • 20.5 kB
JavaScript
(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function n(e,t,n){return(t=function(e){var t=function(e){if("object"!=i(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==i(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}e.r(t),e.d(t,{CROPPING_SHAPE:()=>r,RENDERER_TYPE:()=>a});const a={_2D:0,WEBGL:1,WEBGL_2:2,WEBGPU:3},r={CIRCLE:0,ELLIPSE:1};function s(e,t,i){o(e,t),t.set(e,i)}function o(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function l(e,t){return e.get(h(e,t))}function c(e,t,i){return e.set(h(e,t),i),i}function h(e,t,i){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:i;throw new TypeError("Private element is not present on this object")}var u=new WeakMap,d=new WeakMap,p=new WeakMap,E=new WeakMap,m=new WeakMap,R=new WeakMap,f=new WeakMap,_=new WeakMap,v=new WeakMap,T=new WeakMap,g=new WeakMap,S=new WeakMap,C=new WeakMap,P=new WeakMap,A=new WeakMap,O=new WeakSet;function w(e,t){e?t===a._2D?h(O,this,L).call(this,e):t===a.WEBGL?h(O,this,y).call(this,e):t===a.WEBGL_2?h(O,this,b).call(this,e):t===a.WEBGPU?h(O,this,I).call(this,e):h(O,this,y).call(this,e):console.error("DynamicMaskRenderDisplay#initContext() cannot initialize context due to null context")}function y(e){c(p,this,h(O,this,F).call(this,e,e.VERTEX_SHADER,"\n attribute vec2 aPosition;\n attribute vec2 aTexCoord;\n varying vec2 vTexCoord;\n void main() {\n gl_Position = vec4(aPosition.x, -aPosition.y, 0.0, 1.0);\n vTexCoord = aTexCoord;\n }\n")),c(E,this,h(O,this,F).call(this,e,e.FRAGMENT_SHADER,"\n precision mediump float;\n const int SHAPE_CIRCLE = 0;\n const int SHAPE_ELLIPSE = 1;\n varying vec2 vTexCoord;\n uniform sampler2D uVideoTexture;\n uniform sampler2D uMaskTexture;\n uniform vec4 uEllipses[10];\n uniform float uAngles[10]; \n uniform int uEllipseCount;\n uniform int uCroppingShape;\n uniform float uAspectRatio;\n uniform float uScaleFactor;\n uniform int uZoomVideo;\n\n vec2 applyZoom(vec2 uv, vec2 center, float scaleFactor) {\n return center + (uv - center) / scaleFactor;\n }\n\n void main() {\n vec4 maskColor = texture2D(uMaskTexture, vTexCoord);\n vec2 videoUV = vTexCoord;\n bool inShape = false;\n bool isZoomVideo = uZoomVideo == 1;\n\n if (uEllipseCount > 0) {\n for (int i = 0; i < 10; i++) {\n if (i >= uEllipseCount) break;\n\n vec2 ellipseCenter = uEllipses[i].xy;\n float angle = radians(uAngles[i]);\n float condition = 0.0;\n vec2 ellipseRadii;\n\n if (uCroppingShape == SHAPE_CIRCLE) {\n // Circle\n float minRadii = min(uEllipses[i].z * uScaleFactor, uEllipses[i].w * uScaleFactor);\n ellipseRadii = vec2(minRadii, minRadii);\n vec2 pos = vec2(vTexCoord.x, vTexCoord.y / uAspectRatio) - vec2(ellipseCenter.x, ellipseCenter.y / uAspectRatio);\n\n condition = dot(pos, pos) / (ellipseRadii.x * ellipseRadii.x);\n if (isZoomVideo && condition <= 1.0) {\n videoUV = applyZoom(videoUV, ellipseCenter, uScaleFactor);\n }\n } else if (uCroppingShape == SHAPE_ELLIPSE) {\n // Ellipse\n ellipseRadii = uEllipses[i].zw * uScaleFactor;\n vec2 pos = vTexCoord - ellipseCenter;\n\n // Rotate position for ellipse calculation\n vec2 rotatedPos;\n rotatedPos.x = pos.x * cos(angle) + pos.y * sin(angle);\n rotatedPos.y = -pos.x * sin(angle) + pos.y * cos(angle);\n\n condition = (rotatedPos.x * rotatedPos.x) / (ellipseRadii.x * ellipseRadii.x) +\n (rotatedPos.y * rotatedPos.y) / (ellipseRadii.y * ellipseRadii.y);\n\n if (isZoomVideo && condition <= 1.0) {\n videoUV = applyZoom(videoUV, ellipseCenter, uScaleFactor);\n }\n }\n\n if (condition <= 1.0) {\n inShape = true;\n break;\n }\n }\n }\n\n // Output color based on whether inShape is true\n gl_FragColor = inShape ? texture2D(uVideoTexture, videoUV) : maskColor;\n }\n")),c(m,this,h(O,this,M).call(this,e,l(p,this),l(E,this)));const t=new Float32Array([-1,-1,0,0,1,-1,1,0,-1,1,0,1,-1,1,0,1,1,-1,1,0,1,1,1,1]),i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW);const n=e.getAttribLocation(l(m,this),"aPosition");e.vertexAttribPointer(n,2,e.FLOAT,!1,16,0),e.enableVertexAttribArray(n);const a=e.getAttribLocation(l(m,this),"aTexCoord");e.vertexAttribPointer(a,2,e.FLOAT,!1,16,8),e.enableVertexAttribArray(a),c(R,this,e.createTexture()),c(f,this,e.createTexture())}function b(e){h(O,this,y).call(this,e)}function I(e){}function L(e){}function F(e,t,i){const n=e.createShader(t);return e.shaderSource(n,i),e.compileShader(n),e.getShaderParameter(n,e.COMPILE_STATUS)?n:(console.error("Error compiling shader:",e.getShaderInfoLog(n)),e.deleteShader(n),null)}function M(e,t,i){const n=e.createProgram();return e.attachShader(n,t),e.attachShader(n,i),e.linkProgram(n),e.getProgramParameter(n,e.LINK_STATUS)||(console.error("Error linking program:",e.getProgramInfoLog(n)),e.deleteProgram(n)),e.useProgram(n),n}function k(e){let t=l(d,this);t&&e&&(l(f,this)||c(f,this,t.createTexture()),t.bindTexture(t.TEXTURE_2D,l(f,this)),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE))}function x(e,t){let i=l(d,this),n=l(m,this);if(!i||!n)return;i.viewport(0,0,l(u,this).width,l(u,this).height),i.bindTexture(i.TEXTURE_2D,l(R,this)),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,e),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,l(R,this)),i.uniform1i(i.getUniformLocation(n,"uVideoTexture"),0),i.activeTexture(i.TEXTURE1),i.bindTexture(i.TEXTURE_2D,l(f,this)),i.uniform1i(i.getUniformLocation(n,"uMaskTexture"),1);const a=t.ellipses.length;if(a>0){const e=new Float32Array(t.ellipses.flat());let a;a=l(P,this)?new Float32Array(t.angles):new Float32Array(t.angles.length).fill(0),i.uniform4fv(i.getUniformLocation(n,"uEllipses"),e),i.uniform1fv(i.getUniformLocation(n,"uAngles"),a)}i.uniform1i(i.getUniformLocation(n,"uEllipseCount"),a),i.uniform1i(i.getUniformLocation(n,"uCroppingShape"),l(g,this)),i.uniform1f(i.getUniformLocation(n,"uAspectRatio"),l(S,this)),i.uniform1f(i.getUniformLocation(n,"uScaleFactor"),l(C,this));let r=0;l(A,this)&&(r=1),i.uniform1i(i.getUniformLocation(n,"uZoomVideo"),r),i.drawArrays(i.TRIANGLES,0,6)}function D(e,t,i){let n=l(d,this);if(!n||!l(u,this))return void console.error("Canvas context or canvas not initialized");const a=l(u,this).width,s=l(u,this).height;n.drawImage(e,0,0,a,s),n.drawImage(t,0,0,a,s),i&&i.ellipses.length>0&&i.ellipses.forEach((t=>{const i=t[0],o=t[1],c=t[2],h=t[3];if(n.save(),n.beginPath(),l(g,this)==r.ELLIPSE)n.ellipse(i,o,c,h,0,0,2*Math.PI);else if(l(g,this)==r.CIRCLE){let e=Math.min(c,h)*l(C,this);n.arc(i,o,e,0,360)}n.clip(),n.drawImage(e,0,0,a,s),n.restore()}))}function U(e){e===r.CIRCLE?c(g,this,r.CIRCLE):(e===r.ELLIPSE||console.error("updateCroppingShape() unsupported cropping shape! Switch to ellipse. val:".concat(e)),c(g,this,r.ELLIPSE))}function W(e){return Number.isNaN(e)||!e?(console.error("updateCroppingShapeScaleFactor() scaleFactor is not a number! scaleFactor:".concat(JSON.stringify(e))),void c(C,this,1)):e<=0?(console.error("updateCroppingShapeScaleFactor() scaleFactor should be a non-zero positive number! scaleFactor:".concat(e)),void c(C,this,1)):void c(C,this,e)}function N(e){c(P,this,!0===e)}function V(e){c(A,this,!0===e)}const B=class{constructor(e,t){var i;o(this,i=O),i.add(this),s(this,u,null),s(this,d,null),s(this,p,null),s(this,E,null),s(this,m,null),s(this,R,null),s(this,f,null),s(this,_,0),s(this,v,null),s(this,T,null),s(this,g,r.ELLIPSE),s(this,S,1),s(this,C,1),s(this,P,!1),s(this,A,!1),c(u,this,e),c(_,this,t),c(d,this,function(e,t){if(!e)return null;t!==a._2D&&t!==a.WEBGL&&t!==a.WEBGL_2&&t!==a.WEBGPU&&(t=a.WEBGL);let i="webgl";i=t===a._2D?"2d":t===a.WEBGL?"webgl":t===a.WEBGL_2?"webgl2":t===a.WEBGPU?"webgpu":"webgl";let n=e.getContext(i);return n||console.error("getContext() cannot get context from canvas! contextType:".concat(i)),n}(e,t)),h(O,this,w).call(this,l(d,this),t),c(S,this,e.width/e.height),l(S,this)<=0&&c(S,this,1);const n={croppingShape:r.ELLIPSE,scaleFactor:1,useAngle:!1,zoomVideo:!1};this.updateMaskOptions(n)}getRendererType(){return l(_,this)}updateMaskImage(e){c(v,this,e),l(_,this)!=a.WEBGL&&l(_,this)!=a.WEBGL_2||h(O,this,k).call(this,e)}updateMaskOptions(e){c(T,this,e),e&&(h(O,this,U).call(this,e.croppingShape),h(O,this,W).call(this,e.scaleFactor),h(O,this,N).call(this,e.useAngle),h(O,this,V).call(this,e.zoomVideo))}render(e,t){l(v,this)&&e&&l(T,this)&&t&&(l(_,this)==a.WEBGL_2||l(_,this)==a.WEBGL?h(O,this,x).call(this,e,t):l(_,this)==a._2D&&h(O,this,D).call(this,e,l(v,this),t))}cleanup(){c(u,this,null),c(d,this,null),c(p,this,null),c(E,this,null),c(m,this,null),c(R,this,null),c(f,this,null),c(_,this,0),c(v,this,null),c(T,this,null)}};function G(e,t,i){H(e,t),t.set(e,i)}function H(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function X(e,t,i){return e.set(q(e,t),i),i}function j(e,t){return e.get(q(e,t))}function q(e,t,i){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:i;throw new TypeError("Private element is not present on this object")}var z=new WeakMap,Z=new WeakMap,Y=new WeakSet;function K(e,t,i,n){let r=[],s=[];if(e.length<=2)for(let p of e){var o,l;const[e,E,m]=p.keypoints,R={x:(E.x+e.x)/2,y:(E.y+e.y)/2},f=Math.atan2(R.y-E.y,R.x-E.x),_={x:(R.x+m.x)/2,y:(R.y+m.y)/2};if(null!==(o=p.boundingBox)&&void 0!==o&&o.width&&null!==(l=p.boundingBox)&&void 0!==l&&l.height){let e=0,o=0,l=0,E=0;var c,h,u,d;n==a._2D?(e=_.x*t,o=_.y*i,l=(null===(c=p.boundingBox)||void 0===c?void 0:c.width)/2,E=(null===(h=p.boundingBox)||void 0===h?void 0:h.height)/1.5):(e=_.x,o=_.y,l=(null===(u=p.boundingBox)||void 0===u?void 0:u.width)/2/t,E=(null===(d=p.boundingBox)||void 0===d?void 0:d.height)/1.5/i),r.push([e,o,l,E]),s.push([f*(180/Math.PI)])}}return{ellipses:r,angles:s,raw:e}}const Q=class{constructor(){var e;H(this,e=Y),e.add(this),G(this,z,null),G(this,Z,a.WEBGL)}initDynamicMaskEngine(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a.WEBGL_2,i=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;if(!e||!i||!n)return console.error("initDynamicMaskEngine() failed to start! invalid args."),!1;t!==a._2D&&t!==a.WEBGL&&t!==a.WEBGL_2&&t!==a.WEBGPU&&(t=a.WEBGL),j(z,this)||X(z,this,new B(e,t)),this.updateMaskImage(i),this.updateMaskOptions(n),X(Z,this,t)}updateMaskImage(e){j(z,this)&&j(z,this).updateMaskImage(e)}updateMaskOptions(e){j(z,this)&&j(z,this).updateMaskOptions(e)}render(e,t){if(e)if(t){if(j(z,this)){let i=e.displayWidth,n=e.displayHeight,a=q(Y,this,K).call(this,t,i,n,j(Z,this));j(z,this).render(e,a)}}else console.error("DynamicMaskEngine#render() dataSet is invalid!");else console.error("DynamicMaskEngine#render() videoSrc is invalid!")}uninitDynamicMaskEngine(){j(z,this)&&(j(z,this).cleanup(),X(z,this,null))}};function J(e,t){return e.get($(e,t))}function $(e,t,i){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:i;throw new TypeError("Private element is not present on this object")}var ee=new WeakMap;class te{constructor(){if(i=null,function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e=this,t=ee),t.set(e,i),te.instance)return te.instance;var e,t,i;te.instance=this}getDynamicMaskEngine(){var e,t;return J(ee,this)||(e=ee,t=new Q,e.set($(e,this),t)),J(ee,this)}}const ie=new te;var ne,ae,re,se;!function(e){e.ADD_VIDEO_PORT="add_video_port",e.ADD_SHADOW_PORT="add_shadow_port",e.ADD_VIDEO_PROCESSOR="add_video_processor",e.PROCESSOR_READY="processor_ready",e.PROCESSOR_ERROR="processor_error"}(ne||(ne={})),function(e){e.ADD_SHARE_PORT="add_share_port",e.ADD_SHADOW_PORT="add_shadow_port",e.ADD_SHARE_PROCESSOR="add_share_processor",e.ADD_SHARE_ENCODE_PORT="add_share_encode_port",e.PROCESSOR_READY="processor_ready",e.PROCESSOR_ERROR="processor_error"}(ae||(ae={})),function(e){e.INIT_PROCESSOR="init_processor",e.UNINIT_PROCESSOR="uninit_processor",e.INIT_OUTPUT_CANVAS="init_output_canvas",e.OUTPUT_WRITABLE_STREAM="output_writable_stream",e.INPUT_READABLE_STREAM="input_readable_stream",e.FRAME_DATA="frame_data",e.START_REQUEST_FRAME="start_request_frame",e.STOP_REQUEST_FRAME="stop_request_frame",e.REQUEST_FRAME="request_frame",e.FRAME_CALLBACK="frame_callback",e.RESOLUTION_CHANGE="RESOLUTION_CHANGE",e.PROCESSOR_WORKER_ERROR="PROCESSOR_WORKER_ERROR",e.PROCESSOR_STOP_COMPLETE="PROCESSOR_STOP_COMPLETE"}(re||(re={})),se||(se={});let oe=!1;const le=new Map,ce=new Map,he=new Map;function ue(e,t){le.set(e,t)}function de(e){let t;"string"==typeof e?t=e:e instanceof ErrorEvent?t=e.error:e instanceof PromiseRejectionEvent&&(t=e.reason),self.postMessage({cmd:re.PROCESSOR_WORKER_ERROR,data:t})}self.addEventListener("error",de),self.addEventListener("unhandledrejection",de);class pe{constructor(e,t){this.port=e,this.options=t,this.getOutput=()=>null}onInit(){}onUninit(){}processFrame(e,t){throw new Error("please implement the processFrame method")}}class Ee{constructor(e,t,i){n(this,"requestFrame",(e=>()=>{this.frameReader.read().then((t=>{let{value:i,done:n}=t;n?(clearTimeout(this.readFrameTimer),this.readFrameTimer=0):(this.updateOutputCanvas(i),this.processFrame(i),this.readFrameTimer=setTimeout(this.requestFrame(e),1e3/e.data.frameRate-4))})).catch((()=>{clearTimeout(this.readFrameTimer),this.readFrameTimer=0}))})),n(this,"frameCallback",(e=>{const t=he.get(this.processorName);t&&t.postMessage({cmd:re.FRAME_CALLBACK,frame:e}),this.port.postMessage({cmd:re.FRAME_CALLBACK,frame:e}),e.close()})),n(this,"callback",((e,t)=>{this.port.postMessage({cmd:e,data:t})})),n(this,"processFrame",(e=>{if(this.processor){var t;const i=t=>{if(t){let t;this.pVideoFrameCount++,e.close(),(this.frameWriter||this.VideoFrameNeeded)&&(t=this.generateVideoFrame(this.outPutCanvas)),this.frameWriter?(this.checkAndCopyBack(this.outPutCanvas),this.frameWriter.write(t).finally((()=>{t.close()}))):this.VideoFrameNeeded&&this.frameCallback(t)}else this.fVideoFrameCount++,this.frameWriter?(this.checkAndCopyBack(e),this.frameWriter.write(e).finally((()=>{e.close()}))):this.VideoFrameNeeded?this.frameCallback(e):e.close()};this.tickInWorker&&(null===this.preVideoWidth?this.preVideoWidth=e.visibleRect.width:this.preVideoWidth!=e.visibleRect.width&&(this.preVideoWidth=e.visibleRect.width,this.port.postMessage({cmd:re.RESOLUTION_CHANGE,data:{width:e.visibleRect.width,height:e.visibleRect.height}}))),this.cVideoFrameCount++;const n=this.processor.processFrame(e,this.outPutCanvas);n.then?null===(t=n.then)||void 0===t||t.call(n,(e=>i(e))):i(n)}else this.frameCallback(e)})),this.outPutCanvas=null,this.frameWriter=null,this.frameReader=null,this.requestFrameInterval=0,this.port=e,this.processor=t,this.processorName=i,this.outputCanvasReady,this.outputPromise=new Promise((e=>{this.outputCanvasReady=e})),this.preVideoWidth=null,this.tickInWorker=!1,this.VideoFrameNeeded=!0,this.pHealthCheckInterval=0,this.cVideoFrameCount=0,this.pVideoFrameCount=0,this.fVideoFrameCount=0}async onMessage(e,t){var i,n,a;switch(e){case re.INIT_OUTPUT_CANVAS:t.canvas?this.outPutCanvas=t.canvas:this.outPutCanvas=new OffscreenCanvas(1,1),this.outPutCanvas.addEventListener("webglcontextlost",(()=>{de("pccl")})),this.outPutCanvas.addEventListener("webglcontextrestored",(()=>{de("pccs")})),null===(i=this.outputCanvasReady)||void 0===i||i.call(this);break;case re.OUTPUT_WRITABLE_STREAM:this.frameWriter=t.writableStream.getWriter();break;case re.INPUT_READABLE_STREAM:this.frameReader=t.readableStream.getReader();break;case re.FRAME_DATA:{this.outPutCanvas||await this.outputPromise;const e=t.frame;if(this.updateOutputCanvas(e),t.captureStream)return void this.processor.processFrame(e,this.outPutCanvas).then((()=>{e.close()}));this.processFrame(e)}break;case re.START_REQUEST_FRAME:this.VideoFrameNeeded=!!t.VideoFrameNeeded,this.tickInWorker=!0,this.frameReader?this.requestFrame({data:t})(this.port):this.requestFrameInterval||(this.requestFrameInterval=setInterval((()=>{this.port.postMessage({cmd:re.REQUEST_FRAME})}),1e3/t.frameRate-4));break;case re.STOP_REQUEST_FRAME:this.tickInWorker=!1,this.requestFrameInterval&&(clearInterval(this.requestFrameInterval),this.requestFrameInterval=0),this.readFrameTimer&&(clearTimeout(this.readFrameTimer),this.readFrameTimer=0),null===(n=this.frameReader)||void 0===n||null===(a=n.cancel)||void 0===a||a.call(n)}}updateOutputCanvas(e){this.outPutCanvas.width!==e.visibleRect.width&&(this.outPutCanvas.width=e.visibleRect.width),this.outPutCanvas.height!==e.visibleRect.height&&(this.outPutCanvas.height=e.visibleRect.height)}checkAndCopyBack(e){if(this.VideoFrameNeeded){const t=this.generateVideoFrame(e);this.frameCallback(t)}}generateVideoFrame(e){return new VideoFrame(e,{timestamp:1e3*performance.now()})}startHealthCheck(){this.pHealthCheckInterval||(this.pHealthCheckInterval=setInterval((()=>{de("VPCFP:".concat(this.cVideoFrameCount,"-").concat(this.fVideoFrameCount,"-").concat(this.pVideoFrameCount))}),1e4))}stopHealthCheck(){clearInterval(this.pHealthCheckInterval),this.pHealthCheckInterval=0}destroy(){var e,t;null===(e=this.frameReader)||void 0===e||e.cancel(),null===(t=this.frameWriter)||void 0===t||t.close()}}const me=new Map;self.addEventListener("message",(function(e){const i=e.data;switch(i.command){case ne.ADD_VIDEO_PROCESSOR:oe||((a=self).registerProcessor=ue,a.VideoProcessor=pe,a.ZoomUtils={RenderEngine:ie,RenderEngineConst:t},oe=!0);try{if(self,importScripts(i.url),i.port.start(),!ce.has(i.name)){const e=le.get(i.name);e&&ce.set(i.name,new e(i.port,i.options))}self.postMessage({cmd:ne.PROCESSOR_READY,name:i.name})}catch(e){console.error(e),self.postMessage({cmd:ne.PROCESSOR_ERROR,name:i.name})}break;case ne.ADD_VIDEO_PORT:(n=i.data).start(),n.addEventListener("message",(e=>{const{cmd:t,processorName:i}=e.data;if(me.get(i)||t===re.UNINIT_PROCESSOR||me.set(i,new Ee(n,ce.get(i),i)),t===re.INIT_PROCESSOR){const e=me.get(i);e.startHealthCheck(),e.outputPromise.then((()=>{var t;ce.get(i).getOutput=()=>e.outPutCanvas,null===(t=ce.get(i))||void 0===t||t.onInit()}))}else if(t===re.UNINIT_PROCESSOR){var a;null===(a=ce.get(i))||void 0===a||a.onUninit();const e=me.get(i);e.stopHealthCheck(),e.destroy(),me.delete(i)}else{var r;i&&(null===(r=me.get(i))||void 0===r||r.onMessage(t,e.data))}}));break;case ne.ADD_SHADOW_PORT:{const e=i.data;e.start(),e.addEventListener("message",(t=>{const{cmd:i,processorName:n}=t.data;i===re.INIT_PROCESSOR?he.set(n,e):i===re.UNINIT_PROCESSOR&&he.delete(n)}))}}var n,a}))})();
//# sourceMappingURL=https://d1cdksi819e9z7.cloudfront.net/sourcemap/video_processor.min.js-98be86e1b51a2183762f.map