免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2051 | 回复: 0
打印 上一主题 下一主题

TS流解析之TS包头解析 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-02 16:27 |只看该作者 |倒序浏览
[color="#000102"]根据前一篇中各数据的定义及数据结构,对数据进行分别解析如下:
[color="#000102"]TS包头定义:
[color="#000102"]typedef struct TS_packet_header{    unsigned sync_byte                        : 8; //同步字节, 固定为0x47,表示后面的是一个TS分组    unsigned transport_error_indicator        : 1; //传输误码指示符    unsigned payload_unit_start_indicator    : 1; //有效荷载单元起始指示符       unsigned transport_priority              : 1; //传输优先, 1表示高优先级,传输机制可能用到,解码用不着    unsigned PID                            : 13; //PID    unsigned transport_scrambling_control    : 2; //传输加扰控制     unsigned adaption_field_control            : 2; //自适应控制 01仅含有效负载,10仅含调整字段,11含有调整字段和有效负载。为00解码器不进行处理    unsigned continuity_counter                : 4; //连续计数器 一个4bit的计数器,范围0-15} TS_packet_header;
[color="#000102"]
[color="#000102"]TS包头解析代码:
[color="#000102"]HRESULT CTS_Stream_Parse::adjust_TS_packet_header( TS_packet_header* TS_header ){ unsigned char buf[4];      memcpy(buf, TS_header, 4);    TS_header->transport_error_indicator        = buf[1] >> 7;    TS_header->payload_unit_start_indicator    = buf[1] >> 6 & 0x01;    TS_header->transport_priority                = buf[1] >> 5 & 0x01;    TS_header->PID                            = (buf[1] & 0x1F)     TS_header->transport_scrambling_control    = buf[3] >> 6;    TS_header->adaption_field_control            = buf[3] >> 4 & 0x03;    TS_header->continuity_counter                = buf[3] & 0x0F; // 四位数据,应为0x0F xyy 09.03.18
[color="#000102"] return 0;}
[color="#000102"]如下为一个TS包数据:
[color="#000102"]0x47 0x40 0x00 0x12[color="#000102"] [color="#000102"]0x00[color="#000102"] 0x00 0xb0 0x0d 0x00 0x00 0xc1 0x00 0x00 0x00 0x01 0xe3 0xe8 0xf0 0x0b 0xd7 0x79 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
[color="#000102"]分析知道前四位[color="#000102"]0x47 0x40 0x00 0x12[color="#000102"]TS[color="#000102"]头部即为TS包头数据,解析如下:
[color="#000102"]sync_byte   [color="#000102"]:[color="#000102"]0x47transport_error_indicator: 0x00payload_unit_start_indicator: 0x01transport_priority  : 0x00
[color="#000102"]  PID                     :0x0000transport_scrambling_control  :0x00adaptation_field_control  :0x01                                    
[color="#000102"]continuity_counter   :0x02
[color="#000102"]PID = 0x0000,表示此TS包的内容为PSI信息表格的PAT表格数据,在4字节的TS包头之后的第一个字节的Point_field = 0x00, 表示偏移量为0,即紧随其后的即为PAT的数据信息。
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/98222/showart_2015654.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP