TS包頭解析

來源:互聯網
上載者:User
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的資料資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.