123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- const time = require('./time.js');
- function hexStrToBitStr(str){
- // 移除0x 以及空格
- str = str.replace(/0x/g,'').replace(/\s/g,'');
- // 转换为二进制
- return parseInt(str,16).toString(2);
- }
- function parseRtpHeader(hexStr){
- let bitStr = hexStrToBitStr(hexStr);
- let version = parseInt(bitStr.substr(0,2),2);
- let padding = bitStr.substr(2,1);
- let extension = bitStr.substr(3,1);
- let csrcCount = bitStr.substr(4,4);
- let marker = bitStr.substr(8,1);
- let payloadType = parseInt(bitStr.substr(9,7),2);
- let sequenceNumber = parseInt(bitStr.substr(16,16),2);
- let timestamp = parseInt(bitStr.substr(32,32),2);
- // 格式化时间戳
- let _time = time.timestr(timestamp )
- let ssrc = bitStr.substr(64,32);
- let csrc = bitStr.substr(96,32);
- return {
- version,
- padding,
- extension,
- csrcCount,
- marker,
- payloadType,
- sequenceNumber,
- timestamp,
- ssrc,
- csrc,
- time: _time
- }
- }
- console.log(parseInt(hexStrToBitStr('00 10'),2));
- // console.log(parseInt(hexStrToBitStr('00 5b'),2));
- // console.log(parseInt(hexStrToBitStr('00 5d'),2));
- // console.log(parseInt(hexStrToBitStr('01 e2'),2));
- // console.log(parseInt(hexStrToBitStr('00 5a'),2));
- // console.log(parseInt(hexStrToBitStr('00 5a'),2));
- // console.log(parseInt(hexStrToBitStr('00 5a'),2));
- let lineStr = "| 黑屏设备包头解析 | 不黑屏设备解析 |"
- console.log(lineStr);
- // rtp黑屏
- // 00 10 80 e0 00 02 00 00 46 50 01 e1 5e 79 68 ce 31 b2 00 11 80 e0 00 03 00 00 69 78 01 e1 5e 79 06 e5 01 42 80 05 78 80 60 00 04 00
- //
- // console.log(parseRtpHeader('00 10 80 e0 00 02 00 00 46 50 01 e1 5e 79 68 ce 31 b2 00 11 80 e0 00'));
- // console.log(parseRtpHeader('80 e0 00 02 00 00 46 50 01 e1 5e 79 68 ce 31 b2'));
- console.log(parseRtpHeader('80 e0 00 02 00 00 46 50 01 e1 5e 79'));
- // {
- // version: 2,
- // padding: '0',
- // extension: '0',
- // csrcCount: '0000',
- // marker: '1',
- // payloadType: 96,
- // sequenceNumber: 2,
- // timestamp: 18432,
- // ssrc: '00000000000000000000000000000000',
- // csrc: '',
- // time: '1970-01-01 08:00:18'
- // }
- // 正常播放
- // 00 10 80 60 00 02 3b 09 a5 d0 01 df 5a d9 68 ee 31 b2 00 11 80 60 00 03 3b 09 a5 d0 01 df 5a d9 06 e5 01 cb 80 05 86 80 60 00 04 3b
- // console.log(parseRtpHeader('00 10 80 60 00 02 3b 09 a5 d0 01 df 5a d9 68 ee 31 b2 00 11 80 60 00'));
- // console.log(parseRtpHeader('00 10 80 60 00 02 3b 09 a5 d0 01 df 5a d9 68 ee'));
- console.log(parseRtpHeader('80 60 00 02 3b 09 a5 d0 01 df 01'));
- // {
- // version: 2,
- // padding: '0',
- // extension: '0',
- // csrcCount: '0000',
- // marker: '0',
- // payloadType: 96,
- // sequenceNumber: 2,
- // timestamp: 990488576,
- // ssrc: '000000000000000000000000',
- // csrc: '',
- // time: '1970-01-12 19:08:08'
- // }
- // console.log(parseRtpHeader('80080108b387a86000000194'));
- // console.log(parseRtpHeader('8008010bb387aa4000000194'));
- // console.log(parseRtpHeader('8008010cb387aae000000194'));
- // console.log(parseRtpHeader('8008010db387ab8000000194'));
- // console.log(parseRtpHeader('8008010eb387ac2000000194'));
- // console.log(parseRtpHeader('00 04 d4 91 5e 08 07 27 11 e8 d6 d4'));
- // console.log(parseRtpHeader('00 05 d4 91 5e a8 07 27 11 e8 d5 57'));
- // console.log(parseRtpHeader('00 06 d4 91 5f 48 07 27 11 e8 54 d4'));
|