Parsing MPEG-TS PSI
I am trying to plot EIT table partitions as specified in EN 300 468 . I have successfully parsed the packages into data structures (in Java) and can access the payload of each package.
I don't understand how the table section is split into packages, the spec is a little confusing / undefined. What is the process assuming that it is possible to filter the TS packet stream using PIDs to build such a table?
I understand that being set payload_unit_start_indicator
indicates that the first byte of the payload field is a pointer to the first byte of the new section, is this 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, I then read the bytes in the 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 before bytesRead == sectionLength
?
Thanks for reading, any advice or help at all would be greatly appreciated! :)
source to share
Here you can visualize the structure of the Transport Package (TP).
What is the process assuming that one can filter the TS packet stream by PID to build such a table?
Well, you've nailed it pretty much:
To create a section from a stream, you need to accumulate TP from the same PID. As you might have guessed, payload_unit_start_indicator
indicates the start of a new section. However, this is not an offset.
Then, as you said, you just need to collect the TP payload of the same PID before 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 |
--------------------------------------- ---------------------
source to share
From the en300 468 spec:
Sections can start at the beginning of the TS packet payload, but this is not required since the beginning of the first section in the TS packet payload is indicated by the pointer_field.
So the start of a section is actually an offset from the payload:
uint8_t* section_start = payload + *payload + 1
source to share