"use strict";(function(){var e=0;var r=0;"use strict";var t=require("util");var s=require("events");var i=require("moment");var a=require("./jsUtil");var n=require("./Logger").getLogger("rtpsCap.js");function o(e,t){var s=this;var i=require("cap").Cap,o=require("cap").decoders,c=o.PROTOCOL;var f=new i,u=i.findDevice(),v="udp",d=10*1024*1024,p=new Buffer(65535);this.c=f;var l=require("fs");var g=i.deviceList();var m=[];for(var y=0;y<g.length;y++){m.push(g[y].name)}var q=require("./jsUtil");var R=q.getDataPath();var h=R+"/config";var M=R+"/config/cap_device.json";if(!a.fsExistsSync(h)){l.mkdirSync(h)}this.exists=a.fsExistsSync(M);var P={};if(this.exists){P=JSON.parse(l.readFileSync(M,"utf-8"));if(P.cur_device!=null){for(var y=0;y<m.length;y++){if(P.cur_device==m[y]){u=P.cur_device;break}}}}else{P.cur_device=null}P.device_list=g;l.writeFileSync(M,JSON.stringify(P,null,"	"),"utf-8");var P=JSON.parse(l.readFileSync(M,"utf-8"));var T=require("./rtpsMgr");var D=new T.RtpSessionMgr;this.rtpsMgr=D;var S=T.measureRtp;D.setDb(e,t);s.startCap=function(e){if(r)n.debug("[rtps_cap.startCap]","device:",u);var t=s.c.open(u,v,d,p);s.c.setMinBytes&&s.c.setMinBytes(0);s.c.on("packet",function(r,s){var i=process.hrtime();var a=i[0]*1e3+i[1]/1e6;var n=new T.RtpKey;if(t!=="ETHERNET"){return}var f=o.Ethernet(p);if(f.info.type!==c.ETHERNET.IPV4){return}f=o.IPV4(p,f.offset);if(f.info.protocol!==c.IP.UDP){return}n.setAddr(f.info.srcaddr,f.info.dstaddr);f=o.UDP(p,f.offset);if(!o.isRTP(p,f.offset,f.info.length)){return}n.setPort(f.info.srcport,f.info.dstport);f=o.RTP(p,f.offset);n.setRtp(f.info.ssrc);e.addPktInfo(n,f.info.seq,f.info.timestamp,a)})}}exports.rtps_cap=o;if(e){var c=require("sqlite3").verbose();var f=new c.Database("./xx.db");var u=require("./dbMgr");var v=new u(f,3e3);var i=require("moment");var d=new o(f,v);var p=d.rtpsMgr;d.startCap(p);setTimeout(function(){p.getLastestUsersAndRate(function(e,r){console.log(r,"getLastestUsersAndRate-------------------------------------------------------------")});p.getHistoryMaxUsersAndRate(function(e,r){console.log(r,"getHistoryMaxUsersAndRate-------------------------------------------------------------")});var e={};e.interval="hour";e.endTime=i().format("YYYY-MM-DD HH:mm:ss");e.startTime=i().add(-5,"hours").format("YYYY-MM-DD HH:mm:ss");p.getRtpUsersAndRate(e,function(e,r){console.log(r,"getRtpUsersAndRate-------------------------------------------------------------")});e.srcAddr="172.24.0.12";e.dstAddr="";e.srcPort="";e.dstPort="";e.delayTime="";p.queryTypeFromDb(e,function(e,r){console.log(r,"queryTypeFromDb-------------------------------------------------------------")})},2e3)}})();