Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsmpeglive

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsmpeglive - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.editorconfig

2

dist/jsmpeglive-bundle-min.js

@@ -1,1 +0,1 @@

"use strict";var WebSocketClient=function(t){if(!t)throw new Error("jsmpeglive has not been passed in to the constructor");this.number=0,this.autoReconnectInterval=5e3,this.jsmpeglive=t,this.instance=null};WebSocketClient.prototype.close=function(){this.instance&&this.instance.close&&(this.instance.close(),this.instance.onopen=null,this.instance.onmessage=null,this.instance.onclose=null,this.instance.onerror=null,this.instance=null)},WebSocketClient.prototype.connect=function(t){var e=this;this.url=t,this.instance=new WebSocket(this.url),this.instance.onopen=function(){e.instance.binaryType="arraybuffer",e.instance.onmessage=function(t){e.jsmpeglive.receiveData.bind(e.jsmpeglive,t.data)(),e.number++,e.onmessage(t)},e.onopen()},this.instance.onclose=function(t){switch(t.code){case 1e3:console.log("WebSocket: closed");break;default:e.reconnect.bind(e)(t)}e.onclose(t)},this.instance.onerror=function(t){switch(t.code){case"ECONNREFUSED":e.reconnect.bind(e)(t);break;default:e.onerror(t)}}},WebSocketClient.prototype.send=function(t){try{this.instance.send(t)}catch(t){this.instance.emit("error",t)}},WebSocketClient.prototype.reconnect=function(t){console.log("WebSocketClient: retry in "+this.autoReconnectInterval+"ms",t);var e=this;setTimeout(function(){console.log("WebSocketClient: reconnecting..."),e.connect(e.url)},this.autoReconnectInterval)},WebSocketClient.prototype.onopen=function(){console.log("WebSocketClient: open",arguments)},WebSocketClient.prototype.onerror=function(t){console.log("WebSocketClient: error",arguments)},WebSocketClient.prototype.onmessage=function(t){console.log("WebSocketClient: message")},WebSocketClient.prototype.onclose=function(t){console.log("WebSocketClient: closed",arguments)},function(t){function e(t){return new RegExp("^(ws|wss)://","i").test(t)}var r=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}(),i=t.jsmpeglive=function(t,r){if(r=r||{},this.canvas=r.canvas||document.createElement("canvas"),this.externalDecodeCallback=r.ondecodeframe||null,!r.forceCanvas2D&&this.initWebGL()?this.renderFrame=this.renderFrameGL:(this.canvasContext=this.canvas.getContext("2d"),this.renderFrame=this.renderFrame2D),this.transportEngine=null,!e(t))throw new Error("Invalid url. It should be a recognized Transport uri: ws, wss");if(!WebSocketClient)throw new Error("You should include WebSocketSupport to the page");this.blockData=new Int32Array(64),this.zeroBlockData=new Int32Array(64),this.fillArray(this.zeroBlockData,0),this.transportEngine=new WebSocketClient(this),this.transportEngine.onopen=this.init.bind(this),this.transportEngine.connect(t)};i.prototype.init=function(){this.buffer=new S(new ArrayBuffer(this.socketBufferSize)),this.nextPictureBuffer=new S(new ArrayBuffer(this.socketBufferSize)),this.nextPictureBuffer.writePos=0,this.nextPictureBuffer.chunkBegin=0,this.nextPictureBuffer.lastWriteBeforeWrap=0},i.prototype.stop=function(){this.transportEngine&&this.transportEngine.close(),this.canvasContext&&this.canvasContext.clearRect(0,0,this.canvas.width,this.canvas.height)},i.prototype.waitForIntraFrame=!0,i.prototype.socketBufferSize=524288,i.prototype.decodeHeader=function(t){t[0]===o.charCodeAt(0)&&t[1]===o.charCodeAt(1)&&t[2]===o.charCodeAt(2)&&t[3]===o.charCodeAt(3)&&(this.width=256*t[4]+t[5],this.height=256*t[6]+t[7],this.initBuffers())},i.prototype.receiveData=function(t){var e=new Uint8Array(t);this.sequenceStarted||this.decodeHeader(e);var i=this.buffer,o=this.nextPictureBuffer;o.writePos+e.length>o.length&&(o.lastWriteBeforeWrap=o.writePos,o.writePos=0,o.index=0),o.bytes.set(e,o.writePos),o.writePos+=e.length;for(var n;;){if(n=o.findNextMPEGStartCode(),n===S.NOT_FOUND||o.index>>3>o.writePos)return void(o.index=Math.max(o.writePos-3,0)<<3);if(n===x)break}if(this.waitForIntraFrame)return o.advance(10),void(o.getBits(3)===C&&(this.waitForIntraFrame=!1,o.chunkBegin=o.index-13>>3));this.currentPictureDecoded||this.decodePicture(s);var h=o.index>>3;if(h>o.chunkBegin)i.bytes.set(o.bytes.subarray(o.chunkBegin,h)),i.writePos=h-o.chunkBegin;else{i.bytes.set(o.bytes.subarray(o.chunkBegin,o.lastWriteBeforeWrap));var a=o.lastWriteBeforeWrap-o.chunkBegin;i.bytes.set(o.bytes.subarray(0,h),a),i.writePos=h+a}i.index=0,o.chunkBegin=h,this.currentPictureDecoded=!1,r(this.scheduleDecoding.bind(this),this.canvas)},i.prototype.scheduleDecoding=function(){this.decodePicture(),this.currentPictureDecoded=!0},i.prototype.readCode=function(t){var e=0;do e=t[e+this.buffer.getBits(1)];while(e>=0&&0!==t[e]);return t[e+2]},i.prototype.fillArray=function(t,e){for(var r=0,i=t.length;r<i;r++)t[r]=e},i.prototype.pictureRate=30,i.prototype.initBuffers=function(){if(this.intraQuantMatrix=h,this.nonIntraQuantMatrix=a,this.mbWidth=this.width+15>>4,this.mbHeight=this.height+15>>4,this.mbSize=this.mbWidth*this.mbHeight,this.codedWidth=this.mbWidth<<4,this.codedHeight=this.mbHeight<<4,this.codedSize=this.codedWidth*this.codedHeight,this.halfWidth=this.mbWidth<<3,this.halfHeight=this.mbHeight<<3,this.quarterSize=this.codedSize>>2,!this.sequenceStarted){this.sequenceStarted=!0;var e=t.Uint8ClampedArray||t.Uint8Array;t.Uint8ClampedArray||(this.copyBlockToDestination=this.copyBlockToDestinationClamp,this.addBlockToDestination=this.addBlockToDestinationClamp),this.currentY=new e(this.codedSize),this.currentY32=new Uint32Array(this.currentY.buffer),this.currentCr=new e(this.codedSize>>2),this.currentCr32=new Uint32Array(this.currentCr.buffer),this.currentCb=new e(this.codedSize>>2),this.currentCb32=new Uint32Array(this.currentCb.buffer),this.forwardY=new e(this.codedSize),this.forwardY32=new Uint32Array(this.forwardY.buffer),this.forwardCr=new e(this.codedSize>>2),this.forwardCr32=new Uint32Array(this.forwardCr.buffer),this.forwardCb=new e(this.codedSize>>2),this.forwardCb32=new Uint32Array(this.forwardCb.buffer),this.canvas.width=this.width,this.canvas.height=this.height,this.gl?(this.gl.useProgram(this.program),this.gl.viewport(0,0,this.width,this.height)):(this.currentRGBA=this.canvasContext.getImageData(0,0,this.width,this.height),this.fillArray(this.currentRGBA.data,255))}},i.prototype.currentY=null,i.prototype.currentCr=null,i.prototype.currentCb=null,i.prototype.currentRGBA=null,i.prototype.pictureCodingType=0,i.prototype.forwardY=null,i.prototype.forwardCr=null,i.prototype.forwardCb=null,i.prototype.fullPelForward=!1,i.prototype.forwardFCode=0,i.prototype.forwardRSize=0,i.prototype.forwardF=0,i.prototype.currentFrame=-1,i.prototype.currentTime=0,i.prototype.decodePicture=function(t){if(this.currentFrame++,this.currentTime=this.currentFrame/this.pictureRate,this.buffer.advance(10),this.pictureCodingType=this.buffer.getBits(3),this.buffer.advance(16),!(this.pictureCodingType<=0||this.pictureCodingType>=v)){if(this.pictureCodingType===g){if(this.fullPelForward=this.buffer.getBits(1),this.forwardFCode=this.buffer.getBits(3),0===this.forwardFCode)return;this.forwardRSize=this.forwardFCode-1,this.forwardF=1<<this.forwardRSize}var e=0;do e=this.buffer.findNextMPEGStartCode();while(e===A||e===P);for(;e>=T&&e<=k;)this.decodeSlice(255&e),e=this.buffer.findNextMPEGStartCode();if(this.buffer.rewind(32),t!==s&&(this.renderFrame(),this.externalDecodeCallback&&this.externalDecodeCallback(this,this.canvas)),this.pictureCodingType===C||this.pictureCodingType===g){var r=this.forwardY,i=this.forwardY32,o=this.forwardCr,n=this.forwardCr32,h=this.forwardCb,a=this.forwardCb32;this.forwardY=this.currentY,this.forwardY32=this.currentY32,this.forwardCr=this.currentCr,this.forwardCr32=this.currentCr32,this.forwardCb=this.currentCb,this.forwardCb32=this.currentCb32,this.currentY=r,this.currentY32=i,this.currentCr=o,this.currentCr32=n,this.currentCb=h,this.currentCb32=a}}},i.prototype.YCbCrToRGBA=function(){for(var t,e,r,i,o,s=this.currentY,n=this.currentCb,h=this.currentCr,a=this.currentRGBA.data,c=0,d=this.codedWidth,u=this.codedWidth+(this.codedWidth-this.width),f=0,l=this.halfWidth-(this.width>>1),p=0,b=4*this.width,m=4*this.width,w=this.width>>1,y=this.height>>1,C=0;C<y;C++){for(var g=0;g<w;g++){t=n[f],e=h[f],f++,r=e+(103*e>>8)-179,i=(88*t>>8)-44+(183*e>>8)-91,o=t+(198*t>>8)-227;var v=s[c++],T=s[c++];a[p]=v+r,a[p+1]=v-i,a[p+2]=v+o,a[p+4]=T+r,a[p+5]=T-i,a[p+6]=T+o,p+=8;var k=s[d++],x=s[d++];a[b]=k+r,a[b+1]=k-i,a[b+2]=k+o,a[b+4]=x+r,a[b+5]=x-i,a[b+6]=x+o,b+=8}c+=u,d+=u,p+=m,b+=m,f+=l}},i.prototype.renderFrame2D=function(){this.YCbCrToRGBA(),this.canvasContext.putImageData(this.currentRGBA,0,0)},i.prototype.gl=null,i.prototype.program=null,i.prototype.YTexture=null,i.prototype.CBTexture=null,i.prototype.CRTexture=null,i.prototype.createTexture=function(t,e){var r=this.gl,i=r.createTexture();return r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.uniform1i(r.getUniformLocation(this.program,e),t),i},i.prototype.compileShader=function(t,e){var r=this.gl,i=r.createShader(t);if(r.shaderSource(i,e),r.compileShader(i),!r.getShaderParameter(i,r.COMPILE_STATUS))throw new Error(r.getShaderInfoLog(i));return i},i.prototype.initWebGL=function(){var t;try{t=this.gl=this.canvas.getContext("webgl")||this.canvas.getContext("experimental-webgl")}catch(t){return!1}if(!t)return!1;if(this.buffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.buffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,1]),t.STATIC_DRAW),this.program=t.createProgram(),t.attachShader(this.program,this.compileShader(t.VERTEX_SHADER,E)),t.attachShader(this.program,this.compileShader(t.FRAGMENT_SHADER,F)),t.linkProgram(this.program),!t.getProgramParameter(this.program,t.LINK_STATUS))throw new Error(t.getProgramInfoLog(this.program));t.useProgram(this.program),this.YTexture=this.createTexture(0,"YTexture"),this.CBTexture=this.createTexture(1,"CBTexture"),this.CRTexture=this.createTexture(2,"CRTexture");var e=t.getAttribLocation(this.program,"vertex");return t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),this.loadingProgram=t.createProgram(),t.attachShader(this.loadingProgram,this.compileShader(t.VERTEX_SHADER,E)),t.attachShader(this.loadingProgram,this.compileShader(t.FRAGMENT_SHADER,D)),t.linkProgram(this.loadingProgram),t.useProgram(this.loadingProgram),e=t.getAttribLocation(this.loadingProgram,"vertex"),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),!0},i.prototype.renderFrameGL=function(){var t=this.gl,e=new Uint8Array(this.currentY.buffer),r=new Uint8Array(this.currentCr.buffer),i=new Uint8Array(this.currentCb.buffer);t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.YTexture),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,this.codedWidth,this.height,0,t.LUMINANCE,t.UNSIGNED_BYTE,e),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this.CBTexture),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,this.halfWidth,this.height/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,r),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this.CRTexture),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,this.halfWidth,this.height/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,i),t.drawArrays(t.TRIANGLE_STRIP,0,4)},i.prototype.quantizerScale=0,i.prototype.sliceBegin=!1,i.prototype.decodeSlice=function(t){for(this.sliceBegin=!0,this.macroblockAddress=(t-1)*this.mbWidth-1,this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0,this.dcPredictorY=128,this.dcPredictorCr=128,this.dcPredictorCb=128,this.quantizerScale=this.buffer.getBits(5);this.buffer.getBits(1);)this.buffer.advance(8);do this.decodeMacroblock();while(!this.buffer.nextBytesAreStartCode())},i.prototype.macroblockAddress=0,i.prototype.mbRow=0,i.prototype.mbCol=0,i.prototype.macroblockType=0,i.prototype.macroblockIntra=!1,i.prototype.macroblockMotFw=!1,i.prototype.motionFwH=0,i.prototype.motionFwV=0,i.prototype.motionFwHPrev=0,i.prototype.motionFwVPrev=0,i.prototype.decodeMacroblock=function(){for(var t=0,e=this.readCode(d);34===e;)e=this.readCode(d);for(;35===e;)t+=33,e=this.readCode(d);if(t+=e,this.sliceBegin)this.sliceBegin=!1,this.macroblockAddress+=t;else{if(this.macroblockAddress+t>=this.mbSize)return;for(t>1&&(this.dcPredictorY=128,this.dcPredictorCr=128,this.dcPredictorCb=128,this.pictureCodingType===g&&(this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0));t>1;)this.macroblockAddress++,this.mbRow=this.macroblockAddress/this.mbWidth|0,this.mbCol=this.macroblockAddress%this.mbWidth,this.copyMacroblock(this.motionFwH,this.motionFwV,this.forwardY,this.forwardCr,this.forwardCb),t--;this.macroblockAddress++}this.mbRow=this.macroblockAddress/this.mbWidth|0,this.mbCol=this.macroblockAddress%this.mbWidth,this.macroblockType=this.readCode(B[this.pictureCodingType]),this.macroblockIntra=1&this.macroblockType,this.macroblockMotFw=8&this.macroblockType,0!==(16&this.macroblockType)&&(this.quantizerScale=this.buffer.getBits(5)),this.macroblockIntra?(this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0):(this.dcPredictorY=128,this.dcPredictorCr=128,this.dcPredictorCb=128,this.decodeMotionVectors(),this.copyMacroblock(this.motionFwH,this.motionFwV,this.forwardY,this.forwardCr,this.forwardCb));for(var r=0!==(2&this.macroblockType)?this.readCode(p):this.macroblockIntra?63:0,i=0,o=32;i<6;i++)0!==(r&o)&&this.decodeBlock(i),o>>=1},i.prototype.decodeMotionVectors=function(){var t,e,r=0;this.macroblockMotFw?(t=this.readCode(b),0!==t&&1!==this.forwardF?(r=this.buffer.getBits(this.forwardRSize),e=(Math.abs(t)-1<<this.forwardRSize)+r+1,t<0&&(e=-e)):e=t,this.motionFwHPrev+=e,this.motionFwHPrev>(this.forwardF<<4)-1?this.motionFwHPrev-=this.forwardF<<5:this.motionFwHPrev<-this.forwardF<<4&&(this.motionFwHPrev+=this.forwardF<<5),this.motionFwH=this.motionFwHPrev,this.fullPelForward&&(this.motionFwH<<=1),t=this.readCode(b),0!==t&&1!==this.forwardF?(r=this.buffer.getBits(this.forwardRSize),e=(Math.abs(t)-1<<this.forwardRSize)+r+1,t<0&&(e=-e)):e=t,this.motionFwVPrev+=e,this.motionFwVPrev>(this.forwardF<<4)-1?this.motionFwVPrev-=this.forwardF<<5:this.motionFwVPrev<-this.forwardF<<4&&(this.motionFwVPrev+=this.forwardF<<5),this.motionFwV=this.motionFwVPrev,this.fullPelForward&&(this.motionFwV<<=1)):this.pictureCodingType===g&&(this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0)},i.prototype.copyMacroblock=function(t,e,r,i,o){var s,n,h,a,c,d,u,f,l,p=this.currentY32,b=this.currentCb32,m=this.currentCr32;s=this.codedWidth,n=s-16,h=t>>1,a=e>>1,c=1===(1&t),d=1===(1&e),u=((this.mbRow<<4)+a)*s+(this.mbCol<<4)+h,f=this.mbRow*s+this.mbCol<<2,l=f+(s<<2);var w,y,C,g;if(c)if(d)for(;f<l;){for(y=r[u]+r[u+s],u++,w=0;w<4;w++)C=r[u]+r[u+s],u++,g=y+C+2>>2&255,y=r[u]+r[u+s],u++,g|=y+C+2<<6&65280,C=r[u]+r[u+s],u++,g|=y+C+2<<14&16711680,y=r[u]+r[u+s],u++,g|=y+C+2<<22&4278190080,p[f++]=g;f+=n>>2,u+=n-1}else for(;f<l;){for(y=r[u++],w=0;w<4;w++)C=r[u++],g=y+C+1>>1&255,y=r[u++],g|=y+C+1<<7&65280,C=r[u++],g|=y+C+1<<15&16711680,y=r[u++],g|=y+C+1<<23&4278190080,p[f++]=g;f+=n>>2,u+=n-1}else if(d)for(;f<l;){for(w=0;w<4;w++)g=r[u]+r[u+s]+1>>1&255,u++,g|=r[u]+r[u+s]+1<<7&65280,u++,g|=r[u]+r[u+s]+1<<15&16711680,u++,g|=r[u]+r[u+s]+1<<23&4278190080,u++,p[f++]=g;f+=n>>2,u+=n}else for(;f<l;){for(w=0;w<4;w++)g=r[u],u++,g|=r[u]<<8,u++,g|=r[u]<<16,u++,g|=r[u]<<24,u++,p[f++]=g;f+=n>>2,u+=n}s=this.halfWidth,n=s-8,h=t/2>>1,a=e/2>>1,c=1===(t/2&1),d=1===(e/2&1),u=((this.mbRow<<3)+a)*s+(this.mbCol<<3)+h,f=this.mbRow*s+this.mbCol<<1,l=f+(s<<1);var v,T,k,x,A,P;if(c)if(d)for(;f<l;){for(v=i[u]+i[u+s],x=o[u]+o[u+s],u++,w=0;w<2;w++)T=i[u]+i[u+s],A=o[u]+o[u+s],u++,k=v+T+2>>2&255,P=x+A+2>>2&255,v=i[u]+i[u+s],x=o[u]+o[u+s],u++,k|=v+T+2<<6&65280,P|=x+A+2<<6&65280,T=i[u]+i[u+s],A=o[u]+o[u+s],u++,k|=v+T+2<<14&16711680,P|=x+A+2<<14&16711680,v=i[u]+i[u+s],x=o[u]+o[u+s],u++,k|=v+T+2<<22&4278190080,P|=x+A+2<<22&4278190080,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n-1}else for(;f<l;){for(v=i[u],x=o[u],u++,w=0;w<2;w++)T=i[u],A=o[u++],k=v+T+1>>1&255,P=x+A+1>>1&255,v=i[u],x=o[u++],k|=v+T+1<<7&65280,P|=x+A+1<<7&65280,T=i[u],A=o[u++],k|=v+T+1<<15&16711680,P|=x+A+1<<15&16711680,v=i[u],x=o[u++],k|=v+T+1<<23&4278190080,P|=x+A+1<<23&4278190080,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n-1}else if(d)for(;f<l;){for(w=0;w<2;w++)k=i[u]+i[u+s]+1>>1&255,P=o[u]+o[u+s]+1>>1&255,u++,k|=i[u]+i[u+s]+1<<7&65280,P|=o[u]+o[u+s]+1<<7&65280,u++,k|=i[u]+i[u+s]+1<<15&16711680,P|=o[u]+o[u+s]+1<<15&16711680,u++,k|=i[u]+i[u+s]+1<<23&4278190080,P|=o[u]+o[u+s]+1<<23&4278190080,u++,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n}else for(;f<l;){for(w=0;w<2;w++)k=i[u],P=o[u],u++,k|=i[u]<<8,P|=o[u]<<8,u++,k|=i[u]<<16,P|=o[u]<<16,u++,k|=i[u]<<24,P|=o[u]<<24,u++,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n}},i.prototype.blockData=null,i.prototype.decodeBlock=function(t){var e,r=0;if(this.macroblockIntra){var i,o;if(t<4?(i=this.dcPredictorY,o=this.readCode(m)):(i=4===t?this.dcPredictorCr:this.dcPredictorCb,o=this.readCode(w)),o>0){var s=this.buffer.getBits(o);0!==(s&1<<o-1)?this.blockData[0]=i+s:this.blockData[0]=i+(-1<<o|s+1)}else this.blockData[0]=i;t<4?this.dcPredictorY=this.blockData[0]:4===t?this.dcPredictorCr=this.blockData[0]:this.dcPredictorCb=this.blockData[0],this.blockData[0]<<=8,e=this.intraQuantMatrix,r=1}else e=this.nonIntraQuantMatrix;for(var h=0;;){var a=0,d=this.readCode(y);if(1===d&&r>0&&0===this.buffer.getBits(1))break;65535===d?(a=this.buffer.getBits(6),h=this.buffer.getBits(8),0===h?h=this.buffer.getBits(8):128===h?h=this.buffer.getBits(8)-256:h>128&&(h-=256)):(a=d>>8,h=255&d,this.buffer.getBits(1)&&(h=-h)),r+=a;var u=n[r];r++,h<<=1,this.macroblockIntra||(h+=h<0?-1:1),h=h*this.quantizerScale*e[u]>>4,0===(1&h)&&(h-=h>0?1:-1),h>2047?h=2047:h<-2048&&(h=-2048),this.blockData[u]=h*c[u]}var f,l,p;t<4?(f=this.currentY,p=this.codedWidth-8,l=this.mbRow*this.codedWidth+this.mbCol<<4,0!==(1&t)&&(l+=8),0!==(2&t)&&(l+=this.codedWidth<<3)):(f=4===t?this.currentCb:this.currentCr,p=(this.codedWidth>>1)-8,l=(this.mbRow*this.codedWidth<<2)+(this.mbCol<<3)),this.macroblockIntra?1===r?(this.copyValueToDestination(this.blockData[0]+128>>8,f,l,p),this.blockData[0]=0):(this.IDCT(),this.copyBlockToDestination(this.blockData,f,l,p),this.blockData.set(this.zeroBlockData)):1===r?(this.addValueToDestination(this.blockData[0]+128>>8,f,l,p),this.blockData[0]=0):(this.IDCT(),this.addBlockToDestination(this.blockData,f,l,p),this.blockData.set(this.zeroBlockData)),r=0},i.prototype.copyBlockToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]=t[o],e[r+1]=t[o+1],e[r+2]=t[o+2],e[r+3]=t[o+3],e[r+4]=t[o+4],e[r+5]=t[o+5],e[r+6]=t[o+6],e[r+7]=t[o+7]},i.prototype.addBlockToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]+=t[o],e[r+1]+=t[o+1],e[r+2]+=t[o+2],e[r+3]+=t[o+3],e[r+4]+=t[o+4],e[r+5]+=t[o+5],e[r+6]+=t[o+6],e[r+7]+=t[o+7]},i.prototype.copyValueToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]=t,e[r+1]=t,e[r+2]=t,e[r+3]=t,e[r+4]=t,e[r+5]=t,e[r+6]=t,e[r+7]=t},i.prototype.addValueToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]+=t,e[r+1]+=t,e[r+2]+=t,e[r+3]+=t,e[r+4]+=t,e[r+5]+=t,e[r+6]+=t,e[r+7]+=t},i.prototype.copyBlockToDestinationClamp=function(t,e,r,i){for(var o=0,s=0;s<8;s++){for(var n=0;n<8;n++){var h=t[o++];e[r++]=h>255?255:h<0?0:h}r+=i}},i.prototype.addBlockToDestinationClamp=function(t,e,r,i){for(var o=0,s=0;s<8;s++){for(var n=0;n<8;n++){var h=t[o++]+e[r];e[r++]=h>255?255:h<0?0:h}r+=i}},i.prototype.IDCT=function(){var t,e,r,i,o,s,n,h,a,c,d,u,f,l,p,b,m,w,y,C=this.blockData;for(y=0;y<8;++y)t=C[32+y],e=C[16+y]+C[48+y],r=C[40+y]-C[24+y],s=C[8+y]+C[56+y],n=C[24+y]+C[40+y],i=C[8+y]-C[56+y],o=s+n,h=C[y],f=(473*i-196*r+128>>8)-o,a=f-(362*(s-n)+128>>8),c=h-t,d=(362*(C[16+y]-C[48+y])+128>>8)-e,u=h+t,l=c+d,p=u+e,b=c-d,m=u-e,w=-a-(473*r+196*i+128>>8),C[y]=o+p,C[8+y]=f+l,C[16+y]=b-a,C[24+y]=m-w,C[32+y]=m+w,C[40+y]=a+b,C[48+y]=l-f,C[56+y]=p-o;for(y=0;y<64;y+=8)t=C[4+y],e=C[2+y]+C[6+y],r=C[5+y]-C[3+y],s=C[1+y]+C[7+y],n=C[3+y]+C[5+y],i=C[1+y]-C[7+y],o=s+n,h=C[y],f=(473*i-196*r+128>>8)-o,a=f-(362*(s-n)+128>>8),c=h-t,d=(362*(C[2+y]-C[6+y])+128>>8)-e,u=h+t,l=c+d,p=u+e,b=c-d,m=u-e,w=-a-(473*r+196*i+128>>8),C[y]=o+p+128>>8,C[1+y]=f+l+128>>8,C[2+y]=b-a+128>>8,C[3+y]=m-w+128>>8,C[4+y]=m+w+128>>8,C[5+y]=a+b+128>>8,C[6+y]=l-f+128>>8,C[7+y]=p-o+128>>8};var o="jsmp",s=1,n=new Uint8Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),h=new Uint8Array([8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27,29,32,35,40,48,26,27,29,32,35,40,48,58,26,27,29,34,38,46,56,69,27,29,35,38,46,56,69,83]),a=new Uint8Array([16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]),c=new Uint8Array([32,44,42,38,32,25,17,9,44,62,58,52,44,35,24,12,42,58,55,49,42,33,23,12,38,52,49,44,38,30,20,10,32,44,42,38,32,25,17,9,25,35,33,30,25,20,14,7,17,24,23,20,17,14,9,5,9,12,12,10,9,7,5,2]),d=new Int16Array([3,6,0,9,12,0,0,0,1,15,18,0,21,24,0,27,30,0,33,36,0,0,0,3,0,0,2,39,42,0,45,48,0,0,0,5,0,0,4,51,54,0,57,60,0,0,0,7,0,0,6,63,66,0,69,72,0,75,78,0,81,84,0,-1,87,0,-1,90,0,93,96,0,99,102,0,105,108,0,111,114,0,0,0,9,0,0,8,117,120,0,123,126,0,129,132,0,135,138,0,0,0,15,0,0,14,0,0,13,0,0,12,0,0,11,0,0,10,141,-1,0,-1,144,0,147,150,0,153,156,0,159,162,0,165,168,0,171,174,0,177,180,0,183,-1,0,-1,186,0,189,192,0,195,198,0,201,204,0,207,210,0,213,216,0,219,222,0,0,0,21,0,0,20,0,0,19,0,0,18,0,0,17,0,0,16,0,0,35,0,0,34,0,0,33,0,0,32,0,0,31,0,0,30,0,0,29,0,0,28,0,0,27,0,0,26,0,0,25,0,0,24,0,0,23,0,0,22]),u=new Int8Array([3,6,0,-1,9,0,0,0,1,0,0,17]),f=new Int8Array([3,6,0,9,12,0,0,0,10,15,18,0,0,0,2,21,24,0,0,0,8,27,30,0,33,36,0,-1,39,0,0,0,18,0,0,26,0,0,1,0,0,17]),l=new Int8Array([3,6,0,9,15,0,12,18,0,24,21,0,0,0,12,27,30,0,0,0,14,39,42,0,36,33,0,0,0,4,0,0,6,54,48,0,45,51,0,0,0,8,0,0,10,-1,57,0,0,0,1,60,63,0,0,0,30,0,0,17,0,0,22,0,0,26]),p=new Int16Array([6,3,0,9,18,0,12,15,0,24,33,0,36,39,0,27,21,0,30,42,0,60,57,0,54,48,0,69,51,0,81,75,0,63,84,0,45,66,0,72,78,0,0,0,60,105,120,0,132,144,0,114,108,0,126,141,0,87,93,0,117,96,0,0,0,32,135,138,0,99,123,0,129,102,0,0,0,4,90,111,0,0,0,8,0,0,16,0,0,44,150,168,0,0,0,28,0,0,52,0,0,62,183,177,0,156,180,0,0,0,1,165,162,0,0,0,61,0,0,56,171,174,0,0,0,2,0,0,40,153,186,0,0,0,48,192,189,0,147,159,0,0,0,20,0,0,12,240,249,0,0,0,63,231,225,0,195,219,0,252,198,0,0,0,24,0,0,36,0,0,3,207,261,0,243,237,0,204,213,0,210,234,0,201,228,0,216,222,0,258,255,0,264,246,0,-1,282,0,285,291,0,0,0,33,0,0,9,318,330,0,306,348,0,0,0,5,0,0,10,279,267,0,0,0,6,0,0,18,0,0,17,0,0,34,339,357,0,309,312,0,270,276,0,327,321,0,351,354,0,303,297,0,294,288,0,300,273,0,342,345,0,315,324,0,336,333,0,363,375,0,0,0,41,0,0,14,0,0,21,372,366,0,360,369,0,0,0,11,0,0,19,0,0,7,0,0,35,0,0,13,0,0,50,0,0,49,0,0,58,0,0,37,0,0,25,0,0,45,0,0,57,0,0,26,0,0,29,0,0,38,0,0,53,0,0,23,0,0,43,0,0,46,0,0,42,0,0,22,0,0,54,0,0,51,0,0,15,0,0,30,0,0,39,0,0,47,0,0,55,0,0,27,0,0,59,0,0,31]),b=new Int16Array([3,6,0,12,9,0,0,0,0,18,15,0,24,21,0,0,0,-1,0,0,1,27,30,0,36,33,0,0,0,2,0,0,-2,42,45,0,48,39,0,60,54,0,0,0,3,0,0,-3,51,57,0,-1,69,0,81,75,0,78,63,0,72,66,0,96,84,0,87,93,0,-1,99,0,108,105,0,0,0,-4,90,102,0,0,0,4,0,0,-7,0,0,5,111,123,0,0,0,-5,0,0,7,114,120,0,126,117,0,0,0,-6,0,0,6,153,162,0,150,147,0,135,138,0,156,141,0,129,159,0,132,144,0,0,0,10,0,0,9,0,0,8,0,0,-8,171,198,0,0,0,-9,180,192,0,168,183,0,165,186,0,174,189,0,0,0,-10,177,195,0,0,0,12,0,0,16,0,0,13,0,0,14,0,0,11,0,0,15,0,0,-16,0,0,-12,0,0,-14,0,0,-15,0,0,-11,0,0,-13]),m=new Int8Array([6,3,0,18,15,0,9,12,0,0,0,1,0,0,2,27,24,0,21,30,0,0,0,0,36,33,0,0,0,4,0,0,3,39,42,0,0,0,5,0,0,6,48,45,0,51,-1,0,0,0,7,0,0,8]),w=new Int8Array([6,3,0,12,9,0,18,15,0,24,21,0,0,0,2,0,0,1,0,0,0,30,27,0,0,0,3,36,33,0,0,0,4,42,39,0,0,0,5,48,45,0,0,0,6,51,-1,0,0,0,7,0,0,8]),y=new Int32Array([3,6,0,12,9,0,0,0,1,21,24,0,18,15,0,39,27,0,33,30,0,42,36,0,0,0,257,60,66,0,54,63,0,48,57,0,0,0,513,51,45,0,0,0,2,0,0,3,81,75,0,87,93,0,72,78,0,96,90,0,0,0,1025,69,84,0,0,0,769,0,0,258,0,0,1793,0,0,65535,0,0,1537,111,108,0,0,0,1281,105,102,0,117,114,0,99,126,0,120,123,0,156,150,0,162,159,0,144,147,0,129,135,0,138,132,0,0,0,2049,0,0,4,0,0,514,0,0,2305,153,141,0,165,171,0,180,168,0,177,174,0,183,186,0,0,0,2561,0,0,3329,0,0,6,0,0,259,0,0,5,0,0,770,0,0,2817,0,0,3073,228,225,0,201,210,0,219,213,0,234,222,0,216,231,0,207,192,0,204,189,0,198,195,0,243,261,0,273,240,0,246,237,0,249,258,0,279,276,0,252,255,0,270,282,0,264,267,0,0,0,515,0,0,260,0,0,7,0,0,1026,0,0,1282,0,0,4097,0,0,3841,0,0,3585,315,321,0,333,342,0,312,291,0,375,357,0,288,294,0,-1,369,0,285,303,0,318,363,0,297,306,0,339,309,0,336,348,0,330,300,0,372,345,0,351,366,0,327,354,0,360,324,0,381,408,0,417,420,0,390,378,0,435,438,0,384,387,0,0,0,2050,396,402,0,465,462,0,0,0,8,411,399,0,429,432,0,453,414,0,426,423,0,0,0,10,0,0,9,0,0,11,0,0,5377,0,0,1538,0,0,771,0,0,5121,0,0,1794,0,0,4353,0,0,4609,0,0,4865,444,456,0,0,0,1027,459,450,0,0,0,261,393,405,0,0,0,516,447,441,0,516,519,0,486,474,0,510,483,0,504,498,0,471,537,0,507,501,0,522,513,0,534,531,0,468,477,0,492,495,0,549,546,0,525,528,0,0,0,263,0,0,2562,0,0,2306,0,0,5633,0,0,5889,0,0,6401,0,0,6145,0,0,1283,0,0,772,0,0,13,0,0,12,0,0,14,0,0,15,0,0,517,0,0,6657,0,0,262,540,543,0,480,489,0,588,597,0,0,0,27,609,555,0,606,603,0,0,0,19,0,0,22,591,621,0,0,0,18,573,576,0,564,570,0,0,0,20,552,582,0,0,0,21,558,579,0,0,0,23,612,594,0,0,0,25,0,0,24,600,615,0,0,0,31,0,0,30,0,0,28,0,0,29,0,0,26,0,0,17,0,0,16,567,618,0,561,585,0,654,633,0,0,0,37,645,648,0,0,0,36,630,636,0,0,0,34,639,627,0,663,666,0,657,624,0,651,642,0,669,660,0,0,0,35,0,0,267,0,0,40,0,0,268,0,0,266,0,0,32,0,0,264,0,0,265,0,0,38,0,0,269,0,0,270,0,0,33,0,0,39,0,0,7937,0,0,6913,0,0,7681,0,0,4098,0,0,7425,0,0,7169,0,0,271,0,0,274,0,0,273,0,0,272,0,0,1539,0,0,2818,0,0,3586,0,0,3330,0,0,3074,0,0,3842]),C=1,g=2,v=3,T=1,k=175,x=0,A=181,P=178,F=["precision mediump float;","uniform sampler2D YTexture;","uniform sampler2D CBTexture;","uniform sampler2D CRTexture;","varying vec2 texCoord;","void main() {","float y = texture2D(YTexture, texCoord).r;","float cr = texture2D(CBTexture, texCoord).r - 0.5;","float cb = texture2D(CRTexture, texCoord).r - 0.5;","gl_FragColor = vec4(","y + 1.4 * cr,","y + -0.343 * cb - 0.711 * cr,","y + 1.765 * cb,","1.0",");","}"].join("\n"),D=["precision mediump float;","uniform float loaded;","varying vec2 texCoord;","void main() {","float c = ceil(loaded-(1.0-texCoord.y));","gl_FragColor = vec4(c,c,c,1);","}"].join("\n"),E=["attribute vec2 vertex;","varying vec2 texCoord;","void main() {","texCoord = vertex;","gl_Position = vec4((vertex * 2.0 - 1.0) * vec2(1, -1), 0.0, 1.0);","}"].join("\n"),B=[null,u,f,l],S=function(t){this.bytes=new Uint8Array(t),this.length=this.bytes.length,this.writePos=this.bytes.length,this.index=0};S.NOT_FOUND=-1,S.prototype.findNextMPEGStartCode=function(){for(var t=this.index+7>>3;t<this.writePos;t++)if(0===this.bytes[t]&&0===this.bytes[t+1]&&1===this.bytes[t+2])return this.index=t+4<<3,this.bytes[t+3];return this.index=this.writePos<<3,S.NOT_FOUND},S.prototype.nextBytesAreStartCode=function(){var t=this.index+7>>3;return t>=this.writePos||0===this.bytes[t]&&0===this.bytes[t+1]&&1===this.bytes[t+2]},S.prototype.nextBits=function(t){var e=this.index>>3,r=8-this.index%8;if(r>=t)return this.bytes[e]>>r-t&255>>8-t;var i=(this.index+t)%8,o=this.index+t-1>>3,s=this.bytes[e]&255>>8-r;for(e++;e<o;e++)s<<=8,s|=this.bytes[e];return i>0?(s<<=i,s|=this.bytes[e]>>8-i):(s<<=8,s|=this.bytes[e]),s},S.prototype.getBits=function(t){var e=this.nextBits(t);return this.index+=t,e},S.prototype.advance=function(t){return this.index+=t},S.prototype.rewind=function(t){return this.index-=t}}(window);
"use strict";var WebSocketClient=function(t){if(!t)throw new Error("jsmpeglive has not been passed in to the constructor");this.number=0,this.attempts=1,this.jsmpeglive=t,this.instance=null};WebSocketClient.prototype.close=function(){this.instance&&this.instance.close&&(this.instance.close(),this.instance.onopen=null,this.instance.onmessage=null,this.instance.onclose=null,this.instance.onerror=null,this.instance=null)},WebSocketClient.prototype.connect=function(t){var e=this;this.url=t,this.instance=new WebSocket(this.url),this.instance.onopen=function(){e.attempts=1,e.instance.binaryType="arraybuffer",e.instance.onmessage=function(t){console.debug("onmessage"),e.jsmpeglive.receiveData.bind(e.jsmpeglive,t.data)(),e.number++,e.onmessage(t)},e.onopen()},this.instance.onclose=function(t){switch(t.code){case 1e3:console.debug("WebSocket: closed");break;default:e.reconnect.bind(e)(t)}e.onclose(t)},this.instance.onerror=function(t){switch(t.code){case"ECONNREFUSED":e.reconnect.bind(e)(t);break;default:e.onerror(t)}}},WebSocketClient.prototype.send=function(t){try{this.instance.send(t)}catch(t){this.instance.emit("error",t)}},WebSocketClient.prototype.reconnect=function(t){function e(t){return 1e3*Math.min(30,Math.pow(2,t)-1)}var r=this,i=e(r.attempts);console.debug("WebSocketClient: retry in "+i+"ms",t),setTimeout(function(){r.attempts++,console.debug("WebSocketClient: reconnecting..."+r.attempts),r.connect(r.url)},i)},WebSocketClient.prototype.onopen=function(){console.debug("WebSocketClient: open",arguments)},WebSocketClient.prototype.onerror=function(t){console.debug("WebSocketClient: error",t)},WebSocketClient.prototype.onmessage=function(t){console.debug("WebSocketClient: message",t.data.length)},WebSocketClient.prototype.onclose=function(t){console.debug("WebSocketClient: closed",t.code)},function(t){function e(t){return new RegExp("^(ws|wss)://","i").test(t)}var r=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(e){t.setTimeout(e,1e3/60)}}(),i=t.jsmpeglive=function(t,r){if(r=r||{},this.canvas=r.canvas||document.createElement("canvas"),this.externalDecodeCallback=r.ondecodeframe||null,!r.forceCanvas2D&&this.initWebGL()?this.renderFrame=this.renderFrameGL:(this.canvasContext=this.canvas.getContext("2d"),this.renderFrame=this.renderFrame2D),this.transportEngine=null,!e(t))throw new Error("Invalid url. It should be a recognized Transport uri: ws, wss");if(!WebSocketClient)throw new Error("You should include WebSocketSupport to the page");this.blockData=new Int32Array(64),this.zeroBlockData=new Int32Array(64),this.fillArray(this.zeroBlockData,0),this.transportEngine=new WebSocketClient(this),this.transportEngine.onopen=this.init.bind(this),this.transportEngine.connect(t)};i.prototype.init=function(){this.buffer=new S(new ArrayBuffer(this.socketBufferSize)),this.nextPictureBuffer=new S(new ArrayBuffer(this.socketBufferSize)),this.nextPictureBuffer.writePos=0,this.nextPictureBuffer.chunkBegin=0,this.nextPictureBuffer.lastWriteBeforeWrap=0},i.prototype.stop=function(){this.transportEngine&&this.transportEngine.close(),this.canvasContext&&this.canvasContext.clearRect(0,0,this.canvas.width,this.canvas.height)},i.prototype.waitForIntraFrame=!0,i.prototype.socketBufferSize=524288,i.prototype.decodeHeader=function(t){t[0]===o.charCodeAt(0)&&t[1]===o.charCodeAt(1)&&t[2]===o.charCodeAt(2)&&t[3]===o.charCodeAt(3)&&(this.width=256*t[4]+t[5],this.height=256*t[6]+t[7],this.initBuffers())},i.prototype.receiveData=function(t){var e=new Uint8Array(t);this.sequenceStarted||this.decodeHeader(e);var i=this.buffer,o=this.nextPictureBuffer;o.writePos+e.length>o.length&&(o.lastWriteBeforeWrap=o.writePos,o.writePos=0,o.index=0),o.bytes.set(e,o.writePos),o.writePos+=e.length;for(var n;;){if(n=o.findNextMPEGStartCode(),n===S.NOT_FOUND||o.index>>3>o.writePos)return void(o.index=Math.max(o.writePos-3,0)<<3);if(n===x)break}if(this.waitForIntraFrame)return o.advance(10),void(o.getBits(3)===C&&(this.waitForIntraFrame=!1,o.chunkBegin=o.index-13>>3));this.currentPictureDecoded||this.decodePicture(s);var h=o.index>>3;if(h>o.chunkBegin)i.bytes.set(o.bytes.subarray(o.chunkBegin,h)),i.writePos=h-o.chunkBegin;else{i.bytes.set(o.bytes.subarray(o.chunkBegin,o.lastWriteBeforeWrap));var a=o.lastWriteBeforeWrap-o.chunkBegin;i.bytes.set(o.bytes.subarray(0,h),a),i.writePos=h+a}i.index=0,o.chunkBegin=h,this.currentPictureDecoded=!1,r(this.scheduleDecoding.bind(this),this.canvas)},i.prototype.scheduleDecoding=function(){this.decodePicture(),this.currentPictureDecoded=!0},i.prototype.readCode=function(t){var e=0;do e=t[e+this.buffer.getBits(1)];while(e>=0&&0!==t[e]);return t[e+2]},i.prototype.fillArray=function(t,e){for(var r=0,i=t.length;r<i;r++)t[r]=e},i.prototype.pictureRate=30,i.prototype.initBuffers=function(){if(this.intraQuantMatrix=h,this.nonIntraQuantMatrix=a,this.mbWidth=this.width+15>>4,this.mbHeight=this.height+15>>4,this.mbSize=this.mbWidth*this.mbHeight,this.codedWidth=this.mbWidth<<4,this.codedHeight=this.mbHeight<<4,this.codedSize=this.codedWidth*this.codedHeight,this.halfWidth=this.mbWidth<<3,this.halfHeight=this.mbHeight<<3,this.quarterSize=this.codedSize>>2,!this.sequenceStarted){this.sequenceStarted=!0;var e=t.Uint8ClampedArray||t.Uint8Array;t.Uint8ClampedArray||(this.copyBlockToDestination=this.copyBlockToDestinationClamp,this.addBlockToDestination=this.addBlockToDestinationClamp),this.currentY=new e(this.codedSize),this.currentY32=new Uint32Array(this.currentY.buffer),this.currentCr=new e(this.codedSize>>2),this.currentCr32=new Uint32Array(this.currentCr.buffer),this.currentCb=new e(this.codedSize>>2),this.currentCb32=new Uint32Array(this.currentCb.buffer),this.forwardY=new e(this.codedSize),this.forwardY32=new Uint32Array(this.forwardY.buffer),this.forwardCr=new e(this.codedSize>>2),this.forwardCr32=new Uint32Array(this.forwardCr.buffer),this.forwardCb=new e(this.codedSize>>2),this.forwardCb32=new Uint32Array(this.forwardCb.buffer),this.canvas.width=this.width,this.canvas.height=this.height,this.gl?(this.gl.useProgram(this.program),this.gl.viewport(0,0,this.width,this.height)):(this.currentRGBA=this.canvasContext.getImageData(0,0,this.width,this.height),this.fillArray(this.currentRGBA.data,255))}},i.prototype.currentY=null,i.prototype.currentCr=null,i.prototype.currentCb=null,i.prototype.currentRGBA=null,i.prototype.pictureCodingType=0,i.prototype.forwardY=null,i.prototype.forwardCr=null,i.prototype.forwardCb=null,i.prototype.fullPelForward=!1,i.prototype.forwardFCode=0,i.prototype.forwardRSize=0,i.prototype.forwardF=0,i.prototype.currentFrame=-1,i.prototype.currentTime=0,i.prototype.decodePicture=function(t){if(this.currentFrame++,this.currentTime=this.currentFrame/this.pictureRate,this.buffer.advance(10),this.pictureCodingType=this.buffer.getBits(3),this.buffer.advance(16),!(this.pictureCodingType<=0||this.pictureCodingType>=v)){if(this.pictureCodingType===g){if(this.fullPelForward=this.buffer.getBits(1),this.forwardFCode=this.buffer.getBits(3),0===this.forwardFCode)return;this.forwardRSize=this.forwardFCode-1,this.forwardF=1<<this.forwardRSize}var e=0;do e=this.buffer.findNextMPEGStartCode();while(e===A||e===P);for(;e>=T&&e<=k;)this.decodeSlice(255&e),e=this.buffer.findNextMPEGStartCode();if(this.buffer.rewind(32),t!==s&&(this.renderFrame(),this.externalDecodeCallback&&this.externalDecodeCallback(this,this.canvas)),this.pictureCodingType===C||this.pictureCodingType===g){var r=this.forwardY,i=this.forwardY32,o=this.forwardCr,n=this.forwardCr32,h=this.forwardCb,a=this.forwardCb32;this.forwardY=this.currentY,this.forwardY32=this.currentY32,this.forwardCr=this.currentCr,this.forwardCr32=this.currentCr32,this.forwardCb=this.currentCb,this.forwardCb32=this.currentCb32,this.currentY=r,this.currentY32=i,this.currentCr=o,this.currentCr32=n,this.currentCb=h,this.currentCb32=a}}},i.prototype.YCbCrToRGBA=function(){for(var t,e,r,i,o,s=this.currentY,n=this.currentCb,h=this.currentCr,a=this.currentRGBA.data,c=0,d=this.codedWidth,u=this.codedWidth+(this.codedWidth-this.width),f=0,l=this.halfWidth-(this.width>>1),p=0,b=4*this.width,m=4*this.width,w=this.width>>1,y=this.height>>1,C=0;C<y;C++){for(var g=0;g<w;g++){t=n[f],e=h[f],f++,r=e+(103*e>>8)-179,i=(88*t>>8)-44+(183*e>>8)-91,o=t+(198*t>>8)-227;var v=s[c++],T=s[c++];a[p]=v+r,a[p+1]=v-i,a[p+2]=v+o,a[p+4]=T+r,a[p+5]=T-i,a[p+6]=T+o,p+=8;var k=s[d++],x=s[d++];a[b]=k+r,a[b+1]=k-i,a[b+2]=k+o,a[b+4]=x+r,a[b+5]=x-i,a[b+6]=x+o,b+=8}c+=u,d+=u,p+=m,b+=m,f+=l}},i.prototype.renderFrame2D=function(){this.YCbCrToRGBA(),this.canvasContext.putImageData(this.currentRGBA,0,0)},i.prototype.gl=null,i.prototype.program=null,i.prototype.YTexture=null,i.prototype.CBTexture=null,i.prototype.CRTexture=null,i.prototype.createTexture=function(t,e){var r=this.gl,i=r.createTexture();return r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.uniform1i(r.getUniformLocation(this.program,e),t),i},i.prototype.compileShader=function(t,e){var r=this.gl,i=r.createShader(t);if(r.shaderSource(i,e),r.compileShader(i),!r.getShaderParameter(i,r.COMPILE_STATUS))throw new Error(r.getShaderInfoLog(i));return i},i.prototype.initWebGL=function(){var t;try{t=this.gl=this.canvas.getContext("webgl")||this.canvas.getContext("experimental-webgl")}catch(t){return!1}if(!t)return!1;if(this.buffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.buffer),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,1]),t.STATIC_DRAW),this.program=t.createProgram(),t.attachShader(this.program,this.compileShader(t.VERTEX_SHADER,E)),t.attachShader(this.program,this.compileShader(t.FRAGMENT_SHADER,F)),t.linkProgram(this.program),!t.getProgramParameter(this.program,t.LINK_STATUS))throw new Error(t.getProgramInfoLog(this.program));t.useProgram(this.program),this.YTexture=this.createTexture(0,"YTexture"),this.CBTexture=this.createTexture(1,"CBTexture"),this.CRTexture=this.createTexture(2,"CRTexture");var e=t.getAttribLocation(this.program,"vertex");return t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),this.loadingProgram=t.createProgram(),t.attachShader(this.loadingProgram,this.compileShader(t.VERTEX_SHADER,E)),t.attachShader(this.loadingProgram,this.compileShader(t.FRAGMENT_SHADER,D)),t.linkProgram(this.loadingProgram),t.useProgram(this.loadingProgram),e=t.getAttribLocation(this.loadingProgram,"vertex"),t.enableVertexAttribArray(e),t.vertexAttribPointer(e,2,t.FLOAT,!1,0,0),!0},i.prototype.renderFrameGL=function(){var t=this.gl,e=new Uint8Array(this.currentY.buffer),r=new Uint8Array(this.currentCr.buffer),i=new Uint8Array(this.currentCb.buffer);t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.YTexture),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,this.codedWidth,this.height,0,t.LUMINANCE,t.UNSIGNED_BYTE,e),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this.CBTexture),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,this.halfWidth,this.height/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,r),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this.CRTexture),t.texImage2D(t.TEXTURE_2D,0,t.LUMINANCE,this.halfWidth,this.height/2,0,t.LUMINANCE,t.UNSIGNED_BYTE,i),t.drawArrays(t.TRIANGLE_STRIP,0,4)},i.prototype.quantizerScale=0,i.prototype.sliceBegin=!1,i.prototype.decodeSlice=function(t){for(this.sliceBegin=!0,this.macroblockAddress=(t-1)*this.mbWidth-1,this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0,this.dcPredictorY=128,this.dcPredictorCr=128,this.dcPredictorCb=128,this.quantizerScale=this.buffer.getBits(5);this.buffer.getBits(1);)this.buffer.advance(8);do this.decodeMacroblock();while(!this.buffer.nextBytesAreStartCode())},i.prototype.macroblockAddress=0,i.prototype.mbRow=0,i.prototype.mbCol=0,i.prototype.macroblockType=0,i.prototype.macroblockIntra=!1,i.prototype.macroblockMotFw=!1,i.prototype.motionFwH=0,i.prototype.motionFwV=0,i.prototype.motionFwHPrev=0,i.prototype.motionFwVPrev=0,i.prototype.decodeMacroblock=function(){for(var t=0,e=this.readCode(d);34===e;)e=this.readCode(d);for(;35===e;)t+=33,e=this.readCode(d);if(t+=e,this.sliceBegin)this.sliceBegin=!1,this.macroblockAddress+=t;else{if(this.macroblockAddress+t>=this.mbSize)return;for(t>1&&(this.dcPredictorY=128,this.dcPredictorCr=128,this.dcPredictorCb=128,this.pictureCodingType===g&&(this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0));t>1;)this.macroblockAddress++,this.mbRow=this.macroblockAddress/this.mbWidth|0,this.mbCol=this.macroblockAddress%this.mbWidth,this.copyMacroblock(this.motionFwH,this.motionFwV,this.forwardY,this.forwardCr,this.forwardCb),t--;this.macroblockAddress++}this.mbRow=this.macroblockAddress/this.mbWidth|0,this.mbCol=this.macroblockAddress%this.mbWidth,this.macroblockType=this.readCode(B[this.pictureCodingType]),this.macroblockIntra=1&this.macroblockType,this.macroblockMotFw=8&this.macroblockType,0!==(16&this.macroblockType)&&(this.quantizerScale=this.buffer.getBits(5)),this.macroblockIntra?(this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0):(this.dcPredictorY=128,this.dcPredictorCr=128,this.dcPredictorCb=128,this.decodeMotionVectors(),this.copyMacroblock(this.motionFwH,this.motionFwV,this.forwardY,this.forwardCr,this.forwardCb));for(var r=0!==(2&this.macroblockType)?this.readCode(p):this.macroblockIntra?63:0,i=0,o=32;i<6;i++)0!==(r&o)&&this.decodeBlock(i),o>>=1},i.prototype.decodeMotionVectors=function(){var t,e,r=0;this.macroblockMotFw?(t=this.readCode(b),0!==t&&1!==this.forwardF?(r=this.buffer.getBits(this.forwardRSize),e=(Math.abs(t)-1<<this.forwardRSize)+r+1,t<0&&(e=-e)):e=t,this.motionFwHPrev+=e,this.motionFwHPrev>(this.forwardF<<4)-1?this.motionFwHPrev-=this.forwardF<<5:this.motionFwHPrev<-this.forwardF<<4&&(this.motionFwHPrev+=this.forwardF<<5),this.motionFwH=this.motionFwHPrev,this.fullPelForward&&(this.motionFwH<<=1),t=this.readCode(b),0!==t&&1!==this.forwardF?(r=this.buffer.getBits(this.forwardRSize),e=(Math.abs(t)-1<<this.forwardRSize)+r+1,t<0&&(e=-e)):e=t,this.motionFwVPrev+=e,this.motionFwVPrev>(this.forwardF<<4)-1?this.motionFwVPrev-=this.forwardF<<5:this.motionFwVPrev<-this.forwardF<<4&&(this.motionFwVPrev+=this.forwardF<<5),this.motionFwV=this.motionFwVPrev,this.fullPelForward&&(this.motionFwV<<=1)):this.pictureCodingType===g&&(this.motionFwH=this.motionFwHPrev=0,this.motionFwV=this.motionFwVPrev=0)},i.prototype.copyMacroblock=function(t,e,r,i,o){var s,n,h,a,c,d,u,f,l,p=this.currentY32,b=this.currentCb32,m=this.currentCr32;s=this.codedWidth,n=s-16,h=t>>1,a=e>>1,c=1===(1&t),d=1===(1&e),u=((this.mbRow<<4)+a)*s+(this.mbCol<<4)+h,f=this.mbRow*s+this.mbCol<<2,l=f+(s<<2);var w,y,C,g;if(c)if(d)for(;f<l;){for(y=r[u]+r[u+s],u++,w=0;w<4;w++)C=r[u]+r[u+s],u++,g=y+C+2>>2&255,y=r[u]+r[u+s],u++,g|=y+C+2<<6&65280,C=r[u]+r[u+s],u++,g|=y+C+2<<14&16711680,y=r[u]+r[u+s],u++,g|=y+C+2<<22&4278190080,p[f++]=g;f+=n>>2,u+=n-1}else for(;f<l;){for(y=r[u++],w=0;w<4;w++)C=r[u++],g=y+C+1>>1&255,y=r[u++],g|=y+C+1<<7&65280,C=r[u++],g|=y+C+1<<15&16711680,y=r[u++],g|=y+C+1<<23&4278190080,p[f++]=g;f+=n>>2,u+=n-1}else if(d)for(;f<l;){for(w=0;w<4;w++)g=r[u]+r[u+s]+1>>1&255,u++,g|=r[u]+r[u+s]+1<<7&65280,u++,g|=r[u]+r[u+s]+1<<15&16711680,u++,g|=r[u]+r[u+s]+1<<23&4278190080,u++,p[f++]=g;f+=n>>2,u+=n}else for(;f<l;){for(w=0;w<4;w++)g=r[u],u++,g|=r[u]<<8,u++,g|=r[u]<<16,u++,g|=r[u]<<24,u++,p[f++]=g;f+=n>>2,u+=n}s=this.halfWidth,n=s-8,h=t/2>>1,a=e/2>>1,c=1===(t/2&1),d=1===(e/2&1),u=((this.mbRow<<3)+a)*s+(this.mbCol<<3)+h,f=this.mbRow*s+this.mbCol<<1,l=f+(s<<1);var v,T,k,x,A,P;if(c)if(d)for(;f<l;){for(v=i[u]+i[u+s],x=o[u]+o[u+s],u++,w=0;w<2;w++)T=i[u]+i[u+s],A=o[u]+o[u+s],u++,k=v+T+2>>2&255,P=x+A+2>>2&255,v=i[u]+i[u+s],x=o[u]+o[u+s],u++,k|=v+T+2<<6&65280,P|=x+A+2<<6&65280,T=i[u]+i[u+s],A=o[u]+o[u+s],u++,k|=v+T+2<<14&16711680,P|=x+A+2<<14&16711680,v=i[u]+i[u+s],x=o[u]+o[u+s],u++,k|=v+T+2<<22&4278190080,P|=x+A+2<<22&4278190080,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n-1}else for(;f<l;){for(v=i[u],x=o[u],u++,w=0;w<2;w++)T=i[u],A=o[u++],k=v+T+1>>1&255,P=x+A+1>>1&255,v=i[u],x=o[u++],k|=v+T+1<<7&65280,P|=x+A+1<<7&65280,T=i[u],A=o[u++],k|=v+T+1<<15&16711680,P|=x+A+1<<15&16711680,v=i[u],x=o[u++],k|=v+T+1<<23&4278190080,P|=x+A+1<<23&4278190080,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n-1}else if(d)for(;f<l;){for(w=0;w<2;w++)k=i[u]+i[u+s]+1>>1&255,P=o[u]+o[u+s]+1>>1&255,u++,k|=i[u]+i[u+s]+1<<7&65280,P|=o[u]+o[u+s]+1<<7&65280,u++,k|=i[u]+i[u+s]+1<<15&16711680,P|=o[u]+o[u+s]+1<<15&16711680,u++,k|=i[u]+i[u+s]+1<<23&4278190080,P|=o[u]+o[u+s]+1<<23&4278190080,u++,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n}else for(;f<l;){for(w=0;w<2;w++)k=i[u],P=o[u],u++,k|=i[u]<<8,P|=o[u]<<8,u++,k|=i[u]<<16,P|=o[u]<<16,u++,k|=i[u]<<24,P|=o[u]<<24,u++,m[f]=k,b[f]=P,f++;f+=n>>2,u+=n}},i.prototype.blockData=null,i.prototype.decodeBlock=function(t){var e,r=0;if(this.macroblockIntra){var i,o;if(t<4?(i=this.dcPredictorY,o=this.readCode(m)):(i=4===t?this.dcPredictorCr:this.dcPredictorCb,o=this.readCode(w)),o>0){var s=this.buffer.getBits(o);0!==(s&1<<o-1)?this.blockData[0]=i+s:this.blockData[0]=i+(-1<<o|s+1)}else this.blockData[0]=i;t<4?this.dcPredictorY=this.blockData[0]:4===t?this.dcPredictorCr=this.blockData[0]:this.dcPredictorCb=this.blockData[0],this.blockData[0]<<=8,e=this.intraQuantMatrix,r=1}else e=this.nonIntraQuantMatrix;for(var h=0;;){var a=0,d=this.readCode(y);if(1===d&&r>0&&0===this.buffer.getBits(1))break;65535===d?(a=this.buffer.getBits(6),h=this.buffer.getBits(8),0===h?h=this.buffer.getBits(8):128===h?h=this.buffer.getBits(8)-256:h>128&&(h-=256)):(a=d>>8,h=255&d,this.buffer.getBits(1)&&(h=-h)),r+=a;var u=n[r];r++,h<<=1,this.macroblockIntra||(h+=h<0?-1:1),h=h*this.quantizerScale*e[u]>>4,0===(1&h)&&(h-=h>0?1:-1),h>2047?h=2047:h<-2048&&(h=-2048),this.blockData[u]=h*c[u]}var f,l,p;t<4?(f=this.currentY,p=this.codedWidth-8,l=this.mbRow*this.codedWidth+this.mbCol<<4,0!==(1&t)&&(l+=8),0!==(2&t)&&(l+=this.codedWidth<<3)):(f=4===t?this.currentCb:this.currentCr,p=(this.codedWidth>>1)-8,l=(this.mbRow*this.codedWidth<<2)+(this.mbCol<<3)),this.macroblockIntra?1===r?(this.copyValueToDestination(this.blockData[0]+128>>8,f,l,p),this.blockData[0]=0):(this.IDCT(),this.copyBlockToDestination(this.blockData,f,l,p),this.blockData.set(this.zeroBlockData)):1===r?(this.addValueToDestination(this.blockData[0]+128>>8,f,l,p),this.blockData[0]=0):(this.IDCT(),this.addBlockToDestination(this.blockData,f,l,p),this.blockData.set(this.zeroBlockData)),r=0},i.prototype.copyBlockToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]=t[o],e[r+1]=t[o+1],e[r+2]=t[o+2],e[r+3]=t[o+3],e[r+4]=t[o+4],e[r+5]=t[o+5],e[r+6]=t[o+6],e[r+7]=t[o+7]},i.prototype.addBlockToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]+=t[o],e[r+1]+=t[o+1],e[r+2]+=t[o+2],e[r+3]+=t[o+3],e[r+4]+=t[o+4],e[r+5]+=t[o+5],e[r+6]+=t[o+6],e[r+7]+=t[o+7]},i.prototype.copyValueToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]=t,e[r+1]=t,e[r+2]=t,e[r+3]=t,e[r+4]=t,e[r+5]=t,e[r+6]=t,e[r+7]=t},i.prototype.addValueToDestination=function(t,e,r,i){for(var o=0;o<64;o+=8,r+=i+8)e[r+0]+=t,e[r+1]+=t,e[r+2]+=t,e[r+3]+=t,e[r+4]+=t,e[r+5]+=t,e[r+6]+=t,e[r+7]+=t},i.prototype.copyBlockToDestinationClamp=function(t,e,r,i){for(var o=0,s=0;s<8;s++){for(var n=0;n<8;n++){var h=t[o++];e[r++]=h>255?255:h<0?0:h}r+=i}},i.prototype.addBlockToDestinationClamp=function(t,e,r,i){for(var o=0,s=0;s<8;s++){for(var n=0;n<8;n++){var h=t[o++]+e[r];e[r++]=h>255?255:h<0?0:h}r+=i}},i.prototype.IDCT=function(){var t,e,r,i,o,s,n,h,a,c,d,u,f,l,p,b,m,w,y,C=this.blockData;for(y=0;y<8;++y)t=C[32+y],e=C[16+y]+C[48+y],r=C[40+y]-C[24+y],s=C[8+y]+C[56+y],n=C[24+y]+C[40+y],i=C[8+y]-C[56+y],o=s+n,h=C[y],f=(473*i-196*r+128>>8)-o,a=f-(362*(s-n)+128>>8),c=h-t,d=(362*(C[16+y]-C[48+y])+128>>8)-e,u=h+t,l=c+d,p=u+e,b=c-d,m=u-e,w=-a-(473*r+196*i+128>>8),C[y]=o+p,C[8+y]=f+l,C[16+y]=b-a,C[24+y]=m-w,C[32+y]=m+w,C[40+y]=a+b,C[48+y]=l-f,C[56+y]=p-o;for(y=0;y<64;y+=8)t=C[4+y],e=C[2+y]+C[6+y],r=C[5+y]-C[3+y],s=C[1+y]+C[7+y],n=C[3+y]+C[5+y],i=C[1+y]-C[7+y],o=s+n,h=C[y],f=(473*i-196*r+128>>8)-o,a=f-(362*(s-n)+128>>8),c=h-t,d=(362*(C[2+y]-C[6+y])+128>>8)-e,u=h+t,l=c+d,p=u+e,b=c-d,m=u-e,w=-a-(473*r+196*i+128>>8),C[y]=o+p+128>>8,C[1+y]=f+l+128>>8,C[2+y]=b-a+128>>8,C[3+y]=m-w+128>>8,C[4+y]=m+w+128>>8,C[5+y]=a+b+128>>8,C[6+y]=l-f+128>>8,C[7+y]=p-o+128>>8};var o="jsmp",s=1,n=new Uint8Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),h=new Uint8Array([8,16,19,22,26,27,29,34,16,16,22,24,27,29,34,37,19,22,26,27,29,34,34,38,22,22,26,27,29,34,37,40,22,26,27,29,32,35,40,48,26,27,29,32,35,40,48,58,26,27,29,34,38,46,56,69,27,29,35,38,46,56,69,83]),a=new Uint8Array([16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16]),c=new Uint8Array([32,44,42,38,32,25,17,9,44,62,58,52,44,35,24,12,42,58,55,49,42,33,23,12,38,52,49,44,38,30,20,10,32,44,42,38,32,25,17,9,25,35,33,30,25,20,14,7,17,24,23,20,17,14,9,5,9,12,12,10,9,7,5,2]),d=new Int16Array([3,6,0,9,12,0,0,0,1,15,18,0,21,24,0,27,30,0,33,36,0,0,0,3,0,0,2,39,42,0,45,48,0,0,0,5,0,0,4,51,54,0,57,60,0,0,0,7,0,0,6,63,66,0,69,72,0,75,78,0,81,84,0,-1,87,0,-1,90,0,93,96,0,99,102,0,105,108,0,111,114,0,0,0,9,0,0,8,117,120,0,123,126,0,129,132,0,135,138,0,0,0,15,0,0,14,0,0,13,0,0,12,0,0,11,0,0,10,141,-1,0,-1,144,0,147,150,0,153,156,0,159,162,0,165,168,0,171,174,0,177,180,0,183,-1,0,-1,186,0,189,192,0,195,198,0,201,204,0,207,210,0,213,216,0,219,222,0,0,0,21,0,0,20,0,0,19,0,0,18,0,0,17,0,0,16,0,0,35,0,0,34,0,0,33,0,0,32,0,0,31,0,0,30,0,0,29,0,0,28,0,0,27,0,0,26,0,0,25,0,0,24,0,0,23,0,0,22]),u=new Int8Array([3,6,0,-1,9,0,0,0,1,0,0,17]),f=new Int8Array([3,6,0,9,12,0,0,0,10,15,18,0,0,0,2,21,24,0,0,0,8,27,30,0,33,36,0,-1,39,0,0,0,18,0,0,26,0,0,1,0,0,17]),l=new Int8Array([3,6,0,9,15,0,12,18,0,24,21,0,0,0,12,27,30,0,0,0,14,39,42,0,36,33,0,0,0,4,0,0,6,54,48,0,45,51,0,0,0,8,0,0,10,-1,57,0,0,0,1,60,63,0,0,0,30,0,0,17,0,0,22,0,0,26]),p=new Int16Array([6,3,0,9,18,0,12,15,0,24,33,0,36,39,0,27,21,0,30,42,0,60,57,0,54,48,0,69,51,0,81,75,0,63,84,0,45,66,0,72,78,0,0,0,60,105,120,0,132,144,0,114,108,0,126,141,0,87,93,0,117,96,0,0,0,32,135,138,0,99,123,0,129,102,0,0,0,4,90,111,0,0,0,8,0,0,16,0,0,44,150,168,0,0,0,28,0,0,52,0,0,62,183,177,0,156,180,0,0,0,1,165,162,0,0,0,61,0,0,56,171,174,0,0,0,2,0,0,40,153,186,0,0,0,48,192,189,0,147,159,0,0,0,20,0,0,12,240,249,0,0,0,63,231,225,0,195,219,0,252,198,0,0,0,24,0,0,36,0,0,3,207,261,0,243,237,0,204,213,0,210,234,0,201,228,0,216,222,0,258,255,0,264,246,0,-1,282,0,285,291,0,0,0,33,0,0,9,318,330,0,306,348,0,0,0,5,0,0,10,279,267,0,0,0,6,0,0,18,0,0,17,0,0,34,339,357,0,309,312,0,270,276,0,327,321,0,351,354,0,303,297,0,294,288,0,300,273,0,342,345,0,315,324,0,336,333,0,363,375,0,0,0,41,0,0,14,0,0,21,372,366,0,360,369,0,0,0,11,0,0,19,0,0,7,0,0,35,0,0,13,0,0,50,0,0,49,0,0,58,0,0,37,0,0,25,0,0,45,0,0,57,0,0,26,0,0,29,0,0,38,0,0,53,0,0,23,0,0,43,0,0,46,0,0,42,0,0,22,0,0,54,0,0,51,0,0,15,0,0,30,0,0,39,0,0,47,0,0,55,0,0,27,0,0,59,0,0,31]),b=new Int16Array([3,6,0,12,9,0,0,0,0,18,15,0,24,21,0,0,0,-1,0,0,1,27,30,0,36,33,0,0,0,2,0,0,-2,42,45,0,48,39,0,60,54,0,0,0,3,0,0,-3,51,57,0,-1,69,0,81,75,0,78,63,0,72,66,0,96,84,0,87,93,0,-1,99,0,108,105,0,0,0,-4,90,102,0,0,0,4,0,0,-7,0,0,5,111,123,0,0,0,-5,0,0,7,114,120,0,126,117,0,0,0,-6,0,0,6,153,162,0,150,147,0,135,138,0,156,141,0,129,159,0,132,144,0,0,0,10,0,0,9,0,0,8,0,0,-8,171,198,0,0,0,-9,180,192,0,168,183,0,165,186,0,174,189,0,0,0,-10,177,195,0,0,0,12,0,0,16,0,0,13,0,0,14,0,0,11,0,0,15,0,0,-16,0,0,-12,0,0,-14,0,0,-15,0,0,-11,0,0,-13]),m=new Int8Array([6,3,0,18,15,0,9,12,0,0,0,1,0,0,2,27,24,0,21,30,0,0,0,0,36,33,0,0,0,4,0,0,3,39,42,0,0,0,5,0,0,6,48,45,0,51,-1,0,0,0,7,0,0,8]),w=new Int8Array([6,3,0,12,9,0,18,15,0,24,21,0,0,0,2,0,0,1,0,0,0,30,27,0,0,0,3,36,33,0,0,0,4,42,39,0,0,0,5,48,45,0,0,0,6,51,-1,0,0,0,7,0,0,8]),y=new Int32Array([3,6,0,12,9,0,0,0,1,21,24,0,18,15,0,39,27,0,33,30,0,42,36,0,0,0,257,60,66,0,54,63,0,48,57,0,0,0,513,51,45,0,0,0,2,0,0,3,81,75,0,87,93,0,72,78,0,96,90,0,0,0,1025,69,84,0,0,0,769,0,0,258,0,0,1793,0,0,65535,0,0,1537,111,108,0,0,0,1281,105,102,0,117,114,0,99,126,0,120,123,0,156,150,0,162,159,0,144,147,0,129,135,0,138,132,0,0,0,2049,0,0,4,0,0,514,0,0,2305,153,141,0,165,171,0,180,168,0,177,174,0,183,186,0,0,0,2561,0,0,3329,0,0,6,0,0,259,0,0,5,0,0,770,0,0,2817,0,0,3073,228,225,0,201,210,0,219,213,0,234,222,0,216,231,0,207,192,0,204,189,0,198,195,0,243,261,0,273,240,0,246,237,0,249,258,0,279,276,0,252,255,0,270,282,0,264,267,0,0,0,515,0,0,260,0,0,7,0,0,1026,0,0,1282,0,0,4097,0,0,3841,0,0,3585,315,321,0,333,342,0,312,291,0,375,357,0,288,294,0,-1,369,0,285,303,0,318,363,0,297,306,0,339,309,0,336,348,0,330,300,0,372,345,0,351,366,0,327,354,0,360,324,0,381,408,0,417,420,0,390,378,0,435,438,0,384,387,0,0,0,2050,396,402,0,465,462,0,0,0,8,411,399,0,429,432,0,453,414,0,426,423,0,0,0,10,0,0,9,0,0,11,0,0,5377,0,0,1538,0,0,771,0,0,5121,0,0,1794,0,0,4353,0,0,4609,0,0,4865,444,456,0,0,0,1027,459,450,0,0,0,261,393,405,0,0,0,516,447,441,0,516,519,0,486,474,0,510,483,0,504,498,0,471,537,0,507,501,0,522,513,0,534,531,0,468,477,0,492,495,0,549,546,0,525,528,0,0,0,263,0,0,2562,0,0,2306,0,0,5633,0,0,5889,0,0,6401,0,0,6145,0,0,1283,0,0,772,0,0,13,0,0,12,0,0,14,0,0,15,0,0,517,0,0,6657,0,0,262,540,543,0,480,489,0,588,597,0,0,0,27,609,555,0,606,603,0,0,0,19,0,0,22,591,621,0,0,0,18,573,576,0,564,570,0,0,0,20,552,582,0,0,0,21,558,579,0,0,0,23,612,594,0,0,0,25,0,0,24,600,615,0,0,0,31,0,0,30,0,0,28,0,0,29,0,0,26,0,0,17,0,0,16,567,618,0,561,585,0,654,633,0,0,0,37,645,648,0,0,0,36,630,636,0,0,0,34,639,627,0,663,666,0,657,624,0,651,642,0,669,660,0,0,0,35,0,0,267,0,0,40,0,0,268,0,0,266,0,0,32,0,0,264,0,0,265,0,0,38,0,0,269,0,0,270,0,0,33,0,0,39,0,0,7937,0,0,6913,0,0,7681,0,0,4098,0,0,7425,0,0,7169,0,0,271,0,0,274,0,0,273,0,0,272,0,0,1539,0,0,2818,0,0,3586,0,0,3330,0,0,3074,0,0,3842]),C=1,g=2,v=3,T=1,k=175,x=0,A=181,P=178,F=["precision mediump float;","uniform sampler2D YTexture;","uniform sampler2D CBTexture;","uniform sampler2D CRTexture;","varying vec2 texCoord;","void main() {","float y = texture2D(YTexture, texCoord).r;","float cr = texture2D(CBTexture, texCoord).r - 0.5;","float cb = texture2D(CRTexture, texCoord).r - 0.5;","gl_FragColor = vec4(","y + 1.4 * cr,","y + -0.343 * cb - 0.711 * cr,","y + 1.765 * cb,","1.0",");","}"].join("\n"),D=["precision mediump float;","uniform float loaded;","varying vec2 texCoord;","void main() {","float c = ceil(loaded-(1.0-texCoord.y));","gl_FragColor = vec4(c,c,c,1);","}"].join("\n"),E=["attribute vec2 vertex;","varying vec2 texCoord;","void main() {","texCoord = vertex;","gl_Position = vec4((vertex * 2.0 - 1.0) * vec2(1, -1), 0.0, 1.0);","}"].join("\n"),B=[null,u,f,l],S=function(t){this.bytes=new Uint8Array(t),this.length=this.bytes.length,this.writePos=this.bytes.length,this.index=0};S.NOT_FOUND=-1,S.prototype.findNextMPEGStartCode=function(){for(var t=this.index+7>>3;t<this.writePos;t++)if(0===this.bytes[t]&&0===this.bytes[t+1]&&1===this.bytes[t+2])return this.index=t+4<<3,this.bytes[t+3];return this.index=this.writePos<<3,S.NOT_FOUND},S.prototype.nextBytesAreStartCode=function(){var t=this.index+7>>3;return t>=this.writePos||0===this.bytes[t]&&0===this.bytes[t+1]&&1===this.bytes[t+2]},S.prototype.nextBits=function(t){var e=this.index>>3,r=8-this.index%8;if(r>=t)return this.bytes[e]>>r-t&255>>8-t;var i=(this.index+t)%8,o=this.index+t-1>>3,s=this.bytes[e]&255>>8-r;for(e++;e<o;e++)s<<=8,s|=this.bytes[e];return i>0?(s<<=i,s|=this.bytes[e]>>8-i):(s<<=8,s|=this.bytes[e]),s},S.prototype.getBits=function(t){var e=this.nextBits(t);return this.index+=t,e},S.prototype.advance=function(t){return this.index+=t},S.prototype.rewind=function(t){return this.index-=t}}(window);

