TS包头解析

来源:互联网 发布:手机淘宝模版售后服务 编辑:程序博客网 时间:2024/04/29 07:35

TS包解析

表标识符值(table_id)的分配

值 描述

0x00 节目关联段(PAT)

0x01 条件接收段(CAT)

0x02 节目映射段(PMT)

0x03 传输流描述段

0x04 至 0x3F 预留

0x40 现行网络信息段(NIT actual)

0x41 其它网络信息段(NIT other)

0x42 现行传输流业务描述段(SDT actual)

0x43 至 0x45 预留使用

0x46 现行传输流业务描述段(SDT other)

0x47 至 0x49 预留使用

0x4A 业务群关联段(BAT)

0x4B 至 0x4D 预留使用

0x4E 现行传输流事件信息段,当前/后续(EIT PF actual)

0x4F 其它传输流事件信息段,当前/后续(EIT PF other)

0x50 至 0x5F 现行传输流事件信息段,时间表(EIT Schedule actual)

0x60 至 0x6F 其它传输流事件信息段,时间表(EIT Schedule other)

0x70 时间-日期段(TDT)

0x71 运行状态段(RST)

0x72 填充段(ST)

0x73 时间偏移段(TOT)

0x74 至 0x7D 预留使用

0x7E 不连续信息段

0x7F 选择信息段

0x80 至 0xFE 用户定义

0xFF 预留

业务信息的PID分配

表                PID 值

PAT               0x0000

CAT               0x0001

TSDT              0x0002

预留               0x0003 至0x000F

NIT, ST           0x0010

SDT , BAT, ST     0x0011

EIT, ST           0x0012

RST, ST           0x0013

TDT, TOT, ST      0x0014

网络同步           0x0015

预留使用           0x0016 至 0x001B

带内信令           0x001C

测量               0x001D

DIT               0x001E

SIT               0x001F


 

根据前一篇中各数据的定义及数据结构,对数据进行分别解析如下:

TS包头定义:

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;

 

TS包解析代码:

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) << 8 | buf[2];
    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

 return 0;
}

如下为一个TS包数据:

0x47 0x40 0x00 0x12 0x00 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

分析知道前四位0x47 0x40 0x00 0x12TS头部即为TS包头数据,解析如下:

sync_byte   :0x47
transport_error_indicator: 0x00
payload_unit_start_indicator: 0x01
transport_priority  : 0x00

  PID                     :0x0000
transport_scrambling_control  :0x00
adaptation_field_control  :0x01                                     

continuity_counter   :0x02

PID = 0x0000,表示此TS包的内容为PSI信息表格的PAT表格数据,在4字节的TS包头之后的第一个字节的Point_field = 0x00, 表示偏移量为0,即紧随其后的即为PAT的数据信息

原创粉丝点击