The RTP header has the following format:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|X| CC |M| PT | sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| synchronization source (SSRC) identifier |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| contributing source (CSRC) identifiers |
| .... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
从上面的显示中我们可以看到rtp包在网路上传送时的字节序。那在程序中怎么写呢?
来看一下人家写好的代码就知道了。
struct RTPFixedHeader
{
#if __BYTE_ORDER == __BIG_ENDIAN
/// For big endian boxes
unsigned char version:2; ///< Version, currently 2
unsigned char padding:1; ///< Padding bit
unsigned char extension:1; ///< Extension bit
unsigned char cc:4; ///< CSRC count
unsigned char marker:1; ///< Marker bit
unsigned char payload:7; ///< Payload type
#else
/// For little endian boxes
unsigned char cc:4; ///< CSRC count
unsigned char extension:1; ///< Extension bit
unsigned char padding:1; ///< Padding bit
unsigned char version:2; ///< Version, currently 2
unsigned char payload:7; ///< Payload type
unsigned char marker:1; ///< Marker bit
#endif
uint16 sequence; ///< sequence number
uint32 timestamp; ///< timestamp
uint32 sources[1]; ///< contributing sources
};
怎么样,明白了吧。
以后要发格式特殊的报文的时候就这样写,就ok了。
而且重要的一点,这个顺序是以字节为单位的。 也就是以字节为单位的话,顺序是不变的,都是由低到高。但是在一个字节内,要进行区分的话,根据大小字节序来调整。
貌似这个和我们平时见的整型数值,表达有点不一样。 整型的话,是以字节为单位。
在小子节序时, 低字节在低位。
在大字节序时, 高字节在低位。
类似的表达方式,还有种更牛的。。。。 我服了
typedef struct {
uint8
Wlan_WpaAKm_None:1,
Wlan_WpaAKm_Unspecified:1,
Wlan_WpaAKm_Psk:1,
reserved:3,
Wlan_Wpa2AKm_Unspecified:1,
Wlan_Wpa2AKm_Psk:1;
} Wlan_WpaAKmBit;
用逗号分隔,牛的。
1466

被折叠的 条评论
为什么被折叠?



