|
@@ -0,0 +1,190 @@
|
|
|
+// 读取 rtpPack1.txt 文件,解析其中的 rtp 包,检查其中的序列号是否连续
|
|
|
+const path = require("path");
|
|
|
+const loadTxt = require("./loadTxt");
|
|
|
+const rtp = require("./rtpParse");
|
|
|
+function handle(promise){
|
|
|
+ return promise.then(data=>[null,data]).catch(err=>[err,null])
|
|
|
+}
|
|
|
+let filePath1 = path.join(__dirname, 'rtpPack1.txt');
|
|
|
+let filePath2 = path.join(__dirname, 'rtpPack2.txt');
|
|
|
+
|
|
|
+async function parseRtpPackTxt(filePath) {
|
|
|
+ let rtpPacks = [];
|
|
|
+ let [err,lines] = await handle( loadTxt.loadFileLines(filePath) );
|
|
|
+ if (err){
|
|
|
+ return console.log(err);
|
|
|
+ }
|
|
|
+ // 读取一行,跳过一行
|
|
|
+ for (let i = 0; i < lines.length; i+=2) {
|
|
|
+ let line = lines[i];
|
|
|
+ if (line === "***end***"){
|
|
|
+ console.log("文件解析结束");
|
|
|
+ return rtpPacks;
|
|
|
+ }
|
|
|
+ rtpPacks.push(line);
|
|
|
+ }
|
|
|
+ return rtpPacks;
|
|
|
+}
|
|
|
+
|
|
|
+// 格式化输出内容 用于打印表格 例如
|
|
|
+// 表单长度 用于打印表格 例如 [20,20] 则再打印表格时,每个单元格的长度为 20
|
|
|
+let tbLen = [50, 50];
|
|
|
+let lineLen = 2;
|
|
|
+function printf() {
|
|
|
+ let str = "";
|
|
|
+ str += "|";
|
|
|
+ for (let i = 0; i < lineLen; i++) {
|
|
|
+ let arg = arguments[i] || "";
|
|
|
+ let len = tbLen[i];
|
|
|
+ let argLen = arg.length;
|
|
|
+ let spaceLen = len - argLen;
|
|
|
+ let space = "";
|
|
|
+ for (let j = 0; j < spaceLen; j++) {
|
|
|
+ space += " ";
|
|
|
+ }
|
|
|
+ //
|
|
|
+ // 如果长度超过了表单长度,则截取字符串
|
|
|
+ if (argLen > len){
|
|
|
+ arg = arg.substr(0,len);
|
|
|
+ }
|
|
|
+ str += arg + space + "|";
|
|
|
+
|
|
|
+ }
|
|
|
+ console.log(str);
|
|
|
+}
|
|
|
+
|
|
|
+// 解析剩余数据
|
|
|
+let last_data = ["",""];
|
|
|
+let bitLen = 2;
|
|
|
+
|
|
|
+// rtp over tcp 包的前两个字节为rtp包的长度
|
|
|
+function parseRtpOverTcp(no, package){
|
|
|
+ // 合并旧数据
|
|
|
+ if(last_data[no] !== ""){
|
|
|
+ package = last_data[no] + package;
|
|
|
+ last_data[no] = "";
|
|
|
+ }
|
|
|
+ let allLen = package.length;
|
|
|
+ console.log(`---*-*-*-*-*------ allLen: ${allLen} ------*-*-*-*-*-*---`)
|
|
|
+ let len = 0;
|
|
|
+ // 读取包长度
|
|
|
+ let packageLenStr = package.substr(0,4);
|
|
|
+ let packageLen = parseInt(packageLenStr,16);
|
|
|
+ console.log(`packageLenStr: ${packageLenStr} >>> ${packageLen}`);
|
|
|
+ // package_len + i <= left_len + data_len
|
|
|
+ while ( (len + packageLen) * 2 <= allLen ){
|
|
|
+
|
|
|
+ console.log('----')
|
|
|
+ // 解析rtp包
|
|
|
+ let rtpPackage = package.substr(len * 2 + 4, packageLen * bitLen);
|
|
|
+ let rtpHeaderInfo = rtp.parseRtpHeader(rtpPackage.substr(0,24));
|
|
|
+ console.log(rtpHeaderInfo)
|
|
|
+ // i += package_len + 2;
|
|
|
+
|
|
|
+ // 读取下一个包长度
|
|
|
+
|
|
|
+ len += packageLen + 2;
|
|
|
+ console.log(`len: ${len}`)
|
|
|
+ packageLenStr = package.substr(len * 2, 4);
|
|
|
+ packageLen = parseInt(packageLenStr,16);
|
|
|
+ console.log(`packageLenStr: ${packageLenStr} >>> ${packageLen} `);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 如果剩余数据不足以解析一个包,则跳出循环
|
|
|
+
|
|
|
+ }
|
|
|
+ // 读取剩余数据
|
|
|
+ last_data[no] = package.substr(len * 2 );
|
|
|
+ console.log(`last_data: ${last_data[no].length}`);
|
|
|
+}
|
|
|
+
|
|
|
+async function main(){
|
|
|
+ let rtpPackages_1 = await parseRtpPackTxt(filePath2);
|
|
|
+ let rtpPackages_2 = await parseRtpPackTxt(filePath2);
|
|
|
+ printf(" black"," ok");
|
|
|
+ printf("------------------------------","------------------------------");
|
|
|
+ // 开始解析rtp数据
|
|
|
+ for (let i = 0; i < rtpPackages_1.length; i++) {
|
|
|
+ console.log(`---*-*-*-*-*------ ${i} ------*-*-*-*-*-*---`)
|
|
|
+ let rtpPackage_1 = rtpPackages_1[i];
|
|
|
+ // 输出前10个字节
|
|
|
+ console.log(rtpPackage_1.substr(0,20));
|
|
|
+ let rtpPackage_2 = rtpPackages_2[i];
|
|
|
+ // rtpPackage_1 = rtpPackage_1.substr(4,24);
|
|
|
+ // rtpPackage_2 = rtpPackage_2.substr(4,24);
|
|
|
+ // printf(
|
|
|
+ // ` ${rtpPackage_1}`,
|
|
|
+ // ` ${rtpPackage_2}`,
|
|
|
+ // );
|
|
|
+ let rtpHeaderInfo_1 = parseRtpOverTcp(0, rtpPackage_1);
|
|
|
+ // let rtpHeaderInfo_2 = rtp.parseRtpOverTcp(1, rtpPackage_2);
|
|
|
+ let rtpHeaderInfo_2 = {};
|
|
|
+ // printf(
|
|
|
+ // `${i} version: ${rtpHeaderInfo_1.version}`,
|
|
|
+ // `${i} version: ${rtpHeaderInfo_2.version}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} padding: ${rtpHeaderInfo_1.padding}`,
|
|
|
+ // `${i} padding: ${rtpHeaderInfo_2.padding}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} extension: ${rtpHeaderInfo_1.extension}`,
|
|
|
+ // `${i} extension: ${rtpHeaderInfo_2.extension}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} csrcCount: ${rtpHeaderInfo_1.csrcCount}`,
|
|
|
+ // `${i} csrcCount: ${rtpHeaderInfo_2.csrcCount}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} csrcCount: ${rtpHeaderInfo_1.csrcCount}`,
|
|
|
+ // `${i} csrcCount: ${rtpHeaderInfo_2.csrcCount}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} marker: ${rtpHeaderInfo_1.marker}`,
|
|
|
+ // `${i} marker: ${rtpHeaderInfo_2.marker}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} payloadType: ${rtpHeaderInfo_1.payloadType}`,
|
|
|
+ // `${i} payloadType: ${rtpHeaderInfo_2.payloadType}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} sequenceNumber: ${rtpHeaderInfo_1.sequenceNumber}`,
|
|
|
+ // `${i} sequenceNumber: ${rtpHeaderInfo_2.sequenceNumber}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} timestamp: ${rtpHeaderInfo_1.timestamp}`,
|
|
|
+ // `${i} timestamp: ${rtpHeaderInfo_2.timestamp}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} ssrc: ${rtpHeaderInfo_1.ssrc}`,
|
|
|
+ // `${i} ssrc: ${rtpHeaderInfo_2.ssrc}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} csrc: ${rtpHeaderInfo_1.csrc}`,
|
|
|
+ // `${i} csrc: ${rtpHeaderInfo_2.csrc}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf(
|
|
|
+ // `${i} time: ${rtpHeaderInfo_1.time}`,
|
|
|
+ // `${i} time: ${rtpHeaderInfo_2.time}`,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // printf("------------------------------","------------------------------");
|
|
|
+ // printf("------------------------------","------------------------------");
|
|
|
+ // printf("------------------------------","------------------------------");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+main()
|