test.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const time = require('./time.js');
  2. function hexStrToBitStr(str){
  3. // 移除0x 以及空格
  4. str = str.replace(/0x/g,'').replace(/\s/g,'');
  5. // 转换为二进制
  6. return parseInt(str,16).toString(2);
  7. }
  8. function parseRtpHeader(hexStr){
  9. let bitStr = hexStrToBitStr(hexStr);
  10. let version = parseInt(bitStr.substr(0,2),2);
  11. let padding = bitStr.substr(2,1);
  12. let extension = bitStr.substr(3,1);
  13. let csrcCount = bitStr.substr(4,4);
  14. let marker = bitStr.substr(8,1);
  15. let payloadType = parseInt(bitStr.substr(9,7),2);
  16. let sequenceNumber = parseInt(bitStr.substr(16,16),2);
  17. let timestamp = parseInt(bitStr.substr(32,32),2);
  18. // 格式化时间戳
  19. let _time = time.timestr(timestamp )
  20. let ssrc = bitStr.substr(64,32);
  21. let csrc = bitStr.substr(96,32);
  22. return {
  23. version,
  24. padding,
  25. extension,
  26. csrcCount,
  27. marker,
  28. payloadType,
  29. sequenceNumber,
  30. timestamp,
  31. ssrc,
  32. csrc,
  33. time: _time
  34. }
  35. }
  36. console.log(parseInt(hexStrToBitStr('00 10'),2));
  37. // console.log(parseInt(hexStrToBitStr('00 5b'),2));
  38. // console.log(parseInt(hexStrToBitStr('00 5d'),2));
  39. // console.log(parseInt(hexStrToBitStr('01 e2'),2));
  40. // console.log(parseInt(hexStrToBitStr('00 5a'),2));
  41. // console.log(parseInt(hexStrToBitStr('00 5a'),2));
  42. // console.log(parseInt(hexStrToBitStr('00 5a'),2));
  43. let lineStr = "| 黑屏设备包头解析 | 不黑屏设备解析 |"
  44. console.log(lineStr);
  45. // rtp黑屏
  46. // 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
  47. //
  48. // 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'));
  49. // console.log(parseRtpHeader('80 e0 00 02 00 00 46 50 01 e1 5e 79 68 ce 31 b2'));
  50. console.log(parseRtpHeader('80 e0 00 02 00 00 46 50 01 e1 5e 79'));
  51. // {
  52. // version: 2,
  53. // padding: '0',
  54. // extension: '0',
  55. // csrcCount: '0000',
  56. // marker: '1',
  57. // payloadType: 96,
  58. // sequenceNumber: 2,
  59. // timestamp: 18432,
  60. // ssrc: '00000000000000000000000000000000',
  61. // csrc: '',
  62. // time: '1970-01-01 08:00:18'
  63. // }
  64. // 正常播放
  65. // 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
  66. // 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'));
  67. // console.log(parseRtpHeader('00 10 80 60 00 02 3b 09 a5 d0 01 df 5a d9 68 ee'));
  68. console.log(parseRtpHeader('80 60 00 02 3b 09 a5 d0 01 df 01'));
  69. // {
  70. // version: 2,
  71. // padding: '0',
  72. // extension: '0',
  73. // csrcCount: '0000',
  74. // marker: '0',
  75. // payloadType: 96,
  76. // sequenceNumber: 2,
  77. // timestamp: 990488576,
  78. // ssrc: '000000000000000000000000',
  79. // csrc: '',
  80. // time: '1970-01-12 19:08:08'
  81. // }
  82. // console.log(parseRtpHeader('80080108b387a86000000194'));
  83. // console.log(parseRtpHeader('8008010bb387aa4000000194'));
  84. // console.log(parseRtpHeader('8008010cb387aae000000194'));
  85. // console.log(parseRtpHeader('8008010db387ab8000000194'));
  86. // console.log(parseRtpHeader('8008010eb387ac2000000194'));
  87. // console.log(parseRtpHeader('00 04 d4 91 5e 08 07 27 11 e8 d6 d4'));
  88. // console.log(parseRtpHeader('00 05 d4 91 5e a8 07 27 11 e8 d5 57'));
  89. // console.log(parseRtpHeader('00 06 d4 91 5f 48 07 27 11 e8 54 d4'));