RTCP包的头部结构体定义
struct RTCP_Header { unsigned short rc:5; unsigned short padding:1; unsigned short version:2; //1 char unsigned short payloadtype:8; //2 char unsigned short length; //3,4 char unsigned int ssrc; //5,6,7,8 char };
Sender Report 类型的RTCP数据部分结构体定义
struct Rtcp_SR { unsigned int NtpTimestampMSW; unsigned int NtpTimestampLSW; unsigned int RtpTimestamp; unsigned int SenderPacketCnt; unsigned int SenderOctetCnt; };
RTCP报文解析函数
入参:RTCP报文指针、报文字节大小
void parse_udp_packet(unsigned char* packet, int packet_length) { int offset = 0; while (offset < packet_length) { RTCP_Header* pHeader = (RTCP_Header*)(packet + offset); printf("ssrc: 0x%08x ver: %d, padding: %d, rc: %d, type: %d, paloadlen: %d\n", ntohl(pHeader->ssrc), pHeader->version, pHeader->padding, pHeader->rc, pHeader->payloadtype, 4 * ntohs(pHeader->length)); if(pHeader->payloadtype == 200) { Rtcp_SR* pstSR = (Rtcp_SR*)(packet + offset + 8); printf("octetCnt:%d, packetCnt: %d\n", ntohl(pstSR->SenderOctetCnt), ntohl(pstSR->SenderPacketCnt)); } offset += 4 * ntohs(pHeader->length) + 4; } return; }
标签:pHeader,解析,int,报文,unsigned,packet,char,RTCP From: https://www.cnblogs.com/Arthurian/p/18228011