系统:ubuntu 11.04 little-end
描述:这个问题是在研究TS包头解析时遇到的,用两种方式取TS包头,但结果不同
耗时:2天
程序:
1. 使用正常顺序方式定义TS包头结构体,然后将TS包头数据拷贝到包头结构体中。
void bob_get_packet_header_mem_cpy_1(unsigned char *ts_package)
{
printf(" [%s]:\n", __func__);
printf(" Package Source Data: ");
unsigned char *p = ts_package;
while(p < (ts_package + sizeof(TS_packet_header))){
printf("%02x ", *p);
p++;
}
printf(" (0x%04x)\n", *(unsigned int *)ts_package);
struct bob_TS_packet_header
{
unsigned int sync_byte :8;
unsigned int transport_error_indicator :1;
unsigned int payload_unit_start_indicator :1;
unsigned int transport_priority :1;
unsigned int PID :13;
unsigned int transport_scrambling_control :2;
unsigned int adaptation_field_control :2;
unsigned int continuity_counter :4;
}header;
memcpy((void *)&header, ts_package, sizeof(header));
printf(" sync_byte(8b): 0x%02X (%u) %s\n", header.sync_byte, header.sync_byte, (header.sync_byte == 0x47 ? "" : "(sync error)"));
printf(" transport_error_indicator(1b): 0x%02X (%u) %s\n", header.transport_error_indicator, header.transport_error_indicator, (header.transport_error_indicator == 0x00 ? "" : "(packet error)"));
printf(" payload_unit_start_indicator(1b): 0x%02X (%u)\n", header.payload_unit_start_indicator, header.payload_unit_start_indicator);
printf(" transport_priority(1b): 0x%02X (%u)\n", header.transport_priority, header.transport_priority);
printf(" PID(13b): 0x%04X (%u)\n", header.PID, header.PID);
printf(" transport_scrambling_control(2b): 0x%02X (%u) %s\n", header.transport_scrambling_control, header.transport_scrambling_control