Final Solution PSI-SI (1)

Source: Internet
Author: User

Packet Concept

 (1)TSThe stream is based onPacket bit stream format. Each package is 188 bytes or 204 bytes.(Generally, it is 188 bytes. The format of 204 bytes is only to add 16 bytes of CRC data at the back of the 188-byte packet. Other formats are the same.) The composition of the entire TS stream is as follows:   

  Packet1    Packet2   ......   PacketN

In actual use, because the TS stream has a strong internal error processing capability, it generally uses a 188-byte package format, the format of a 204-byte package is generally used in HD programs.

 All packet formats are unified, including a packetHeader and packetDatas. PacketThe header contains the Synchronization Byte (this byte is fixed to 0x47, indicating that the data in this package is correct at the beginning), the unique number of the packet (that is, the PID) and other information. the format is as follows (in C format)

TypedefStruct

{

 UnsignedSync_byte: 8;

 UnsignedTransport_error_indicator: 1;

 UnsignedPayload_unit_start_indicator: 1;

 UnsignedTransport_priority: 1;

 UnsignedPID: 13;

 UnsignedTransport_scrambling_control: 2;

 UnsignedAdaptation_field_control: 2;

 UnsignedContinuity_counter: 4;

} Packet_header;

The above structure occupies 32BITs, that is, four bytes. Therefore, the four bytes of the packet header of a TS stream are header information. By analyzing this header information, you can know the attributes of the current packet..The rest184 bytes may be video data, audio data, or DVB.SI information,HowWhat is the difference? In fact, it is very easy to use the PID information in the header. in the previous chapter, Pat is the program Association table, and its PID is 0x0000. This PID correspondsHeader PID. In other words, if we find that the PID of a packet is equal to 0x0000, it indicates that this packet is a pat table of DVB insteadVideo or audio data.

RealWhen the signal is encoded into a TS code stream, different PIDs are allocated for video and audio data of different programs. For example, a program has two channels of video, three channels of audioWhen PID is assigned, it may be video.1 = 0x100, video2 = 0x101, audio1 = 0x102, audio2 = 0x103,Audio3 = 0x104, so the PID in the transmitted ts code stream may have the above PID. Therefore, if we needProgramFilter the first video and second video.Audio can be processed in this way (pseudoCodeDescription ):

 VoidProcess_packet (unsignedChar * buff)

 {

  IntPID = getpid (buff );

  If (pid = 0x100)

  {

   Savetovideobuffer (buff + 4 );

  }

  ElseIf (pid = 0x103)

  {

   Savetoaudiobuffer (buff + 4 );

  }

  Else

  {

   Printf ("unknownPID! "N ");

  }  

 }

NowThe problem is, how do I know the data corresponding to the PID allocated during encoding? This is DVB.The Analysis and Processing of the SI table are completed. See chapter 3. here firstLet's look at an example of the actual ts code stream. The data here is obtained by opening the TS code stream file in the hexadecimal format using ultraedit. The file is a Taiwan-551.ts.

ThisOnly 3 packets are intercepted. Note the red part in the figure. This is the header information of the 4 bytes of the TS Stream packet. this TS stream uses 188 bytes in total for each packetFormat, because the interval between the two headers is 188 bytes (the interval between the first 0x47 and the second 0x47). All future packages will be in the format of 188 bytes, which isDVBThe fixed size specified by the TS standard. what data are contained in these three packages? Let's analyze them by ourselves.

 FirstCheck the first package. The header information is "0x47 ".0x070xe50x12 ", I already know that the header information is operated by bit (that is why ts code streams can also be calledThe reason for bitstream). Note that MSB is used for definition and transmission.First, that is, the first bit that appears is the highest bit of the data. First, it is converted into a binary format:

 01000111000001111110010100010010

Compare the packet_header structure above:

TypedefStruct

{

 UnsignedSync_byte: 8;

 UnsignedTransport_error_indicator: 1;

 UnsignedPayload_unit_start_indicator: 1;

 UnsignedTransport_priority: 1;

 UnsignedPID: 13;

 UnsignedTransport_scrambling_control: 2;

 UnsignedAdaptation_field_control: 2;

 UnsignedContinuity_counter: 4;

} Packet_header;

In comparison, we can find that:

 Sync_byte = 01000111, that is, 0x47. This is DVB.Synchronization Byte specified by ts, fixed to 0x47.

 Transport_error_indicator = 0, indicating that the current package has no transmission error.

 Payload_unit_start_indicator = 0, meaning please refer to ISO13818-1 standard documentation

 Transport_priority = 0, indicating that the current package has a low priority.

 PID = 1, 0011111100101 is 0x07e5. What does this mean? I don't know it yet (actually videoPID, refer)

 Transport_scrambling_control = 00, indicating that the program is not encrypted

 Adaptation_field_control = 01 0x01. For more information, see ISO13818-1.

 Continuity_counte = 0010, that is, 0x02, indicates that the number of packages of the same type currently transmitted is 3rd.

Let's take a look at the second package "0x47.0x070xe50x13 ", 2 in 01000111000001111110010100010011

 Sync_byte = 01000111, that is, 0x47. This is DVB.Synchronization Byte specified by ts, fixed to 0x47.

 Transport_error_indicator = 0, indicating that the current package has no transmission error.

 Payload_unit_start_indicator = 0, meaning please refer to ISO13818-1 standard documentation

 Transport_priority = 0, indicating that the current package has a low priority.

 PID = 1, 0011111100101 is 0x07e5. What does this mean? I don't know it yet (actually videoPID, refer)

 Transport_scrambling_control = 00, indicating that the program is not encrypted

 Adaptation_field_control = 01 0x01. For more information, see ISO13818-1.

 Continuity_counte = 0011, that is, 0x03, indicates that the number of packages of the same type currently transmitted is 4th (note that the PID of the above two packages is 0x07e5, so the continuity_counte here is incremented once)

The third package is "0x47 ".0x070xf10x18 ", 2 in 01000111000001111111000100011000.

 Sync_byte = 01000111, that is, 0x47. This is DVB.Synchronization Byte specified by ts, fixed to 0x47.

 Transport_error_indicator = 0, indicating that the current package has no transmission error.

 Payload_unit_start_indicator = 0, meaning please refer to ISO13818-1 standard documentation

 Transport_priority = 0, indicating that the current package has a low priority.

 PID = 1, 0011111100101 is 0x07f1. What does this mean? I don't know yet (actually it's audioPID, refer)

 Transport_scrambling_control = 00, indicating that the program is not encrypted

 Adaptation_field_control = 01 0x01. For more information, see ISO13818-1.

 Continuity_counte = 1000, that is, 0x08, indicates that 9th packets of the same type are currently transmitted.

See the decoder <seekforMPEG-2Decoder> Read the result of the file:

 

We can find that the Taiwan-551.ts has a program called "Dimo", its videoPID is 0x07e5, audioPID is 0x07e6

There is also a program called "Service1 ", no videoPID, its audioPID is 0x07f1 (indicating a broadcast program rather than a TV program)

This data exactly matches our analysis.

but I think you still have questions. Why does 0x07e5 represent video PID and 0x07e6 represent an audio PID? This is what we just mentioned. It is allocated when the TS stream is encoded . But how does it know that 0x07e5 represents video rather than audio during decoding?

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.