@@ -5,17 +5,51 @@ var gulp = require('gulp');

var uglify = require('gulp-uglify');
var eslint = require('gulp-eslint');
var pump = require('pump');
//script paths
var jsFiles = ['WebSocketClient.js','jsmpeglive.js'],
jsDest = 'dist';
var jsFiles = ['WebSocketClient.js', 'jsmpeglive.js'],
jsDest = 'dist';
gulp.task('build', function() {
return gulp.src(jsFiles)
.pipe(concat('jsmpeglive-bundle.js'))
.pipe(gulp.dest(jsDest))
.pipe(rename('jsmpeglive-bundle-min.js'))
.pipe(uglify())
.pipe(gulp.dest(jsDest));
var uglifyOpts = {
mangle: true,
compress: {
sequences: true, // join consecutive statemets with the “comma operator”
properties: true, // optimize property access: a["foo"] → a.foo
dead_code: true, // discard unreachable code
drop_debugger: true, // discard “debugger” statements
unsafe: false, // some unsafe optimizations (see below)
conditionals: true, // optimize if-s and conditional expressions
comparisons: true, // optimize comparisons
evaluate: true, // evaluate constant expressions
booleans: true, // optimize boolean expressions
loops: true, // optimize loops
unused: true, // drop unused variables/functions
hoist_funs: true, // hoist function declarations
hoist_vars: false, // hoist variable declarations
if_return: true, // optimize if-s followed by return/continue
join_vars: true, // join var declarations
cascade: true, // try to cascade `right` into `left` in sequences
side_effects: true, // drop side-effect-free statements
warnings: true, // warn about potentially dangerous optimizations/code
global_defs: {} // global definitions
}
};
gulp.task('build', function (cb) {
pump([
gulp.src(jsFiles),
eslint(),
eslint.format(),
eslint.failAfterError(),
concat('jsmpeglive-bundle.js'),
gulp.dest(jsDest),
rename('jsmpeglive-bundle-min.js'),
uglify(uglifyOpts),
gulp.dest(jsDest)
],
cb);
});
gulp.task('default', ['build'], function(){});
gulp.task('default', ['build'], function () {
});
{
"name": "jsmpeglive",
"version": "1.0.1",
"version": "1.0.2",
"description": "#### An MPEG1 Live Stream Video Decoder in JavaScript ####",

@@ -11,7 +11,11 @@ "main": "jsmpeglive.js",

"babel-preset-es2015": "^6.18.0",
"eslint": "^3.12.2",
"gulp": "~3.9.1",
"gulp-babel": "~6.1.2",
"gulp-concat": "~2.6.1",
"gulp-eslint": "^3.0.1",
"gulp-rename": "~1.2.2",
"gulp-uglify": "~2.0.0"
"gulp-sourcemaps": "^1.9.1",
"gulp-uglify": "~2.0.0",
"pump": "^1.0.2"
},

@@ -18,0 +22,0 @@ "scripts": {

@@ -16,4 +16,4 @@ // ----------------------------------------------------------------------------

}
this.number = 0; // Message number
this.autoReconnectInterval = 5 * 1000; // ms
this.number = 0; // Message number
this.attempts = 1; // reconnection attempts
this.jsmpeglive = jsmpeglive;

@@ -41,4 +41,6 @@ this.instance = null;

this.instance.onopen = function () {
self.attempts = 1;
self.instance.binaryType = 'arraybuffer';
self.instance.onmessage = function (event) {
console.debug('onmessage');
self.jsmpeglive.receiveData.bind(self.jsmpeglive, event.data)();

@@ -53,6 +55,6 @@ self.number++;

switch (err.code) {
case 1000: // CLOSE_NORMAL
console.log("WebSocket: closed");
case 1000: // CLOSE_NORMAL
console.debug('WebSocket: closed');
break;
default: // Abnormal closure
default: // Abnormal closure
self.reconnect.bind(self)(err);

@@ -85,24 +87,31 @@ break;

WebSocketClient.prototype.reconnect = function (e) {
console.log('WebSocketClient: retry in ' + this.autoReconnectInterval + 'ms', e);
var that = this;
var self = this;
var time = generateInterval(self.attempts);
function generateInterval(k) {
return Math.min(30, (Math.pow(2, k) - 1)) * 1000;
}
console.debug('WebSocketClient: retry in ' + time + 'ms', e);
setTimeout(function () {
console.log("WebSocketClient: reconnecting...");
that.connect(that.url);
}, this.autoReconnectInterval);
self.attempts++;
console.debug('WebSocketClient: reconnecting...' + self.attempts);
self.connect(self.url);
}, time);
};
WebSocketClient.prototype.onopen = function () {
console.log("WebSocketClient: open", arguments);
console.debug('WebSocketClient: open', arguments);
};
WebSocketClient.prototype.onerror = function (e) {
console.log("WebSocketClient: error", arguments);
console.debug('WebSocketClient: error', e);
};
WebSocketClient.prototype.onmessage = function (event) {
console.log("WebSocketClient: message");
console.debug('WebSocketClient: message', event.data.length);
};
WebSocketClient.prototype.onclose = function (e) {
console.log("WebSocketClient: closed", arguments);
};
WebSocketClient.prototype.onclose = function (err) {
console.debug('WebSocketClient: closed', err.code);
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc