var IvsSession=function(){function a(){this.firstTime=0,this.lastMSW=0}function b(a){var b={result:!0,type:0};return b.params=JSON.parse(String.fromCharCode.apply(null,a)),b}function c(a){var b={result:!1},c=0,d=(a[c+1]<<8)+a[c];if(1!==d&&2!==d)return b;b.result=!0,b.type=5,b.params=null,c+=2;var e=a[c];if(0===e)return b;c+=1;var f=a[c];c+=1,b.params={},b.params.coordinate=128&f?8192:1024,b.params.isTrack=127&f?!0:!1,b.params.object=[];for(var g=0;e>g;g++){var h={};h.objectId=(a[c+3]<<24)+(a[c+2]<<16)+(a[c+1]<<8)+a[c],c+=4,h.operateType=a[c],c+=1;var i=a[c];c+=1,h.objectType=a[c],c+=1;var j=a[c];c+=1,c+=1,c+=1,h.classID=a[c],c+=1,h.subType=a[c],c+=1,j>0&&(h.fatherId=[]);for(var k=0;j>k;k++)h.fatherId.push((a[c+3]<<24)+(a[c+2]<<16)+(a[c+1]<<8)+a[c]),c+=4;i>0&&(h.track=[]);for(var l=0;i>l;l++){var m=(a[c+1]<<8)+a[c];c+=2;var n=(a[c+1]<<8)+a[c];c+=2;var o=(a[c+1]<<8)+a[c];c+=2;var p=(a[c+1]<<8)+a[c];c+=2,h.track.push([m-o,n-p,m+o,n+p])}b.params.object.push(h)}return b}function d(a,b){b.hasOwnProperty("attribute80")||(b.attribute80=[]);var c=1,d=a[c];c+=1;var e={};e.color={},e.color.valid=a[c],c+=1,e.carModel=a[c],c+=1,e.color.red=a[c],c+=1,e.color.green=a[c],c+=1,e.color.blue=a[c],c+=1,e.color.alpha=a[c],c+=1,e.brand=(a[c+1]<<8)+a[c],c+=2,e.subBrand=(a[c+1]<<8)+a[c],c+=2,e.year=(a[c+1]<<8)+a[c],c+=2,e.reliability=a[c],c+=1,c+=1;var f=(a[c+1]<<8)+a[c];c+=2;var g=(a[c+1]<<8)+a[c];c+=2;var h=(a[c+1]<<8)+a[c];c+=2;var i=(a[c+1]<<8)+a[c];return c+=2,e.windowPosition=[f-h,g-i,f+h,g+i],b.attribute80.push(e),d}function e(a,b){b.hasOwnProperty("attribute81")||(b.attribute81=[]);var c={},d=1,e=a[d];d+=1;var f=(a[d+1]<<8)+a[d];d+=2;var g=(a[d+1]<<8)+a[d];d+=2;var h=(a[d+1]<<8)+a[d];d+=2;var i=(a[d+1]<<8)+a[d];return d+=2,c.mainPosition=[f-h,g-i,f+h,g+i],f=(a[d+1]<<8)+a[d],d+=2,g=(a[d+1]<<8)+a[d],d+=2,h=(a[d+1]<<8)+a[d],d+=2,i=(a[d+1]<<8)+a[d],d+=2,c.coPosition=[f-h,g-i,f+h,g+i],c.mainSafetyBelt=a[d]>>2&3,c.coSafetyBelt=3&a[d],d+=1,c.mainSunvisor=a[d]>>2&3,c.coSunvisor=3&a[d],d+=1,b.attribute81.push(c),e}function f(a,b){b.hasOwnProperty("attribute82")||(b.attribute82=[]);var c={},d=1,e=a[d];return d+=1,c.plateEncode=a[d],d+=1,c.plateInfoLen=a[d],d+=1,c.plateInfo=a.subarray(d,d+c.plateInfoLen),b.attribute82.push(c),e}function g(a,b){b.hasOwnProperty("attribute83")||(b.attribute83=[]);var c={},d=1,e=a[d];return d+=1,c.color={},c.color.valid=a[d],d+=1,c.color.red=a[d],d+=1,c.color.green=a[d],d+=1,c.color.blue=a[d],d+=1,c.color.alpha=a[d],d+=1,c.country=String.fromCharCode.apply(null,a.subarray(d,d+4)),d+=4,c.plateType=(a[d+1]<<8)+a[d],d+=2,d+=1,c.plateWidth=(a[d+1]<<8)+a[d],b.attribute83.push(c),e}function h(a,b){b.hasOwnProperty("attribute84")||(b.attribute84=[]);var c={},d=1,e=a[d];d+=1,c.fatherCount=a[d],d+=1,c.trackCount=a[d],d+=1,c.trackType=a[d],d+=1,d+=3,c.fatherCount>0&&(c.fatherID=[]);for(var f=0;f0&&(c.track=[]);for(var g=0;g0&&(c.mainColorInfo=[]);for(var f=0;f>2&3,c.beard=3&a[d],b.attribute88.push(c),len}function m(a,b){b.hasOwnProperty("attribute89")||(b.attribute89=[]);var c={},d=1,e=a[d];d+=1,c.yawAngle=parseInt((a[d+1]<<8)+a[d]),d+=2,c.rollAngle=parseInt((a[d+1]<<8)+a[d]),d+=2,c.pitchAngle=parseInt((a[d+1]<<8)+a[d]),d+=2;var f=(a[d+1]<<8)+a[d];d+=2;var g=(a[d+1]<<8)+a[d];d+=2,c.lEyePos=[f,g],f=(a[d+1]<<8)+a[d],d+=2,g=(a[d+1]<<8)+a[d],d+=2,c.rEyePos=[f,g],f=(a[d+1]<<8)+a[d],d+=2,g=(a[d+1]<<8)+a[d],d+=2,c.nosePos=[f,g],f=(a[d+1]<<8)+a[d],d+=2,g=(a[d+1]<<8)+a[d],d+=2,c.lMouthPos=[f,g],f=(a[d+1]<<8)+a[d],d+=2,g=(a[d+1]<<8)+a[d],d+=2,c.rMouthPos=[f,g];var h=a[d];d+=3,h>0&&(c.featurePos=[]);for(var i=0;h>i;i++)f=(a[d+1]<<8)+a[d],d+=2,g=(a[d+1]<<8)+a[d],d+=2,c.featurePos.push([f,g]);return b.attribute89.push(c),e}function n(a,b){b.hasOwnProperty("attribute8C")||(b.attribute8C=[]);var c={},d=1,e=a[d];d+=1,c.hangingCount=a[d],d+=1,c.tissueCount=a[d],d+=1,c.sunVisorCount=a[d],d+=1,c.annualInspectionCount=a[d],d+=1,d+=6,c.hangingCount>0&&(c.hangingCount=[]);for(var f=0;f0&&(c.tissueCount=[]);for(var f=0;f0&&(c.sunVisorCount=[]);for(var f=0;f0&&(c.annualInspectionCount=[]);for(var f=0;fe?0:(d+=2,c.objectId=(a[d+3]<<24)+(a[d+2]<<16)+(a[d+1]<<8)+a[d],d+=4,c.version=a[d],d+=1,d+=3,c.faceData=a.subarray(d,e),b.faceObject.push(c),e)}function s(a,b){b.hasOwnProperty("commonObject")||(b.commonObject=[]);var c={},d=0;c.type=a[d],d+=1,d+=1;var e=(a[d+1]<<8)+a[d];d+=2,c.objectId=(a[d+3]<<24)+(a[d+2]<<16)+(a[d+1]<<8)+a[d],d+=4,c.operateType=a[d],d+=1,d+=3;var f=a.subarray(d,e);return p(f,c),b.commonObject.push(c),e}function t(a,b,c){var d=0,e=(a[d+3]<<24)+(a[d+2]<<16)+(a[d+1]<<8)+a[d];d+=4;var f=a[d];if(d+=1,d+=3,0==f)return d;b.params.groupId=e,b.params.object={};for(var g=0;f>g;g++){var h=a[d],i=a.subarray(d,a.length),j=0;switch(h){case 2:case 5:j=q(i,b.params.object);break;case 15:j=r(i,b.params.object);break;default:j=s(i,b.params.object)}if(0==j)return 0;d+=j}return c({ivsDraw:b,timeStamp:y}),d}function u(a,b,c){var d={result:!1,type:14,params:{coordinate:8192}};if(b.length<32)return d.result=!0,c({ivsDraw:d,timeStamp:y}),!1;var e=4;d.params.classID=a;var f=b[e];if(0==f)return c({ivsDraw:d,timeStamp:y}),!0;d.params.groupCount=f,e+=1,e+=7,d.params.cameral=[];for(var g=0;20>g;g++)d.params.cameral.push(b[e+g]);e+=20;for(var h=0;h=j)break;e+=j}}function v(a,b){for(var c=a.length,d=0;c>d+4;){var e=a[d],f=(a[d+1],(a[d+3]<<8)+a[d+2]),g=a.subarray(d,f);if(d+=f,161!==e&&!u(A[e-64],g,b))break}}function w(a,d,e){var f=d[22],g=d.subarray(24+f,d.length-8);switch(a){case 0:e({ivsDraw:b(g),timeStamp:y});break;case 5:e({ivsDraw:c(g),timeStamp:y});break;case 6:break;case 14:v(g,e)}}var x,y,z=null,A={1:"VideoSynopsis",2:"TrafficGate",3:"ElectronicPolice",4:"SinglePtzParking",5:"PtzParking",6:"Traffic",7:"Normal",8:"Prison",9:"ATM",10:"MetroIVS",11:"FaceDetection",12:"FaceRecognition",13:"NumberStat",14:"HeatMap",15:"VideoDiagnosis",16:"VideoEnhance",17:"SmokeFireDetect",18:"VehicleAnalyse",19:"PersonFeature",20:"SDFaceDetect",21:"HeatMapPlan",22:"ATMFD",23:"SCR",24:"NumberStatPlan",25:"CourseRecord",26:"Highway",27:"City",28:"LeTrack",29:"ObjectStruct",30:"Stereo",31:"StereoPc",32:"HumanDetect",33:"SDPedestrain",34:"FaceAnalysis",35:"FaceAttribute",36:"FacePicAnalyse",37:"SDEP",38:"XRayDetect",39:"ObjectDetect",40:"CrowdDistriMap",41:"StereoBehavior"};return a.prototype={init:function(){debug.log("init")},parseRTPData:function(a,b){var c=(b[19]<<24)+(b[18]<<16)+(b[17]<<8)+b[16]>>>0,d=Date.UTC("20"+(c>>26),(c>>22&15)-1,c>>17&31,c>>12&31,c>>6&63,63&c)/1e3;if(d-=28800,0==this.firstTime)this.firstTime=d,this.lastMSW=0,z=(b[21]<<8)+b[20],y={timestamp:this.firstTime,timestamp_usec:0};else{var e,f=(b[21]<<8)+b[20];e=f>=z?f-z:f+65535-z,this.lastMSW+=e,d>this.firstTime&&(this.lastMSW-=1e3),this.firstTime=d,y={timestamp:d,timestamp_usec:this.lastMSW},z=f}x=b[5],w(x,b,this.rtpReturnCallback)},setBufferfullCallback:function(){},setReturnCallback:function(a){this.rtpReturnCallback=a}},new a};