|  | @@ -0,0 +1,57 @@
 | 
	
		
			
				|  |  | +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 ac'),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));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +console.log(parseRtpHeader('80 08 00 04 d4 91 5e 08 07 27 11 e8'));
 | 
	
		
			
				|  |  | +console.log(parseRtpHeader('80 08 00 05 d4 91 5e a8 07 27 11 e8'));
 | 
	
		
			
				|  |  | +console.log(parseRtpHeader('80 08 00 06 d4 91 5f 48 07 27 11 e8'));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +console.log(parseRtpHeader('80 08 00 15 00 41 ad c0 00 00 27 66'));
 | 
	
		
			
				|  |  | +console.log(parseRtpHeader('80 08 00 17 00 41 af 00 00 00 27 66'));
 | 
	
		
			
				|  |  | +console.log(parseRtpHeader('80 08 00 18 00 41 af a0 00 00 27 66'));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +// 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'));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 |