MPEG-TS PSI parsing

3.8k Views Asked by At

I am trying to construct EIT table sections as specified in EN 300 468. I have successfully parsed the packets into data structures (in Java), and can access the payload of each packet.

I don't understand how the table section is split across the packets, the specification is slightly confusing/uncertain. What is the process, assuming one can filter a stream of TS packets by PID, to construct such a table ?

I understand the payload_unit_start_indicator being set, indicates that the first byte of the payload field is a pointer to the first byte of the new section, is that an offset from the start of the payload ?

If for example I receive a TS packet, and I identify it as the start of a section, do I then read the bytes into an array, determine the section length from the header and then keep filling my array with more and more TS packet payloads of the same PID until bytesRead == sectionLength?

Thanks for reading, any advice or help at all would be hugely appreciated! :)

2

There are 2 best solutions below

0
On

From the en300 468 spec:

Sections may start at the beginning of the payload of a TS packet, but this is not a requirement, because the start of the first section in the payload of a TS packet is pointed to by the pointer_field.

So the section start actually is an offset from the payload:

uint8_t* section_start = payload + *payload + 1
0
On

Here you can visualize the structure of a Transport Packet (TP).

What is the process, assuming one can filter a stream of TS packets by PID, to construct such a table ?

Well you pretty much nailed it:

To build a section from the stream, you have to accumulate TPs from the same PID. As you guessed payload_unit_start_indicator indicates the start of a new section. However it is not an offset.

Then as you said you simply have to keep gathering the payloads of TPs of the same PID until payloadBytesRead == sectionLength.

Transport Packets (188 bytes each):
---------------------------
|Header|     Payload1     |            TP1: payload_unit_start_indicator = 1
---------------------------
^
0x47 (Sync Byte)

---------------------------
|Header|     Payload2     |            TP2: payload_unit_start_indicator = 0
---------------------------

... 

Section (sectionLength):
---------------------------------------    ---------------------
|     Payload1     |     Payload2     | ...|      Payload N    |
---------------------------------------    ---------------------