RTP数据包由12字节RTP头和 后续RTP有效载荷 标题的第3和第4个字节包含 最重要的字节和最不重要的字节 RTP数据包的序列号 Seq Num =(MSB <&lt; 8)+ LSB
char pszPacket [12];
...
长lSeq = ???? - 如何从数据包中获取序列号?
答案 0 :(得分:4)
unsigned short seq = (packet[2] << 8) | packet[3];
答案 1 :(得分:2)
当然那只是“长lSeq =(unsigned char)(pszPacket [2]&lt;&lt; 8)|(unsigned char)pszPacket [3];”?
答案 2 :(得分:0)
如果您需要适当的实现方式
typedef struct _RTPHeader
{
//first byte
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
unsigned int CC:4; /* CC field */
unsigned int X:1; /* X field */
unsigned int P:1; /* padding flag */
unsigned int version:2;
#elif G_BYTE_ORDER == G_BIG_ENDIAN
unsigned int version:2;
unsigned int P:1; /* padding flag */
unsigned int X:1; /* X field */
unsigned int CC:4; /* CC field*/
#else
#error "G_BYTE_ORDER should be big or little endian."
#endif
//second byte
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
unsigned int PT:7; /* PT field */
unsigned int M:1; /* M field */
#elif G_BYTE_ORDER == G_BIG_ENDIAN
unsigned int M:1; /* M field */
unsigned int PT:7; /* PT field */
#else
#error "G_BYTE_ORDER should be big or little endian."
#endif
guint16 seq_num; /* length of the recovery */
guint32 TS; /* Timestamp */
guint32 ssrc;
} RTPHeader; //12 bytes
您可以做的是:
char pszPacket[12];
RTPHeader* myRTPPacket = (RTPHeader*) pszPacket;
printf("Sequence number is: %hu", myRTPPacket->seq_num;
答案 3 :(得分:0)
unsigned __int16 seq = _rotr16( *( unsigned __int16* )&packet[2] , 8 );
答案 4 :(得分:0)
假设我们有一个指向字节缓冲区的指针,该缓冲区包含称为rtpBuffer的整个RTP数据包(包括RTP头),则可以使用以下代码提取位置2和3的16位字:
int8_t *rtpBuffer;
uint16_t packetSeqNbr = ntohs(*(reinterpret_cast<uint16_t *>(rtpBuffer + 2)));
ntohs()用于从网络字节顺序转换为主机字节顺序,以便代码可移植到不同的机器上。