日期:2014-05-16  浏览次数:20757 次

ts包头结构问题
对于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;


例如unsigned payload_unit_start_indicator : 1;
是什么意思?
还有pheader->payload_unit_start_indicator = buf[1] >> 6 & 0x01;什么意思

------解决方案--------------------
unsigned payload_unit_start_indicator : 1;
表示这个变量占用1位 (1 bit)
楼主可以google看看“位域”