对于TS包头的结构体如下:
typedef struct TS_packet_header
{
unsigned sync_byte : 8;
unsigned transport_error_indicator : 1;
unsigned payload_unit_start_indicator : 1;
unsigned transport_priority : 1;
unsigned PID : 13;
unsigned transport_scrambling_control : 2;
unsigned adaption_field_control : 2;
unsigned continuity_counter : 4;
} TS_packet_header; 解析包头的函数为
void adjust_TS_packet_header(TS_packet_header* pheader)
{
unsigned char buf[4];
memcpy(buf, pheader, 4);
pheader->transport_error_indicator = buf[1] >> 7;
pheader->payload_unit_start_indicator = buf[1] >> 6 & 0x01;
pheader->transport_priority = buf[1] >> 5 & 0x01;
pheader->PID = (buf[1] & 0x1F) << 8 | buf[2];
pheader->transport_scrambling_control = buf[3] >> 6;
pheader->adaption_field_control = buf[3] >> 4 & 0x03;
pheader->continuity_counter = buf[3] & 0x03;
} 看到这里我不明白,为什么要这样进行移位运算,
比如说象:pheader->transport_error_indicator = buf[1] >> 7;
pheader->payload_unit_start_indicator = buf[1] >> 6 & 0x01;
pheader->transport_priority = buf[1] >> 5 & 0x01;等等
大家能不能给我详细说说为什么TS流数据头要进行这样的移位,这样为什么能够得到结构体每个成员的值
typedef struct TS_packet_header
{
unsigned sync_byte : 8;
unsigned transport_error_indicator : 1;
unsigned payload_unit_start_indicator : 1;
unsigned transport_priority : 1;
unsigned PID : 13;
unsigned transport_scrambling_control : 2;
unsigned adaption_field_control : 2;
unsigned continuity_counter : 4;
} TS_packet_header; 解析包头的函数为
void adjust_TS_packet_header(TS_packet_header* pheader)
{
unsigned char buf[4];
memcpy(buf, pheader, 4);
pheader->transport_error_indicator = buf[1] >> 7;
pheader->payload_unit_start_indicator = buf[1] >> 6 & 0x01;
pheader->transport_priority = buf[1] >> 5 & 0x01;
pheader->PID = (buf[1] & 0x1F) << 8 | buf[2];
pheader->transport_scrambling_control = buf[3] >> 6;
pheader->adaption_field_control = buf[3] >> 4 & 0x03;
pheader->continuity_counter = buf[3] & 0x03;
} 看到这里我不明白,为什么要这样进行移位运算,
比如说象:pheader->transport_error_indicator = buf[1] >> 7;
pheader->payload_unit_start_indicator = buf[1] >> 6 & 0x01;
pheader->transport_priority = buf[1] >> 5 & 0x01;等等
大家能不能给我详细说说为什么TS流数据头要进行这样的移位,这样为什么能够得到结构体每个成员的值
解决方案 »
- 我用控制台编写了个基本的socket服务器程序,请问怎样调试?
- 求问Visual Studio 2010打不开dll的问题
- windows中进队消息和不进队消息的区别?
- MFC时钟问题
- VC++中COM是个什么概念?托管如何理解?
- 关于文件监控
- 关于IE控件的高深问题
- 编译一个最简单的带 DirecTX 的问题, 连接问题, 不明白 高手指点一下!!!!!!!!!!
- 请问wincore.cpp 中的 DestroyWindow()在什么时候调用 ,为什么我的程序在这个地方被终止,谢谢!
- 照搬书本都出毛病!高手看过来
- 请教PlgBlt, recttracker用法
- 关于releace下获取Edit框内容
{
unsigned sync_byte : 8;
unsigned transport_error_indicator : 1;
unsigned payload_unit_start_indicator : 1;
unsigned transport_priority : 1;
unsigned PID : 13;
unsigned transport_scrambling_control : 2;
unsigned adaption_field_control : 2;
unsigned continuity_counter : 4;
} TS_packet_header;
“:”后面表示的是该成员所占的位数,位数为1则表示该成员的取值范围是0~1;位数为2则表示取值范围是0~3;位数为3则是0~7……
整个结构体占4字节(32位)储存空间,第0~7位是sync_byte,第8位是transport_error_indicator,第9位是payload_unit_start_indicator……
例如要提取结构体中的adaption_field_control,因为它是第26~27位,也就是第3(基于0)字节的第2~3位(共两位),所以要取第3字节,然后右移2位(把右边多余的2位抛弃),再“与”3(屏蔽左边多余的位)。