TS Stream parsing-ts Header Parsing

Source: Internet
Author: User

 

Based on the definition and structure of each data in the previous article, the data is parsed as follows:

TS header definition:

Typedef struct ts_packet_header
{
Unsigned sync_byte: 8; // Synchronization Byte, fixed to 0x47, indicating a TS group
Unsigned transport_error_indicator: 1; // Transmission Error Code Indicator
Unsigned payload_unit_start_indicator: 1; // start indicator of the effective load unit

Unsigned transport_priority: 1; // transmission priority. 1 indicates a high priority. The transmission mechanism may be used and decoding is not required.
Unsigned PID: 13; // PID
Unsigned transport_scrambling_control: 2; // transmission Disturbance Control
Unsigned adaption_field_control: 2; // adaptive control 01 contains only payload, 10 contains only adjustment fields, and 11 contains adjustment fields and payload. 00 decoder not processed
Unsigned continuity_counter: 4; // continuous counter: A 4-bit counter, ranging from 0 to 15
} Ts_packet_header;

 

TS 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 the data of a TS package:

0x47 0x40 0x00 0x12 0x00 0x00 0xb0 0x0d 0x00 0x00 0xc1 0x00 0x00 0x00 0 0x01 0xe3 0xf0 000000000x79 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0000000000000xff 0xff 0xff 0xff 0xff 0xff 0x0xff 0xff 0x0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0000000000000000000000000000000000000xff 0xff 0xff 0x0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0000000000000000000000000000000000000xff 0xff 0xff 0x0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0000000000000000000000000000000000000xff 0xff 0xff 0x0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff

The analysis shows that the first four 0x47 0x40 0x00 0x12ts headers are ts header data. The analysis is 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, indicating that the content of this ts package is the Pat table data of the PSI information table, point_field = 0x00 in the first byte after the 4-byte ts header, it indicates that the offset is 0, followed by Pat's data information.

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.