TS Header Parsing

Source: Internet
Author: User
Tags reserved
TS Packet header parsing

Allocation of table identifier value (TABLE_ID)

Value Description

0X00 Program Association segment (PAT)

0x01 conditional receive segment (CAT)

0X02 Program Map segment (PMT)

0X03 Transport Stream Description segment

0x04 to 0x3F reserved

0x40 Current Network information segment (NIT actual)

0x41 Other network information segments (NIT other)

0x42 Current Transport Flow Service description segment (SDT actual)

0x43 to 0x45 reserved for use

0X46 Current Transport Flow Service description segment (SDT other)

0x47 to 0x49 reserved for use

0x4A Business Group Association segment (BAT)

0x4B to 0x4d reserved for use

0x4E Current/Subsequent (EIT PF Actual) event information segment for present stream

0x4f Other transport Stream event information segment, current/subsequent (EIT PF other)

0x50 to 0x5f current stream event information segment, schedule (EIT Schedule Actual)

0x60 to 0x6F other transport stream event information segment, schedule (EIT Schedule Other)

0x70 Time-Date segment (TDT)

0x71 Run status segment (RST)

0x72 filling segment (ST)

0x73 Time offset segment (TOT)

0x74 to 0x7d reserved for use

0x7E Discontinuous Information segment

0x7F Select information Segment

0x80 to 0xFE User defined

0xFF reserved

PID Assignment of Business information

Table PID Values

PAT 0x0000

CAT 0x0001

TSDT 0x0002

Reserved 0x0003 to 0x000f

NIT, ST 0x0010

SDT, BAT, ST 0x0011

EIT, ST 0x0012

RST, ST 0x0013

TDT, TOT, ST 0x0014

Network Synchronization 0x0015

Reserved for use 0x0016 to 0x001b

In-band signaling 0x001c

Measurement 0x001d

DIT 0x001e

SIT 0x001f


According to the definition of the data in the previous article and the data structure, the data are analyzed separately as follows:

TS Package Header definition:

typedef struct TS_PACKET_HEADER
{
unsigned sync_byte:8; Synchronization byte, fixed to 0x47, indicates that a TS group is followed
unsigned transport_error_indicator:1; Transmit Error Indicator
unsigned payload_unit_start_indicator:1; Effective load cell Start indicator

unsigned transport_priority:1; Transmit priority, 1 means high priority, transmission mechanism may be used, decoding is not
unsigned pid:13; Pid
unsigned transport_scrambling_control:2; Transmission scrambling control
unsigned adaption_field_control:2; Adaptive Control 01 contains only payload, 10 only adjustment fields, 11 contains adjustment fields and payload. No processing for 00 decoder
unsigned continuity_counter:4; Continuous counter a 4bit counter, range 0-15
} Ts_packet_header;

TS Packet header parsing code:

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; Four-bit data, should be 0x0f XYY 09.03.18

return 0;
}

The following is a TS package data:

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 0 Xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xf F 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xFF 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0x FF 0xFF 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xFF 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0 Xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff

The analysis knows that the first four bits 0x47 0x40 0x00 0x12ts Head is the TS packet header data, parsing as follows:

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, which indicates that the contents of this TS package are the PAT table data for the PSI information table, the first byte after the 4-byte TS packet header is Point_field = 0x00, which represents an offset of 0, The data information that is immediately followed by Pat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.